* [U-Boot] [PATCH] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs @ 2008-11-02 5:20 Mike Frysinger 2008-12-05 22:21 ` Wolfgang Denk 2010-10-02 19:44 ` [U-Boot] [PATCH] cmd_elf: add an option for loading " Mike Frysinger 0 siblings, 2 replies; 6+ messages in thread From: Mike Frysinger @ 2008-11-02 5:20 UTC (permalink / raw) To: u-boot 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@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 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs 2008-11-02 5:20 [U-Boot] [PATCH] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs Mike Frysinger @ 2008-12-05 22:21 ` Wolfgang Denk 2008-12-06 1:02 ` Mike Frysinger 2010-10-02 19:44 ` [U-Boot] [PATCH] cmd_elf: add an option for loading " Mike Frysinger 1 sibling, 1 reply; 6+ messages in thread From: Wolfgang Denk @ 2008-12-05 22:21 UTC (permalink / raw) To: u-boot Dear Mike, In message <1225603202-5757-1-git-send-email-vapier@gentoo.org> you wrote: > 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. I apologize for the late review... > +#ifdef CONFIG_ELF_SIMPLE_LOAD > +unsigned long load_elf_image (unsigned long addr) ... ...but would it not make sense to allow to make the decision which behaviour fits the user's requirements at runtime instead of compile time? We could either make this depend on some environment variable setting, or on a command line option when running the command. If you prefer to stick with the CONFIG_ELF_SIMPLE_LOAD solution, then this variable has to be documented in the README. Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de The Gates in my computer are AND, OR and NOT; they are not Bill. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs 2008-12-05 22:21 ` Wolfgang Denk @ 2008-12-06 1:02 ` Mike Frysinger 2008-12-07 0:21 ` Wolfgang Denk 0 siblings, 1 reply; 6+ messages in thread From: Mike Frysinger @ 2008-12-06 1:02 UTC (permalink / raw) To: u-boot On Friday 05 December 2008 17:21:27 Wolfgang Denk wrote: > In message <1225603202-5757-1-git-send-email-vapier@gentoo.org> you wrote: > > 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. > > I apologize for the late review... > > > +#ifdef CONFIG_ELF_SIMPLE_LOAD > > +unsigned long load_elf_image (unsigned long addr) > > ... > > ...but would it not make sense to allow to make the decision which > behaviour fits the user's requirements at runtime instead of compile > time? > > We could either make this depend on some environment variable setting, > or on a command line option when running the command. > > > If you prefer to stick with the CONFIG_ELF_SIMPLE_LOAD solution, then > this variable has to be documented in the README. it doesnt matter to me which route is taken so long as the default can be controlled (so via env is ok as you can set the default env values). if you prefer one over the other, let me know. otherwise simply updating the README is the easiest route for me ... -mike -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 835 bytes Desc: This is a digitally signed message part. Url : http://lists.denx.de/pipermail/u-boot/attachments/20081205/9ba137e8/attachment.pgp ^ permalink raw reply [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs 2008-12-06 1:02 ` Mike Frysinger @ 2008-12-07 0:21 ` Wolfgang Denk 0 siblings, 0 replies; 6+ messages in thread From: Wolfgang Denk @ 2008-12-07 0:21 UTC (permalink / raw) To: u-boot Dear Mike, in message <200812052002.18103.vapier@gentoo.org> you wrote: > > > ...but would it not make sense to allow to make the decision which > > behaviour fits the user's requirements at runtime instead of compile > > time? > > > > We could either make this depend on some environment variable setting, > > or on a command line option when running the command. > > > > > > If you prefer to stick with the CONFIG_ELF_SIMPLE_LOAD solution, then > > this variable has to be documented in the README. > > it doesnt matter to me which route is taken so long as the default can be > controlled (so via env is ok as you can set the default env values). if you > prefer one over the other, let me know. otherwise simply updating the README > is the easiest route for me ... Well, my preference is a command line option; I think we should move into that direction instead of adding more and more magic environment variables. But if you submit a patch that uses environment variables I would not object either. Thanks. Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de To the systems programmer, users and applications serve only to provide a test load. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH] cmd_elf: add an option for loading ELFs according to PHDRs 2008-11-02 5:20 [U-Boot] [PATCH] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs Mike Frysinger 2008-12-05 22:21 ` Wolfgang Denk @ 2010-10-02 19:44 ` Mike Frysinger 2010-10-06 20:42 ` Wolfgang Denk 1 sibling, 1 reply; 6+ messages in thread From: Mike Frysinger @ 2010-10-02 19:44 UTC (permalink / raw) To: u-boot 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. So add a command line option to let people choose to load via either the program or section headers. I'd prefer to have program header loading be the default, but this would break historical behavior, so I'll leave section header loading as the norm. Signed-off-by: Mike Frysinger <vapier@gentoo.org> --- common/cmd_elf.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 53 insertions(+), 9 deletions(-) diff --git a/common/cmd_elf.c b/common/cmd_elf.c index 104d6e6..bf32612 100644 --- a/common/cmd_elf.c +++ b/common/cmd_elf.c @@ -25,7 +25,8 @@ DECLARE_GLOBAL_DATA_PTR; #endif int valid_elf_image (unsigned long addr); -unsigned long load_elf_image (unsigned long addr); +static unsigned long load_elf_image_phdr(unsigned long addr); +static unsigned long load_elf_image_shdr(unsigned long addr); /* Allow ports to override the default behavior */ __attribute__((weak)) @@ -61,19 +62,34 @@ int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { unsigned long addr; /* Address of the ELF image */ unsigned long rc; /* Return value from user code */ + char *sload, *saddr; /* -------------------------------------------------- */ int rcode = 0; - if (argc < 2) - addr = load_addr; + sload = saddr = NULL; + if (argc == 3) { + sload = argv[1]; + saddr = argv[2]; + } else if (argc == 2) { + if (argv[1][0] == '-') + sload = argv[1]; + else + saddr = argv[1]; + } + + if (saddr) + addr = simple_strtoul(saddr, NULL, 16); else - addr = simple_strtoul (argv[1], NULL, 16); + addr = load_addr; if (!valid_elf_image (addr)) return 1; - addr = load_elf_image (addr); + if (sload && sload[1] == 'p') + addr = load_elf_image_phdr(addr); + else + addr = load_elf_image_shdr(addr); printf ("## Starting application@0x%08lx ...\n", addr); @@ -204,7 +220,7 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) */ if (valid_elf_image (addr)) { - addr = load_elf_image (addr); + addr = load_elf_image_shdr (addr); } else { puts ("## Not an ELF image, assuming binary\n"); /* leave addr as load_addr */ @@ -258,7 +274,33 @@ int valid_elf_image (unsigned long addr) * A very simple elf loader, assumes the image is valid, returns the * entry point address. * ====================================================================== */ -unsigned long load_elf_image (unsigned long addr) +static unsigned long load_elf_image_phdr(unsigned long addr) +{ + Elf32_Ehdr *ehdr; /* Elf header structure pointer */ + Elf32_Phdr *phdr; /* Program header structure pointer */ + int i; + + ehdr = (Elf32_Ehdr *) addr; + phdr = (Elf32_Phdr *) (addr + ehdr->e_phoff); + + /* 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; + debug("Loading phdr %i to 0x%p (%i bytes)\n", + i, dst, phdr->p_filesz); + if (phdr->p_filesz) + memcpy(dst, src, phdr->p_filesz); + if (phdr->p_filesz != phdr->p_memsz) + memset(dst + phdr->p_filesz, 0x00, phdr->p_memsz - phdr->p_filesz); + flush_cache((unsigned long)dst, phdr->p_filesz); + ++phdr; + } + + return ehdr->e_entry; +} + +static unsigned long load_elf_image_shdr(unsigned long addr) { Elf32_Ehdr *ehdr; /* Elf header structure pointer */ Elf32_Shdr *shdr; /* Section header structure pointer */ @@ -312,9 +354,11 @@ unsigned long load_elf_image (unsigned long addr) /* ====================================================================== */ U_BOOT_CMD( - bootelf, 2, 0, do_bootelf, + bootelf, 3, 0, do_bootelf, "Boot from an ELF image in memory", - " [address] - load address of ELF image." + "[-p|-s] [address]\n" + "\t- load ELF image at [address] via program headers (-p)\n" + "\t or via section headers (-s)" ); U_BOOT_CMD( -- 1.7.3.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH] cmd_elf: add an option for loading ELFs according to PHDRs 2010-10-02 19:44 ` [U-Boot] [PATCH] cmd_elf: add an option for loading " Mike Frysinger @ 2010-10-06 20:42 ` Wolfgang Denk 0 siblings, 0 replies; 6+ messages in thread From: Wolfgang Denk @ 2010-10-06 20:42 UTC (permalink / raw) To: u-boot Dear Mike Frysinger, In message <1286048693-1773-1-git-send-email-vapier@gentoo.org> you wrote: > 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. > > So add a command line option to let people choose to load via either the > program or section headers. I'd prefer to have program header loading > be the default, but this would break historical behavior, so I'll leave > section header loading as the norm. > > Signed-off-by: Mike Frysinger <vapier@gentoo.org> > --- > common/cmd_elf.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++------- > 1 files changed, 53 insertions(+), 9 deletions(-) Applied, thanks. Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de When properly administered, vacations do not diminish productivity: for every week you're away and get nothing done, there's another when your boss is away and you get twice as much done. -- Daniel B. Luten ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-10-06 20:42 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-11-02 5:20 [U-Boot] [PATCH] cmd_elf: CONFIG_ELF_SIMPLE_LOAD: load ELFs according to PHDRs Mike Frysinger 2008-12-05 22:21 ` Wolfgang Denk 2008-12-06 1:02 ` Mike Frysinger 2008-12-07 0:21 ` Wolfgang Denk 2010-10-02 19:44 ` [U-Boot] [PATCH] cmd_elf: add an option for loading " Mike Frysinger 2010-10-06 20:42 ` Wolfgang Denk
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox