From 39cae56c41a9c93aff15c8d0e0247cdc6a89ec04 Mon Sep 17 00:00:00 2001 From: Zheng Bao Date: Tue, 7 Mar 2023 18:37:43 +0800 Subject: 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/73509 Reviewed-by: Martin Roth Tested-by: build bot (Jenkins) Reviewed-by: Fred Reitberger --- util/amdfwtool/amdfwtool.c | 48 +++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'util/amdfwtool/amdfwtool.c') 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); -- cgit v1.2.3