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