return value: 0: The config file can not be parsed correctly. 1: The config file can be parsed correctly. */
| 548 | 1: The config file can be parsed correctly. |
| 549 | */ |
| 550 | uint8_t process_config(FILE *config, amd_cb_config *cb_config) |
| 551 | { |
| 552 | char oneline[MAX_LINE_SIZE]; |
| 553 | regmatch_t match[N_MATCHES]; |
| 554 | char dir[MAX_LINE_SIZE] = {'\0'}; |
| 555 | uint32_t dir_len; |
| 556 | char *platform_name = NULL; |
| 557 | int index; |
| 558 | |
| 559 | for (index = 0; index < N_MATCHES; index++) { |
| 560 | match[index].rm_so = -1; |
| 561 | match[index].rm_eo = -1; |
| 562 | } |
| 563 | |
| 564 | compile_reg_expr(REG_EXTENDED | REG_NEWLINE, |
| 565 | blank_or_comment_regex, &blank_or_comment_expr); |
| 566 | compile_reg_expr(REG_EXTENDED | REG_NEWLINE, |
| 567 | entries_line_regex, &entries_line_expr); |
| 568 | |
| 569 | /* Get a line */ |
| 570 | /* Get FIRMWARE_LOCATION in the first loop */ |
| 571 | while (get_input_file_line(config, oneline, MAX_LINE_SIZE) == OK) { |
| 572 | /* get a line */ |
| 573 | if (skip_comment_blank_line(oneline)) |
| 574 | continue; |
| 575 | if (is_valid_entry(oneline, match)) { |
| 576 | if (strcmp(&(oneline[match[FW_TYPE].rm_so]), FW_LOCATION) == 0) { |
| 577 | dir_len = match[FW_FILE].rm_eo - match[FW_FILE].rm_so; |
| 578 | assert(dir_len < MAX_LINE_SIZE); |
| 579 | snprintf(dir, MAX_LINE_SIZE, "%.*s", dir_len, |
| 580 | &(oneline[match[FW_FILE].rm_so])); |
| 581 | } else if (strcmp(&(oneline[match[FW_TYPE].rm_so]), SOC_NAME) == 0) { |
| 582 | platform_name = strdup(&(oneline[match[FW_FILE].rm_so])); |
| 583 | cb_config->soc_id = platform_identify(platform_name); |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | if (!platform_name) { |
| 589 | fprintf(stderr, "AMDFWTOOL: Platform not specified in config\n"); |
| 590 | return 0; |
| 591 | } else if (cb_config->soc_id == PLATFORM_UNKNOWN) { |
| 592 | fprintf(stderr, "AMDFWTOOL: Unknown platform '%s'\n", platform_name); |
| 593 | free(platform_name); |
| 594 | return 0; |
| 595 | } |
| 596 | free(platform_name); |
| 597 | |
| 598 | if (platform_needs_ish(cb_config->soc_id)) |
| 599 | cb_config->recovery_ab = true; |
| 600 | |
| 601 | if (dir[0] == '\0') { |
| 602 | fprintf(stderr, "No line with FIRMWARE_LOCATION\n"); |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | fseek(config, 0, SEEK_SET); |
| 607 | /* Get a line */ |
no test coverage detected