From e9e4e54e27d7d6ff987f694d183534a7f1713c04 Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Wed, 17 Feb 2021 17:34:44 +0100 Subject: util/ifittool: Add an option to set the FIT pointer a CBFS file The purpose of this is to eventually move the FIT table out of the bootblock, generate it separately as a cbfs file and then have the FIT pointer point to that cbfs file. TESTED: extracted a FIT table using dd, added it as a cbfs file and see that the FIT pointer correctly points to it. Also test that trying to add a non valid FIT cbfs file results in an error. Change-Id: I6e38b7df31e6b30f75b0ae57a5332f386e00f16b Signed-off-by: Arthur Heymans Reviewed-on: https://review.coreboot.org/c/coreboot/+/50925 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Rudolph Reviewed-by: Christian Walter --- util/cbfstool/fit.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'util/cbfstool/fit.c') diff --git a/util/cbfstool/fit.c b/util/cbfstool/fit.c index 63956dd7f9..da931432e9 100644 --- a/util/cbfstool/fit.c +++ b/util/cbfstool/fit.c @@ -519,6 +519,40 @@ int fit_add_microcode_file(struct fit_table *fit, return 0; } +static uint32_t *get_fit_ptr(struct buffer *bootblock, fit_offset_converter_t offset_fn, + uint32_t topswap_size) +{ + return rom_buffer_pointer(bootblock, + ptr_to_offset(offset_fn, bootblock, + FIT_POINTER_LOCATION - topswap_size)); +} + +/* Set the FIT pointer to a FIT table. */ +int set_fit_pointer(struct buffer *bootblock, + const uint32_t fit_address, + fit_offset_converter_t offset_fn, + uint32_t topswap_size) +{ + struct fit_table *fit; + uint32_t *fit_pointer = get_fit_ptr(bootblock, offset_fn, topswap_size); + + fit = rom_buffer_pointer(bootblock, ptr_to_offset(offset_fn, bootblock, fit_address)); + + if (fit_address < FIT_TABLE_LOWEST_ADDRESS) { + ERROR("FIT must be reside in the top 16MiB.\n"); + return 1; + } + + if (!fit_table_verified(fit)) { + ERROR("FIT not found at address.\n"); + return 1; + } + + fit_pointer[0] = fit_address; + fit_pointer[1] = 0; + return 0; +} + /* * Return a pointer to the active FIT. */ @@ -527,11 +561,7 @@ struct fit_table *fit_get_table(struct buffer *bootblock, uint32_t topswap_size) { struct fit_table *fit; - uint32_t *fit_pointer; - - fit_pointer = rom_buffer_pointer(bootblock, - ptr_to_offset(offset_fn, bootblock, - FIT_POINTER_LOCATION)); + uint32_t *fit_pointer = get_fit_ptr(bootblock, offset_fn, 0); /* Ensure pointer is below 4GiB and within 16MiB of 4GiB */ if (fit_pointer[1] != 0 || fit_pointer[0] < FIT_TABLE_LOWEST_ADDRESS) { -- cgit v1.2.3