1 // SPDX-License-Identifier: BSD-2-Clause
3 * Copyright (c) 2001 William L. Pitts
13 #ifdef CONFIG_CMD_ELF_BOOTVX
19 #include <asm/cache.h>
21 #include <linux/linkage.h>
24 /* Interpreter command to boot an arbitrary ELF image from memory */
25 int do_bootelf(struct cmd_tbl
*cmdtp
, int flag
, int argc
, char *const argv
[])
27 #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP)
28 struct bootm_headers img
= {0};
29 unsigned long fdt_addr
= 0; /* Address of the FDT */
31 unsigned long addr
; /* Address of the ELF image */
32 unsigned long rc
; /* Return value from user code */
33 int rcode
= CMD_RET_SUCCESS
;
34 Bootelf_flags flags
= {0};
36 /* Consume 'bootelf' */
39 /* Check for [-p|-s] flag. */
40 if (argc
>= 1 && (argv
[0][0] == '-' && \
41 (argv
[0][1] == 'p' || argv
[0][1] == 's'))) {
42 if (argv
[0][1] == 'p')
44 log_debug("Using ELF header format %s\n",
45 flags
.phdr
? "phdr" : "shdr");
50 #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP)
51 /* Check for [-d fdt_addr_r] option. */
52 if ((argc
>= 2) && (argv
[0][0] == '-') && (argv
[0][1] == 'd')) {
53 if (strict_strtoul(argv
[1], 16, &fdt_addr
) != 0)
61 /* Check for address. */
62 if (argc
>= 1 && strict_strtoul(argv
[0], 16, &addr
) != -EINVAL
) {
66 addr
= image_load_addr
;
68 #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP)
70 log_debug("Setting up FDT at 0x%08lx ...\n", fdt_addr
);
73 fdt_set_totalsize((void *)fdt_addr
,
74 fdt_totalsize(fdt_addr
) + CONFIG_SYS_FDT_PAD
);
75 if (image_setup_libfdt(&img
, (void *)fdt_addr
, false))
80 if (env_get_autostart()) {
82 log_debug("Starting application at 0x%08lx ...\n", addr
);
87 * pass address parameter as argv[0] (aka command name),
88 * and all remaining arguments
90 rc
= bootelf(addr
, flags
, argc
, argv
);
92 rcode
= CMD_RET_FAILURE
;
97 log_err("Invalid ELF image\n");
99 log_debug("## Application terminated, rc = 0x%lx\n", rc
);
105 #ifdef CONFIG_CMD_ELF_BOOTVX
107 * Interpreter command to boot VxWorks from a memory image. The image can
108 * be either an ELF image or a raw binary. Will attempt to setup the
109 * bootline and other parameters correctly.
111 int do_bootvx(struct cmd_tbl
*cmdtp
, int flag
, int argc
, char *const argv
[])
113 unsigned long addr
; /* Address of image */
114 unsigned long bootaddr
= 0; /* Address to put the bootline */
115 char *bootline
; /* Text of the bootline */
116 char *tmp
; /* Temporary char pointer */
117 char build_buf
[128]; /* Buffer for building the bootline */
121 struct e820_info
*info
;
122 struct e820_entry
*data
;
123 struct efi_gop_info
*gop
;
124 struct vesa_mode_info
*vesa
= &mode_info
.vesa
;
128 * Check the loadaddr variable.
129 * If we don't know where the image is then we're done.
132 addr
= image_load_addr
;
134 addr
= hextoul(argv
[1], NULL
);
136 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_NET_LWIP)
138 * Check to see if we need to tftp the image ourselves
141 if ((argc
== 2) && (strcmp(argv
[1], "tftp") == 0)) {
142 if (net_loop(TFTPGET
) <= 0)
144 printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
150 * This should equate to
151 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
152 * from the VxWorks BSP header files.
153 * This will vary from board to board
155 #if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
156 tmp
= (char *)CONFIG_SYS_VXWORKS_MAC_PTR
;
157 eth_env_get_enetaddr("ethaddr", (uchar
*)build_buf
);
158 memcpy(tmp
, build_buf
, 6);
160 puts("## Ethernet MAC address not copied to NV RAM\n");
165 * Get VxWorks's physical memory base address from environment,
166 * if we don't specify it in the environment, use a default one.
168 base
= env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE
);
169 data
= (struct e820_entry
*)(base
+ E820_DATA_OFFSET
);
170 info
= (struct e820_info
*)(base
+ E820_INFO_OFFSET
);
172 memset(info
, 0, sizeof(struct e820_info
));
173 info
->sign
= E820_SIGNATURE
;
174 info
->entries
= install_e820_map(E820MAX
, data
);
175 info
->addr
= (info
->entries
- 1) * sizeof(struct e820_entry
) +
179 * Explicitly clear the bootloader image size otherwise if memory
180 * at this offset happens to contain some garbage data, the final
181 * available memory size for the kernel is insane.
183 *(u32
*)(base
+ BOOT_IMAGE_SIZE_OFFSET
) = 0;
186 * Prepare compatible framebuffer information block.
187 * The VESA mode has to be 32-bit RGBA.
189 if (vesa
->x_resolution
&& vesa
->y_resolution
) {
190 gop
= (struct efi_gop_info
*)(base
+ EFI_GOP_INFO_OFFSET
);
191 gop
->magic
= EFI_GOP_INFO_MAGIC
;
192 gop
->info
.version
= 0;
193 gop
->info
.width
= vesa
->x_resolution
;
194 gop
->info
.height
= vesa
->y_resolution
;
195 gop
->info
.pixel_format
= EFI_GOT_RGBA8
;
196 gop
->info
.pixels_per_scanline
= vesa
->bytes_per_scanline
/ 4;
197 gop
->fb_base
= vesa
->phys_base_ptr
;
198 gop
->fb_size
= vesa
->bytes_per_scanline
* vesa
->y_resolution
;
203 * Use bootaddr to find the location in memory that VxWorks
204 * will look for the bootline string. The default value is
205 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
206 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
208 tmp
= env_get("bootaddr");
211 bootaddr
= base
+ X86_BOOT_LINE_OFFSET
;
213 printf("## VxWorks bootline address not specified\n");
219 bootaddr
= hextoul(tmp
, NULL
);
222 * Check to see if the bootline is defined in the 'bootargs' parameter.
223 * If it is not defined, we may be able to construct the info.
225 bootline
= env_get("bootargs");
227 tmp
= env_get("bootdev");
229 strcpy(build_buf
, tmp
);
232 printf("## VxWorks boot device not specified\n");
235 tmp
= env_get("bootfile");
237 ptr
+= sprintf(build_buf
+ ptr
, "host:%s ", tmp
);
239 ptr
+= sprintf(build_buf
+ ptr
, "host:vxWorks ");
242 * The following parameters are only needed if 'bootdev'
243 * is an ethernet device, otherwise they are optional.
245 tmp
= env_get("ipaddr");
247 ptr
+= sprintf(build_buf
+ ptr
, "e=%s", tmp
);
248 tmp
= env_get("netmask");
250 u32 mask
= env_get_ip("netmask").s_addr
;
251 ptr
+= sprintf(build_buf
+ ptr
,
252 ":%08x ", ntohl(mask
));
254 ptr
+= sprintf(build_buf
+ ptr
, " ");
258 tmp
= env_get("serverip");
260 ptr
+= sprintf(build_buf
+ ptr
, "h=%s ", tmp
);
262 tmp
= env_get("gatewayip");
264 ptr
+= sprintf(build_buf
+ ptr
, "g=%s ", tmp
);
266 tmp
= env_get("hostname");
268 ptr
+= sprintf(build_buf
+ ptr
, "tn=%s ", tmp
);
270 tmp
= env_get("othbootargs");
272 strcpy(build_buf
+ ptr
, tmp
);
276 bootline
= build_buf
;
279 memcpy((void *)bootaddr
, bootline
, max(strlen(bootline
), (size_t)255));
280 flush_cache(bootaddr
, max(strlen(bootline
), (size_t)255));
281 printf("## Using bootline (@ 0x%lx): %s\n", bootaddr
, (char *)bootaddr
);
284 * If the data at the load address is an elf image, then
285 * treat it like an elf image. Otherwise, assume that it is a
288 if (valid_elf_image(addr
))
289 addr
= load_elf_image_phdr(addr
);
291 puts("## Not an ELF image, assuming binary\n");
293 printf("## Starting vxWorks at 0x%08lx ...\n", addr
);
297 #if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
303 /* VxWorks on x86 uses stack to pass parameters */
304 ((asmlinkage
void (*)(int))addr
)(0);
306 ((void (*)(int))addr
)(0);
309 puts("## vxWorks terminated\n");
316 bootelf
, CONFIG_SYS_MAXARGS
, 0, do_bootelf
,
317 "Boot from an ELF image in memory",
319 #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP)
323 "\t- load ELF image at [address] via program headers (-p)\n"
324 "\t or via section headers (-s)\n"
325 #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP)
326 "\t- setup FDT image at [fdt_addr_r] (-d)"
330 #ifdef CONFIG_CMD_ELF_BOOTVX
332 bootvx
, 2, 0, do_bootvx
,
333 "Boot vxWorks from an ELF image",
334 " [address] - load address of vxWorks ELF image."