summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Heymans <arthur@aheymans.xyz>2024-08-30 09:54:36 +0200
committerFelix Held <felix-coreboot@felixheld.de>2024-10-02 12:05:49 +0000
commit4e92938fd1219513284d861edc9742854c790c64 (patch)
treef79df0c482099185f6b8cce51d4bfc9be9013747
parent4493f66904b1cb4fb33a7d9d08f6f137ebb3c780 (diff)
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>
-rw-r--r--util/cbfstool/cbfs-mkstage.c12
1 files 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)