cmd_elf.c: Cleanup bootvx and handle new CONFIG_SYS_VXWORKS parameters

- fix size too small by one in sprintf
- changed old (pre 2004) device name ibmEmac to emac
- boot device may be overriden in board config
- servername may be defined in board config
- additional parameters may be defined in board config
- fixed some line wrappings
- replaced  redundant MAX define by max

Signed-off-by: Niklaus Giger <niklaus.giger@member.fsf.org>
This commit is contained in:
Niklaus Giger 2008-11-03 22:15:34 +01:00 committed by Wolfgang Denk
parent e9084b23d1
commit 29a4c24de9
1 changed files with 31 additions and 48 deletions

View File

@ -18,6 +18,7 @@
#include <linux/ctype.h> #include <linux/ctype.h>
#include <net.h> #include <net.h>
#include <elf.h> #include <elf.h>
#include <vxworks.h>
#if defined(CONFIG_WALNUT) || defined(CONFIG_SYS_VXWORKS_MAC_PTR) #if defined(CONFIG_WALNUT) || defined(CONFIG_SYS_VXWORKS_MAC_PTR)
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
@ -98,13 +99,10 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
unsigned long bootaddr; /* Address to put the bootline */ unsigned long bootaddr; /* Address to put the bootline */
char *bootline; /* Text of the bootline */ char *bootline; /* Text of the bootline */
char *tmp; /* Temporary char pointer */ char *tmp; /* Temporary char pointer */
char build_buf[128]; /* Buffer for building the bootline */
#if defined(CONFIG_4xx) || defined(CONFIG_IOP480) /* ---------------------------------------------------
char build_buf[80]; /* Buffer for building the bootline */ *
#endif
/* -------------------------------------------------- */
/*
* Check the loadaddr variable. * Check the loadaddr variable.
* If we don't know where the image is then we're done. * If we don't know where the image is then we're done.
*/ */
@ -120,7 +118,8 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
if ((argc == 2) && (strcmp (argv[1], "tftp") == 0)) { if ((argc == 2) && (strcmp (argv[1], "tftp") == 0)) {
if (NetLoop (TFTP) <= 0) if (NetLoop (TFTP) <= 0)
return 1; return 1;
printf ("Automatic boot of VxWorks image at address 0x%08lx ... \n", addr); printf ("Automatic boot of VxWorks image at address 0x%08lx ... \n",
addr);
} }
#endif #endif
@ -148,7 +147,7 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
*/ */
if ((tmp = getenv ("bootaddr")) == NULL) if ((tmp = getenv ("bootaddr")) == NULL)
bootaddr = 0x4200; bootaddr = CONFIG_SYS_VXWORKS_BOOT_ADDR;
else else
bootaddr = simple_strtoul (tmp, NULL, 16); bootaddr = simple_strtoul (tmp, NULL, 16);
@ -159,54 +158,40 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
*/ */
if ((bootline = getenv ("bootargs")) != NULL) { if ((bootline = getenv ("bootargs")) != NULL) {
memcpy ((void *) bootaddr, bootline, MAX(strlen(bootline), 255)); memcpy ((void *) bootaddr, bootline,
flush_cache (bootaddr, MAX(strlen(bootline), 255)); max (strlen (bootline), 255));
flush_cache (bootaddr, max (strlen (bootline), 255));
} else { } else {
#if defined(CONFIG_4xx)
sprintf (build_buf, "ibmEmac(0,0)");
if ((tmp = getenv ("hostname")) != NULL) {
sprintf (&build_buf[strlen (build_buf - 1)], sprintf (build_buf, CONFIG_SYS_VXWORKS_BOOT_DEVICE);
"host:%s ", tmp); if ((tmp = getenv ("bootfile")) != NULL) {
sprintf (&build_buf[strlen (build_buf)],
"%s:%s ", CONFIG_SYS_VXWORKS_SERVERNAME, tmp);
} else { } else {
sprintf (&build_buf[strlen (build_buf - 1)], sprintf (&build_buf[strlen (build_buf)],
": "); "%s:file ", CONFIG_SYS_VXWORKS_SERVERNAME);
} }
if ((tmp = getenv ("ipaddr")) != NULL) { if ((tmp = getenv ("ipaddr")) != NULL) {
sprintf (&build_buf[strlen (build_buf - 1)], sprintf (&build_buf[strlen (build_buf)], "e=%s ", tmp);
"e=%s ", tmp); }
if ((tmp = getenv ("serverip")) != NULL) {
sprintf (&build_buf[strlen (build_buf)], "h=%s ", tmp);
} }
memcpy ((void *)bootaddr, build_buf, MAX(strlen(build_buf), 255));
flush_cache (bootaddr, MAX(strlen(build_buf), 255));
#elif defined(CONFIG_IOP480)
sprintf (build_buf, "dc(0,0)");
if ((tmp = getenv ("hostname")) != NULL) { if ((tmp = getenv ("hostname")) != NULL) {
sprintf (&build_buf[strlen (build_buf - 1)], sprintf (&build_buf[strlen (build_buf)], "tn=%s ", tmp);
"host:%s ", tmp);
} else {
sprintf (&build_buf[strlen (build_buf - 1)],
": ");
} }
#ifdef CONFIG_SYS_VXWORKS_ADD_PARAMS
if ((tmp = getenv ("ipaddr")) != NULL) { sprintf (&build_buf[strlen (build_buf)],
sprintf (&build_buf[strlen (build_buf - 1)], CONFIG_SYS_VXWORKS_ADD_PARAMS);
"e=%s ", tmp);
}
memcpy ((void *) bootaddr, build_buf, MAX(strlen(build_buf), 255));
flush_cache (bootaddr, MAX(strlen(build_buf), 255));
#else
/*
* I'm not sure what the device should be for other
* PPC flavors, the hostname and ipaddr should be ok
* to just copy
*/
puts ("No bootargs defined\n");
return 1;
#endif #endif
memcpy ((void *) bootaddr, build_buf,
max (strlen (build_buf), 255));
flush_cache (bootaddr, max (strlen (build_buf), 255));
} }
/* /*
@ -251,8 +236,7 @@ int valid_elf_image (unsigned long addr)
} }
if (ehdr->e_type != ET_EXEC) { if (ehdr->e_type != ET_EXEC) {
printf ("## Not a 32-bit elf image at address 0x%08lx\n", printf ("## Not a 32-bit elf image at address 0x%08lx\n", addr);
addr);
return 0; return 0;
} }
@ -267,7 +251,6 @@ int valid_elf_image (unsigned long addr)
return 1; 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.