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