[U-Boot] [PATCH] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs
Mike Frysinger
vapier at gentoo.org
Sun Nov 2 06:20:02 CET 2008
The current ELF loading function does a lot of work above and beyond a
simple "loading". It ignores the real load addresses and loads things into
their virtual (runtime) address. This is undesirable when we just want it
to load an ELF and let the ELF do the actual C runtime init.
Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
common/cmd_elf.c | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/common/cmd_elf.c b/common/cmd_elf.c
index 3ebb6d9..7b82749 100644
--- a/common/cmd_elf.c
+++ b/common/cmd_elf.c
@@ -276,6 +276,32 @@ int valid_elf_image (unsigned long addr)
* A very simple elf loader, assumes the image is valid, returns the
* entry point address.
* ====================================================================== */
+#ifdef CONFIG_ELF_SIMPLE_LOAD
+unsigned long load_elf_image (unsigned long addr)
+{
+ Elf32_Ehdr *ehdr;
+ Elf32_Phdr *phdr;
+ unsigned long entry;
+ size_t i;
+
+ ehdr = (Elf32_Ehdr *) addr;
+ phdr = (Elf32_Phdr *) (addr + ehdr->e_phoff);
+
+ entry = ehdr->e_entry;
+
+ /* Load each program header */
+ for (i = 0; i < ehdr->e_phnum; ++i) {
+ void *dst = (void *) phdr->p_paddr;
+ void *src = (void *) addr + phdr->p_offset;
+ printf ("Loading phdr %i to 0x%p (%i bytes)\n",
+ i, dst, phdr->p_filesz);
+ memcpy (dst, src, phdr->p_filesz);
+ ++phdr;
+ }
+
+ return entry;
+}
+#else
unsigned long load_elf_image (unsigned long addr)
{
Elf32_Ehdr *ehdr; /* Elf header structure pointer */
@@ -327,6 +353,7 @@ unsigned long load_elf_image (unsigned long addr)
return ehdr->e_entry;
}
+#endif
/* ====================================================================== */
U_BOOT_CMD(
--
1.6.0.3
More information about the U-Boot
mailing list