amdfwtool: combo: Add combo feature for BIOS table

It is similar to PSP combo.

Change-Id: If0523a4a0e1f31969e4bbaa6062dcc0f2d6da420
Signed-off-by: Zheng Bao <fishbaozi@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/66856
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 c62ad2b..9b91386 100644
--- a/util/amdfwtool/amdfwtool.c
+++ b/util/amdfwtool/amdfwtool.c
@@ -633,6 +633,7 @@
 
 	switch (cookie) {
 	case PSP2_COOKIE:
+	case BHD2_COOKIE:
 		cdir->header.cookie = cookie;
 		/* lookup mode is hardcoded for now. */
 		cdir->header.lookup = 1;
@@ -2159,7 +2160,7 @@
 	psp_directory_table *pspdir = NULL;
 	psp_directory_table *pspdir2 = NULL;
 	psp_directory_table *pspdir2_b = NULL;
-	psp_combo_directory *psp_combo_dir = NULL;
+	psp_combo_directory *psp_combo_dir = NULL, *bhd_combo_dir = NULL;
 	int fuse_defined = 0;
 	int targetfd;
 	char *output = NULL, *config = NULL;
@@ -2590,6 +2591,10 @@
 
 	if (cb_config.use_combo) {
 		psp_combo_dir = new_combo_dir(&ctx);
+
+		adjust_current_pointer(&ctx, 0, 0x1000U);
+
+		bhd_combo_dir = new_combo_dir(&ctx);
 	}
 
 	if (cb_config.multi_level) {
@@ -2667,7 +2672,17 @@
 			integrate_bios_firmwares(&ctx, biosdir, NULL,
 						amd_bios_table, BHD_COOKIE, &cb_config);
 		}
-		fill_bios_directory_to_efs(amd_romsig, biosdir, &ctx, &cb_config);
+		if (!cb_config.use_combo) {
+			fill_bios_directory_to_efs(amd_romsig, biosdir, &ctx, &cb_config);
+		} else {
+			fill_bios_directory_to_efs(amd_romsig, bhd_combo_dir, &ctx, &cb_config);
+			bhd_combo_dir->entries[0].id_sel = 0;
+			bhd_combo_dir->entries[0].id = get_psp_id(cb_config.soc_id);
+			bhd_combo_dir->entries[0].lvl2_addr =
+				BUFF_TO_RUN_MODE(ctx, biosdir, AMD_ADDR_REL_BIOS);
+
+			fill_dir_header(bhd_combo_dir, 1, BHD2_COOKIE, &ctx);
+		}
 	}
 
 	targetfd = open(output, O_RDWR | O_CREAT | O_TRUNC, 0666);
diff --git a/util/amdfwtool/amdfwtool.h b/util/amdfwtool/amdfwtool.h
index 7aa3aac..2ccb3e9 100644
--- a/util/amdfwtool/amdfwtool.h
+++ b/util/amdfwtool/amdfwtool.h
@@ -317,6 +317,7 @@
 #define PSP2_COOKIE 0x50535032		/* 'PSP2' */
 #define BHD_COOKIE 0x44484224		/* 'DHB$ */
 #define BHDL2_COOKIE 0x324c4224		/* '2LB$ */
+#define BHD2_COOKIE 0x44484232		/* 'DHB2' */
 
 #define PSP_LVL1 (1 << 0)
 #define PSP_LVL2 (1 << 1)