blob: ba06df06cf338e1a8c3c0a8eabe209df25898e5f [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>
Simon Glass370382c2019-11-14 12:57:35 -070018#include <cpu_func.h>
wdenk458ded32002-09-20 10:59:08 +000019#include <elf.h>
Simon Glass83c2e492019-08-01 09:46:50 -060020#include <env.h>
Simon Glass85f13782019-12-28 10:45:03 -070021#include <image.h>
Bin Meng53f3afb2015-10-07 20:19:13 -070022#include <net.h>
Niklaus Gigerf662b232008-11-03 22:15:34 +010023#include <vxworks.h>
Bin Meng321e8602015-10-07 20:19:18 -070024#ifdef CONFIG_X86
Bin Meng71606c42018-04-11 22:02:19 -070025#include <vbe.h>
Bin Meng321e8602015-10-07 20:19:18 -070026#include <asm/e820.h>
Bin Mengf6900e22015-10-07 20:19:19 -070027#include <linux/linkage.h>
Bin Meng321e8602015-10-07 20:19:18 -070028#endif
wdenk458ded32002-09-20 10:59:08 +000029
Bin Meng8c77af62015-10-07 20:19:14 -070030/*
Bin Mengc71073f2018-04-11 22:02:14 -070031 * A very simple ELF64 loader, assumes the image is valid, returns the
Bin Meng8c77af62015-10-07 20:19:14 -070032 * entry point address.
Bin Mengc71073f2018-04-11 22:02:14 -070033 *
34 * Note if U-Boot is 32-bit, the loader assumes the to segment's
35 * physical address and size is within the lower 32-bit address space.
36 */
37static unsigned long load_elf64_image_phdr(unsigned long addr)
38{
39 Elf64_Ehdr *ehdr; /* Elf header structure pointer */
40 Elf64_Phdr *phdr; /* Program header structure pointer */
41 int i;
42
43 ehdr = (Elf64_Ehdr *)addr;
44 phdr = (Elf64_Phdr *)(addr + (ulong)ehdr->e_phoff);
45
46 /* Load each program header */
47 for (i = 0; i < ehdr->e_phnum; ++i) {
48 void *dst = (void *)(ulong)phdr->p_paddr;
49 void *src = (void *)addr + phdr->p_offset;
50
51 debug("Loading phdr %i to 0x%p (%lu bytes)\n",
52 i, dst, (ulong)phdr->p_filesz);
53 if (phdr->p_filesz)
54 memcpy(dst, src, phdr->p_filesz);
55 if (phdr->p_filesz != phdr->p_memsz)
56 memset(dst + phdr->p_filesz, 0x00,
57 phdr->p_memsz - phdr->p_filesz);
Kurban Mallachieva064f192019-02-07 14:19:45 +030058 flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
59 roundup(phdr->p_memsz, ARCH_DMA_MINALIGN));
Bin Mengc71073f2018-04-11 22:02:14 -070060 ++phdr;
61 }
62
Rob Bracero7c8b3252018-07-31 22:57:42 -040063 if (ehdr->e_machine == EM_PPC64 && (ehdr->e_flags &
64 EF_PPC64_ELFV1_ABI)) {
65 /*
66 * For the 64-bit PowerPC ELF V1 ABI, e_entry is a function
67 * descriptor pointer with the first double word being the
68 * address of the entry point of the function.
69 */
70 uintptr_t addr = ehdr->e_entry;
71
72 return *(Elf64_Addr *)addr;
73 }
74
Bin Mengc71073f2018-04-11 22:02:14 -070075 return ehdr->e_entry;
76}
77
Rob Bracero7c8b3252018-07-31 22:57:42 -040078static unsigned long load_elf64_image_shdr(unsigned long addr)
79{
80 Elf64_Ehdr *ehdr; /* Elf header structure pointer */
81 Elf64_Shdr *shdr; /* Section header structure pointer */
82 unsigned char *strtab = 0; /* String table pointer */
83 unsigned char *image; /* Binary image pointer */
84 int i; /* Loop counter */
85
86 ehdr = (Elf64_Ehdr *)addr;
87
88 /* Find the section header string table for output info */
89 shdr = (Elf64_Shdr *)(addr + (ulong)ehdr->e_shoff +
90 (ehdr->e_shstrndx * sizeof(Elf64_Shdr)));
91
92 if (shdr->sh_type == SHT_STRTAB)
93 strtab = (unsigned char *)(addr + (ulong)shdr->sh_offset);
94
95 /* Load each appropriate section */
96 for (i = 0; i < ehdr->e_shnum; ++i) {
97 shdr = (Elf64_Shdr *)(addr + (ulong)ehdr->e_shoff +
98 (i * sizeof(Elf64_Shdr)));
99
100 if (!(shdr->sh_flags & SHF_ALLOC) ||
101 shdr->sh_addr == 0 || shdr->sh_size == 0) {
102 continue;
103 }
104
105 if (strtab) {
106 debug("%sing %s @ 0x%08lx (%ld bytes)\n",
107 (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
108 &strtab[shdr->sh_name],
109 (unsigned long)shdr->sh_addr,
110 (long)shdr->sh_size);
111 }
112
113 if (shdr->sh_type == SHT_NOBITS) {
114 memset((void *)(uintptr_t)shdr->sh_addr, 0,
115 shdr->sh_size);
116 } else {
117 image = (unsigned char *)addr + (ulong)shdr->sh_offset;
118 memcpy((void *)(uintptr_t)shdr->sh_addr,
119 (const void *)image, shdr->sh_size);
120 }
Neil Stainton6e91bd92018-08-20 15:46:19 +0000121 flush_cache(rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN),
122 roundup((shdr->sh_addr + shdr->sh_size),
123 ARCH_DMA_MINALIGN) -
124 rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN));
Rob Bracero7c8b3252018-07-31 22:57:42 -0400125 }
126
127 if (ehdr->e_machine == EM_PPC64 && (ehdr->e_flags &
128 EF_PPC64_ELFV1_ABI)) {
129 /*
130 * For the 64-bit PowerPC ELF V1 ABI, e_entry is a function
131 * descriptor pointer with the first double word being the
132 * address of the entry point of the function.
133 */
134 uintptr_t addr = ehdr->e_entry;
135
136 return *(Elf64_Addr *)addr;
137 }
138
139 return ehdr->e_entry;
140}
141
Bin Mengc71073f2018-04-11 22:02:14 -0700142/*
143 * A very simple ELF loader, assumes the image is valid, returns the
144 * entry point address.
145 *
146 * The loader firstly reads the EFI class to see if it's a 64-bit image.
147 * If yes, call the ELF64 loader. Otherwise continue with the ELF32 loader.
Bin Meng8c77af62015-10-07 20:19:14 -0700148 */
149static unsigned long load_elf_image_phdr(unsigned long addr)
150{
151 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
152 Elf32_Phdr *phdr; /* Program header structure pointer */
153 int i;
154
155 ehdr = (Elf32_Ehdr *)addr;
Bin Mengc71073f2018-04-11 22:02:14 -0700156 if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
157 return load_elf64_image_phdr(addr);
158
Bin Meng8c77af62015-10-07 20:19:14 -0700159 phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff);
160
161 /* Load each program header */
162 for (i = 0; i < ehdr->e_phnum; ++i) {
163 void *dst = (void *)(uintptr_t)phdr->p_paddr;
164 void *src = (void *)addr + phdr->p_offset;
Bin Mengc71073f2018-04-11 22:02:14 -0700165
Bin Meng8c77af62015-10-07 20:19:14 -0700166 debug("Loading phdr %i to 0x%p (%i bytes)\n",
167 i, dst, phdr->p_filesz);
168 if (phdr->p_filesz)
169 memcpy(dst, src, phdr->p_filesz);
170 if (phdr->p_filesz != phdr->p_memsz)
171 memset(dst + phdr->p_filesz, 0x00,
172 phdr->p_memsz - phdr->p_filesz);
Kurban Mallachieva064f192019-02-07 14:19:45 +0300173 flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
174 roundup(phdr->p_memsz, ARCH_DMA_MINALIGN));
Bin Meng8c77af62015-10-07 20:19:14 -0700175 ++phdr;
176 }
177
178 return ehdr->e_entry;
179}
180
181static unsigned long load_elf_image_shdr(unsigned long addr)
182{
183 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
184 Elf32_Shdr *shdr; /* Section header structure pointer */
185 unsigned char *strtab = 0; /* String table pointer */
186 unsigned char *image; /* Binary image pointer */
187 int i; /* Loop counter */
188
189 ehdr = (Elf32_Ehdr *)addr;
Rob Bracero7c8b3252018-07-31 22:57:42 -0400190 if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
191 return load_elf64_image_shdr(addr);
Bin Meng8c77af62015-10-07 20:19:14 -0700192
193 /* Find the section header string table for output info */
194 shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
195 (ehdr->e_shstrndx * sizeof(Elf32_Shdr)));
196
197 if (shdr->sh_type == SHT_STRTAB)
198 strtab = (unsigned char *)(addr + shdr->sh_offset);
199
200 /* Load each appropriate section */
201 for (i = 0; i < ehdr->e_shnum; ++i) {
202 shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
203 (i * sizeof(Elf32_Shdr)));
204
205 if (!(shdr->sh_flags & SHF_ALLOC) ||
206 shdr->sh_addr == 0 || shdr->sh_size == 0) {
207 continue;
208 }
209
210 if (strtab) {
211 debug("%sing %s @ 0x%08lx (%ld bytes)\n",
212 (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
213 &strtab[shdr->sh_name],
214 (unsigned long)shdr->sh_addr,
215 (long)shdr->sh_size);
216 }
217
218 if (shdr->sh_type == SHT_NOBITS) {
219 memset((void *)(uintptr_t)shdr->sh_addr, 0,
220 shdr->sh_size);
221 } else {
222 image = (unsigned char *)addr + shdr->sh_offset;
223 memcpy((void *)(uintptr_t)shdr->sh_addr,
224 (const void *)image, shdr->sh_size);
225 }
Neil Staintonf92c83b2018-09-19 10:38:07 +0100226 flush_cache(rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN),
227 roundup((shdr->sh_addr + shdr->sh_size),
228 ARCH_DMA_MINALIGN) -
229 rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN));
Bin Meng8c77af62015-10-07 20:19:14 -0700230 }
231
232 return ehdr->e_entry;
233}
Mike Frysingere60644a2008-04-13 19:42:18 -0400234
235/* Allow ports to override the default behavior */
Jeroen Hofstee3cc2a742014-10-08 22:57:31 +0200236static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
Bin Meng53f3afb2015-10-07 20:19:13 -0700237 int argc, char * const argv[])
Mike Frysingerf79507e2008-01-29 18:21:05 -0500238{
Mike Frysingere60644a2008-04-13 19:42:18 -0400239 unsigned long ret;
240
Mike Frysingerf79507e2008-01-29 18:21:05 -0500241 /*
Mike Frysingere60644a2008-04-13 19:42:18 -0400242 * pass address parameter as argv[0] (aka command name),
243 * and all remaining args
244 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000245 ret = entry(argc, argv);
Mike Frysingerf79507e2008-01-29 18:21:05 -0500246
Mike Frysingere60644a2008-04-13 19:42:18 -0400247 return ret;
248}
wdenk458ded32002-09-20 10:59:08 +0000249
Bin Meng53f3afb2015-10-07 20:19:13 -0700250/*
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000251 * Determine if a valid ELF image exists at the given memory location.
Bin Meng53f3afb2015-10-07 20:19:13 -0700252 * First look at the ELF header magic field, then make sure that it is
253 * executable.
254 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000255int valid_elf_image(unsigned long addr)
256{
Bin Meng53f3afb2015-10-07 20:19:13 -0700257 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000258
Bin Meng53f3afb2015-10-07 20:19:13 -0700259 ehdr = (Elf32_Ehdr *)addr;
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000260
261 if (!IS_ELF(*ehdr)) {
262 printf("## No elf image at address 0x%08lx\n", addr);
263 return 0;
264 }
265
266 if (ehdr->e_type != ET_EXEC) {
267 printf("## Not a 32-bit elf image at address 0x%08lx\n", addr);
268 return 0;
269 }
270
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000271 return 1;
272}
273
Bin Meng53f3afb2015-10-07 20:19:13 -0700274/* Interpreter command to boot an arbitrary ELF image from memory */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000275int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk458ded32002-09-20 10:59:08 +0000276{
Bin Meng53f3afb2015-10-07 20:19:13 -0700277 unsigned long addr; /* Address of the ELF image */
278 unsigned long rc; /* Return value from user code */
Tom Rini3c95c792017-05-18 17:03:07 -0400279 char *sload = NULL;
Simon Glass64b723f2017-08-03 12:22:12 -0600280 const char *ep = env_get("autostart");
wdenk458ded32002-09-20 10:59:08 +0000281 int rcode = 0;
282
Tom Rini3c95c792017-05-18 17:03:07 -0400283 /* Consume 'bootelf' */
284 argc--; argv++;
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400285
Tom Rini3c95c792017-05-18 17:03:07 -0400286 /* Check for flag. */
287 if (argc >= 1 && (argv[0][0] == '-' && \
288 (argv[0][1] == 'p' || argv[0][1] == 's'))) {
289 sload = argv[0];
290 /* Consume flag. */
291 argc--; argv++;
292 }
293 /* Check for address. */
294 if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) {
295 /* Consume address */
296 argc--; argv++;
297 } else
Simon Glass892265d2019-12-28 10:45:02 -0700298 addr = image_load_addr;
wdenk458ded32002-09-20 10:59:08 +0000299
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000300 if (!valid_elf_image(addr))
wdenk458ded32002-09-20 10:59:08 +0000301 return 1;
302
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400303 if (sload && sload[1] == 'p')
304 addr = load_elf_image_phdr(addr);
305 else
306 addr = load_elf_image_shdr(addr);
wdenk458ded32002-09-20 10:59:08 +0000307
Siva Durga Prasad Paladugu3825bfa2015-03-09 12:46:47 +0100308 if (ep && !strcmp(ep, "no"))
309 return rcode;
310
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000311 printf("## Starting application at 0x%08lx ...\n", addr);
wdenk458ded32002-09-20 10:59:08 +0000312
wdenk458ded32002-09-20 10:59:08 +0000313 /*
314 * pass address parameter as argv[0] (aka command name),
315 * and all remaining args
316 */
Tom Rini3c95c792017-05-18 17:03:07 -0400317 rc = do_bootelf_exec((void *)addr, argc, argv);
wdenk458ded32002-09-20 10:59:08 +0000318 if (rc != 0)
319 rcode = 1;
320
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000321 printf("## Application terminated, rc = 0x%lx\n", rc);
Bin Meng53f3afb2015-10-07 20:19:13 -0700322
wdenk458ded32002-09-20 10:59:08 +0000323 return rcode;
324}
325
Bin Meng53f3afb2015-10-07 20:19:13 -0700326/*
wdenk458ded32002-09-20 10:59:08 +0000327 * Interpreter command to boot VxWorks from a memory image. The image can
328 * be either an ELF image or a raw binary. Will attempt to setup the
329 * bootline and other parameters correctly.
Bin Meng53f3afb2015-10-07 20:19:13 -0700330 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000331int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk458ded32002-09-20 10:59:08 +0000332{
Bin Meng53f3afb2015-10-07 20:19:13 -0700333 unsigned long addr; /* Address of image */
Bin Meng75f4b722018-04-11 22:02:22 -0700334 unsigned long bootaddr = 0; /* Address to put the bootline */
Bin Meng53f3afb2015-10-07 20:19:13 -0700335 char *bootline; /* Text of the bootline */
336 char *tmp; /* Temporary char pointer */
337 char build_buf[128]; /* Buffer for building the bootline */
Bin Meng0401c862015-10-07 20:19:15 -0700338 int ptr = 0;
Bin Meng321e8602015-10-07 20:19:18 -0700339#ifdef CONFIG_X86
Bin Menge3be8902018-04-11 22:02:07 -0700340 ulong base;
Bin Mengdde4ebb2018-04-11 22:02:09 -0700341 struct e820_info *info;
Bin Meng4b8fc742018-04-11 22:02:11 -0700342 struct e820_entry *data;
Bin Meng71606c42018-04-11 22:02:19 -0700343 struct efi_gop_info *gop;
344 struct vesa_mode_info *vesa = &mode_info.vesa;
Bin Meng321e8602015-10-07 20:19:18 -0700345#endif
wdenk458ded32002-09-20 10:59:08 +0000346
Bin Meng53f3afb2015-10-07 20:19:13 -0700347 /*
wdenk458ded32002-09-20 10:59:08 +0000348 * Check the loadaddr variable.
349 * If we don't know where the image is then we're done.
350 */
Stany MARCELe5deaf582013-11-27 14:48:43 +0100351 if (argc < 2)
Simon Glass892265d2019-12-28 10:45:02 -0700352 addr = image_load_addr;
Stefan Roese00487782006-11-29 12:53:15 +0100353 else
Stany MARCELe5deaf582013-11-27 14:48:43 +0100354 addr = simple_strtoul(argv[1], NULL, 16);
wdenk458ded32002-09-20 10:59:08 +0000355
Jon Loeliger54324d02007-07-08 17:51:39 -0500356#if defined(CONFIG_CMD_NET)
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000357 /*
Bin Meng53f3afb2015-10-07 20:19:13 -0700358 * Check to see if we need to tftp the image ourselves
359 * before starting
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000360 */
Stany MARCELe5deaf582013-11-27 14:48:43 +0100361 if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500362 if (net_loop(TFTPGET) <= 0)
wdenk458ded32002-09-20 10:59:08 +0000363 return 1;
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000364 printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
365 addr);
wdenk458ded32002-09-20 10:59:08 +0000366 }
367#endif
368
Bin Meng53f3afb2015-10-07 20:19:13 -0700369 /*
370 * This should equate to
371 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
wdenk458ded32002-09-20 10:59:08 +0000372 * from the VxWorks BSP header files.
373 * This will vary from board to board
374 */
Tuomas Tynkkynenf66276d2018-01-21 18:16:42 +0200375#if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
Bin Meng53f3afb2015-10-07 20:19:13 -0700376 tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
Simon Glass399a9ce2017-08-03 12:22:14 -0600377 eth_env_get_enetaddr("ethaddr", (uchar *)build_buf);
Mike Frysinger8bcee042009-02-11 18:51:43 -0500378 memcpy(tmp, build_buf, 6);
wdenk458ded32002-09-20 10:59:08 +0000379#else
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000380 puts("## Ethernet MAC address not copied to NV RAM\n");
wdenk458ded32002-09-20 10:59:08 +0000381#endif
382
Bin Meng75f4b722018-04-11 22:02:22 -0700383#ifdef CONFIG_X86
384 /*
385 * Get VxWorks's physical memory base address from environment,
386 * if we don't specify it in the environment, use a default one.
387 */
388 base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE);
389 data = (struct e820_entry *)(base + E820_DATA_OFFSET);
390 info = (struct e820_info *)(base + E820_INFO_OFFSET);
391
392 memset(info, 0, sizeof(struct e820_info));
393 info->sign = E820_SIGNATURE;
394 info->entries = install_e820_map(E820MAX, data);
395 info->addr = (info->entries - 1) * sizeof(struct e820_entry) +
396 E820_DATA_OFFSET;
397
398 /*
399 * Explicitly clear the bootloader image size otherwise if memory
400 * at this offset happens to contain some garbage data, the final
401 * available memory size for the kernel is insane.
402 */
403 *(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0;
404
405 /*
406 * Prepare compatible framebuffer information block.
407 * The VESA mode has to be 32-bit RGBA.
408 */
409 if (vesa->x_resolution && vesa->y_resolution) {
410 gop = (struct efi_gop_info *)(base + EFI_GOP_INFO_OFFSET);
411 gop->magic = EFI_GOP_INFO_MAGIC;
412 gop->info.version = 0;
413 gop->info.width = vesa->x_resolution;
414 gop->info.height = vesa->y_resolution;
415 gop->info.pixel_format = EFI_GOT_RGBA8;
416 gop->info.pixels_per_scanline = vesa->bytes_per_scanline / 4;
417 gop->fb_base = vesa->phys_base_ptr;
418 gop->fb_size = vesa->bytes_per_scanline * vesa->y_resolution;
419 }
420#endif
421
wdenk57b2d802003-06-27 21:31:46 +0000422 /*
423 * Use bootaddr to find the location in memory that VxWorks
Bin Mengfb694b92015-10-07 20:19:17 -0700424 * will look for the bootline string. The default value is
425 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
426 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
wdenk458ded32002-09-20 10:59:08 +0000427 */
Simon Glass64b723f2017-08-03 12:22:12 -0600428 tmp = env_get("bootaddr");
Bin Mengfb694b92015-10-07 20:19:17 -0700429 if (!tmp) {
Bin Meng75f4b722018-04-11 22:02:22 -0700430#ifdef CONFIG_X86
431 bootaddr = base + X86_BOOT_LINE_OFFSET;
432#else
Bin Mengfb694b92015-10-07 20:19:17 -0700433 printf("## VxWorks bootline address not specified\n");
Bin Meng051f95e2018-04-11 22:02:21 -0700434 return 1;
Bin Meng75f4b722018-04-11 22:02:22 -0700435#endif
Bin Meng051f95e2018-04-11 22:02:21 -0700436 }
437
Bin Meng75f4b722018-04-11 22:02:22 -0700438 if (!bootaddr)
439 bootaddr = simple_strtoul(tmp, NULL, 16);
Bin Meng051f95e2018-04-11 22:02:21 -0700440
441 /*
442 * Check to see if the bootline is defined in the 'bootargs' parameter.
443 * If it is not defined, we may be able to construct the info.
444 */
445 bootline = env_get("bootargs");
446 if (!bootline) {
447 tmp = env_get("bootdev");
448 if (tmp) {
449 strcpy(build_buf, tmp);
450 ptr = strlen(tmp);
451 } else {
452 printf("## VxWorks boot device not specified\n");
453 }
454
455 tmp = env_get("bootfile");
456 if (tmp)
457 ptr += sprintf(build_buf + ptr, "host:%s ", tmp);
458 else
459 ptr += sprintf(build_buf + ptr, "host:vxWorks ");
wdenk458ded32002-09-20 10:59:08 +0000460
Bin Mengfb694b92015-10-07 20:19:17 -0700461 /*
Bin Meng051f95e2018-04-11 22:02:21 -0700462 * The following parameters are only needed if 'bootdev'
463 * is an ethernet device, otherwise they are optional.
Bin Mengfb694b92015-10-07 20:19:17 -0700464 */
Bin Meng051f95e2018-04-11 22:02:21 -0700465 tmp = env_get("ipaddr");
466 if (tmp) {
467 ptr += sprintf(build_buf + ptr, "e=%s", tmp);
468 tmp = env_get("netmask");
Ben Whitten34fd6c92015-12-30 13:05:58 +0000469 if (tmp) {
Bin Meng051f95e2018-04-11 22:02:21 -0700470 u32 mask = env_get_ip("netmask").s_addr;
Bin Mengfb694b92015-10-07 20:19:17 -0700471 ptr += sprintf(build_buf + ptr,
Bin Meng051f95e2018-04-11 22:02:21 -0700472 ":%08x ", ntohl(mask));
473 } else {
474 ptr += sprintf(build_buf + ptr, " ");
Bin Mengbf0ba252015-10-07 20:19:16 -0700475 }
Bin Meng051f95e2018-04-11 22:02:21 -0700476 }
wdenk458ded32002-09-20 10:59:08 +0000477
Bin Meng051f95e2018-04-11 22:02:21 -0700478 tmp = env_get("serverip");
479 if (tmp)
480 ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
wdenk458ded32002-09-20 10:59:08 +0000481
Bin Meng051f95e2018-04-11 22:02:21 -0700482 tmp = env_get("gatewayip");
483 if (tmp)
484 ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
Bin Mengbf0ba252015-10-07 20:19:16 -0700485
Bin Meng051f95e2018-04-11 22:02:21 -0700486 tmp = env_get("hostname");
487 if (tmp)
488 ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000489
Bin Meng051f95e2018-04-11 22:02:21 -0700490 tmp = env_get("othbootargs");
491 if (tmp) {
492 strcpy(build_buf + ptr, tmp);
493 ptr += strlen(tmp);
Bin Mengfb694b92015-10-07 20:19:17 -0700494 }
495
Bin Meng051f95e2018-04-11 22:02:21 -0700496 bootline = build_buf;
wdenk458ded32002-09-20 10:59:08 +0000497 }
498
Bin Meng051f95e2018-04-11 22:02:21 -0700499 memcpy((void *)bootaddr, bootline, max(strlen(bootline), (size_t)255));
500 flush_cache(bootaddr, max(strlen(bootline), (size_t)255));
501 printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, (char *)bootaddr);
502
wdenk57b2d802003-06-27 21:31:46 +0000503 /*
504 * If the data at the load address is an elf image, then
505 * treat it like an elf image. Otherwise, assume that it is a
Bin Meng53f3afb2015-10-07 20:19:13 -0700506 * binary image.
wdenk458ded32002-09-20 10:59:08 +0000507 */
Bin Meng53f3afb2015-10-07 20:19:13 -0700508 if (valid_elf_image(addr))
Christian Gmeinerae7d4be2018-03-20 14:18:25 +0100509 addr = load_elf_image_phdr(addr);
Bin Meng53f3afb2015-10-07 20:19:13 -0700510 else
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000511 puts("## Not an ELF image, assuming binary\n");
wdenk458ded32002-09-20 10:59:08 +0000512
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000513 printf("## Starting vxWorks at 0x%08lx ...\n", addr);
wdenk458ded32002-09-20 10:59:08 +0000514
Reinhard Arlt4fa117c2011-11-18 09:06:52 +0000515 dcache_disable();
Vasyl Vavrychuk70b551c2018-04-10 12:36:36 +0300516#if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
517 armv8_setup_psci();
518 smp_kick_all_cpus();
519#endif
520
Bin Mengf6900e22015-10-07 20:19:19 -0700521#ifdef CONFIG_X86
522 /* VxWorks on x86 uses stack to pass parameters */
523 ((asmlinkage void (*)(int))addr)(0);
524#else
Bin Meng53f3afb2015-10-07 20:19:13 -0700525 ((void (*)(int))addr)(0);
Bin Mengf6900e22015-10-07 20:19:19 -0700526#endif
wdenk458ded32002-09-20 10:59:08 +0000527
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000528 puts("## vxWorks terminated\n");
Bin Meng53f3afb2015-10-07 20:19:13 -0700529
wdenk458ded32002-09-20 10:59:08 +0000530 return 1;
531}
532
wdenkf287a242003-07-01 21:06:45 +0000533U_BOOT_CMD(
Tom Rini3c95c792017-05-18 17:03:07 -0400534 bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600535 "Boot from an ELF image in memory",
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400536 "[-p|-s] [address]\n"
537 "\t- load ELF image at [address] via program headers (-p)\n"
538 "\t or via section headers (-s)"
wdenk57b2d802003-06-27 21:31:46 +0000539);
540
wdenkf287a242003-07-01 21:06:45 +0000541U_BOOT_CMD(
Bin Meng53f3afb2015-10-07 20:19:13 -0700542 bootvx, 2, 0, do_bootvx,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600543 "Boot vxWorks from an ELF image",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200544 " [address] - load address of vxWorks ELF image."
wdenk57b2d802003-06-27 21:31:46 +0000545);