blob: 036be5f44381ae5ac0e24820d30854d7eb0b3c5e [file] [log] [blame]
Tom Rini8abb4cb2020-01-29 11:03:34 -05001// SPDX-License-Identifier: BSD-2-Clause
wdenk458ded32002-09-20 10:59:08 +00002/*
3 * Copyright (c) 2001 William L. Pitts
4 * All rights reserved.
wdenk458ded32002-09-20 10:59:08 +00005 */
6
7#include <common.h>
8#include <command.h>
Simon Glass370382c2019-11-14 12:57:35 -07009#include <cpu_func.h>
wdenk458ded32002-09-20 10:59:08 +000010#include <elf.h>
Simon Glass83c2e492019-08-01 09:46:50 -060011#include <env.h>
Simon Glass85f13782019-12-28 10:45:03 -070012#include <image.h>
Bin Meng53f3afb2015-10-07 20:19:13 -070013#include <net.h>
Niklaus Gigerf662b232008-11-03 22:15:34 +010014#include <vxworks.h>
Bin Meng321e8602015-10-07 20:19:18 -070015#ifdef CONFIG_X86
Bin Meng71606c42018-04-11 22:02:19 -070016#include <vbe.h>
Bin Meng321e8602015-10-07 20:19:18 -070017#include <asm/e820.h>
Bin Mengf6900e22015-10-07 20:19:19 -070018#include <linux/linkage.h>
Bin Meng321e8602015-10-07 20:19:18 -070019#endif
wdenk458ded32002-09-20 10:59:08 +000020
Bin Meng8c77af62015-10-07 20:19:14 -070021/*
Bin Mengc71073f2018-04-11 22:02:14 -070022 * A very simple ELF64 loader, assumes the image is valid, returns the
Bin Meng8c77af62015-10-07 20:19:14 -070023 * entry point address.
Bin Mengc71073f2018-04-11 22:02:14 -070024 *
25 * Note if U-Boot is 32-bit, the loader assumes the to segment's
26 * physical address and size is within the lower 32-bit address space.
27 */
28static unsigned long load_elf64_image_phdr(unsigned long addr)
29{
30 Elf64_Ehdr *ehdr; /* Elf header structure pointer */
31 Elf64_Phdr *phdr; /* Program header structure pointer */
32 int i;
33
34 ehdr = (Elf64_Ehdr *)addr;
35 phdr = (Elf64_Phdr *)(addr + (ulong)ehdr->e_phoff);
36
37 /* Load each program header */
38 for (i = 0; i < ehdr->e_phnum; ++i) {
39 void *dst = (void *)(ulong)phdr->p_paddr;
40 void *src = (void *)addr + phdr->p_offset;
41
42 debug("Loading phdr %i to 0x%p (%lu bytes)\n",
43 i, dst, (ulong)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);
Kurban Mallachieva064f192019-02-07 14:19:45 +030049 flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
50 roundup(phdr->p_memsz, ARCH_DMA_MINALIGN));
Bin Mengc71073f2018-04-11 22:02:14 -070051 ++phdr;
52 }
53
Rob Bracero7c8b3252018-07-31 22:57:42 -040054 if (ehdr->e_machine == EM_PPC64 && (ehdr->e_flags &
55 EF_PPC64_ELFV1_ABI)) {
56 /*
57 * For the 64-bit PowerPC ELF V1 ABI, e_entry is a function
58 * descriptor pointer with the first double word being the
59 * address of the entry point of the function.
60 */
61 uintptr_t addr = ehdr->e_entry;
62
63 return *(Elf64_Addr *)addr;
64 }
65
Bin Mengc71073f2018-04-11 22:02:14 -070066 return ehdr->e_entry;
67}
68
Rob Bracero7c8b3252018-07-31 22:57:42 -040069static unsigned long load_elf64_image_shdr(unsigned long addr)
70{
71 Elf64_Ehdr *ehdr; /* Elf header structure pointer */
72 Elf64_Shdr *shdr; /* Section header structure pointer */
73 unsigned char *strtab = 0; /* String table pointer */
74 unsigned char *image; /* Binary image pointer */
75 int i; /* Loop counter */
76
77 ehdr = (Elf64_Ehdr *)addr;
78
79 /* Find the section header string table for output info */
80 shdr = (Elf64_Shdr *)(addr + (ulong)ehdr->e_shoff +
81 (ehdr->e_shstrndx * sizeof(Elf64_Shdr)));
82
83 if (shdr->sh_type == SHT_STRTAB)
84 strtab = (unsigned char *)(addr + (ulong)shdr->sh_offset);
85
86 /* Load each appropriate section */
87 for (i = 0; i < ehdr->e_shnum; ++i) {
88 shdr = (Elf64_Shdr *)(addr + (ulong)ehdr->e_shoff +
89 (i * sizeof(Elf64_Shdr)));
90
91 if (!(shdr->sh_flags & SHF_ALLOC) ||
92 shdr->sh_addr == 0 || shdr->sh_size == 0) {
93 continue;
94 }
95
96 if (strtab) {
97 debug("%sing %s @ 0x%08lx (%ld bytes)\n",
98 (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
99 &strtab[shdr->sh_name],
100 (unsigned long)shdr->sh_addr,
101 (long)shdr->sh_size);
102 }
103
104 if (shdr->sh_type == SHT_NOBITS) {
105 memset((void *)(uintptr_t)shdr->sh_addr, 0,
106 shdr->sh_size);
107 } else {
108 image = (unsigned char *)addr + (ulong)shdr->sh_offset;
109 memcpy((void *)(uintptr_t)shdr->sh_addr,
110 (const void *)image, shdr->sh_size);
111 }
Neil Stainton6e91bd92018-08-20 15:46:19 +0000112 flush_cache(rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN),
113 roundup((shdr->sh_addr + shdr->sh_size),
114 ARCH_DMA_MINALIGN) -
115 rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN));
Rob Bracero7c8b3252018-07-31 22:57:42 -0400116 }
117
118 if (ehdr->e_machine == EM_PPC64 && (ehdr->e_flags &
119 EF_PPC64_ELFV1_ABI)) {
120 /*
121 * For the 64-bit PowerPC ELF V1 ABI, e_entry is a function
122 * descriptor pointer with the first double word being the
123 * address of the entry point of the function.
124 */
125 uintptr_t addr = ehdr->e_entry;
126
127 return *(Elf64_Addr *)addr;
128 }
129
130 return ehdr->e_entry;
131}
132
Bin Mengc71073f2018-04-11 22:02:14 -0700133/*
134 * A very simple ELF loader, assumes the image is valid, returns the
135 * entry point address.
136 *
137 * The loader firstly reads the EFI class to see if it's a 64-bit image.
138 * If yes, call the ELF64 loader. Otherwise continue with the ELF32 loader.
Bin Meng8c77af62015-10-07 20:19:14 -0700139 */
140static unsigned long load_elf_image_phdr(unsigned long addr)
141{
142 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
143 Elf32_Phdr *phdr; /* Program header structure pointer */
144 int i;
145
146 ehdr = (Elf32_Ehdr *)addr;
Bin Mengc71073f2018-04-11 22:02:14 -0700147 if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
148 return load_elf64_image_phdr(addr);
149
Bin Meng8c77af62015-10-07 20:19:14 -0700150 phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff);
151
152 /* Load each program header */
153 for (i = 0; i < ehdr->e_phnum; ++i) {
154 void *dst = (void *)(uintptr_t)phdr->p_paddr;
155 void *src = (void *)addr + phdr->p_offset;
Bin Mengc71073f2018-04-11 22:02:14 -0700156
Bin Meng8c77af62015-10-07 20:19:14 -0700157 debug("Loading phdr %i to 0x%p (%i bytes)\n",
158 i, dst, phdr->p_filesz);
159 if (phdr->p_filesz)
160 memcpy(dst, src, phdr->p_filesz);
161 if (phdr->p_filesz != phdr->p_memsz)
162 memset(dst + phdr->p_filesz, 0x00,
163 phdr->p_memsz - phdr->p_filesz);
Kurban Mallachieva064f192019-02-07 14:19:45 +0300164 flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
165 roundup(phdr->p_memsz, ARCH_DMA_MINALIGN));
Bin Meng8c77af62015-10-07 20:19:14 -0700166 ++phdr;
167 }
168
169 return ehdr->e_entry;
170}
171
172static unsigned long load_elf_image_shdr(unsigned long addr)
173{
174 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
175 Elf32_Shdr *shdr; /* Section header structure pointer */
176 unsigned char *strtab = 0; /* String table pointer */
177 unsigned char *image; /* Binary image pointer */
178 int i; /* Loop counter */
179
180 ehdr = (Elf32_Ehdr *)addr;
Rob Bracero7c8b3252018-07-31 22:57:42 -0400181 if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
182 return load_elf64_image_shdr(addr);
Bin Meng8c77af62015-10-07 20:19:14 -0700183
184 /* Find the section header string table for output info */
185 shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
186 (ehdr->e_shstrndx * sizeof(Elf32_Shdr)));
187
188 if (shdr->sh_type == SHT_STRTAB)
189 strtab = (unsigned char *)(addr + shdr->sh_offset);
190
191 /* Load each appropriate section */
192 for (i = 0; i < ehdr->e_shnum; ++i) {
193 shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
194 (i * sizeof(Elf32_Shdr)));
195
196 if (!(shdr->sh_flags & SHF_ALLOC) ||
197 shdr->sh_addr == 0 || shdr->sh_size == 0) {
198 continue;
199 }
200
201 if (strtab) {
202 debug("%sing %s @ 0x%08lx (%ld bytes)\n",
203 (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
204 &strtab[shdr->sh_name],
205 (unsigned long)shdr->sh_addr,
206 (long)shdr->sh_size);
207 }
208
209 if (shdr->sh_type == SHT_NOBITS) {
210 memset((void *)(uintptr_t)shdr->sh_addr, 0,
211 shdr->sh_size);
212 } else {
213 image = (unsigned char *)addr + shdr->sh_offset;
214 memcpy((void *)(uintptr_t)shdr->sh_addr,
215 (const void *)image, shdr->sh_size);
216 }
Neil Staintonf92c83b2018-09-19 10:38:07 +0100217 flush_cache(rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN),
218 roundup((shdr->sh_addr + shdr->sh_size),
219 ARCH_DMA_MINALIGN) -
220 rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN));
Bin Meng8c77af62015-10-07 20:19:14 -0700221 }
222
223 return ehdr->e_entry;
224}
Mike Frysingere60644a2008-04-13 19:42:18 -0400225
226/* Allow ports to override the default behavior */
Jeroen Hofstee3cc2a742014-10-08 22:57:31 +0200227static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
Bin Meng53f3afb2015-10-07 20:19:13 -0700228 int argc, char * const argv[])
Mike Frysingerf79507e2008-01-29 18:21:05 -0500229{
Mike Frysingere60644a2008-04-13 19:42:18 -0400230 unsigned long ret;
231
Mike Frysingerf79507e2008-01-29 18:21:05 -0500232 /*
Mike Frysingere60644a2008-04-13 19:42:18 -0400233 * pass address parameter as argv[0] (aka command name),
234 * and all remaining args
235 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000236 ret = entry(argc, argv);
Mike Frysingerf79507e2008-01-29 18:21:05 -0500237
Mike Frysingere60644a2008-04-13 19:42:18 -0400238 return ret;
239}
wdenk458ded32002-09-20 10:59:08 +0000240
Bin Meng53f3afb2015-10-07 20:19:13 -0700241/*
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000242 * Determine if a valid ELF image exists at the given memory location.
Bin Meng53f3afb2015-10-07 20:19:13 -0700243 * First look at the ELF header magic field, then make sure that it is
244 * executable.
245 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000246int valid_elf_image(unsigned long addr)
247{
Bin Meng53f3afb2015-10-07 20:19:13 -0700248 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000249
Bin Meng53f3afb2015-10-07 20:19:13 -0700250 ehdr = (Elf32_Ehdr *)addr;
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000251
252 if (!IS_ELF(*ehdr)) {
253 printf("## No elf image at address 0x%08lx\n", addr);
254 return 0;
255 }
256
257 if (ehdr->e_type != ET_EXEC) {
258 printf("## Not a 32-bit elf image at address 0x%08lx\n", addr);
259 return 0;
260 }
261
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000262 return 1;
263}
264
Bin Meng53f3afb2015-10-07 20:19:13 -0700265/* Interpreter command to boot an arbitrary ELF image from memory */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000266int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk458ded32002-09-20 10:59:08 +0000267{
Bin Meng53f3afb2015-10-07 20:19:13 -0700268 unsigned long addr; /* Address of the ELF image */
269 unsigned long rc; /* Return value from user code */
Tom Rini3c95c792017-05-18 17:03:07 -0400270 char *sload = NULL;
Simon Glass64b723f2017-08-03 12:22:12 -0600271 const char *ep = env_get("autostart");
wdenk458ded32002-09-20 10:59:08 +0000272 int rcode = 0;
273
Tom Rini3c95c792017-05-18 17:03:07 -0400274 /* Consume 'bootelf' */
275 argc--; argv++;
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400276
Tom Rini3c95c792017-05-18 17:03:07 -0400277 /* Check for flag. */
278 if (argc >= 1 && (argv[0][0] == '-' && \
279 (argv[0][1] == 'p' || argv[0][1] == 's'))) {
280 sload = argv[0];
281 /* Consume flag. */
282 argc--; argv++;
283 }
284 /* Check for address. */
285 if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) {
286 /* Consume address */
287 argc--; argv++;
288 } else
Simon Glass892265d2019-12-28 10:45:02 -0700289 addr = image_load_addr;
wdenk458ded32002-09-20 10:59:08 +0000290
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000291 if (!valid_elf_image(addr))
wdenk458ded32002-09-20 10:59:08 +0000292 return 1;
293
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400294 if (sload && sload[1] == 'p')
295 addr = load_elf_image_phdr(addr);
296 else
297 addr = load_elf_image_shdr(addr);
wdenk458ded32002-09-20 10:59:08 +0000298
Siva Durga Prasad Paladugu3825bfa2015-03-09 12:46:47 +0100299 if (ep && !strcmp(ep, "no"))
300 return rcode;
301
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000302 printf("## Starting application at 0x%08lx ...\n", addr);
wdenk458ded32002-09-20 10:59:08 +0000303
wdenk458ded32002-09-20 10:59:08 +0000304 /*
305 * pass address parameter as argv[0] (aka command name),
306 * and all remaining args
307 */
Tom Rini3c95c792017-05-18 17:03:07 -0400308 rc = do_bootelf_exec((void *)addr, argc, argv);
wdenk458ded32002-09-20 10:59:08 +0000309 if (rc != 0)
310 rcode = 1;
311
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000312 printf("## Application terminated, rc = 0x%lx\n", rc);
Bin Meng53f3afb2015-10-07 20:19:13 -0700313
wdenk458ded32002-09-20 10:59:08 +0000314 return rcode;
315}
316
Bin Meng53f3afb2015-10-07 20:19:13 -0700317/*
wdenk458ded32002-09-20 10:59:08 +0000318 * Interpreter command to boot VxWorks from a memory image. The image can
319 * be either an ELF image or a raw binary. Will attempt to setup the
320 * bootline and other parameters correctly.
Bin Meng53f3afb2015-10-07 20:19:13 -0700321 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000322int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk458ded32002-09-20 10:59:08 +0000323{
Bin Meng53f3afb2015-10-07 20:19:13 -0700324 unsigned long addr; /* Address of image */
Bin Meng75f4b722018-04-11 22:02:22 -0700325 unsigned long bootaddr = 0; /* Address to put the bootline */
Bin Meng53f3afb2015-10-07 20:19:13 -0700326 char *bootline; /* Text of the bootline */
327 char *tmp; /* Temporary char pointer */
328 char build_buf[128]; /* Buffer for building the bootline */
Bin Meng0401c862015-10-07 20:19:15 -0700329 int ptr = 0;
Bin Meng321e8602015-10-07 20:19:18 -0700330#ifdef CONFIG_X86
Bin Menge3be8902018-04-11 22:02:07 -0700331 ulong base;
Bin Mengdde4ebb2018-04-11 22:02:09 -0700332 struct e820_info *info;
Bin Meng4b8fc742018-04-11 22:02:11 -0700333 struct e820_entry *data;
Bin Meng71606c42018-04-11 22:02:19 -0700334 struct efi_gop_info *gop;
335 struct vesa_mode_info *vesa = &mode_info.vesa;
Bin Meng321e8602015-10-07 20:19:18 -0700336#endif
wdenk458ded32002-09-20 10:59:08 +0000337
Bin Meng53f3afb2015-10-07 20:19:13 -0700338 /*
wdenk458ded32002-09-20 10:59:08 +0000339 * Check the loadaddr variable.
340 * If we don't know where the image is then we're done.
341 */
Stany MARCELe5deaf582013-11-27 14:48:43 +0100342 if (argc < 2)
Simon Glass892265d2019-12-28 10:45:02 -0700343 addr = image_load_addr;
Stefan Roese00487782006-11-29 12:53:15 +0100344 else
Stany MARCELe5deaf582013-11-27 14:48:43 +0100345 addr = simple_strtoul(argv[1], NULL, 16);
wdenk458ded32002-09-20 10:59:08 +0000346
Jon Loeliger54324d02007-07-08 17:51:39 -0500347#if defined(CONFIG_CMD_NET)
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000348 /*
Bin Meng53f3afb2015-10-07 20:19:13 -0700349 * Check to see if we need to tftp the image ourselves
350 * before starting
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000351 */
Stany MARCELe5deaf582013-11-27 14:48:43 +0100352 if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500353 if (net_loop(TFTPGET) <= 0)
wdenk458ded32002-09-20 10:59:08 +0000354 return 1;
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000355 printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
356 addr);
wdenk458ded32002-09-20 10:59:08 +0000357 }
358#endif
359
Bin Meng53f3afb2015-10-07 20:19:13 -0700360 /*
361 * This should equate to
362 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
wdenk458ded32002-09-20 10:59:08 +0000363 * from the VxWorks BSP header files.
364 * This will vary from board to board
365 */
Tuomas Tynkkynenf66276d2018-01-21 18:16:42 +0200366#if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
Bin Meng53f3afb2015-10-07 20:19:13 -0700367 tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
Simon Glass399a9ce2017-08-03 12:22:14 -0600368 eth_env_get_enetaddr("ethaddr", (uchar *)build_buf);
Mike Frysinger8bcee042009-02-11 18:51:43 -0500369 memcpy(tmp, build_buf, 6);
wdenk458ded32002-09-20 10:59:08 +0000370#else
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000371 puts("## Ethernet MAC address not copied to NV RAM\n");
wdenk458ded32002-09-20 10:59:08 +0000372#endif
373
Bin Meng75f4b722018-04-11 22:02:22 -0700374#ifdef CONFIG_X86
375 /*
376 * Get VxWorks's physical memory base address from environment,
377 * if we don't specify it in the environment, use a default one.
378 */
379 base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE);
380 data = (struct e820_entry *)(base + E820_DATA_OFFSET);
381 info = (struct e820_info *)(base + E820_INFO_OFFSET);
382
383 memset(info, 0, sizeof(struct e820_info));
384 info->sign = E820_SIGNATURE;
385 info->entries = install_e820_map(E820MAX, data);
386 info->addr = (info->entries - 1) * sizeof(struct e820_entry) +
387 E820_DATA_OFFSET;
388
389 /*
390 * Explicitly clear the bootloader image size otherwise if memory
391 * at this offset happens to contain some garbage data, the final
392 * available memory size for the kernel is insane.
393 */
394 *(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0;
395
396 /*
397 * Prepare compatible framebuffer information block.
398 * The VESA mode has to be 32-bit RGBA.
399 */
400 if (vesa->x_resolution && vesa->y_resolution) {
401 gop = (struct efi_gop_info *)(base + EFI_GOP_INFO_OFFSET);
402 gop->magic = EFI_GOP_INFO_MAGIC;
403 gop->info.version = 0;
404 gop->info.width = vesa->x_resolution;
405 gop->info.height = vesa->y_resolution;
406 gop->info.pixel_format = EFI_GOT_RGBA8;
407 gop->info.pixels_per_scanline = vesa->bytes_per_scanline / 4;
408 gop->fb_base = vesa->phys_base_ptr;
409 gop->fb_size = vesa->bytes_per_scanline * vesa->y_resolution;
410 }
411#endif
412
wdenk57b2d802003-06-27 21:31:46 +0000413 /*
414 * Use bootaddr to find the location in memory that VxWorks
Bin Mengfb694b92015-10-07 20:19:17 -0700415 * will look for the bootline string. The default value is
416 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
417 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
wdenk458ded32002-09-20 10:59:08 +0000418 */
Simon Glass64b723f2017-08-03 12:22:12 -0600419 tmp = env_get("bootaddr");
Bin Mengfb694b92015-10-07 20:19:17 -0700420 if (!tmp) {
Bin Meng75f4b722018-04-11 22:02:22 -0700421#ifdef CONFIG_X86
422 bootaddr = base + X86_BOOT_LINE_OFFSET;
423#else
Bin Mengfb694b92015-10-07 20:19:17 -0700424 printf("## VxWorks bootline address not specified\n");
Bin Meng051f95e2018-04-11 22:02:21 -0700425 return 1;
Bin Meng75f4b722018-04-11 22:02:22 -0700426#endif
Bin Meng051f95e2018-04-11 22:02:21 -0700427 }
428
Bin Meng75f4b722018-04-11 22:02:22 -0700429 if (!bootaddr)
430 bootaddr = simple_strtoul(tmp, NULL, 16);
Bin Meng051f95e2018-04-11 22:02:21 -0700431
432 /*
433 * Check to see if the bootline is defined in the 'bootargs' parameter.
434 * If it is not defined, we may be able to construct the info.
435 */
436 bootline = env_get("bootargs");
437 if (!bootline) {
438 tmp = env_get("bootdev");
439 if (tmp) {
440 strcpy(build_buf, tmp);
441 ptr = strlen(tmp);
442 } else {
443 printf("## VxWorks boot device not specified\n");
444 }
445
446 tmp = env_get("bootfile");
447 if (tmp)
448 ptr += sprintf(build_buf + ptr, "host:%s ", tmp);
449 else
450 ptr += sprintf(build_buf + ptr, "host:vxWorks ");
wdenk458ded32002-09-20 10:59:08 +0000451
Bin Mengfb694b92015-10-07 20:19:17 -0700452 /*
Bin Meng051f95e2018-04-11 22:02:21 -0700453 * The following parameters are only needed if 'bootdev'
454 * is an ethernet device, otherwise they are optional.
Bin Mengfb694b92015-10-07 20:19:17 -0700455 */
Bin Meng051f95e2018-04-11 22:02:21 -0700456 tmp = env_get("ipaddr");
457 if (tmp) {
458 ptr += sprintf(build_buf + ptr, "e=%s", tmp);
459 tmp = env_get("netmask");
Ben Whitten34fd6c92015-12-30 13:05:58 +0000460 if (tmp) {
Bin Meng051f95e2018-04-11 22:02:21 -0700461 u32 mask = env_get_ip("netmask").s_addr;
Bin Mengfb694b92015-10-07 20:19:17 -0700462 ptr += sprintf(build_buf + ptr,
Bin Meng051f95e2018-04-11 22:02:21 -0700463 ":%08x ", ntohl(mask));
464 } else {
465 ptr += sprintf(build_buf + ptr, " ");
Bin Mengbf0ba252015-10-07 20:19:16 -0700466 }
Bin Meng051f95e2018-04-11 22:02:21 -0700467 }
wdenk458ded32002-09-20 10:59:08 +0000468
Bin Meng051f95e2018-04-11 22:02:21 -0700469 tmp = env_get("serverip");
470 if (tmp)
471 ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
wdenk458ded32002-09-20 10:59:08 +0000472
Bin Meng051f95e2018-04-11 22:02:21 -0700473 tmp = env_get("gatewayip");
474 if (tmp)
475 ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
Bin Mengbf0ba252015-10-07 20:19:16 -0700476
Bin Meng051f95e2018-04-11 22:02:21 -0700477 tmp = env_get("hostname");
478 if (tmp)
479 ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000480
Bin Meng051f95e2018-04-11 22:02:21 -0700481 tmp = env_get("othbootargs");
482 if (tmp) {
483 strcpy(build_buf + ptr, tmp);
484 ptr += strlen(tmp);
Bin Mengfb694b92015-10-07 20:19:17 -0700485 }
486
Bin Meng051f95e2018-04-11 22:02:21 -0700487 bootline = build_buf;
wdenk458ded32002-09-20 10:59:08 +0000488 }
489
Bin Meng051f95e2018-04-11 22:02:21 -0700490 memcpy((void *)bootaddr, bootline, max(strlen(bootline), (size_t)255));
491 flush_cache(bootaddr, max(strlen(bootline), (size_t)255));
492 printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, (char *)bootaddr);
493
wdenk57b2d802003-06-27 21:31:46 +0000494 /*
495 * If the data at the load address is an elf image, then
496 * treat it like an elf image. Otherwise, assume that it is a
Bin Meng53f3afb2015-10-07 20:19:13 -0700497 * binary image.
wdenk458ded32002-09-20 10:59:08 +0000498 */
Bin Meng53f3afb2015-10-07 20:19:13 -0700499 if (valid_elf_image(addr))
Christian Gmeinerae7d4be2018-03-20 14:18:25 +0100500 addr = load_elf_image_phdr(addr);
Bin Meng53f3afb2015-10-07 20:19:13 -0700501 else
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000502 puts("## Not an ELF image, assuming binary\n");
wdenk458ded32002-09-20 10:59:08 +0000503
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000504 printf("## Starting vxWorks at 0x%08lx ...\n", addr);
wdenk458ded32002-09-20 10:59:08 +0000505
Reinhard Arlt4fa117c2011-11-18 09:06:52 +0000506 dcache_disable();
Vasyl Vavrychuk70b551c2018-04-10 12:36:36 +0300507#if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
508 armv8_setup_psci();
509 smp_kick_all_cpus();
510#endif
511
Bin Mengf6900e22015-10-07 20:19:19 -0700512#ifdef CONFIG_X86
513 /* VxWorks on x86 uses stack to pass parameters */
514 ((asmlinkage void (*)(int))addr)(0);
515#else
Bin Meng53f3afb2015-10-07 20:19:13 -0700516 ((void (*)(int))addr)(0);
Bin Mengf6900e22015-10-07 20:19:19 -0700517#endif
wdenk458ded32002-09-20 10:59:08 +0000518
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000519 puts("## vxWorks terminated\n");
Bin Meng53f3afb2015-10-07 20:19:13 -0700520
wdenk458ded32002-09-20 10:59:08 +0000521 return 1;
522}
523
wdenkf287a242003-07-01 21:06:45 +0000524U_BOOT_CMD(
Tom Rini3c95c792017-05-18 17:03:07 -0400525 bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600526 "Boot from an ELF image in memory",
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400527 "[-p|-s] [address]\n"
528 "\t- load ELF image at [address] via program headers (-p)\n"
529 "\t or via section headers (-s)"
wdenk57b2d802003-06-27 21:31:46 +0000530);
531
wdenkf287a242003-07-01 21:06:45 +0000532U_BOOT_CMD(
Bin Meng53f3afb2015-10-07 20:19:13 -0700533 bootvx, 2, 0, do_bootvx,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600534 "Boot vxWorks from an ELF image",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200535 " [address] - load address of vxWorks ELF image."
wdenk57b2d802003-06-27 21:31:46 +0000536);