Subrata Banik has submitted this change. ( https://review.coreboot.org/c/coreboot/+/81618?usp=email )
Change subject: lib: Refactor bmp_load_logo() implementation ......................................................................
lib: Refactor bmp_load_logo() implementation
This refactoring ensures bmp_load_logo() takes logo_size as an argument, returning a valid logo_ptr only if logo_size is non-zero.
This prevents potential errors from mismatched size assumption.
BUG=b:242829490 TEST=google/rex0 builds successfully.
Change-Id: I14bc54670a67980ec93bc366b274832d1f959e50 Signed-off-by: Subrata Banik subratabanik@google.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/81618 Reviewed-by: Matt DeVillier matt.devillier@amd.corp-partner.google.com Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Dinesh Gehlot digehlot@google.com Reviewed-by: Julius Werner jwerner@chromium.org --- M src/drivers/intel/fsp1_1/ramstage.c M src/drivers/intel/fsp2_0/fsp_gop_blt.c M src/include/bootsplash.h M src/lib/bmp_logo.c M src/soc/amd/mendocino/fsp_s_params.c M src/soc/intel/apollolake/chip.c M src/soc/intel/cannonlake/fsp_params.c M src/soc/intel/skylake/chip.c 8 files changed, 29 insertions(+), 17 deletions(-)
Approvals: build bot (Jenkins): Verified Julius Werner: Looks good to me, approved Matt DeVillier: Looks good to me, but someone else must approve Dinesh Gehlot: Looks good to me, approved
diff --git a/src/drivers/intel/fsp1_1/ramstage.c b/src/drivers/intel/fsp1_1/ramstage.c index 5c40966..713770a 100644 --- a/src/drivers/intel/fsp1_1/ramstage.c +++ b/src/drivers/intel/fsp1_1/ramstage.c @@ -76,9 +76,11 @@ load_vbt(&silicon_init_params); mainboard_silicon_init_params(&silicon_init_params);
- if (CONFIG(BMP_LOGO)) - bmp_load_logo(&silicon_init_params.PcdLogoPtr, - &silicon_init_params.PcdLogoSize); + if (CONFIG(BMP_LOGO)) { + size_t logo_size; + silicon_init_params.PcdLogoPtr = (uint32_t)(uintptr_t)bmp_load_logo(&logo_size); + silicon_init_params.PcdLogoSize = (uint32_t)logo_size; + }
/* Display the UPD data */ if (CONFIG(DISPLAY_UPD_DATA)) diff --git a/src/drivers/intel/fsp2_0/fsp_gop_blt.c b/src/drivers/intel/fsp2_0/fsp_gop_blt.c index 8b64502..f59bb86 100644 --- a/src/drivers/intel/fsp2_0/fsp_gop_blt.c +++ b/src/drivers/intel/fsp2_0/fsp_gop_blt.c @@ -237,13 +237,15 @@ uint32_t *blt_ptr, uint32_t *blt_size, uint32_t *pixel_height, uint32_t *pixel_width) { - uint32_t logo_ptr, logo_ptr_size, blt_buffer_size; + uint32_t logo_ptr; + size_t logo_ptr_size, blt_buffer_size; efi_bmp_image_header *bmp_header;
if (!logo || !logo_size || !blt_ptr || !blt_size || !pixel_height || !pixel_width) return;
- bmp_load_logo(&logo_ptr, &logo_ptr_size); + logo_ptr = (uint32_t)(uintptr_t)bmp_load_logo(&logo_ptr_size); + if (!logo_ptr || logo_ptr_size < sizeof(efi_bmp_image_header)) { printk(BIOS_ERR, "%s: BMP Image size is too small.\n", __func__); return; diff --git a/src/include/bootsplash.h b/src/include/bootsplash.h index 86048a4..372e8c2 100644 --- a/src/include/bootsplash.h +++ b/src/include/bootsplash.h @@ -20,7 +20,7 @@ * For example: Introduce configurable BMP logo for customization on platforms like ChromeOS */ const char *bmp_logo_filename(void); -void bmp_load_logo(uint32_t *logo_ptr, uint32_t *logo_size); +void *bmp_load_logo(size_t *logo_size); void bmp_release_logo(void);
#endif diff --git a/src/lib/bmp_logo.c b/src/lib/bmp_logo.c index 2888777..becb605 100644 --- a/src/lib/bmp_logo.c +++ b/src/lib/bmp_logo.c @@ -16,25 +16,27 @@ } #endif
-void bmp_load_logo(uint32_t *logo_ptr, uint32_t *logo_size) +void *bmp_load_logo(size_t *logo_size) { void *logo_buffer;
/* CBMEM is locked for S3 resume path. */ if (acpi_is_wakeup_s3()) - return; + return NULL;
logo_entry = cbmem_entry_add(CBMEM_ID_FSP_LOGO, 1 * MiB); if (!logo_entry) - return; + return NULL;
logo_buffer = cbmem_entry_start(logo_entry); if (!logo_buffer) - return; + return NULL;
*logo_size = cbfs_load(bmp_logo_filename(), logo_buffer, 1 * MiB); - if (*logo_size) - *logo_ptr = (uintptr_t)logo_buffer; + if (*logo_size == 0) + return NULL; + + return logo_buffer; }
void bmp_release_logo(void) diff --git a/src/soc/amd/mendocino/fsp_s_params.c b/src/soc/amd/mendocino/fsp_s_params.c index 8374fb3..50923e9 100644 --- a/src/soc/amd/mendocino/fsp_s_params.c +++ b/src/soc/amd/mendocino/fsp_s_params.c @@ -55,6 +55,6 @@
void soc_load_logo(FSPS_UPD *supd) { - uint32_t logo_size; - bmp_load_logo(&supd->FspsConfig.logo_bmp_buffer, &logo_size); + size_t logo_size; + supd->FspsConfig.logo_bmp_buffer = (uint32_t)(uintptr_t)bmp_load_logo(&logo_size); } diff --git a/src/soc/intel/apollolake/chip.c b/src/soc/intel/apollolake/chip.c index 91e39c9..1d15eec 100644 --- a/src/soc/intel/apollolake/chip.c +++ b/src/soc/intel/apollolake/chip.c @@ -915,7 +915,9 @@ /* Handle FSP logo params */ void soc_load_logo(FSPS_UPD *supd) { - bmp_load_logo(&supd->FspsConfig.LogoPtr, &supd->FspsConfig.LogoSize); + size_t logo_size; + supd->FspsConfig.LogoPtr = (uint32_t)(uintptr_t)bmp_load_logo(&logo_size); + supd->FspsConfig.LogoSize = (uint32_t)logo_size; }
BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, spi_flash_init_cb, NULL); diff --git a/src/soc/intel/cannonlake/fsp_params.c b/src/soc/intel/cannonlake/fsp_params.c index c9ef548..e1eede2 100644 --- a/src/soc/intel/cannonlake/fsp_params.c +++ b/src/soc/intel/cannonlake/fsp_params.c @@ -754,5 +754,7 @@ /* Handle FSP logo params */ void soc_load_logo(FSPS_UPD *supd) { - bmp_load_logo(&supd->FspsConfig.LogoPtr, &supd->FspsConfig.LogoSize); + size_t logo_size; + supd->FspsConfig.LogoPtr = (uintptr_t)bmp_load_logo(&logo_size); + supd->FspsConfig.LogoSize = (uint32_t)logo_size; } diff --git a/src/soc/intel/skylake/chip.c b/src/soc/intel/skylake/chip.c index ea091ce..050a272 100644 --- a/src/soc/intel/skylake/chip.c +++ b/src/soc/intel/skylake/chip.c @@ -529,5 +529,7 @@ /* Handle FSP logo params */ void soc_load_logo(FSPS_UPD *supd) { - bmp_load_logo(&supd->FspsConfig.LogoPtr, &supd->FspsConfig.LogoSize); + size_t logo_size; + supd->FspsConfig.LogoPtr = (uint32_t)(uintptr_t)bmp_load_logo(&logo_size); + supd->FspsConfig.LogoSize = (uint32_t)logo_size; }