blob: d883be41931deea96e5a2be3fac3fb7ce4614ae6 [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 Kiernan9925f1d2018-04-01 09:22:38 +000019#include <environment.h>
Bin Mengebca3df2015-10-07 20:19:13 -070020#include <net.h>
Niklaus Giger29a4c242008-11-03 22:15:34 +010021#include <vxworks.h>
Bin Mengb90ff0f2015-10-07 20:19:18 -070022#ifdef CONFIG_X86
Bin Meng447ae4f2018-04-11 22:02:19 -070023#include <vbe.h>
Bin Mengb90ff0f2015-10-07 20:19:18 -070024#include <asm/e820.h>
Bin Meng9aa12802015-10-07 20:19:19 -070025#include <linux/linkage.h>
Bin Mengb90ff0f2015-10-07 20:19:18 -070026#endif
wdenk458ded32002-09-20 10:59:08 +000027
Bin Meng9dffa522015-10-07 20:19:14 -070028/*
Bin Meng839c4e92018-04-11 22:02:14 -070029 * A very simple ELF64 loader, assumes the image is valid, returns the
Bin Meng9dffa522015-10-07 20:19:14 -070030 * entry point address.
Bin Meng839c4e92018-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);
Kurban Mallachiev957f51e2019-02-07 14:19:45 +030056 flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
57 roundup(phdr->p_memsz, ARCH_DMA_MINALIGN));
Bin Meng839c4e92018-04-11 22:02:14 -070058 ++phdr;
59 }
60
Rob Bracero2846ea82018-07-31 22:57:42 -040061 if (ehdr->e_machine == EM_PPC64 && (ehdr->e_flags &
62 EF_PPC64_ELFV1_ABI)) {
63 /*
64 * For the 64-bit PowerPC ELF V1 ABI, e_entry is a function
65 * descriptor pointer with the first double word being the
66 * address of the entry point of the function.
67 */
68 uintptr_t addr = ehdr->e_entry;
69
70 return *(Elf64_Addr *)addr;
71 }
72
73 return ehdr->e_entry;
74}
75
76static unsigned long load_elf64_image_shdr(unsigned long addr)
77{
78 Elf64_Ehdr *ehdr; /* Elf header structure pointer */
79 Elf64_Shdr *shdr; /* Section header structure pointer */
80 unsigned char *strtab = 0; /* String table pointer */
81 unsigned char *image; /* Binary image pointer */
82 int i; /* Loop counter */
83
84 ehdr = (Elf64_Ehdr *)addr;
85
86 /* Find the section header string table for output info */
87 shdr = (Elf64_Shdr *)(addr + (ulong)ehdr->e_shoff +
88 (ehdr->e_shstrndx * sizeof(Elf64_Shdr)));
89
90 if (shdr->sh_type == SHT_STRTAB)
91 strtab = (unsigned char *)(addr + (ulong)shdr->sh_offset);
92
93 /* Load each appropriate section */
94 for (i = 0; i < ehdr->e_shnum; ++i) {
95 shdr = (Elf64_Shdr *)(addr + (ulong)ehdr->e_shoff +
96 (i * sizeof(Elf64_Shdr)));
97
98 if (!(shdr->sh_flags & SHF_ALLOC) ||
99 shdr->sh_addr == 0 || shdr->sh_size == 0) {
100 continue;
101 }
102
103 if (strtab) {
104 debug("%sing %s @ 0x%08lx (%ld bytes)\n",
105 (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
106 &strtab[shdr->sh_name],
107 (unsigned long)shdr->sh_addr,
108 (long)shdr->sh_size);
109 }
110
111 if (shdr->sh_type == SHT_NOBITS) {
112 memset((void *)(uintptr_t)shdr->sh_addr, 0,
113 shdr->sh_size);
114 } else {
115 image = (unsigned char *)addr + (ulong)shdr->sh_offset;
116 memcpy((void *)(uintptr_t)shdr->sh_addr,
117 (const void *)image, shdr->sh_size);
118 }
Neil Stainton8744d6c2018-08-20 15:46:19 +0000119 flush_cache(rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN),
120 roundup((shdr->sh_addr + shdr->sh_size),
121 ARCH_DMA_MINALIGN) -
122 rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN));
Rob Bracero2846ea82018-07-31 22:57:42 -0400123 }
124
125 if (ehdr->e_machine == EM_PPC64 && (ehdr->e_flags &
126 EF_PPC64_ELFV1_ABI)) {
127 /*
128 * For the 64-bit PowerPC ELF V1 ABI, e_entry is a function
129 * descriptor pointer with the first double word being the
130 * address of the entry point of the function.
131 */
132 uintptr_t addr = ehdr->e_entry;
133
134 return *(Elf64_Addr *)addr;
135 }
136
Bin Meng839c4e92018-04-11 22:02:14 -0700137 return ehdr->e_entry;
138}
139
140/*
141 * A very simple ELF loader, assumes the image is valid, returns the
142 * entry point address.
143 *
144 * The loader firstly reads the EFI class to see if it's a 64-bit image.
145 * If yes, call the ELF64 loader. Otherwise continue with the ELF32 loader.
Bin Meng9dffa522015-10-07 20:19:14 -0700146 */
147static unsigned long load_elf_image_phdr(unsigned long addr)
148{
149 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
150 Elf32_Phdr *phdr; /* Program header structure pointer */
151 int i;
152
153 ehdr = (Elf32_Ehdr *)addr;
Bin Meng839c4e92018-04-11 22:02:14 -0700154 if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
155 return load_elf64_image_phdr(addr);
156
Bin Meng9dffa522015-10-07 20:19:14 -0700157 phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff);
158
159 /* Load each program header */
160 for (i = 0; i < ehdr->e_phnum; ++i) {
161 void *dst = (void *)(uintptr_t)phdr->p_paddr;
162 void *src = (void *)addr + phdr->p_offset;
Bin Meng839c4e92018-04-11 22:02:14 -0700163
Bin Meng9dffa522015-10-07 20:19:14 -0700164 debug("Loading phdr %i to 0x%p (%i bytes)\n",
165 i, dst, phdr->p_filesz);
166 if (phdr->p_filesz)
167 memcpy(dst, src, phdr->p_filesz);
168 if (phdr->p_filesz != phdr->p_memsz)
169 memset(dst + phdr->p_filesz, 0x00,
170 phdr->p_memsz - phdr->p_filesz);
Kurban Mallachiev957f51e2019-02-07 14:19:45 +0300171 flush_cache(rounddown((unsigned long)dst, ARCH_DMA_MINALIGN),
172 roundup(phdr->p_memsz, ARCH_DMA_MINALIGN));
Bin Meng9dffa522015-10-07 20:19:14 -0700173 ++phdr;
174 }
175
176 return ehdr->e_entry;
177}
178
179static unsigned long load_elf_image_shdr(unsigned long addr)
180{
181 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
182 Elf32_Shdr *shdr; /* Section header structure pointer */
183 unsigned char *strtab = 0; /* String table pointer */
184 unsigned char *image; /* Binary image pointer */
185 int i; /* Loop counter */
186
187 ehdr = (Elf32_Ehdr *)addr;
Rob Bracero2846ea82018-07-31 22:57:42 -0400188 if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
189 return load_elf64_image_shdr(addr);
Bin Meng9dffa522015-10-07 20:19:14 -0700190
191 /* Find the section header string table for output info */
192 shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
193 (ehdr->e_shstrndx * sizeof(Elf32_Shdr)));
194
195 if (shdr->sh_type == SHT_STRTAB)
196 strtab = (unsigned char *)(addr + shdr->sh_offset);
197
198 /* Load each appropriate section */
199 for (i = 0; i < ehdr->e_shnum; ++i) {
200 shdr = (Elf32_Shdr *)(addr + ehdr->e_shoff +
201 (i * sizeof(Elf32_Shdr)));
202
203 if (!(shdr->sh_flags & SHF_ALLOC) ||
204 shdr->sh_addr == 0 || shdr->sh_size == 0) {
205 continue;
206 }
207
208 if (strtab) {
209 debug("%sing %s @ 0x%08lx (%ld bytes)\n",
210 (shdr->sh_type == SHT_NOBITS) ? "Clear" : "Load",
211 &strtab[shdr->sh_name],
212 (unsigned long)shdr->sh_addr,
213 (long)shdr->sh_size);
214 }
215
216 if (shdr->sh_type == SHT_NOBITS) {
217 memset((void *)(uintptr_t)shdr->sh_addr, 0,
218 shdr->sh_size);
219 } else {
220 image = (unsigned char *)addr + shdr->sh_offset;
221 memcpy((void *)(uintptr_t)shdr->sh_addr,
222 (const void *)image, shdr->sh_size);
223 }
Neil Stainton18f201e2018-09-19 10:38:07 +0100224 flush_cache(rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN),
225 roundup((shdr->sh_addr + shdr->sh_size),
226 ARCH_DMA_MINALIGN) -
227 rounddown(shdr->sh_addr, ARCH_DMA_MINALIGN));
Bin Meng9dffa522015-10-07 20:19:14 -0700228 }
229
230 return ehdr->e_entry;
231}
Mike Frysinger017e9b72008-04-13 19:42:18 -0400232
233/* Allow ports to override the default behavior */
Jeroen Hofstee553d8c32014-10-08 22:57:31 +0200234static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
Bin Mengebca3df2015-10-07 20:19:13 -0700235 int argc, char * const argv[])
Mike Frysinger1f1d88d2008-01-29 18:21:05 -0500236{
Mike Frysinger017e9b72008-04-13 19:42:18 -0400237 unsigned long ret;
238
Mike Frysinger1f1d88d2008-01-29 18:21:05 -0500239 /*
Mike Frysinger017e9b72008-04-13 19:42:18 -0400240 * pass address parameter as argv[0] (aka command name),
241 * and all remaining args
242 */
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000243 ret = entry(argc, argv);
Mike Frysinger1f1d88d2008-01-29 18:21:05 -0500244
Mike Frysinger017e9b72008-04-13 19:42:18 -0400245 return ret;
246}
wdenk458ded32002-09-20 10:59:08 +0000247
Bin Mengebca3df2015-10-07 20:19:13 -0700248/*
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000249 * Determine if a valid ELF image exists at the given memory location.
Bin Mengebca3df2015-10-07 20:19:13 -0700250 * First look at the ELF header magic field, then make sure that it is
251 * executable.
252 */
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000253int valid_elf_image(unsigned long addr)
254{
Bin Mengebca3df2015-10-07 20:19:13 -0700255 Elf32_Ehdr *ehdr; /* Elf header structure pointer */
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000256
Bin Mengebca3df2015-10-07 20:19:13 -0700257 ehdr = (Elf32_Ehdr *)addr;
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000258
259 if (!IS_ELF(*ehdr)) {
260 printf("## No elf image at address 0x%08lx\n", addr);
261 return 0;
262 }
263
264 if (ehdr->e_type != ET_EXEC) {
265 printf("## Not a 32-bit elf image at address 0x%08lx\n", addr);
266 return 0;
267 }
268
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000269 return 1;
270}
271
Bin Mengebca3df2015-10-07 20:19:13 -0700272/* Interpreter command to boot an arbitrary ELF image from memory */
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000273int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk458ded32002-09-20 10:59:08 +0000274{
Bin Mengebca3df2015-10-07 20:19:13 -0700275 unsigned long addr; /* Address of the ELF image */
276 unsigned long rc; /* Return value from user code */
Tom Rinibe1b8672017-05-18 17:03:07 -0400277 char *sload = NULL;
Simon Glass00caae62017-08-03 12:22:12 -0600278 const char *ep = env_get("autostart");
wdenk458ded32002-09-20 10:59:08 +0000279 int rcode = 0;
280
Tom Rinibe1b8672017-05-18 17:03:07 -0400281 /* Consume 'bootelf' */
282 argc--; argv++;
Mike Frysingerf44a9282010-10-02 15:44:53 -0400283
Tom Rinibe1b8672017-05-18 17:03:07 -0400284 /* Check for flag. */
285 if (argc >= 1 && (argv[0][0] == '-' && \
286 (argv[0][1] == 'p' || argv[0][1] == 's'))) {
287 sload = argv[0];
288 /* Consume flag. */
289 argc--; argv++;
290 }
291 /* Check for address. */
292 if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) {
293 /* Consume address */
294 argc--; argv++;
295 } else
Mike Frysingerf44a9282010-10-02 15:44:53 -0400296 addr = load_addr;
wdenk458ded32002-09-20 10:59:08 +0000297
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000298 if (!valid_elf_image(addr))
wdenk458ded32002-09-20 10:59:08 +0000299 return 1;
300
Mike Frysingerf44a9282010-10-02 15:44:53 -0400301 if (sload && sload[1] == 'p')
302 addr = load_elf_image_phdr(addr);
303 else
304 addr = load_elf_image_shdr(addr);
wdenk458ded32002-09-20 10:59:08 +0000305
Siva Durga Prasad Paladugu44c8fd32015-03-09 12:46:47 +0100306 if (ep && !strcmp(ep, "no"))
307 return rcode;
308
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000309 printf("## Starting application at 0x%08lx ...\n", addr);
wdenk458ded32002-09-20 10:59:08 +0000310
wdenk458ded32002-09-20 10:59:08 +0000311 /*
312 * pass address parameter as argv[0] (aka command name),
313 * and all remaining args
314 */
Tom Rinibe1b8672017-05-18 17:03:07 -0400315 rc = do_bootelf_exec((void *)addr, argc, argv);
wdenk458ded32002-09-20 10:59:08 +0000316 if (rc != 0)
317 rcode = 1;
318
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000319 printf("## Application terminated, rc = 0x%lx\n", rc);
Bin Mengebca3df2015-10-07 20:19:13 -0700320
wdenk458ded32002-09-20 10:59:08 +0000321 return rcode;
322}
323
Bin Mengebca3df2015-10-07 20:19:13 -0700324/*
wdenk458ded32002-09-20 10:59:08 +0000325 * Interpreter command to boot VxWorks from a memory image. The image can
326 * be either an ELF image or a raw binary. Will attempt to setup the
327 * bootline and other parameters correctly.
Bin Mengebca3df2015-10-07 20:19:13 -0700328 */
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000329int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk458ded32002-09-20 10:59:08 +0000330{
Bin Mengebca3df2015-10-07 20:19:13 -0700331 unsigned long addr; /* Address of image */
Bin Meng79c584e2018-04-11 22:02:22 -0700332 unsigned long bootaddr = 0; /* Address to put the bootline */
Bin Mengebca3df2015-10-07 20:19:13 -0700333 char *bootline; /* Text of the bootline */
334 char *tmp; /* Temporary char pointer */
335 char build_buf[128]; /* Buffer for building the bootline */
Bin Meng7f0c3c52015-10-07 20:19:15 -0700336 int ptr = 0;
Bin Mengb90ff0f2015-10-07 20:19:18 -0700337#ifdef CONFIG_X86
Bin Meng2902be82018-04-11 22:02:07 -0700338 ulong base;
Bin Mengfa5e91f2018-04-11 22:02:09 -0700339 struct e820_info *info;
Bin Meng45519922018-04-11 22:02:11 -0700340 struct e820_entry *data;
Bin Meng447ae4f2018-04-11 22:02:19 -0700341 struct efi_gop_info *gop;
342 struct vesa_mode_info *vesa = &mode_info.vesa;
Bin Mengb90ff0f2015-10-07 20:19:18 -0700343#endif
wdenk458ded32002-09-20 10:59:08 +0000344
Bin Mengebca3df2015-10-07 20:19:13 -0700345 /*
wdenk458ded32002-09-20 10:59:08 +0000346 * Check the loadaddr variable.
347 * If we don't know where the image is then we're done.
348 */
Stany MARCEL07a1a0c2013-11-27 14:48:43 +0100349 if (argc < 2)
Stefan Roese1bdd4682006-11-29 12:53:15 +0100350 addr = load_addr;
351 else
Stany MARCEL07a1a0c2013-11-27 14:48:43 +0100352 addr = simple_strtoul(argv[1], NULL, 16);
wdenk458ded32002-09-20 10:59:08 +0000353
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500354#if defined(CONFIG_CMD_NET)
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000355 /*
Bin Mengebca3df2015-10-07 20:19:13 -0700356 * Check to see if we need to tftp the image ourselves
357 * before starting
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000358 */
Stany MARCEL07a1a0c2013-11-27 14:48:43 +0100359 if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
Joe Hershbergerbc0571f2015-04-08 01:41:21 -0500360 if (net_loop(TFTPGET) <= 0)
wdenk458ded32002-09-20 10:59:08 +0000361 return 1;
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000362 printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
363 addr);
wdenk458ded32002-09-20 10:59:08 +0000364 }
365#endif
366
Bin Mengebca3df2015-10-07 20:19:13 -0700367 /*
368 * This should equate to
369 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
wdenk458ded32002-09-20 10:59:08 +0000370 * from the VxWorks BSP header files.
371 * This will vary from board to board
372 */
Tuomas Tynkkynen89969752018-01-21 18:16:42 +0200373#if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
Bin Mengebca3df2015-10-07 20:19:13 -0700374 tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
Simon Glass35affd72017-08-03 12:22:14 -0600375 eth_env_get_enetaddr("ethaddr", (uchar *)build_buf);
Mike Frysinger62c93d92009-02-11 18:51:43 -0500376 memcpy(tmp, build_buf, 6);
wdenk458ded32002-09-20 10:59:08 +0000377#else
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000378 puts("## Ethernet MAC address not copied to NV RAM\n");
wdenk458ded32002-09-20 10:59:08 +0000379#endif
380
Bin Meng79c584e2018-04-11 22:02:22 -0700381#ifdef CONFIG_X86
382 /*
383 * Get VxWorks's physical memory base address from environment,
384 * if we don't specify it in the environment, use a default one.
385 */
386 base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE);
387 data = (struct e820_entry *)(base + E820_DATA_OFFSET);
388 info = (struct e820_info *)(base + E820_INFO_OFFSET);
389
390 memset(info, 0, sizeof(struct e820_info));
391 info->sign = E820_SIGNATURE;
392 info->entries = install_e820_map(E820MAX, data);
393 info->addr = (info->entries - 1) * sizeof(struct e820_entry) +
394 E820_DATA_OFFSET;
395
396 /*
397 * Explicitly clear the bootloader image size otherwise if memory
398 * at this offset happens to contain some garbage data, the final
399 * available memory size for the kernel is insane.
400 */
401 *(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0;
402
403 /*
404 * Prepare compatible framebuffer information block.
405 * The VESA mode has to be 32-bit RGBA.
406 */
407 if (vesa->x_resolution && vesa->y_resolution) {
408 gop = (struct efi_gop_info *)(base + EFI_GOP_INFO_OFFSET);
409 gop->magic = EFI_GOP_INFO_MAGIC;
410 gop->info.version = 0;
411 gop->info.width = vesa->x_resolution;
412 gop->info.height = vesa->y_resolution;
413 gop->info.pixel_format = EFI_GOT_RGBA8;
414 gop->info.pixels_per_scanline = vesa->bytes_per_scanline / 4;
415 gop->fb_base = vesa->phys_base_ptr;
416 gop->fb_size = vesa->bytes_per_scanline * vesa->y_resolution;
417 }
418#endif
419
wdenk8bde7f72003-06-27 21:31:46 +0000420 /*
421 * Use bootaddr to find the location in memory that VxWorks
Bin Meng9e98b7e2015-10-07 20:19:17 -0700422 * will look for the bootline string. The default value is
423 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
424 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
wdenk458ded32002-09-20 10:59:08 +0000425 */
Simon Glass00caae62017-08-03 12:22:12 -0600426 tmp = env_get("bootaddr");
Bin Meng9e98b7e2015-10-07 20:19:17 -0700427 if (!tmp) {
Bin Meng79c584e2018-04-11 22:02:22 -0700428#ifdef CONFIG_X86
429 bootaddr = base + X86_BOOT_LINE_OFFSET;
430#else
Bin Meng9e98b7e2015-10-07 20:19:17 -0700431 printf("## VxWorks bootline address not specified\n");
Bin Mengced71a22018-04-11 22:02:21 -0700432 return 1;
Bin Meng79c584e2018-04-11 22:02:22 -0700433#endif
Bin Mengced71a22018-04-11 22:02:21 -0700434 }
wdenk458ded32002-09-20 10:59:08 +0000435
Bin Meng79c584e2018-04-11 22:02:22 -0700436 if (!bootaddr)
437 bootaddr = simple_strtoul(tmp, NULL, 16);
wdenk458ded32002-09-20 10:59:08 +0000438
Bin Mengced71a22018-04-11 22:02:21 -0700439 /*
440 * Check to see if the bootline is defined in the 'bootargs' parameter.
441 * If it is not defined, we may be able to construct the info.
442 */
443 bootline = env_get("bootargs");
444 if (!bootline) {
445 tmp = env_get("bootdev");
446 if (tmp) {
447 strcpy(build_buf, tmp);
448 ptr = strlen(tmp);
449 } else {
450 printf("## VxWorks boot device not specified\n");
Bin Menga4092db2015-10-07 20:19:16 -0700451 }
Niklaus Giger29a4c242008-11-03 22:15:34 +0100452
Bin Mengced71a22018-04-11 22:02:21 -0700453 tmp = env_get("bootfile");
454 if (tmp)
455 ptr += sprintf(build_buf + ptr, "host:%s ", tmp);
456 else
457 ptr += sprintf(build_buf + ptr, "host:vxWorks ");
458
459 /*
460 * The following parameters are only needed if 'bootdev'
461 * is an ethernet device, otherwise they are optional.
462 */
463 tmp = env_get("ipaddr");
464 if (tmp) {
465 ptr += sprintf(build_buf + ptr, "e=%s", tmp);
466 tmp = env_get("netmask");
467 if (tmp) {
468 u32 mask = env_get_ip("netmask").s_addr;
469 ptr += sprintf(build_buf + ptr,
470 ":%08x ", ntohl(mask));
471 } else {
472 ptr += sprintf(build_buf + ptr, " ");
473 }
474 }
475
476 tmp = env_get("serverip");
477 if (tmp)
478 ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
479
480 tmp = env_get("gatewayip");
481 if (tmp)
482 ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
483
484 tmp = env_get("hostname");
485 if (tmp)
486 ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
487
488 tmp = env_get("othbootargs");
489 if (tmp) {
490 strcpy(build_buf + ptr, tmp);
491 ptr += strlen(tmp);
492 }
493
494 bootline = build_buf;
wdenk458ded32002-09-20 10:59:08 +0000495 }
496
Bin Mengced71a22018-04-11 22:02:21 -0700497 memcpy((void *)bootaddr, bootline, max(strlen(bootline), (size_t)255));
498 flush_cache(bootaddr, max(strlen(bootline), (size_t)255));
499 printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, (char *)bootaddr);
500
wdenk8bde7f72003-06-27 21:31:46 +0000501 /*
502 * If the data at the load address is an elf image, then
503 * treat it like an elf image. Otherwise, assume that it is a
Bin Mengebca3df2015-10-07 20:19:13 -0700504 * binary image.
wdenk458ded32002-09-20 10:59:08 +0000505 */
Bin Mengebca3df2015-10-07 20:19:13 -0700506 if (valid_elf_image(addr))
Christian Gmeiner476c2fc2018-03-20 14:18:25 +0100507 addr = load_elf_image_phdr(addr);
Bin Mengebca3df2015-10-07 20:19:13 -0700508 else
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000509 puts("## Not an ELF image, assuming binary\n");
wdenk458ded32002-09-20 10:59:08 +0000510
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000511 printf("## Starting vxWorks at 0x%08lx ...\n", addr);
wdenk458ded32002-09-20 10:59:08 +0000512
Reinhard Arlt6eee21d2011-11-18 09:06:52 +0000513 dcache_disable();
Vasyl Vavrychuk3194daa2018-04-10 12:36:36 +0300514#if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
515 armv8_setup_psci();
516 smp_kick_all_cpus();
517#endif
518
Bin Meng9aa12802015-10-07 20:19:19 -0700519#ifdef CONFIG_X86
520 /* VxWorks on x86 uses stack to pass parameters */
521 ((asmlinkage void (*)(int))addr)(0);
522#else
Bin Mengebca3df2015-10-07 20:19:13 -0700523 ((void (*)(int))addr)(0);
Bin Meng9aa12802015-10-07 20:19:19 -0700524#endif
wdenk458ded32002-09-20 10:59:08 +0000525
Daniel Schwierzeck62e03d32012-09-16 06:55:05 +0000526 puts("## vxWorks terminated\n");
Bin Mengebca3df2015-10-07 20:19:13 -0700527
wdenk458ded32002-09-20 10:59:08 +0000528 return 1;
529}
530
wdenk0d498392003-07-01 21:06:45 +0000531U_BOOT_CMD(
Tom Rinibe1b8672017-05-18 17:03:07 -0400532 bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf,
Peter Tyser2fb26042009-01-27 18:03:12 -0600533 "Boot from an ELF image in memory",
Mike Frysingerf44a9282010-10-02 15:44:53 -0400534 "[-p|-s] [address]\n"
535 "\t- load ELF image at [address] via program headers (-p)\n"
536 "\t or via section headers (-s)"
wdenk8bde7f72003-06-27 21:31:46 +0000537);
538
wdenk0d498392003-07-01 21:06:45 +0000539U_BOOT_CMD(
Bin Mengebca3df2015-10-07 20:19:13 -0700540 bootvx, 2, 0, do_bootvx,
Peter Tyser2fb26042009-01-27 18:03:12 -0600541 "Boot vxWorks from an ELF image",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200542 " [address] - load address of vxWorks ELF image."
wdenk8bde7f72003-06-27 21:31:46 +0000543);