From 4a359401370d179b6b37dd6a6ff0c87ca8e1d241 Mon Sep 17 00:00:00 2001 From: Dun Tan Date: Wed, 1 Sep 2021 10:29:41 +0800 Subject: util/cbftool: Fix the bug in parsing Uefipayload with extended header The patch is to fix "Not a usable UEFI firmware volume" issue when creating CBFS/flash image. This issue is caused by adding FvNameGuid in UefiPayloadEntry.fdf in EDKII. There is an ext header between header of Fv and header of PayloadEntry in Fv with FvNameGuid. The ext header causes the UefiPayloadEntry to be found incorrectly when parsing Fv. Commit in EDKII: 4bac086e8e007c7143e33f87bb96238326d1d6ba Bugzila: https://bugzilla.tianocore.org/show_bug.cgi?id=3585 Signed-off-by: Dun Tan Change-Id: Id063efb1c8e6c7a96ec2182e87b71c7e8b7b6423 Reviewed-on: https://review.coreboot.org/c/coreboot/+/57296 Reviewed-by: Ray Ni Reviewed-by: King Sumo Reviewed-by: Patrick Rudolph Reviewed-by: Patrick Rudolph Tested-by: build bot (Jenkins) --- util/cbfstool/cbfs-mkpayload.c | 7 +++++++ util/cbfstool/fv.h | 5 +++++ 2 files changed, 12 insertions(+) (limited to 'util/cbfstool') diff --git a/util/cbfstool/cbfs-mkpayload.c b/util/cbfstool/cbfs-mkpayload.c index ae875f36349b..5341337a8501 100644 --- a/util/cbfstool/cbfs-mkpayload.c +++ b/util/cbfstool/cbfs-mkpayload.c @@ -283,6 +283,7 @@ int parse_fv_to_payload(const struct buffer *input, struct buffer *output, struct cbfs_payload_segment segs[2] = { {0} }; int doffset, len = 0; firmware_volume_header_t *fv; + firmware_volume_ext_header_t *fvh_ext; ffs_file_header_t *fh; common_section_header_t *cs; dos_header_t *dh; @@ -305,6 +306,12 @@ int parse_fv_to_payload(const struct buffer *input, struct buffer *output, } fh = (ffs_file_header_t *)(input->data + fv->header_length); + if (fv->ext_header_offs != 0) { + fvh_ext = (firmware_volume_ext_header_t *)((uintptr_t)fv + fv->ext_header_offs); + fh = (ffs_file_header_t *)((uintptr_t)fvh_ext + fvh_ext->ext_header_size); + fh = (ffs_file_header_t *)(((uintptr_t)fh + 7) & ~7); + } + while (fh->file_type == FILETYPE_PAD) { unsigned long offset = (fh->size[2] << 16) | (fh->size[1] << 8) | fh->size[0]; DEBUG("skipping %lu bytes of FV padding\n", offset); diff --git a/util/cbfstool/fv.h b/util/cbfstool/fv.h index 21bd89f56350..0ad650f1babf 100644 --- a/util/cbfstool/fv.h +++ b/util/cbfstool/fv.h @@ -32,3 +32,8 @@ typedef struct { uint8_t size[3]; uint8_t section_type; } common_section_header_t; + +typedef struct { + uint8_t guid[16]; + uint32_t ext_header_size; +} firmware_volume_ext_header_t; -- cgit v1.2.3