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