1 // SPDX-License-Identifier: BSD-2-Clause
3 * Copyright (c) 2001 William L. Pitts
18 #include <linux/linkage.h>
21 /* Allow ports to override the default behavior */
22 static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
23 int argc, char * const argv[])
28 * pass address parameter as argv[0] (aka command name),
29 * and all remaining args
31 ret = entry(argc, argv);
36 /* Interpreter command to boot an arbitrary ELF image from memory */
37 int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
39 unsigned long addr; /* Address of the ELF image */
40 unsigned long rc; /* Return value from user code */
42 const char *ep = env_get("autostart");
45 /* Consume 'bootelf' */
49 if (argc >= 1 && (argv[0][0] == '-' && \
50 (argv[0][1] == 'p' || argv[0][1] == 's'))) {
55 /* Check for address. */
56 if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) {
60 addr = image_load_addr;
62 if (!valid_elf_image(addr))
65 if (sload && sload[1] == 'p')
66 addr = load_elf_image_phdr(addr);
68 addr = load_elf_image_shdr(addr);
70 if (ep && !strcmp(ep, "no"))
73 printf("## Starting application at 0x%08lx ...\n", addr);
76 * pass address parameter as argv[0] (aka command name),
77 * and all remaining args
79 rc = do_bootelf_exec((void *)addr, argc, argv);
83 printf("## Application terminated, rc = 0x%lx\n", rc);
89 * Interpreter command to boot VxWorks from a memory image. The image can
90 * be either an ELF image or a raw binary. Will attempt to setup the
91 * bootline and other parameters correctly.
93 int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
95 unsigned long addr; /* Address of image */
96 unsigned long bootaddr = 0; /* Address to put the bootline */
97 char *bootline; /* Text of the bootline */
98 char *tmp; /* Temporary char pointer */
99 char build_buf[128]; /* Buffer for building the bootline */
103 struct e820_info *info;
104 struct e820_entry *data;
105 struct efi_gop_info *gop;
106 struct vesa_mode_info *vesa = &mode_info.vesa;
110 * Check the loadaddr variable.
111 * If we don't know where the image is then we're done.
114 addr = image_load_addr;
116 addr = simple_strtoul(argv[1], NULL, 16);
118 #if defined(CONFIG_CMD_NET)
120 * Check to see if we need to tftp the image ourselves
123 if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
124 if (net_loop(TFTPGET) <= 0)
126 printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
132 * This should equate to
133 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
134 * from the VxWorks BSP header files.
135 * This will vary from board to board
137 #if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
138 tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
139 eth_env_get_enetaddr("ethaddr", (uchar *)build_buf);
140 memcpy(tmp, build_buf, 6);
142 puts("## Ethernet MAC address not copied to NV RAM\n");
147 * Get VxWorks's physical memory base address from environment,
148 * if we don't specify it in the environment, use a default one.
150 base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE);
151 data = (struct e820_entry *)(base + E820_DATA_OFFSET);
152 info = (struct e820_info *)(base + E820_INFO_OFFSET);
154 memset(info, 0, sizeof(struct e820_info));
155 info->sign = E820_SIGNATURE;
156 info->entries = install_e820_map(E820MAX, data);
157 info->addr = (info->entries - 1) * sizeof(struct e820_entry) +
161 * Explicitly clear the bootloader image size otherwise if memory
162 * at this offset happens to contain some garbage data, the final
163 * available memory size for the kernel is insane.
165 *(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0;
168 * Prepare compatible framebuffer information block.
169 * The VESA mode has to be 32-bit RGBA.
171 if (vesa->x_resolution && vesa->y_resolution) {
172 gop = (struct efi_gop_info *)(base + EFI_GOP_INFO_OFFSET);
173 gop->magic = EFI_GOP_INFO_MAGIC;
174 gop->info.version = 0;
175 gop->info.width = vesa->x_resolution;
176 gop->info.height = vesa->y_resolution;
177 gop->info.pixel_format = EFI_GOT_RGBA8;
178 gop->info.pixels_per_scanline = vesa->bytes_per_scanline / 4;
179 gop->fb_base = vesa->phys_base_ptr;
180 gop->fb_size = vesa->bytes_per_scanline * vesa->y_resolution;
185 * Use bootaddr to find the location in memory that VxWorks
186 * will look for the bootline string. The default value is
187 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
188 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
190 tmp = env_get("bootaddr");
193 bootaddr = base + X86_BOOT_LINE_OFFSET;
195 printf("## VxWorks bootline address not specified\n");
201 bootaddr = simple_strtoul(tmp, NULL, 16);
204 * Check to see if the bootline is defined in the 'bootargs' parameter.
205 * If it is not defined, we may be able to construct the info.
207 bootline = env_get("bootargs");
209 tmp = env_get("bootdev");
211 strcpy(build_buf, tmp);
214 printf("## VxWorks boot device not specified\n");
217 tmp = env_get("bootfile");
219 ptr += sprintf(build_buf + ptr, "host:%s ", tmp);
221 ptr += sprintf(build_buf + ptr, "host:vxWorks ");
224 * The following parameters are only needed if 'bootdev'
225 * is an ethernet device, otherwise they are optional.
227 tmp = env_get("ipaddr");
229 ptr += sprintf(build_buf + ptr, "e=%s", tmp);
230 tmp = env_get("netmask");
232 u32 mask = env_get_ip("netmask").s_addr;
233 ptr += sprintf(build_buf + ptr,
234 ":%08x ", ntohl(mask));
236 ptr += sprintf(build_buf + ptr, " ");
240 tmp = env_get("serverip");
242 ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
244 tmp = env_get("gatewayip");
246 ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
248 tmp = env_get("hostname");
250 ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
252 tmp = env_get("othbootargs");
254 strcpy(build_buf + ptr, tmp);
258 bootline = build_buf;
261 memcpy((void *)bootaddr, bootline, max(strlen(bootline), (size_t)255));
262 flush_cache(bootaddr, max(strlen(bootline), (size_t)255));
263 printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, (char *)bootaddr);
266 * If the data at the load address is an elf image, then
267 * treat it like an elf image. Otherwise, assume that it is a
270 if (valid_elf_image(addr))
271 addr = load_elf_image_phdr(addr);
273 puts("## Not an ELF image, assuming binary\n");
275 printf("## Starting vxWorks at 0x%08lx ...\n", addr);
278 #if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
284 /* VxWorks on x86 uses stack to pass parameters */
285 ((asmlinkage void (*)(int))addr)(0);
287 ((void (*)(int))addr)(0);
290 puts("## vxWorks terminated\n");
296 bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf,
297 "Boot from an ELF image in memory",
298 "[-p|-s] [address]\n"
299 "\t- load ELF image at [address] via program headers (-p)\n"
300 "\t or via section headers (-s)"
304 bootvx, 2, 0, do_bootvx,
305 "Boot vxWorks from an ELF image",
306 " [address] - load address of vxWorks ELF image."