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