From fe1eaeb15947e1fec986acbe80f29debbb650efb Mon Sep 17 00:00:00 2001 From: Prakruthi Deepak Heragu Date: Mon, 19 Aug 2019 17:13:36 -0700 Subject: edk2: QcomModulePkg: Calculate image offsets based on Header Version [Cherry-picked from https://source.codeaurora.org/quic/la/abl/tianocore/edk2/commit/?id=221dc1de0c97e4eb91262e67539908fb0b0f14e3] When we disable avb feature, calculate the size of the data needed to be read from the flash completely. Add suport to read the dtb.img which is present at the end of the boot image in case of the header version 2. This change is needed because up until header version 2, dtbs were appended to the kernel and in kernel size, dtbs were included. Change-Id: Iad055672e473951fc92c4138c98555e67875aeb0 Signed-off-by: Amit Pundir --- QcomModulePkg/Library/BootLib/BootLinux.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/QcomModulePkg/Library/BootLib/BootLinux.c b/QcomModulePkg/Library/BootLib/BootLinux.c index 61feed46d9..6492e91c1f 100644 --- a/QcomModulePkg/Library/BootLib/BootLinux.c +++ b/QcomModulePkg/Library/BootLib/BootLinux.c @@ -1309,6 +1309,7 @@ CheckImageHeader (VOID *ImageHdrBuffer, BOOLEAN BootIntoRecovery) { EFI_STATUS Status = EFI_SUCCESS; + struct boot_img_hdr_v2 *BootImgHdrV2; UINT32 KernelSizeActual = 0; UINT32 DtSizeActual = 0; UINT32 RamdiskSizeActual = 0; @@ -1318,6 +1319,7 @@ CheckImageHeader (VOID *ImageHdrBuffer, UINT32 KernelSize = 0; UINT32 RamdiskSize = 0; UINT32 SecondSize = 0; + UINT32 DtSize = 0; UINT32 tempImgSize = 0; if (CompareMem ((void *)((boot_img_hdr *)(ImageHdrBuffer))->magic, BOOT_MAGIC, @@ -1358,6 +1360,21 @@ CheckImageHeader (VOID *ImageHdrBuffer, return EFI_BAD_BUFFER_SIZE; } + if (HeaderVersion == BOOT_HEADER_VERSION_TWO) { + BootImgHdrV2 = (struct boot_img_hdr_v2 *) + ((UINT64) ImageHdrBuffer + + BOOT_IMAGE_HEADER_V1_RECOVERY_DTBO_SIZE_OFFSET + + BOOT_IMAGE_HEADER_V2_OFFSET); + DtSize = BootImgHdrV2->dtb_size; + + DtSizeActual = ROUND_TO_PAGE (DtSize, *PageSize - 1); + if (DtSize && + !DtSizeActual) { + DEBUG ((EFI_D_ERROR, "Integer Overflow: dt Size = %u\n", DtSize)); + return EFI_BAD_BUFFER_SIZE; + } + } + *ImageSizeActual = ADD_OF (*PageSize, KernelSizeActual); if (!*ImageSizeActual) { DEBUG ((EFI_D_ERROR, "Integer Overflow: Actual Kernel size = %u\n", -- cgit v1.2.3