amdfwtool: Detect the flag multilevel to decide the actual value

To save the space for FW, some of the FWs are going to be defined as
LVL2 entries. To be compatible to "flattened" layout, we still drop
the LVL2 entry to level1 if there is only one level.

Change-Id: Ibe8cdd5c14225899352b02bb19aae6059d56d428
Signed-off-by: Zheng Bao <fishbaozi@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/57063
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Martin Roth <martinroth@google.com>
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c
index 57c67f0..d051582 100644
--- a/util/amdfwtool/amdfwtool.c
+++ b/util/amdfwtool/amdfwtool.c
@@ -585,7 +585,8 @@
 					psp_directory_table *pspdir,
 					psp_directory_table *pspdir2,
 					amd_fw_entry *fw_table,
-					uint32_t cookie)
+					uint32_t cookie,
+					amd_cb_config *cb_config)
 {
 	ssize_t bytes;
 	unsigned int i, count;
@@ -598,7 +599,9 @@
 	 * 1st-level cookie may indicate level 1 or flattened.  If the caller
 	 * passes a pointer to a 2nd-level table, then assume not flat.
 	 */
-	if (cookie == PSPL2_COOKIE)
+	if (cb_config->multi_level == 0)
+		level = PSP_BOTH;
+	else if (cookie == PSPL2_COOKIE)
 		level = PSP_LVL2;
 	else if (pspdir2)
 		level = PSP_LVL1;
@@ -763,7 +766,8 @@
 					bios_directory_table *biosdir,
 					bios_directory_table *biosdir2,
 					amd_bios_entry *fw_table,
-					uint32_t cookie)
+					uint32_t cookie,
+					amd_cb_config *cb_config)
 {
 	ssize_t bytes;
 	unsigned int i, count;
@@ -779,7 +783,9 @@
 	 * 1st-level cookie may indicate level 1 or flattened.  If the caller
 	 * passes a pointer to a 2nd-level table, then assume not flat.
 	 */
-	if (cookie == BDT2_COOKIE)
+	if (cb_config->multi_level == 0)
+		level = BDT_BOTH;
+	else if (cookie == BDT2_COOKIE)
 		level = BDT_LVL2;
 	else if (biosdir2)
 		level = BDT_LVL1;
@@ -1568,16 +1574,16 @@
 		/* Do 2nd PSP directory followed by 1st */
 		psp_directory_table *pspdir2 = new_psp_dir(&ctx, cb_config.multi_level);
 		integrate_psp_firmwares(&ctx, pspdir2, 0,
-						amd_psp_fw_table, PSPL2_COOKIE);
+						amd_psp_fw_table, PSPL2_COOKIE, &cb_config);
 
 		pspdir = new_psp_dir(&ctx, cb_config.multi_level);
 		integrate_psp_firmwares(&ctx, pspdir, pspdir2,
-						amd_psp_fw_table, PSP_COOKIE);
+						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, 0,
-						amd_psp_fw_table, PSP_COOKIE);
+						amd_psp_fw_table, PSP_COOKIE, &cb_config);
 	}
 
 	if (comboable)
@@ -1605,16 +1611,16 @@
 			bios_directory_table *biosdir2 =
 						new_bios_dir(&ctx, cb_config.multi_level);
 			integrate_bios_firmwares(&ctx, biosdir2, 0,
-						amd_bios_table, BDT2_COOKIE);
+						amd_bios_table, BDT2_COOKIE, &cb_config);
 
 			biosdir = new_bios_dir(&ctx, cb_config.multi_level);
 			integrate_bios_firmwares(&ctx, biosdir, biosdir2,
-						amd_bios_table, BDT1_COOKIE);
+						amd_bios_table, BDT1_COOKIE, &cb_config);
 		} else {
 			/* flat: BDT1 cookie and no pointer to 2nd table */
 			biosdir = new_bios_dir(&ctx, cb_config.multi_level);
 			integrate_bios_firmwares(&ctx, biosdir, 0,
-						amd_bios_table, BDT1_COOKIE);
+						amd_bios_table, BDT1_COOKIE, &cb_config);
 		}
 		switch (soc_id) {
 		case PLATFORM_RENOIR: