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(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
40 #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP)
41 struct bootm_headers img = {0};
42 unsigned long fdt_addr = 0; /* Address of the FDT */
44 unsigned long addr; /* Address of the ELF image */
45 unsigned long rc; /* Return value from user code */
49 /* Consume 'bootelf' */
52 /* Check for [-p|-s] flag. */
53 if (argc >= 1 && (argv[0][0] == '-' && \
54 (argv[0][1] == 'p' || argv[0][1] == 's'))) {
60 #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP)
61 /* Check for [-d fdt_addr_r] option. */
62 if ((argc >= 2) && (argv[0][0] == '-') && (argv[0][1] == 'd')) {
63 if (strict_strtoul(argv[1], 16, &fdt_addr) != 0)
71 /* Check for address. */
72 if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) {
76 addr = image_load_addr;
78 if (!valid_elf_image(addr))
81 if (sload && sload[1] == 'p')
82 addr = load_elf_image_phdr(addr);
84 addr = load_elf_image_shdr(addr);
86 #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP)
88 printf("## Setting up FDT at 0x%08lx ...\n", fdt_addr);
91 if (image_setup_libfdt(&img, (void *)fdt_addr, NULL))
96 if (!env_get_autostart())
99 printf("## Starting application at 0x%08lx ...\n", addr);
103 * pass address parameter as argv[0] (aka command name),
104 * and all remaining args
106 rc = do_bootelf_exec((void *)addr, argc, argv);
110 printf("## Application terminated, rc = 0x%lx\n", rc);
116 * Interpreter command to boot VxWorks from a memory image. The image can
117 * be either an ELF image or a raw binary. Will attempt to setup the
118 * bootline and other parameters correctly.
120 int do_bootvx(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
122 unsigned long addr; /* Address of image */
123 unsigned long bootaddr = 0; /* Address to put the bootline */
124 char *bootline; /* Text of the bootline */
125 char *tmp; /* Temporary char pointer */
126 char build_buf[128]; /* Buffer for building the bootline */
130 struct e820_info *info;
131 struct e820_entry *data;
132 struct efi_gop_info *gop;
133 struct vesa_mode_info *vesa = &mode_info.vesa;
137 * Check the loadaddr variable.
138 * If we don't know where the image is then we're done.
141 addr = image_load_addr;
143 addr = hextoul(argv[1], NULL);
145 #if defined(CONFIG_CMD_NET)
147 * Check to see if we need to tftp the image ourselves
150 if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
151 if (net_loop(TFTPGET) <= 0)
153 printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
159 * This should equate to
160 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
161 * from the VxWorks BSP header files.
162 * This will vary from board to board
164 #if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
165 tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
166 eth_env_get_enetaddr("ethaddr", (uchar *)build_buf);
167 memcpy(tmp, build_buf, 6);
169 puts("## Ethernet MAC address not copied to NV RAM\n");
174 * Get VxWorks's physical memory base address from environment,
175 * if we don't specify it in the environment, use a default one.
177 base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE);
178 data = (struct e820_entry *)(base + E820_DATA_OFFSET);
179 info = (struct e820_info *)(base + E820_INFO_OFFSET);
181 memset(info, 0, sizeof(struct e820_info));
182 info->sign = E820_SIGNATURE;
183 info->entries = install_e820_map(E820MAX, data);
184 info->addr = (info->entries - 1) * sizeof(struct e820_entry) +
188 * Explicitly clear the bootloader image size otherwise if memory
189 * at this offset happens to contain some garbage data, the final
190 * available memory size for the kernel is insane.
192 *(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0;
195 * Prepare compatible framebuffer information block.
196 * The VESA mode has to be 32-bit RGBA.
198 if (vesa->x_resolution && vesa->y_resolution) {
199 gop = (struct efi_gop_info *)(base + EFI_GOP_INFO_OFFSET);
200 gop->magic = EFI_GOP_INFO_MAGIC;
201 gop->info.version = 0;
202 gop->info.width = vesa->x_resolution;
203 gop->info.height = vesa->y_resolution;
204 gop->info.pixel_format = EFI_GOT_RGBA8;
205 gop->info.pixels_per_scanline = vesa->bytes_per_scanline / 4;
206 gop->fb_base = vesa->phys_base_ptr;
207 gop->fb_size = vesa->bytes_per_scanline * vesa->y_resolution;
212 * Use bootaddr to find the location in memory that VxWorks
213 * will look for the bootline string. The default value is
214 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
215 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
217 tmp = env_get("bootaddr");
220 bootaddr = base + X86_BOOT_LINE_OFFSET;
222 printf("## VxWorks bootline address not specified\n");
228 bootaddr = hextoul(tmp, NULL);
231 * Check to see if the bootline is defined in the 'bootargs' parameter.
232 * If it is not defined, we may be able to construct the info.
234 bootline = env_get("bootargs");
236 tmp = env_get("bootdev");
238 strcpy(build_buf, tmp);
241 printf("## VxWorks boot device not specified\n");
244 tmp = env_get("bootfile");
246 ptr += sprintf(build_buf + ptr, "host:%s ", tmp);
248 ptr += sprintf(build_buf + ptr, "host:vxWorks ");
251 * The following parameters are only needed if 'bootdev'
252 * is an ethernet device, otherwise they are optional.
254 tmp = env_get("ipaddr");
256 ptr += sprintf(build_buf + ptr, "e=%s", tmp);
257 tmp = env_get("netmask");
259 u32 mask = env_get_ip("netmask").s_addr;
260 ptr += sprintf(build_buf + ptr,
261 ":%08x ", ntohl(mask));
263 ptr += sprintf(build_buf + ptr, " ");
267 tmp = env_get("serverip");
269 ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
271 tmp = env_get("gatewayip");
273 ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
275 tmp = env_get("hostname");
277 ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
279 tmp = env_get("othbootargs");
281 strcpy(build_buf + ptr, tmp);
285 bootline = build_buf;
288 memcpy((void *)bootaddr, bootline, max(strlen(bootline), (size_t)255));
289 flush_cache(bootaddr, max(strlen(bootline), (size_t)255));
290 printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, (char *)bootaddr);
293 * If the data at the load address is an elf image, then
294 * treat it like an elf image. Otherwise, assume that it is a
297 if (valid_elf_image(addr))
298 addr = load_elf_image_phdr(addr);
300 puts("## Not an ELF image, assuming binary\n");
302 printf("## Starting vxWorks at 0x%08lx ...\n", addr);
306 #if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
312 /* VxWorks on x86 uses stack to pass parameters */
313 ((asmlinkage void (*)(int))addr)(0);
315 ((void (*)(int))addr)(0);
318 puts("## vxWorks terminated\n");
324 bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf,
325 "Boot from an ELF image in memory",
327 #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP)
331 "\t- load ELF image at [address] via program headers (-p)\n"
332 "\t or via section headers (-s)\n"
333 #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP)
334 "\t- setup FDT image at [fdt_addr_r] (-d)"
339 bootvx, 2, 0, do_bootvx,
340 "Boot vxWorks from an ELF image",
341 " [address] - load address of vxWorks ELF image."