wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2001 William L. Pitts |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms are freely |
| 6 | * permitted provided that the above copyright notice and this |
| 7 | * paragraph and the following disclaimer are duplicated in all |
| 8 | * such forms. |
| 9 | * |
| 10 | * This software is provided "AS IS" and without any express or |
| 11 | * implied warranties, including, without limitation, the implied |
| 12 | * warranties of merchantability and fitness for a particular |
| 13 | * purpose. |
| 14 | */ |
| 15 | |
| 16 | #include <common.h> |
| 17 | #include <command.h> |
| 18 | #include <linux/ctype.h> |
| 19 | #include <net.h> |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 20 | #include <elf.h> |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 21 | #include <vxworks.h> |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 22 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | #if defined(CONFIG_WALNUT) || defined(CONFIG_SYS_VXWORKS_MAC_PTR) |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | #endif |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 26 | |
Mike Frysinger | 017e9b7 | 2008-04-13 19:42:18 -0400 | [diff] [blame] | 27 | int valid_elf_image (unsigned long addr); |
Mike Frysinger | f44a928 | 2010-10-02 15:44:53 -0400 | [diff] [blame] | 28 | static unsigned long load_elf_image_phdr(unsigned long addr); |
| 29 | static unsigned long load_elf_image_shdr(unsigned long addr); |
Mike Frysinger | 017e9b7 | 2008-04-13 19:42:18 -0400 | [diff] [blame] | 30 | |
| 31 | /* Allow ports to override the default behavior */ |
| 32 | __attribute__((weak)) |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 33 | unsigned long do_bootelf_exec (ulong (*entry)(int, char * const[]), |
| 34 | int argc, char * const argv[]) |
Mike Frysinger | 1f1d88d | 2008-01-29 18:21:05 -0500 | [diff] [blame] | 35 | { |
Mike Frysinger | 017e9b7 | 2008-04-13 19:42:18 -0400 | [diff] [blame] | 36 | unsigned long ret; |
| 37 | |
Mike Frysinger | 1f1d88d | 2008-01-29 18:21:05 -0500 | [diff] [blame] | 38 | /* |
| 39 | * QNX images require the data cache is disabled. |
| 40 | * Data cache is already flushed, so just turn it off. |
| 41 | */ |
Mike Frysinger | 017e9b7 | 2008-04-13 19:42:18 -0400 | [diff] [blame] | 42 | int dcache = dcache_status (); |
| 43 | if (dcache) |
Mike Frysinger | 1f1d88d | 2008-01-29 18:21:05 -0500 | [diff] [blame] | 44 | dcache_disable (); |
| 45 | |
Mike Frysinger | 017e9b7 | 2008-04-13 19:42:18 -0400 | [diff] [blame] | 46 | /* |
| 47 | * pass address parameter as argv[0] (aka command name), |
| 48 | * and all remaining args |
| 49 | */ |
| 50 | ret = entry (argc, argv); |
Mike Frysinger | 1f1d88d | 2008-01-29 18:21:05 -0500 | [diff] [blame] | 51 | |
Mike Frysinger | 017e9b7 | 2008-04-13 19:42:18 -0400 | [diff] [blame] | 52 | if (dcache) |
| 53 | dcache_enable (); |
| 54 | |
| 55 | return ret; |
| 56 | } |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 57 | |
| 58 | /* ====================================================================== |
| 59 | * Interpreter command to boot an arbitrary ELF image from memory. |
| 60 | * ====================================================================== */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 61 | int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 62 | { |
| 63 | unsigned long addr; /* Address of the ELF image */ |
| 64 | unsigned long rc; /* Return value from user code */ |
Mike Frysinger | f44a928 | 2010-10-02 15:44:53 -0400 | [diff] [blame] | 65 | char *sload, *saddr; |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 66 | |
| 67 | /* -------------------------------------------------- */ |
| 68 | int rcode = 0; |
| 69 | |
Mike Frysinger | f44a928 | 2010-10-02 15:44:53 -0400 | [diff] [blame] | 70 | sload = saddr = NULL; |
| 71 | if (argc == 3) { |
| 72 | sload = argv[1]; |
| 73 | saddr = argv[2]; |
| 74 | } else if (argc == 2) { |
| 75 | if (argv[1][0] == '-') |
| 76 | sload = argv[1]; |
| 77 | else |
| 78 | saddr = argv[1]; |
| 79 | } |
| 80 | |
| 81 | if (saddr) |
| 82 | addr = simple_strtoul(saddr, NULL, 16); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 83 | else |
Mike Frysinger | f44a928 | 2010-10-02 15:44:53 -0400 | [diff] [blame] | 84 | addr = load_addr; |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 85 | |
| 86 | if (!valid_elf_image (addr)) |
| 87 | return 1; |
| 88 | |
Mike Frysinger | f44a928 | 2010-10-02 15:44:53 -0400 | [diff] [blame] | 89 | if (sload && sload[1] == 'p') |
| 90 | addr = load_elf_image_phdr(addr); |
| 91 | else |
| 92 | addr = load_elf_image_shdr(addr); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 93 | |
| 94 | printf ("## Starting application at 0x%08lx ...\n", addr); |
| 95 | |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 96 | /* |
| 97 | * pass address parameter as argv[0] (aka command name), |
| 98 | * and all remaining args |
| 99 | */ |
Mike Frysinger | 017e9b7 | 2008-04-13 19:42:18 -0400 | [diff] [blame] | 100 | rc = do_bootelf_exec ((void *)addr, argc - 1, argv + 1); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 101 | if (rc != 0) |
| 102 | rcode = 1; |
| 103 | |
| 104 | printf ("## Application terminated, rc = 0x%lx\n", rc); |
| 105 | return rcode; |
| 106 | } |
| 107 | |
| 108 | /* ====================================================================== |
| 109 | * Interpreter command to boot VxWorks from a memory image. The image can |
| 110 | * be either an ELF image or a raw binary. Will attempt to setup the |
| 111 | * bootline and other parameters correctly. |
| 112 | * ====================================================================== */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 113 | int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 114 | { |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 115 | unsigned long addr; /* Address of image */ |
| 116 | unsigned long bootaddr; /* Address to put the bootline */ |
| 117 | char *bootline; /* Text of the bootline */ |
| 118 | char *tmp; /* Temporary char pointer */ |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 119 | char build_buf[128]; /* Buffer for building the bootline */ |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 120 | |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 121 | /* --------------------------------------------------- |
| 122 | * |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 123 | * Check the loadaddr variable. |
| 124 | * If we don't know where the image is then we're done. |
| 125 | */ |
| 126 | |
Stefan Roese | 1bdd468 | 2006-11-29 12:53:15 +0100 | [diff] [blame] | 127 | if (argc < 2) |
| 128 | addr = load_addr; |
| 129 | else |
| 130 | addr = simple_strtoul (argv[1], NULL, 16); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 131 | |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 132 | #if defined(CONFIG_CMD_NET) |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 133 | /* Check to see if we need to tftp the image ourselves before starting */ |
| 134 | |
| 135 | if ((argc == 2) && (strcmp (argv[1], "tftp") == 0)) { |
wdenk | eb9401e | 2002-11-11 02:11:37 +0000 | [diff] [blame] | 136 | if (NetLoop (TFTP) <= 0) |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 137 | return 1; |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 138 | printf ("Automatic boot of VxWorks image at address 0x%08lx ... \n", |
| 139 | addr); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 140 | } |
| 141 | #endif |
| 142 | |
| 143 | /* This should equate |
| 144 | * to NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET |
| 145 | * from the VxWorks BSP header files. |
| 146 | * This will vary from board to board |
| 147 | */ |
| 148 | |
Stefan Roese | c157d8e | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 149 | #if defined(CONFIG_WALNUT) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 150 | tmp = (char *) CONFIG_SYS_NVRAM_BASE_ADDR + 0x500; |
Heiko Schocher | 76756e4 | 2009-03-26 07:33:59 +0100 | [diff] [blame] | 151 | eth_getenv_enetaddr("ethaddr", (uchar *)build_buf); |
Mike Frysinger | 62c93d9 | 2009-02-11 18:51:43 -0500 | [diff] [blame] | 152 | memcpy(tmp, &build_buf[3], 3); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 153 | #elif defined(CONFIG_SYS_VXWORKS_MAC_PTR) |
| 154 | tmp = (char *) CONFIG_SYS_VXWORKS_MAC_PTR; |
Heiko Schocher | 76756e4 | 2009-03-26 07:33:59 +0100 | [diff] [blame] | 155 | eth_getenv_enetaddr("ethaddr", (uchar *)build_buf); |
Mike Frysinger | 62c93d9 | 2009-02-11 18:51:43 -0500 | [diff] [blame] | 156 | memcpy(tmp, build_buf, 6); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 157 | #else |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 158 | puts ("## Ethernet MAC address not copied to NV RAM\n"); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 159 | #endif |
| 160 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 161 | /* |
| 162 | * Use bootaddr to find the location in memory that VxWorks |
| 163 | * will look for the bootline string. The default value for |
| 164 | * PowerPC is LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET which |
| 165 | * defaults to 0x4200 |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 166 | */ |
| 167 | |
| 168 | if ((tmp = getenv ("bootaddr")) == NULL) |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 169 | bootaddr = CONFIG_SYS_VXWORKS_BOOT_ADDR; |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 170 | else |
| 171 | bootaddr = simple_strtoul (tmp, NULL, 16); |
| 172 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 173 | /* |
| 174 | * Check to see if the bootline is defined in the 'bootargs' |
| 175 | * parameter. If it is not defined, we may be able to |
| 176 | * construct the info |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 177 | */ |
| 178 | |
| 179 | if ((bootline = getenv ("bootargs")) != NULL) { |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 180 | memcpy ((void *) bootaddr, bootline, |
| 181 | max (strlen (bootline), 255)); |
| 182 | flush_cache (bootaddr, max (strlen (bootline), 255)); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 183 | } else { |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 184 | |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 185 | |
| 186 | sprintf (build_buf, CONFIG_SYS_VXWORKS_BOOT_DEVICE); |
| 187 | if ((tmp = getenv ("bootfile")) != NULL) { |
| 188 | sprintf (&build_buf[strlen (build_buf)], |
| 189 | "%s:%s ", CONFIG_SYS_VXWORKS_SERVERNAME, tmp); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 190 | } else { |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 191 | sprintf (&build_buf[strlen (build_buf)], |
| 192 | "%s:file ", CONFIG_SYS_VXWORKS_SERVERNAME); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | if ((tmp = getenv ("ipaddr")) != NULL) { |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 196 | sprintf (&build_buf[strlen (build_buf)], "e=%s ", tmp); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 197 | } |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 198 | |
| 199 | if ((tmp = getenv ("serverip")) != NULL) { |
| 200 | sprintf (&build_buf[strlen (build_buf)], "h=%s ", tmp); |
| 201 | } |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 202 | |
| 203 | if ((tmp = getenv ("hostname")) != NULL) { |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 204 | sprintf (&build_buf[strlen (build_buf)], "tn=%s ", tmp); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 205 | } |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 206 | #ifdef CONFIG_SYS_VXWORKS_ADD_PARAMS |
| 207 | sprintf (&build_buf[strlen (build_buf)], |
| 208 | CONFIG_SYS_VXWORKS_ADD_PARAMS); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 209 | #endif |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 210 | |
| 211 | memcpy ((void *) bootaddr, build_buf, |
| 212 | max (strlen (build_buf), 255)); |
| 213 | flush_cache (bootaddr, max (strlen (build_buf), 255)); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 214 | } |
| 215 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 216 | /* |
| 217 | * If the data at the load address is an elf image, then |
| 218 | * treat it like an elf image. Otherwise, assume that it is a |
| 219 | * binary image |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 220 | */ |
| 221 | |
| 222 | if (valid_elf_image (addr)) { |
Mike Frysinger | f44a928 | 2010-10-02 15:44:53 -0400 | [diff] [blame] | 223 | addr = load_elf_image_shdr (addr); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 224 | } else { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 225 | puts ("## Not an ELF image, assuming binary\n"); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 226 | /* leave addr as load_addr */ |
| 227 | } |
| 228 | |
| 229 | printf ("## Using bootline (@ 0x%lx): %s\n", bootaddr, |
| 230 | (char *) bootaddr); |
| 231 | printf ("## Starting vxWorks at 0x%08lx ...\n", addr); |
| 232 | |
| 233 | ((void (*)(void)) addr) (); |
| 234 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 235 | puts ("## vxWorks terminated\n"); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 236 | return 1; |
| 237 | } |
| 238 | |
| 239 | /* ====================================================================== |
| 240 | * Determine if a valid ELF image exists at the given memory location. |
| 241 | * First looks at the ELF header magic field, the makes sure that it is |
| 242 | * executable and makes sure that it is for a PowerPC. |
| 243 | * ====================================================================== */ |
| 244 | int valid_elf_image (unsigned long addr) |
| 245 | { |
| 246 | Elf32_Ehdr *ehdr; /* Elf header structure pointer */ |
| 247 | |
| 248 | /* -------------------------------------------------- */ |
| 249 | |
| 250 | ehdr = (Elf32_Ehdr *) addr; |
| 251 | |
| 252 | if (!IS_ELF (*ehdr)) { |
| 253 | printf ("## No elf image at address 0x%08lx\n", addr); |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | if (ehdr->e_type != ET_EXEC) { |
Niklaus Giger | 29a4c24 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 258 | printf ("## Not a 32-bit elf image at address 0x%08lx\n", addr); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 259 | return 0; |
| 260 | } |
| 261 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 262 | #if 0 |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 263 | if (ehdr->e_machine != EM_PPC) { |
| 264 | printf ("## Not a PowerPC elf image at address 0x%08lx\n", |
| 265 | addr); |
| 266 | return 0; |
| 267 | } |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 268 | #endif |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 269 | |
| 270 | return 1; |
| 271 | } |
| 272 | |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 273 | /* ====================================================================== |
| 274 | * A very simple elf loader, assumes the image is valid, returns the |
| 275 | * entry point address. |
| 276 | * ====================================================================== */ |
Mike Frysinger | f44a928 | 2010-10-02 15:44:53 -0400 | [diff] [blame] | 277 | static unsigned long load_elf_image_phdr(unsigned long addr) |
| 278 | { |
| 279 | Elf32_Ehdr *ehdr; /* Elf header structure pointer */ |
| 280 | Elf32_Phdr *phdr; /* Program header structure pointer */ |
| 281 | int i; |
| 282 | |
| 283 | ehdr = (Elf32_Ehdr *) addr; |
| 284 | phdr = (Elf32_Phdr *) (addr + ehdr->e_phoff); |
| 285 | |
| 286 | /* Load each program header */ |
| 287 | for (i = 0; i < ehdr->e_phnum; ++i) { |
| 288 | void *dst = (void *) phdr->p_paddr; |
| 289 | void *src = (void *) addr + phdr->p_offset; |
| 290 | debug("Loading phdr %i to 0x%p (%i bytes)\n", |
| 291 | i, dst, phdr->p_filesz); |
| 292 | if (phdr->p_filesz) |
| 293 | memcpy(dst, src, phdr->p_filesz); |
| 294 | if (phdr->p_filesz != phdr->p_memsz) |
| 295 | memset(dst + phdr->p_filesz, 0x00, phdr->p_memsz - phdr->p_filesz); |
| 296 | flush_cache((unsigned long)dst, phdr->p_filesz); |
| 297 | ++phdr; |
| 298 | } |
| 299 | |
| 300 | return ehdr->e_entry; |
| 301 | } |
| 302 | |
| 303 | static unsigned long load_elf_image_shdr(unsigned long addr) |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 304 | { |
| 305 | Elf32_Ehdr *ehdr; /* Elf header structure pointer */ |
| 306 | Elf32_Shdr *shdr; /* Section header structure pointer */ |
| 307 | unsigned char *strtab = 0; /* String table pointer */ |
| 308 | unsigned char *image; /* Binary image pointer */ |
| 309 | int i; /* Loop counter */ |
| 310 | |
| 311 | /* -------------------------------------------------- */ |
| 312 | |
| 313 | ehdr = (Elf32_Ehdr *) addr; |
| 314 | |
| 315 | /* Find the section header string table for output info */ |
| 316 | shdr = (Elf32_Shdr *) (addr + ehdr->e_shoff + |
| 317 | (ehdr->e_shstrndx * sizeof (Elf32_Shdr))); |
| 318 | |
| 319 | if (shdr->sh_type == SHT_STRTAB) |
| 320 | strtab = (unsigned char *) (addr + shdr->sh_offset); |
| 321 | |
| 322 | /* Load each appropriate section */ |
| 323 | for (i = 0; i < ehdr->e_shnum; ++i) { |
| 324 | shdr = (Elf32_Shdr *) (addr + ehdr->e_shoff + |
| 325 | (i * sizeof (Elf32_Shdr))); |
| 326 | |
| 327 | if (!(shdr->sh_flags & SHF_ALLOC) |
| 328 | || shdr->sh_addr == 0 || shdr->sh_size == 0) { |
| 329 | continue; |
| 330 | } |
| 331 | |
| 332 | if (strtab) { |
Niklaus Giger | 3c97284 | 2009-07-23 23:31:58 +0200 | [diff] [blame] | 333 | debug("%sing %s @ 0x%08lx (%ld bytes)\n", |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 334 | (shdr->sh_type == SHT_NOBITS) ? |
| 335 | "Clear" : "Load", |
| 336 | &strtab[shdr->sh_name], |
| 337 | (unsigned long) shdr->sh_addr, |
| 338 | (long) shdr->sh_size); |
| 339 | } |
| 340 | |
| 341 | if (shdr->sh_type == SHT_NOBITS) { |
| 342 | memset ((void *)shdr->sh_addr, 0, shdr->sh_size); |
| 343 | } else { |
| 344 | image = (unsigned char *) addr + shdr->sh_offset; |
| 345 | memcpy ((void *) shdr->sh_addr, |
| 346 | (const void *) image, |
| 347 | shdr->sh_size); |
| 348 | } |
| 349 | flush_cache (shdr->sh_addr, shdr->sh_size); |
| 350 | } |
| 351 | |
| 352 | return ehdr->e_entry; |
| 353 | } |
| 354 | |
| 355 | /* ====================================================================== */ |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 356 | U_BOOT_CMD( |
Mike Frysinger | f44a928 | 2010-10-02 15:44:53 -0400 | [diff] [blame] | 357 | bootelf, 3, 0, do_bootelf, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 358 | "Boot from an ELF image in memory", |
Mike Frysinger | f44a928 | 2010-10-02 15:44:53 -0400 | [diff] [blame] | 359 | "[-p|-s] [address]\n" |
| 360 | "\t- load ELF image at [address] via program headers (-p)\n" |
| 361 | "\t or via section headers (-s)" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 362 | ); |
| 363 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 364 | U_BOOT_CMD( |
| 365 | bootvx, 2, 0, do_bootvx, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 366 | "Boot vxWorks from an ELF image", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 367 | " [address] - load address of vxWorks ELF image." |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 368 | ); |