Tom Rini | 8abb4cb | 2020-01-29 11:03:34 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-2-Clause |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2001 William L. Pitts |
| 4 | * All rights reserved. |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | 370382c | 2019-11-14 12:57:35 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 9 | #include <elf.h> |
Simon Glass | 83c2e49 | 2019-08-01 09:46:50 -0600 | [diff] [blame] | 10 | #include <env.h> |
Simon Glass | 85f1378 | 2019-12-28 10:45:03 -0700 | [diff] [blame] | 11 | #include <image.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 13 | #include <net.h> |
Niklaus Giger | f662b23 | 2008-11-03 22:15:34 +0100 | [diff] [blame] | 14 | #include <vxworks.h> |
Bin Meng | 321e860 | 2015-10-07 20:19:18 -0700 | [diff] [blame] | 15 | #ifdef CONFIG_X86 |
Simon Glass | ec86bc6 | 2022-07-30 15:52:04 -0600 | [diff] [blame] | 16 | #include <vesa.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 17 | #include <asm/cache.h> |
Bin Meng | 321e860 | 2015-10-07 20:19:18 -0700 | [diff] [blame] | 18 | #include <asm/e820.h> |
Bin Meng | f6900e2 | 2015-10-07 20:19:19 -0700 | [diff] [blame] | 19 | #include <linux/linkage.h> |
Bin Meng | 321e860 | 2015-10-07 20:19:18 -0700 | [diff] [blame] | 20 | #endif |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 21 | |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 22 | /* Interpreter command to boot an arbitrary ELF image from memory */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 23 | int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 24 | { |
Maxim Moskalets | 938f011 | 2024-03-08 00:29:14 +0300 | [diff] [blame] | 25 | #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP) |
| 26 | struct bootm_headers img = {0}; |
| 27 | unsigned long fdt_addr = 0; /* Address of the FDT */ |
| 28 | #endif |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 29 | unsigned long addr; /* Address of the ELF image */ |
| 30 | unsigned long rc; /* Return value from user code */ |
Maxim Moskalets | e4170b8 | 2024-06-05 21:43:34 +0300 | [diff] [blame] | 31 | int rcode = CMD_RET_SUCCESS; |
| 32 | Bootelf_flags flags = {0}; |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 33 | |
Tom Rini | 3c95c79 | 2017-05-18 17:03:07 -0400 | [diff] [blame] | 34 | /* Consume 'bootelf' */ |
| 35 | argc--; argv++; |
Mike Frysinger | e6dc29f | 2010-10-02 15:44:53 -0400 | [diff] [blame] | 36 | |
Maxim Moskalets | 938f011 | 2024-03-08 00:29:14 +0300 | [diff] [blame] | 37 | /* Check for [-p|-s] flag. */ |
Tom Rini | 3c95c79 | 2017-05-18 17:03:07 -0400 | [diff] [blame] | 38 | if (argc >= 1 && (argv[0][0] == '-' && \ |
| 39 | (argv[0][1] == 'p' || argv[0][1] == 's'))) { |
Maxim Moskalets | e4170b8 | 2024-06-05 21:43:34 +0300 | [diff] [blame] | 40 | if (argv[0][1] == 'p') |
| 41 | flags.phdr = 1; |
| 42 | log_debug("Using ELF header format %s\n", |
| 43 | flags.phdr ? "phdr" : "shdr"); |
Tom Rini | 3c95c79 | 2017-05-18 17:03:07 -0400 | [diff] [blame] | 44 | /* Consume flag. */ |
| 45 | argc--; argv++; |
| 46 | } |
Maxim Moskalets | 938f011 | 2024-03-08 00:29:14 +0300 | [diff] [blame] | 47 | |
| 48 | #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP) |
| 49 | /* Check for [-d fdt_addr_r] option. */ |
| 50 | if ((argc >= 2) && (argv[0][0] == '-') && (argv[0][1] == 'd')) { |
| 51 | if (strict_strtoul(argv[1], 16, &fdt_addr) != 0) |
| 52 | return CMD_RET_USAGE; |
| 53 | /* Consume option. */ |
| 54 | argc -= 2; |
| 55 | argv += 2; |
| 56 | } |
| 57 | #endif |
| 58 | |
Tom Rini | 3c95c79 | 2017-05-18 17:03:07 -0400 | [diff] [blame] | 59 | /* Check for address. */ |
| 60 | if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) { |
| 61 | /* Consume address */ |
| 62 | argc--; argv++; |
| 63 | } else |
Simon Glass | 892265d | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 64 | addr = image_load_addr; |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 65 | |
Maxim Moskalets | 938f011 | 2024-03-08 00:29:14 +0300 | [diff] [blame] | 66 | #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP) |
| 67 | if (fdt_addr) { |
Maxim Moskalets | e4170b8 | 2024-06-05 21:43:34 +0300 | [diff] [blame] | 68 | log_debug("Setting up FDT at 0x%08lx ...\n", fdt_addr); |
Maxim Moskalets | 938f011 | 2024-03-08 00:29:14 +0300 | [diff] [blame] | 69 | flush(); |
| 70 | |
| 71 | if (image_setup_libfdt(&img, (void *)fdt_addr, NULL)) |
| 72 | return 1; |
| 73 | } |
| 74 | #endif |
| 75 | |
Maxim Moskalets | e4170b8 | 2024-06-05 21:43:34 +0300 | [diff] [blame] | 76 | if (env_get_autostart()) { |
| 77 | flags.autostart = 1; |
| 78 | log_debug("Starting application at 0x%08lx ...\n", addr); |
| 79 | flush(); |
| 80 | } |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 81 | |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 82 | /* |
| 83 | * pass address parameter as argv[0] (aka command name), |
Maxim Moskalets | e4170b8 | 2024-06-05 21:43:34 +0300 | [diff] [blame] | 84 | * and all remaining arguments |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 85 | */ |
Maxim Moskalets | e4170b8 | 2024-06-05 21:43:34 +0300 | [diff] [blame] | 86 | rc = bootelf(addr, flags, argc, argv); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 87 | if (rc != 0) |
Maxim Moskalets | e4170b8 | 2024-06-05 21:43:34 +0300 | [diff] [blame] | 88 | rcode = CMD_RET_FAILURE; |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 89 | |
Maxim Moskalets | e4170b8 | 2024-06-05 21:43:34 +0300 | [diff] [blame] | 90 | if (flags.autostart) |
| 91 | { |
| 92 | if (ENOEXEC == errno) |
| 93 | log_err("Invalid ELF image\n"); |
| 94 | else |
| 95 | log_debug("## Application terminated, rc = 0x%lx\n", rc); |
| 96 | } |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 97 | |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 98 | return rcode; |
| 99 | } |
| 100 | |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 101 | /* |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 102 | * Interpreter command to boot VxWorks from a memory image. The image can |
| 103 | * be either an ELF image or a raw binary. Will attempt to setup the |
| 104 | * bootline and other parameters correctly. |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 105 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 106 | int do_bootvx(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 107 | { |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 108 | unsigned long addr; /* Address of image */ |
Bin Meng | 75f4b72 | 2018-04-11 22:02:22 -0700 | [diff] [blame] | 109 | unsigned long bootaddr = 0; /* Address to put the bootline */ |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 110 | char *bootline; /* Text of the bootline */ |
| 111 | char *tmp; /* Temporary char pointer */ |
| 112 | char build_buf[128]; /* Buffer for building the bootline */ |
Bin Meng | 0401c86 | 2015-10-07 20:19:15 -0700 | [diff] [blame] | 113 | int ptr = 0; |
Bin Meng | 321e860 | 2015-10-07 20:19:18 -0700 | [diff] [blame] | 114 | #ifdef CONFIG_X86 |
Bin Meng | e3be890 | 2018-04-11 22:02:07 -0700 | [diff] [blame] | 115 | ulong base; |
Bin Meng | dde4ebb | 2018-04-11 22:02:09 -0700 | [diff] [blame] | 116 | struct e820_info *info; |
Bin Meng | 4b8fc74 | 2018-04-11 22:02:11 -0700 | [diff] [blame] | 117 | struct e820_entry *data; |
Bin Meng | 71606c4 | 2018-04-11 22:02:19 -0700 | [diff] [blame] | 118 | struct efi_gop_info *gop; |
| 119 | struct vesa_mode_info *vesa = &mode_info.vesa; |
Bin Meng | 321e860 | 2015-10-07 20:19:18 -0700 | [diff] [blame] | 120 | #endif |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 121 | |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 122 | /* |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 123 | * Check the loadaddr variable. |
| 124 | * If we don't know where the image is then we're done. |
| 125 | */ |
Stany MARCEL | e5deaf58 | 2013-11-27 14:48:43 +0100 | [diff] [blame] | 126 | if (argc < 2) |
Simon Glass | 892265d | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 127 | addr = image_load_addr; |
Stefan Roese | 0048778 | 2006-11-29 12:53:15 +0100 | [diff] [blame] | 128 | else |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 129 | addr = hextoul(argv[1], NULL); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 130 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 131 | #if defined(CONFIG_CMD_NET) |
Daniel Schwierzeck | fa87af3 | 2012-09-16 06:55:05 +0000 | [diff] [blame] | 132 | /* |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 133 | * Check to see if we need to tftp the image ourselves |
| 134 | * before starting |
Daniel Schwierzeck | fa87af3 | 2012-09-16 06:55:05 +0000 | [diff] [blame] | 135 | */ |
Stany MARCEL | e5deaf58 | 2013-11-27 14:48:43 +0100 | [diff] [blame] | 136 | if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) { |
Joe Hershberger | c80b41b0 | 2015-04-08 01:41:21 -0500 | [diff] [blame] | 137 | if (net_loop(TFTPGET) <= 0) |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 138 | return 1; |
Daniel Schwierzeck | fa87af3 | 2012-09-16 06:55:05 +0000 | [diff] [blame] | 139 | printf("Automatic boot of VxWorks image at address 0x%08lx ...\n", |
| 140 | addr); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 141 | } |
| 142 | #endif |
| 143 | |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 144 | /* |
| 145 | * This should equate to |
| 146 | * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 147 | * from the VxWorks BSP header files. |
| 148 | * This will vary from board to board |
| 149 | */ |
Tuomas Tynkkynen | f66276d | 2018-01-21 18:16:42 +0200 | [diff] [blame] | 150 | #if defined(CONFIG_SYS_VXWORKS_MAC_PTR) |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 151 | tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR; |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 152 | eth_env_get_enetaddr("ethaddr", (uchar *)build_buf); |
Mike Frysinger | 8bcee04 | 2009-02-11 18:51:43 -0500 | [diff] [blame] | 153 | memcpy(tmp, build_buf, 6); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 154 | #else |
Daniel Schwierzeck | fa87af3 | 2012-09-16 06:55:05 +0000 | [diff] [blame] | 155 | puts("## Ethernet MAC address not copied to NV RAM\n"); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 156 | #endif |
| 157 | |
Bin Meng | 75f4b72 | 2018-04-11 22:02:22 -0700 | [diff] [blame] | 158 | #ifdef CONFIG_X86 |
| 159 | /* |
| 160 | * Get VxWorks's physical memory base address from environment, |
| 161 | * if we don't specify it in the environment, use a default one. |
| 162 | */ |
| 163 | base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE); |
| 164 | data = (struct e820_entry *)(base + E820_DATA_OFFSET); |
| 165 | info = (struct e820_info *)(base + E820_INFO_OFFSET); |
| 166 | |
| 167 | memset(info, 0, sizeof(struct e820_info)); |
| 168 | info->sign = E820_SIGNATURE; |
| 169 | info->entries = install_e820_map(E820MAX, data); |
| 170 | info->addr = (info->entries - 1) * sizeof(struct e820_entry) + |
| 171 | E820_DATA_OFFSET; |
| 172 | |
| 173 | /* |
| 174 | * Explicitly clear the bootloader image size otherwise if memory |
| 175 | * at this offset happens to contain some garbage data, the final |
| 176 | * available memory size for the kernel is insane. |
| 177 | */ |
| 178 | *(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0; |
| 179 | |
| 180 | /* |
| 181 | * Prepare compatible framebuffer information block. |
| 182 | * The VESA mode has to be 32-bit RGBA. |
| 183 | */ |
| 184 | if (vesa->x_resolution && vesa->y_resolution) { |
| 185 | gop = (struct efi_gop_info *)(base + EFI_GOP_INFO_OFFSET); |
| 186 | gop->magic = EFI_GOP_INFO_MAGIC; |
| 187 | gop->info.version = 0; |
| 188 | gop->info.width = vesa->x_resolution; |
| 189 | gop->info.height = vesa->y_resolution; |
| 190 | gop->info.pixel_format = EFI_GOT_RGBA8; |
| 191 | gop->info.pixels_per_scanline = vesa->bytes_per_scanline / 4; |
| 192 | gop->fb_base = vesa->phys_base_ptr; |
| 193 | gop->fb_size = vesa->bytes_per_scanline * vesa->y_resolution; |
| 194 | } |
| 195 | #endif |
| 196 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 197 | /* |
| 198 | * Use bootaddr to find the location in memory that VxWorks |
Bin Meng | fb694b9 | 2015-10-07 20:19:17 -0700 | [diff] [blame] | 199 | * will look for the bootline string. The default value is |
| 200 | * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by |
| 201 | * VxWorks BSP. For example, on PowerPC it defaults to 0x4200. |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 202 | */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 203 | tmp = env_get("bootaddr"); |
Bin Meng | fb694b9 | 2015-10-07 20:19:17 -0700 | [diff] [blame] | 204 | if (!tmp) { |
Bin Meng | 75f4b72 | 2018-04-11 22:02:22 -0700 | [diff] [blame] | 205 | #ifdef CONFIG_X86 |
| 206 | bootaddr = base + X86_BOOT_LINE_OFFSET; |
| 207 | #else |
Bin Meng | fb694b9 | 2015-10-07 20:19:17 -0700 | [diff] [blame] | 208 | printf("## VxWorks bootline address not specified\n"); |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 209 | return 1; |
Bin Meng | 75f4b72 | 2018-04-11 22:02:22 -0700 | [diff] [blame] | 210 | #endif |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Bin Meng | 75f4b72 | 2018-04-11 22:02:22 -0700 | [diff] [blame] | 213 | if (!bootaddr) |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 214 | bootaddr = hextoul(tmp, NULL); |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 215 | |
| 216 | /* |
| 217 | * Check to see if the bootline is defined in the 'bootargs' parameter. |
| 218 | * If it is not defined, we may be able to construct the info. |
| 219 | */ |
| 220 | bootline = env_get("bootargs"); |
| 221 | if (!bootline) { |
| 222 | tmp = env_get("bootdev"); |
| 223 | if (tmp) { |
| 224 | strcpy(build_buf, tmp); |
| 225 | ptr = strlen(tmp); |
| 226 | } else { |
| 227 | printf("## VxWorks boot device not specified\n"); |
| 228 | } |
| 229 | |
| 230 | tmp = env_get("bootfile"); |
| 231 | if (tmp) |
| 232 | ptr += sprintf(build_buf + ptr, "host:%s ", tmp); |
| 233 | else |
| 234 | ptr += sprintf(build_buf + ptr, "host:vxWorks "); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 235 | |
Bin Meng | fb694b9 | 2015-10-07 20:19:17 -0700 | [diff] [blame] | 236 | /* |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 237 | * The following parameters are only needed if 'bootdev' |
| 238 | * is an ethernet device, otherwise they are optional. |
Bin Meng | fb694b9 | 2015-10-07 20:19:17 -0700 | [diff] [blame] | 239 | */ |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 240 | tmp = env_get("ipaddr"); |
| 241 | if (tmp) { |
| 242 | ptr += sprintf(build_buf + ptr, "e=%s", tmp); |
| 243 | tmp = env_get("netmask"); |
Ben Whitten | 34fd6c9 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 244 | if (tmp) { |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 245 | u32 mask = env_get_ip("netmask").s_addr; |
Bin Meng | fb694b9 | 2015-10-07 20:19:17 -0700 | [diff] [blame] | 246 | ptr += sprintf(build_buf + ptr, |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 247 | ":%08x ", ntohl(mask)); |
| 248 | } else { |
| 249 | ptr += sprintf(build_buf + ptr, " "); |
Bin Meng | bf0ba25 | 2015-10-07 20:19:16 -0700 | [diff] [blame] | 250 | } |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 251 | } |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 252 | |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 253 | tmp = env_get("serverip"); |
| 254 | if (tmp) |
| 255 | ptr += sprintf(build_buf + ptr, "h=%s ", tmp); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 256 | |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 257 | tmp = env_get("gatewayip"); |
| 258 | if (tmp) |
| 259 | ptr += sprintf(build_buf + ptr, "g=%s ", tmp); |
Bin Meng | bf0ba25 | 2015-10-07 20:19:16 -0700 | [diff] [blame] | 260 | |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 261 | tmp = env_get("hostname"); |
| 262 | if (tmp) |
| 263 | ptr += sprintf(build_buf + ptr, "tn=%s ", tmp); |
Daniel Schwierzeck | fa87af3 | 2012-09-16 06:55:05 +0000 | [diff] [blame] | 264 | |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 265 | tmp = env_get("othbootargs"); |
| 266 | if (tmp) { |
| 267 | strcpy(build_buf + ptr, tmp); |
| 268 | ptr += strlen(tmp); |
Bin Meng | fb694b9 | 2015-10-07 20:19:17 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 271 | bootline = build_buf; |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Bin Meng | 051f95e | 2018-04-11 22:02:21 -0700 | [diff] [blame] | 274 | memcpy((void *)bootaddr, bootline, max(strlen(bootline), (size_t)255)); |
| 275 | flush_cache(bootaddr, max(strlen(bootline), (size_t)255)); |
| 276 | printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, (char *)bootaddr); |
| 277 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 278 | /* |
| 279 | * If the data at the load address is an elf image, then |
| 280 | * treat it like an elf image. Otherwise, assume that it is a |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 281 | * binary image. |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 282 | */ |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 283 | if (valid_elf_image(addr)) |
Christian Gmeiner | ae7d4be | 2018-03-20 14:18:25 +0100 | [diff] [blame] | 284 | addr = load_elf_image_phdr(addr); |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 285 | else |
Daniel Schwierzeck | fa87af3 | 2012-09-16 06:55:05 +0000 | [diff] [blame] | 286 | puts("## Not an ELF image, assuming binary\n"); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 287 | |
Daniel Schwierzeck | fa87af3 | 2012-09-16 06:55:05 +0000 | [diff] [blame] | 288 | printf("## Starting vxWorks at 0x%08lx ...\n", addr); |
Pali Rohár | 937b7d8 | 2022-09-05 11:31:21 +0200 | [diff] [blame] | 289 | flush(); |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 290 | |
Reinhard Arlt | 4fa117c | 2011-11-18 09:06:52 +0000 | [diff] [blame] | 291 | dcache_disable(); |
Vasyl Vavrychuk | 70b551c | 2018-04-10 12:36:36 +0300 | [diff] [blame] | 292 | #if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI) |
| 293 | armv8_setup_psci(); |
| 294 | smp_kick_all_cpus(); |
| 295 | #endif |
| 296 | |
Bin Meng | f6900e2 | 2015-10-07 20:19:19 -0700 | [diff] [blame] | 297 | #ifdef CONFIG_X86 |
| 298 | /* VxWorks on x86 uses stack to pass parameters */ |
| 299 | ((asmlinkage void (*)(int))addr)(0); |
| 300 | #else |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 301 | ((void (*)(int))addr)(0); |
Bin Meng | f6900e2 | 2015-10-07 20:19:19 -0700 | [diff] [blame] | 302 | #endif |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 303 | |
Daniel Schwierzeck | fa87af3 | 2012-09-16 06:55:05 +0000 | [diff] [blame] | 304 | puts("## vxWorks terminated\n"); |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 305 | |
wdenk | 458ded3 | 2002-09-20 10:59:08 +0000 | [diff] [blame] | 306 | return 1; |
| 307 | } |
| 308 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 309 | U_BOOT_CMD( |
Tom Rini | 3c95c79 | 2017-05-18 17:03:07 -0400 | [diff] [blame] | 310 | bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 311 | "Boot from an ELF image in memory", |
Maxim Moskalets | 938f011 | 2024-03-08 00:29:14 +0300 | [diff] [blame] | 312 | "[-p|-s] " |
| 313 | #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP) |
| 314 | "[-d fdt_addr_r] " |
| 315 | #endif |
| 316 | "[address]\n" |
Mike Frysinger | e6dc29f | 2010-10-02 15:44:53 -0400 | [diff] [blame] | 317 | "\t- load ELF image at [address] via program headers (-p)\n" |
Maxim Moskalets | 938f011 | 2024-03-08 00:29:14 +0300 | [diff] [blame] | 318 | "\t or via section headers (-s)\n" |
| 319 | #if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP) |
| 320 | "\t- setup FDT image at [fdt_addr_r] (-d)" |
| 321 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 322 | ); |
| 323 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 324 | U_BOOT_CMD( |
Bin Meng | 53f3afb | 2015-10-07 20:19:13 -0700 | [diff] [blame] | 325 | bootvx, 2, 0, do_bootvx, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 326 | "Boot vxWorks from an ELF image", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 327 | " [address] - load address of vxWorks ELF image." |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 328 | ); |