amdfwtool: Move the filling of table headers into functions

It is easier to understand what these statements are about.

Change-Id: Ib02c68c9f2ea84020b12682c41fb1a6f8f93d725
Signed-off-by: Zheng Bao <fishbaozi@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/66852
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 edac06a..8c78080 100644
--- a/util/amdfwtool/amdfwtool.c
+++ b/util/amdfwtool/amdfwtool.c
@@ -688,6 +688,58 @@
 
 }
 
+static void fill_psp_directory_to_efs(embedded_firmware *amd_romsig, void *pspdir,
+	context *ctx, amd_cb_config *cb_config)
+{
+	switch (cb_config->soc_id) {
+	case PLATFORM_UNKNOWN:
+		amd_romsig->psp_directory =
+			BUFF_TO_RUN_MODE(*ctx, pspdir, AMD_ADDR_REL_BIOS);
+		break;
+	case PLATFORM_CEZANNE:
+	case PLATFORM_MENDOCINO:
+	case PLATFORM_PHOENIX:
+	case PLATFORM_GLINDA:
+	case PLATFORM_CARRIZO:
+	case PLATFORM_STONEYRIDGE:
+	case PLATFORM_RAVEN:
+	case PLATFORM_PICASSO:
+	case PLATFORM_LUCIENNE:
+	case PLATFORM_RENOIR:
+	default:
+		/* for combo, it is also combo_psp_directory */
+		amd_romsig->new_psp_directory =
+			BUFF_TO_RUN_MODE(*ctx, pspdir, AMD_ADDR_REL_BIOS);
+		break;
+	}
+}
+
+static void fill_bios_directory_to_efs(embedded_firmware *amd_romsig, void *biosdir,
+	context *ctx, amd_cb_config *cb_config)
+{
+	switch (cb_config->soc_id) {
+	case PLATFORM_RENOIR:
+	case PLATFORM_LUCIENNE:
+	case PLATFORM_CEZANNE:
+		if (!cb_config->recovery_ab)
+			amd_romsig->bios3_entry =
+				BUFF_TO_RUN_MODE(*ctx, biosdir, AMD_ADDR_REL_BIOS);
+		break;
+	case PLATFORM_MENDOCINO:
+	case PLATFORM_PHOENIX:
+	case PLATFORM_GLINDA:
+		break;
+	case PLATFORM_CARRIZO:
+	case PLATFORM_STONEYRIDGE:
+	case PLATFORM_RAVEN:
+	case PLATFORM_PICASSO:
+	default:
+		amd_romsig->bios1_entry =
+			BUFF_TO_RUN_MODE(*ctx, biosdir, AMD_ADDR_REL_BIOS);
+		break;
+	}
+}
+
 static ssize_t copy_blob(void *dest, const char *src_file, size_t room)
 {
 	int fd;
@@ -2564,31 +2616,11 @@
 					amd_psp_fw_table, PSP_COOKIE, &cb_config);
 	}
 
-	switch (cb_config.soc_id) {
-	case PLATFORM_UNKNOWN:
-		amd_romsig->psp_directory =
-			BUFF_TO_RUN_MODE(ctx, pspdir, AMD_ADDR_REL_BIOS);
-		break;
-	case PLATFORM_CEZANNE:
-	case PLATFORM_MENDOCINO:
-	case PLATFORM_PHOENIX:
-	case PLATFORM_GLINDA:
-	case PLATFORM_CARRIZO:
-	case PLATFORM_STONEYRIDGE:
-	case PLATFORM_RAVEN:
-	case PLATFORM_PICASSO:
-	case PLATFORM_LUCIENNE:
-	case PLATFORM_RENOIR:
-	default:
-		amd_romsig->new_psp_directory =
-			BUFF_TO_RUN_MODE(ctx, pspdir, AMD_ADDR_REL_BIOS);
-		break;
-	}
+	fill_psp_directory_to_efs(amd_romsig, pspdir, &ctx, &cb_config);
 
 	if (cb_config.use_combo) {
 		psp_combo_directory *combo_dir = new_combo_dir(&ctx);
-		amd_romsig->combo_psp_directory =
-			BUFF_TO_RUN_MODE(ctx, combo_dir, AMD_ADDR_REL_BIOS);
+		fill_psp_directory_to_efs(amd_romsig, combo_dir, &ctx, &cb_config);
 		/* 0 -Compare PSP ID, 1 -Compare chip family ID */
 		combo_dir->entries[0].id_sel = 0;
 		combo_dir->entries[0].id = get_psp_id(cb_config.soc_id);
@@ -2631,27 +2663,7 @@
 			integrate_bios_firmwares(&ctx, biosdir, NULL,
 						amd_bios_table, BHD_COOKIE, &cb_config);
 		}
-		switch (cb_config.soc_id) {
-		case PLATFORM_RENOIR:
-		case PLATFORM_LUCIENNE:
-		case PLATFORM_CEZANNE:
-			if (!cb_config.recovery_ab)
-				amd_romsig->bios3_entry =
-					BUFF_TO_RUN_MODE(ctx, biosdir, AMD_ADDR_REL_BIOS);
-			break;
-		case PLATFORM_MENDOCINO:
-		case PLATFORM_PHOENIX:
-		case PLATFORM_GLINDA:
-			break;
-		case PLATFORM_CARRIZO:
-		case PLATFORM_STONEYRIDGE:
-		case PLATFORM_RAVEN:
-		case PLATFORM_PICASSO:
-		default:
-			amd_romsig->bios1_entry =
-				BUFF_TO_RUN_MODE(ctx, biosdir, AMD_ADDR_REL_BIOS);
-			break;
-		}
+		fill_bios_directory_to_efs(amd_romsig, biosdir, &ctx, &cb_config);
 	}
 
 	targetfd = open(output, O_RDWR | O_CREAT | O_TRUNC, 0666);