Felix Held has submitted this change. ( https://review.coreboot.org/c/coreboot/+/84140?usp=email )
Change subject: util/cbfstool: Make sure to only compare PT_LOAD segments ......................................................................
util/cbfstool: Make sure to only compare PT_LOAD segments
When parsing XIP stages only compare PT_LOAD phdrs. Currently coreboot stages only use PT_LOAD phdrs.
Change-Id: I305b25032a3c4a9fdefc76cad77fafdb862a604c Signed-off-by: Arthur Heymans arthur@aheymans.xyz Reviewed-on: https://review.coreboot.org/c/coreboot/+/84140 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Julius Werner jwerner@chromium.org --- M util/cbfstool/cbfs-mkstage.c 1 file changed, 5 insertions(+), 7 deletions(-)
Approvals: Julius Werner: Looks good to me, approved build bot (Jenkins): Verified
diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c index 8129f0b..2338adc 100644 --- a/util/cbfstool/cbfs-mkstage.c +++ b/util/cbfstool/cbfs-mkstage.c @@ -295,10 +295,10 @@ static Elf64_Phdr **find_loadable_segments(struct parsed_elf *pelf) { Elf64_Phdr **phdrs = NULL; - Elf64_Phdr *prev = NULL, *cur; + Elf64_Phdr *prev = NULL, *cur = NULL; size_t size = 1, i;
- for (i = 0; i < pelf->ehdr.e_phnum; i++, prev = cur) { + for (i = 0; i < pelf->ehdr.e_phnum; i++) { cur = &pelf->phdr[i];
if (cur->p_type != PT_LOAD || cur->p_memsz == 0) @@ -311,16 +311,14 @@ } phdrs[size - 2] = cur;
- if (!prev) - continue; - - if (prev->p_paddr + prev->p_memsz != cur->p_paddr || - prev->p_filesz != prev->p_memsz) { + 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; } + prev = cur; }
if (phdrs)