blob: eafea38aed18938621ecafa4a5d3da0a13322046 [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
60 return ehdr->e_entry;
61}
62
63/*
64 * A very simple ELF loader, assumes the image is valid, returns the
65 * entry point address.
66 *
67 * The loader firstly reads the EFI class to see if it's a 64-bit image.
68 * If yes, call the ELF64 loader. Otherwise continue with the ELF32 loader.
Bin Meng8c77af62015-10-07 20:19:14 -070069 */
70static unsigned long load_elf_image_phdr(unsigned long addr)
71{
72 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
73 Elf32_Phdr *phdr; /* Program header structure pointer */
74 int i;
75
76 ehdr = (Elf32_Ehdr *)addr;
Bin Mengc71073f2018-04-11 22:02:14 -070077 if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
78 return load_elf64_image_phdr(addr);
79
Bin Meng8c77af62015-10-07 20:19:14 -070080 phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff);
81
82 /* Load each program header */
83 for (i = 0; i < ehdr->e_phnum; ++i) {
84 void *dst = (void *)(uintptr_t)phdr->p_paddr;
85 void *src = (void *)addr + phdr->p_offset;
Bin Mengc71073f2018-04-11 22:02:14 -070086
Bin Meng8c77af62015-10-07 20:19:14 -070087 debug("Loading phdr %i to 0x%p (%i bytes)\n",
88 i, dst, phdr->p_filesz);
89 if (phdr->p_filesz)
90 memcpy(dst, src, phdr->p_filesz);
91 if (phdr->p_filesz != phdr->p_memsz)
92 memset(dst + phdr->p_filesz, 0x00,
93 phdr->p_memsz - phdr->p_filesz);
94 flush_cache((unsigned long)dst, phdr->p_filesz);
95 ++phdr;
96 }
97
98 return ehdr->e_entry;
99}
100
101static unsigned long load_elf_image_shdr(unsigned long addr)
102{
103 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
104 Elf32_Shdr *shdr; /* Section header structure pointer */
105 unsigned char *strtab = 0; /* String table pointer */
106 unsigned char *image; /* Binary image pointer */
107 int i; /* Loop counter */
108
109 ehdr = (Elf32_Ehdr *)addr;
110
111 /* Find the section header string table for output info */
112 shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
113 (ehdr->e_shstrndx * sizeof(Elf32_Shdr)));
114
115 if (shdr->sh_type == SHT_STRTAB)
116 strtab = (unsigned char *)(addr + shdr->sh_offset);
117
118 /* Load each appropriate section */
119 for (i = 0; i < ehdr->e_shnum; ++i) {
120 shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
121 (i * sizeof(Elf32_Shdr)));
122
123 if (!(shdr->sh_flags & SHF_ALLOC) ||
124 shdr->sh_addr == 0 || shdr->sh_size == 0) {
125 continue;
126 }
127
128 if (strtab) {
129 debug("%sing %s @ 0x%08lx (%ld bytes)\n",
130 (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
131 &strtab[shdr->sh_name],
132 (unsigned long)shdr->sh_addr,
133 (long)shdr->sh_size);
134 }
135
136 if (shdr->sh_type == SHT_NOBITS) {
137 memset((void *)(uintptr_t)shdr->sh_addr, 0,
138 shdr->sh_size);
139 } else {
140 image = (unsigned char *)addr + shdr->sh_offset;
141 memcpy((void *)(uintptr_t)shdr->sh_addr,
142 (const void *)image, shdr->sh_size);
143 }
144 flush_cache(shdr->sh_addr, shdr->sh_size);
145 }
146
147 return ehdr->e_entry;
148}
Mike Frysingere60644a2008-04-13 19:42:18 -0400149
150/* Allow ports to override the default behavior */
Jeroen Hofstee3cc2a742014-10-08 22:57:31 +0200151static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
Bin Meng53f3afb2015-10-07 20:19:13 -0700152 int argc, char * const argv[])
Mike Frysingerf79507e2008-01-29 18:21:05 -0500153{
Mike Frysingere60644a2008-04-13 19:42:18 -0400154 unsigned long ret;
155
Mike Frysingerf79507e2008-01-29 18:21:05 -0500156 /*
Mike Frysingere60644a2008-04-13 19:42:18 -0400157 * pass address parameter as argv[0] (aka command name),
158 * and all remaining args
159 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000160 ret = entry(argc, argv);
Mike Frysingerf79507e2008-01-29 18:21:05 -0500161
Mike Frysingere60644a2008-04-13 19:42:18 -0400162 return ret;
163}
wdenk458ded32002-09-20 10:59:08 +0000164
Bin Meng53f3afb2015-10-07 20:19:13 -0700165/*
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000166 * Determine if a valid ELF image exists at the given memory location.
Bin Meng53f3afb2015-10-07 20:19:13 -0700167 * First look at the ELF header magic field, then make sure that it is
168 * executable.
169 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000170int valid_elf_image(unsigned long addr)
171{
Bin Meng53f3afb2015-10-07 20:19:13 -0700172 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000173
Bin Meng53f3afb2015-10-07 20:19:13 -0700174 ehdr = (Elf32_Ehdr *)addr;
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000175
176 if (!IS_ELF(*ehdr)) {
177 printf("## No elf image at address 0x%08lx\n", addr);
178 return 0;
179 }
180
181 if (ehdr->e_type != ET_EXEC) {
182 printf("## Not a 32-bit elf image at address 0x%08lx\n", addr);
183 return 0;
184 }
185
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000186 return 1;
187}
188
Bin Meng53f3afb2015-10-07 20:19:13 -0700189/* Interpreter command to boot an arbitrary ELF image from memory */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000190int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk458ded32002-09-20 10:59:08 +0000191{
Bin Meng53f3afb2015-10-07 20:19:13 -0700192 unsigned long addr; /* Address of the ELF image */
193 unsigned long rc; /* Return value from user code */
Tom Rini3c95c792017-05-18 17:03:07 -0400194 char *sload = NULL;
Simon Glass64b723f2017-08-03 12:22:12 -0600195 const char *ep = env_get("autostart");
wdenk458ded32002-09-20 10:59:08 +0000196 int rcode = 0;
197
Tom Rini3c95c792017-05-18 17:03:07 -0400198 /* Consume 'bootelf' */
199 argc--; argv++;
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400200
Tom Rini3c95c792017-05-18 17:03:07 -0400201 /* Check for flag. */
202 if (argc >= 1 && (argv[0][0] == '-' && \
203 (argv[0][1] == 'p' || argv[0][1] == 's'))) {
204 sload = argv[0];
205 /* Consume flag. */
206 argc--; argv++;
207 }
208 /* Check for address. */
209 if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) {
210 /* Consume address */
211 argc--; argv++;
212 } else
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400213 addr = load_addr;
wdenk458ded32002-09-20 10:59:08 +0000214
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000215 if (!valid_elf_image(addr))
wdenk458ded32002-09-20 10:59:08 +0000216 return 1;
217
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400218 if (sload && sload[1] == 'p')
219 addr = load_elf_image_phdr(addr);
220 else
221 addr = load_elf_image_shdr(addr);
wdenk458ded32002-09-20 10:59:08 +0000222
Siva Durga Prasad Paladugu3825bfa2015-03-09 12:46:47 +0100223 if (ep && !strcmp(ep, "no"))
224 return rcode;
225
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000226 printf("## Starting application at 0x%08lx ...\n", addr);
wdenk458ded32002-09-20 10:59:08 +0000227
wdenk458ded32002-09-20 10:59:08 +0000228 /*
229 * pass address parameter as argv[0] (aka command name),
230 * and all remaining args
231 */
Tom Rini3c95c792017-05-18 17:03:07 -0400232 rc = do_bootelf_exec((void *)addr, argc, argv);
wdenk458ded32002-09-20 10:59:08 +0000233 if (rc != 0)
234 rcode = 1;
235
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000236 printf("## Application terminated, rc = 0x%lx\n", rc);
Bin Meng53f3afb2015-10-07 20:19:13 -0700237
wdenk458ded32002-09-20 10:59:08 +0000238 return rcode;
239}
240
Bin Meng53f3afb2015-10-07 20:19:13 -0700241/*
wdenk458ded32002-09-20 10:59:08 +0000242 * Interpreter command to boot VxWorks from a memory image. The image can
243 * be either an ELF image or a raw binary. Will attempt to setup the
244 * bootline and other parameters correctly.
Bin Meng53f3afb2015-10-07 20:19:13 -0700245 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000246int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk458ded32002-09-20 10:59:08 +0000247{
Bin Meng53f3afb2015-10-07 20:19:13 -0700248 unsigned long addr; /* Address of image */
Bin Meng75f4b722018-04-11 22:02:22 -0700249 unsigned long bootaddr = 0; /* Address to put the bootline */
Bin Meng53f3afb2015-10-07 20:19:13 -0700250 char *bootline; /* Text of the bootline */
251 char *tmp; /* Temporary char pointer */
252 char build_buf[128]; /* Buffer for building the bootline */
Bin Meng0401c862015-10-07 20:19:15 -0700253 int ptr = 0;
Bin Meng321e8602015-10-07 20:19:18 -0700254#ifdef CONFIG_X86
Bin Menge3be8902018-04-11 22:02:07 -0700255 ulong base;
Bin Mengdde4ebb2018-04-11 22:02:09 -0700256 struct e820_info *info;
Bin Meng4b8fc742018-04-11 22:02:11 -0700257 struct e820_entry *data;
Bin Meng71606c42018-04-11 22:02:19 -0700258 struct efi_gop_info *gop;
259 struct vesa_mode_info *vesa = &mode_info.vesa;
Bin Meng321e8602015-10-07 20:19:18 -0700260#endif
wdenk458ded32002-09-20 10:59:08 +0000261
Bin Meng53f3afb2015-10-07 20:19:13 -0700262 /*
wdenk458ded32002-09-20 10:59:08 +0000263 * Check the loadaddr variable.
264 * If we don't know where the image is then we're done.
265 */
Stany MARCELe5deaf582013-11-27 14:48:43 +0100266 if (argc < 2)
Stefan Roese00487782006-11-29 12:53:15 +0100267 addr = load_addr;
268 else
Stany MARCELe5deaf582013-11-27 14:48:43 +0100269 addr = simple_strtoul(argv[1], NULL, 16);
wdenk458ded32002-09-20 10:59:08 +0000270
Jon Loeliger54324d02007-07-08 17:51:39 -0500271#if defined(CONFIG_CMD_NET)
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000272 /*
Bin Meng53f3afb2015-10-07 20:19:13 -0700273 * Check to see if we need to tftp the image ourselves
274 * before starting
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000275 */
Stany MARCELe5deaf582013-11-27 14:48:43 +0100276 if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500277 if (net_loop(TFTPGET) <= 0)
wdenk458ded32002-09-20 10:59:08 +0000278 return 1;
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000279 printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
280 addr);
wdenk458ded32002-09-20 10:59:08 +0000281 }
282#endif
283
Bin Meng53f3afb2015-10-07 20:19:13 -0700284 /*
285 * This should equate to
286 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
wdenk458ded32002-09-20 10:59:08 +0000287 * from the VxWorks BSP header files.
288 * This will vary from board to board
289 */
Tuomas Tynkkynenf66276d2018-01-21 18:16:42 +0200290#if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
Bin Meng53f3afb2015-10-07 20:19:13 -0700291 tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
Simon Glass399a9ce2017-08-03 12:22:14 -0600292 eth_env_get_enetaddr("ethaddr", (uchar *)build_buf);
Mike Frysinger8bcee042009-02-11 18:51:43 -0500293 memcpy(tmp, build_buf, 6);
wdenk458ded32002-09-20 10:59:08 +0000294#else
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000295 puts("## Ethernet MAC address not copied to NV RAM\n");
wdenk458ded32002-09-20 10:59:08 +0000296#endif
297
Bin Meng75f4b722018-04-11 22:02:22 -0700298#ifdef CONFIG_X86
299 /*
300 * Get VxWorks's physical memory base address from environment,
301 * if we don't specify it in the environment, use a default one.
302 */
303 base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE);
304 data = (struct e820_entry *)(base + E820_DATA_OFFSET);
305 info = (struct e820_info *)(base + E820_INFO_OFFSET);
306
307 memset(info, 0, sizeof(struct e820_info));
308 info->sign = E820_SIGNATURE;
309 info->entries = install_e820_map(E820MAX, data);
310 info->addr = (info->entries - 1) * sizeof(struct e820_entry) +
311 E820_DATA_OFFSET;
312
313 /*
314 * Explicitly clear the bootloader image size otherwise if memory
315 * at this offset happens to contain some garbage data, the final
316 * available memory size for the kernel is insane.
317 */
318 *(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0;
319
320 /*
321 * Prepare compatible framebuffer information block.
322 * The VESA mode has to be 32-bit RGBA.
323 */
324 if (vesa->x_resolution && vesa->y_resolution) {
325 gop = (struct efi_gop_info *)(base + EFI_GOP_INFO_OFFSET);
326 gop->magic = EFI_GOP_INFO_MAGIC;
327 gop->info.version = 0;
328 gop->info.width = vesa->x_resolution;
329 gop->info.height = vesa->y_resolution;
330 gop->info.pixel_format = EFI_GOT_RGBA8;
331 gop->info.pixels_per_scanline = vesa->bytes_per_scanline / 4;
332 gop->fb_base = vesa->phys_base_ptr;
333 gop->fb_size = vesa->bytes_per_scanline * vesa->y_resolution;
334 }
335#endif
336
wdenk57b2d802003-06-27 21:31:46 +0000337 /*
338 * Use bootaddr to find the location in memory that VxWorks
Bin Mengfb694b92015-10-07 20:19:17 -0700339 * will look for the bootline string. The default value is
340 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
341 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
wdenk458ded32002-09-20 10:59:08 +0000342 */
Simon Glass64b723f2017-08-03 12:22:12 -0600343 tmp = env_get("bootaddr");
Bin Mengfb694b92015-10-07 20:19:17 -0700344 if (!tmp) {
Bin Meng75f4b722018-04-11 22:02:22 -0700345#ifdef CONFIG_X86
346 bootaddr = base + X86_BOOT_LINE_OFFSET;
347#else
Bin Mengfb694b92015-10-07 20:19:17 -0700348 printf("## VxWorks bootline address not specified\n");
Bin Meng051f95e2018-04-11 22:02:21 -0700349 return 1;
Bin Meng75f4b722018-04-11 22:02:22 -0700350#endif
Bin Meng051f95e2018-04-11 22:02:21 -0700351 }
352
Bin Meng75f4b722018-04-11 22:02:22 -0700353 if (!bootaddr)
354 bootaddr = simple_strtoul(tmp, NULL, 16);
Bin Meng051f95e2018-04-11 22:02:21 -0700355
356 /*
357 * Check to see if the bootline is defined in the 'bootargs' parameter.
358 * If it is not defined, we may be able to construct the info.
359 */
360 bootline = env_get("bootargs");
361 if (!bootline) {
362 tmp = env_get("bootdev");
363 if (tmp) {
364 strcpy(build_buf, tmp);
365 ptr = strlen(tmp);
366 } else {
367 printf("## VxWorks boot device not specified\n");
368 }
369
370 tmp = env_get("bootfile");
371 if (tmp)
372 ptr += sprintf(build_buf + ptr, "host:%s ", tmp);
373 else
374 ptr += sprintf(build_buf + ptr, "host:vxWorks ");
wdenk458ded32002-09-20 10:59:08 +0000375
Bin Mengfb694b92015-10-07 20:19:17 -0700376 /*
Bin Meng051f95e2018-04-11 22:02:21 -0700377 * The following parameters are only needed if 'bootdev'
378 * is an ethernet device, otherwise they are optional.
Bin Mengfb694b92015-10-07 20:19:17 -0700379 */
Bin Meng051f95e2018-04-11 22:02:21 -0700380 tmp = env_get("ipaddr");
381 if (tmp) {
382 ptr += sprintf(build_buf + ptr, "e=%s", tmp);
383 tmp = env_get("netmask");
Ben Whitten34fd6c92015-12-30 13:05:58 +0000384 if (tmp) {
Bin Meng051f95e2018-04-11 22:02:21 -0700385 u32 mask = env_get_ip("netmask").s_addr;
Bin Mengfb694b92015-10-07 20:19:17 -0700386 ptr += sprintf(build_buf + ptr,
Bin Meng051f95e2018-04-11 22:02:21 -0700387 ":%08x ", ntohl(mask));
388 } else {
389 ptr += sprintf(build_buf + ptr, " ");
Bin Mengbf0ba252015-10-07 20:19:16 -0700390 }
Bin Meng051f95e2018-04-11 22:02:21 -0700391 }
wdenk458ded32002-09-20 10:59:08 +0000392
Bin Meng051f95e2018-04-11 22:02:21 -0700393 tmp = env_get("serverip");
394 if (tmp)
395 ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
wdenk458ded32002-09-20 10:59:08 +0000396
Bin Meng051f95e2018-04-11 22:02:21 -0700397 tmp = env_get("gatewayip");
398 if (tmp)
399 ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
Bin Mengbf0ba252015-10-07 20:19:16 -0700400
Bin Meng051f95e2018-04-11 22:02:21 -0700401 tmp = env_get("hostname");
402 if (tmp)
403 ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000404
Bin Meng051f95e2018-04-11 22:02:21 -0700405 tmp = env_get("othbootargs");
406 if (tmp) {
407 strcpy(build_buf + ptr, tmp);
408 ptr += strlen(tmp);
Bin Mengfb694b92015-10-07 20:19:17 -0700409 }
410
Bin Meng051f95e2018-04-11 22:02:21 -0700411 bootline = build_buf;
wdenk458ded32002-09-20 10:59:08 +0000412 }
413
Bin Meng051f95e2018-04-11 22:02:21 -0700414 memcpy((void *)bootaddr, bootline, max(strlen(bootline), (size_t)255));
415 flush_cache(bootaddr, max(strlen(bootline), (size_t)255));
416 printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, (char *)bootaddr);
417
wdenk57b2d802003-06-27 21:31:46 +0000418 /*
419 * If the data at the load address is an elf image, then
420 * treat it like an elf image. Otherwise, assume that it is a
Bin Meng53f3afb2015-10-07 20:19:13 -0700421 * binary image.
wdenk458ded32002-09-20 10:59:08 +0000422 */
Bin Meng53f3afb2015-10-07 20:19:13 -0700423 if (valid_elf_image(addr))
Christian Gmeinerae7d4be2018-03-20 14:18:25 +0100424 addr = load_elf_image_phdr(addr);
Bin Meng53f3afb2015-10-07 20:19:13 -0700425 else
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000426 puts("## Not an ELF image, assuming binary\n");
wdenk458ded32002-09-20 10:59:08 +0000427
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000428 printf("## Starting vxWorks at 0x%08lx ...\n", addr);
wdenk458ded32002-09-20 10:59:08 +0000429
Reinhard Arlt4fa117c2011-11-18 09:06:52 +0000430 dcache_disable();
Vasyl Vavrychuk70b551c2018-04-10 12:36:36 +0300431#if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
432 armv8_setup_psci();
433 smp_kick_all_cpus();
434#endif
435
Bin Mengf6900e22015-10-07 20:19:19 -0700436#ifdef CONFIG_X86
437 /* VxWorks on x86 uses stack to pass parameters */
438 ((asmlinkage void (*)(int))addr)(0);
439#else
Bin Meng53f3afb2015-10-07 20:19:13 -0700440 ((void (*)(int))addr)(0);
Bin Mengf6900e22015-10-07 20:19:19 -0700441#endif
wdenk458ded32002-09-20 10:59:08 +0000442
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000443 puts("## vxWorks terminated\n");
Bin Meng53f3afb2015-10-07 20:19:13 -0700444
wdenk458ded32002-09-20 10:59:08 +0000445 return 1;
446}
447
wdenkf287a242003-07-01 21:06:45 +0000448U_BOOT_CMD(
Tom Rini3c95c792017-05-18 17:03:07 -0400449 bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600450 "Boot from an ELF image in memory",
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400451 "[-p|-s] [address]\n"
452 "\t- load ELF image at [address] via program headers (-p)\n"
453 "\t or via section headers (-s)"
wdenk57b2d802003-06-27 21:31:46 +0000454);
455
wdenkf287a242003-07-01 21:06:45 +0000456U_BOOT_CMD(
Bin Meng53f3afb2015-10-07 20:19:13 -0700457 bootvx, 2, 0, do_bootvx,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600458 "Boot vxWorks from an ELF image",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200459 " [address] - load address of vxWorks ELF image."
wdenk57b2d802003-06-27 21:31:46 +0000460);