amdfwtool: Move soc_id to cb_config

Save the soc_id into a global struct.

Change-Id: I2a0f04a09635086e3076a97b535df8a19d0693ce
Signed-off-by: Zheng Bao <fishbaozi@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/72450
Reviewed-by: Fred Reitberger <reitbergerfred@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c
index 9fe6b9a..82825e1 100644
--- a/util/amdfwtool/amdfwtool.c
+++ b/util/amdfwtool/amdfwtool.c
@@ -713,20 +713,6 @@
 	return buf_size;
 }
 
-enum platform {
-	PLATFORM_UNKNOWN,
-	PLATFORM_CARRIZO,
-	PLATFORM_STONEYRIDGE,
-	PLATFORM_RAVEN,
-	PLATFORM_PICASSO,
-	PLATFORM_RENOIR,
-	PLATFORM_CEZANNE,
-	PLATFORM_MENDOCINO,
-	PLATFORM_LUCIENNE,
-	PLATFORM_PHOENIX,
-	PLATFORM_GLINDA
-};
-
 static uint32_t get_psp_id(enum platform soc_id)
 {
 	uint32_t psp_id;
@@ -1236,7 +1222,6 @@
 					psp_directory_table *pspdir2_b,
 					amd_fw_entry *fw_table,
 					uint32_t cookie,
-					enum platform soc_id,
 					amd_cb_config *cb_config)
 {
 	ssize_t bytes;
@@ -1378,13 +1363,13 @@
 		}
 		pspdir->header.num_entries = count;
 		integrate_psp_ab(ctx, pspdir, pspdir2, ish_a_dir,
-			AMD_FW_RECOVERYAB_A, soc_id);
+			AMD_FW_RECOVERYAB_A, cb_config->soc_id);
 		if (pspdir2_b != NULL)
 			integrate_psp_ab(ctx, pspdir, pspdir2_b, ish_b_dir,
-				AMD_FW_RECOVERYAB_B, soc_id);
+				AMD_FW_RECOVERYAB_B, cb_config->soc_id);
 		else
 			integrate_psp_ab(ctx, pspdir, pspdir2, ish_a_dir,
-				AMD_FW_RECOVERYAB_B, soc_id);
+				AMD_FW_RECOVERYAB_B, cb_config->soc_id);
 
 		count = pspdir->header.num_entries;
 	} else if (pspdir2 != NULL) {
@@ -2154,7 +2139,6 @@
 	bool any_location = 0;
 	uint32_t romsig_offset;
 	uint32_t rom_base_address;
-	uint8_t soc_id = PLATFORM_UNKNOWN;
 	uint8_t efs_spi_readmode = 0xff;
 	uint8_t efs_spi_speed = 0xff;
 	uint8_t efs_spi_micron_flag = 0xff;
@@ -2299,8 +2283,8 @@
 			sub = instance = 0;
 			break;
 		case AMDFW_OPT_SOC_NAME:
-			soc_id = identify_platform(optarg);
-			if (soc_id == PLATFORM_UNKNOWN) {
+			cb_config.soc_id = identify_platform(optarg);
+			if (cb_config.soc_id == PLATFORM_UNKNOWN) {
 				fprintf(stderr, "Error: Invalid SOC name specified\n\n");
 				retval = 1;
 			}
@@ -2396,9 +2380,9 @@
 		}
 	}
 
-	cb_config.second_gen = is_second_gen(soc_id);
+	cb_config.second_gen = is_second_gen(cb_config.soc_id);
 
-	if (needs_ish(soc_id))
+	if (needs_ish(cb_config.soc_id))
 		cb_config.need_ish = true;
 
 	if (cb_config.need_ish)
@@ -2564,9 +2548,9 @@
 	amd_romsig->gec_entry = 0;
 	amd_romsig->xhci_entry = 0;
 
