Blame view
cmd/bootm.c
14.5 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
47d1a6e1e Initial revision |
2 |
/* |
ca95c9df0 Add error checkin... |
3 |
* (C) Copyright 2000-2009 |
47d1a6e1e Initial revision |
4 |
* Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
47d1a6e1e Initial revision |
5 6 7 8 9 10 |
*/ /* * Boot support */ #include <common.h> |
b63964037 bootm: Split out ... |
11 |
#include <bootm.h> |
47d1a6e1e Initial revision |
12 |
#include <command.h> |
7b51b576d env: Move env_get... |
13 |
#include <env.h> |
90268b878 x86: Support load... |
14 |
#include <errno.h> |
b63964037 bootm: Split out ... |
15 |
#include <image.h> |
b63964037 bootm: Split out ... |
16 17 |
#include <malloc.h> #include <nand.h> |
47d1a6e1e Initial revision |
18 |
#include <asm/byteorder.h> |
b63964037 bootm: Split out ... |
19 20 21 |
#include <linux/ctype.h> #include <linux/err.h> #include <u-boot/zlib.h> |
ae0d12f8d iminfo: add missi... |
22 |
#include <mapmem.h> |
20dde48bc add lzop decompre... |
23 |
|
1ee1180b6 [new uImage] Clea... |
24 |
DECLARE_GLOBAL_DATA_PTR; |
228f29ac6 * Improve log buf... |
25 |
|
baa26db41 common/cmd_[af]*:... |
26 |
#if defined(CONFIG_CMD_IMI) |
712fbcf38 checkpatch whites... |
27 |
static int image_info(unsigned long addr); |
47d1a6e1e Initial revision |
28 |
#endif |
27b207fd0 * Implement new m... |
29 |
|
baa26db41 common/cmd_[af]*:... |
30 |
#if defined(CONFIG_CMD_IMLS) |
27b207fd0 * Implement new m... |
31 |
#include <flash.h> |
ca5def3f3 cfi_flash: Simpli... |
32 |
#include <mtd/cfi_flash.h> |
e6f2e9023 Added support for... |
33 |
extern flash_info_t flash_info[]; /* info for FLASH chips */ |
8fdf1e0f6 imls: Add support... |
34 35 36 |
#endif #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) |
712fbcf38 checkpatch whites... |
37 |
static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
27b207fd0 * Implement new m... |
38 |
#endif |
49c3a861d bootm: Add subcom... |
39 40 |
/* we overload the cmd field with our state machine info instead of a * function pointer */ |
f74d9bd2a cmd_bootm.c: made... |
41 |
static cmd_tbl_t cmd_bootm_sub[] = { |
49c3a861d bootm: Add subcom... |
42 43 |
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... |
44 |
#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
49c3a861d bootm: Add subcom... |
45 46 47 48 49 |
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... |
50 |
U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""), |
224c90d10 bootm: Fix help m... |
51 |
U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""), |
49c3a861d bootm: Add subcom... |
52 |
U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""), |
d0ae31eb0 Add a 'fake' go c... |
53 |
U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""), |
49c3a861d bootm: Add subcom... |
54 55 |
U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""), }; |
088f1b199 common/cmd_*.c: s... |
56 |
static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc, |
712fbcf38 checkpatch whites... |
57 |
char * const argv[]) |
49c3a861d bootm: Add subcom... |
58 59 |
{ int ret = 0; |
6d6f12363 sandbox: Add boot... |
60 |
long state; |
49c3a861d bootm: Add subcom... |
61 |
cmd_tbl_t *c; |
49c3a861d bootm: Add subcom... |
62 |
|
983c72f47 Clarify bootm OS ... |
63 64 |
c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub)); argc--; argv++; |
49c3a861d bootm: Add subcom... |
65 66 |
if (c) { |
6d6f12363 sandbox: Add boot... |
67 |
state = (long)c->cmd; |
983c72f47 Clarify bootm OS ... |
68 |
if (state == BOOTM_STATE_START) |
35fc84fa1 Refactor the boot... |
69 |
state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER; |
47e26b1bf cmd_usage(): simp... |
70 71 |
} else { /* Unrecognized command */ |
4c12eeb8b Convert cmd_usage... |
72 |
return CMD_RET_USAGE; |
49c3a861d bootm: Add subcom... |
73 |
} |
ff6c032ea spl: fix calling ... |
74 75 |
if (((state & BOOTM_STATE_START) != BOOTM_STATE_START) && images.state >= state) { |
712fbcf38 checkpatch whites... |
76 77 |
printf("Trying to execute a command out of order "); |
4c12eeb8b Convert cmd_usage... |
78 |
return CMD_RET_USAGE; |
49c3a861d bootm: Add subcom... |
79 |
} |
35fc84fa1 Refactor the boot... |
80 |
ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0); |
49c3a861d bootm: Add subcom... |
81 82 83 |
return ret; } |
396f635b8 bootm: refactor i... |
84 85 86 |
/*******************************************************************/ /* bootm - boot application image from image in memory */ /*******************************************************************/ |
be0831593 bootm: Move to us... |
87 |
|
712fbcf38 checkpatch whites... |
88 |
int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
396f635b8 bootm: refactor i... |
89 |
{ |
2e5167cca Replace CONFIG_RE... |
90 |
#ifdef CONFIG_NEEDS_MANUAL_RELOC |
521af04d8 Conditionally per... |
91 |
static int relocated = 0; |
be0831593 bootm: Move to us... |
92 |
|
be0831593 bootm: Move to us... |
93 94 |
if (!relocated) { int i; |
58bd77db9 bootm: relocate n... |
95 |
|
58bd77db9 bootm: relocate n... |
96 97 98 |
/* 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... |
99 100 |
relocated = 1; } |
521af04d8 Conditionally per... |
101 |
#endif |
396f635b8 bootm: refactor i... |
102 |
|
49c3a861d bootm: Add subcom... |
103 |
/* determine if we have a sub command */ |
983c72f47 Clarify bootm OS ... |
104 105 |
argc--; argv++; if (argc > 0) { |
49c3a861d bootm: Add subcom... |
106 |
char *endp; |
983c72f47 Clarify bootm OS ... |
107 108 |
simple_strtoul(argv[0], &endp, 16); /* endp pointing to NULL means that argv[0] was just a |
49c3a861d bootm: Add subcom... |
109 110 111 112 113 114 115 116 117 118 |
* 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); } |
6605ea47d MLK-12500-1 HAB: ... |
119 120 121 |
#ifdef CONFIG_IMX_HAB extern int authenticate_image( uint32_t ddr_start, uint32_t raw_image_size); |
0e492bffc MLK-17086 bootm: ... |
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
#ifdef CONFIG_IMX_OPTEE ulong tee_addr = 0; int ret; ulong zi_start, zi_end; tee_addr = env_get_ulong("tee_addr", 16, tee_addr); if (!tee_addr) { printf("Not valid tee_addr, Please check "); return 1; } switch (genimg_get_format((const void *)tee_addr)) { case IMAGE_FORMAT_LEGACY: if (authenticate_image(tee_addr, image_get_image_size((image_header_t *)tee_addr)) != 0) { printf("Authenticate uImage Fail, Please check "); return 1; } break; default: printf("Not valid image format for Authentication, Please check "); return 1; }; ret = bootz_setup(image_load_addr, &zi_start, &zi_end); if (ret != 0) return 1; if (authenticate_image(image_load_addr, zi_end - zi_start) != 0) { printf("Authenticate zImage Fail, Please check "); return 1; } #else |
6605ea47d MLK-12500-1 HAB: ... |
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
switch (genimg_get_format((const void *)image_load_addr)) { #if defined(CONFIG_LEGACY_IMAGE_FORMAT) case IMAGE_FORMAT_LEGACY: if (authenticate_image(image_load_addr, image_get_image_size((image_header_t *)image_load_addr)) != 0) { printf("Authenticate uImage Fail, Please check "); return 1; } break; #endif #ifdef CONFIG_ANDROID_BOOT_IMAGE case IMAGE_FORMAT_ANDROID: /* Do this authentication in boota command */ break; #endif default: printf("Not valid image format for Authentication, Please check "); return 1; } #endif |
0e492bffc MLK-17086 bootm: ... |
182 |
#endif |
6605ea47d MLK-12500-1 HAB: ... |
183 |
|
35fc84fa1 Refactor the boot... |
184 185 |
return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START | BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER | |
3d187b392 cmd_bootm.c: Only... |
186 |
BOOTM_STATE_LOADOS | |
c2e7e72bb bootm: relocate r... |
187 188 189 |
#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH BOOTM_STATE_RAMDISK | #endif |
3d187b392 cmd_bootm.c: Only... |
190 191 192 |
#if defined(CONFIG_PPC) || defined(CONFIG_MIPS) BOOTM_STATE_OS_CMDLINE | #endif |
5c427e49c bootm: use BOOTM_... |
193 194 |
BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO, &images, 1); |
47d1a6e1e Initial revision |
195 |
} |
67d668bf9 autostart: unify ... |
196 197 |
int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd) { |
00caae6d4 env: Rename geten... |
198 |
const char *ep = env_get("autostart"); |
67d668bf9 autostart: unify ... |
199 200 201 202 203 |
if (ep && !strcmp(ep, "yes")) { char *local_args[2]; local_args[0] = (char *)cmd; local_args[1] = NULL; |
bb872dd93 image: Rename loa... |
204 205 206 |
printf("Automatic boot of image at addr 0x%08lX ... ", image_load_addr); |
67d668bf9 autostart: unify ... |
207 208 209 210 211 |
return do_bootm(cmdtp, 0, 1, local_args); } return 0; } |
088f1b199 common/cmd_*.c: s... |
212 213 |
#ifdef CONFIG_SYS_LONGHELP static char bootm_help_text[] = |
1ee1180b6 [new uImage] Clea... |
214 215 216 217 218 219 220 |
"[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... |
221 |
#if defined(CONFIG_OF_LIBFDT) |
98a9c4d46 * Modify bootm co... |
222 223 |
"\tWhen booting a Linux kernel which requires a flat device-tree " |
5441f61a3 Fix two typos. |
224 225 |
"\ta third argument is required which is the address of the " |
98a9c4d46 * Modify bootm co... |
226 227 228 229 230 231 |
"\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... |
232 |
#endif |
6986a3856 [new uImage] Add ... |
233 234 235 236 |
#if defined(CONFIG_FIT) "\t For the new multi component uImage format (FIT) addresses " |
da1a3bd4d Fix spelling of "... |
237 238 |
"\tmust be extended to include component or configuration unit name: " |
6986a3856 [new uImage] Add ... |
239 240 241 242 243 244 245 246 247 |
"\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... |
248 249 250 251 252 253 254 255 256 257 |
" 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... |
258 |
#if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH) |
49c3a861d bootm: Add subcom... |
259 260 261 262 263 264 265 |
"\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... |
266 267 |
"\tcmdline - OS specific command line processing/setup " |
224c90d10 bootm: Fix help m... |
268 269 |
"\tbdt - OS specific bd_t processing " |
49c3a861d bootm: Add subcom... |
270 271 |
"\tprep - OS specific prep before relocation or go " |
e3046ba4d common: bootm: Do... |
272 273 274 275 |
#if defined(CONFIG_TRACE) "\tfake - OS specific fake start without go " #endif |
088f1b199 common/cmd_*.c: s... |
276 277 278 279 280 281 |
"\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: |
282 |
); |
47d1a6e1e Initial revision |
283 |
|
1ee1180b6 [new uImage] Clea... |
284 285 286 |
/*******************************************************************/ /* bootd - boot default image */ /*******************************************************************/ |
baa26db41 common/cmd_[af]*:... |
287 |
#if defined(CONFIG_CMD_BOOTD) |
712fbcf38 checkpatch whites... |
288 |
int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
47d1a6e1e Initial revision |
289 |
{ |
00caae6d4 env: Rename geten... |
290 |
return run_command(env_get("bootcmd"), flag); |
47d1a6e1e Initial revision |
291 |
} |
47d1a6e1e Initial revision |
292 |
|
0d4983930 Patch by Kenneth ... |
293 |
U_BOOT_CMD( |
1ee1180b6 [new uImage] Clea... |
294 |
boot, 1, 1, do_bootd, |
2fb2604d5 Command usage cle... |
295 |
"boot default, i.e., run 'bootcmd'", |
a89c33db9 General help mess... |
296 |
"" |
9d2b18a0f Rewrite command l... |
297 |
); |
47d1a6e1e Initial revision |
298 |
|
9d2b18a0f Rewrite command l... |
299 |
/* keep old command name "bootd" for backward compatibility */ |
0d4983930 Patch by Kenneth ... |
300 |
U_BOOT_CMD( |
1ee1180b6 [new uImage] Clea... |
301 |
bootd, 1, 1, do_bootd, |
2fb2604d5 Command usage cle... |
302 |
"boot default, i.e., run 'bootcmd'", |
a89c33db9 General help mess... |
303 |
"" |
8bde7f776 * Code cleanup: |
304 |
); |
47d1a6e1e Initial revision |
305 |
|
47d1a6e1e Initial revision |
306 |
#endif |
47d1a6e1e Initial revision |
307 |
|
47d1a6e1e Initial revision |
308 |
|
1ee1180b6 [new uImage] Clea... |
309 310 311 |
/*******************************************************************/ /* iminfo - print header info for a requested image */ /*******************************************************************/ |
baa26db41 common/cmd_[af]*:... |
312 |
#if defined(CONFIG_CMD_IMI) |
088f1b199 common/cmd_*.c: s... |
313 |
static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
47d1a6e1e Initial revision |
314 315 316 |
{ int arg; ulong addr; |
1ee1180b6 [new uImage] Clea... |
317 |
int rcode = 0; |
47d1a6e1e Initial revision |
318 |
|
47d1a6e1e Initial revision |
319 |
if (argc < 2) { |
bb872dd93 image: Rename loa... |
320 |
return image_info(image_load_addr); |
47d1a6e1e Initial revision |
321 |
} |
47d1a6e1e Initial revision |
322 |
|
1ee1180b6 [new uImage] Clea... |
323 |
for (arg = 1; arg < argc; ++arg) { |
712fbcf38 checkpatch whites... |
324 325 |
addr = simple_strtoul(argv[arg], NULL, 16); if (image_info(addr) != 0) |
1ee1180b6 [new uImage] Clea... |
326 |
rcode = 1; |
47d1a6e1e Initial revision |
327 328 329 |
} return rcode; } |
47d1a6e1e Initial revision |
330 |
|
712fbcf38 checkpatch whites... |
331 |
static int image_info(ulong addr) |
47d1a6e1e Initial revision |
332 |
{ |
ae0d12f8d iminfo: add missi... |
333 |
void *hdr = (void *)map_sysmem(addr, 0); |
47d1a6e1e Initial revision |
334 |
|
712fbcf38 checkpatch whites... |
335 336 337 |
printf(" ## Checking Image at %08lx ... ", addr); |
47d1a6e1e Initial revision |
338 |
|
712fbcf38 checkpatch whites... |
339 |
switch (genimg_get_format(hdr)) { |
c76c93a3d configs: Rename C... |
340 |
#if defined(CONFIG_LEGACY_IMAGE_FORMAT) |
d5934ad77 [new uImage] Add ... |
341 |
case IMAGE_FORMAT_LEGACY: |
712fbcf38 checkpatch whites... |
342 343 344 345 346 |
puts(" Legacy image found "); if (!image_check_magic(hdr)) { puts(" Bad Magic Number "); |
ae0d12f8d iminfo: add missi... |
347 |
unmap_sysmem(hdr); |
d5934ad77 [new uImage] Add ... |
348 349 |
return 1; } |
47d1a6e1e Initial revision |
350 |
|
712fbcf38 checkpatch whites... |
351 352 353 |
if (!image_check_hcrc(hdr)) { puts(" Bad Header Checksum "); |
ae0d12f8d iminfo: add missi... |
354 |
unmap_sysmem(hdr); |
d5934ad77 [new uImage] Add ... |
355 |
return 1; |
47d1a6e1e Initial revision |
356 |
} |
712fbcf38 checkpatch whites... |
357 |
image_print_contents(hdr); |
47d1a6e1e Initial revision |
358 |
|
712fbcf38 checkpatch whites... |
359 360 361 362 |
puts(" Verifying Checksum ... "); if (!image_check_dcrc(hdr)) { puts(" Bad Data CRC "); |
ae0d12f8d iminfo: add missi... |
363 |
unmap_sysmem(hdr); |
d5934ad77 [new uImage] Add ... |
364 |
return 1; |
47d1a6e1e Initial revision |
365 |
} |
712fbcf38 checkpatch whites... |
366 367 |
puts("OK "); |
ae0d12f8d iminfo: add missi... |
368 |
unmap_sysmem(hdr); |
d5934ad77 [new uImage] Add ... |
369 |
return 0; |
21d29f7f9 bootm: make use o... |
370 |
#endif |
4f1318b29 common: image: mi... |
371 372 373 374 375 |
#if defined(CONFIG_ANDROID_BOOT_IMAGE) case IMAGE_FORMAT_ANDROID: puts(" Android image found "); android_print_contents(hdr); |
ae0d12f8d iminfo: add missi... |
376 |
unmap_sysmem(hdr); |
4f1318b29 common: image: mi... |
377 378 |
return 0; #endif |
d5934ad77 [new uImage] Add ... |
379 380 |
#if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: |
712fbcf38 checkpatch whites... |
381 382 |
puts(" FIT image found "); |
47d1a6e1e Initial revision |
383 |
|
712fbcf38 checkpatch whites... |
384 385 386 |
if (!fit_check_format(hdr)) { puts("Bad FIT image format! "); |
ae0d12f8d iminfo: add missi... |
387 |
unmap_sysmem(hdr); |
e32fea6ad [new uImage] Add ... |
388 |
return 1; |
47d1a6e1e Initial revision |
389 |
} |
712fbcf38 checkpatch whites... |
390 |
fit_print_contents(hdr); |
a4f243452 FIT: make iminfo ... |
391 |
|
b8da83665 image: Rename fit... |
392 |
if (!fit_all_image_verify(hdr)) { |
712fbcf38 checkpatch whites... |
393 394 |
puts("Bad hash in FIT image! "); |
ae0d12f8d iminfo: add missi... |
395 |
unmap_sysmem(hdr); |
a4f243452 FIT: make iminfo ... |
396 397 |
return 1; } |
ae0d12f8d iminfo: add missi... |
398 |
unmap_sysmem(hdr); |
d5934ad77 [new uImage] Add ... |
399 400 401 |
return 0; #endif default: |
712fbcf38 checkpatch whites... |
402 403 |
puts("Unknown image format! "); |
d5934ad77 [new uImage] Add ... |
404 |
break; |
47d1a6e1e Initial revision |
405 |
} |
ae0d12f8d iminfo: add missi... |
406 |
unmap_sysmem(hdr); |
d5934ad77 [new uImage] Add ... |
407 |
return 1; |
47d1a6e1e Initial revision |
408 |
} |
0d4983930 Patch by Kenneth ... |
409 410 |
U_BOOT_CMD( |
6d0f6bcf3 rename CFG_ macro... |
411 |
iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo, |
2fb2604d5 Command usage cle... |
412 |
"print header information for application image", |
8bde7f776 * Code cleanup: |
413 414 415 416 417 418 |
"addr [addr ...] " " - print header information for application image starting at " " address 'addr' in memory; this includes verification of the " |
a89c33db9 General help mess... |
419 |
" image contents (magic number, header and payload checksums)" |
8bde7f776 * Code cleanup: |
420 |
); |
25c751e9a * Support for FDT... |
421 |
#endif |
87a449c8a Support for FDT i... |
422 |
|
25c751e9a * Support for FDT... |
423 |
|
1ee1180b6 [new uImage] Clea... |
424 425 426 |
/*******************************************************************/ /* imls - list all images found in flash */ /*******************************************************************/ |
baa26db41 common/cmd_[af]*:... |
427 |
#if defined(CONFIG_CMD_IMLS) |
8fdf1e0f6 imls: Add support... |
428 |
static int do_imls_nor(void) |
27b207fd0 * Implement new m... |
429 430 431 |
{ flash_info_t *info; int i, j; |
d5934ad77 [new uImage] Add ... |
432 |
void *hdr; |
25c751e9a * Support for FDT... |
433 |
|
1ee1180b6 [new uImage] Clea... |
434 |
for (i = 0, info = &flash_info[0]; |
6d0f6bcf3 rename CFG_ macro... |
435 |
i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) { |
25c751e9a * Support for FDT... |
436 |
|
27b207fd0 * Implement new m... |
437 438 |
if (info->flash_id == FLASH_UNKNOWN) goto next_bank; |
1ee1180b6 [new uImage] Clea... |
439 |
for (j = 0; j < info->sector_count; ++j) { |
25c751e9a * Support for FDT... |
440 |
|
d5934ad77 [new uImage] Add ... |
441 442 |
hdr = (void *)info->start[j]; if (!hdr) |
b97a2a0a2 [new uImage] Defi... |
443 |
goto next_sector; |
27b207fd0 * Implement new m... |
444 |
|
712fbcf38 checkpatch whites... |
445 |
switch (genimg_get_format(hdr)) { |
c76c93a3d configs: Rename C... |
446 |
#if defined(CONFIG_LEGACY_IMAGE_FORMAT) |
d5934ad77 [new uImage] Add ... |
447 |
case IMAGE_FORMAT_LEGACY: |
712fbcf38 checkpatch whites... |
448 |
if (!image_check_hcrc(hdr)) |
d5934ad77 [new uImage] Add ... |
449 |
goto next_sector; |
712fbcf38 checkpatch whites... |
450 451 452 |
printf("Legacy Image at %08lX: ", (ulong)hdr); image_print_contents(hdr); |
d5934ad77 [new uImage] Add ... |
453 |
|
712fbcf38 checkpatch whites... |
454 455 456 457 |
puts(" Verifying Checksum ... "); if (!image_check_dcrc(hdr)) { puts("Bad Data CRC "); |
d5934ad77 [new uImage] Add ... |
458 |
} else { |
712fbcf38 checkpatch whites... |
459 460 |
puts("OK "); |
d5934ad77 [new uImage] Add ... |
461 462 |
} break; |
21d29f7f9 bootm: make use o... |
463 |
#endif |
d5934ad77 [new uImage] Add ... |
464 465 |
#if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: |
712fbcf38 checkpatch whites... |
466 |
if (!fit_check_format(hdr)) |
e32fea6ad [new uImage] Add ... |
467 |
goto next_sector; |
712fbcf38 checkpatch whites... |
468 469 470 |
printf("FIT Image at %08lX: ", (ulong)hdr); fit_print_contents(hdr); |
d5934ad77 [new uImage] Add ... |
471 |
break; |
213bf8c82 Add a flattened d... |
472 |
#endif |
d5934ad77 [new uImage] Add ... |
473 |
default: |
27b207fd0 * Implement new m... |
474 |
goto next_sector; |
25c751e9a * Support for FDT... |
475 |
} |
87a449c8a Support for FDT i... |
476 |
|
bdccc4fed * Map ISP1362 USB... |
477 |
next_sector: ; |
c76f951a7 Added support for... |
478 |
} |
bdccc4fed * Map ISP1362 USB... |
479 |
next_bank: ; |
27b207fd0 * Implement new m... |
480 |
} |
8fdf1e0f6 imls: Add support... |
481 482 483 484 485 |
return 0; } #endif #if defined(CONFIG_CMD_IMLS_NAND) |
151c06ec6 mtd: nand: Remove... |
486 487 |
static int nand_imls_legacyimage(struct mtd_info *mtd, int nand_dev, loff_t off, size_t len) |
8fdf1e0f6 imls: Add support... |
488 489 490 491 492 493 494 495 496 497 498 499 500 |
{ 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; } |
dbe7881de cmd: bootm: fix b... |
501 |
ret = nand_read_skip_bad(mtd, off, &len, NULL, mtd->size, imgdata); |
8fdf1e0f6 imls: Add support... |
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 |
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; } |
151c06ec6 mtd: nand: Remove... |
529 530 |
static int nand_imls_fitimage(struct mtd_info *mtd, int nand_dev, loff_t off, size_t len) |
8fdf1e0f6 imls: Add support... |
531 532 533 534 535 536 537 538 539 540 541 542 543 |
{ 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; } |
dbe7881de cmd: bootm: fix b... |
544 |
ret = nand_read_skip_bad(mtd, off, &len, NULL, mtd->size, imgdata); |
8fdf1e0f6 imls: Add support... |
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
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) { |
151c06ec6 mtd: nand: Remove... |
566 |
struct mtd_info *mtd; |
8fdf1e0f6 imls: Add support... |
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
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++) { |
f370b5151 cmd: bootm: use g... |
583 |
mtd = get_nand_dev_by_index(nand_dev); |
151c06ec6 mtd: nand: Remove... |
584 |
if (!mtd->name || !mtd->size) |
8fdf1e0f6 imls: Add support... |
585 |
continue; |
151c06ec6 mtd: nand: Remove... |
586 |
for (off = 0; off < mtd->size; off += mtd->erasesize) { |
8fdf1e0f6 imls: Add support... |
587 588 |
const image_header_t *header; int ret; |
151c06ec6 mtd: nand: Remove... |
589 |
if (nand_block_isbad(mtd, off)) |
8fdf1e0f6 imls: Add support... |
590 591 592 |
continue; len = sizeof(buffer); |
151c06ec6 mtd: nand: Remove... |
593 |
ret = nand_read(mtd, off, &len, (u8 *)buffer); |
8fdf1e0f6 imls: Add support... |
594 595 596 597 598 599 600 601 |
if (ret < 0 && ret != -EUCLEAN) { printf("NAND read error %d at offset %08llX ", ret, off); continue; } switch (genimg_get_format(buffer)) { |
c76c93a3d configs: Rename C... |
602 |
#if defined(CONFIG_LEGACY_IMAGE_FORMAT) |
8fdf1e0f6 imls: Add support... |
603 604 605 606 |
case IMAGE_FORMAT_LEGACY: header = (const image_header_t *)buffer; len = image_get_image_size(header); |
151c06ec6 mtd: nand: Remove... |
607 |
nand_imls_legacyimage(mtd, nand_dev, off, len); |
8fdf1e0f6 imls: Add support... |
608 |
break; |
21d29f7f9 bootm: make use o... |
609 |
#endif |
8fdf1e0f6 imls: Add support... |
610 611 612 |
#if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: len = fit_get_size(buffer); |
151c06ec6 mtd: nand: Remove... |
613 |
nand_imls_fitimage(mtd, nand_dev, off, len); |
8fdf1e0f6 imls: Add support... |
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
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... |
642 |
|
27b207fd0 * Implement new m... |
643 644 |
return (0); } |
c76f951a7 Added support for... |
645 |
|
27b207fd0 * Implement new m... |
646 647 |
U_BOOT_CMD( imls, 1, 1, do_imls, |
2fb2604d5 Command usage cle... |
648 |
"list all images found in flash", |
27b207fd0 * Implement new m... |
649 650 |
" " |
8fdf1e0f6 imls: Add support... |
651 652 653 |
" - Prints information about all images found at sector/block " " boundaries in nor/nand flash." |
27b207fd0 * Implement new m... |
654 |
); |
98a9c4d46 * Modify bootm co... |
655 |
#endif |