From 4e92938fd1219513284d861edc9742854c790c64 Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Fri, 30 Aug 2024 09:54:36 +0200 Subject: 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/84140 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- util/cbfstool/cbfs-mkstage.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c index 8129f0b4d6..2338adc7ae 100644 --- a/util/cbfstool/cbfs-mkstage.c +++ b/util/cbfstool/cbfs-mkstage.c @@ -295,10 +295,10 @@ static int rmod_filter(struct reloc_filter *f, const Elf64_Rela *r) 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 @@ static Elf64_Phdr **find_loadable_segments(struct parsed_elf *pelf) } 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) -- cgit v1.2.3