]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
47d1a6e1 | 2 | /* |
ca95c9df | 3 | * (C) Copyright 2000-2009 |
47d1a6e1 | 4 | * Wolfgang Denk, DENX Software Engineering, [email protected]. |
47d1a6e1 WD |
5 | */ |
6 | ||
7 | /* | |
8 | * Boot support | |
9 | */ | |
10 | #include <common.h> | |
b6396403 | 11 | #include <bootm.h> |
47d1a6e1 | 12 | #include <command.h> |
7b51b576 | 13 | #include <env.h> |
90268b87 | 14 | #include <errno.h> |
b6396403 | 15 | #include <image.h> |
b6396403 SG |
16 | #include <malloc.h> |
17 | #include <nand.h> | |
47d1a6e1 | 18 | #include <asm/byteorder.h> |
b6396403 SG |
19 | #include <linux/ctype.h> |
20 | #include <linux/err.h> | |
21 | #include <u-boot/zlib.h> | |
ae0d12f8 | 22 | #include <mapmem.h> |
20dde48b | 23 | |
1ee1180b | 24 | DECLARE_GLOBAL_DATA_PTR; |
228f29ac | 25 | |
baa26db4 | 26 | #if defined(CONFIG_CMD_IMI) |
712fbcf3 | 27 | static int image_info(unsigned long addr); |
47d1a6e1 | 28 | #endif |
27b207fd | 29 | |
baa26db4 | 30 | #if defined(CONFIG_CMD_IMLS) |
27b207fd | 31 | #include <flash.h> |
ca5def3f | 32 | #include <mtd/cfi_flash.h> |
e6f2e902 | 33 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
8fdf1e0f VK |
34 | #endif |
35 | ||
36 | #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) | |
09140113 SG |
37 | static int do_imls(struct cmd_tbl *cmdtp, int flag, int argc, |
38 | char *const argv[]); | |
27b207fd WD |
39 | #endif |
40 | ||
49c3a861 KG |
41 | /* we overload the cmd field with our state machine info instead of a |
42 | * function pointer */ | |
09140113 | 43 | static struct cmd_tbl cmd_bootm_sub[] = { |
49c3a861 KG |
44 | U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""), |
45 | U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""), | |
fca43cc8 | 46 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
49c3a861 KG |
47 | U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""), |
48 | #endif | |
49 | #ifdef CONFIG_OF_LIBFDT | |
50 | U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""), | |
51 | #endif | |
49c3a861 | 52 | U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""), |
224c90d1 | 53 | U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""), |
49c3a861 | 54 | U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""), |
d0ae31eb | 55 | U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""), |
49c3a861 KG |
56 | U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""), |
57 | }; | |
58 | ||
09140113 SG |
59 | static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc, |
60 | char *const argv[]) | |
49c3a861 KG |
61 | { |
62 | int ret = 0; | |
6d6f1236 | 63 | long state; |
09140113 | 64 | struct cmd_tbl *c; |
49c3a861 | 65 | |
983c72f4 SG |
66 | c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub)); |
67 | argc--; argv++; | |
49c3a861 KG |
68 | |
69 | if (c) { | |
6d6f1236 | 70 | state = (long)c->cmd; |
983c72f4 | 71 | if (state == BOOTM_STATE_START) |
35fc84fa | 72 | state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER; |
47e26b1b WD |
73 | } else { |
74 | /* Unrecognized command */ | |
4c12eeb8 | 75 | return CMD_RET_USAGE; |
49c3a861 KG |
76 | } |
77 | ||
ff6c032e HS |
78 | if (((state & BOOTM_STATE_START) != BOOTM_STATE_START) && |
79 | images.state >= state) { | |
712fbcf3 | 80 | printf("Trying to execute a command out of order\n"); |
4c12eeb8 | 81 | return CMD_RET_USAGE; |
49c3a861 KG |
82 | } |
83 | ||
35fc84fa | 84 | ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0); |
49c3a861 KG |
85 | |
86 | return ret; | |
87 | } | |
88 | ||
396f635b KG |
89 | /*******************************************************************/ |
90 | /* bootm - boot application image from image in memory */ | |
91 | /*******************************************************************/ | |
be083159 | 92 | |
09140113 | 93 | int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
396f635b | 94 | { |
2e5167cc | 95 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
521af04d | 96 | static int relocated = 0; |
be083159 | 97 | |
be083159 KG |
98 | if (!relocated) { |
99 | int i; | |
58bd77db | 100 | |
58bd77db DS |
101 | /* relocate names of sub-command table */ |
102 | for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++) | |
103 | cmd_bootm_sub[i].name += gd->reloc_off; | |
104 | ||
be083159 KG |
105 | relocated = 1; |
106 | } | |
521af04d | 107 | #endif |
396f635b | 108 | |
49c3a861 | 109 | /* determine if we have a sub command */ |
983c72f4 SG |
110 | argc--; argv++; |
111 | if (argc > 0) { | |
49c3a861 KG |
112 | char *endp; |
113 | ||
983c72f4 SG |
114 | simple_strtoul(argv[0], &endp, 16); |
115 | /* endp pointing to NULL means that argv[0] was just a | |
49c3a861 KG |
116 | * valid number, pass it along to the normal bootm processing |
117 | * | |
118 | * If endp is ':' or '#' assume a FIT identifier so pass | |
119 | * along for normal processing. | |
120 | * | |
121 | * Right now we assume the first arg should never be '-' | |
122 | */ | |
123 | if ((*endp != 0) && (*endp != ':') && (*endp != '#')) | |
124 | return do_bootm_subcommand(cmdtp, flag, argc, argv); | |
125 | } | |
126 | ||
35fc84fa SG |
127 | return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START | |
128 | BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER | | |
3d187b39 | 129 | BOOTM_STATE_LOADOS | |
c2e7e72b RA |
130 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
131 | BOOTM_STATE_RAMDISK | | |
132 | #endif | |
3d187b39 TR |
133 | #if defined(CONFIG_PPC) || defined(CONFIG_MIPS) |
134 | BOOTM_STATE_OS_CMDLINE | | |
135 | #endif | |
5c427e49 PB |
136 | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | |
137 | BOOTM_STATE_OS_GO, &images, 1); | |
47d1a6e1 WD |
138 | } |
139 | ||
09140113 | 140 | int bootm_maybe_autostart(struct cmd_tbl *cmdtp, const char *cmd) |
67d668bf | 141 | { |
00caae6d | 142 | const char *ep = env_get("autostart"); |
67d668bf MF |
143 | |
144 | if (ep && !strcmp(ep, "yes")) { | |
145 | char *local_args[2]; | |
146 | local_args[0] = (char *)cmd; | |
147 | local_args[1] = NULL; | |
bb872dd9 SG |
148 | printf("Automatic boot of image at addr 0x%08lX ...\n", |
149 | image_load_addr); | |
67d668bf MF |
150 | return do_bootm(cmdtp, 0, 1, local_args); |
151 | } | |
152 | ||
153 | return 0; | |
154 | } | |
155 | ||
088f1b19 KP |
156 | #ifdef CONFIG_SYS_LONGHELP |
157 | static char bootm_help_text[] = | |
1ee1180b MB |
158 | "[addr [arg ...]]\n - boot application image stored in memory\n" |
159 | "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n" | |
160 | "\t'arg' can be the address of an initrd image\n" | |
4a2ad5ff | 161 | #if defined(CONFIG_OF_LIBFDT) |
98a9c4d4 | 162 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
5441f61a | 163 | "\ta third argument is required which is the address of the\n" |
98a9c4d4 MM |
164 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
165 | "\tuse a '-' for the second argument. If you do not pass a third\n" | |
166 | "\ta bd_info struct will be passed instead\n" | |
98a9c4d4 | 167 | #endif |
6986a385 MB |
168 | #if defined(CONFIG_FIT) |
169 | "\t\nFor the new multi component uImage format (FIT) addresses\n" | |
da1a3bd4 | 170 | "\tmust be extended to include component or configuration unit name:\n" |
6986a385 MB |
171 | "\taddr:<subimg_uname> - direct component image specification\n" |
172 | "\taddr#<conf_uname> - configuration specification\n" | |
173 | "\tUse iminfo command to get the list of existing component\n" | |
174 | "\timages and configurations.\n" | |
175 | #endif | |
49c3a861 KG |
176 | "\nSub-commands to do part of the bootm sequence. The sub-commands " |
177 | "must be\n" | |
178 | "issued in the order below (it's ok to not issue all sub-commands):\n" | |
179 | "\tstart [addr [arg ...]]\n" | |
180 | "\tloados - load OS image\n" | |
59af76d9 | 181 | #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH) |
49c3a861 KG |
182 | "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n" |
183 | #endif | |
184 | #if defined(CONFIG_OF_LIBFDT) | |
185 | "\tfdt - relocate flat device tree\n" | |
186 | #endif | |
49c3a861 | 187 | "\tcmdline - OS specific command line processing/setup\n" |
224c90d1 | 188 | "\tbdt - OS specific bd_t processing\n" |
49c3a861 | 189 | "\tprep - OS specific prep before relocation or go\n" |
e3046ba4 MS |
190 | #if defined(CONFIG_TRACE) |
191 | "\tfake - OS specific fake start without go\n" | |
192 | #endif | |
088f1b19 KP |
193 | "\tgo - start OS"; |
194 | #endif | |
195 | ||
196 | U_BOOT_CMD( | |
197 | bootm, CONFIG_SYS_MAXARGS, 1, do_bootm, | |
198 | "boot application image from memory", bootm_help_text | |
8bde7f77 | 199 | ); |
47d1a6e1 | 200 | |
1ee1180b MB |
201 | /*******************************************************************/ |
202 | /* bootd - boot default image */ | |
203 | /*******************************************************************/ | |
baa26db4 | 204 | #if defined(CONFIG_CMD_BOOTD) |
09140113 | 205 | int do_bootd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
47d1a6e1 | 206 | { |
00caae6d | 207 | return run_command(env_get("bootcmd"), flag); |
47d1a6e1 | 208 | } |
47d1a6e1 | 209 | |
0d498393 | 210 | U_BOOT_CMD( |
1ee1180b | 211 | boot, 1, 1, do_bootd, |
2fb2604d | 212 | "boot default, i.e., run 'bootcmd'", |
a89c33db | 213 | "" |
9d2b18a0 | 214 | ); |
47d1a6e1 | 215 | |
9d2b18a0 | 216 | /* keep old command name "bootd" for backward compatibility */ |
0d498393 | 217 | U_BOOT_CMD( |
1ee1180b | 218 | bootd, 1, 1, do_bootd, |
2fb2604d | 219 | "boot default, i.e., run 'bootcmd'", |
a89c33db | 220 | "" |
8bde7f77 | 221 | ); |
47d1a6e1 | 222 | |
47d1a6e1 | 223 | #endif |
47d1a6e1 | 224 | |
47d1a6e1 | 225 | |
1ee1180b MB |
226 | /*******************************************************************/ |
227 | /* iminfo - print header info for a requested image */ | |
228 | /*******************************************************************/ | |
baa26db4 | 229 | #if defined(CONFIG_CMD_IMI) |
09140113 SG |
230 | static int do_iminfo(struct cmd_tbl *cmdtp, int flag, int argc, |
231 | char *const argv[]) | |
47d1a6e1 WD |
232 | { |
233 | int arg; | |
234 | ulong addr; | |
1ee1180b | 235 | int rcode = 0; |
47d1a6e1 | 236 | |
47d1a6e1 | 237 | if (argc < 2) { |
bb872dd9 | 238 | return image_info(image_load_addr); |
47d1a6e1 | 239 | } |
47d1a6e1 | 240 | |
1ee1180b | 241 | for (arg = 1; arg < argc; ++arg) { |
712fbcf3 SW |
242 | addr = simple_strtoul(argv[arg], NULL, 16); |
243 | if (image_info(addr) != 0) | |
1ee1180b | 244 | rcode = 1; |
47d1a6e1 WD |
245 | } |
246 | return rcode; | |
247 | } | |
47d1a6e1 | 248 | |
712fbcf3 | 249 | static int image_info(ulong addr) |
47d1a6e1 | 250 | { |
ae0d12f8 | 251 | void *hdr = (void *)map_sysmem(addr, 0); |
47d1a6e1 | 252 | |
712fbcf3 | 253 | printf("\n## Checking Image at %08lx ...\n", addr); |
47d1a6e1 | 254 | |
712fbcf3 | 255 | switch (genimg_get_format(hdr)) { |
c76c93a3 | 256 | #if defined(CONFIG_LEGACY_IMAGE_FORMAT) |
d5934ad7 | 257 | case IMAGE_FORMAT_LEGACY: |
712fbcf3 SW |
258 | puts(" Legacy image found\n"); |
259 | if (!image_check_magic(hdr)) { | |
260 | puts(" Bad Magic Number\n"); | |
ae0d12f8 | 261 | unmap_sysmem(hdr); |
d5934ad7 MB |
262 | return 1; |
263 | } | |
47d1a6e1 | 264 | |
712fbcf3 SW |
265 | if (!image_check_hcrc(hdr)) { |
266 | puts(" Bad Header Checksum\n"); | |
ae0d12f8 | 267 | unmap_sysmem(hdr); |
d5934ad7 | 268 | return 1; |
47d1a6e1 WD |
269 | } |
270 | ||
712fbcf3 | 271 | image_print_contents(hdr); |
47d1a6e1 | 272 | |
712fbcf3 SW |
273 | puts(" Verifying Checksum ... "); |
274 | if (!image_check_dcrc(hdr)) { | |
275 | puts(" Bad Data CRC\n"); | |
ae0d12f8 | 276 | unmap_sysmem(hdr); |
d5934ad7 | 277 | return 1; |
47d1a6e1 | 278 | } |
712fbcf3 | 279 | puts("OK\n"); |
ae0d12f8 | 280 | unmap_sysmem(hdr); |
d5934ad7 | 281 | return 0; |
21d29f7f | 282 | #endif |
4f1318b2 MT |
283 | #if defined(CONFIG_ANDROID_BOOT_IMAGE) |
284 | case IMAGE_FORMAT_ANDROID: | |
285 | puts(" Android image found\n"); | |
286 | android_print_contents(hdr); | |
ae0d12f8 | 287 | unmap_sysmem(hdr); |
4f1318b2 MT |
288 | return 0; |
289 | #endif | |
d5934ad7 MB |
290 | #if defined(CONFIG_FIT) |
291 | case IMAGE_FORMAT_FIT: | |
712fbcf3 | 292 | puts(" FIT image found\n"); |
47d1a6e1 | 293 | |
712fbcf3 SW |
294 | if (!fit_check_format(hdr)) { |
295 | puts("Bad FIT image format!\n"); | |
ae0d12f8 | 296 | unmap_sysmem(hdr); |
e32fea6a | 297 | return 1; |
47d1a6e1 WD |
298 | } |
299 | ||
712fbcf3 | 300 | fit_print_contents(hdr); |
a4f24345 | 301 | |
b8da8366 | 302 | if (!fit_all_image_verify(hdr)) { |
712fbcf3 | 303 | puts("Bad hash in FIT image!\n"); |
ae0d12f8 | 304 | unmap_sysmem(hdr); |
a4f24345 BS |
305 | return 1; |
306 | } | |
307 | ||
ae0d12f8 | 308 | unmap_sysmem(hdr); |
d5934ad7 MB |
309 | return 0; |
310 | #endif | |
311 | default: | |
712fbcf3 | 312 | puts("Unknown image format!\n"); |
d5934ad7 | 313 | break; |
47d1a6e1 WD |
314 | } |
315 | ||
ae0d12f8 | 316 | unmap_sysmem(hdr); |
d5934ad7 | 317 | return 1; |
47d1a6e1 | 318 | } |
0d498393 WD |
319 | |
320 | U_BOOT_CMD( | |
6d0f6bcf | 321 | iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo, |
2fb2604d | 322 | "print header information for application image", |
8bde7f77 WD |
323 | "addr [addr ...]\n" |
324 | " - print header information for application image starting at\n" | |
325 | " address 'addr' in memory; this includes verification of the\n" | |
a89c33db | 326 | " image contents (magic number, header and payload checksums)" |
8bde7f77 | 327 | ); |
25c751e9 | 328 | #endif |
87a449c8 | 329 | |
25c751e9 | 330 | |
1ee1180b MB |
331 | /*******************************************************************/ |
332 | /* imls - list all images found in flash */ | |
333 | /*******************************************************************/ | |
baa26db4 | 334 | #if defined(CONFIG_CMD_IMLS) |
8fdf1e0f | 335 | static int do_imls_nor(void) |
27b207fd WD |
336 | { |
337 | flash_info_t *info; | |
338 | int i, j; | |
d5934ad7 | 339 | void *hdr; |
25c751e9 | 340 | |
1ee1180b | 341 | for (i = 0, info = &flash_info[0]; |
6d0f6bcf | 342 | i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) { |
25c751e9 | 343 | |
27b207fd WD |
344 | if (info->flash_id == FLASH_UNKNOWN) |
345 | goto next_bank; | |
1ee1180b | 346 | for (j = 0; j < info->sector_count; ++j) { |
25c751e9 | 347 | |
d5934ad7 MB |
348 | hdr = (void *)info->start[j]; |
349 | if (!hdr) | |
b97a2a0a | 350 | goto next_sector; |
27b207fd | 351 | |
712fbcf3 | 352 | switch (genimg_get_format(hdr)) { |
c76c93a3 | 353 | #if defined(CONFIG_LEGACY_IMAGE_FORMAT) |
d5934ad7 | 354 | case IMAGE_FORMAT_LEGACY: |
712fbcf3 | 355 | if (!image_check_hcrc(hdr)) |
d5934ad7 MB |
356 | goto next_sector; |
357 | ||
712fbcf3 SW |
358 | printf("Legacy Image at %08lX:\n", (ulong)hdr); |
359 | image_print_contents(hdr); | |
d5934ad7 | 360 | |
712fbcf3 SW |
361 | puts(" Verifying Checksum ... "); |
362 | if (!image_check_dcrc(hdr)) { | |
363 | puts("Bad Data CRC\n"); | |
d5934ad7 | 364 | } else { |
712fbcf3 | 365 | puts("OK\n"); |
d5934ad7 MB |
366 | } |
367 | break; | |
21d29f7f | 368 | #endif |
d5934ad7 MB |
369 | #if defined(CONFIG_FIT) |
370 | case IMAGE_FORMAT_FIT: | |
712fbcf3 | 371 | if (!fit_check_format(hdr)) |
e32fea6a MB |
372 | goto next_sector; |
373 | ||
712fbcf3 SW |
374 | printf("FIT Image at %08lX:\n", (ulong)hdr); |
375 | fit_print_contents(hdr); | |
d5934ad7 | 376 | break; |
213bf8c8 | 377 | #endif |
d5934ad7 | 378 | default: |
27b207fd | 379 | goto next_sector; |
25c751e9 | 380 | } |
87a449c8 | 381 | |
bdccc4fe | 382 | next_sector: ; |
c76f951a | 383 | } |
bdccc4fe | 384 | next_bank: ; |
27b207fd | 385 | } |
8fdf1e0f VK |
386 | return 0; |
387 | } | |
388 | #endif | |
389 | ||
390 | #if defined(CONFIG_CMD_IMLS_NAND) | |
151c06ec SW |
391 | static int nand_imls_legacyimage(struct mtd_info *mtd, int nand_dev, |
392 | loff_t off, size_t len) | |
8fdf1e0f VK |
393 | { |
394 | void *imgdata; | |
395 | int ret; | |
396 | ||
397 | imgdata = malloc(len); | |
398 | if (!imgdata) { | |
399 | printf("May be a Legacy Image at NAND device %d offset %08llX:\n", | |
400 | nand_dev, off); | |
401 | printf(" Low memory(cannot allocate memory for image)\n"); | |
402 | return -ENOMEM; | |
403 | } | |
404 | ||
dbe7881d | 405 | ret = nand_read_skip_bad(mtd, off, &len, NULL, mtd->size, imgdata); |
8fdf1e0f VK |
406 | if (ret < 0 && ret != -EUCLEAN) { |
407 | free(imgdata); | |
408 | return ret; | |
409 | } | |
410 | ||
411 | if (!image_check_hcrc(imgdata)) { | |
412 | free(imgdata); | |
413 | return 0; | |
414 | } | |
415 | ||
416 | printf("Legacy Image at NAND device %d offset %08llX:\n", | |
417 | nand_dev, off); | |
418 | image_print_contents(imgdata); | |
419 | ||
420 | puts(" Verifying Checksum ... "); | |
421 | if (!image_check_dcrc(imgdata)) | |
422 | puts("Bad Data CRC\n"); | |
423 | else | |
424 | puts("OK\n"); | |
425 | ||
426 | free(imgdata); | |
427 | ||
428 | return 0; | |
429 | } | |
430 | ||
151c06ec SW |
431 | static int nand_imls_fitimage(struct mtd_info *mtd, int nand_dev, loff_t off, |
432 | size_t len) | |
8fdf1e0f VK |
433 | { |
434 | void *imgdata; | |
435 | int ret; | |
436 | ||
437 | imgdata = malloc(len); | |
438 | if (!imgdata) { | |
439 | printf("May be a FIT Image at NAND device %d offset %08llX:\n", | |
440 | nand_dev, off); | |
441 | printf(" Low memory(cannot allocate memory for image)\n"); | |
442 | return -ENOMEM; | |
443 | } | |
444 | ||
dbe7881d | 445 | ret = nand_read_skip_bad(mtd, off, &len, NULL, mtd->size, imgdata); |
8fdf1e0f VK |
446 | if (ret < 0 && ret != -EUCLEAN) { |
447 | free(imgdata); | |
448 | return ret; | |
449 | } | |
450 | ||
451 | if (!fit_check_format(imgdata)) { | |
452 | free(imgdata); | |
453 | return 0; | |
454 | } | |
455 | ||
456 | printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off); | |
457 | ||
458 | fit_print_contents(imgdata); | |
459 | free(imgdata); | |
460 | ||
461 | return 0; | |
462 | } | |
463 | ||
464 | static int do_imls_nand(void) | |
465 | { | |
151c06ec | 466 | struct mtd_info *mtd; |
8fdf1e0f VK |
467 | int nand_dev = nand_curr_device; |
468 | size_t len; | |
469 | loff_t off; | |
470 | u32 buffer[16]; | |
471 | ||
472 | if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) { | |
473 | puts("\nNo NAND devices available\n"); | |
474 | return -ENODEV; | |
475 | } | |
476 | ||
477 | printf("\n"); | |
478 | ||
479 | for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) { | |
f370b515 | 480 | mtd = get_nand_dev_by_index(nand_dev); |
151c06ec | 481 | if (!mtd->name || !mtd->size) |
8fdf1e0f VK |
482 | continue; |
483 | ||
151c06ec | 484 | for (off = 0; off < mtd->size; off += mtd->erasesize) { |
8fdf1e0f VK |
485 | const image_header_t *header; |
486 | int ret; | |
487 | ||
151c06ec | 488 | if (nand_block_isbad(mtd, off)) |
8fdf1e0f VK |
489 | continue; |
490 | ||
491 | len = sizeof(buffer); | |
492 | ||
151c06ec | 493 | ret = nand_read(mtd, off, &len, (u8 *)buffer); |
8fdf1e0f VK |
494 | if (ret < 0 && ret != -EUCLEAN) { |
495 | printf("NAND read error %d at offset %08llX\n", | |
496 | ret, off); | |
497 | continue; | |
498 | } | |
499 | ||
500 | switch (genimg_get_format(buffer)) { | |
c76c93a3 | 501 | #if defined(CONFIG_LEGACY_IMAGE_FORMAT) |
8fdf1e0f VK |
502 | case IMAGE_FORMAT_LEGACY: |
503 | header = (const image_header_t *)buffer; | |
504 | ||
505 | len = image_get_image_size(header); | |
151c06ec | 506 | nand_imls_legacyimage(mtd, nand_dev, off, len); |
8fdf1e0f | 507 | break; |
21d29f7f | 508 | #endif |
8fdf1e0f VK |
509 | #if defined(CONFIG_FIT) |
510 | case IMAGE_FORMAT_FIT: | |
511 | len = fit_get_size(buffer); | |
151c06ec | 512 | nand_imls_fitimage(mtd, nand_dev, off, len); |
8fdf1e0f VK |
513 | break; |
514 | #endif | |
515 | } | |
516 | } | |
517 | } | |
518 | ||
519 | return 0; | |
520 | } | |
521 | #endif | |
522 | ||
523 | #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) | |
09140113 SG |
524 | static int do_imls(struct cmd_tbl *cmdtp, int flag, int argc, |
525 | char *const argv[]) | |
8fdf1e0f VK |
526 | { |
527 | int ret_nor = 0, ret_nand = 0; | |
528 | ||
529 | #if defined(CONFIG_CMD_IMLS) | |
530 | ret_nor = do_imls_nor(); | |
531 | #endif | |
532 | ||
533 | #if defined(CONFIG_CMD_IMLS_NAND) | |
534 | ret_nand = do_imls_nand(); | |
535 | #endif | |
536 | ||
537 | if (ret_nor) | |
538 | return ret_nor; | |
539 | ||
540 | if (ret_nand) | |
541 | return ret_nand; | |
c76f951a | 542 | |
27b207fd WD |
543 | return (0); |
544 | } | |
c76f951a | 545 | |
27b207fd WD |
546 | U_BOOT_CMD( |
547 | imls, 1, 1, do_imls, | |
2fb2604d | 548 | "list all images found in flash", |
27b207fd | 549 | "\n" |
8fdf1e0f VK |
550 | " - Prints information about all images found at sector/block\n" |
551 | " boundaries in nor/nand flash." | |
27b207fd | 552 | ); |
98a9c4d4 | 553 | #endif |