Blame view
common/cmd_bootm.c
18.5 KB
47d1a6e1e Initial revision |
1 |
/* |
ca95c9df0 Add error checkin... |
2 |
* (C) Copyright 2000-2009 |
47d1a6e1e Initial revision |
3 4 |
* Wolfgang Denk, DENX Software Engineering, wd@denx.de. * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
47d1a6e1e Initial revision |
6 7 8 9 10 11 |
*/ /* * Boot support */ #include <common.h> |
b63964037 bootm: Split out ... |
12 |
#include <bootm.h> |
47d1a6e1e Initial revision |
13 |
#include <command.h> |
7f70e8530 * Patch by David ... |
14 |
#include <environment.h> |
90268b878 x86: Support load... |
15 |
#include <errno.h> |
b63964037 bootm: Split out ... |
16 |
#include <image.h> |
4ed6552f7 [new uImage] Intr... |
17 |
#include <lmb.h> |
b63964037 bootm: Split out ... |
18 |
#include <malloc.h> |
0eb25b619 common: Make sure... |
19 |
#include <mapmem.h> |
b63964037 bootm: Split out ... |
20 |
#include <nand.h> |
47d1a6e1e Initial revision |
21 |
#include <asm/byteorder.h> |
5bf2766b4 common/cmd_bootm.... |
22 |
#include <linux/compiler.h> |
b63964037 bootm: Split out ... |
23 24 25 |
#include <linux/ctype.h> #include <linux/err.h> #include <u-boot/zlib.h> |
20dde48bc add lzop decompre... |
26 |
|
1ee1180b6 [new uImage] Clea... |
27 |
DECLARE_GLOBAL_DATA_PTR; |
228f29ac6 * Improve log buf... |
28 |
|
baa26db41 common/cmd_[af]*:... |
29 |
#if defined(CONFIG_CMD_IMI) |
712fbcf38 checkpatch whites... |
30 |
static int image_info(unsigned long addr); |
47d1a6e1e Initial revision |
31 |
#endif |
27b207fd0 * Implement new m... |
32 |
|
baa26db41 common/cmd_[af]*:... |
33 |
#if defined(CONFIG_CMD_IMLS) |
27b207fd0 * Implement new m... |
34 |
#include <flash.h> |
ca5def3f3 cfi_flash: Simpli... |
35 |
#include <mtd/cfi_flash.h> |
e6f2e9023 Added support for... |
36 |
extern flash_info_t flash_info[]; /* info for FLASH chips */ |
8fdf1e0f6 imls: Add support... |
37 38 39 |
#endif #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) |
712fbcf38 checkpatch whites... |
40 |
static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
27b207fd0 * Implement new m... |
41 |
#endif |
dee17768d removed static fr... |
42 |
bootm_headers_t images; /* pointers to os/initrd/fdt images */ |
15940c9af Change max size o... |
43 |
|
49c3a861d bootm: Add subcom... |
44 45 |
/* we overload the cmd field with our state machine info instead of a * function pointer */ |
f74d9bd2a cmd_bootm.c: made... |
46 |
static cmd_tbl_t cmd_bootm_sub[] = { |
49c3a861d bootm: Add subcom... |
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 boot: change some... |
49 |
#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
49c3a861d bootm: Add subcom... |
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 bootm: Add subcom... |
55 |
U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""), |
224c90d10 bootm: Fix help m... |
56 |
U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""), |
49c3a861d bootm: Add subcom... |
57 |
U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""), |
d0ae31eb0 Add a 'fake' go c... |
58 |
U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""), |
49c3a861d bootm: Add subcom... |
59 60 |
U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""), }; |
088f1b199 common/cmd_*.c: s... |
61 |
static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc, |
712fbcf38 checkpatch whites... |
62 |
char * const argv[]) |
49c3a861d bootm: Add subcom... |
63 64 |
{ int ret = 0; |
6d6f12363 sandbox: Add boot... |
65 |
long state; |
49c3a861d bootm: Add subcom... |
66 |
cmd_tbl_t *c; |
49c3a861d bootm: Add subcom... |
67 |
|
983c72f47 Clarify bootm OS ... |
68 69 |
c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub)); argc--; argv++; |
49c3a861d bootm: Add subcom... |
70 71 |
if (c) { |
6d6f12363 sandbox: Add boot... |
72 |
state = (long)c->cmd; |
983c72f47 Clarify bootm OS ... |
73 |
if (state == BOOTM_STATE_START) |
35fc84fa1 Refactor the boot... |
74 |
state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER; |
47e26b1bf cmd_usage(): simp... |
75 76 |
} else { /* Unrecognized command */ |
4c12eeb8b Convert cmd_usage... |
77 |
return CMD_RET_USAGE; |
49c3a861d bootm: Add subcom... |
78 |
} |
ff6c032ea spl: fix calling ... |
79 80 |
if (((state & BOOTM_STATE_START) != BOOTM_STATE_START) && images.state >= state) { |
712fbcf38 checkpatch whites... |
81 82 |
printf("Trying to execute a command out of order "); |
4c12eeb8b Convert cmd_usage... |
83 |
return CMD_RET_USAGE; |
49c3a861d bootm: Add subcom... |
84 |
} |
35fc84fa1 Refactor the boot... |
85 |
ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0); |
49c3a861d bootm: Add subcom... |
86 87 88 |
return ret; } |
396f635b8 bootm: refactor i... |
89 90 91 |
/*******************************************************************/ /* bootm - boot application image from image in memory */ /*******************************************************************/ |
be0831593 bootm: Move to us... |
92 |
|
712fbcf38 checkpatch whites... |
93 |
int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
396f635b8 bootm: refactor i... |
94 |
{ |
2e5167cca Replace CONFIG_RE... |
95 |
#ifdef CONFIG_NEEDS_MANUAL_RELOC |
521af04d8 Conditionally per... |
96 |
static int relocated = 0; |
be0831593 bootm: Move to us... |
97 |
|
be0831593 bootm: Move to us... |
98 99 |
if (!relocated) { int i; |
58bd77db9 bootm: relocate n... |
100 |
|
58bd77db9 bootm: relocate n... |
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 bootm: Move to us... |
104 105 |
relocated = 1; } |
521af04d8 Conditionally per... |
106 |
#endif |
396f635b8 bootm: refactor i... |
107 |
|
49c3a861d bootm: Add subcom... |
108 |
/* determine if we have a sub command */ |
983c72f47 Clarify bootm OS ... |
109 110 |
argc--; argv++; if (argc > 0) { |
49c3a861d bootm: Add subcom... |
111 |
char *endp; |
983c72f47 Clarify bootm OS ... |
112 113 |
simple_strtoul(argv[0], &endp, 16); /* endp pointing to NULL means that argv[0] was just a |
49c3a861d bootm: Add subcom... |
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 Refactor the boot... |
124 125 |
return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START | BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER | |
3d187b392 cmd_bootm.c: Only... |
126 127 128 129 |
BOOTM_STATE_LOADOS | #if defined(CONFIG_PPC) || defined(CONFIG_MIPS) BOOTM_STATE_OS_CMDLINE | #endif |
5c427e49c bootm: use BOOTM_... |
130 131 |
BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO, &images, 1); |
47d1a6e1e Initial revision |
132 |
} |
67d668bf9 autostart: unify ... |
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 common/cmd_*.c: s... |
148 149 |
#ifdef CONFIG_SYS_LONGHELP static char bootm_help_text[] = |
1ee1180b6 [new uImage] Clea... |
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 [new uImage] Remo... |
157 |
#if defined(CONFIG_OF_LIBFDT) |
98a9c4d46 * Modify bootm co... |
158 159 |
"\tWhen booting a Linux kernel which requires a flat device-tree " |
5441f61a3 Fix two typos. |
160 161 |
"\ta third argument is required which is the address of the " |
98a9c4d46 * Modify bootm co... |
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 * Modify bootm co... |
168 |
#endif |
6986a3856 [new uImage] Add ... |
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 bootm: Add subcom... |
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 bootm: fix condit... |
194 |
#if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH) |
49c3a861d bootm: Add subcom... |
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 bootm: Add subcom... |
202 203 |
"\tcmdline - OS specific command line processing/setup " |
224c90d10 bootm: Fix help m... |
204 205 |
"\tbdt - OS specific bd_t processing " |
49c3a861d bootm: Add subcom... |
206 207 |
"\tprep - OS specific prep before relocation or go " |
e3046ba4d common: bootm: Do... |
208 209 210 211 |
#if defined(CONFIG_TRACE) "\tfake - OS specific fake start without go " #endif |
088f1b199 common/cmd_*.c: s... |
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 * Code cleanup: |
218 |
); |
47d1a6e1e Initial revision |
219 |
|
1ee1180b6 [new uImage] Clea... |
220 221 222 |
/*******************************************************************/ /* bootd - boot default image */ /*******************************************************************/ |
baa26db41 common/cmd_[af]*:... |
223 |
#if defined(CONFIG_CMD_BOOTD) |
712fbcf38 checkpatch whites... |
224 |
int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
47d1a6e1e Initial revision |
225 |
{ |
73671dad4 Check run_command... |
226 |
return run_command(getenv("bootcmd"), flag); |
47d1a6e1e Initial revision |
227 |
} |
47d1a6e1e Initial revision |
228 |
|
0d4983930 Patch by Kenneth ... |
229 |
U_BOOT_CMD( |
1ee1180b6 [new uImage] Clea... |
230 |
boot, 1, 1, do_bootd, |
2fb2604d5 Command usage cle... |
231 |
"boot default, i.e., run 'bootcmd'", |
a89c33db9 General help mess... |
232 |
"" |
9d2b18a0f Rewrite command l... |
233 |
); |
47d1a6e1e Initial revision |
234 |
|
9d2b18a0f Rewrite command l... |
235 |
/* keep old command name "bootd" for backward compatibility */ |
0d4983930 Patch by Kenneth ... |
236 |
U_BOOT_CMD( |
1ee1180b6 [new uImage] Clea... |
237 |
bootd, 1, 1, do_bootd, |
2fb2604d5 Command usage cle... |
238 |
"boot default, i.e., run 'bootcmd'", |
a89c33db9 General help mess... |
239 |
"" |
8bde7f776 * Code cleanup: |
240 |
); |
47d1a6e1e Initial revision |
241 |
|
47d1a6e1e Initial revision |
242 |
#endif |
47d1a6e1e Initial revision |
243 |
|
47d1a6e1e Initial revision |
244 |
|
1ee1180b6 [new uImage] Clea... |
245 246 247 |
/*******************************************************************/ /* iminfo - print header info for a requested image */ /*******************************************************************/ |
baa26db41 common/cmd_[af]*:... |
248 |
#if defined(CONFIG_CMD_IMI) |
088f1b199 common/cmd_*.c: s... |
249 |
static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
47d1a6e1e Initial revision |
250 251 252 |
{ int arg; ulong addr; |
1ee1180b6 [new uImage] Clea... |
253 |
int rcode = 0; |
47d1a6e1e Initial revision |
254 |
|
47d1a6e1e Initial revision |
255 |
if (argc < 2) { |
712fbcf38 checkpatch whites... |
256 |
return image_info(load_addr); |
47d1a6e1e Initial revision |
257 |
} |
47d1a6e1e Initial revision |
258 |
|
1ee1180b6 [new uImage] Clea... |
259 |
for (arg = 1; arg < argc; ++arg) { |
712fbcf38 checkpatch whites... |
260 261 |
addr = simple_strtoul(argv[arg], NULL, 16); if (image_info(addr) != 0) |
1ee1180b6 [new uImage] Clea... |
262 |
rcode = 1; |
47d1a6e1e Initial revision |
263 264 265 |
} return rcode; } |
47d1a6e1e Initial revision |
266 |
|
712fbcf38 checkpatch whites... |
267 |
static int image_info(ulong addr) |
47d1a6e1e Initial revision |
268 |
{ |
d5934ad77 [new uImage] Add ... |
269 |
void *hdr = (void *)addr; |
47d1a6e1e Initial revision |
270 |
|
712fbcf38 checkpatch whites... |
271 272 273 |
printf(" ## Checking Image at %08lx ... ", addr); |
47d1a6e1e Initial revision |
274 |
|
712fbcf38 checkpatch whites... |
275 |
switch (genimg_get_format(hdr)) { |
21d29f7f9 bootm: make use o... |
276 |
#if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
d5934ad77 [new uImage] Add ... |
277 |
case IMAGE_FORMAT_LEGACY: |
712fbcf38 checkpatch whites... |
278 279 280 281 282 |
puts(" Legacy image found "); if (!image_check_magic(hdr)) { puts(" Bad Magic Number "); |
d5934ad77 [new uImage] Add ... |
283 284 |
return 1; } |
47d1a6e1e Initial revision |
285 |
|
712fbcf38 checkpatch whites... |
286 287 288 |
if (!image_check_hcrc(hdr)) { puts(" Bad Header Checksum "); |
d5934ad77 [new uImage] Add ... |
289 |
return 1; |
47d1a6e1e Initial revision |
290 |
} |
712fbcf38 checkpatch whites... |
291 |
image_print_contents(hdr); |
47d1a6e1e Initial revision |
292 |
|
712fbcf38 checkpatch whites... |
293 294 295 296 |
puts(" Verifying Checksum ... "); if (!image_check_dcrc(hdr)) { puts(" Bad Data CRC "); |
d5934ad77 [new uImage] Add ... |
297 |
return 1; |
47d1a6e1e Initial revision |
298 |
} |
712fbcf38 checkpatch whites... |
299 300 |
puts("OK "); |
d5934ad77 [new uImage] Add ... |
301 |
return 0; |
21d29f7f9 bootm: make use o... |
302 |
#endif |
d5934ad77 [new uImage] Add ... |
303 304 |
#if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: |
712fbcf38 checkpatch whites... |
305 306 |
puts(" FIT image found "); |
47d1a6e1e Initial revision |
307 |
|
712fbcf38 checkpatch whites... |
308 309 310 |
if (!fit_check_format(hdr)) { puts("Bad FIT image format! "); |
e32fea6ad [new uImage] Add ... |
311 |
return 1; |
47d1a6e1e Initial revision |
312 |
} |
712fbcf38 checkpatch whites... |
313 |
fit_print_contents(hdr); |
a4f243452 FIT: make iminfo ... |
314 |
|
b8da83665 image: Rename fit... |
315 |
if (!fit_all_image_verify(hdr)) { |
712fbcf38 checkpatch whites... |
316 317 |
puts("Bad hash in FIT image! "); |
a4f243452 FIT: make iminfo ... |
318 319 |
return 1; } |
d5934ad77 [new uImage] Add ... |
320 321 322 |
return 0; #endif default: |
712fbcf38 checkpatch whites... |
323 324 |
puts("Unknown image format! "); |
d5934ad77 [new uImage] Add ... |
325 |
break; |
47d1a6e1e Initial revision |
326 |
} |
d5934ad77 [new uImage] Add ... |
327 |
return 1; |
47d1a6e1e Initial revision |
328 |
} |
0d4983930 Patch by Kenneth ... |
329 330 |
U_BOOT_CMD( |
6d0f6bcf3 rename CFG_ macro... |
331 |
iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo, |
2fb2604d5 Command usage cle... |
332 |
"print header information for application image", |
8bde7f776 * Code cleanup: |
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 General help mess... |
339 |
" image contents (magic number, header and payload checksums)" |
8bde7f776 * Code cleanup: |
340 |
); |
25c751e9a * Support for FDT... |
341 |
#endif |
87a449c8a Support for FDT i... |
342 |
|
25c751e9a * Support for FDT... |
343 |
|
1ee1180b6 [new uImage] Clea... |
344 345 346 |
/*******************************************************************/ /* imls - list all images found in flash */ /*******************************************************************/ |
baa26db41 common/cmd_[af]*:... |
347 |
#if defined(CONFIG_CMD_IMLS) |
8fdf1e0f6 imls: Add support... |
348 |
static int do_imls_nor(void) |
27b207fd0 * Implement new m... |
349 350 351 |
{ flash_info_t *info; int i, j; |
d5934ad77 [new uImage] Add ... |
352 |
void *hdr; |
25c751e9a * Support for FDT... |
353 |
|
1ee1180b6 [new uImage] Clea... |
354 |
for (i = 0, info = &flash_info[0]; |
6d0f6bcf3 rename CFG_ macro... |
355 |
i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) { |
25c751e9a * Support for FDT... |
356 |
|
27b207fd0 * Implement new m... |
357 358 |
if (info->flash_id == FLASH_UNKNOWN) goto next_bank; |
1ee1180b6 [new uImage] Clea... |
359 |
for (j = 0; j < info->sector_count; ++j) { |
25c751e9a * Support for FDT... |
360 |
|
d5934ad77 [new uImage] Add ... |
361 362 |
hdr = (void *)info->start[j]; if (!hdr) |
b97a2a0a2 [new uImage] Defi... |
363 |
goto next_sector; |
27b207fd0 * Implement new m... |
364 |
|
712fbcf38 checkpatch whites... |
365 |
switch (genimg_get_format(hdr)) { |
21d29f7f9 bootm: make use o... |
366 |
#if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
d5934ad77 [new uImage] Add ... |
367 |
case IMAGE_FORMAT_LEGACY: |
712fbcf38 checkpatch whites... |
368 |
if (!image_check_hcrc(hdr)) |
d5934ad77 [new uImage] Add ... |
369 |
goto next_sector; |
712fbcf38 checkpatch whites... |
370 371 372 |
printf("Legacy Image at %08lX: ", (ulong)hdr); image_print_contents(hdr); |
d5934ad77 [new uImage] Add ... |
373 |
|
712fbcf38 checkpatch whites... |
374 375 376 377 |
puts(" Verifying Checksum ... "); if (!image_check_dcrc(hdr)) { puts("Bad Data CRC "); |
d5934ad77 [new uImage] Add ... |
378 |
} else { |
712fbcf38 checkpatch whites... |
379 380 |
puts("OK "); |
d5934ad77 [new uImage] Add ... |
381 382 |
} break; |
21d29f7f9 bootm: make use o... |
383 |
#endif |
d5934ad77 [new uImage] Add ... |
384 385 |
#if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: |
712fbcf38 checkpatch whites... |
386 |
if (!fit_check_format(hdr)) |
e32fea6ad [new uImage] Add ... |
387 |
goto next_sector; |
712fbcf38 checkpatch whites... |
388 389 390 |
printf("FIT Image at %08lX: ", (ulong)hdr); fit_print_contents(hdr); |
d5934ad77 [new uImage] Add ... |
391 |
break; |
213bf8c82 Add a flattened d... |
392 |
#endif |
d5934ad77 [new uImage] Add ... |
393 |
default: |
27b207fd0 * Implement new m... |
394 |
goto next_sector; |
25c751e9a * Support for FDT... |
395 |
} |
87a449c8a Support for FDT i... |
396 |
|
bdccc4fed * Map ISP1362 USB... |
397 |
next_sector: ; |
c76f951a7 Added support for... |
398 |
} |
bdccc4fed * Map ISP1362 USB... |
399 |
next_bank: ; |
27b207fd0 * Implement new m... |
400 |
} |
8fdf1e0f6 imls: Add support... |
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 bootm: make use o... |
530 |
#if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
8fdf1e0f6 imls: Add support... |
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 bootm: make use o... |
537 |
#endif |
8fdf1e0f6 imls: Add support... |
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 Added support for... |
570 |
|
27b207fd0 * Implement new m... |
571 572 |
return (0); } |
c76f951a7 Added support for... |
573 |
|
27b207fd0 * Implement new m... |
574 575 |
U_BOOT_CMD( imls, 1, 1, do_imls, |
2fb2604d5 Command usage cle... |
576 |
"list all images found in flash", |
27b207fd0 * Implement new m... |
577 578 |
" " |
8fdf1e0f6 imls: Add support... |
579 580 581 |
" - Prints information about all images found at sector/block " " boundaries in nor/nand flash." |
27b207fd0 * Implement new m... |
582 |
); |
98a9c4d46 * Modify bootm co... |
583 |
#endif |
47d1a6e1e Initial revision |
584 |
|
44f074c77 BOOT: Add "bootz"... |
585 |
#ifdef CONFIG_CMD_BOOTZ |
a5266d6b5 bootm: Clean up b... |
586 |
int __weak bootz_setup(ulong image, ulong *start, ulong *end) |
44f074c77 BOOT: Add "bootz"... |
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 BOOT: Add "bootz"... |
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 bootm: Clean up b... |
602 |
ulong zi_start, zi_end; |
44f074c77 BOOT: Add "bootz"... |
603 |
|
35fc84fa1 Refactor the boot... |
604 605 |
ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, images, 1); |
44f074c77 BOOT: Add "bootz"... |
606 607 |
/* Setup Linux kernel zImage entry point */ |
2b9599e01 cmd_bootm.c: Make... |
608 |
if (!argc) { |
44f074c77 BOOT: Add "bootz"... |
609 610 611 612 613 |
images->ep = load_addr; debug("* kernel: default image load address = 0x%08lx ", load_addr); } else { |
2b9599e01 cmd_bootm.c: Make... |
614 |
images->ep = simple_strtoul(argv[0], NULL, 16); |
44f074c77 BOOT: Add "bootz"... |
615 616 617 618 |
debug("* kernel: cmdline image address = 0x%08lx ", images->ep); } |
a5266d6b5 bootm: Clean up b... |
619 |
ret = bootz_setup(images->ep, &zi_start, &zi_end); |
44f074c77 BOOT: Add "bootz"... |
620 621 622 623 |
if (ret != 0) return 1; lmb_reserve(&images->lmb, images->ep, zi_end - zi_start); |
225fd8c5d cmd_bootm.c: Make... |
624 625 626 627 |
/* * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not * have a header that provide this informaiton. */ |
d52e8575d Combine bootm_fin... |
628 |
if (bootm_find_images(flag, argc, argv)) |
2b9599e01 cmd_bootm.c: Make... |
629 |
return 1; |
44f074c77 BOOT: Add "bootz"... |
630 |
|
2b9599e01 cmd_bootm.c: Make... |
631 |
return 0; |
44f074c77 BOOT: Add "bootz"... |
632 |
} |
da620222f bootz: un-statici... |
633 |
int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
44f074c77 BOOT: Add "bootz"... |
634 |
{ |
35fc84fa1 Refactor the boot... |
635 |
int ret; |
44f074c77 BOOT: Add "bootz"... |
636 |
|
2b9599e01 cmd_bootm.c: Make... |
637 638 |
/* Consume 'bootz' */ argc--; argv++; |
44f074c77 BOOT: Add "bootz"... |
639 640 |
if (bootz_start(cmdtp, flag, argc, argv, &images)) return 1; |
385501d38 bootm: Disable in... |
641 642 643 644 645 |
/* * We are doing the BOOTM_STATE_LOADOS state ourselves, so must * disable interrupts ourselves */ bootm_disable_interrupts(); |
fb1b139bb bootm: Add the mi... |
646 |
images.os.os = IH_OS_LINUX; |
35fc84fa1 Refactor the boot... |
647 |
ret = do_bootm_states(cmdtp, flag, argc, argv, |
fb1b139bb bootm: Add the mi... |
648 649 |
BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO, |
d0ae31eb0 Add a 'fake' go c... |
650 |
&images, 1); |
f8be7d659 net: Improve the ... |
651 |
|
35fc84fa1 Refactor the boot... |
652 |
return ret; |
44f074c77 BOOT: Add "bootz"... |
653 |
} |
088f1b199 common/cmd_*.c: s... |
654 655 |
#ifdef CONFIG_SYS_LONGHELP static char bootz_help_text[] = |
017e1f3f9 BOOT: Add RAW ram... |
656 657 658 659 |
"[addr [initrd[:size]] [fdt]] " " - boot Linux zImage stored in memory " |
44f074c77 BOOT: Add "bootz"... |
660 661 |
"\tThe argument 'initrd' is optional and specifies the address " |
017e1f3f9 BOOT: Add RAW ram... |
662 663 664 665 |
"\tof the initrd in memory. The optional argument ':size' allows " "\tspecifying the size of RAW initrd. " |
44f074c77 BOOT: Add "bootz"... |
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 common/cmd_*.c: s... |
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 BOOT: Add "bootz"... |
684 685 |
); #endif /* CONFIG_CMD_BOOTZ */ |
d2b2ffe31 cmd_bootm.c: Add ... |
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 Combine bootm_fin... |
779 |
if (bootm_find_images(flag, argc, argv)) |
d2b2ffe31 cmd_bootm.c: Add ... |
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 */ |