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>
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c
index e53e5dc..75aa94b 100644
--- a/util/amdfwtool/amdfwtool.c
+++ b/util/amdfwtool/amdfwtool.c
@@ -2155,6 +2155,33 @@
 	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 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 @@
 		}
 	}
 
-	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);