aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorZheng Bao <fishbaozi@gmail.com>2024-03-14 13:35:38 +0800
committerFelix Held <felix-coreboot@felixheld.de>2024-03-20 13:34:57 +0000
commitf360095d935b0591c9a1a539078858f7c0174954 (patch)
tree6de00c0b2c1a399ea6c36a48041b900d70ebe472 /util
parente4214b793919fa2fe8675709021437c025e95876 (diff)
amdfwtool: Add functions to link all the tables
The purpose of integration function is to pack the FWs into table. We need to remove other process. Create a dedicate function to link all the tables together. And this linking function is only called when both the level 1 and level 2 directory are created. This simplifies the main function and logic. TEST=Identical test on all AMD SOC platform Change-Id: Ieaf97208e943c79d7b76ea62eea9355138c220b9 Signed-off-by: Zheng Bao <fishbaozi@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/81252 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
Diffstat (limited to 'util')
-rw-r--r--util/amdfwtool/amdfwtool.c150
1 files changed, 89 insertions, 61 deletions
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c
index aedd3260be..f85c36df8c 100644
--- a/util/amdfwtool/amdfwtool.c
+++ b/util/amdfwtool/amdfwtool.c
@@ -880,6 +880,60 @@ static void integrate_psp_ab(context *ctx, psp_directory_table *pspdir,
ctx->current_table = current_table_save;
}
+static void integrate_psp_levels(context *ctx,
+ amd_cb_config *cb_config)
+{
+ uint32_t current_table_save;
+ bool recovery_ab = cb_config->recovery_ab;
+ unsigned int count;
+ psp_directory_table *pspdir, *pspdir2, *pspdir2_b;
+ bool use_only_a = (cb_config->soc_id == PLATFORM_PHOENIX); /* TODO: b:285390041 */
+
+ pspdir = ctx->pspdir;
+ pspdir2 = ctx->pspdir2;
+ pspdir2_b = ctx->pspdir2_b;
+ count = pspdir->header.num_entries;
+
+ current_table_save = ctx->current_table;
+ ctx->current_table = BUFF_TO_RUN_MODE(*ctx, pspdir, AMD_ADDR_REL_BIOS);
+ if (recovery_ab && (pspdir2 != NULL)) {
+ if (cb_config->need_ish) { /* Need ISH */
+ ctx->ish_a_dir = new_ish_dir(ctx);
+ if (pspdir2_b != NULL)
+ ctx->ish_b_dir = new_ish_dir(ctx);
+ }
+ pspdir->header.num_entries = count;
+ integrate_psp_ab(ctx, pspdir, pspdir2, ctx->ish_a_dir,
+ AMD_FW_RECOVERYAB_A, cb_config->soc_id);
+ if (pspdir2_b != NULL)
+ integrate_psp_ab(ctx, pspdir, pspdir2_b, ctx->ish_b_dir,
+ use_only_a ? AMD_FW_RECOVERYAB_A : AMD_FW_RECOVERYAB_B,
+ cb_config->soc_id);
+ else
+ integrate_psp_ab(ctx, pspdir, pspdir2, ctx->ish_a_dir,
+ use_only_a ? AMD_FW_RECOVERYAB_A : AMD_FW_RECOVERYAB_B,
+ cb_config->soc_id);
+
+ count = pspdir->header.num_entries;
+ } else if (pspdir2 != NULL) {
+ assert_fw_entry(count, MAX_PSP_ENTRIES, ctx);
+ pspdir->entries[count].type = AMD_FW_L2_PTR;
+ pspdir->entries[count].subprog = 0;
+ pspdir->entries[count].rsvd = 0;
+ pspdir->entries[count].size = sizeof(pspdir2->header)
+ + pspdir2->header.num_entries
+ * sizeof(psp_directory_entry);
+
+ pspdir->entries[count].addr =
+ BUFF_TO_RUN_MODE(*ctx, pspdir2, AMD_ADDR_REL_BIOS);
+ pspdir->entries[count].address_mode =
+ SET_ADDR_MODE(pspdir, AMD_ADDR_REL_BIOS);
+ count++;
+ }
+ fill_dir_header(pspdir, count, PSP_COOKIE, ctx);
+ ctx->current_table = current_table_save;
+}
+
static void integrate_psp_firmwares(context *ctx,
psp_directory_table *pspdir,
psp_directory_table *pspdir2,
@@ -895,7 +949,6 @@ static void integrate_psp_firmwares(context *ctx,
uint64_t addr;
uint32_t current_table_save;
bool recovery_ab = cb_config->recovery_ab;
- bool use_only_a = (cb_config->soc_id == PLATFORM_PHOENIX); /* TODO: b:285390041 */
/* This function can create a primary table, a secondary table, or a
* flattened table which contains all applicable types. These if-else
@@ -1018,43 +1071,8 @@ static void integrate_psp_firmwares(context *ctx,
}
}
- fill_dir_header(pspdir, count, cookie, ctx);
-
- if (recovery_ab && (pspdir2 != NULL)) {
- if (cb_config->need_ish) { /* Need ISH */
- ctx->ish_a_dir = new_ish_dir(ctx);
- if (pspdir2_b != NULL)
- ctx->ish_b_dir = new_ish_dir(ctx);
- }
- pspdir->header.num_entries = count;
- integrate_psp_ab(ctx, pspdir, pspdir2, ctx->ish_a_dir,
- AMD_FW_RECOVERYAB_A, cb_config->soc_id);
- if (pspdir2_b != NULL)
- integrate_psp_ab(ctx, pspdir, pspdir2_b, ctx->ish_b_dir,
- use_only_a ? AMD_FW_RECOVERYAB_A : AMD_FW_RECOVERYAB_B,
- cb_config->soc_id);
- else
- integrate_psp_ab(ctx, pspdir, pspdir2, ctx->ish_a_dir,
- use_only_a ? AMD_FW_RECOVERYAB_A : AMD_FW_RECOVERYAB_B,
- cb_config->soc_id);
-
- count = pspdir->header.num_entries;
- } else if (pspdir2 != NULL) {
- assert_fw_entry(count, MAX_PSP_ENTRIES, ctx);
- pspdir->entries[count].type = AMD_FW_L2_PTR;
- pspdir->entries[count].subprog = 0;
- pspdir->entries[count].rsvd = 0;
- pspdir->entries[count].size = sizeof(pspdir2->header)
- + pspdir2->header.num_entries
- * sizeof(psp_directory_entry);
-
- pspdir->entries[count].addr =
- BUFF_TO_RUN_MODE(*ctx, pspdir2, AMD_ADDR_REL_BIOS);
- pspdir->entries[count].address_mode =
- SET_ADDR_MODE(pspdir, AMD_ADDR_REL_BIOS);
- count++;
- }
-
+ (void) (pspdir2); /* TODO: To be removed in next CLs */
+ (void) (pspdir2_b);
fill_dir_header(pspdir, count, cookie, ctx);
ctx->current_table = current_table_save;
}
@@ -1183,6 +1201,37 @@ static void add_bios_apcb_bk_entry(bios_directory_table *biosdir, unsigned int i
biosdir->entries[idx].address_mode = SET_ADDR_MODE_BY_TABLE(biosdir);
}
+static void integrate_bios_levels(context *ctx)
+{
+ unsigned int count = ctx->biosdir->header.num_entries;
+ uint32_t current_table_save;
+
+ current_table_save = ctx->current_table;
+ ctx->current_table = (char *)ctx->biosdir - ctx->rom;
+
+ if (ctx->biosdir2) {
+ assert_fw_entry(count, MAX_BIOS_ENTRIES, ctx);
+ ctx->biosdir->entries[count].type = AMD_BIOS_L2_PTR;
+ ctx->biosdir->entries[count].region_type = 0;
+ ctx->biosdir->entries[count].size =
+ + MAX_BIOS_ENTRIES
+ * sizeof(bios_directory_entry);
+ ctx->biosdir->entries[count].source =
+ BUFF_TO_RUN(*ctx, ctx->biosdir2);
+ ctx->biosdir->entries[count].address_mode =
+ SET_ADDR_MODE(ctx->biosdir, AMD_ADDR_REL_BIOS);
+ ctx->biosdir->entries[count].subprog = 0;
+ ctx->biosdir->entries[count].inst = 0;
+ ctx->biosdir->entries[count].copy = 0;
+ ctx->biosdir->entries[count].compressed = 0;
+ ctx->biosdir->entries[count].dest = -1;
+ ctx->biosdir->entries[count].reset = 0;
+ ctx->biosdir->entries[count].ro = 0;
+ count++;
+ }
+ fill_dir_header(ctx->biosdir, count, BHD_COOKIE, ctx);
+ ctx->current_table = current_table_save;
+}
static void integrate_bios_firmwares(context *ctx,
bios_directory_table *biosdir,
bios_directory_table *biosdir2,
@@ -1394,29 +1443,6 @@ static void integrate_bios_firmwares(context *ctx,
}
fill_dir_header(biosdir, count, cookie, ctx);
-
- if (biosdir2) {
- assert_fw_entry(count, MAX_BIOS_ENTRIES, ctx);
- biosdir->entries[count].type = AMD_BIOS_L2_PTR;
- biosdir->entries[count].region_type = 0;
- biosdir->entries[count].size =
- + MAX_BIOS_ENTRIES
- * sizeof(bios_directory_entry);
- biosdir->entries[count].source =
- BUFF_TO_RUN(*ctx, biosdir2);
- biosdir->entries[count].address_mode =
- SET_ADDR_MODE(biosdir, AMD_ADDR_REL_BIOS);
- biosdir->entries[count].subprog = 0;
- biosdir->entries[count].inst = 0;
- biosdir->entries[count].copy = 0;
- biosdir->entries[count].compressed = 0;
- biosdir->entries[count].dest = -1;
- biosdir->entries[count].reset = 0;
- biosdir->entries[count].ro = 0;
- count++;
- }
-
- fill_dir_header(biosdir, count, cookie, ctx);
ctx->current_table = current_table_save;
}
@@ -1689,6 +1715,7 @@ int main(int argc, char **argv)
ctx.pspdir = new_psp_dir(&ctx, cb_config.multi_level);
integrate_psp_firmwares(&ctx, ctx.pspdir, ctx.pspdir2, ctx.pspdir2_b,
amd_psp_fw_table, PSP_COOKIE, &cb_config);
+ integrate_psp_levels(&ctx, &cb_config);
} else {
/* flat: PSP 1 cookie and no pointer to 2nd table */
ctx.pspdir = new_psp_dir(&ctx, cb_config.multi_level);
@@ -1735,6 +1762,7 @@ int main(int argc, char **argv)
ctx.biosdir = new_bios_dir(&ctx, cb_config.multi_level);
integrate_bios_firmwares(&ctx, ctx.biosdir, ctx.biosdir2,
amd_bios_table, BHD_COOKIE, &cb_config);
+ integrate_bios_levels(&ctx);
}
} else {
/* flat: BHD1 cookie and no pointer to 2nd table */