1 // SPDX-License-Identifier: BSD-2-Clause
3 * Copyright (c) 2001 William L. Pitts
18 #include <asm/cache.h>
20 #include <linux/linkage.h>
23 /* Allow ports to override the default behavior */
24 static unsigned long do_bootelf_exec(ulong (*entry
)(int, char * const[]),
25 int argc
, char *const argv
[])
30 * pass address parameter as argv[0] (aka command name),
31 * and all remaining args
33 ret
= entry(argc
, argv
);
38 /* Interpreter command to boot an arbitrary ELF image from memory */
39 int do_bootelf(struct cmd_tbl
*cmdtp
, int flag
, int argc
, char *const argv
[])
41 unsigned long addr
; /* Address of the ELF image */
42 unsigned long rc
; /* Return value from user code */
44 const char *ep
= env_get("autostart");
47 /* Consume 'bootelf' */
51 if (argc
>= 1 && (argv
[0][0] == '-' && \
52 (argv
[0][1] == 'p' || argv
[0][1] == 's'))) {
57 /* Check for address. */
58 if (argc
>= 1 && strict_strtoul(argv
[0], 16, &addr
) != -EINVAL
) {
62 addr
= image_load_addr
;
64 if (!valid_elf_image(addr
))
67 if (sload
&& sload
[1] == 'p')
68 addr
= load_elf_image_phdr(addr
);
70 addr
= load_elf_image_shdr(addr
);
72 if (ep
&& !strcmp(ep
, "no"))
75 printf("## Starting application at 0x%08lx ...\n", addr
);
78 * pass address parameter as argv[0] (aka command name),
79 * and all remaining args
81 rc
= do_bootelf_exec((void *)addr
, argc
, argv
);
85 printf("## Application terminated, rc = 0x%lx\n", rc
);
91 * Interpreter command to boot VxWorks from a memory image. The image can
92 * be either an ELF image or a raw binary. Will attempt to setup the
93 * bootline and other parameters correctly.
95 int do_bootvx(struct cmd_tbl
*cmdtp
, int flag
, int argc
, char *const argv
[])
97 unsigned long addr
; /* Address of image */
98 unsigned long bootaddr
= 0; /* Address to put the bootline */
99 char *bootline
; /* Text of the bootline */
100 char *tmp
; /* Temporary char pointer */
101 char build_buf
[128]; /* Buffer for building the bootline */
105 struct e820_info
*info
;
106 struct e820_entry
*data
;
107 struct efi_gop_info
*gop
;
108 struct vesa_mode_info
*vesa
= &mode_info
.vesa
;
112 * Check the loadaddr variable.
113 * If we don't know where the image is then we're done.
116 addr
= image_load_addr
;
118 addr
= simple_strtoul(argv
[1], NULL
, 16);
120 #if defined(CONFIG_CMD_NET)
122 * Check to see if we need to tftp the image ourselves
125 if ((argc
== 2) && (strcmp(argv
[1], "tftp") == 0)) {
126 if (net_loop(TFTPGET
) <= 0)
128 printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
134 * This should equate to
135 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
136 * from the VxWorks BSP header files.
137 * This will vary from board to board
139 #if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
140 tmp
= (char *)CONFIG_SYS_VXWORKS_MAC_PTR
;
141 eth_env_get_enetaddr("ethaddr", (uchar
*)build_buf
);
142 memcpy(tmp
, build_buf
, 6);
144 puts("## Ethernet MAC address not copied to NV RAM\n");
149 * Get VxWorks's physical memory base address from environment,
150 * if we don't specify it in the environment, use a default one.
152 base
= env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE
);
153 data
= (struct e820_entry
*)(base
+ E820_DATA_OFFSET
);
154 info
= (struct e820_info
*)(base
+ E820_INFO_OFFSET
);
156 memset(info
, 0, sizeof(struct e820_info
));
157 info
->sign
= E820_SIGNATURE
;
158 info
->entries
= install_e820_map(E820MAX
, data
);
159 info
->addr
= (info
->entries
- 1) * sizeof(struct e820_entry
) +
163 * Explicitly clear the bootloader image size otherwise if memory
164 * at this offset happens to contain some garbage data, the final
165 * available memory size for the kernel is insane.
167 *(u32
*)(base
+ BOOT_IMAGE_SIZE_OFFSET
) = 0;
170 * Prepare compatible framebuffer information block.
171 * The VESA mode has to be 32-bit RGBA.
173 if (vesa
->x_resolution
&& vesa
->y_resolution
) {
174 gop
= (struct efi_gop_info
*)(base
+ EFI_GOP_INFO_OFFSET
);
175 gop
->magic
= EFI_GOP_INFO_MAGIC
;
176 gop
->info
.version
= 0;
177 gop
->info
.width
= vesa
->x_resolution
;
178 gop
->info
.height
= vesa
->y_resolution
;
179 gop
->info
.pixel_format
= EFI_GOT_RGBA8
;
180 gop
->info
.pixels_per_scanline
= vesa
->bytes_per_scanline
/ 4;
181 gop
->fb_base
= vesa
->phys_base_ptr
;
182 gop
->fb_size
= vesa
->bytes_per_scanline
* vesa
->y_resolution
;
187 * Use bootaddr to find the location in memory that VxWorks
188 * will look for the bootline string. The default value is
189 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
190 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
192 tmp
= env_get("bootaddr");
195 bootaddr
= base
+ X86_BOOT_LINE_OFFSET
;
197 printf("## VxWorks bootline address not specified\n");
203 bootaddr
= simple_strtoul(tmp
, NULL
, 16);
206 * Check to see if the bootline is defined in the 'bootargs' parameter.
207 * If it is not defined, we may be able to construct the info.
209 bootline
= env_get("bootargs");
211 tmp
= env_get("bootdev");
213 strcpy(build_buf
, tmp
);
216 printf("## VxWorks boot device not specified\n");
219 tmp
= env_get("bootfile");
221 ptr
+= sprintf(build_buf
+ ptr
, "host:%s ", tmp
);
223 ptr
+= sprintf(build_buf
+ ptr
, "host:vxWorks ");
226 * The following parameters are only needed if 'bootdev'
227 * is an ethernet device, otherwise they are optional.
229 tmp
= env_get("ipaddr");
231 ptr
+= sprintf(build_buf
+ ptr
, "e=%s", tmp
);
232 tmp
= env_get("netmask");
234 u32 mask
= env_get_ip("netmask").s_addr
;
235 ptr
+= sprintf(build_buf
+ ptr
,
236 ":%08x ", ntohl(mask
));
238 ptr
+= sprintf(build_buf
+ ptr
, " ");
242 tmp
= env_get("serverip");
244 ptr
+= sprintf(build_buf
+ ptr
, "h=%s ", tmp
);
246 tmp
= env_get("gatewayip");
248 ptr
+= sprintf(build_buf
+ ptr
, "g=%s ", tmp
);
250 tmp
= env_get("hostname");
252 ptr
+= sprintf(build_buf
+ ptr
, "tn=%s ", tmp
);
254 tmp
= env_get("othbootargs");
256 strcpy(build_buf
+ ptr
, tmp
);
260 bootline
= build_buf
;
263 memcpy((void *)bootaddr
, bootline
, max(strlen(bootline
), (size_t)255));
264 flush_cache(bootaddr
, max(strlen(bootline
), (size_t)255));
265 printf("## Using bootline (@ 0x%lx): %s\n", bootaddr
, (char *)bootaddr
);
268 * If the data at the load address is an elf image, then
269 * treat it like an elf image. Otherwise, assume that it is a
272 if (valid_elf_image(addr
))
273 addr
= load_elf_image_phdr(addr
);
275 puts("## Not an ELF image, assuming binary\n");
277 printf("## Starting vxWorks at 0x%08lx ...\n", addr
);
280 #if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
286 /* VxWorks on x86 uses stack to pass parameters */
287 ((asmlinkage
void (*)(int))addr
)(0);
289 ((void (*)(int))addr
)(0);
292 puts("## vxWorks terminated\n");
298 bootelf
, CONFIG_SYS_MAXARGS
, 0, do_bootelf
,
299 "Boot from an ELF image in memory",
300 "[-p|-s] [address]\n"
301 "\t- load ELF image at [address] via program headers (-p)\n"
302 "\t or via section headers (-s)"
306 bootvx
, 2, 0, do_bootvx
,
307 "Boot vxWorks from an ELF image",
308 " [address] - load address of vxWorks ELF image."