1 // SPDX-License-Identifier: BSD-2-Clause
3 * Copyright (c) 2001 William L. Pitts
17 #include <asm/cache.h>
19 #include <linux/linkage.h>
22 /* Allow ports to override the default behavior */
23 static unsigned long do_bootelf_exec(ulong (*entry
)(int, char * const[]),
24 int argc
, char * const argv
[])
29 * pass address parameter as argv[0] (aka command name),
30 * and all remaining args
32 ret
= entry(argc
, argv
);
37 /* Interpreter command to boot an arbitrary ELF image from memory */
38 int do_bootelf(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
40 unsigned long addr
; /* Address of the ELF image */
41 unsigned long rc
; /* Return value from user code */
43 const char *ep
= env_get("autostart");
46 /* Consume 'bootelf' */
50 if (argc
>= 1 && (argv
[0][0] == '-' && \
51 (argv
[0][1] == 'p' || argv
[0][1] == 's'))) {
56 /* Check for address. */
57 if (argc
>= 1 && strict_strtoul(argv
[0], 16, &addr
) != -EINVAL
) {
61 addr
= image_load_addr
;
63 if (!valid_elf_image(addr
))
66 if (sload
&& sload
[1] == 'p')
67 addr
= load_elf_image_phdr(addr
);
69 addr
= load_elf_image_shdr(addr
);
71 if (ep
&& !strcmp(ep
, "no"))
74 printf("## Starting application at 0x%08lx ...\n", addr
);
77 * pass address parameter as argv[0] (aka command name),
78 * and all remaining args
80 rc
= do_bootelf_exec((void *)addr
, argc
, argv
);
84 printf("## Application terminated, rc = 0x%lx\n", rc
);
90 * Interpreter command to boot VxWorks from a memory image. The image can
91 * be either an ELF image or a raw binary. Will attempt to setup the
92 * bootline and other parameters correctly.
94 int do_bootvx(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
96 unsigned long addr
; /* Address of image */
97 unsigned long bootaddr
= 0; /* Address to put the bootline */
98 char *bootline
; /* Text of the bootline */
99 char *tmp
; /* Temporary char pointer */
100 char build_buf
[128]; /* Buffer for building the bootline */
104 struct e820_info
*info
;
105 struct e820_entry
*data
;
106 struct efi_gop_info
*gop
;
107 struct vesa_mode_info
*vesa
= &mode_info
.vesa
;
111 * Check the loadaddr variable.
112 * If we don't know where the image is then we're done.
115 addr
= image_load_addr
;
117 addr
= simple_strtoul(argv
[1], NULL
, 16);
119 #if defined(CONFIG_CMD_NET)
121 * Check to see if we need to tftp the image ourselves
124 if ((argc
== 2) && (strcmp(argv
[1], "tftp") == 0)) {
125 if (net_loop(TFTPGET
) <= 0)
127 printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
133 * This should equate to
134 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
135 * from the VxWorks BSP header files.
136 * This will vary from board to board
138 #if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
139 tmp
= (char *)CONFIG_SYS_VXWORKS_MAC_PTR
;
140 eth_env_get_enetaddr("ethaddr", (uchar
*)build_buf
);
141 memcpy(tmp
, build_buf
, 6);
143 puts("## Ethernet MAC address not copied to NV RAM\n");
148 * Get VxWorks's physical memory base address from environment,
149 * if we don't specify it in the environment, use a default one.
151 base
= env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE
);
152 data
= (struct e820_entry
*)(base
+ E820_DATA_OFFSET
);
153 info
= (struct e820_info
*)(base
+ E820_INFO_OFFSET
);
155 memset(info
, 0, sizeof(struct e820_info
));
156 info
->sign
= E820_SIGNATURE
;
157 info
->entries
= install_e820_map(E820MAX
, data
);
158 info
->addr
= (info
->entries
- 1) * sizeof(struct e820_entry
) +
162 * Explicitly clear the bootloader image size otherwise if memory
163 * at this offset happens to contain some garbage data, the final
164 * available memory size for the kernel is insane.
166 *(u32
*)(base
+ BOOT_IMAGE_SIZE_OFFSET
) = 0;
169 * Prepare compatible framebuffer information block.
170 * The VESA mode has to be 32-bit RGBA.
172 if (vesa
->x_resolution
&& vesa
->y_resolution
) {
173 gop
= (struct efi_gop_info
*)(base
+ EFI_GOP_INFO_OFFSET
);
174 gop
->magic
= EFI_GOP_INFO_MAGIC
;
175 gop
->info
.version
= 0;
176 gop
->info
.width
= vesa
->x_resolution
;
177 gop
->info
.height
= vesa
->y_resolution
;
178 gop
->info
.pixel_format
= EFI_GOT_RGBA8
;
179 gop
->info
.pixels_per_scanline
= vesa
->bytes_per_scanline
/ 4;
180 gop
->fb_base
= vesa
->phys_base_ptr
;
181 gop
->fb_size
= vesa
->bytes_per_scanline
* vesa
->y_resolution
;
186 * Use bootaddr to find the location in memory that VxWorks
187 * will look for the bootline string. The default value is
188 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
189 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
191 tmp
= env_get("bootaddr");
194 bootaddr
= base
+ X86_BOOT_LINE_OFFSET
;
196 printf("## VxWorks bootline address not specified\n");
202 bootaddr
= simple_strtoul(tmp
, NULL
, 16);
205 * Check to see if the bootline is defined in the 'bootargs' parameter.
206 * If it is not defined, we may be able to construct the info.
208 bootline
= env_get("bootargs");
210 tmp
= env_get("bootdev");
212 strcpy(build_buf
, tmp
);
215 printf("## VxWorks boot device not specified\n");
218 tmp
= env_get("bootfile");
220 ptr
+= sprintf(build_buf
+ ptr
, "host:%s ", tmp
);
222 ptr
+= sprintf(build_buf
+ ptr
, "host:vxWorks ");
225 * The following parameters are only needed if 'bootdev'
226 * is an ethernet device, otherwise they are optional.
228 tmp
= env_get("ipaddr");
230 ptr
+= sprintf(build_buf
+ ptr
, "e=%s", tmp
);
231 tmp
= env_get("netmask");
233 u32 mask
= env_get_ip("netmask").s_addr
;
234 ptr
+= sprintf(build_buf
+ ptr
,
235 ":%08x ", ntohl(mask
));
237 ptr
+= sprintf(build_buf
+ ptr
, " ");
241 tmp
= env_get("serverip");
243 ptr
+= sprintf(build_buf
+ ptr
, "h=%s ", tmp
);
245 tmp
= env_get("gatewayip");
247 ptr
+= sprintf(build_buf
+ ptr
, "g=%s ", tmp
);
249 tmp
= env_get("hostname");
251 ptr
+= sprintf(build_buf
+ ptr
, "tn=%s ", tmp
);
253 tmp
= env_get("othbootargs");
255 strcpy(build_buf
+ ptr
, tmp
);
259 bootline
= build_buf
;
262 memcpy((void *)bootaddr
, bootline
, max(strlen(bootline
), (size_t)255));
263 flush_cache(bootaddr
, max(strlen(bootline
), (size_t)255));
264 printf("## Using bootline (@ 0x%lx): %s\n", bootaddr
, (char *)bootaddr
);
267 * If the data at the load address is an elf image, then
268 * treat it like an elf image. Otherwise, assume that it is a
271 if (valid_elf_image(addr
))
272 addr
= load_elf_image_phdr(addr
);
274 puts("## Not an ELF image, assuming binary\n");
276 printf("## Starting vxWorks at 0x%08lx ...\n", addr
);
279 #if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
285 /* VxWorks on x86 uses stack to pass parameters */
286 ((asmlinkage
void (*)(int))addr
)(0);
288 ((void (*)(int))addr
)(0);
291 puts("## vxWorks terminated\n");
297 bootelf
, CONFIG_SYS_MAXARGS
, 0, do_bootelf
,
298 "Boot from an ELF image in memory",
299 "[-p|-s] [address]\n"
300 "\t- load ELF image at [address] via program headers (-p)\n"
301 "\t or via section headers (-s)"
305 bootvx
, 2, 0, do_bootvx
,
306 "Boot vxWorks from an ELF image",
307 " [address] - load address of vxWorks ELF image."