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