From e15b584961e682ba73210f96dfcab8ebfc5551bb Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Wed, 20 Mar 2024 10:15:01 +0100 Subject: [PATCH] util/cbfstool: Deal with how lld organizes loadable segments LLD deals with loadable segments in a different manner than BFD. The MemSiz of the .text loadable section is padded till the virtaddr of the .car.data section. Since .text is not loaded in ENV_CAR this does not matter. Change-Id: I1a0541c8ea3dfbebfba83d505d84b6db12000723 Signed-off-by: Arthur Heymans Reviewed-on: https://review.coreboot.org/c/coreboot/+/84043 Reviewed-by: Elyes Haouas Tested-by: build bot (Jenkins) --- util/cbfstool/cbfs-mkstage.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c index a72b387c2b..cdd353e063 100644 --- a/util/cbfstool/cbfs-mkstage.c +++ b/util/cbfstool/cbfs-mkstage.c @@ -311,12 +311,21 @@ static Elf64_Phdr **find_loadable_segments(struct parsed_elf *pelf) } phdrs[size - 2] = cur; - if (prev && (prev->p_paddr + prev->p_memsz != cur->p_paddr || - prev->p_filesz != prev->p_memsz)) { - ERROR("Loadable segments physical addresses should " - "be consecutive\n"); - free(phdrs); - return NULL; + if (prev) { + const bool bfd_is_consecutive = prev->p_paddr + prev->p_memsz == cur->p_paddr + && prev->p_filesz == prev->p_memsz; + /* + * lld pads the memsz of the .text vaddr till the vaddr of car.data. + * Since we don't load XIP stages at runtime, we don't care. + */ + const bool lld_is_consecutive = prev->p_vaddr + prev->p_memsz == cur->p_vaddr; + + if (!bfd_is_consecutive && !lld_is_consecutive) { + ERROR("Loadable segments physical addresses should " + "be consecutive\n"); + free(phdrs); + return NULL; + } } prev = cur; }