Blame view
common/cmd_bootm.c
18.5 KB
47d1a6e1e
|
1 |
/* |
ca95c9df0
|
2 |
* (C) Copyright 2000-2009 |
47d1a6e1e
|
3 4 |
* Wolfgang Denk, DENX Software Engineering, wd@denx.de. * |
1a4596601
|
5 |
* SPDX-License-Identifier: GPL-2.0+ |
47d1a6e1e
|
6 7 8 9 10 11 |
*/ /* * Boot support */ #include <common.h> |
b63964037
|
12 |
#include <bootm.h> |
47d1a6e1e
|
13 |
#include <command.h> |
7f70e8530
|
14 |
#include <environment.h> |
90268b878
|
15 |
#include <errno.h> |
b63964037
|
16 |
#include <image.h> |
4ed6552f7
|
17 |
#include <lmb.h> |
b63964037
|
18 |
#include <malloc.h> |
0eb25b619
|
19 |
#include <mapmem.h> |
b63964037
|
20 |
#include <nand.h> |
47d1a6e1e
|
21 |
#include <asm/byteorder.h> |
5bf2766b4
|
22 |
#include <linux/compiler.h> |
b63964037
|
23 24 25 |
#include <linux/ctype.h> #include <linux/err.h> #include <u-boot/zlib.h> |
20dde48bc
|
26 |
|
1ee1180b6
|
27 |
DECLARE_GLOBAL_DATA_PTR; |
228f29ac6
|
28 |
|
baa26db41
|
29 |
#if defined(CONFIG_CMD_IMI) |
712fbcf38
|
30 |
static int image_info(unsigned long addr); |
47d1a6e1e
|
31 |
#endif |
27b207fd0
|
32 |
|
baa26db41
|
33 |
#if defined(CONFIG_CMD_IMLS) |
27b207fd0
|
34 |
#include <flash.h> |
ca5def3f3
|
35 |
#include <mtd/cfi_flash.h> |
e6f2e9023
|
36 |
extern flash_info_t flash_info[]; /* info for FLASH chips */ |
8fdf1e0f6
|
37 38 39 |
#endif #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) |
712fbcf38
|
40 |
static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
27b207fd0
|
41 |
#endif |
dee17768d
|
42 |
bootm_headers_t images; /* pointers to os/initrd/fdt images */ |
15940c9af
|
43 |
|
49c3a861d
|
44 45 |
/* we overload the cmd field with our state machine info instead of a * function pointer */ |
f74d9bd2a
|
46 |
static cmd_tbl_t cmd_bootm_sub[] = { |
49c3a861d
|
47 48 |
U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""), U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""), |
fca43cc80
|
49 |
#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
49c3a861d
|
50 51 52 53 54 |
U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""), #endif #ifdef CONFIG_OF_LIBFDT U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""), #endif |
49c3a861d
|
55 |
U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""), |
224c90d10
|
56 |
U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""), |
49c3a861d
|
57 |
U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""), |
d0ae31eb0
|
58 |
U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""), |
49c3a861d
|
59 60 |
U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""), }; |
088f1b199
|
61 |
static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc, |
712fbcf38
|
62 |
char * const argv[]) |
49c3a861d
|
63 64 |
{ int ret = 0; |
6d6f12363
|
65 |
long state; |
49c3a861d
|
66 |
cmd_tbl_t *c; |
49c3a861d
|
67 |
|
983c72f47
|
68 69 |
c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub)); argc--; argv++; |
49c3a861d
|
70 71 |
if (c) { |
6d6f12363
|
72 |
state = (long)c->cmd; |
983c72f47
|
73 |
if (state == BOOTM_STATE_START) |
35fc84fa1
|
74 |
state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER; |
47e26b1bf
|
75 76 |
} else { /* Unrecognized command */ |
4c12eeb8b
|
77 |
return CMD_RET_USAGE; |
49c3a861d
|
78 |
} |
ff6c032ea
|
79 80 |
if (((state & BOOTM_STATE_START) != BOOTM_STATE_START) && images.state >= state) { |
712fbcf38
|
81 82 |
printf("Trying to execute a command out of order "); |
4c12eeb8b
|
83 |
return CMD_RET_USAGE; |
49c3a861d
|
84 |
} |
35fc84fa1
|
85 |
ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0); |
49c3a861d
|
86 87 88 |
return ret; } |
396f635b8
|
89 90 91 |
/*******************************************************************/ /* bootm - boot application image from image in memory */ /*******************************************************************/ |
be0831593
|
92 |
|
712fbcf38
|
93 |
int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
396f635b8
|
94 |
{ |
2e5167cca
|
95 |
#ifdef CONFIG_NEEDS_MANUAL_RELOC |
521af04d8
|
96 |
static int relocated = 0; |
be0831593
|
97 |
|
be0831593
|
98 99 |
if (!relocated) { int i; |
58bd77db9
|
100 |
|
58bd77db9
|
101 102 103 |
/* relocate names of sub-command table */ for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++) cmd_bootm_sub[i].name += gd->reloc_off; |
be0831593
|
104 105 |
relocated = 1; } |
521af04d8
|
106 |
#endif |
396f635b8
|
107 |
|
49c3a861d
|
108 |
/* determine if we have a sub command */ |
983c72f47
|
109 110 |
argc--; argv++; if (argc > 0) { |
49c3a861d
|
111 |
char *endp; |
983c72f47
|
112 113 |
simple_strtoul(argv[0], &endp, 16); /* endp pointing to NULL means that argv[0] was just a |
49c3a861d
|
114 115 116 117 118 119 120 121 122 123 |
* valid number, pass it along to the normal bootm processing * * If endp is ':' or '#' assume a FIT identifier so pass * along for normal processing. * * Right now we assume the first arg should never be '-' */ if ((*endp != 0) && (*endp != ':') && (*endp != '#')) return do_bootm_subcommand(cmdtp, flag, argc, argv); } |
35fc84fa1
|
124 125 |
return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START | BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER | |
3d187b392
|
126 127 128 129 |
BOOTM_STATE_LOADOS | #if defined(CONFIG_PPC) || defined(CONFIG_MIPS) BOOTM_STATE_OS_CMDLINE | #endif |
5c427e49c
|
130 131 |
BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO, &images, 1); |
47d1a6e1e
|
132 |
} |
67d668bf9
|
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd) { const char *ep = getenv("autostart"); if (ep && !strcmp(ep, "yes")) { char *local_args[2]; local_args[0] = (char *)cmd; local_args[1] = NULL; printf("Automatic boot of image at addr 0x%08lX ... ", load_addr); return do_bootm(cmdtp, 0, 1, local_args); } return 0; } |
088f1b199
|
148 149 |
#ifdef CONFIG_SYS_LONGHELP static char bootm_help_text[] = |
1ee1180b6
|
150 151 152 153 154 155 156 |
"[addr [arg ...]] - boot application image stored in memory " "\tpassing arguments 'arg ...'; when booting a Linux kernel, " "\t'arg' can be the address of an initrd image " |
4a2ad5ff6
|
157 |
#if defined(CONFIG_OF_LIBFDT) |
98a9c4d46
|
158 159 |
"\tWhen booting a Linux kernel which requires a flat device-tree " |
5441f61a3
|
160 161 |
"\ta third argument is required which is the address of the " |
98a9c4d46
|
162 163 164 165 166 167 |
"\tdevice-tree blob. To boot that kernel without an initrd image, " "\tuse a '-' for the second argument. If you do not pass a third " "\ta bd_info struct will be passed instead " |
98a9c4d46
|
168 |
#endif |
6986a3856
|
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
#if defined(CONFIG_FIT) "\t For the new multi component uImage format (FIT) addresses " "\tmust be extened to include component or configuration unit name: " "\taddr:<subimg_uname> - direct component image specification " "\taddr#<conf_uname> - configuration specification " "\tUse iminfo command to get the list of existing component " "\timages and configurations. " #endif |
49c3a861d
|
184 185 186 187 188 189 190 191 192 193 |
" Sub-commands to do part of the bootm sequence. The sub-commands " "must be " "issued in the order below (it's ok to not issue all sub-commands): " "\tstart [addr [arg ...]] " "\tloados - load OS image " |
59af76d9c
|
194 |
#if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH) |
49c3a861d
|
195 196 197 198 199 200 201 |
"\tramdisk - relocate initrd, set env initrd_start/initrd_end " #endif #if defined(CONFIG_OF_LIBFDT) "\tfdt - relocate flat device tree " #endif |
49c3a861d
|
202 203 |
"\tcmdline - OS specific command line processing/setup " |
224c90d10
|
204 205 |
"\tbdt - OS specific bd_t processing " |
49c3a861d
|
206 207 |
"\tprep - OS specific prep before relocation or go " |
e3046ba4d
|
208 209 210 211 |
#if defined(CONFIG_TRACE) "\tfake - OS specific fake start without go " #endif |
088f1b199
|
212 213 214 215 216 217 |
"\tgo - start OS"; #endif U_BOOT_CMD( bootm, CONFIG_SYS_MAXARGS, 1, do_bootm, "boot application image from memory", bootm_help_text |
8bde7f776
|
218 |
); |
47d1a6e1e
|
219 |
|
1ee1180b6
|
220 221 222 |
/*******************************************************************/ /* bootd - boot default image */ /*******************************************************************/ |
baa26db41
|
223 |
#if defined(CONFIG_CMD_BOOTD) |
712fbcf38
|
224 |
int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
47d1a6e1e
|
225 |
{ |
73671dad4
|
226 |
return run_command(getenv("bootcmd"), flag); |
47d1a6e1e
|
227 |
} |
47d1a6e1e
|
228 |
|
0d4983930
|
229 |
U_BOOT_CMD( |
1ee1180b6
|
230 |
boot, 1, 1, do_bootd, |
2fb2604d5
|
231 |
"boot default, i.e., run 'bootcmd'", |
a89c33db9
|
232 |
"" |
9d2b18a0f
|
233 |
); |
47d1a6e1e
|
234 |
|
9d2b18a0f
|
235 |
/* keep old command name "bootd" for backward compatibility */ |
0d4983930
|
236 |
U_BOOT_CMD( |
1ee1180b6
|
237 |
bootd, 1, 1, do_bootd, |
2fb2604d5
|
238 |
"boot default, i.e., run 'bootcmd'", |
a89c33db9
|
239 |
"" |
8bde7f776
|
240 |
); |
47d1a6e1e
|
241 |
|
47d1a6e1e
|
242 |
#endif |
47d1a6e1e
|
243 |
|
47d1a6e1e
|
244 |
|
1ee1180b6
|
245 246 247 |
/*******************************************************************/ /* iminfo - print header info for a requested image */ /*******************************************************************/ |
baa26db41
|
248 |
#if defined(CONFIG_CMD_IMI) |
088f1b199
|
249 |
static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
47d1a6e1e
|
250 251 252 |
{ int arg; ulong addr; |
1ee1180b6
|
253 |
int rcode = 0; |
47d1a6e1e
|
254 |
|
47d1a6e1e
|
255 |
if (argc < 2) { |
712fbcf38
|
256 |
return image_info(load_addr); |
47d1a6e1e
|
257 |
} |
47d1a6e1e
|
258 |
|
1ee1180b6
|
259 |
for (arg = 1; arg < argc; ++arg) { |
712fbcf38
|
260 261 |
addr = simple_strtoul(argv[arg], NULL, 16); if (image_info(addr) != 0) |
1ee1180b6
|
262 |
rcode = 1; |
47d1a6e1e
|
263 264 265 |
} return rcode; } |
47d1a6e1e
|
266 |
|
712fbcf38
|
267 |
static int image_info(ulong addr) |
47d1a6e1e
|
268 |
{ |
d5934ad77
|
269 |
void *hdr = (void *)addr; |
47d1a6e1e
|
270 |
|
712fbcf38
|
271 272 273 |
printf(" ## Checking Image at %08lx ... ", addr); |
47d1a6e1e
|
274 |
|
712fbcf38
|
275 |
switch (genimg_get_format(hdr)) { |
21d29f7f9
|
276 |
#if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
d5934ad77
|
277 |
case IMAGE_FORMAT_LEGACY: |
712fbcf38
|
278 279 280 281 282 |
puts(" Legacy image found "); if (!image_check_magic(hdr)) { puts(" Bad Magic Number "); |
d5934ad77
|
283 284 |
return 1; } |
47d1a6e1e
|
285 |
|
712fbcf38
|
286 287 288 |
if (!image_check_hcrc(hdr)) { puts(" Bad Header Checksum "); |
d5934ad77
|
289 |
return 1; |
47d1a6e1e
|
290 |
} |
712fbcf38
|
291 |
image_print_contents(hdr); |
47d1a6e1e
|
292 |
|
712fbcf38
|
293 294 295 296 |
puts(" Verifying Checksum ... "); if (!image_check_dcrc(hdr)) { puts(" Bad Data CRC "); |
d5934ad77
|
297 |
return 1; |
47d1a6e1e
|
298 |
} |
712fbcf38
|
299 300 |
puts("OK "); |
d5934ad77
|
301 |
return 0; |
21d29f7f9
|
302 |
#endif |
d5934ad77
|
303 304 |
#if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: |
712fbcf38
|
305 306 |
puts(" FIT image found "); |
47d1a6e1e
|
307 |
|
712fbcf38
|
308 309 310 |
if (!fit_check_format(hdr)) { puts("Bad FIT image format! "); |
e32fea6ad
|
311 |
return 1; |
47d1a6e1e
|
312 |
} |
712fbcf38
|
313 |
fit_print_contents(hdr); |
a4f243452
|
314 |
|
b8da83665
|
315 |
if (!fit_all_image_verify(hdr)) { |
712fbcf38
|
316 317 |
puts("Bad hash in FIT image! "); |
a4f243452
|
318 319 |
return 1; } |
d5934ad77
|
320 321 322 |
return 0; #endif default: |
712fbcf38
|
323 324 |
puts("Unknown image format! "); |
d5934ad77
|
325 |
break; |
47d1a6e1e
|
326 |
} |
d5934ad77
|
327 |
return 1; |
47d1a6e1e
|
328 |
} |
0d4983930
|
329 330 |
U_BOOT_CMD( |
6d0f6bcf3
|
331 |
iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo, |
2fb2604d5
|
332 |
"print header information for application image", |
8bde7f776
|
333 334 335 336 337 338 |
"addr [addr ...] " " - print header information for application image starting at " " address 'addr' in memory; this includes verification of the " |
a89c33db9
|
339 |
" image contents (magic number, header and payload checksums)" |
8bde7f776
|
340 |
); |
25c751e9a
|
341 |
#endif |
87a449c8a
|
342 |
|
25c751e9a
|
343 |
|
1ee1180b6
|
344 345 346 |
/*******************************************************************/ /* imls - list all images found in flash */ /*******************************************************************/ |
baa26db41
|
347 |
#if defined(CONFIG_CMD_IMLS) |
8fdf1e0f6
|
348 |
static int do_imls_nor(void) |
27b207fd0
|
349 350 351 |
{ flash_info_t *info; int i, j; |
d5934ad77
|
352 |
void *hdr; |
25c751e9a
|
353 |
|
1ee1180b6
|
354 |
for (i = 0, info = &flash_info[0]; |
6d0f6bcf3
|
355 |
i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) { |
25c751e9a
|
356 |
|
27b207fd0
|
357 358 |
if (info->flash_id == FLASH_UNKNOWN) goto next_bank; |
1ee1180b6
|
359 |
for (j = 0; j < info->sector_count; ++j) { |
25c751e9a
|
360 |
|
d5934ad77
|
361 362 |
hdr = (void *)info->start[j]; if (!hdr) |
b97a2a0a2
|
363 |
goto next_sector; |
27b207fd0
|
364 |
|
712fbcf38
|
365 |
switch (genimg_get_format(hdr)) { |
21d29f7f9
|
366 |
#if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
d5934ad77
|
367 |
case IMAGE_FORMAT_LEGACY: |
712fbcf38
|
368 |
if (!image_check_hcrc(hdr)) |
d5934ad77
|
369 |
goto next_sector; |
712fbcf38
|
370 371 372 |
printf("Legacy Image at %08lX: ", (ulong)hdr); image_print_contents(hdr); |
d5934ad77
|
373 |
|
712fbcf38
|
374 375 376 377 |
puts(" Verifying Checksum ... "); if (!image_check_dcrc(hdr)) { puts("Bad Data CRC "); |
d5934ad77
|
378 |
} else { |
712fbcf38
|
379 380 |
puts("OK "); |
d5934ad77
|
381 382 |
} break; |
21d29f7f9
|
383 |
#endif |
d5934ad77
|
384 385 |
#if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: |
712fbcf38
|
386 |
if (!fit_check_format(hdr)) |
e32fea6ad
|
387 |
goto next_sector; |
712fbcf38
|
388 389 390 |
printf("FIT Image at %08lX: ", (ulong)hdr); fit_print_contents(hdr); |
d5934ad77
|
391 |
break; |
213bf8c82
|
392 |
#endif |
d5934ad77
|
393 |
default: |
27b207fd0
|
394 |
goto next_sector; |
25c751e9a
|
395 |
} |
87a449c8a
|
396 |
|
bdccc4fed
|
397 |
next_sector: ; |
c76f951a7
|
398 |
} |
bdccc4fed
|
399 |
next_bank: ; |
27b207fd0
|
400 |
} |
8fdf1e0f6
|
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
return 0; } #endif #if defined(CONFIG_CMD_IMLS_NAND) static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off, size_t len) { void *imgdata; int ret; imgdata = malloc(len); if (!imgdata) { printf("May be a Legacy Image at NAND device %d offset %08llX: ", nand_dev, off); printf(" Low memory(cannot allocate memory for image) "); return -ENOMEM; } ret = nand_read_skip_bad(nand, off, &len, imgdata); if (ret < 0 && ret != -EUCLEAN) { free(imgdata); return ret; } if (!image_check_hcrc(imgdata)) { free(imgdata); return 0; } printf("Legacy Image at NAND device %d offset %08llX: ", nand_dev, off); image_print_contents(imgdata); puts(" Verifying Checksum ... "); if (!image_check_dcrc(imgdata)) puts("Bad Data CRC "); else puts("OK "); free(imgdata); return 0; } static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off, size_t len) { void *imgdata; int ret; imgdata = malloc(len); if (!imgdata) { printf("May be a FIT Image at NAND device %d offset %08llX: ", nand_dev, off); printf(" Low memory(cannot allocate memory for image) "); return -ENOMEM; } ret = nand_read_skip_bad(nand, off, &len, imgdata); if (ret < 0 && ret != -EUCLEAN) { free(imgdata); return ret; } if (!fit_check_format(imgdata)) { free(imgdata); return 0; } printf("FIT Image at NAND device %d offset %08llX: ", nand_dev, off); fit_print_contents(imgdata); free(imgdata); return 0; } static int do_imls_nand(void) { nand_info_t *nand; int nand_dev = nand_curr_device; size_t len; loff_t off; u32 buffer[16]; if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) { puts(" No NAND devices available "); return -ENODEV; } printf(" "); for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) { nand = &nand_info[nand_dev]; if (!nand->name || !nand->size) continue; for (off = 0; off < nand->size; off += nand->erasesize) { const image_header_t *header; int ret; if (nand_block_isbad(nand, off)) continue; len = sizeof(buffer); ret = nand_read(nand, off, &len, (u8 *)buffer); if (ret < 0 && ret != -EUCLEAN) { printf("NAND read error %d at offset %08llX ", ret, off); continue; } switch (genimg_get_format(buffer)) { |
21d29f7f9
|
530 |
#if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
8fdf1e0f6
|
531 532 533 534 535 536 |
case IMAGE_FORMAT_LEGACY: header = (const image_header_t *)buffer; len = image_get_image_size(header); nand_imls_legacyimage(nand, nand_dev, off, len); break; |
21d29f7f9
|
537 |
#endif |
8fdf1e0f6
|
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
#if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: len = fit_get_size(buffer); nand_imls_fitimage(nand, nand_dev, off, len); break; #endif } } } return 0; } #endif #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int ret_nor = 0, ret_nand = 0; #if defined(CONFIG_CMD_IMLS) ret_nor = do_imls_nor(); #endif #if defined(CONFIG_CMD_IMLS_NAND) ret_nand = do_imls_nand(); #endif if (ret_nor) return ret_nor; if (ret_nand) return ret_nand; |
c76f951a7
|
570 |
|
27b207fd0
|
571 572 |
return (0); } |
c76f951a7
|
573 |
|
27b207fd0
|
574 575 |
U_BOOT_CMD( imls, 1, 1, do_imls, |
2fb2604d5
|
576 |
"list all images found in flash", |
27b207fd0
|
577 578 |
" " |
8fdf1e0f6
|
579 580 581 |
" - Prints information about all images found at sector/block " " boundaries in nor/nand flash." |
27b207fd0
|
582 |
); |
98a9c4d46
|
583 |
#endif |
47d1a6e1e
|
584 |
|
44f074c77
|
585 |
#ifdef CONFIG_CMD_BOOTZ |
a5266d6b5
|
586 |
int __weak bootz_setup(ulong image, ulong *start, ulong *end) |
44f074c77
|
587 588 589 590 591 592 593 |
{ /* Please define bootz_setup() for your platform */ puts("Your platform's zImage format isn't supported yet! "); return -1; } |
44f074c77
|
594 595 596 597 598 599 600 601 |
/* * zImage booting support */ static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], bootm_headers_t *images) { int ret; |
a5266d6b5
|
602 |
ulong zi_start, zi_end; |
44f074c77
|
603 |
|
35fc84fa1
|
604 605 |
ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, images, 1); |
44f074c77
|
606 607 |
/* Setup Linux kernel zImage entry point */ |
2b9599e01
|
608 |
if (!argc) { |
44f074c77
|
609 610 611 612 613 |
images->ep = load_addr; debug("* kernel: default image load address = 0x%08lx ", load_addr); } else { |
2b9599e01
|
614 |
images->ep = simple_strtoul(argv[0], NULL, 16); |
44f074c77
|
615 616 617 618 |
debug("* kernel: cmdline image address = 0x%08lx ", images->ep); } |
a5266d6b5
|
619 |
ret = bootz_setup(images->ep, &zi_start, &zi_end); |
44f074c77
|
620 621 622 623 |
if (ret != 0) return 1; lmb_reserve(&images->lmb, images->ep, zi_end - zi_start); |
225fd8c5d
|
624 625 626 627 |
/* * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not * have a header that provide this informaiton. */ |
d52e8575d
|
628 |
if (bootm_find_images(flag, argc, argv)) |
2b9599e01
|
629 |
return 1; |
44f074c77
|
630 |
|
2b9599e01
|
631 |
return 0; |
44f074c77
|
632 |
} |
da620222f
|
633 |
int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
44f074c77
|
634 |
{ |
35fc84fa1
|
635 |
int ret; |
44f074c77
|
636 |
|
2b9599e01
|
637 638 |
/* Consume 'bootz' */ argc--; argv++; |
44f074c77
|
639 640 |
if (bootz_start(cmdtp, flag, argc, argv, &images)) return 1; |
385501d38
|
641 642 643 644 645 |
/* * We are doing the BOOTM_STATE_LOADOS state ourselves, so must * disable interrupts ourselves */ bootm_disable_interrupts(); |
fb1b139bb
|
646 |
images.os.os = IH_OS_LINUX; |
35fc84fa1
|
647 |
ret = do_bootm_states(cmdtp, flag, argc, argv, |
fb1b139bb
|
648 649 |
BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO, |
d0ae31eb0
|
650 |
&images, 1); |
f8be7d659
|
651 |
|
35fc84fa1
|
652 |
return ret; |
44f074c77
|
653 |
} |
088f1b199
|
654 655 |
#ifdef CONFIG_SYS_LONGHELP static char bootz_help_text[] = |
017e1f3f9
|
656 657 658 659 |
"[addr [initrd[:size]] [fdt]] " " - boot Linux zImage stored in memory " |
44f074c77
|
660 661 |
"\tThe argument 'initrd' is optional and specifies the address " |
017e1f3f9
|
662 663 664 665 |
"\tof the initrd in memory. The optional argument ':size' allows " "\tspecifying the size of RAW initrd. " |
44f074c77
|
666 667 668 669 670 671 672 673 674 675 676 677 |
#if defined(CONFIG_OF_LIBFDT) "\tWhen booting a Linux kernel which requires a flat device-tree " "\ta third argument is required which is the address of the " "\tdevice-tree blob. To boot that kernel without an initrd image, " "\tuse a '-' for the second argument. If you do not pass a third " "\ta bd_info struct will be passed instead " #endif |
088f1b199
|
678 679 680 681 682 683 |
""; #endif U_BOOT_CMD( bootz, CONFIG_SYS_MAXARGS, 1, do_bootz, "boot Linux zImage image from memory", bootz_help_text |
44f074c77
|
684 685 |
); #endif /* CONFIG_CMD_BOOTZ */ |
d2b2ffe31
|
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 |
#ifdef CONFIG_CMD_BOOTI /* See Documentation/arm64/booting.txt in the Linux kernel */ struct Image_header { uint32_t code0; /* Executable code */ uint32_t code1; /* Executable code */ uint64_t text_offset; /* Image load offset, LE */ uint64_t image_size; /* Effective Image size, LE */ uint64_t res1; /* reserved */ uint64_t res2; /* reserved */ uint64_t res3; /* reserved */ uint64_t res4; /* reserved */ uint32_t magic; /* Magic number */ uint32_t res5; }; #define LINUX_ARM64_IMAGE_MAGIC 0x644d5241 static int booti_setup(bootm_headers_t *images) { struct Image_header *ih; uint64_t dst; ih = (struct Image_header *)map_sysmem(images->ep, 0); if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) { puts("Bad Linux ARM64 Image magic! "); return 1; } if (ih->image_size == 0) { puts("Image lacks image_size field, assuming 16MiB "); ih->image_size = (16 << 20); } /* * If we are not at the correct run-time location, set the new * correct location and then move the image there. */ dst = gd->bd->bi_dram[0].start + le32_to_cpu(ih->text_offset); if (images->ep != dst) { void *src; debug("Moving Image from 0x%lx to 0x%llx ", images->ep, dst); src = (void *)images->ep; images->ep = dst; memmove((void *)dst, src, le32_to_cpu(ih->image_size)); } return 0; } /* * Image booting support */ static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], bootm_headers_t *images) { int ret; struct Image_header *ih; ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, images, 1); /* Setup Linux kernel Image entry point */ if (!argc) { images->ep = load_addr; debug("* kernel: default image load address = 0x%08lx ", load_addr); } else { images->ep = simple_strtoul(argv[0], NULL, 16); debug("* kernel: cmdline image address = 0x%08lx ", images->ep); } ret = booti_setup(images); if (ret != 0) return 1; ih = (struct Image_header *)map_sysmem(images->ep, 0); lmb_reserve(&images->lmb, images->ep, le32_to_cpu(ih->image_size)); /* * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not * have a header that provide this informaiton. */ |
d52e8575d
|
779 |
if (bootm_find_images(flag, argc, argv)) |
d2b2ffe31
|
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 |
return 1; return 0; } int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int ret; /* Consume 'booti' */ argc--; argv++; if (booti_start(cmdtp, flag, argc, argv, &images)) return 1; /* * We are doing the BOOTM_STATE_LOADOS state ourselves, so must * disable interrupts ourselves */ bootm_disable_interrupts(); images.os.os = IH_OS_LINUX; ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO, &images, 1); return ret; } #ifdef CONFIG_SYS_LONGHELP static char booti_help_text[] = "[addr [initrd[:size]] [fdt]] " " - boot Linux Image stored in memory " "\tThe argument 'initrd' is optional and specifies the address " "\tof the initrd in memory. The optional argument ':size' allows " "\tspecifying the size of RAW initrd. " #if defined(CONFIG_OF_LIBFDT) "\tSince booting a Linux kernelrequires a flat device-tree " "\ta third argument is required which is the address of the " "\tdevice-tree blob. To boot that kernel without an initrd image, " "\tuse a '-' for the second argument. " #endif ""; #endif U_BOOT_CMD( booti, CONFIG_SYS_MAXARGS, 1, do_booti, "boot arm64 Linux Image image from memory", booti_help_text ); #endif /* CONFIG_CMD_BOOTI */ |