ELF: add mmu callback to map segments before loading

pull/327/head
Marco Oliverio 2023-07-13 07:31:57 +00:00
parent 95ea6659f9
commit 0fd34f23c7
2 changed files with 20 additions and 1 deletions

View File

@ -136,6 +136,8 @@ typedef struct elf64_program_header {
} elf64_program_header;
typedef int (*elf_mmu_map_cb)(uint64_t, uint64_t, uint32_t);
int elf_load_image_mmu(uint8_t *image, uintptr_t *entry, elf_mmu_map_cb mmu_cb);
int elf_load_image(uint8_t *image, uintptr_t *entry);

View File

@ -67,7 +67,7 @@
/* Loader for elf32 or elf64 format program headers
* Returns the entry point function
*/
int elf_load_image(uint8_t *image, uintptr_t *entry)
int elf_load_image_mmu(uint8_t *image, uintptr_t *entry, elf_mmu_map_cb mmu_cb)
{
elf32_header* h32 = (elf32_header*)image;
elf64_header* h64 = (elf64_header*)image;
@ -134,6 +134,17 @@ int elf_load_image(uint8_t *image, uintptr_t *entry)
#endif
#ifndef ELF_PARSER
if (mmu_cb != NULL) {
if (mmu_cb(vaddr, paddr, mem_size) != 0) {
#ifdef DEBUG_ELF
wolfBoot_printf(
"\tFail to map %u bytes to %p (p %p)\n",
(uint32_t)mem_size, (void*)vaddr, (void*)paddr);
#endif
continue;
}
}
memcpy((void*)(uintptr_t)vaddr, image + offset, file_size);
if (mem_size > file_size) {
memset((void*)(uintptr_t)(vaddr + file_size), 0,
@ -153,4 +164,10 @@ int elf_load_image(uint8_t *image, uintptr_t *entry)
return 0;
}
int elf_load_image(uint8_t *image, uintptr_t *entry)
{
return elf_load_image_mmu(image, entry, NULL);
}
#endif /* WOLFBOOT_ELF */