To make it clearer which parts of struct elf_image are used only in barebox proper, reorganize the struct.
Also .base_load_addr is assigned and never used outside the function that sets it, so turn it into a local variable instead. Signed-off-by: Ahmad Fatoum <[email protected]> --- common/elf.c | 13 +++++++------ include/lib/elf.h | 11 ++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/common/elf.c b/common/elf.c index 296ff3ec7d4c..0df40c13a3a6 100644 --- a/common/elf.c +++ b/common/elf.c @@ -65,6 +65,7 @@ static int elf_compute_load_offset(struct elf_image *elf) void *phdr = buf + elf_hdr_e_phoff(elf, buf); u64 min_vaddr = (u64)-1; u64 min_paddr = (u64)-1; + unsigned long base_load_addr; /* Find lowest p_vaddr and p_paddr in PT_LOAD segments */ elf_for_each_segment(phdr, elf, buf) { @@ -86,11 +87,11 @@ static int elf_compute_load_offset(struct elf_image *elf) * 3. For ET_DYN, use lowest p_paddr */ if (elf->load_address) - elf->base_load_addr = elf->load_address; + base_load_addr = (unsigned long)elf->load_address; else if (elf->type == ET_EXEC) - elf->base_load_addr = NULL; + base_load_addr = 0; else - elf->base_load_addr = (void *)(phys_addr_t)min_paddr; + base_load_addr = min_paddr; /* * Calculate relocation offset: @@ -100,11 +101,11 @@ static int elf_compute_load_offset(struct elf_image *elf) if (elf->type == ET_EXEC && !elf->load_address) elf->reloc_offset = 0; else - elf->reloc_offset = ((unsigned long)elf->base_load_addr - min_vaddr); + elf->reloc_offset = base_load_addr - min_vaddr; - pr_debug("ELF load: type=%s, base=%p, offset=%08lx\n", + pr_debug("ELF load: type=%s, base=%08lx, offset=%08lx\n", elf->type == ET_EXEC ? "ET_EXEC" : "ET_DYN", - elf->base_load_addr, elf->reloc_offset); + base_load_addr, elf->reloc_offset); return 0; } diff --git a/include/lib/elf.h b/include/lib/elf.h index 1521c81df6a7..c62d8f791273 100644 --- a/include/lib/elf.h +++ b/include/lib/elf.h @@ -7,17 +7,18 @@ #include <linux/list.h> struct elf_image { - struct list_head list; u8 class; u16 type; /* ET_EXEC or ET_DYN */ u64 entry; + void *hdr_buf; + void *load_address; /* User-specified load address (NULL = use p_paddr) */ + unsigned long reloc_offset; /* Offset between p_vaddr and actual load address */ + + /* Only used in barebox proper */ + struct list_head list; void *low_addr; void *high_addr; - void *hdr_buf; const char *filename; - void *load_address; /* User-specified load address (NULL = use p_paddr) */ - void *base_load_addr; /* Calculated base address for ET_DYN */ - unsigned long reloc_offset; /* Offset between p_vaddr and actual load address */ }; static inline void elf_init_struct(struct elf_image *elf) -- 2.47.3
