]> Git Repo - J-u-boot.git/blame - cmd/elf.c
watchdog: kconfig: Enable designware for rk3399
[J-u-boot.git] / cmd / elf.c
CommitLineData
89789ebd 1// SPDX-License-Identifier: BSD-2-Clause
458ded34
WD
2/*
3 * Copyright (c) 2001 William L. Pitts
4 * All rights reserved.
458ded34
WD
5 */
6
7#include <common.h>
8#include <command.h>
62270f43 9#include <cpu_func.h>
458ded34 10#include <elf.h>
cdbff9fc 11#include <env.h>
8e8ccfe1 12#include <image.h>
ebca3df7 13#include <net.h>
29a4c24d 14#include <vxworks.h>
b90ff0fd 15#ifdef CONFIG_X86
447ae4f7 16#include <vbe.h>
b90ff0fd 17#include <asm/e820.h>
9aa1280a 18#include <linux/linkage.h>
b90ff0fd 19#endif
458ded34 20
017e9b79 21/* Allow ports to override the default behavior */
553d8c3a 22static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
ebca3df7 23 int argc, char * const argv[])
1f1d88dd 24{
017e9b79
MF
25 unsigned long ret;
26
017e9b79
MF
27 /*
28 * pass address parameter as argv[0] (aka command name),
29 * and all remaining args
30 */
62e03d33 31 ret = entry(argc, argv);
1f1d88dd 32
017e9b79
MF
33 return ret;
34}
458ded34 35
ebca3df7 36/* Interpreter command to boot an arbitrary ELF image from memory */
62e03d33 37int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
458ded34 38{
ebca3df7
BM
39 unsigned long addr; /* Address of the ELF image */
40 unsigned long rc; /* Return value from user code */
be1b8679 41 char *sload = NULL;
00caae6d 42 const char *ep = env_get("autostart");
458ded34
WD
43 int rcode = 0;
44
be1b8679
TR
45 /* Consume 'bootelf' */
46 argc--; argv++;
f44a928e 47
be1b8679
TR
48 /* Check for flag. */
49 if (argc >= 1 && (argv[0][0] == '-' && \
50 (argv[0][1] == 'p' || argv[0][1] == 's'))) {
51 sload = argv[0];
52 /* Consume flag. */
53 argc--; argv++;
54 }
55 /* Check for address. */
56 if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) {
57 /* Consume address */
58 argc--; argv++;
59 } else
bb872dd9 60 addr = image_load_addr;
458ded34 61
62e03d33 62 if (!valid_elf_image(addr))
458ded34
WD
63 return 1;
64
f44a928e
MF
65 if (sload && sload[1] == 'p')
66 addr = load_elf_image_phdr(addr);
67 else
68 addr = load_elf_image_shdr(addr);
458ded34 69
44c8fd3a
SDPP
70 if (ep && !strcmp(ep, "no"))
71 return rcode;
72
62e03d33 73 printf("## Starting application at 0x%08lx ...\n", addr);
458ded34 74
458ded34
WD
75 /*
76 * pass address parameter as argv[0] (aka command name),
77 * and all remaining args
78 */
be1b8679 79 rc = do_bootelf_exec((void *)addr, argc, argv);
458ded34
WD
80 if (rc != 0)
81 rcode = 1;
82
62e03d33 83 printf("## Application terminated, rc = 0x%lx\n", rc);
ebca3df7 84
458ded34
WD
85 return rcode;
86}
87
ebca3df7 88/*
458ded34
WD
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.
ebca3df7 92 */
62e03d33 93int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
458ded34 94{
ebca3df7 95 unsigned long addr; /* Address of image */
79c584e5 96 unsigned long bootaddr = 0; /* Address to put the bootline */
ebca3df7
BM
97 char *bootline; /* Text of the bootline */
98 char *tmp; /* Temporary char pointer */
99 char build_buf[128]; /* Buffer for building the bootline */
7f0c3c51 100 int ptr = 0;
b90ff0fd 101#ifdef CONFIG_X86
2902be86 102 ulong base;
fa5e91f7 103 struct e820_info *info;
45519924 104 struct e820_entry *data;
447ae4f7
BM
105 struct efi_gop_info *gop;
106 struct vesa_mode_info *vesa = &mode_info.vesa;
b90ff0fd 107#endif
ebca3df7
BM
108
109 /*
458ded34
WD
110 * Check the loadaddr variable.
111 * If we don't know where the image is then we're done.
112 */
07a1a0c9 113 if (argc < 2)
bb872dd9 114 addr = image_load_addr;
1bdd4683 115 else
07a1a0c9 116 addr = simple_strtoul(argv[1], NULL, 16);
458ded34 117
baa26db4 118#if defined(CONFIG_CMD_NET)
62e03d33 119 /*
ebca3df7
BM
120 * Check to see if we need to tftp the image ourselves
121 * before starting
62e03d33 122 */
07a1a0c9 123 if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
bc0571fc 124 if (net_loop(TFTPGET) <= 0)
458ded34 125 return 1;
62e03d33
DS
126 printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
127 addr);
458ded34
WD
128 }
129#endif
130
ebca3df7
BM
131 /*
132 * This should equate to
133 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
458ded34
WD
134 * from the VxWorks BSP header files.
135 * This will vary from board to board
136 */
8996975f 137#if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
ebca3df7 138 tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
35affd7a 139 eth_env_get_enetaddr("ethaddr", (uchar *)build_buf);
62c93d92 140 memcpy(tmp, build_buf, 6);
458ded34 141#else
62e03d33 142 puts("## Ethernet MAC address not copied to NV RAM\n");
458ded34
WD
143#endif
144
79c584e5
BM
145#ifdef CONFIG_X86
146 /*
147 * Get VxWorks's physical memory base address from environment,
148 * if we don't specify it in the environment, use a default one.
149 */
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);
153
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) +
158 E820_DATA_OFFSET;
159
160 /*
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.
164 */
165 *(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0;
166
167 /*
168 * Prepare compatible framebuffer information block.
169 * The VESA mode has to be 32-bit RGBA.
170 */
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;
181 }
182#endif
183
8bde7f77
WD
184 /*
185 * Use bootaddr to find the location in memory that VxWorks
9e98b7e3
BM
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.
458ded34 189 */
00caae6d 190 tmp = env_get("bootaddr");
9e98b7e3 191 if (!tmp) {
79c584e5
BM
192#ifdef CONFIG_X86
193 bootaddr = base + X86_BOOT_LINE_OFFSET;
194#else
9e98b7e3 195 printf("## VxWorks bootline address not specified\n");
ced71a2f 196 return 1;
79c584e5 197#endif
ced71a2f
BM
198 }
199
79c584e5
BM
200 if (!bootaddr)
201 bootaddr = simple_strtoul(tmp, NULL, 16);
ced71a2f
BM
202
203 /*
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.
206 */
207 bootline = env_get("bootargs");
208 if (!bootline) {
209 tmp = env_get("bootdev");
210 if (tmp) {
211 strcpy(build_buf, tmp);
212 ptr = strlen(tmp);
213 } else {
214 printf("## VxWorks boot device not specified\n");
215 }
216
217 tmp = env_get("bootfile");
218 if (tmp)
219 ptr += sprintf(build_buf + ptr, "host:%s ", tmp);
220 else
221 ptr += sprintf(build_buf + ptr, "host:vxWorks ");
458ded34 222
9e98b7e3 223 /*
ced71a2f
BM
224 * The following parameters are only needed if 'bootdev'
225 * is an ethernet device, otherwise they are optional.
9e98b7e3 226 */
ced71a2f
BM
227 tmp = env_get("ipaddr");
228 if (tmp) {
229 ptr += sprintf(build_buf + ptr, "e=%s", tmp);
230 tmp = env_get("netmask");
192bc694 231 if (tmp) {
ced71a2f 232 u32 mask = env_get_ip("netmask").s_addr;
9e98b7e3 233 ptr += sprintf(build_buf + ptr,
ced71a2f
BM
234 ":%08x ", ntohl(mask));
235 } else {
236 ptr += sprintf(build_buf + ptr, " ");
a4092dbd 237 }
ced71a2f 238 }
458ded34 239
ced71a2f
BM
240 tmp = env_get("serverip");
241 if (tmp)
242 ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
a4092dbd 243
ced71a2f
BM
244 tmp = env_get("gatewayip");
245 if (tmp)
246 ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
458ded34 247
ced71a2f
BM
248 tmp = env_get("hostname");
249 if (tmp)
250 ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
9e98b7e3 251
ced71a2f
BM
252 tmp = env_get("othbootargs");
253 if (tmp) {
254 strcpy(build_buf + ptr, tmp);
255 ptr += strlen(tmp);
9e98b7e3 256 }
29a4c24d 257
ced71a2f 258 bootline = build_buf;
458ded34
WD
259 }
260
ced71a2f
BM
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);
264
8bde7f77
WD
265 /*
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
ebca3df7 268 * binary image.
458ded34 269 */
ebca3df7 270 if (valid_elf_image(addr))
476c2fcd 271 addr = load_elf_image_phdr(addr);
ebca3df7 272 else
62e03d33 273 puts("## Not an ELF image, assuming binary\n");
458ded34 274
62e03d33 275 printf("## Starting vxWorks at 0x%08lx ...\n", addr);
458ded34 276
6eee21da 277 dcache_disable();
3194daa1
VV
278#if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
279 armv8_setup_psci();
280 smp_kick_all_cpus();
281#endif
282
9aa1280a
BM
283#ifdef CONFIG_X86
284 /* VxWorks on x86 uses stack to pass parameters */
285 ((asmlinkage void (*)(int))addr)(0);
286#else
ebca3df7 287 ((void (*)(int))addr)(0);
9aa1280a 288#endif
458ded34 289
62e03d33 290 puts("## vxWorks terminated\n");
ebca3df7 291
458ded34
WD
292 return 1;
293}
294
0d498393 295U_BOOT_CMD(
be1b8679 296 bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf,
2fb2604d 297 "Boot from an ELF image in memory",
f44a928e
MF
298 "[-p|-s] [address]\n"
299 "\t- load ELF image at [address] via program headers (-p)\n"
300 "\t or via section headers (-s)"
8bde7f77
WD
301);
302
0d498393 303U_BOOT_CMD(
ebca3df7 304 bootvx, 2, 0, do_bootvx,
2fb2604d 305 "Boot vxWorks from an ELF image",
a89c33db 306 " [address] - load address of vxWorks ELF image."
8bde7f77 307);
This page took 0.535344 seconds and 4 git commands to generate.