From: Bin Meng <bmeng.cn@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 08/13] cmd: elf: Reorder load_elf_image_phdr() and load_elf_image_shdr()
Date: Mon, 28 Sep 2015 02:12:05 -0700 [thread overview]
Message-ID: <1443431530-472-9-git-send-email-bmeng.cn@gmail.com> (raw)
In-Reply-To: <1443431530-472-1-git-send-email-bmeng.cn@gmail.com>
Move load_elf_image_phdr() and load_elf_image_shdr() to the beginning
of the cmd_elf.c so that forward declaration is not needed.
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
---
Changes in v2: None
common/cmd_elf.c | 161 +++++++++++++++++++++++++++----------------------------
1 file changed, 79 insertions(+), 82 deletions(-)
diff --git a/common/cmd_elf.c b/common/cmd_elf.c
index c5e4432..62863df 100644
--- a/common/cmd_elf.c
+++ b/common/cmd_elf.c
@@ -19,8 +19,85 @@
#include <net.h>
#include <vxworks.h>
-static unsigned long load_elf_image_phdr(unsigned long addr);
-static unsigned long load_elf_image_shdr(unsigned long addr);
+/*
+ * A very simple elf loader, assumes the image is valid, returns the
+ * entry point address.
+ */
+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 *)(uintptr_t)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 */
+ unsigned char *strtab = 0; /* String table pointer */
+ unsigned char *image; /* Binary image pointer */
+ int i; /* Loop counter */
+
+ ehdr = (Elf32_Ehdr *)addr;
+
+ /* Find the section header string table for output info */
+ shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
+ (ehdr->e_shstrndx * sizeof(Elf32_Shdr)));
+
+ if (shdr->sh_type == SHT_STRTAB)
+ strtab = (unsigned char *)(addr + shdr->sh_offset);
+
+ /* Load each appropriate section */
+ for (i = 0; i < ehdr->e_shnum; ++i) {
+ shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
+ (i * sizeof(Elf32_Shdr)));
+
+ if (!(shdr->sh_flags & SHF_ALLOC) ||
+ shdr->sh_addr == 0 || shdr->sh_size == 0) {
+ continue;
+ }
+
+ if (strtab) {
+ debug("%sing %s @ 0x%08lx (%ld bytes)\n",
+ (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
+ &strtab[shdr->sh_name],
+ (unsigned long)shdr->sh_addr,
+ (long)shdr->sh_size);
+ }
+
+ if (shdr->sh_type == SHT_NOBITS) {
+ memset((void *)(uintptr_t)shdr->sh_addr, 0,
+ shdr->sh_size);
+ } else {
+ image = (unsigned char *)addr + shdr->sh_offset;
+ memcpy((void *)(uintptr_t)shdr->sh_addr,
+ (const void *)image, shdr->sh_size);
+ }
+ flush_cache(shdr->sh_addr, shdr->sh_size);
+ }
+
+ return ehdr->e_entry;
+}
/* Allow ports to override the default behavior */
static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
@@ -253,86 +330,6 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 1;
}
-/*
- * A very simple elf loader, assumes the image is valid, returns the
- * entry point address.
- */
-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 *)(uintptr_t)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 */
- unsigned char *strtab = 0; /* String table pointer */
- unsigned char *image; /* Binary image pointer */
- int i; /* Loop counter */
-
- ehdr = (Elf32_Ehdr *)addr;
-
- /* Find the section header string table for output info */
- shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
- (ehdr->e_shstrndx * sizeof(Elf32_Shdr)));
-
- if (shdr->sh_type == SHT_STRTAB)
- strtab = (unsigned char *)(addr + shdr->sh_offset);
-
- /* Load each appropriate section */
- for (i = 0; i < ehdr->e_shnum; ++i) {
- shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
- (i * sizeof(Elf32_Shdr)));
-
- if (!(shdr->sh_flags & SHF_ALLOC) ||
- shdr->sh_addr == 0 || shdr->sh_size == 0) {
- continue;
- }
-
- if (strtab) {
- debug("%sing %s @ 0x%08lx (%ld bytes)\n",
- (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
- &strtab[shdr->sh_name],
- (unsigned long)shdr->sh_addr,
- (long)shdr->sh_size);
- }
-
- if (shdr->sh_type == SHT_NOBITS) {
- memset((void *)(uintptr_t)shdr->sh_addr, 0,
- shdr->sh_size);
- } else {
- image = (unsigned char *)addr + shdr->sh_offset;
- memcpy((void *)(uintptr_t)shdr->sh_addr,
- (const void *)image, shdr->sh_size);
- }
- flush_cache(shdr->sh_addr, shdr->sh_size);
- }
-
- return ehdr->e_entry;
-}
-
U_BOOT_CMD(
bootelf, 3, 0, do_bootelf,
"Boot from an ELF image in memory",
--
1.8.2.1
next prev parent reply other threads:[~2015-09-28 9:12 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-28 9:11 [U-Boot] [PATCH v2 00/13] Better support of booting VxWorks via 'bootvx' Bin Meng
2015-09-28 9:11 ` [U-Boot] [PATCH v2 01/13] Reorder defconfigs with 'savedefconfig' Bin Meng
2015-09-28 9:11 ` [U-Boot] [PATCH v2 02/13] x86: fsp: Report correct number of E820 table entries Bin Meng
2015-09-29 4:52 ` Simon Glass
2015-10-18 12:58 ` Simon Glass
2015-10-18 15:55 ` Tom Rini
2015-10-18 20:25 ` Simon Glass
2015-10-19 0:09 ` Tom Rini
2015-10-19 2:28 ` Simon Glass
2015-09-28 9:12 ` [U-Boot] [PATCH v2 03/13] x86: Initialize GDT entry 1 to be the 32-bit CS as well Bin Meng
2015-10-01 23:00 ` Simon Glass
2015-09-28 9:12 ` [U-Boot] [PATCH v2 04/13] x86: Move install_e820_map() out of zimage.c Bin Meng
2015-10-02 7:06 ` Simon Glass
2015-09-28 9:12 ` [U-Boot] [PATCH v2 05/13] x86: Remove quotation mark in CONFIG_HOSTNAME Bin Meng
2015-10-02 7:06 ` Simon Glass
2015-09-28 9:12 ` [U-Boot] [PATCH v2 06/13] cmd: Convert CONFIG_CMD_ELF to Kconfig Bin Meng
2015-09-29 6:47 ` Hannes Schmelzer
2015-09-28 9:12 ` [U-Boot] [PATCH v2 07/13] cmd: Clean up cmd_elf a little bit Bin Meng
2015-09-29 6:54 ` Hannes Schmelzer
2015-09-28 9:12 ` Bin Meng [this message]
2015-09-28 9:12 ` [U-Boot] [PATCH v2 09/13] cmd: bootvx: Pass netmask and gatewayip to VxWorks bootline Bin Meng
2015-10-01 23:01 ` Simon Glass
2015-09-28 9:12 ` [U-Boot] [PATCH v2 10/13] cmd: bootvx: Always get VxWorks bootline from env Bin Meng
2015-09-29 6:54 ` Hannes Schmelzer
2015-09-28 9:12 ` [U-Boot] [PATCH v2 11/13] cmd: bootvx: Pass E820 information to an x86 VxWorks kernel Bin Meng
2015-10-02 7:06 ` Simon Glass
2015-09-28 9:12 ` [U-Boot] [PATCH v2 12/13] cmd: bootvx: Add asmlinkage to the VxWorks x86 entry Bin Meng
2015-10-02 7:06 ` Simon Glass
2015-09-28 9:12 ` [U-Boot] [PATCH v2 13/13] doc: Complement document about booting VxWorks Bin Meng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1443431530-472-9-git-send-email-bmeng.cn@gmail.com \
--to=bmeng.cn@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox