blob: 7bad1f80d42f9b23fec595871dc3cb1794bee55c [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 }
Neil Stainton6e91bd92018-08-20 15:46:19 +0000118 flush_cache(rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN),
119 roundup((shdr->sh_addr + shdr->sh_size),
120 ARCH_DMA_MINALIGN) -
121 rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN));
Rob Bracero7c8b3252018-07-31 22:57:42 -0400122 }
123
124 if (ehdr->e_machine == EM_PPC64 && (ehdr->e_flags &
125 EF_PPC64_ELFV1_ABI)) {
126 /*
127 * For the 64-bit PowerPC ELF V1 ABI, e_entry is a function
128 * descriptor pointer with the first double word being the
129 * address of the entry point of the function.
130 */
131 uintptr_t addr = ehdr->e_entry;
132
133 return *(Elf64_Addr *)addr;
134 }
135
136 return ehdr->e_entry;
137}
138
Bin Mengc71073f2018-04-11 22:02:14 -0700139/*
140 * A very simple ELF loader, assumes the image is valid, returns the
141 * entry point address.
142 *
143 * The loader firstly reads the EFI class to see if it's a 64-bit image.
144 * If yes, call the ELF64 loader. Otherwise continue with the ELF32 loader.
Bin Meng8c77af62015-10-07 20:19:14 -0700145 */
146static unsigned long load_elf_image_phdr(unsigned long addr)
147{
148 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
149 Elf32_Phdr *phdr; /* Program header structure pointer */
150 int i;
151
152 ehdr = (Elf32_Ehdr *)addr;
Bin Mengc71073f2018-04-11 22:02:14 -0700153 if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
154 return load_elf64_image_phdr(addr);
155
Bin Meng8c77af62015-10-07 20:19:14 -0700156 phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff);
157
158 /* Load each program header */
159 for (i = 0; i < ehdr->e_phnum; ++i) {
160 void *dst = (void *)(uintptr_t)phdr->p_paddr;
161 void *src = (void *)addr + phdr->p_offset;
Bin Mengc71073f2018-04-11 22:02:14 -0700162
Bin Meng8c77af62015-10-07 20:19:14 -0700163 debug("Loading phdr %i to 0x%p (%i bytes)\n",
164 i, dst, phdr->p_filesz);
165 if (phdr->p_filesz)
166 memcpy(dst, src, phdr->p_filesz);
167 if (phdr->p_filesz != phdr->p_memsz)
168 memset(dst + phdr->p_filesz, 0x00,
169 phdr->p_memsz - phdr->p_filesz);
170 flush_cache((unsigned long)dst, phdr->p_filesz);
171 ++phdr;
172 }
173
174 return ehdr->e_entry;
175}
176
177static unsigned long load_elf_image_shdr(unsigned long addr)
178{
179 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
180 Elf32_Shdr *shdr; /* Section header structure pointer */
181 unsigned char *strtab = 0; /* String table pointer */
182 unsigned char *image; /* Binary image pointer */
183 int i; /* Loop counter */
184
185 ehdr = (Elf32_Ehdr *)addr;
Rob Bracero7c8b3252018-07-31 22:57:42 -0400186 if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
187 return load_elf64_image_shdr(addr);
Bin Meng8c77af62015-10-07 20:19:14 -0700188
189 /* Find the section header string table for output info */
190 shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
191 (ehdr->e_shstrndx * sizeof(Elf32_Shdr)));
192
193 if (shdr->sh_type == SHT_STRTAB)
194 strtab = (unsigned char *)(addr + shdr->sh_offset);
195
196 /* Load each appropriate section */
197 for (i = 0; i < ehdr->e_shnum; ++i) {
198 shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
199 (i * sizeof(Elf32_Shdr)));
200
201 if (!(shdr->sh_flags & SHF_ALLOC) ||
202 shdr->sh_addr == 0 || shdr->sh_size == 0) {
203 continue;
204 }
205
206 if (strtab) {
207 debug("%sing %s @ 0x%08lx (%ld bytes)\n",
208 (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
209 &strtab[shdr->sh_name],
210 (unsigned long)shdr->sh_addr,
211 (long)shdr->sh_size);
212 }
213
214 if (shdr->sh_type == SHT_NOBITS) {
215 memset((void *)(uintptr_t)shdr->sh_addr, 0,
216 shdr->sh_size);
217 } else {
218 image = (unsigned char *)addr + shdr->sh_offset;
219 memcpy((void *)(uintptr_t)shdr->sh_addr,
220 (const void *)image, shdr->sh_size);
221 }
Neil Staintonf92c83b2018-09-19 10:38:07 +0100222 flush_cache(rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN),
223 roundup((shdr->sh_addr + shdr->sh_size),
224 ARCH_DMA_MINALIGN) -
225 rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN));
Bin Meng8c77af62015-10-07 20:19:14 -0700226 }
227
228 return ehdr->e_entry;
229}
Mike Frysingere60644a2008-04-13 19:42:18 -0400230
231/* Allow ports to override the default behavior */
Jeroen Hofstee3cc2a742014-10-08 22:57:31 +0200232static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
Bin Meng53f3afb2015-10-07 20:19:13 -0700233 int argc, char * const argv[])
Mike Frysingerf79507e2008-01-29 18:21:05 -0500234{
Mike Frysingere60644a2008-04-13 19:42:18 -0400235 unsigned long ret;
236
Mike Frysingerf79507e2008-01-29 18:21:05 -0500237 /*
Mike Frysingere60644a2008-04-13 19:42:18 -0400238 * pass address parameter as argv[0] (aka command name),
239 * and all remaining args
240 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000241 ret = entry(argc, argv);
Mike Frysingerf79507e2008-01-29 18:21:05 -0500242
Mike Frysingere60644a2008-04-13 19:42:18 -0400243 return ret;
244}
wdenk458ded32002-09-20 10:59:08 +0000245
Bin Meng53f3afb2015-10-07 20:19:13 -0700246/*
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000247 * Determine if a valid ELF image exists at the given memory location.
Bin Meng53f3afb2015-10-07 20:19:13 -0700248 * First look at the ELF header magic field, then make sure that it is
249 * executable.
250 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000251int valid_elf_image(unsigned long addr)
252{
Bin Meng53f3afb2015-10-07 20:19:13 -0700253 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000254
Bin Meng53f3afb2015-10-07 20:19:13 -0700255 ehdr = (Elf32_Ehdr *)addr;
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000256
257 if (!IS_ELF(*ehdr)) {
258 printf("## No elf image at address 0x%08lx\n", addr);
259 return 0;
260 }
261
262 if (ehdr->e_type != ET_EXEC) {
263 printf("## Not a 32-bit elf image at address 0x%08lx\n", addr);
264 return 0;
265 }
266
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000267 return 1;
268}
269
Bin Meng53f3afb2015-10-07 20:19:13 -0700270/* Interpreter command to boot an arbitrary ELF image from memory */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000271int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk458ded32002-09-20 10:59:08 +0000272{
Bin Meng53f3afb2015-10-07 20:19:13 -0700273 unsigned long addr; /* Address of the ELF image */
274 unsigned long rc; /* Return value from user code */
Tom Rini3c95c792017-05-18 17:03:07 -0400275 char *sload = NULL;
Simon Glass64b723f2017-08-03 12:22:12 -0600276 const char *ep = env_get("autostart");
wdenk458ded32002-09-20 10:59:08 +0000277 int rcode = 0;
278
Tom Rini3c95c792017-05-18 17:03:07 -0400279 /* Consume 'bootelf' */
280 argc--; argv++;
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400281
Tom Rini3c95c792017-05-18 17:03:07 -0400282 /* Check for flag. */
283 if (argc >= 1 && (argv[0][0] == '-' && \
284 (argv[0][1] == 'p' || argv[0][1] == 's'))) {
285 sload = argv[0];
286 /* Consume flag. */
287 argc--; argv++;
288 }
289 /* Check for address. */
290 if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) {
291 /* Consume address */
292 argc--; argv++;
293 } else
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400294 addr = load_addr;
wdenk458ded32002-09-20 10:59:08 +0000295
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000296 if (!valid_elf_image(addr))
wdenk458ded32002-09-20 10:59:08 +0000297 return 1;
298
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400299 if (sload && sload[1] == 'p')
300 addr = load_elf_image_phdr(addr);
301 else
302 addr = load_elf_image_shdr(addr);
wdenk458ded32002-09-20 10:59:08 +0000303
Siva Durga Prasad Paladugu3825bfa2015-03-09 12:46:47 +0100304 if (ep && !strcmp(ep, "no"))
305 return rcode;
306
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000307 printf("## Starting application at 0x%08lx ...\n", addr);
wdenk458ded32002-09-20 10:59:08 +0000308
wdenk458ded32002-09-20 10:59:08 +0000309 /*
310 * pass address parameter as argv[0] (aka command name),
311 * and all remaining args
312 */
Tom Rini3c95c792017-05-18 17:03:07 -0400313 rc = do_bootelf_exec((void *)addr, argc, argv);
wdenk458ded32002-09-20 10:59:08 +0000314 if (rc != 0)
315 rcode = 1;
316
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000317 printf("## Application terminated, rc = 0x%lx\n", rc);
Bin Meng53f3afb2015-10-07 20:19:13 -0700318
wdenk458ded32002-09-20 10:59:08 +0000319 return rcode;
320}
321
Bin Meng53f3afb2015-10-07 20:19:13 -0700322/*
wdenk458ded32002-09-20 10:59:08 +0000323 * Interpreter command to boot VxWorks from a memory image. The image can
324 * be either an ELF image or a raw binary. Will attempt to setup the
325 * bootline and other parameters correctly.
Bin Meng53f3afb2015-10-07 20:19:13 -0700326 */
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000327int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk458ded32002-09-20 10:59:08 +0000328{
Bin Meng53f3afb2015-10-07 20:19:13 -0700329 unsigned long addr; /* Address of image */
Bin Meng75f4b722018-04-11 22:02:22 -0700330 unsigned long bootaddr = 0; /* Address to put the bootline */
Bin Meng53f3afb2015-10-07 20:19:13 -0700331 char *bootline; /* Text of the bootline */
332 char *tmp; /* Temporary char pointer */
333 char build_buf[128]; /* Buffer for building the bootline */
Bin Meng0401c862015-10-07 20:19:15 -0700334 int ptr = 0;
Bin Meng321e8602015-10-07 20:19:18 -0700335#ifdef CONFIG_X86
Bin Menge3be8902018-04-11 22:02:07 -0700336 ulong base;
Bin Mengdde4ebb2018-04-11 22:02:09 -0700337 struct e820_info *info;
Bin Meng4b8fc742018-04-11 22:02:11 -0700338 struct e820_entry *data;
Bin Meng71606c42018-04-11 22:02:19 -0700339 struct efi_gop_info *gop;
340 struct vesa_mode_info *vesa = &mode_info.vesa;
Bin Meng321e8602015-10-07 20:19:18 -0700341#endif
wdenk458ded32002-09-20 10:59:08 +0000342
Bin Meng53f3afb2015-10-07 20:19:13 -0700343 /*
wdenk458ded32002-09-20 10:59:08 +0000344 * Check the loadaddr variable.
345 * If we don't know where the image is then we're done.
346 */
Stany MARCELe5deaf582013-11-27 14:48:43 +0100347 if (argc < 2)
Stefan Roese00487782006-11-29 12:53:15 +0100348 addr = load_addr;
349 else
Stany MARCELe5deaf582013-11-27 14:48:43 +0100350 addr = simple_strtoul(argv[1], NULL, 16);
wdenk458ded32002-09-20 10:59:08 +0000351
Jon Loeliger54324d02007-07-08 17:51:39 -0500352#if defined(CONFIG_CMD_NET)
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000353 /*
Bin Meng53f3afb2015-10-07 20:19:13 -0700354 * Check to see if we need to tftp the image ourselves
355 * before starting
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000356 */
Stany MARCELe5deaf582013-11-27 14:48:43 +0100357 if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500358 if (net_loop(TFTPGET) <= 0)
wdenk458ded32002-09-20 10:59:08 +0000359 return 1;
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000360 printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
361 addr);
wdenk458ded32002-09-20 10:59:08 +0000362 }
363#endif
364
Bin Meng53f3afb2015-10-07 20:19:13 -0700365 /*
366 * This should equate to
367 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
wdenk458ded32002-09-20 10:59:08 +0000368 * from the VxWorks BSP header files.
369 * This will vary from board to board
370 */
Tuomas Tynkkynenf66276d2018-01-21 18:16:42 +0200371#if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
Bin Meng53f3afb2015-10-07 20:19:13 -0700372 tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
Simon Glass399a9ce2017-08-03 12:22:14 -0600373 eth_env_get_enetaddr("ethaddr", (uchar *)build_buf);
Mike Frysinger8bcee042009-02-11 18:51:43 -0500374 memcpy(tmp, build_buf, 6);
wdenk458ded32002-09-20 10:59:08 +0000375#else
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000376 puts("## Ethernet MAC address not copied to NV RAM\n");
wdenk458ded32002-09-20 10:59:08 +0000377#endif
378
Bin Meng75f4b722018-04-11 22:02:22 -0700379#ifdef CONFIG_X86
380 /*
381 * Get VxWorks's physical memory base address from environment,
382 * if we don't specify it in the environment, use a default one.
383 */
384 base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE);
385 data = (struct e820_entry *)(base + E820_DATA_OFFSET);
386 info = (struct e820_info *)(base + E820_INFO_OFFSET);
387
388 memset(info, 0, sizeof(struct e820_info));
389 info->sign = E820_SIGNATURE;
390 info->entries = install_e820_map(E820MAX, data);
391 info->addr = (info->entries - 1) * sizeof(struct e820_entry) +
392 E820_DATA_OFFSET;
393
394 /*
395 * Explicitly clear the bootloader image size otherwise if memory
396 * at this offset happens to contain some garbage data, the final
397 * available memory size for the kernel is insane.
398 */
399 *(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0;
400
401 /*
402 * Prepare compatible framebuffer information block.
403 * The VESA mode has to be 32-bit RGBA.
404 */
405 if (vesa->x_resolution && vesa->y_resolution) {
406 gop = (struct efi_gop_info *)(base + EFI_GOP_INFO_OFFSET);
407 gop->magic = EFI_GOP_INFO_MAGIC;
408 gop->info.version = 0;
409 gop->info.width = vesa->x_resolution;
410 gop->info.height = vesa->y_resolution;
411 gop->info.pixel_format = EFI_GOT_RGBA8;
412 gop->info.pixels_per_scanline = vesa->bytes_per_scanline / 4;
413 gop->fb_base = vesa->phys_base_ptr;
414 gop->fb_size = vesa->bytes_per_scanline * vesa->y_resolution;
415 }
416#endif
417
wdenk57b2d802003-06-27 21:31:46 +0000418 /*
419 * Use bootaddr to find the location in memory that VxWorks
Bin Mengfb694b92015-10-07 20:19:17 -0700420 * will look for the bootline string. The default value is
421 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
422 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
wdenk458ded32002-09-20 10:59:08 +0000423 */
Simon Glass64b723f2017-08-03 12:22:12 -0600424 tmp = env_get("bootaddr");
Bin Mengfb694b92015-10-07 20:19:17 -0700425 if (!tmp) {
Bin Meng75f4b722018-04-11 22:02:22 -0700426#ifdef CONFIG_X86
427 bootaddr = base + X86_BOOT_LINE_OFFSET;
428#else
Bin Mengfb694b92015-10-07 20:19:17 -0700429 printf("## VxWorks bootline address not specified\n");
Bin Meng051f95e2018-04-11 22:02:21 -0700430 return 1;
Bin Meng75f4b722018-04-11 22:02:22 -0700431#endif
Bin Meng051f95e2018-04-11 22:02:21 -0700432 }
433
Bin Meng75f4b722018-04-11 22:02:22 -0700434 if (!bootaddr)
435 bootaddr = simple_strtoul(tmp, NULL, 16);
Bin Meng051f95e2018-04-11 22:02:21 -0700436
437 /*
438 * Check to see if the bootline is defined in the 'bootargs' parameter.
439 * If it is not defined, we may be able to construct the info.
440 */
441 bootline = env_get("bootargs");
442 if (!bootline) {
443 tmp = env_get("bootdev");
444 if (tmp) {
445 strcpy(build_buf, tmp);
446 ptr = strlen(tmp);
447 } else {
448 printf("## VxWorks boot device not specified\n");
449 }
450
451 tmp = env_get("bootfile");
452 if (tmp)
453 ptr += sprintf(build_buf + ptr, "host:%s ", tmp);
454 else
455 ptr += sprintf(build_buf + ptr, "host:vxWorks ");
wdenk458ded32002-09-20 10:59:08 +0000456
Bin Mengfb694b92015-10-07 20:19:17 -0700457 /*
Bin Meng051f95e2018-04-11 22:02:21 -0700458 * The following parameters are only needed if 'bootdev'
459 * is an ethernet device, otherwise they are optional.
Bin Mengfb694b92015-10-07 20:19:17 -0700460 */
Bin Meng051f95e2018-04-11 22:02:21 -0700461 tmp = env_get("ipaddr");
462 if (tmp) {
463 ptr += sprintf(build_buf + ptr, "e=%s", tmp);
464 tmp = env_get("netmask");
Ben Whitten34fd6c92015-12-30 13:05:58 +0000465 if (tmp) {
Bin Meng051f95e2018-04-11 22:02:21 -0700466 u32 mask = env_get_ip("netmask").s_addr;
Bin Mengfb694b92015-10-07 20:19:17 -0700467 ptr += sprintf(build_buf + ptr,
Bin Meng051f95e2018-04-11 22:02:21 -0700468 ":%08x ", ntohl(mask));
469 } else {
470 ptr += sprintf(build_buf + ptr, " ");
Bin Mengbf0ba252015-10-07 20:19:16 -0700471 }
Bin Meng051f95e2018-04-11 22:02:21 -0700472 }
wdenk458ded32002-09-20 10:59:08 +0000473
Bin Meng051f95e2018-04-11 22:02:21 -0700474 tmp = env_get("serverip");
475 if (tmp)
476 ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
wdenk458ded32002-09-20 10:59:08 +0000477
Bin Meng051f95e2018-04-11 22:02:21 -0700478 tmp = env_get("gatewayip");
479 if (tmp)
480 ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
Bin Mengbf0ba252015-10-07 20:19:16 -0700481
Bin Meng051f95e2018-04-11 22:02:21 -0700482 tmp = env_get("hostname");
483 if (tmp)
484 ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000485
Bin Meng051f95e2018-04-11 22:02:21 -0700486 tmp = env_get("othbootargs");
487 if (tmp) {
488 strcpy(build_buf + ptr, tmp);
489 ptr += strlen(tmp);
Bin Mengfb694b92015-10-07 20:19:17 -0700490 }
491
Bin Meng051f95e2018-04-11 22:02:21 -0700492 bootline = build_buf;
wdenk458ded32002-09-20 10:59:08 +0000493 }
494
Bin Meng051f95e2018-04-11 22:02:21 -0700495 memcpy((void *)bootaddr, bootline, max(strlen(bootline), (size_t)255));
496 flush_cache(bootaddr, max(strlen(bootline), (size_t)255));
497 printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, (char *)bootaddr);
498
wdenk57b2d802003-06-27 21:31:46 +0000499 /*
500 * If the data at the load address is an elf image, then
501 * treat it like an elf image. Otherwise, assume that it is a
Bin Meng53f3afb2015-10-07 20:19:13 -0700502 * binary image.
wdenk458ded32002-09-20 10:59:08 +0000503 */
Bin Meng53f3afb2015-10-07 20:19:13 -0700504 if (valid_elf_image(addr))
Christian Gmeinerae7d4be2018-03-20 14:18:25 +0100505 addr = load_elf_image_phdr(addr);
Bin Meng53f3afb2015-10-07 20:19:13 -0700506 else
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000507 puts("## Not an ELF image, assuming binary\n");
wdenk458ded32002-09-20 10:59:08 +0000508
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000509 printf("## Starting vxWorks at 0x%08lx ...\n", addr);
wdenk458ded32002-09-20 10:59:08 +0000510
Reinhard Arlt4fa117c2011-11-18 09:06:52 +0000511 dcache_disable();
Vasyl Vavrychuk70b551c2018-04-10 12:36:36 +0300512#if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
513 armv8_setup_psci();
514 smp_kick_all_cpus();
515#endif
516
Bin Mengf6900e22015-10-07 20:19:19 -0700517#ifdef CONFIG_X86
518 /* VxWorks on x86 uses stack to pass parameters */
519 ((asmlinkage void (*)(int))addr)(0);
520#else
Bin Meng53f3afb2015-10-07 20:19:13 -0700521 ((void (*)(int))addr)(0);
Bin Mengf6900e22015-10-07 20:19:19 -0700522#endif
wdenk458ded32002-09-20 10:59:08 +0000523
Daniel Schwierzeckfa87af32012-09-16 06:55:05 +0000524 puts("## vxWorks terminated\n");
Bin Meng53f3afb2015-10-07 20:19:13 -0700525
wdenk458ded32002-09-20 10:59:08 +0000526 return 1;
527}
528
wdenkf287a242003-07-01 21:06:45 +0000529U_BOOT_CMD(
Tom Rini3c95c792017-05-18 17:03:07 -0400530 bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600531 "Boot from an ELF image in memory",
Mike Frysingere6dc29f2010-10-02 15:44:53 -0400532 "[-p|-s] [address]\n"
533 "\t- load ELF image at [address] via program headers (-p)\n"
534 "\t or via section headers (-s)"
wdenk57b2d802003-06-27 21:31:46 +0000535);
536
wdenkf287a242003-07-01 21:06:45 +0000537U_BOOT_CMD(
Bin Meng53f3afb2015-10-07 20:19:13 -0700538 bootvx, 2, 0, do_bootvx,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600539 "Boot vxWorks from an ELF image",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200540 " [address] - load address of vxWorks ELF image."
wdenk57b2d802003-06-27 21:31:46 +0000541);