diff options
author | Zheng Bao <fishbaozi@gmail.com> | 2023-03-07 18:37:43 +0800 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2023-03-10 13:40:21 +0000 |
commit | 39cae56c41a9c93aff15c8d0e0247cdc6a89ec04 (patch) | |
tree | 8f8be17b824da9aa5991042ce6a48c287d2a65f6 | |
parent | 9bb62cb364b95c21161dc52a66f11bd8ef60cc50 (diff) |
amdfwtool: Add a wrapper function to open and process config file
And move the additional processing to this new function.
Change-Id: Id101d63e4d30a6e57ac1aa79665a4ba22b2956f1
Signed-off-by: Zheng Bao <fishbaozi@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/73509
Reviewed-by: Martin Roth <martin.roth@amd.corp-partner.google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Fred Reitberger <reitbergerfred@gmail.com>
-rw-r--r-- | util/amdfwtool/amdfwtool.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c index e53e5dc0b3..75aa94b5f8 100644 --- a/util/amdfwtool/amdfwtool.c +++ b/util/amdfwtool/amdfwtool.c @@ -2155,6 +2155,33 @@ static ssize_t write_body(char *output, void *body_offset, ssize_t body_size, co return bytes; } +void open_process_config(char *config, amd_cb_config *cb_config, int list_deps, int debug) +{ + FILE *config_handle; + + if (config) { + config_handle = fopen(config, "r"); + if (config_handle == NULL) { + fprintf(stderr, "Can not open file %s for reading: %s\n", + config, strerror(errno)); + exit(1); + } + if (process_config(config_handle, cb_config, list_deps) == 0) { + fprintf(stderr, "Configuration file %s parsing error\n", + config); + fclose(config_handle); + exit(1); + } + fclose(config_handle); + } + + /* For debug. */ + if (debug) { + dump_psp_firmwares(amd_psp_fw_table); + dump_bdt_firmwares(amd_bios_table); + } +} + int main(int argc, char **argv) { int c; @@ -2168,7 +2195,6 @@ int main(int argc, char **argv) int fuse_defined = 0; int targetfd; char *output = NULL, *config = NULL; - FILE *config_handle; context ctx = { 0 }; /* Values cleared after each firmware or parameter, regardless if N/A */ uint8_t sub = 0, instance = 0; @@ -2415,25 +2441,7 @@ int main(int argc, char **argv) } } - if (config) { - config_handle = fopen(config, "r"); - if (config_handle == NULL) { - fprintf(stderr, "Can not open file %s for reading: %s\n", - config, strerror(errno)); - exit(1); - } - if (process_config(config_handle, &cb_config, list_deps) == 0) { - fprintf(stderr, "Configuration file %s parsing error\n", config); - fclose(config_handle); - exit(1); - } - fclose(config_handle); - } - /* For debug. */ - if (debug) { - dump_psp_firmwares(amd_psp_fw_table); - dump_bdt_firmwares(amd_bios_table); - } + open_process_config(config, &cb_config, list_deps, debug); if (!fuse_defined) register_fw_fuse(DEFAULT_SOFT_FUSE_CHAIN); |