drivers/intel/fsp2_0: Enable firmware splash using 24-bit BMP logo

The get_color_map_num function previously returned 0 for both error
conditions (e.g., NULL header, invalid image offset) and for BMPs
that legitimately lack a color map, such as 24-bit BMP logo. This
ambiguity prevented the correct processing of 24-bit BMPs for
firmware splash screens, as the caller could not distinguish them
from malformed images.

This commit addresses this by refining error handling:
1. Modifying `get_color_map_num` to return -1 for actual errors.
2. Ensuring a return value of 0 from `get_color_map_num` now
   unambiguously signifies that the BMP has no color map. This
   is relevant for formats like 24-bit or 32-bit, where the
   default switch case now explicitly sets the color map count to 0.
3. Changing the function's return type and its internal color map
   count variable (`col_map_number`) to `int` to accommodate the
   negative error code.
4. Updating the caller, `fsp_convert_bmp_to_gop_blt`, to check for
   a return value `< 0` to identify errors, separating these from
   the valid no-colormap case (return 0).

These changes enable the successful rendering of 24-bit BMP images
as firmware splash screens. This also provides more robust BMP
parsing and clearer error distinction overall.

BUG=b:410318591
TEST=Able to build and boot google/fatcat. Verified 24-bit
BMP logo is able to render successful.

Change-Id: I7006e823e10b9892da17ff904095ef5892bb690d
Signed-off-by: Subrata Banik <subratabanik@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/87581
Reviewed-by: Jayvik Desai <jayvik@google.com>
Reviewed-by: Dinesh Gehlot <digehlot@google.com>
Reviewed-by: Kapil Porwal <kapilporwal@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Subrata Banik 2025-05-09 08:58:42 +00:00
commit aa1eba2f25

View file

@ -100,12 +100,12 @@ static uint32_t calculate_blt_buffer_size(efi_bmp_image_header *header)
return blt_buffer_size;
}
static uint32_t get_color_map_num(efi_bmp_image_header *header)
static int get_color_map_num(efi_bmp_image_header *header)
{
uint32_t col_map_number = 0;
int col_map_number;
if (header == NULL)
return 0;
return -1;
switch (header->BitPerPixel) {
case 1:
@ -118,6 +118,11 @@ static uint32_t get_color_map_num(efi_bmp_image_header *header)
col_map_number = 256;
break;
default:
/*
* For other bit depths (e.g., 24-bit and 32-bit) that doesn't have
* a standard palette, col_map_number remains 0.
*/
col_map_number = 0;
break;
}
@ -127,7 +132,7 @@ static uint32_t get_color_map_num(efi_bmp_image_header *header)
*/
if (header->ImageOffset - sizeof(efi_bmp_image_header) <
sizeof(efi_bmp_color_map) * col_map_number)
return 0;
return -1;
return col_map_number;
}
@ -450,7 +455,7 @@ void fsp_convert_bmp_to_gop_blt(efi_uintn_t *logo, uint32_t *logo_size,
if (!blt_buffer_size)
return;
if (!get_color_map_num(bmp_header))
if (get_color_map_num(bmp_header) < 0)
return;
bool is_standard_orientation = (orientation == LB_FB_ORIENTATION_NORMAL ||