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