summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorClement Leger <cleger@kalray.eu>2020-06-12 09:10:33 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-06-15 16:15:05 +0200
commit7a7cc824c7d748eb6b6821c2fcdb04074cede97b (patch)
treea21fadd505976de6d6fa7e7ef9c3d076648dc311 /include
parent860fbba93e53666ca46dd92dedfda43c9c426931 (diff)
downloadbarebox-7a7cc824c7d748eb6b6821c2fcdb04074cede97b.tar.gz
barebox-7a7cc824c7d748eb6b6821c2fcdb04074cede97b.tar.xz
common: elf: load elf directly from file
Currently, elf file must be loaded into a buffer and then passed to elf_load_image. This requires to copy the whole elf file before booting it. This commit allows to pass the filename directly and will allocate data only for the elf header (elf header + program headers). This will then be used to load the elf data from the file without copying it in an intermediate buffer. Elf segments are first parsed into a list and are then loaded from the file in a second time. Signed-off-by: Clement Leger <cleger@kalray.eu> Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/elf.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/include/elf.h b/include/elf.h
index 403412f3f0..f1a80a20a5 100644
--- a/include/elf.h
+++ b/include/elf.h
@@ -405,7 +405,8 @@ struct elf_image {
u64 entry;
void *low_addr;
void *high_addr;
- void *buf;
+ void *hdr_buf;
+ char *filename;
};
static inline size_t elf_get_mem_size(struct elf_image *elf)
@@ -413,7 +414,7 @@ static inline size_t elf_get_mem_size(struct elf_image *elf)
return elf->high_addr - elf->low_addr;
}
-struct elf_image *elf_load_image(void *buf);
+struct elf_image *elf_load_image(const char *filename);
void elf_release_image(struct elf_image *elf);
#define ELF_GET_FIELD(__s, __field, __type) \
@@ -427,6 +428,7 @@ static inline __type elf_##__s##_##__field(struct elf_image *elf, void *arg) { \
ELF_GET_FIELD(hdr, e_entry, u64)
ELF_GET_FIELD(hdr, e_phnum, u16)
ELF_GET_FIELD(hdr, e_phoff, u64)
+ELF_GET_FIELD(hdr, e_phentsize, u16)
ELF_GET_FIELD(hdr, e_type, u16)
ELF_GET_FIELD(phdr, p_paddr, u64)
ELF_GET_FIELD(phdr, p_filesz, u64)