-	if (soc_id != PLATFORM_UNKNOWN) {
-		retval = set_efs_table(soc_id, &cb_config, amd_romsig, efs_spi_readmode,
-					efs_spi_speed, efs_spi_micron_flag);
+	if (cb_config.soc_id != PLATFORM_UNKNOWN) {
+		retval = set_efs_table(cb_config.soc_id, &cb_config, amd_romsig,
+					efs_spi_readmode, efs_spi_speed, efs_spi_micron_flag);
 		if (retval) {
 			fprintf(stderr, "ERROR: Failed to initialize EFS table!\n");
 			return retval;
@@ -2599,19 +2583,19 @@
 		process_signed_psp_firmwares(signed_output_file,
 				amd_psp_fw_table,
 				signed_start_addr,
-				soc_id);
+				cb_config.soc_id);
 
 	if (cb_config.multi_level) {
 		/* Do 2nd PSP directory followed by 1st */
 		pspdir2 = new_psp_dir(&ctx, cb_config.multi_level);
 		integrate_psp_firmwares(&ctx, pspdir2, NULL, NULL,
-					amd_psp_fw_table, PSPL2_COOKIE, soc_id, &cb_config);
+					amd_psp_fw_table, PSPL2_COOKIE, &cb_config);
 		if (cb_config.recovery_ab && !cb_config.recovery_ab_single_copy) {
 			/* Create a copy of PSP Directory 2 in the backup slot B.
 			   Related biosdir2_b copy will be created later. */
 			pspdir2_b = new_psp_dir(&ctx, cb_config.multi_level);
 			integrate_psp_firmwares(&ctx, pspdir2_b, NULL, NULL,
-					amd_psp_fw_table, PSPL2_COOKIE, soc_id, &cb_config);
+					amd_psp_fw_table, PSPL2_COOKIE, &cb_config);
 		} else {
 			/*
 			 * Either the platform is using only one slot or B is same as above
@@ -2622,12 +2606,12 @@
 		}
 		pspdir = new_psp_dir(&ctx, cb_config.multi_level);
 		integrate_psp_firmwares(&ctx, pspdir, pspdir2, pspdir2_b,
-					amd_psp_fw_table, PSP_COOKIE, soc_id, &cb_config);
+					amd_psp_fw_table, PSP_COOKIE, &cb_config);
 	} else {
 		/* flat: PSP 1 cookie and no pointer to 2nd table */
 		pspdir = new_psp_dir(&ctx, cb_config.multi_level);
 		integrate_psp_firmwares(&ctx, pspdir, NULL, NULL,
-					amd_psp_fw_table, PSP_COOKIE, soc_id, &cb_config);
+					amd_psp_fw_table, PSP_COOKIE, &cb_config);
 	}
 
 	if (comboable)
@@ -2640,7 +2624,7 @@
 		amd_romsig->combo_psp_directory = BUFF_TO_RUN(ctx, combo_dir);
 		/* 0 -Compare PSP ID, 1 -Compare chip family ID */
 		combo_dir->entries[0].id_sel = 0;
-		combo_dir->entries[0].id = get_psp_id(soc_id);
+		combo_dir->entries[0].id = get_psp_id(cb_config.soc_id);
 		combo_dir->entries[0].lvl2_addr = BUFF_TO_RUN(ctx, pspdir);
 
 		combo_dir->header.lookup = 1;
@@ -2680,7 +2664,7 @@
 			integrate_bios_firmwares(&ctx, biosdir, NULL,
 						amd_bios_table, BHD_COOKIE, &cb_config);
 		}
-		switch (soc_id) {
+		switch (cb_config.soc_id) {
 		case PLATFORM_RENOIR:
 		case PLATFORM_LUCIENNE:
 		case PLATFORM_CEZANNE:
diff --git a/util/amdfwtool/amdfwtool.h b/util/amdfwtool/amdfwtool.h
index 774c2e4..7aa3aac 100644
--- a/util/amdfwtool/amdfwtool.h
+++ b/util/amdfwtool/amdfwtool.h
@@ -9,6 +9,20 @@
 #include <stdint.h>
 #include <stdbool.h>
 
+enum platform {
+	PLATFORM_UNKNOWN,
+	PLATFORM_CARRIZO,
+	PLATFORM_STONEYRIDGE,
+	PLATFORM_RAVEN,
+	PLATFORM_PICASSO,
+	PLATFORM_RENOIR,
+	PLATFORM_CEZANNE,
+	PLATFORM_MENDOCINO,
+	PLATFORM_LUCIENNE,
+	PLATFORM_PHOENIX,
+	PLATFORM_GLINDA
+};
+
 typedef enum _amd_fw_type {
 	AMD_FW_PSP_PUBKEY = 0x00,
 	AMD_FW_PSP_BOOTLOADER = 0x01,
@@ -390,6 +404,7 @@
 	bool recovery_ab_single_copy;
 	bool need_ish;
 	bool use_combo;
+	enum platform soc_id;
 } amd_cb_config;
 
 void register_fw_fuse(char *str);