blob: 22cba58c68c07426988f5557bc8e21569d7d7858 [file] [log] [blame]
wdenk458ded32002-09-20 10:59:08 +00001/*
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>
wdenk458ded32002-09-20 10:59:08 +000018#include <elf.h>
Alex Kiernan9c215492018-04-01 09:22:38 +000019#include <environment.h>
Bin Meng53f3afb2015-10-07 20:19:13 -070020#include <net.h>
Niklaus Gigerf662b232008-11-03 22:15:34 +010021#include <vxworks.h>
Bin Meng321e8602015-10-07 20:19:18 -070022#ifdef CONFIG_X86
Bin Meng71606c42018-04-11 22:02:19 -070023#include <vbe.h>
Bin Meng321e8602015-10-07 20:19:18 -070024#include <asm/e820.h>
Bin Mengf6900e22015-10-07 20:19:19 -070025#include <linux/linkage.h>
Bin Meng321e8602015-10-07 20:19:18 -070026#endif
wdenk458ded32002-09-20 10:59:08 +000027
Bin Meng8c77af62015-10-07 20:19:14 -070028/*
Bin Mengc71073f2018-04-11 22:02:14 -070029 * A very simple ELF64 loader, assumes the image is valid, returns the
Bin Meng8c77af62015-10-07 20:19:14 -070030 * entry point address.
Bin Mengc71073f2018-04-11 22:02:14 -070031 *
32 * Note if U-Boot is 32-bit, the loader assumes the to segment's
33 * physical address and size is within the lower 32-bit address space.
34 */
35static unsigned long load_elf64_image_phdr(unsigned long addr)
36{
37 Elf64_Ehdr *ehdr; /* Elf header structure pointer */
38 Elf64_Phdr *phdr; /* Program header structure pointer */
39 int i;
40
41 ehdr = (Elf64_Ehdr *)addr;
42 phdr = (Elf64_Phdr *)(addr + (ulong)ehdr->e_phoff);
43
44 /* Load each program header */
45 for (i = 0; i < ehdr->e_phnum; ++i) {
46 void *dst = (void *)(ulong)phdr->p_paddr;
47 void *src = (void *)addr + phdr->p_offset;
48
49 debug("Loading phdr %i to 0x%p (%lu bytes)\n",
50 i, dst, (ulong)phdr->p_filesz);
51 if (phdr->p_filesz)
52 memcpy(dst, src, phdr->p_filesz);
53 if (phdr->p_filesz != phdr->p_memsz)
54 memset(dst + phdr->p_filesz, 0x00,
55 phdr->p_memsz - phdr->p_filesz);
56 flush_cache((unsigned long)dst, phdr->p_filesz);
57 ++phdr;
58 }
59
Rob Bracero7c8b3252018-07-31 22:57:42 -040060 if (ehdr->e_machine == EM_PPC64 && (ehdr->e_flags &
61 EF_PPC64_ELFV1_ABI)) {
62 /*
63 * For the 64-bit PowerPC ELF V1 ABI, e_entry is a function
64 * descriptor pointer with the first double word being the
65 * address of the entry point of the function.
66 */
67 uintptr_t addr = ehdr->e_entry;
68
69 return *(Elf64_Addr *)addr;
70 }
71
Bin Mengc71073f2018-04-11 22:02:14 -070072 return ehdr->e_entry;
73}
74
Rob Bracero7c8b3252018-07-31 22:57:42 -040075static unsigned long load_elf64_image_shdr(unsigned long addr)
76{
77 Elf64_Ehdr *ehdr; /* Elf header structure pointer */
78 Elf64_Shdr *shdr; /* Section header structure pointer */
79 unsigned char *strtab = 0; /* String table pointer */
80 unsigned char *image; /* Binary image pointer */
81 int i; /* Loop counter */
82
83 ehdr = (Elf64_Ehdr *)addr;
84
85 /* Find the section header string table for output info */
86 shdr = (Elf64_Shdr *)(addr + (ulong)ehdr->e_shoff +
87 (ehdr->e_shstrndx * sizeof(Elf64_Shdr)));
88
89 if (shdr->sh_type == SHT_STRTAB)
90 strtab = (unsigned char *)(addr + (ulong)shdr->sh_offset);
91
92 /* Load each appropriate section */
93 for (i = 0; i < ehdr->e_shnum; ++i) {
94 shdr = (Elf64_Shdr *)(addr + (ulong)ehdr->e_shoff +
95 (i * sizeof(Elf64_Shdr)));
96
97 if (!(shdr->sh_flags & SHF_ALLOC) ||
98 shdr->sh_addr == 0 || shdr->sh_size == 0) {
99 continue;
100 }
101
102 if (strtab) {
103 debug("%sing %s @ 0x%08lx (%ld bytes)\n",
104 (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
105 &strtab[shdr->sh_name],
106 (unsigned long)shdr->sh_addr,
107 (long)shdr->sh_size);
108 }
109
110 if (shdr->sh_type == SHT_NOBITS) {
111 memset((void *)(uintptr_t)shdr->sh_addr, 0,
112 shdr->sh_size);
113 } else {
114 image = (unsigned char *)addr + (ulong)shdr->sh_offset;
115 memcpy((void *)(uintptr_t)shdr->sh_addr,
116 (const void *)image, shdr->sh_size);
117 }
118 flush_cache((ulong)shdr->sh_addr, shdr->sh_size);
119 }
120
121 if (ehdr->e_machine == EM_PPC64 && (ehdr->e_flags &
122 EF_PPC64_ELFV1_ABI)) {
123 /*
124 * For the 64-bit PowerPC ELF V1 ABI, e_entry is a function
125 * descriptor pointer with the first double word being the
126 * address of the entry point of the function.
127 */
128 uintptr_t addr = ehdr->e_entry;
129
130 return *(Elf64_Addr *)addr;
131 }
132
133 return ehdr->e_entry;
134}
135
Bin Mengc71073f2018-04-11 22:02:14 -0700136/*
137 * A very simple ELF loader, assumes the image is valid, returns the
138 * entry point address.
139 *
140 * The loader firstly reads the EFI class to see if it's a 64-bit image.
141 * If yes, call the ELF64 loader. Otherwise continue with the ELF32 loader.
Bin Meng8c77af62015-10-07 20:19:14 -0700142 */
143static unsigned long load_elf_image_phdr(unsigned long addr)
144{
145 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
146 Elf32_Phdr *phdr; /* Program header structure pointer */
147 int i;
148
149 ehdr = (Elf32_Ehdr *)addr;
Bin Mengc71073f2018-04-11 22:02:14 -0700150 if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
151 return load_elf64_image_phdr(addr);
152
Bin Meng8c77af62015-10-07 20:19:14 -0700153 phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff);
154
155 /* Load each program header */
156 for (i = 0; i < ehdr->e_phnum; ++i) {
157 void *dst = (void *)(uintptr_t)phdr->p_paddr;
158 void *src = (void *)addr + phdr->p_offset;
Bin Mengc71073f2018-04-11 22:02:14 -0700159
Bin Meng8c77af62015-10-07 20:19:14 -0700160 debug("Loading phdr %i to 0x%p (%i bytes)\n",
161 i, dst, phdr->p_filesz);
162 if (phdr->p_filesz)
163 memcpy(dst, src, phdr->p_filesz);
164 if (phdr->p_filesz != phdr->p_memsz)
165 memset(dst + phdr->p_filesz, 0x00,
166 phdr->p_memsz - phdr->p_filesz);
167 flush_cache((unsigned long)dst, phdr->p_filesz);
168 ++phdr;
169 }
170
171 return ehdr->e_entry;
172}
173
174static unsigned long load_elf_image_shdr(unsigned long addr)
175{
176 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
177 Elf32_Shdr *shdr; /* Section header structure pointer */
178 unsigned char *strtab = 0; /* String table pointer */
179 unsigned char *image; /* Binary image pointer */
180 int i; /* Loop counter */
181
182 ehdr = (Elf32_Ehdr *)addr;
Rob Bracero7c8b3252018-07-31 22:57:42 -0400183 if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
184 return load_elf64_image_shdr(addr);
Bin Meng8c77af62015-10-07 20:19:14 -0700185
186 /* Find the section header string table for output info */
187 shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
188 (ehdr->e_shstrndx * sizeof(Elf32_Shdr)));
189
190 if (shdr->sh_type == SHT_STRTAB)
191 strtab = (unsigned char *)(addr + shdr->sh_offset);
192
193 /* Load each appropriate section */
194 for (i = 0; i < ehdr->e_shnum; ++i) {
195 shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
196 (i * sizeof(Elf32_Shdr)));
197
198 if (!(shdr->sh_flags & SHF_ALLOC) ||
199 shdr->sh_addr == 0 || shdr->sh_size == 0) {
200 continue;
201 }
202
203 if (strtab) {
204 debug("%sing %s @ 0x%08lx (%ld bytes)\n",
205 (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
206 &strtab[shdr->sh_name],
207 (unsigned long)shdr->sh_addr,
208 (long)shdr->sh_size);
209 }
210
211 if (shdr->sh_type == SHT_NOBITS) {
212 memset((void *)(uintptr_t)shdr->sh_addr, 0,
213 shdr->sh_size);
214 } else {
215 image = (unsigned char *)addr + shdr->sh_offset;
216 memcpy((void *)(uintptr_t)shdr->sh_addr,
217 (const void *)image, shdr->sh_size);
218 }
219 flush_cache(shdr->sh_addr, shdr->sh_size);
220 }
221
222 return ehdr->e_entry;
223}
Mike Frysingere60644a2008-04-13 19:42:18 -0400224
225/* Allow ports to override the default behavior */
Jeroen Hofstee3cc2a742014-10-08 22:57:31 +0200226static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
Bin Meng53f3afb2015-10-07 20:19:13 -0700227 int argc, char * const argv[])
Mike Frysingerf79507e2008-01-29 18:21:05 -0500228{
Mike Frysingere60644a2008-04-13 19:42:18 -0400229 unsigned long ret;
230
Mike Frysingerf79507e2008-01-29 18:21:05 -0500231 /*
Mike Frysingere60644a2008-04-13 19:42:18 -0400232 * pass address parameter as argv[0] (aka command name),
233 * and all remaining args
234 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000235 ret = entry(argc, argv);
Mike Frysingerf79507e2008-01-29 18:21:05 -0500236
Mike Frysingere60644a2008-04-13 19:42:18 -0400237 return ret;
238}
wdenk458ded32002-09-20 10:59:08 +0000239
Bin Meng53f3afb2015-10-07 20:19:13 -0700240/*
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000241 * Determine if a valid ELF image exists at the given memory location.
Bin Meng53f3afb2015-10-07 20:19:13 -0700242 * First look at the ELF header magic field, then make sure that it is
243 * executable.
244 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000245int valid_elf_image(unsigned long addr)
246{
Bin Meng53f3afb2015-10-07 20:19:13 -0700247 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000248
Bin Meng53f3afb2015-10-07 20:19:13 -0700249 ehdr = (Elf32_Ehdr *)addr;
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000250
251 if (!IS_ELF(*ehdr)) {
252 printf("## No elf image at address 0x%08lx\n", addr);
253 return 0;
254 }
255
256 if (ehdr->e_type != ET_EXEC) {
257 printf("## Not a 32-bit elf image at address 0x%08lx\n", addr);
258 return 0;
259 }
260
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000261 return 1;
262}
263
Bin Meng53f3afb2015-10-07 20:19:13 -0700264/* Interpreter command to boot an arbitrary ELF image from memory */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000265int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk458ded32002-09-20 10:59:08 +0000266{
Bin Meng53f3afb2015-10-07 20:19:13 -0700267 unsigned long addr; /* Address of the ELF image */
268 unsigned long rc; /* Return value from user code */
Tom Rini3c95c792017-05-18 17:03:07 -0400269 char *sload = NULL;
Simon Glass64b723f2017-08-03 12:22:12 -0600270 const char *ep = env_get("autostart");
wdenk458ded32002-09-20 10:59:08 +0000271 int rcode = 0;
272
Tom Rini3c95c792017-05-18 17:03:07 -0400273 /* Consume 'bootelf' */
274 argc--; argv++;
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400275
Tom Rini3c95c792017-05-18 17:03:07 -0400276 /* Check for flag. */
277 if (argc >= 1 && (argv[0][0] == '-' && \
278 (argv[0][1] == 'p' || argv[0][1] == 's'))) {
279 sload = argv[0];
280 /* Consume flag. */
281 argc--; argv++;
282 }
283 /* Check for address. */
284 if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) {
285 /* Consume address */
286 argc--; argv++;
287 } else
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400288 addr = load_addr;
wdenk458ded32002-09-20 10:59:08 +0000289
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000290 if (!valid_elf_image(addr))
wdenk458ded32002-09-20 10:59:08 +0000291 return 1;
292
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400293 if (sload && sload[1] == 'p')
294 addr = load_elf_image_phdr(addr);
295 else
296 addr = load_elf_image_shdr(addr);
wdenk458ded32002-09-20 10:59:08 +0000297
Siva Durga Prasad Paladugu3825bfa2015-03-09 12:46:47 +0100298 if (ep && !strcmp(ep, "no"))
299 return rcode;
300
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000301 printf("## Starting application at 0x%08lx ...\n", addr);
wdenk458ded32002-09-20 10:59:08 +0000302
wdenk458ded32002-09-20 10:59:08 +0000303 /*
304 * pass address parameter as argv[0] (aka command name),
305 * and all remaining args
306 */
Tom Rini3c95c792017-05-18 17:03:07 -0400307 rc = do_bootelf_exec((void *)addr, argc, argv);
wdenk458ded32002-09-20 10:59:08 +0000308 if (rc != 0)
309 rcode = 1;
310
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000311 printf("## Application terminated, rc = 0x%lx\n", rc);
Bin Meng53f3afb2015-10-07 20:19:13 -0700312
wdenk458ded32002-09-20 10:59:08 +0000313 return rcode;
314}
315
Bin Meng53f3afb2015-10-07 20:19:13 -0700316/*
wdenk458ded32002-09-20 10:59:08 +0000317 * Interpreter command to boot VxWorks from a memory image. The image can
318 * be either an ELF image or a raw binary. Will attempt to setup the
319 * bootline and other parameters correctly.
Bin Meng53f3afb2015-10-07 20:19:13 -0700320 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000321int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk458ded32002-09-20 10:59:08 +0000322{
Bin Meng53f3afb2015-10-07 20:19:13 -0700323 unsigned long addr; /* Address of image */
Bin Meng75f4b722018-04-11 22:02:22 -0700324 unsigned long bootaddr = 0; /* Address to put the bootline */
Bin Meng53f3afb2015-10-07 20:19:13 -0700325 char *bootline; /* Text of the bootline */
326 char *tmp; /* Temporary char pointer */
327 char build_buf[128]; /* Buffer for building the bootline */
Bin Meng0401c862015-10-07 20:19:15 -0700328 int ptr = 0;
Bin Meng321e8602015-10-07 20:19:18 -0700329#ifdef CONFIG_X86
Bin Menge3be8902018-04-11 22:02:07 -0700330 ulong base;
Bin Mengdde4ebb2018-04-11 22:02:09 -0700331 struct e820_info *info;
Bin Meng4b8fc742018-04-11 22:02:11 -0700332 struct e820_entry *data;
Bin Meng71606c42018-04-11 22:02:19 -0700333 struct efi_gop_info *gop;
334 struct vesa_mode_info *vesa = &mode_info.vesa;
Bin Meng321e8602015-10-07 20:19:18 -0700335#endif
wdenk458ded32002-09-20 10:59:08 +0000336
Bin Meng53f3afb2015-10-07 20:19:13 -0700337 /*
wdenk458ded32002-09-20 10:59:08 +0000338 * Check the loadaddr variable.
339 * If we don't know where the image is then we're done.
340 */
Stany MARCELe5deaf582013-11-27 14:48:43 +0100341 if (argc < 2)
Stefan Roese00487782006-11-29 12:53:15 +0100342 addr = load_addr;
343 else
Stany MARCELe5deaf582013-11-27 14:48:43 +0100344 addr = simple_strtoul(argv[1], NULL, 16);
wdenk458ded32002-09-20 10:59:08 +0000345
Jon Loeliger54324d02007-07-08 17:51:39 -0500346#if defined(CONFIG_CMD_NET)
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000347 /*
Bin Meng53f3afb2015-10-07 20:19:13 -0700348 * Check to see if we need to tftp the image ourselves
349 * before starting
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000350 */
Stany MARCELe5deaf582013-11-27 14:48:43 +0100351 if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500352 if (net_loop(TFTPGET) <= 0)
wdenk458ded32002-09-20 10:59:08 +0000353 return 1;
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000354 printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
355 addr);
wdenk458ded32002-09-20 10:59:08 +0000356 }
357#endif
358
Bin Meng53f3afb2015-10-07 20:19:13 -0700359 /*
360 * This should equate to
361 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
wdenk458ded32002-09-20 10:59:08 +0000362 * from the VxWorks BSP header files.
363 * This will vary from board to board
364 */
Tuomas Tynkkynenf66276d2018-01-21 18:16:42 +0200365#if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
Bin Meng53f3afb2015-10-07 20:19:13 -0700366 tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
Simon Glass399a9ce2017-08-03 12:22:14 -0600367 eth_env_get_enetaddr("ethaddr", (uchar *)build_buf);
Mike Frysinger8bcee042009-02-11 18:51:43 -0500368 memcpy(tmp, build_buf, 6);
wdenk458ded32002-09-20 10:59:08 +0000369#else
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000370 puts("## Ethernet MAC address not copied to NV RAM\n");
wdenk458ded32002-09-20 10:59:08 +0000371#endif
372
Bin Meng75f4b722018-04-11 22:02:22 -0700373#ifdef CONFIG_X86
374 /*
375 * Get VxWorks's physical memory base address from environment,
376 * if we don't specify it in the environment, use a default one.
377 */
378 base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE);
379 data = (struct e820_entry *)(base + E820_DATA_OFFSET);
380 info = (struct e820_info *)(base + E820_INFO_OFFSET);
381
382 memset(info, 0, sizeof(struct e820_info));
383 info->sign = E820_SIGNATURE;
384 info->entries = install_e820_map(E820MAX, data);
385 info->addr = (info->entries - 1) * sizeof(struct e820_entry) +
386 E820_DATA_OFFSET;
387
388 /*
389 * Explicitly clear the bootloader image size otherwise if memory
390 * at this offset happens to contain some garbage data, the final
391 * available memory size for the kernel is insane.
392 */
393 *(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0;
394
395 /*
396 * Prepare compatible framebuffer information block.
397 * The VESA mode has to be 32-bit RGBA.
398 */
399 if (vesa->x_resolution && vesa->y_resolution) {
400 gop = (struct efi_gop_info *)(base + EFI_GOP_INFO_OFFSET);
401 gop->magic = EFI_GOP_INFO_MAGIC;
402 gop->info.version = 0;
403 gop->info.width = vesa->x_resolution;
404 gop->info.height = vesa->y_resolution;
405 gop->info.pixel_format = EFI_GOT_RGBA8;
406 gop->info.pixels_per_scanline = vesa->bytes_per_scanline / 4;
407 gop->fb_base = vesa->phys_base_ptr;
408 gop->fb_size = vesa->bytes_per_scanline * vesa->y_resolution;
409 }
410#endif
411
wdenk57b2d802003-06-27 21:31:46 +0000412 /*
413 * Use bootaddr to find the location in memory that VxWorks
Bin Mengfb694b92015-10-07 20:19:17 -0700414 * will look for the bootline string. The default value is
415 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
416 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
wdenk458ded32002-09-20 10:59:08 +0000417 */
Simon Glass64b723f2017-08-03 12:22:12 -0600418 tmp = env_get("bootaddr");
Bin Mengfb694b92015-10-07 20:19:17 -0700419 if (!tmp) {
Bin Meng75f4b722018-04-11 22:02:22 -0700420#ifdef CONFIG_X86
421 bootaddr = base + X86_BOOT_LINE_OFFSET;
422#else
Bin Mengfb694b92015-10-07 20:19:17 -0700423 printf("## VxWorks bootline address not specified\n");
Bin Meng051f95e2018-04-11 22:02:21 -0700424 return 1;
Bin Meng75f4b722018-04-11 22:02:22 -0700425#endif
Bin Meng051f95e2018-04-11 22:02:21 -0700426 }
427
Bin Meng75f4b722018-04-11 22:02:22 -0700428 if (!bootaddr)
429 bootaddr = simple_strtoul(tmp, NULL, 16);
Bin Meng051f95e2018-04-11 22:02:21 -0700430
431 /*
432 * Check to see if the bootline is defined in the 'bootargs' parameter.
433 * If it is not defined, we may be able to construct the info.
434 */
435 bootline = env_get("bootargs");
436 if (!bootline) {
437 tmp = env_get("bootdev");
438 if (tmp) {
439 strcpy(build_buf, tmp);
440 ptr = strlen(tmp);
441 } else {
442 printf("## VxWorks boot device not specified\n");
443 }
444
445 tmp = env_get("bootfile");
446 if (tmp)
447 ptr += sprintf(build_buf + ptr, "host:%s ", tmp);
448 else
449 ptr += sprintf(build_buf + ptr, "host:vxWorks ");
wdenk458ded32002-09-20 10:59:08 +0000450
Bin Mengfb694b92015-10-07 20:19:17 -0700451 /*
Bin Meng051f95e2018-04-11 22:02:21 -0700452 * The following parameters are only needed if 'bootdev'
453 * is an ethernet device, otherwise they are optional.
Bin Mengfb694b92015-10-07 20:19:17 -0700454 */
Bin Meng051f95e2018-04-11 22:02:21 -0700455 tmp = env_get("ipaddr");
456 if (tmp) {
457 ptr += sprintf(build_buf + ptr, "e=%s", tmp);
458 tmp = env_get("netmask");
Ben Whitten34fd6c92015-12-30 13:05:58 +0000459 if (tmp) {
Bin Meng051f95e2018-04-11 22:02:21 -0700460 u32 mask = env_get_ip("netmask").s_addr;
Bin Mengfb694b92015-10-07 20:19:17 -0700461 ptr += sprintf(build_buf + ptr,
Bin Meng051f95e2018-04-11 22:02:21 -0700462 ":%08x ", ntohl(mask));
463 } else {
464 ptr += sprintf(build_buf + ptr, " ");
Bin Mengbf0ba252015-10-07 20:19:16 -0700465 }
Bin Meng051f95e2018-04-11 22:02:21 -0700466 }
wdenk458ded32002-09-20 10:59:08 +0000467
Bin Meng051f95e2018-04-11 22:02:21 -0700468 tmp = env_get("serverip");
469 if (tmp)
470 ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
wdenk458ded32002-09-20 10:59:08 +0000471
Bin Meng051f95e2018-04-11 22:02:21 -0700472 tmp = env_get("gatewayip");
473 if (tmp)
474 ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
Bin Mengbf0ba252015-10-07 20:19:16 -0700475
Bin Meng051f95e2018-04-11 22:02:21 -0700476 tmp = env_get("hostname");
477 if (tmp)
478 ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000479
Bin Meng051f95e2018-04-11 22:02:21 -0700480 tmp = env_get("othbootargs");
481 if (tmp) {
482 strcpy(build_buf + ptr, tmp);
483 ptr += strlen(tmp);
Bin Mengfb694b92015-10-07 20:19:17 -0700484 }
485
Bin Meng051f95e2018-04-11 22:02:21 -0700486 bootline = build_buf;
wdenk458ded32002-09-20 10:59:08 +0000487 }
488
Bin Meng051f95e2018-04-11 22:02:21 -0700489 memcpy((void *)bootaddr, bootline, max(strlen(bootline), (size_t)255));
490 flush_cache(bootaddr, max(strlen(bootline), (size_t)255));
491 printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, (char *)bootaddr);
492
wdenk57b2d802003-06-27 21:31:46 +0000493 /*
494 * If the data at the load address is an elf image, then
495 * treat it like an elf image. Otherwise, assume that it is a
Bin Meng53f3afb2015-10-07 20:19:13 -0700496 * binary image.
wdenk458ded32002-09-20 10:59:08 +0000497 */
Bin Meng53f3afb2015-10-07 20:19:13 -0700498 if (valid_elf_image(addr))
Christian Gmeinerae7d4be2018-03-20 14:18:25 +0100499 addr = load_elf_image_phdr(addr);
Bin Meng53f3afb2015-10-07 20:19:13 -0700500 else
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000501 puts("## Not an ELF image, assuming binary\n");
wdenk458ded32002-09-20 10:59:08 +0000502
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000503 printf("## Starting vxWorks at 0x%08lx ...\n", addr);
wdenk458ded32002-09-20 10:59:08 +0000504
Reinhard Arlt4fa117c2011-11-18 09:06:52 +0000505 dcache_disable();
Vasyl Vavrychuk70b551c2018-04-10 12:36:36 +0300506#if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
507 armv8_setup_psci();
508 smp_kick_all_cpus();
509#endif
510
Bin Mengf6900e22015-10-07 20:19:19 -0700511#ifdef CONFIG_X86
512 /* VxWorks on x86 uses stack to pass parameters */
513 ((asmlinkage void (*)(int))addr)(0);
514#else
Bin Meng53f3afb2015-10-07 20:19:13 -0700515 ((void (*)(int))addr)(0);
Bin Mengf6900e22015-10-07 20:19:19 -0700516#endif
wdenk458ded32002-09-20 10:59:08 +0000517
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000518 puts("## vxWorks terminated\n");
Bin Meng53f3afb2015-10-07 20:19:13 -0700519
wdenk458ded32002-09-20 10:59:08 +0000520 return 1;
521}
522
wdenkf287a242003-07-01 21:06:45 +0000523U_BOOT_CMD(
Tom Rini3c95c792017-05-18 17:03:07 -0400524 bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600525 "Boot from an ELF image in memory",
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400526 "[-p|-s] [address]\n"
527 "\t- load ELF image at [address] via program headers (-p)\n"
528 "\t or via section headers (-s)"
wdenk57b2d802003-06-27 21:31:46 +0000529);
530
wdenkf287a242003-07-01 21:06:45 +0000531U_BOOT_CMD(
Bin Meng53f3afb2015-10-07 20:19:13 -0700532 bootvx, 2, 0, do_bootvx,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600533 "Boot vxWorks from an ELF image",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200534 " [address] - load address of vxWorks ELF image."
wdenk57b2d802003-06-27 21:31:46 +0000535);