common: cmd_elf.c: fix checkpath.pl warnings

[Tom: Move valid_elf_image around and don't mark it as static as another
board makes use of this function]

Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Signed-off-by: Tom Rini <trini@ti.com>
This commit is contained in:
Daniel Schwierzeck 2012-09-16 06:55:05 +00:00 committed by Tom Rini
parent 7b64f66c58
commit 62e03d33c9

View file

@ -24,7 +24,6 @@
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
#endif #endif
int valid_elf_image (unsigned long addr);
static unsigned long load_elf_image_phdr(unsigned long addr); static unsigned long load_elf_image_phdr(unsigned long addr);
static unsigned long load_elf_image_shdr(unsigned long addr); static unsigned long load_elf_image_shdr(unsigned long addr);
@ -55,6 +54,39 @@ unsigned long do_bootelf_exec (ulong (*entry)(int, char * const[]),
return ret; return ret;
} }
/* ======================================================================
* Determine if a valid ELF image exists at the given memory location.
* First looks at the ELF header magic field, the makes sure that it is
* executable and makes sure that it is for a PowerPC.
* ====================================================================== */
int valid_elf_image(unsigned long addr)
{
Elf32_Ehdr *ehdr; /* Elf header structure pointer */
/* -------------------------------------------------- */
ehdr = (Elf32_Ehdr *) addr;
if (!IS_ELF(*ehdr)) {
printf("## No elf image at address 0x%08lx\n", addr);
return 0;
}
if (ehdr->e_type != ET_EXEC) {
printf("## Not a 32-bit elf image at address 0x%08lx\n", addr);
return 0;
}
#if 0
if (ehdr->e_machine != EM_PPC) {
printf("## Not a PowerPC elf image at address 0x%08lx\n", addr);
return 0;
}
#endif
return 1;
}
/* ====================================================================== /* ======================================================================
* Interpreter command to boot an arbitrary ELF image from memory. * Interpreter command to boot an arbitrary ELF image from memory.
* ====================================================================== */ * ====================================================================== */
@ -130,13 +162,14 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
addr = simple_strtoul(argv[1], NULL, 16); addr = simple_strtoul(argv[1], NULL, 16);
#if defined(CONFIG_CMD_NET) #if defined(CONFIG_CMD_NET)
/* Check to see if we need to tftp the image ourselves before starting */ /*
* Check to see if we need to tftp the image ourselves before starting
*/
if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) { if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
if (NetLoop(TFTPGET) <= 0) if (NetLoop(TFTPGET) <= 0)
return 1; return 1;
printf("Automatic boot of VxWorks image at address 0x%08lx " printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
"...\n", addr); addr);
} }
#endif #endif
@ -164,8 +197,8 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
* PowerPC is LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET which * PowerPC is LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET which
* defaults to 0x4200 * defaults to 0x4200
*/ */
tmp = getenv("bootaddr");
if ((tmp = getenv ("bootaddr")) == NULL) if (tmp)
bootaddr = CONFIG_SYS_VXWORKS_BOOT_ADDR; bootaddr = CONFIG_SYS_VXWORKS_BOOT_ADDR;
else else
bootaddr = simple_strtoul(tmp, NULL, 16); bootaddr = simple_strtoul(tmp, NULL, 16);
@ -175,34 +208,33 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
* parameter. If it is not defined, we may be able to * parameter. If it is not defined, we may be able to
* construct the info * construct the info
*/ */
bootline = getenv("bootargs");
if ((bootline = getenv ("bootargs")) != NULL) { if (bootline) {
memcpy((void *) bootaddr, bootline, memcpy((void *) bootaddr, bootline,
max(strlen(bootline), 255)); max(strlen(bootline), 255));
flush_cache(bootaddr, max(strlen(bootline), 255)); flush_cache(bootaddr, max(strlen(bootline), 255));
} else { } else {
sprintf(build_buf, CONFIG_SYS_VXWORKS_BOOT_DEVICE); sprintf(build_buf, CONFIG_SYS_VXWORKS_BOOT_DEVICE);
if ((tmp = getenv ("bootfile")) != NULL) { tmp = getenv("bootfile");
if (tmp)
sprintf(&build_buf[strlen(build_buf)], sprintf(&build_buf[strlen(build_buf)],
"%s:%s ", CONFIG_SYS_VXWORKS_SERVERNAME, tmp); "%s:%s ", CONFIG_SYS_VXWORKS_SERVERNAME, tmp);
} else { else
sprintf(&build_buf[strlen(build_buf)], sprintf(&build_buf[strlen(build_buf)],
"%s:file ", CONFIG_SYS_VXWORKS_SERVERNAME); "%s:file ", CONFIG_SYS_VXWORKS_SERVERNAME);
}
if ((tmp = getenv ("ipaddr")) != NULL) { tmp = getenv("ipaddr");
if (tmp)
sprintf(&build_buf[strlen(build_buf)], "e=%s ", tmp); sprintf(&build_buf[strlen(build_buf)], "e=%s ", tmp);
}
if ((tmp = getenv ("serverip")) != NULL) { tmp = getenv("serverip");
if (tmp)
sprintf(&build_buf[strlen(build_buf)], "h=%s ", tmp); sprintf(&build_buf[strlen(build_buf)], "h=%s ", tmp);
}
if ((tmp = getenv ("hostname")) != NULL) { tmp = getenv("hostname");
if (tmp)
sprintf(&build_buf[strlen(build_buf)], "tn=%s ", tmp); sprintf(&build_buf[strlen(build_buf)], "tn=%s ", tmp);
}
#ifdef CONFIG_SYS_VXWORKS_ADD_PARAMS #ifdef CONFIG_SYS_VXWORKS_ADD_PARAMS
sprintf(&build_buf[strlen(build_buf)], sprintf(&build_buf[strlen(build_buf)],
CONFIG_SYS_VXWORKS_ADD_PARAMS); CONFIG_SYS_VXWORKS_ADD_PARAMS);
@ -237,40 +269,6 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 1; return 1;
} }
/* ======================================================================
* Determine if a valid ELF image exists at the given memory location.
* First looks at the ELF header magic field, the makes sure that it is
* executable and makes sure that it is for a PowerPC.
* ====================================================================== */
int valid_elf_image (unsigned long addr)
{
Elf32_Ehdr *ehdr; /* Elf header structure pointer */
/* -------------------------------------------------- */
ehdr = (Elf32_Ehdr *) addr;
if (!IS_ELF (*ehdr)) {
printf ("## No elf image at address 0x%08lx\n", addr);
return 0;
}
if (ehdr->e_type != ET_EXEC) {
printf ("## Not a 32-bit elf image at address 0x%08lx\n", addr);
return 0;
}
#if 0
if (ehdr->e_machine != EM_PPC) {
printf ("## Not a PowerPC elf image at address 0x%08lx\n",
addr);
return 0;
}
#endif
return 1;
}
/* ====================================================================== /* ======================================================================
* A very simple elf loader, assumes the image is valid, returns the * A very simple elf loader, assumes the image is valid, returns the
* entry point address. * entry point address.
@ -293,7 +291,8 @@ static unsigned long load_elf_image_phdr(unsigned long addr)
if (phdr->p_filesz) if (phdr->p_filesz)
memcpy(dst, src, phdr->p_filesz); memcpy(dst, src, phdr->p_filesz);
if (phdr->p_filesz != phdr->p_memsz) if (phdr->p_filesz != phdr->p_memsz)
memset(dst + phdr->p_filesz, 0x00, phdr->p_memsz - phdr->p_filesz); memset(dst + phdr->p_filesz, 0x00,
phdr->p_memsz - phdr->p_filesz);
flush_cache((unsigned long)dst, phdr->p_filesz); flush_cache((unsigned long)dst, phdr->p_filesz);
++phdr; ++phdr;
} }