]>
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 | ||
b97a2a0a | 8 | |
47d1a6e1 WD |
9 | /* |
10 | * Boot support | |
11 | */ | |
12 | #include <common.h> | |
13 | #include <watchdog.h> | |
14 | #include <command.h> | |
47d1a6e1 WD |
15 | #include <image.h> |
16 | #include <malloc.h> | |
a31e091a | 17 | #include <u-boot/zlib.h> |
c29fdfc1 | 18 | #include <bzlib.h> |
7f70e853 | 19 | #include <environment.h> |
4ed6552f | 20 | #include <lmb.h> |
49c3a861 | 21 | #include <linux/ctype.h> |
47d1a6e1 | 22 | #include <asm/byteorder.h> |
35e7b0f1 | 23 | #include <asm/io.h> |
5bf2766b | 24 | #include <linux/compiler.h> |
8bde7f77 | 25 | |
871a57bb MY |
26 | #if defined(CONFIG_BOOTM_VXWORKS) && \ |
27 | (defined(CONFIG_PPC) || defined(CONFIG_ARM)) | |
28 | #include <vxworks.h> | |
29 | #endif | |
30 | ||
ebb86c4e | 31 | #if defined(CONFIG_CMD_USB) |
3d71c81a MK |
32 | #include <usb.h> |
33 | #endif | |
34 | ||
54f9c866 | 35 | #if defined(CONFIG_OF_LIBFDT) |
54f9c866 KG |
36 | #include <libfdt.h> |
37 | #include <fdt_support.h> | |
38 | #endif | |
39 | ||
fc9c1727 | 40 | #ifdef CONFIG_LZMA |
fc9c1727 | 41 | #include <lzma/LzmaTypes.h> |
caf72ff3 | 42 | #include <lzma/LzmaDec.h> |
fc9c1727 LCM |
43 | #include <lzma/LzmaTools.h> |
44 | #endif /* CONFIG_LZMA */ | |
45 | ||
20dde48b PK |
46 | #ifdef CONFIG_LZO |
47 | #include <linux/lzo.h> | |
48 | #endif /* CONFIG_LZO */ | |
49 | ||
1ee1180b | 50 | DECLARE_GLOBAL_DATA_PTR; |
228f29ac | 51 | |
6d0f6bcf JCPV |
52 | #ifndef CONFIG_SYS_BOOTM_LEN |
53 | #define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */ | |
2abbe075 WD |
54 | #endif |
55 | ||
321359f2 MB |
56 | #ifdef CONFIG_BZIP2 |
57 | extern void bz_internal_error(int); | |
47d1a6e1 WD |
58 | #endif |
59 | ||
baa26db4 | 60 | #if defined(CONFIG_CMD_IMI) |
712fbcf3 | 61 | static int image_info(unsigned long addr); |
47d1a6e1 | 62 | #endif |
27b207fd | 63 | |
baa26db4 | 64 | #if defined(CONFIG_CMD_IMLS) |
27b207fd | 65 | #include <flash.h> |
ca5def3f | 66 | #include <mtd/cfi_flash.h> |
e6f2e902 | 67 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
8fdf1e0f VK |
68 | #endif |
69 | ||
70 | #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) | |
712fbcf3 | 71 | static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
27b207fd WD |
72 | #endif |
73 | ||
8fdf1e0f VK |
74 | #include <linux/err.h> |
75 | #include <nand.h> | |
76 | ||
be2e5a09 | 77 | #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY) |
712fbcf3 | 78 | static void fixup_silent_linux(void); |
1ee1180b | 79 | #endif |
47d1a6e1 | 80 | |
c5cbe1e2 SG |
81 | static int do_bootm_standalone(int flag, int argc, char * const argv[], |
82 | bootm_headers_t *images); | |
83 | ||
35e7b0f1 | 84 | static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, |
712fbcf3 SW |
85 | char * const argv[], bootm_headers_t *images, |
86 | ulong *os_data, ulong *os_len); | |
47d1a6e1 WD |
87 | |
88 | /* | |
89 | * Continue booting an OS image; caller already has: | |
90 | * - copied image header to global variable `header' | |
91 | * - checked header magic number, checksums (both header & image), | |
92 | * - verified image architecture (PPC) and type (KERNEL or MULTI), | |
93 | * - loaded (first part of) image to header load address, | |
94 | * - disabled interrupts. | |
983c72f4 | 95 | * |
35fc84fa | 96 | * @flag: Flags indicating what to do (BOOTM_STATE_...) |
983c72f4 SG |
97 | * @argc: Number of arguments. Note that the arguments are shifted down |
98 | * so that 0 is the first argument not processed by U-Boot, and | |
99 | * argc is adjusted accordingly. This avoids confusion as to how | |
100 | * many arguments are available for the OS. | |
101 | * @images: Pointers to os/initrd/fdt | |
102 | * @return 1 on error. On success the OS boots so this function does | |
103 | * not return. | |
47d1a6e1 | 104 | */ |
712fbcf3 | 105 | typedef int boot_os_fn(int flag, int argc, char * const argv[], |
983c72f4 | 106 | bootm_headers_t *images); |
1ee1180b | 107 | |
b1d0db18 | 108 | #ifdef CONFIG_BOOTM_LINUX |
1ee1180b | 109 | extern boot_os_fn do_bootm_linux; |
b1d0db18 KG |
110 | #endif |
111 | #ifdef CONFIG_BOOTM_NETBSD | |
1ee1180b | 112 | static boot_os_fn do_bootm_netbsd; |
b1d0db18 | 113 | #endif |
f13e7b2e | 114 | #if defined(CONFIG_LYNXKDI) |
1ee1180b | 115 | static boot_os_fn do_bootm_lynxkdi; |
712fbcf3 | 116 | extern void lynxkdi_boot(image_header_t *); |
47d1a6e1 | 117 | #endif |
b1d0db18 | 118 | #ifdef CONFIG_BOOTM_RTEMS |
1ee1180b | 119 | static boot_os_fn do_bootm_rtems; |
b1d0db18 | 120 | #endif |
3df61957 TL |
121 | #if defined(CONFIG_BOOTM_OSE) |
122 | static boot_os_fn do_bootm_ose; | |
123 | #endif | |
04d41409 SS |
124 | #if defined(CONFIG_BOOTM_PLAN9) |
125 | static boot_os_fn do_bootm_plan9; | |
126 | #endif | |
871a57bb MY |
127 | #if defined(CONFIG_BOOTM_VXWORKS) && \ |
128 | (defined(CONFIG_PPC) || defined(CONFIG_ARM)) | |
1ee1180b | 129 | static boot_os_fn do_bootm_vxworks; |
17ab52fe MY |
130 | #endif |
131 | #if defined(CONFIG_CMD_ELF) | |
1ee1180b | 132 | static boot_os_fn do_bootm_qnxelf; |
712fbcf3 SW |
133 | int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
134 | int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); | |
90253178 | 135 | #endif |
f5ed9e39 PT |
136 | #if defined(CONFIG_INTEGRITY) |
137 | static boot_os_fn do_bootm_integrity; | |
138 | #endif | |
47d1a6e1 | 139 | |
0008555f | 140 | static boot_os_fn *boot_os[] = { |
c5cbe1e2 | 141 | [IH_OS_U_BOOT] = do_bootm_standalone, |
b1d0db18 | 142 | #ifdef CONFIG_BOOTM_LINUX |
be083159 | 143 | [IH_OS_LINUX] = do_bootm_linux, |
b1d0db18 KG |
144 | #endif |
145 | #ifdef CONFIG_BOOTM_NETBSD | |
be083159 | 146 | [IH_OS_NETBSD] = do_bootm_netbsd, |
b1d0db18 | 147 | #endif |
be083159 KG |
148 | #ifdef CONFIG_LYNXKDI |
149 | [IH_OS_LYNXOS] = do_bootm_lynxkdi, | |
150 | #endif | |
b1d0db18 | 151 | #ifdef CONFIG_BOOTM_RTEMS |
be083159 | 152 | [IH_OS_RTEMS] = do_bootm_rtems, |
b1d0db18 | 153 | #endif |
3df61957 TL |
154 | #if defined(CONFIG_BOOTM_OSE) |
155 | [IH_OS_OSE] = do_bootm_ose, | |
156 | #endif | |
04d41409 SS |
157 | #if defined(CONFIG_BOOTM_PLAN9) |
158 | [IH_OS_PLAN9] = do_bootm_plan9, | |
159 | #endif | |
871a57bb MY |
160 | #if defined(CONFIG_BOOTM_VXWORKS) && \ |
161 | (defined(CONFIG_PPC) || defined(CONFIG_ARM)) | |
be083159 | 162 | [IH_OS_VXWORKS] = do_bootm_vxworks, |
17ab52fe MY |
163 | #endif |
164 | #if defined(CONFIG_CMD_ELF) | |
be083159 KG |
165 | [IH_OS_QNX] = do_bootm_qnxelf, |
166 | #endif | |
167 | #ifdef CONFIG_INTEGRITY | |
168 | [IH_OS_INTEGRITY] = do_bootm_integrity, | |
169 | #endif | |
170 | }; | |
171 | ||
dee17768 | 172 | bootm_headers_t images; /* pointers to os/initrd/fdt images */ |
15940c9a | 173 | |
3dfad40a | 174 | /* Allow for arch specific config before we boot */ |
088f1b19 | 175 | static void __arch_preboot_os(void) |
3dfad40a KG |
176 | { |
177 | /* please define platform specific arch_preboot_os() */ | |
178 | } | |
179 | void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os"))); | |
180 | ||
476af299 | 181 | #define IH_INITRD_ARCH IH_ARCH_DEFAULT |
47d1a6e1 | 182 | |
a16028da | 183 | #ifdef CONFIG_LMB |
44f074c7 MV |
184 | static void boot_start_lmb(bootm_headers_t *images) |
185 | { | |
391fd93a BB |
186 | ulong mem_start; |
187 | phys_size_t mem_size; | |
47d1a6e1 | 188 | |
44f074c7 | 189 | lmb_init(&images->lmb); |
47d1a6e1 | 190 | |
d3f2fa0d KG |
191 | mem_start = getenv_bootm_low(); |
192 | mem_size = getenv_bootm_size(); | |
47d1a6e1 | 193 | |
44f074c7 | 194 | lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size); |
47d1a6e1 | 195 | |
44f074c7 MV |
196 | arch_lmb_reserve(&images->lmb); |
197 | board_lmb_reserve(&images->lmb); | |
198 | } | |
a16028da | 199 | #else |
35cf5fe5 | 200 | #define lmb_reserve(lmb, base, size) |
44f074c7 | 201 | static inline void boot_start_lmb(bootm_headers_t *images) { } |
a16028da | 202 | #endif |
a16028da | 203 | |
54841ab5 | 204 | static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
a16028da | 205 | { |
712fbcf3 SW |
206 | memset((void *)&images, 0, sizeof(images)); |
207 | images.verify = getenv_yesno("verify"); | |
a16028da | 208 | |
44f074c7 | 209 | boot_start_lmb(&images); |
47d1a6e1 | 210 | |
573f14fe | 211 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start"); |
35fc84fa SG |
212 | images.state = BOOTM_STATE_START; |
213 | ||
214 | return 0; | |
215 | } | |
216 | ||
217 | static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc, | |
218 | char * const argv[]) | |
219 | { | |
220 | const void *os_hdr; | |
9ace3fc8 | 221 | bool ep_found = false; |
573f14fe | 222 | |
5cf746c3 | 223 | /* get kernel image header, start address and length */ |
712fbcf3 | 224 | os_hdr = boot_get_kernel(cmdtp, flag, argc, argv, |
396f635b KG |
225 | &images, &images.os.image_start, &images.os.image_len); |
226 | if (images.os.image_len == 0) { | |
712fbcf3 | 227 | puts("ERROR: can't get kernel image!\n"); |
47d1a6e1 | 228 | return 1; |
bccae903 | 229 | } |
bccae903 | 230 | |
d5934ad7 | 231 | /* get image parameters */ |
712fbcf3 | 232 | switch (genimg_get_format(os_hdr)) { |
21d29f7f | 233 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
d5934ad7 | 234 | case IMAGE_FORMAT_LEGACY: |
712fbcf3 SW |
235 | images.os.type = image_get_type(os_hdr); |
236 | images.os.comp = image_get_comp(os_hdr); | |
237 | images.os.os = image_get_os(os_hdr); | |
bccae903 | 238 | |
712fbcf3 SW |
239 | images.os.end = image_get_image_end(os_hdr); |
240 | images.os.load = image_get_load(os_hdr); | |
d5934ad7 | 241 | break; |
21d29f7f | 242 | #endif |
d5934ad7 MB |
243 | #if defined(CONFIG_FIT) |
244 | case IMAGE_FORMAT_FIT: | |
712fbcf3 | 245 | if (fit_image_get_type(images.fit_hdr_os, |
396f635b | 246 | images.fit_noffset_os, &images.os.type)) { |
712fbcf3 | 247 | puts("Can't get image type!\n"); |
770605e4 | 248 | bootstage_error(BOOTSTAGE_ID_FIT_TYPE); |
6986a385 MB |
249 | return 1; |
250 | } | |
47d1a6e1 | 251 | |
712fbcf3 | 252 | if (fit_image_get_comp(images.fit_hdr_os, |
396f635b | 253 | images.fit_noffset_os, &images.os.comp)) { |
712fbcf3 | 254 | puts("Can't get image compression!\n"); |
770605e4 | 255 | bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION); |
6986a385 MB |
256 | return 1; |
257 | } | |
47d1a6e1 | 258 | |
712fbcf3 | 259 | if (fit_image_get_os(images.fit_hdr_os, |
396f635b | 260 | images.fit_noffset_os, &images.os.os)) { |
712fbcf3 | 261 | puts("Can't get image OS!\n"); |
770605e4 | 262 | bootstage_error(BOOTSTAGE_ID_FIT_OS); |
47d1a6e1 WD |
263 | return 1; |
264 | } | |
47d1a6e1 | 265 | |
712fbcf3 | 266 | images.os.end = fit_get_end(images.fit_hdr_os); |
6986a385 | 267 | |
712fbcf3 | 268 | if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os, |
396f635b | 269 | &images.os.load)) { |
712fbcf3 | 270 | puts("Can't get image load address!\n"); |
770605e4 | 271 | bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR); |
6986a385 | 272 | return 1; |
b13fb01a WD |
273 | } |
274 | break; | |
9ace3fc8 SS |
275 | #endif |
276 | #ifdef CONFIG_ANDROID_BOOT_IMAGE | |
277 | case IMAGE_FORMAT_ANDROID: | |
278 | images.os.type = IH_TYPE_KERNEL; | |
279 | images.os.comp = IH_COMP_NONE; | |
280 | images.os.os = IH_OS_LINUX; | |
281 | images.ep = images.os.load; | |
282 | ep_found = true; | |
283 | ||
284 | images.os.end = android_image_get_end(os_hdr); | |
285 | images.os.load = android_image_get_kload(os_hdr); | |
286 | break; | |
d5934ad7 MB |
287 | #endif |
288 | default: | |
712fbcf3 | 289 | puts("ERROR: unknown image format type!\n"); |
47d1a6e1 WD |
290 | return 1; |
291 | } | |
d5934ad7 | 292 | |
c160a954 KG |
293 | /* find kernel entry point */ |
294 | if (images.legacy_hdr_valid) { | |
712fbcf3 | 295 | images.ep = image_get_ep(&images.legacy_hdr_os_copy); |
c160a954 KG |
296 | #if defined(CONFIG_FIT) |
297 | } else if (images.fit_uname_os) { | |
35fc84fa SG |
298 | int ret; |
299 | ||
712fbcf3 | 300 | ret = fit_image_get_entry(images.fit_hdr_os, |
c19d13b0 | 301 | images.fit_noffset_os, &images.ep); |
c160a954 | 302 | if (ret) { |
712fbcf3 | 303 | puts("Can't get entry point property!\n"); |
c160a954 KG |
304 | return 1; |
305 | } | |
306 | #endif | |
9ace3fc8 | 307 | } else if (!ep_found) { |
712fbcf3 | 308 | puts("Could not find kernel entry point!\n"); |
c160a954 KG |
309 | return 1; |
310 | } | |
311 | ||
b9b50e89 SW |
312 | if (images.os.type == IH_TYPE_KERNEL_NOLOAD) { |
313 | images.os.load = images.os.image_start; | |
314 | images.ep += images.os.load; | |
315 | } | |
316 | ||
35fc84fa SG |
317 | images.os.start = (ulong)os_hdr; |
318 | ||
319 | return 0; | |
320 | } | |
321 | ||
225fd8c5 TR |
322 | static int bootm_find_ramdisk(int flag, int argc, char * const argv[]) |
323 | { | |
324 | int ret; | |
325 | ||
326 | /* find ramdisk */ | |
327 | ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH, | |
328 | &images.rd_start, &images.rd_end); | |
329 | if (ret) { | |
330 | puts("Ramdisk image is corrupt or invalid\n"); | |
331 | return 1; | |
332 | } | |
333 | ||
334 | return 0; | |
335 | } | |
336 | ||
337 | #if defined(CONFIG_OF_LIBFDT) | |
338 | static int bootm_find_fdt(int flag, int argc, char * const argv[]) | |
35fc84fa SG |
339 | { |
340 | int ret; | |
341 | ||
225fd8c5 TR |
342 | /* find flattened device tree */ |
343 | ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images, | |
344 | &images.ft_addr, &images.ft_len); | |
345 | if (ret) { | |
346 | puts("Could not find a valid device tree\n"); | |
347 | return 1; | |
348 | } | |
349 | ||
350 | set_working_fdt_addr(images.ft_addr); | |
351 | ||
352 | return 0; | |
353 | } | |
354 | #endif | |
355 | ||
356 | static int bootm_find_other(cmd_tbl_t *cmdtp, int flag, int argc, | |
357 | char * const argv[]) | |
358 | { | |
24de2f4b | 359 | if (((images.os.type == IH_TYPE_KERNEL) || |
b9b50e89 | 360 | (images.os.type == IH_TYPE_KERNEL_NOLOAD) || |
24de2f4b | 361 | (images.os.type == IH_TYPE_MULTI)) && |
871a57bb MY |
362 | (images.os.os == IH_OS_LINUX || |
363 | images.os.os == IH_OS_VXWORKS)) { | |
225fd8c5 | 364 | if (bootm_find_ramdisk(flag, argc, argv)) |
c4f9419c | 365 | return 1; |
06a09918 KG |
366 | |
367 | #if defined(CONFIG_OF_LIBFDT) | |
225fd8c5 | 368 | if (bootm_find_fdt(flag, argc, argv)) |
06a09918 | 369 | return 1; |
06a09918 | 370 | #endif |
c4f9419c KG |
371 | } |
372 | ||
396f635b KG |
373 | return 0; |
374 | } | |
3d71c81a | 375 | |
396f635b KG |
376 | #define BOOTM_ERR_RESET -1 |
377 | #define BOOTM_ERR_OVERLAP -2 | |
378 | #define BOOTM_ERR_UNIMPLEMENTED -3 | |
d366438d TR |
379 | static int bootm_load_os(bootm_headers_t *images, unsigned long *load_end, |
380 | int boot_progress) | |
396f635b | 381 | { |
d366438d | 382 | image_info_t os = images->os; |
396f635b KG |
383 | uint8_t comp = os.comp; |
384 | ulong load = os.load; | |
385 | ulong blob_start = os.start; | |
386 | ulong blob_end = os.end; | |
387 | ulong image_start = os.image_start; | |
388 | ulong image_len = os.image_len; | |
5bf2766b | 389 | __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN; |
d510859b | 390 | int no_overlap = 0; |
aed161e5 | 391 | void *load_buf, *image_buf; |
60fdc5f2 MW |
392 | #if defined(CONFIG_LZMA) || defined(CONFIG_LZO) |
393 | int ret; | |
394 | #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */ | |
3d71c81a | 395 | |
712fbcf3 | 396 | const char *type_name = genimg_get_type_name(os.type); |
c7de829c | 397 | |
315c0ace | 398 | load_buf = map_sysmem(load, unc_len); |
aed161e5 | 399 | image_buf = map_sysmem(image_start, image_len); |
d5934ad7 | 400 | switch (comp) { |
47d1a6e1 | 401 | case IH_COMP_NONE: |
717ccc1d | 402 | if (load == image_start) { |
712fbcf3 | 403 | printf(" XIP %s ... ", type_name); |
d510859b | 404 | no_overlap = 1; |
47d1a6e1 | 405 | } else { |
712fbcf3 | 406 | printf(" Loading %s ... ", type_name); |
aed161e5 | 407 | memmove_wd(load_buf, image_buf, image_len, CHUNKSZ); |
47d1a6e1 | 408 | } |
396f635b | 409 | *load_end = load + image_len; |
47d1a6e1 | 410 | break; |
44431cab | 411 | #ifdef CONFIG_GZIP |
47d1a6e1 | 412 | case IH_COMP_GZIP: |
712fbcf3 | 413 | printf(" Uncompressing %s ... ", type_name); |
aed161e5 | 414 | if (gunzip(load_buf, unc_len, image_buf, &image_len) != 0) { |
712fbcf3 SW |
415 | puts("GUNZIP: uncompress, out-of-mem or overwrite " |
416 | "error - must RESET board to recover\n"); | |
396f635b | 417 | if (boot_progress) |
770605e4 | 418 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
396f635b | 419 | return BOOTM_ERR_RESET; |
47d1a6e1 | 420 | } |
7582438c | 421 | |
396f635b | 422 | *load_end = load + image_len; |
47d1a6e1 | 423 | break; |
44431cab | 424 | #endif /* CONFIG_GZIP */ |
c29fdfc1 WD |
425 | #ifdef CONFIG_BZIP2 |
426 | case IH_COMP_BZIP2: | |
712fbcf3 | 427 | printf(" Uncompressing %s ... ", type_name); |
5653fc33 WD |
428 | /* |
429 | * If we've got less than 4 MB of malloc() space, | |
430 | * use slower decompression algorithm which requires | |
431 | * at most 2300 KB of memory. | |
432 | */ | |
aed161e5 SG |
433 | int i = BZ2_bzBuffToBuffDecompress(load_buf, &unc_len, |
434 | image_buf, image_len, | |
435 | CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0); | |
c29fdfc1 | 436 | if (i != BZ_OK) { |
712fbcf3 | 437 | printf("BUNZIP2: uncompress or overwrite error %d " |
2682ce8a | 438 | "- must RESET board to recover\n", i); |
396f635b | 439 | if (boot_progress) |
770605e4 | 440 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
396f635b | 441 | return BOOTM_ERR_RESET; |
c29fdfc1 | 442 | } |
7582438c | 443 | |
396f635b | 444 | *load_end = load + unc_len; |
c29fdfc1 WD |
445 | break; |
446 | #endif /* CONFIG_BZIP2 */ | |
fc9c1727 | 447 | #ifdef CONFIG_LZMA |
78e1e846 MF |
448 | case IH_COMP_LZMA: { |
449 | SizeT lzma_len = unc_len; | |
712fbcf3 | 450 | printf(" Uncompressing %s ... ", type_name); |
fc9c1727 | 451 | |
aed161e5 SG |
452 | ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len, |
453 | image_buf, image_len); | |
78e1e846 | 454 | unc_len = lzma_len; |
caf72ff3 | 455 | if (ret != SZ_OK) { |
712fbcf3 | 456 | printf("LZMA: uncompress or overwrite error %d " |
fc9c1727 | 457 | "- must RESET board to recover\n", ret); |
770605e4 | 458 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
fc9c1727 LCM |
459 | return BOOTM_ERR_RESET; |
460 | } | |
461 | *load_end = load + unc_len; | |
462 | break; | |
78e1e846 | 463 | } |
fc9c1727 | 464 | #endif /* CONFIG_LZMA */ |
20dde48b | 465 | #ifdef CONFIG_LZO |
628af179 | 466 | case IH_COMP_LZO: { |
77cc8902 | 467 | size_t size = unc_len; |
628af179 | 468 | |
712fbcf3 | 469 | printf(" Uncompressing %s ... ", type_name); |
20dde48b | 470 | |
628af179 | 471 | ret = lzop_decompress(image_buf, image_len, load_buf, &size); |
20dde48b | 472 | if (ret != LZO_E_OK) { |
712fbcf3 | 473 | printf("LZO: uncompress or overwrite error %d " |
20dde48b PK |
474 | "- must RESET board to recover\n", ret); |
475 | if (boot_progress) | |
770605e4 | 476 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
20dde48b PK |
477 | return BOOTM_ERR_RESET; |
478 | } | |
479 | ||
628af179 | 480 | *load_end = load + size; |
20dde48b | 481 | break; |
628af179 | 482 | } |
20dde48b | 483 | #endif /* CONFIG_LZO */ |
47d1a6e1 | 484 | default: |
712fbcf3 | 485 | printf("Unimplemented compression type %d\n", comp); |
396f635b | 486 | return BOOTM_ERR_UNIMPLEMENTED; |
47d1a6e1 | 487 | } |
99ffccbd DC |
488 | |
489 | flush_cache(load, (*load_end - load) * sizeof(ulong)); | |
490 | ||
712fbcf3 SW |
491 | puts("OK\n"); |
492 | debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end); | |
770605e4 | 493 | bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED); |
47d1a6e1 | 494 | |
d510859b | 495 | if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) { |
712fbcf3 SW |
496 | debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n", |
497 | blob_start, blob_end); | |
498 | debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load, | |
499 | *load_end); | |
47d1a6e1 | 500 | |
d366438d TR |
501 | /* Check what type of image this is. */ |
502 | if (images->legacy_hdr_valid) { | |
503 | if (image_get_type(&images->legacy_hdr_os_copy) | |
504 | == IH_TYPE_MULTI) | |
505 | puts("WARNING: legacy format multi component image overwritten\n"); | |
506 | return BOOTM_ERR_OVERLAP; | |
507 | } else { | |
508 | puts("ERROR: new format image overwritten - must RESET the board to recover\n"); | |
509 | bootstage_error(BOOTSTAGE_ID_OVERWRITTEN); | |
510 | return BOOTM_ERR_RESET; | |
511 | } | |
396f635b KG |
512 | } |
513 | ||
514 | return 0; | |
515 | } | |
516 | ||
c5cbe1e2 SG |
517 | static int do_bootm_standalone(int flag, int argc, char * const argv[], |
518 | bootm_headers_t *images) | |
f97ec30b DZ |
519 | { |
520 | char *s; | |
54841ab5 | 521 | int (*appl)(int, char * const []); |
f97ec30b DZ |
522 | |
523 | /* Don't start if "autostart" is set to "no" */ | |
524 | if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) { | |
c5cbe1e2 | 525 | setenv_hex("filesize", images->os.image_len); |
f97ec30b DZ |
526 | return 0; |
527 | } | |
9c89614d CE |
528 | appl = (int (*)(int, char * const []))images->ep; |
529 | appl(argc, argv); | |
f97ec30b DZ |
530 | return 0; |
531 | } | |
532 | ||
49c3a861 KG |
533 | /* we overload the cmd field with our state machine info instead of a |
534 | * function pointer */ | |
f74d9bd2 | 535 | static cmd_tbl_t cmd_bootm_sub[] = { |
49c3a861 KG |
536 | U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""), |
537 | U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""), | |
fca43cc8 | 538 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
49c3a861 KG |
539 | U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""), |
540 | #endif | |
541 | #ifdef CONFIG_OF_LIBFDT | |
542 | U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""), | |
543 | #endif | |
49c3a861 | 544 | U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""), |
224c90d1 | 545 | U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""), |
49c3a861 | 546 | U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""), |
d0ae31eb | 547 | U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""), |
49c3a861 KG |
548 | U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""), |
549 | }; | |
550 | ||
35fc84fa | 551 | static int boot_selected_os(int argc, char * const argv[], int state, |
5ff0d083 | 552 | bootm_headers_t *images, boot_os_fn *boot_fn) |
35fc84fa | 553 | { |
35fc84fa SG |
554 | arch_preboot_os(); |
555 | boot_fn(state, argc, argv, images); | |
c5cbe1e2 SG |
556 | |
557 | /* Stand-alone may return when 'autostart' is 'no' */ | |
558 | if (images->os.type == IH_TYPE_STANDALONE || | |
559 | state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */ | |
d0ae31eb | 560 | return 0; |
35fc84fa SG |
561 | bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED); |
562 | #ifdef DEBUG | |
563 | puts("\n## Control returned to monitor - resetting...\n"); | |
564 | #endif | |
565 | return BOOTM_ERR_RESET; | |
566 | } | |
567 | ||
385501d3 SG |
568 | /** |
569 | * bootm_disable_interrupts() - Disable interrupts in preparation for load/boot | |
570 | * | |
571 | * @return interrupt flag (0 if interrupts were disabled, non-zero if they were | |
572 | * enabled) | |
573 | */ | |
574 | static ulong bootm_disable_interrupts(void) | |
575 | { | |
576 | ulong iflag; | |
577 | ||
578 | /* | |
579 | * We have reached the point of no return: we are going to | |
580 | * overwrite all exception vector code, so we cannot easily | |
581 | * recover from any failures any more... | |
582 | */ | |
583 | iflag = disable_interrupts(); | |
584 | #ifdef CONFIG_NETCONSOLE | |
585 | /* Stop the ethernet stack if NetConsole could have left it up */ | |
586 | eth_halt(); | |
8094972d | 587 | eth_unregister(eth_get_dev()); |
385501d3 SG |
588 | #endif |
589 | ||
590 | #if defined(CONFIG_CMD_USB) | |
591 | /* | |
592 | * turn off USB to prevent the host controller from writing to the | |
593 | * SDRAM while Linux is booting. This could happen (at least for OHCI | |
594 | * controller), because the HCCA (Host Controller Communication Area) | |
595 | * lies within the SDRAM and the host controller writes continously to | |
596 | * this area (as busmaster!). The HccaFrameNumber is for example | |
597 | * updated every 1 ms within the HCCA structure in SDRAM! For more | |
598 | * details see the OpenHCI specification. | |
599 | */ | |
600 | usb_stop(); | |
601 | #endif | |
602 | return iflag; | |
603 | } | |
604 | ||
35fc84fa SG |
605 | /** |
606 | * Execute selected states of the bootm command. | |
607 | * | |
608 | * Note the arguments to this state must be the first argument, Any 'bootm' | |
609 | * or sub-command arguments must have already been taken. | |
610 | * | |
611 | * Note that if states contains more than one flag it MUST contain | |
612 | * BOOTM_STATE_START, since this handles and consumes the command line args. | |
613 | * | |
d366438d TR |
614 | * Also note that aside from boot_os_fn functions and bootm_load_os no other |
615 | * functions we store the return value of in 'ret' may use a negative return | |
616 | * value, without special handling. | |
617 | * | |
35fc84fa SG |
618 | * @param cmdtp Pointer to bootm command table entry |
619 | * @param flag Command flags (CMD_FLAG_...) | |
620 | * @param argc Number of subcommand arguments (0 = no arguments) | |
621 | * @param argv Arguments | |
622 | * @param states Mask containing states to run (BOOTM_STATE_...) | |
623 | * @param images Image header information | |
624 | * @param boot_progress 1 to show boot progress, 0 to not do this | |
625 | * @return 0 if ok, something else on error. Some errors will cause this | |
626 | * function to perform a reboot! If states contains BOOTM_STATE_OS_GO | |
627 | * then the intent is to boot an OS, so this function will not return | |
628 | * unless the image type is standalone. | |
629 | */ | |
630 | static int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, | |
631 | char * const argv[], int states, bootm_headers_t *images, | |
632 | int boot_progress) | |
633 | { | |
634 | boot_os_fn *boot_fn; | |
635 | ulong iflag = 0; | |
a26913f3 | 636 | int ret = 0, need_boot_fn; |
35fc84fa SG |
637 | |
638 | images->state |= states; | |
639 | ||
640 | /* | |
641 | * Work through the states and see how far we get. We stop on | |
642 | * any error. | |
643 | */ | |
644 | if (states & BOOTM_STATE_START) | |
645 | ret = bootm_start(cmdtp, flag, argc, argv); | |
646 | ||
647 | if (!ret && (states & BOOTM_STATE_FINDOS)) | |
648 | ret = bootm_find_os(cmdtp, flag, argc, argv); | |
649 | ||
650 | if (!ret && (states & BOOTM_STATE_FINDOTHER)) { | |
651 | ret = bootm_find_other(cmdtp, flag, argc, argv); | |
652 | argc = 0; /* consume the args */ | |
653 | } | |
654 | ||
655 | /* Load the OS */ | |
656 | if (!ret && (states & BOOTM_STATE_LOADOS)) { | |
657 | ulong load_end; | |
658 | ||
385501d3 | 659 | iflag = bootm_disable_interrupts(); |
d366438d | 660 | ret = bootm_load_os(images, &load_end, 0); |
d366438d | 661 | if (ret == 0) |
35fc84fa SG |
662 | lmb_reserve(&images->lmb, images->os.load, |
663 | (load_end - images->os.load)); | |
970150a1 TR |
664 | else if (ret && ret != BOOTM_ERR_OVERLAP) |
665 | goto err; | |
d366438d TR |
666 | else if (ret == BOOTM_ERR_OVERLAP) |
667 | ret = 0; | |
bd4a3997 | 668 | #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY) |
576aacdb SG |
669 | if (images->os.os == IH_OS_LINUX) |
670 | fixup_silent_linux(); | |
671 | #endif | |
35fc84fa SG |
672 | } |
673 | ||
674 | /* Relocate the ramdisk */ | |
675 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH | |
676 | if (!ret && (states & BOOTM_STATE_RAMDISK)) { | |
677 | ulong rd_len = images->rd_end - images->rd_start; | |
678 | ||
679 | ret = boot_ramdisk_high(&images->lmb, images->rd_start, | |
680 | rd_len, &images->initrd_start, &images->initrd_end); | |
681 | if (!ret) { | |
682 | setenv_hex("initrd_start", images->initrd_start); | |
683 | setenv_hex("initrd_end", images->initrd_end); | |
684 | } | |
685 | } | |
686 | #endif | |
687 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB) | |
688 | if (!ret && (states & BOOTM_STATE_FDT)) { | |
689 | boot_fdt_add_mem_rsv_regions(&images->lmb, images->ft_addr); | |
690 | ret = boot_relocate_fdt(&images->lmb, &images->ft_addr, | |
691 | &images->ft_len); | |
692 | } | |
693 | #endif | |
694 | ||
695 | /* From now on, we need the OS boot function */ | |
696 | if (ret) | |
697 | return ret; | |
698 | boot_fn = boot_os[images->os.os]; | |
a26913f3 SG |
699 | need_boot_fn = states & (BOOTM_STATE_OS_CMDLINE | |
700 | BOOTM_STATE_OS_BD_T | BOOTM_STATE_OS_PREP | | |
701 | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO); | |
702 | if (boot_fn == NULL && need_boot_fn) { | |
35fc84fa SG |
703 | if (iflag) |
704 | enable_interrupts(); | |
705 | printf("ERROR: booting os '%s' (%d) is not supported\n", | |
706 | genimg_get_os_name(images->os.os), images->os.os); | |
707 | bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS); | |
708 | return 1; | |
709 | } | |
710 | ||
711 | /* Call various other states that are not generally used */ | |
712 | if (!ret && (states & BOOTM_STATE_OS_CMDLINE)) | |
713 | ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images); | |
714 | if (!ret && (states & BOOTM_STATE_OS_BD_T)) | |
715 | ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images); | |
716 | if (!ret && (states & BOOTM_STATE_OS_PREP)) | |
717 | ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images); | |
718 | ||
d0ae31eb SG |
719 | #ifdef CONFIG_TRACE |
720 | /* Pretend to run the OS, then run a user command */ | |
721 | if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) { | |
722 | char *cmd_list = getenv("fakegocmd"); | |
723 | ||
724 | ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_FAKE_GO, | |
5ff0d083 | 725 | images, boot_fn); |
d0ae31eb SG |
726 | if (!ret && cmd_list) |
727 | ret = run_command_list(cmd_list, -1, flag); | |
728 | } | |
729 | #endif | |
b7a1d134 SG |
730 | |
731 | /* Check for unsupported subcommand. */ | |
732 | if (ret) { | |
733 | puts("subcommand not supported\n"); | |
734 | return ret; | |
735 | } | |
736 | ||
35fc84fa | 737 | /* Now run the OS! We hope this doesn't return */ |
b7a1d134 | 738 | if (!ret && (states & BOOTM_STATE_OS_GO)) |
35fc84fa | 739 | ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_GO, |
5ff0d083 | 740 | images, boot_fn); |
35fc84fa SG |
741 | |
742 | /* Deal with any fallout */ | |
d366438d | 743 | err: |
35fc84fa SG |
744 | if (iflag) |
745 | enable_interrupts(); | |
d366438d TR |
746 | |
747 | if (ret == BOOTM_ERR_UNIMPLEMENTED) | |
748 | bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL); | |
749 | else if (ret == BOOTM_ERR_RESET) | |
750 | do_reset(cmdtp, flag, argc, argv); | |
35fc84fa SG |
751 | |
752 | return ret; | |
753 | } | |
754 | ||
088f1b19 | 755 | static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc, |
712fbcf3 | 756 | char * const argv[]) |
49c3a861 KG |
757 | { |
758 | int ret = 0; | |
6d6f1236 | 759 | long state; |
49c3a861 | 760 | cmd_tbl_t *c; |
49c3a861 | 761 | |
983c72f4 SG |
762 | c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub)); |
763 | argc--; argv++; | |
49c3a861 KG |
764 | |
765 | if (c) { | |
6d6f1236 | 766 | state = (long)c->cmd; |
983c72f4 | 767 | if (state == BOOTM_STATE_START) |
35fc84fa | 768 | state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER; |
47e26b1b WD |
769 | } else { |
770 | /* Unrecognized command */ | |
4c12eeb8 | 771 | return CMD_RET_USAGE; |
49c3a861 KG |
772 | } |
773 | ||
35fc84fa | 774 | if (state != BOOTM_STATE_START && images.state >= state) { |
712fbcf3 | 775 | printf("Trying to execute a command out of order\n"); |
4c12eeb8 | 776 | return CMD_RET_USAGE; |
49c3a861 KG |
777 | } |
778 | ||
35fc84fa | 779 | ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0); |
49c3a861 KG |
780 | |
781 | return ret; | |
782 | } | |
783 | ||
396f635b KG |
784 | /*******************************************************************/ |
785 | /* bootm - boot application image from image in memory */ | |
786 | /*******************************************************************/ | |
be083159 | 787 | |
712fbcf3 | 788 | int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
396f635b | 789 | { |
2e5167cc | 790 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
521af04d | 791 | static int relocated = 0; |
be083159 | 792 | |
be083159 KG |
793 | if (!relocated) { |
794 | int i; | |
58bd77db DS |
795 | |
796 | /* relocate boot function table */ | |
be083159 | 797 | for (i = 0; i < ARRAY_SIZE(boot_os); i++) |
ca95c9df DZ |
798 | if (boot_os[i] != NULL) |
799 | boot_os[i] += gd->reloc_off; | |
58bd77db DS |
800 | |
801 | /* relocate names of sub-command table */ | |
802 | for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++) | |
803 | cmd_bootm_sub[i].name += gd->reloc_off; | |
804 | ||
be083159 KG |
805 | relocated = 1; |
806 | } | |
521af04d | 807 | #endif |
396f635b | 808 | |
49c3a861 | 809 | /* determine if we have a sub command */ |
983c72f4 SG |
810 | argc--; argv++; |
811 | if (argc > 0) { | |
49c3a861 KG |
812 | char *endp; |
813 | ||
983c72f4 SG |
814 | simple_strtoul(argv[0], &endp, 16); |
815 | /* endp pointing to NULL means that argv[0] was just a | |
49c3a861 KG |
816 | * valid number, pass it along to the normal bootm processing |
817 | * | |
818 | * If endp is ':' or '#' assume a FIT identifier so pass | |
819 | * along for normal processing. | |
820 | * | |
821 | * Right now we assume the first arg should never be '-' | |
822 | */ | |
823 | if ((*endp != 0) && (*endp != ':') && (*endp != '#')) | |
824 | return do_bootm_subcommand(cmdtp, flag, argc, argv); | |
825 | } | |
826 | ||
35fc84fa SG |
827 | return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START | |
828 | BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER | | |
3d187b39 TR |
829 | BOOTM_STATE_LOADOS | |
830 | #if defined(CONFIG_PPC) || defined(CONFIG_MIPS) | |
831 | BOOTM_STATE_OS_CMDLINE | | |
832 | #endif | |
5c427e49 PB |
833 | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | |
834 | BOOTM_STATE_OS_GO, &images, 1); | |
47d1a6e1 WD |
835 | } |
836 | ||
67d668bf MF |
837 | int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd) |
838 | { | |
839 | const char *ep = getenv("autostart"); | |
840 | ||
841 | if (ep && !strcmp(ep, "yes")) { | |
842 | char *local_args[2]; | |
843 | local_args[0] = (char *)cmd; | |
844 | local_args[1] = NULL; | |
845 | printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr); | |
846 | return do_bootm(cmdtp, 0, 1, local_args); | |
847 | } | |
848 | ||
849 | return 0; | |
850 | } | |
851 | ||
21d29f7f | 852 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
1efd4360 | 853 | /** |
9a4daad0 MB |
854 | * image_get_kernel - verify legacy format kernel image |
855 | * @img_addr: in RAM address of the legacy format image to be verified | |
856 | * @verify: data CRC verification flag | |
1efd4360 | 857 | * |
9a4daad0 MB |
858 | * image_get_kernel() verifies legacy image integrity and returns pointer to |
859 | * legacy image header if image verification was completed successfully. | |
1efd4360 MB |
860 | * |
861 | * returns: | |
9a4daad0 MB |
862 | * pointer to a legacy image header if valid image was found |
863 | * otherwise return NULL | |
1efd4360 | 864 | */ |
712fbcf3 | 865 | static image_header_t *image_get_kernel(ulong img_addr, int verify) |
f72da340 | 866 | { |
1efd4360 | 867 | image_header_t *hdr = (image_header_t *)img_addr; |
f72da340 | 868 | |
1efd4360 | 869 | if (!image_check_magic(hdr)) { |
712fbcf3 | 870 | puts("Bad Magic Number\n"); |
770605e4 | 871 | bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC); |
1efd4360 MB |
872 | return NULL; |
873 | } | |
770605e4 | 874 | bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER); |
f72da340 | 875 | |
712fbcf3 SW |
876 | if (!image_check_hcrc(hdr)) { |
877 | puts("Bad Header Checksum\n"); | |
770605e4 | 878 | bootstage_error(BOOTSTAGE_ID_CHECK_HEADER); |
1efd4360 MB |
879 | return NULL; |
880 | } | |
881 | ||
770605e4 | 882 | bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM); |
712fbcf3 | 883 | image_print_contents(hdr); |
1efd4360 MB |
884 | |
885 | if (verify) { | |
712fbcf3 SW |
886 | puts(" Verifying Checksum ... "); |
887 | if (!image_check_dcrc(hdr)) { | |
888 | printf("Bad Data CRC\n"); | |
770605e4 | 889 | bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM); |
1efd4360 | 890 | return NULL; |
f72da340 | 891 | } |
712fbcf3 | 892 | puts("OK\n"); |
f72da340 | 893 | } |
770605e4 | 894 | bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH); |
f72da340 | 895 | |
712fbcf3 SW |
896 | if (!image_check_target_arch(hdr)) { |
897 | printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr)); | |
770605e4 | 898 | bootstage_error(BOOTSTAGE_ID_CHECK_ARCH); |
1efd4360 MB |
899 | return NULL; |
900 | } | |
901 | return hdr; | |
f72da340 | 902 | } |
21d29f7f | 903 | #endif |
f72da340 | 904 | |
5cf746c3 | 905 | /** |
9a4daad0 | 906 | * boot_get_kernel - find kernel image |
5cf746c3 MB |
907 | * @os_data: pointer to a ulong variable, will hold os data start address |
908 | * @os_len: pointer to a ulong variable, will hold os data length | |
909 | * | |
9a4daad0 | 910 | * boot_get_kernel() tries to find a kernel image, verifies its integrity |
5cf746c3 MB |
911 | * and locates kernel data. |
912 | * | |
913 | * returns: | |
914 | * pointer to image header if valid image was found, plus kernel start | |
915 | * address and length, otherwise NULL | |
916 | */ | |
35e7b0f1 | 917 | static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, |
712fbcf3 SW |
918 | char * const argv[], bootm_headers_t *images, ulong *os_data, |
919 | ulong *os_len) | |
5cf746c3 | 920 | { |
21d29f7f | 921 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
5cf746c3 | 922 | image_header_t *hdr; |
21d29f7f | 923 | #endif |
5cf746c3 | 924 | ulong img_addr; |
35e7b0f1 | 925 | const void *buf; |
d5934ad7 | 926 | #if defined(CONFIG_FIT) |
d5934ad7 MB |
927 | const char *fit_uname_config = NULL; |
928 | const char *fit_uname_kernel = NULL; | |
6986a385 | 929 | int os_noffset; |
d5934ad7 | 930 | #endif |
56f94be3 | 931 | |
d5934ad7 | 932 | /* find out kernel image address */ |
983c72f4 | 933 | if (argc < 1) { |
5cf746c3 | 934 | img_addr = load_addr; |
712fbcf3 | 935 | debug("* kernel: default image load address = 0x%08lx\n", |
d5934ad7 MB |
936 | load_addr); |
937 | #if defined(CONFIG_FIT) | |
983c72f4 | 938 | } else if (fit_parse_conf(argv[0], load_addr, &img_addr, |
d5934ad7 | 939 | &fit_uname_config)) { |
712fbcf3 | 940 | debug("* kernel: config '%s' from image at 0x%08lx\n", |
d5934ad7 | 941 | fit_uname_config, img_addr); |
983c72f4 | 942 | } else if (fit_parse_subimage(argv[0], load_addr, &img_addr, |
d5934ad7 | 943 | &fit_uname_kernel)) { |
712fbcf3 | 944 | debug("* kernel: subimage '%s' from image at 0x%08lx\n", |
d5934ad7 MB |
945 | fit_uname_kernel, img_addr); |
946 | #endif | |
5cf746c3 | 947 | } else { |
983c72f4 | 948 | img_addr = simple_strtoul(argv[0], NULL, 16); |
712fbcf3 | 949 | debug("* kernel: cmdline image address = 0x%08lx\n", img_addr); |
5cf746c3 | 950 | } |
47d1a6e1 | 951 | |
770605e4 | 952 | bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC); |
56f94be3 | 953 | |
fff888a1 | 954 | /* copy from dataflash if needed */ |
712fbcf3 | 955 | img_addr = genimg_get_image(img_addr); |
5cf746c3 | 956 | |
d5934ad7 | 957 | /* check image type, for FIT images get FIT kernel node */ |
6986a385 | 958 | *os_data = *os_len = 0; |
35e7b0f1 SG |
959 | buf = map_sysmem(img_addr, 0); |
960 | switch (genimg_get_format(buf)) { | |
21d29f7f | 961 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
d5934ad7 | 962 | case IMAGE_FORMAT_LEGACY: |
712fbcf3 | 963 | printf("## Booting kernel from Legacy Image at %08lx ...\n", |
6986a385 | 964 | img_addr); |
712fbcf3 | 965 | hdr = image_get_kernel(img_addr, images->verify); |
1efd4360 | 966 | if (!hdr) |
d5934ad7 | 967 | return NULL; |
770605e4 | 968 | bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE); |
d5934ad7 | 969 | |
6986a385 | 970 | /* get os_data and os_len */ |
712fbcf3 | 971 | switch (image_get_type(hdr)) { |
d5934ad7 | 972 | case IH_TYPE_KERNEL: |
b9b50e89 | 973 | case IH_TYPE_KERNEL_NOLOAD: |
712fbcf3 SW |
974 | *os_data = image_get_data(hdr); |
975 | *os_len = image_get_data_size(hdr); | |
d5934ad7 MB |
976 | break; |
977 | case IH_TYPE_MULTI: | |
712fbcf3 | 978 | image_multi_getimg(hdr, 0, os_data, os_len); |
d5934ad7 | 979 | break; |
f97ec30b | 980 | case IH_TYPE_STANDALONE: |
712fbcf3 SW |
981 | *os_data = image_get_data(hdr); |
982 | *os_len = image_get_data_size(hdr); | |
f97ec30b | 983 | break; |
d5934ad7 | 984 | default: |
712fbcf3 SW |
985 | printf("Wrong Image Type for %s command\n", |
986 | cmdtp->name); | |
770605e4 | 987 | bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE); |
d5934ad7 MB |
988 | return NULL; |
989 | } | |
cb1c4896 MB |
990 | |
991 | /* | |
712fbcf3 SW |
992 | * copy image header to allow for image overwrites during |
993 | * kernel decompression. | |
cb1c4896 | 994 | */ |
712fbcf3 SW |
995 | memmove(&images->legacy_hdr_os_copy, hdr, |
996 | sizeof(image_header_t)); | |
cb1c4896 MB |
997 | |
998 | /* save pointer to image header */ | |
d5934ad7 | 999 | images->legacy_hdr_os = hdr; |
47d1a6e1 | 1000 | |
cb1c4896 | 1001 | images->legacy_hdr_valid = 1; |
770605e4 | 1002 | bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE); |
5cf746c3 | 1003 | break; |
21d29f7f | 1004 | #endif |
d5934ad7 MB |
1005 | #if defined(CONFIG_FIT) |
1006 | case IMAGE_FORMAT_FIT: | |
4651800d SG |
1007 | os_noffset = fit_image_load(images, FIT_KERNEL_PROP, |
1008 | img_addr, | |
f320a4d8 | 1009 | &fit_uname_kernel, &fit_uname_config, |
4651800d SG |
1010 | IH_ARCH_DEFAULT, IH_TYPE_KERNEL, |
1011 | BOOTSTAGE_ID_FIT_KERNEL_START, | |
1012 | FIT_LOAD_IGNORED, os_data, os_len); | |
1013 | if (os_noffset < 0) | |
6986a385 | 1014 | return NULL; |
47d1a6e1 | 1015 | |
4651800d | 1016 | images->fit_hdr_os = map_sysmem(img_addr, 0); |
6986a385 | 1017 | images->fit_uname_os = fit_uname_kernel; |
f320a4d8 | 1018 | images->fit_uname_cfg = fit_uname_config; |
3dfe1101 | 1019 | images->fit_noffset_os = os_noffset; |
6986a385 | 1020 | break; |
9ace3fc8 SS |
1021 | #endif |
1022 | #ifdef CONFIG_ANDROID_BOOT_IMAGE | |
1023 | case IMAGE_FORMAT_ANDROID: | |
1024 | printf("## Booting Android Image at 0x%08lx ...\n", img_addr); | |
1025 | if (android_image_get_kernel((void *)img_addr, images->verify, | |
1026 | os_data, os_len)) | |
1027 | return NULL; | |
1028 | break; | |
9c4c5ae3 | 1029 | #endif |
5cf746c3 | 1030 | default: |
712fbcf3 | 1031 | printf("Wrong Image Format for %s command\n", cmdtp->name); |
770605e4 | 1032 | bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO); |
5cf746c3 | 1033 | return NULL; |
47d1a6e1 WD |
1034 | } |
1035 | ||
712fbcf3 | 1036 | debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n", |
6986a385 | 1037 | *os_data, *os_len, *os_len); |
47d1a6e1 | 1038 | |
35e7b0f1 | 1039 | return buf; |
5cf746c3 | 1040 | } |
98a9c4d4 | 1041 | |
088f1b19 KP |
1042 | #ifdef CONFIG_SYS_LONGHELP |
1043 | static char bootm_help_text[] = | |
1ee1180b MB |
1044 | "[addr [arg ...]]\n - boot application image stored in memory\n" |
1045 | "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n" | |
1046 | "\t'arg' can be the address of an initrd image\n" | |
4a2ad5ff | 1047 | #if defined(CONFIG_OF_LIBFDT) |
98a9c4d4 | 1048 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
5441f61a | 1049 | "\ta third argument is required which is the address of the\n" |
98a9c4d4 MM |
1050 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
1051 | "\tuse a '-' for the second argument. If you do not pass a third\n" | |
1052 | "\ta bd_info struct will be passed instead\n" | |
98a9c4d4 | 1053 | #endif |
6986a385 MB |
1054 | #if defined(CONFIG_FIT) |
1055 | "\t\nFor the new multi component uImage format (FIT) addresses\n" | |
1056 | "\tmust be extened to include component or configuration unit name:\n" | |
1057 | "\taddr:<subimg_uname> - direct component image specification\n" | |
1058 | "\taddr#<conf_uname> - configuration specification\n" | |
1059 | "\tUse iminfo command to get the list of existing component\n" | |
1060 | "\timages and configurations.\n" | |
1061 | #endif | |
49c3a861 KG |
1062 | "\nSub-commands to do part of the bootm sequence. The sub-commands " |
1063 | "must be\n" | |
1064 | "issued in the order below (it's ok to not issue all sub-commands):\n" | |
1065 | "\tstart [addr [arg ...]]\n" | |
1066 | "\tloados - load OS image\n" | |
59af76d9 | 1067 | #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH) |
49c3a861 KG |
1068 | "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n" |
1069 | #endif | |
1070 | #if defined(CONFIG_OF_LIBFDT) | |
1071 | "\tfdt - relocate flat device tree\n" | |
1072 | #endif | |
49c3a861 | 1073 | "\tcmdline - OS specific command line processing/setup\n" |
224c90d1 | 1074 | "\tbdt - OS specific bd_t processing\n" |
49c3a861 | 1075 | "\tprep - OS specific prep before relocation or go\n" |
088f1b19 KP |
1076 | "\tgo - start OS"; |
1077 | #endif | |
1078 | ||
1079 | U_BOOT_CMD( | |
1080 | bootm, CONFIG_SYS_MAXARGS, 1, do_bootm, | |
1081 | "boot application image from memory", bootm_help_text | |
8bde7f77 | 1082 | ); |
47d1a6e1 | 1083 | |
1ee1180b MB |
1084 | /*******************************************************************/ |
1085 | /* bootd - boot default image */ | |
1086 | /*******************************************************************/ | |
baa26db4 | 1087 | #if defined(CONFIG_CMD_BOOTD) |
712fbcf3 | 1088 | int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
47d1a6e1 | 1089 | { |
73671dad | 1090 | return run_command(getenv("bootcmd"), flag); |
47d1a6e1 | 1091 | } |
47d1a6e1 | 1092 | |
0d498393 | 1093 | U_BOOT_CMD( |
1ee1180b | 1094 | boot, 1, 1, do_bootd, |
2fb2604d | 1095 | "boot default, i.e., run 'bootcmd'", |
a89c33db | 1096 | "" |
9d2b18a0 | 1097 | ); |
47d1a6e1 | 1098 | |
9d2b18a0 | 1099 | /* keep old command name "bootd" for backward compatibility */ |
0d498393 | 1100 | U_BOOT_CMD( |
1ee1180b | 1101 | bootd, 1, 1, do_bootd, |
2fb2604d | 1102 | "boot default, i.e., run 'bootcmd'", |
a89c33db | 1103 | "" |
8bde7f77 | 1104 | ); |
47d1a6e1 | 1105 | |
47d1a6e1 | 1106 | #endif |
47d1a6e1 | 1107 | |
47d1a6e1 | 1108 | |
1ee1180b MB |
1109 | /*******************************************************************/ |
1110 | /* iminfo - print header info for a requested image */ | |
1111 | /*******************************************************************/ | |
baa26db4 | 1112 | #if defined(CONFIG_CMD_IMI) |
088f1b19 | 1113 | static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
47d1a6e1 WD |
1114 | { |
1115 | int arg; | |
1116 | ulong addr; | |
1ee1180b | 1117 | int rcode = 0; |
47d1a6e1 | 1118 | |
47d1a6e1 | 1119 | if (argc < 2) { |
712fbcf3 | 1120 | return image_info(load_addr); |
47d1a6e1 | 1121 | } |
47d1a6e1 | 1122 | |
1ee1180b | 1123 | for (arg = 1; arg < argc; ++arg) { |
712fbcf3 SW |
1124 | addr = simple_strtoul(argv[arg], NULL, 16); |
1125 | if (image_info(addr) != 0) | |
1ee1180b | 1126 | rcode = 1; |
47d1a6e1 WD |
1127 | } |
1128 | return rcode; | |
1129 | } | |
47d1a6e1 | 1130 | |
712fbcf3 | 1131 | static int image_info(ulong addr) |
47d1a6e1 | 1132 | { |
d5934ad7 | 1133 | void *hdr = (void *)addr; |
47d1a6e1 | 1134 | |
712fbcf3 | 1135 | printf("\n## Checking Image at %08lx ...\n", addr); |
47d1a6e1 | 1136 | |
712fbcf3 | 1137 | switch (genimg_get_format(hdr)) { |
21d29f7f | 1138 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
d5934ad7 | 1139 | case IMAGE_FORMAT_LEGACY: |
712fbcf3 SW |
1140 | puts(" Legacy image found\n"); |
1141 | if (!image_check_magic(hdr)) { | |
1142 | puts(" Bad Magic Number\n"); | |
d5934ad7 MB |
1143 | return 1; |
1144 | } | |
47d1a6e1 | 1145 | |
712fbcf3 SW |
1146 | if (!image_check_hcrc(hdr)) { |
1147 | puts(" Bad Header Checksum\n"); | |
d5934ad7 | 1148 | return 1; |
47d1a6e1 WD |
1149 | } |
1150 | ||
712fbcf3 | 1151 | image_print_contents(hdr); |
47d1a6e1 | 1152 | |
712fbcf3 SW |
1153 | puts(" Verifying Checksum ... "); |
1154 | if (!image_check_dcrc(hdr)) { | |
1155 | puts(" Bad Data CRC\n"); | |
d5934ad7 | 1156 | return 1; |
47d1a6e1 | 1157 | } |
712fbcf3 | 1158 | puts("OK\n"); |
d5934ad7 | 1159 | return 0; |
21d29f7f | 1160 | #endif |
d5934ad7 MB |
1161 | #if defined(CONFIG_FIT) |
1162 | case IMAGE_FORMAT_FIT: | |
712fbcf3 | 1163 | puts(" FIT image found\n"); |
47d1a6e1 | 1164 | |
712fbcf3 SW |
1165 | if (!fit_check_format(hdr)) { |
1166 | puts("Bad FIT image format!\n"); | |
e32fea6a | 1167 | return 1; |
47d1a6e1 WD |
1168 | } |
1169 | ||
712fbcf3 | 1170 | fit_print_contents(hdr); |
a4f24345 | 1171 | |
b8da8366 | 1172 | if (!fit_all_image_verify(hdr)) { |
712fbcf3 | 1173 | puts("Bad hash in FIT image!\n"); |
a4f24345 BS |
1174 | return 1; |
1175 | } | |
1176 | ||
d5934ad7 MB |
1177 | return 0; |
1178 | #endif | |
1179 | default: | |
712fbcf3 | 1180 | puts("Unknown image format!\n"); |
d5934ad7 | 1181 | break; |
47d1a6e1 WD |
1182 | } |
1183 | ||
d5934ad7 | 1184 | return 1; |
47d1a6e1 | 1185 | } |
0d498393 WD |
1186 | |
1187 | U_BOOT_CMD( | |
6d0f6bcf | 1188 | iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo, |
2fb2604d | 1189 | "print header information for application image", |
8bde7f77 WD |
1190 | "addr [addr ...]\n" |
1191 | " - print header information for application image starting at\n" | |
1192 | " address 'addr' in memory; this includes verification of the\n" | |
a89c33db | 1193 | " image contents (magic number, header and payload checksums)" |
8bde7f77 | 1194 | ); |
25c751e9 | 1195 | #endif |
87a449c8 | 1196 | |
25c751e9 | 1197 | |
1ee1180b MB |
1198 | /*******************************************************************/ |
1199 | /* imls - list all images found in flash */ | |
1200 | /*******************************************************************/ | |
baa26db4 | 1201 | #if defined(CONFIG_CMD_IMLS) |
8fdf1e0f | 1202 | static int do_imls_nor(void) |
27b207fd WD |
1203 | { |
1204 | flash_info_t *info; | |
1205 | int i, j; | |
d5934ad7 | 1206 | void *hdr; |
25c751e9 | 1207 | |
1ee1180b | 1208 | for (i = 0, info = &flash_info[0]; |
6d0f6bcf | 1209 | i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) { |
25c751e9 | 1210 | |
27b207fd WD |
1211 | if (info->flash_id == FLASH_UNKNOWN) |
1212 | goto next_bank; | |
1ee1180b | 1213 | for (j = 0; j < info->sector_count; ++j) { |
25c751e9 | 1214 | |
d5934ad7 MB |
1215 | hdr = (void *)info->start[j]; |
1216 | if (!hdr) | |
b97a2a0a | 1217 | goto next_sector; |
27b207fd | 1218 | |
712fbcf3 | 1219 | switch (genimg_get_format(hdr)) { |
21d29f7f | 1220 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
d5934ad7 | 1221 | case IMAGE_FORMAT_LEGACY: |
712fbcf3 | 1222 | if (!image_check_hcrc(hdr)) |
d5934ad7 MB |
1223 | goto next_sector; |
1224 | ||
712fbcf3 SW |
1225 | printf("Legacy Image at %08lX:\n", (ulong)hdr); |
1226 | image_print_contents(hdr); | |
d5934ad7 | 1227 | |
712fbcf3 SW |
1228 | puts(" Verifying Checksum ... "); |
1229 | if (!image_check_dcrc(hdr)) { | |
1230 | puts("Bad Data CRC\n"); | |
d5934ad7 | 1231 | } else { |
712fbcf3 | 1232 | puts("OK\n"); |
d5934ad7 MB |
1233 | } |
1234 | break; | |
21d29f7f | 1235 | #endif |
d5934ad7 MB |
1236 | #if defined(CONFIG_FIT) |
1237 | case IMAGE_FORMAT_FIT: | |
712fbcf3 | 1238 | if (!fit_check_format(hdr)) |
e32fea6a MB |
1239 | goto next_sector; |
1240 | ||
712fbcf3 SW |
1241 | printf("FIT Image at %08lX:\n", (ulong)hdr); |
1242 | fit_print_contents(hdr); | |
d5934ad7 | 1243 | break; |
213bf8c8 | 1244 | #endif |
d5934ad7 | 1245 | default: |
27b207fd | 1246 | goto next_sector; |
25c751e9 | 1247 | } |
87a449c8 | 1248 | |
bdccc4fe | 1249 | next_sector: ; |
c76f951a | 1250 | } |
bdccc4fe | 1251 | next_bank: ; |
27b207fd | 1252 | } |
8fdf1e0f VK |
1253 | return 0; |
1254 | } | |
1255 | #endif | |
1256 | ||
1257 | #if defined(CONFIG_CMD_IMLS_NAND) | |
1258 | static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off, | |
1259 | size_t len) | |
1260 | { | |
1261 | void *imgdata; | |
1262 | int ret; | |
1263 | ||
1264 | imgdata = malloc(len); | |
1265 | if (!imgdata) { | |
1266 | printf("May be a Legacy Image at NAND device %d offset %08llX:\n", | |
1267 | nand_dev, off); | |
1268 | printf(" Low memory(cannot allocate memory for image)\n"); | |
1269 | return -ENOMEM; | |
1270 | } | |
1271 | ||
1272 | ret = nand_read_skip_bad(nand, off, &len, | |
1273 | imgdata); | |
1274 | if (ret < 0 && ret != -EUCLEAN) { | |
1275 | free(imgdata); | |
1276 | return ret; | |
1277 | } | |
1278 | ||
1279 | if (!image_check_hcrc(imgdata)) { | |
1280 | free(imgdata); | |
1281 | return 0; | |
1282 | } | |
1283 | ||
1284 | printf("Legacy Image at NAND device %d offset %08llX:\n", | |
1285 | nand_dev, off); | |
1286 | image_print_contents(imgdata); | |
1287 | ||
1288 | puts(" Verifying Checksum ... "); | |
1289 | if (!image_check_dcrc(imgdata)) | |
1290 | puts("Bad Data CRC\n"); | |
1291 | else | |
1292 | puts("OK\n"); | |
1293 | ||
1294 | free(imgdata); | |
1295 | ||
1296 | return 0; | |
1297 | } | |
1298 | ||
1299 | static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off, | |
1300 | size_t len) | |
1301 | { | |
1302 | void *imgdata; | |
1303 | int ret; | |
1304 | ||
1305 | imgdata = malloc(len); | |
1306 | if (!imgdata) { | |
1307 | printf("May be a FIT Image at NAND device %d offset %08llX:\n", | |
1308 | nand_dev, off); | |
1309 | printf(" Low memory(cannot allocate memory for image)\n"); | |
1310 | return -ENOMEM; | |
1311 | } | |
1312 | ||
1313 | ret = nand_read_skip_bad(nand, off, &len, | |
1314 | imgdata); | |
1315 | if (ret < 0 && ret != -EUCLEAN) { | |
1316 | free(imgdata); | |
1317 | return ret; | |
1318 | } | |
1319 | ||
1320 | if (!fit_check_format(imgdata)) { | |
1321 | free(imgdata); | |
1322 | return 0; | |
1323 | } | |
1324 | ||
1325 | printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off); | |
1326 | ||
1327 | fit_print_contents(imgdata); | |
1328 | free(imgdata); | |
1329 | ||
1330 | return 0; | |
1331 | } | |
1332 | ||
1333 | static int do_imls_nand(void) | |
1334 | { | |
1335 | nand_info_t *nand; | |
1336 | int nand_dev = nand_curr_device; | |
1337 | size_t len; | |
1338 | loff_t off; | |
1339 | u32 buffer[16]; | |
1340 | ||
1341 | if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) { | |
1342 | puts("\nNo NAND devices available\n"); | |
1343 | return -ENODEV; | |
1344 | } | |
1345 | ||
1346 | printf("\n"); | |
1347 | ||
1348 | for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) { | |
1349 | nand = &nand_info[nand_dev]; | |
1350 | if (!nand->name || !nand->size) | |
1351 | continue; | |
1352 | ||
1353 | for (off = 0; off < nand->size; off += nand->erasesize) { | |
1354 | const image_header_t *header; | |
1355 | int ret; | |
1356 | ||
1357 | if (nand_block_isbad(nand, off)) | |
1358 | continue; | |
1359 | ||
1360 | len = sizeof(buffer); | |
1361 | ||
1362 | ret = nand_read(nand, off, &len, (u8 *)buffer); | |
1363 | if (ret < 0 && ret != -EUCLEAN) { | |
1364 | printf("NAND read error %d at offset %08llX\n", | |
1365 | ret, off); | |
1366 | continue; | |
1367 | } | |
1368 | ||
1369 | switch (genimg_get_format(buffer)) { | |
21d29f7f | 1370 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
8fdf1e0f VK |
1371 | case IMAGE_FORMAT_LEGACY: |
1372 | header = (const image_header_t *)buffer; | |
1373 | ||
1374 | len = image_get_image_size(header); | |
1375 | nand_imls_legacyimage(nand, nand_dev, off, len); | |
1376 | break; | |
21d29f7f | 1377 | #endif |
8fdf1e0f VK |
1378 | #if defined(CONFIG_FIT) |
1379 | case IMAGE_FORMAT_FIT: | |
1380 | len = fit_get_size(buffer); | |
1381 | nand_imls_fitimage(nand, nand_dev, off, len); | |
1382 | break; | |
1383 | #endif | |
1384 | } | |
1385 | } | |
1386 | } | |
1387 | ||
1388 | return 0; | |
1389 | } | |
1390 | #endif | |
1391 | ||
1392 | #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) | |
1393 | static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
1394 | { | |
1395 | int ret_nor = 0, ret_nand = 0; | |
1396 | ||
1397 | #if defined(CONFIG_CMD_IMLS) | |
1398 | ret_nor = do_imls_nor(); | |
1399 | #endif | |
1400 | ||
1401 | #if defined(CONFIG_CMD_IMLS_NAND) | |
1402 | ret_nand = do_imls_nand(); | |
1403 | #endif | |
1404 | ||
1405 | if (ret_nor) | |
1406 | return ret_nor; | |
1407 | ||
1408 | if (ret_nand) | |
1409 | return ret_nand; | |
c76f951a | 1410 | |
27b207fd WD |
1411 | return (0); |
1412 | } | |
c76f951a | 1413 | |
27b207fd WD |
1414 | U_BOOT_CMD( |
1415 | imls, 1, 1, do_imls, | |
2fb2604d | 1416 | "list all images found in flash", |
27b207fd | 1417 | "\n" |
8fdf1e0f VK |
1418 | " - Prints information about all images found at sector/block\n" |
1419 | " boundaries in nor/nand flash." | |
27b207fd | 1420 | ); |
98a9c4d4 | 1421 | #endif |
47d1a6e1 | 1422 | |
1ee1180b | 1423 | /*******************************************************************/ |
5cf746c3 | 1424 | /* helper routines */ |
1ee1180b | 1425 | /*******************************************************************/ |
be2e5a09 | 1426 | #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY) |
a558ad71 DA |
1427 | |
1428 | #define CONSOLE_ARG "console=" | |
1429 | #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1) | |
1430 | ||
3a8653b3 | 1431 | static void fixup_silent_linux(void) |
1ee1180b | 1432 | { |
a558ad71 DA |
1433 | char *buf; |
1434 | const char *env_val; | |
3a8653b3 | 1435 | char *cmdline = getenv("bootargs"); |
8d51aacd | 1436 | int want_silent; |
47d1a6e1 | 1437 | |
8d51aacd SG |
1438 | /* |
1439 | * Only fix cmdline when requested. The environment variable can be: | |
1440 | * | |
1441 | * no - we never fixup | |
1442 | * yes - we always fixup | |
1443 | * unset - we rely on the console silent flag | |
1444 | */ | |
1445 | want_silent = getenv_yesno("silent_linux"); | |
1446 | if (want_silent == 0) | |
1447 | return; | |
1448 | else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT)) | |
1ee1180b | 1449 | return; |
47d1a6e1 | 1450 | |
3a8653b3 | 1451 | debug("before silent fix-up: %s\n", cmdline); |
a558ad71 DA |
1452 | if (cmdline && (cmdline[0] != '\0')) { |
1453 | char *start = strstr(cmdline, CONSOLE_ARG); | |
1454 | ||
1455 | /* Allocate space for maximum possible new command line */ | |
1456 | buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1); | |
1457 | if (!buf) { | |
1458 | debug("%s: out of memory\n", __func__); | |
1459 | return; | |
1460 | } | |
1461 | ||
3a8653b3 | 1462 | if (start) { |
a558ad71 DA |
1463 | char *end = strchr(start, ' '); |
1464 | int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN; | |
1465 | ||
1466 | strncpy(buf, cmdline, num_start_bytes); | |
1ee1180b | 1467 | if (end) |
a558ad71 | 1468 | strcpy(buf + num_start_bytes, end); |
1ee1180b | 1469 | else |
a558ad71 | 1470 | buf[num_start_bytes] = '\0'; |
1ee1180b | 1471 | } else { |
a558ad71 | 1472 | sprintf(buf, "%s %s", cmdline, CONSOLE_ARG); |
47d1a6e1 | 1473 | } |
a558ad71 | 1474 | env_val = buf; |
47d1a6e1 | 1475 | } else { |
a558ad71 DA |
1476 | buf = NULL; |
1477 | env_val = CONSOLE_ARG; | |
e7902122 | 1478 | } |
10aaf716 | 1479 | |
a558ad71 DA |
1480 | setenv("bootargs", env_val); |
1481 | debug("after silent fix-up: %s\n", env_val); | |
1482 | free(buf); | |
1ee1180b MB |
1483 | } |
1484 | #endif /* CONFIG_SILENT_CONSOLE */ | |
38eb508e | 1485 | |
eeaef5e4 SS |
1486 | #if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9) |
1487 | static void copy_args(char *dest, int argc, char * const argv[], char delim) | |
1488 | { | |
1489 | int i; | |
1490 | ||
1491 | for (i = 0; i < argc; i++) { | |
1492 | if (i > 0) | |
1493 | *dest++ = delim; | |
1494 | strcpy(dest, argv[i]); | |
1495 | dest += strlen(argv[i]); | |
1496 | } | |
1497 | } | |
1498 | #endif | |
38eb508e | 1499 | |
1ee1180b MB |
1500 | /*******************************************************************/ |
1501 | /* OS booting routines */ | |
1502 | /*******************************************************************/ | |
c76f951a | 1503 | |
b1d0db18 | 1504 | #ifdef CONFIG_BOOTM_NETBSD |
712fbcf3 | 1505 | static int do_bootm_netbsd(int flag, int argc, char * const argv[], |
8a5ea3e6 | 1506 | bootm_headers_t *images) |
d791b1dc | 1507 | { |
1ee1180b | 1508 | void (*loader)(bd_t *, image_header_t *, char *, char *); |
d5934ad7 | 1509 | image_header_t *os_hdr, *hdr; |
f13e7b2e | 1510 | ulong kernel_data, kernel_len; |
1ee1180b MB |
1511 | char *consdev; |
1512 | char *cmdline; | |
1513 | ||
5b629319 | 1514 | if (flag != BOOTM_STATE_OS_GO) |
7af26b16 | 1515 | return 0; |
49c3a861 | 1516 | |
d5934ad7 MB |
1517 | #if defined(CONFIG_FIT) |
1518 | if (!images->legacy_hdr_valid) { | |
712fbcf3 | 1519 | fit_unsupported_reset("NetBSD"); |
40d7e99d | 1520 | return 1; |
38eb508e GVB |
1521 | } |
1522 | #endif | |
d5934ad7 | 1523 | hdr = images->legacy_hdr_os; |
47d1a6e1 WD |
1524 | |
1525 | /* | |
1526 | * Booting a (NetBSD) kernel image | |
1527 | * | |
1528 | * This process is pretty similar to a standalone application: | |
1529 | * The (first part of an multi-) image must be a stage-2 loader, | |
1530 | * which in turn is responsible for loading & invoking the actual | |
1531 | * kernel. The only differences are the parameters being passed: | |
1532 | * besides the board info strucure, the loader expects a command | |
1533 | * line, the name of the console device, and (optionally) the | |
1534 | * address of the original image header. | |
1535 | */ | |
d5934ad7 | 1536 | os_hdr = NULL; |
712fbcf3 SW |
1537 | if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) { |
1538 | image_multi_getimg(hdr, 1, &kernel_data, &kernel_len); | |
f13e7b2e | 1539 | if (kernel_len) |
d5934ad7 | 1540 | os_hdr = hdr; |
f13e7b2e | 1541 | } |
47d1a6e1 WD |
1542 | |
1543 | consdev = ""; | |
712fbcf3 | 1544 | #if defined(CONFIG_8xx_CONS_SMC1) |
47d1a6e1 | 1545 | consdev = "smc1"; |
712fbcf3 | 1546 | #elif defined(CONFIG_8xx_CONS_SMC2) |
47d1a6e1 | 1547 | consdev = "smc2"; |
712fbcf3 | 1548 | #elif defined(CONFIG_8xx_CONS_SCC2) |
47d1a6e1 | 1549 | consdev = "scc2"; |
712fbcf3 | 1550 | #elif defined(CONFIG_8xx_CONS_SCC3) |
47d1a6e1 WD |
1551 | consdev = "scc3"; |
1552 | #endif | |
1553 | ||
983c72f4 | 1554 | if (argc > 0) { |
47d1a6e1 WD |
1555 | ulong len; |
1556 | int i; | |
1557 | ||
983c72f4 | 1558 | for (i = 0, len = 0; i < argc; i += 1) |
712fbcf3 SW |
1559 | len += strlen(argv[i]) + 1; |
1560 | cmdline = malloc(len); | |
eeaef5e4 | 1561 | copy_args(cmdline, argc, argv, ' '); |
712fbcf3 | 1562 | } else if ((cmdline = getenv("bootargs")) == NULL) { |
47d1a6e1 WD |
1563 | cmdline = ""; |
1564 | } | |
1565 | ||
c160a954 | 1566 | loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep; |
47d1a6e1 | 1567 | |
712fbcf3 SW |
1568 | printf("## Transferring control to NetBSD stage-2 loader " |
1569 | "(at address %08lx) ...\n", | |
47d1a6e1 WD |
1570 | (ulong)loader); |
1571 | ||
770605e4 | 1572 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
47d1a6e1 WD |
1573 | |
1574 | /* | |
1575 | * NetBSD Stage-2 Loader Parameters: | |
e2ce8169 KJ |
1576 | * arg[0]: pointer to board info data |
1577 | * arg[1]: image load address | |
1578 | * arg[2]: char pointer to the console device to use | |
1579 | * arg[3]: char pointer to the boot arguments | |
47d1a6e1 | 1580 | */ |
712fbcf3 | 1581 | (*loader)(gd->bd, os_hdr, consdev, cmdline); |
40d7e99d KG |
1582 | |
1583 | return 1; | |
47d1a6e1 | 1584 | } |
b1d0db18 | 1585 | #endif /* CONFIG_BOOTM_NETBSD*/ |
47d1a6e1 | 1586 | |
1ee1180b | 1587 | #ifdef CONFIG_LYNXKDI |
712fbcf3 | 1588 | static int do_bootm_lynxkdi(int flag, int argc, char * const argv[], |
8a5ea3e6 | 1589 | bootm_headers_t *images) |
1ee1180b | 1590 | { |
cb1c4896 | 1591 | image_header_t *hdr = &images->legacy_hdr_os_copy; |
d5934ad7 | 1592 | |
5b629319 | 1593 | if (flag != BOOTM_STATE_OS_GO) |
7af26b16 | 1594 | return 0; |
49c3a861 | 1595 | |
d5934ad7 MB |
1596 | #if defined(CONFIG_FIT) |
1597 | if (!images->legacy_hdr_valid) { | |
712fbcf3 | 1598 | fit_unsupported_reset("Lynx"); |
40d7e99d | 1599 | return 1; |
d5934ad7 MB |
1600 | } |
1601 | #endif | |
1602 | ||
712fbcf3 | 1603 | lynxkdi_boot((image_header_t *)hdr); |
40d7e99d KG |
1604 | |
1605 | return 1; | |
1ee1180b MB |
1606 | } |
1607 | #endif /* CONFIG_LYNXKDI */ | |
1608 | ||
b1d0db18 | 1609 | #ifdef CONFIG_BOOTM_RTEMS |
712fbcf3 | 1610 | static int do_bootm_rtems(int flag, int argc, char * const argv[], |
8a5ea3e6 | 1611 | bootm_headers_t *images) |
1ee1180b | 1612 | { |
1ee1180b | 1613 | void (*entry_point)(bd_t *); |
d791b1dc | 1614 | |
5b629319 | 1615 | if (flag != BOOTM_STATE_OS_GO) |
7af26b16 | 1616 | return 0; |
49c3a861 | 1617 | |
d5934ad7 MB |
1618 | #if defined(CONFIG_FIT) |
1619 | if (!images->legacy_hdr_valid) { | |
712fbcf3 | 1620 | fit_unsupported_reset("RTEMS"); |
40d7e99d | 1621 | return 1; |
d5934ad7 MB |
1622 | } |
1623 | #endif | |
1624 | ||
c160a954 | 1625 | entry_point = (void (*)(bd_t *))images->ep; |
d791b1dc | 1626 | |
712fbcf3 | 1627 | printf("## Transferring control to RTEMS (at address %08lx) ...\n", |
d791b1dc WD |
1628 | (ulong)entry_point); |
1629 | ||
770605e4 | 1630 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
d791b1dc WD |
1631 | |
1632 | /* | |
1633 | * RTEMS Parameters: | |
1634 | * r3: ptr to board info data | |
1635 | */ | |
1ee1180b | 1636 | (*entry_point)(gd->bd); |
40d7e99d KG |
1637 | |
1638 | return 1; | |
d791b1dc | 1639 | } |
b1d0db18 | 1640 | #endif /* CONFIG_BOOTM_RTEMS */ |
7f70e853 | 1641 | |
3df61957 | 1642 | #if defined(CONFIG_BOOTM_OSE) |
712fbcf3 | 1643 | static int do_bootm_ose(int flag, int argc, char * const argv[], |
3df61957 TL |
1644 | bootm_headers_t *images) |
1645 | { | |
1646 | void (*entry_point)(void); | |
1647 | ||
5b629319 | 1648 | if (flag != BOOTM_STATE_OS_GO) |
7af26b16 | 1649 | return 0; |
3df61957 TL |
1650 | |
1651 | #if defined(CONFIG_FIT) | |
1652 | if (!images->legacy_hdr_valid) { | |
712fbcf3 | 1653 | fit_unsupported_reset("OSE"); |
3df61957 TL |
1654 | return 1; |
1655 | } | |
1656 | #endif | |
1657 | ||
1658 | entry_point = (void (*)(void))images->ep; | |
1659 | ||
712fbcf3 | 1660 | printf("## Transferring control to OSE (at address %08lx) ...\n", |
3df61957 TL |
1661 | (ulong)entry_point); |
1662 | ||
770605e4 | 1663 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
3df61957 TL |
1664 | |
1665 | /* | |
1666 | * OSE Parameters: | |
1667 | * None | |
1668 | */ | |
1669 | (*entry_point)(); | |
1670 | ||
1671 | return 1; | |
1672 | } | |
1673 | #endif /* CONFIG_BOOTM_OSE */ | |
1674 | ||
04d41409 SS |
1675 | #if defined(CONFIG_BOOTM_PLAN9) |
1676 | static int do_bootm_plan9(int flag, int argc, char * const argv[], | |
1677 | bootm_headers_t *images) | |
1678 | { | |
1679 | void (*entry_point)(void); | |
eeaef5e4 | 1680 | char *s; |
04d41409 | 1681 | |
5b629319 | 1682 | if (flag != BOOTM_STATE_OS_GO) |
7af26b16 | 1683 | return 0; |
04d41409 SS |
1684 | |
1685 | #if defined(CONFIG_FIT) | |
1686 | if (!images->legacy_hdr_valid) { | |
1687 | fit_unsupported_reset("Plan 9"); | |
1688 | return 1; | |
1689 | } | |
1690 | #endif | |
1691 | ||
eeaef5e4 SS |
1692 | /* See README.plan9 */ |
1693 | s = getenv("confaddr"); | |
1694 | if (s != NULL) { | |
1695 | char *confaddr = (char *)simple_strtoul(s, NULL, 16); | |
1696 | ||
1697 | if (argc > 0) { | |
1698 | copy_args(confaddr, argc, argv, '\n'); | |
1699 | } else { | |
1700 | s = getenv("bootargs"); | |
1701 | if (s != NULL) | |
1702 | strcpy(confaddr, s); | |
1703 | } | |
1704 | } | |
1705 | ||
04d41409 SS |
1706 | entry_point = (void (*)(void))images->ep; |
1707 | ||
1708 | printf("## Transferring control to Plan 9 (at address %08lx) ...\n", | |
1709 | (ulong)entry_point); | |
1710 | ||
1711 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); | |
1712 | ||
1713 | /* | |
1714 | * Plan 9 Parameters: | |
1715 | * None | |
1716 | */ | |
1717 | (*entry_point)(); | |
1718 | ||
1719 | return 1; | |
1720 | } | |
1721 | #endif /* CONFIG_BOOTM_PLAN9 */ | |
1722 | ||
871a57bb MY |
1723 | #if defined(CONFIG_BOOTM_VXWORKS) && \ |
1724 | (defined(CONFIG_PPC) || defined(CONFIG_ARM)) | |
1725 | ||
1726 | void do_bootvx_fdt(bootm_headers_t *images) | |
1727 | { | |
1728 | #if defined(CONFIG_OF_LIBFDT) | |
1729 | int ret; | |
1730 | char *bootline; | |
1731 | ulong of_size = images->ft_len; | |
1732 | char **of_flat_tree = &images->ft_addr; | |
1733 | struct lmb *lmb = &images->lmb; | |
1734 | ||
1735 | if (*of_flat_tree) { | |
1736 | boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree); | |
1737 | ||
1738 | ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size); | |
1739 | if (ret) | |
1740 | return; | |
1741 | ||
1742 | ret = fdt_add_subnode(*of_flat_tree, 0, "chosen"); | |
1743 | if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) { | |
1744 | bootline = getenv("bootargs"); | |
1745 | if (bootline) { | |
1746 | ret = fdt_find_and_setprop(*of_flat_tree, | |
1747 | "/chosen", "bootargs", | |
1748 | bootline, | |
1749 | strlen(bootline) + 1, 1); | |
1750 | if (ret < 0) { | |
1751 | printf("## ERROR: %s : %s\n", __func__, | |
1752 | fdt_strerror(ret)); | |
1753 | return; | |
1754 | } | |
1755 | } | |
1756 | } else { | |
1757 | printf("## ERROR: %s : %s\n", __func__, | |
1758 | fdt_strerror(ret)); | |
1759 | return; | |
1760 | } | |
1761 | } | |
1762 | #endif | |
1763 | ||
1764 | boot_prep_vxworks(images); | |
1765 | ||
1766 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); | |
1767 | ||
1768 | #if defined(CONFIG_OF_LIBFDT) | |
1769 | printf("## Starting vxWorks at 0x%08lx, device tree at 0x%08lx ...\n", | |
1770 | (ulong)images->ep, (ulong)*of_flat_tree); | |
1771 | #else | |
1772 | printf("## Starting vxWorks at 0x%08lx\n", (ulong)images->ep); | |
1773 | #endif | |
1774 | ||
1775 | boot_jump_vxworks(images); | |
1776 | ||
1777 | puts("## vxWorks terminated\n"); | |
1778 | } | |
1779 | ||
712fbcf3 | 1780 | static int do_bootm_vxworks(int flag, int argc, char * const argv[], |
8a5ea3e6 | 1781 | bootm_headers_t *images) |
47d1a6e1 | 1782 | { |
5b629319 | 1783 | if (flag != BOOTM_STATE_OS_GO) |
7af26b16 | 1784 | return 0; |
49c3a861 | 1785 | |
d5934ad7 | 1786 | #if defined(CONFIG_FIT) |
cb1c4896 | 1787 | if (!images->legacy_hdr_valid) { |
712fbcf3 | 1788 | fit_unsupported_reset("VxWorks"); |
40d7e99d | 1789 | return 1; |
d5934ad7 MB |
1790 | } |
1791 | #endif | |
47d1a6e1 | 1792 | |
871a57bb | 1793 | do_bootvx_fdt(images); |
40d7e99d KG |
1794 | |
1795 | return 1; | |
47d1a6e1 | 1796 | } |
17ab52fe | 1797 | #endif |
47d1a6e1 | 1798 | |
17ab52fe | 1799 | #if defined(CONFIG_CMD_ELF) |
54841ab5 | 1800 | static int do_bootm_qnxelf(int flag, int argc, char * const argv[], |
8a5ea3e6 | 1801 | bootm_headers_t *images) |
47d1a6e1 | 1802 | { |
47d1a6e1 WD |
1803 | char *local_args[2]; |
1804 | char str[16]; | |
d5934ad7 | 1805 | |
5b629319 | 1806 | if (flag != BOOTM_STATE_OS_GO) |
7af26b16 | 1807 | return 0; |
49c3a861 | 1808 | |
d5934ad7 MB |
1809 | #if defined(CONFIG_FIT) |
1810 | if (!images->legacy_hdr_valid) { | |
712fbcf3 | 1811 | fit_unsupported_reset("QNX"); |
40d7e99d | 1812 | return 1; |
d5934ad7 MB |
1813 | } |
1814 | #endif | |
47d1a6e1 | 1815 | |
c160a954 | 1816 | sprintf(str, "%lx", images->ep); /* write entry-point into string */ |
47d1a6e1 WD |
1817 | local_args[0] = argv[0]; |
1818 | local_args[1] = str; /* and provide it via the arguments */ | |
40d7e99d KG |
1819 | do_bootelf(NULL, 0, 2, local_args); |
1820 | ||
1821 | return 1; | |
47d1a6e1 | 1822 | } |
90253178 | 1823 | #endif |
f5ed9e39 PT |
1824 | |
1825 | #ifdef CONFIG_INTEGRITY | |
712fbcf3 | 1826 | static int do_bootm_integrity(int flag, int argc, char * const argv[], |
f5ed9e39 PT |
1827 | bootm_headers_t *images) |
1828 | { | |
1829 | void (*entry_point)(void); | |
1830 | ||
5b629319 | 1831 | if (flag != BOOTM_STATE_OS_GO) |
7af26b16 | 1832 | return 0; |
49c3a861 | 1833 | |
f5ed9e39 PT |
1834 | #if defined(CONFIG_FIT) |
1835 | if (!images->legacy_hdr_valid) { | |
712fbcf3 | 1836 | fit_unsupported_reset("INTEGRITY"); |
f5ed9e39 PT |
1837 | return 1; |
1838 | } | |
1839 | #endif | |
1840 | ||
1841 | entry_point = (void (*)(void))images->ep; | |
1842 | ||
712fbcf3 | 1843 | printf("## Transferring control to INTEGRITY (at address %08lx) ...\n", |
f5ed9e39 PT |
1844 | (ulong)entry_point); |
1845 | ||
770605e4 | 1846 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
f5ed9e39 PT |
1847 | |
1848 | /* | |
1849 | * INTEGRITY Parameters: | |
1850 | * None | |
1851 | */ | |
1852 | (*entry_point)(); | |
1853 | ||
1854 | return 1; | |
1855 | } | |
1856 | #endif | |
44f074c7 MV |
1857 | |
1858 | #ifdef CONFIG_CMD_BOOTZ | |
1859 | ||
a5266d6b | 1860 | int __weak bootz_setup(ulong image, ulong *start, ulong *end) |
44f074c7 MV |
1861 | { |
1862 | /* Please define bootz_setup() for your platform */ | |
1863 | ||
1864 | puts("Your platform's zImage format isn't supported yet!\n"); | |
1865 | return -1; | |
1866 | } | |
44f074c7 MV |
1867 | |
1868 | /* | |
1869 | * zImage booting support | |
1870 | */ | |
1871 | static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc, | |
1872 | char * const argv[], bootm_headers_t *images) | |
1873 | { | |
1874 | int ret; | |
a5266d6b | 1875 | ulong zi_start, zi_end; |
44f074c7 | 1876 | |
35fc84fa SG |
1877 | ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, |
1878 | images, 1); | |
44f074c7 MV |
1879 | |
1880 | /* Setup Linux kernel zImage entry point */ | |
2b9599e0 | 1881 | if (!argc) { |
44f074c7 MV |
1882 | images->ep = load_addr; |
1883 | debug("* kernel: default image load address = 0x%08lx\n", | |
1884 | load_addr); | |
1885 | } else { | |
2b9599e0 | 1886 | images->ep = simple_strtoul(argv[0], NULL, 16); |
44f074c7 MV |
1887 | debug("* kernel: cmdline image address = 0x%08lx\n", |
1888 | images->ep); | |
1889 | } | |
1890 | ||
a5266d6b | 1891 | ret = bootz_setup(images->ep, &zi_start, &zi_end); |
44f074c7 MV |
1892 | if (ret != 0) |
1893 | return 1; | |
1894 | ||
1895 | lmb_reserve(&images->lmb, images->ep, zi_end - zi_start); | |
1896 | ||
225fd8c5 TR |
1897 | /* |
1898 | * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not | |
1899 | * have a header that provide this informaiton. | |
1900 | */ | |
2b9599e0 TR |
1901 | if (bootm_find_ramdisk(flag, argc, argv)) |
1902 | return 1; | |
44f074c7 | 1903 | |
2b9599e0 TR |
1904 | #if defined(CONFIG_OF_LIBFDT) |
1905 | if (bootm_find_fdt(flag, argc, argv)) | |
1906 | return 1; | |
1907 | #endif | |
1908 | ||
1909 | return 0; | |
44f074c7 MV |
1910 | } |
1911 | ||
da620222 | 1912 | int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
44f074c7 | 1913 | { |
35fc84fa | 1914 | int ret; |
44f074c7 | 1915 | |
2b9599e0 TR |
1916 | /* Consume 'bootz' */ |
1917 | argc--; argv++; | |
1918 | ||
44f074c7 MV |
1919 | if (bootz_start(cmdtp, flag, argc, argv, &images)) |
1920 | return 1; | |
1921 | ||
385501d3 SG |
1922 | /* |
1923 | * We are doing the BOOTM_STATE_LOADOS state ourselves, so must | |
1924 | * disable interrupts ourselves | |
1925 | */ | |
1926 | bootm_disable_interrupts(); | |
1927 | ||
fb1b139b | 1928 | images.os.os = IH_OS_LINUX; |
35fc84fa | 1929 | ret = do_bootm_states(cmdtp, flag, argc, argv, |
fb1b139b SG |
1930 | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | |
1931 | BOOTM_STATE_OS_GO, | |
d0ae31eb | 1932 | &images, 1); |
f8be7d65 | 1933 | |
35fc84fa | 1934 | return ret; |
44f074c7 MV |
1935 | } |
1936 | ||
088f1b19 KP |
1937 | #ifdef CONFIG_SYS_LONGHELP |
1938 | static char bootz_help_text[] = | |
017e1f3f MV |
1939 | "[addr [initrd[:size]] [fdt]]\n" |
1940 | " - boot Linux zImage stored in memory\n" | |
44f074c7 | 1941 | "\tThe argument 'initrd' is optional and specifies the address\n" |
017e1f3f MV |
1942 | "\tof the initrd in memory. The optional argument ':size' allows\n" |
1943 | "\tspecifying the size of RAW initrd.\n" | |
44f074c7 MV |
1944 | #if defined(CONFIG_OF_LIBFDT) |
1945 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" | |
1946 | "\ta third argument is required which is the address of the\n" | |
1947 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" | |
1948 | "\tuse a '-' for the second argument. If you do not pass a third\n" | |
1949 | "\ta bd_info struct will be passed instead\n" | |
1950 | #endif | |
088f1b19 KP |
1951 | ""; |
1952 | #endif | |
1953 | ||
1954 | U_BOOT_CMD( | |
1955 | bootz, CONFIG_SYS_MAXARGS, 1, do_bootz, | |
1956 | "boot Linux zImage image from memory", bootz_help_text | |
44f074c7 MV |
1957 | ); |
1958 | #endif /* CONFIG_CMD_BOOTZ */ |