]>
Commit | Line | Data |
---|---|---|
47d1a6e1 | 1 | /* |
15940c9a | 2 | * (C) Copyright 2000-2006 |
47d1a6e1 WD |
3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
4 | * | |
5 | * See file CREDITS for list of people who contributed to this | |
6 | * project. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public License as | |
10 | * published by the Free Software Foundation; either version 2 of | |
11 | * the License, or (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
21 | * MA 02111-1307 USA | |
22 | */ | |
23 | ||
b97a2a0a | 24 | |
47d1a6e1 WD |
25 | /* |
26 | * Boot support | |
27 | */ | |
28 | #include <common.h> | |
29 | #include <watchdog.h> | |
30 | #include <command.h> | |
47d1a6e1 WD |
31 | #include <image.h> |
32 | #include <malloc.h> | |
33 | #include <zlib.h> | |
c29fdfc1 | 34 | #include <bzlib.h> |
7f70e853 | 35 | #include <environment.h> |
4ed6552f | 36 | #include <lmb.h> |
47d1a6e1 | 37 | #include <asm/byteorder.h> |
8bde7f77 | 38 | |
47d1a6e1 WD |
39 | #ifdef CFG_HUSH_PARSER |
40 | #include <hush.h> | |
41 | #endif | |
42 | ||
1ee1180b | 43 | DECLARE_GLOBAL_DATA_PTR; |
228f29ac | 44 | |
1ee1180b MB |
45 | extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp); |
46 | #ifndef CFG_BOOTM_LEN | |
47 | #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */ | |
2abbe075 WD |
48 | #endif |
49 | ||
321359f2 MB |
50 | #ifdef CONFIG_BZIP2 |
51 | extern void bz_internal_error(int); | |
47d1a6e1 WD |
52 | #endif |
53 | ||
baa26db4 | 54 | #if defined(CONFIG_CMD_IMI) |
47d1a6e1 WD |
55 | static int image_info (unsigned long addr); |
56 | #endif | |
27b207fd | 57 | |
baa26db4 | 58 | #if defined(CONFIG_CMD_IMLS) |
27b207fd | 59 | #include <flash.h> |
e6f2e902 | 60 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
27b207fd WD |
61 | static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
62 | #endif | |
63 | ||
1ee1180b MB |
64 | #ifdef CONFIG_SILENT_CONSOLE |
65 | static void fixup_silent_linux (void); | |
66 | #endif | |
47d1a6e1 | 67 | |
6986a385 MB |
68 | static image_header_t *image_get_kernel (ulong img_addr, int verify); |
69 | #if defined(CONFIG_FIT) | |
70 | static int fit_check_kernel (const void *fit, int os_noffset, int verify); | |
2262cfee WD |
71 | #endif |
72 | ||
9a4daad0 | 73 | static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[], |
8a5ea3e6 | 74 | bootm_headers_t *images, ulong *os_data, ulong *os_len); |
1ee1180b | 75 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
47d1a6e1 WD |
76 | |
77 | /* | |
78 | * Continue booting an OS image; caller already has: | |
79 | * - copied image header to global variable `header' | |
80 | * - checked header magic number, checksums (both header & image), | |
81 | * - verified image architecture (PPC) and type (KERNEL or MULTI), | |
82 | * - loaded (first part of) image to header load address, | |
83 | * - disabled interrupts. | |
84 | */ | |
1ee1180b | 85 | typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag, |
f13e7b2e | 86 | int argc, char *argv[], |
8a5ea3e6 | 87 | bootm_headers_t *images); /* pointers to os/initrd/fdt */ |
1ee1180b MB |
88 | |
89 | extern boot_os_fn do_bootm_linux; | |
90 | static boot_os_fn do_bootm_netbsd; | |
f13e7b2e | 91 | #if defined(CONFIG_LYNXKDI) |
1ee1180b MB |
92 | static boot_os_fn do_bootm_lynxkdi; |
93 | extern void lynxkdi_boot (image_header_t *); | |
47d1a6e1 | 94 | #endif |
1ee1180b | 95 | static boot_os_fn do_bootm_rtems; |
baa26db4 | 96 | #if defined(CONFIG_CMD_ELF) |
1ee1180b MB |
97 | static boot_os_fn do_bootm_vxworks; |
98 | static boot_os_fn do_bootm_qnxelf; | |
99 | int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); | |
100 | int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); | |
90253178 | 101 | #endif |
7f70e853 | 102 | #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC) |
1ee1180b | 103 | static boot_os_fn do_bootm_artos; |
1f4bb37d | 104 | #endif |
47d1a6e1 | 105 | |
1ee1180b | 106 | ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */ |
d5934ad7 | 107 | static bootm_headers_t images; /* pointers to os/initrd/fdt images */ |
15940c9a | 108 | |
e822d7fc KG |
109 | void __board_lmb_reserve(struct lmb *lmb) |
110 | { | |
111 | /* please define platform specific board_lmb_reserve() */ | |
112 | } | |
113 | void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve"))); | |
47d1a6e1 | 114 | |
47d1a6e1 | 115 | |
1ee1180b MB |
116 | /*******************************************************************/ |
117 | /* bootm - boot application image from image in memory */ | |
118 | /*******************************************************************/ | |
47d1a6e1 WD |
119 | int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
120 | { | |
f13e7b2e | 121 | ulong iflag; |
42b73e8e | 122 | const char *type_name; |
f13e7b2e | 123 | uint unc_len = CFG_BOOTM_LEN; |
d5934ad7 | 124 | uint8_t comp, type, os; |
47d1a6e1 | 125 | |
d5934ad7 | 126 | void *os_hdr; |
f13e7b2e | 127 | ulong os_data, os_len; |
7582438c MB |
128 | ulong image_start, image_end; |
129 | ulong load_start, load_end; | |
d3f2fa0d | 130 | ulong mem_start, mem_size; |
47d1a6e1 | 131 | |
4ed6552f | 132 | struct lmb lmb; |
47d1a6e1 | 133 | |
d5934ad7 | 134 | memset ((void *)&images, 0, sizeof (images)); |
8a5ea3e6 | 135 | images.verify = getenv_verify(); |
f5614e79 | 136 | images.autostart = getenv_autostart(); |
4ed6552f | 137 | images.lmb = &lmb; |
47d1a6e1 | 138 | |
4ed6552f | 139 | lmb_init(&lmb); |
47d1a6e1 | 140 | |
d3f2fa0d KG |
141 | mem_start = getenv_bootm_low(); |
142 | mem_size = getenv_bootm_size(); | |
47d1a6e1 | 143 | |
d3f2fa0d | 144 | lmb_add(&lmb, mem_start, mem_size); |
47d1a6e1 | 145 | |
e822d7fc | 146 | board_lmb_reserve(&lmb); |
47d1a6e1 | 147 | |
5cf746c3 | 148 | /* get kernel image header, start address and length */ |
9a4daad0 | 149 | os_hdr = boot_get_kernel (cmdtp, flag, argc, argv, |
d5934ad7 | 150 | &images, &os_data, &os_len); |
6986a385 MB |
151 | if (os_len == 0) { |
152 | puts ("ERROR: can't get kernel image!\n"); | |
47d1a6e1 | 153 | return 1; |
bccae903 | 154 | } |
bccae903 | 155 | |
d5934ad7 | 156 | /* get image parameters */ |
9a4daad0 | 157 | switch (genimg_get_format (os_hdr)) { |
d5934ad7 MB |
158 | case IMAGE_FORMAT_LEGACY: |
159 | type = image_get_type (os_hdr); | |
160 | comp = image_get_comp (os_hdr); | |
161 | os = image_get_os (os_hdr); | |
bccae903 | 162 | |
d5934ad7 MB |
163 | image_end = image_get_image_end (os_hdr); |
164 | load_start = image_get_load (os_hdr); | |
165 | break; | |
166 | #if defined(CONFIG_FIT) | |
167 | case IMAGE_FORMAT_FIT: | |
3dfe1101 MB |
168 | if (fit_image_get_type (images.fit_hdr_os, |
169 | images.fit_noffset_os, &type)) { | |
6986a385 | 170 | puts ("Can't get image type!\n"); |
1372cce2 | 171 | show_boot_progress (-109); |
6986a385 MB |
172 | return 1; |
173 | } | |
47d1a6e1 | 174 | |
3dfe1101 MB |
175 | if (fit_image_get_comp (images.fit_hdr_os, |
176 | images.fit_noffset_os, &comp)) { | |
6986a385 | 177 | puts ("Can't get image compression!\n"); |
1372cce2 | 178 | show_boot_progress (-110); |
6986a385 MB |
179 | return 1; |
180 | } | |
47d1a6e1 | 181 | |
3dfe1101 MB |
182 | if (fit_image_get_os (images.fit_hdr_os, |
183 | images.fit_noffset_os, &os)) { | |
6986a385 | 184 | puts ("Can't get image OS!\n"); |
1372cce2 | 185 | show_boot_progress (-111); |
47d1a6e1 WD |
186 | return 1; |
187 | } | |
47d1a6e1 | 188 | |
6986a385 MB |
189 | image_end = fit_get_end (images.fit_hdr_os); |
190 | ||
3dfe1101 | 191 | if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os, |
6986a385 MB |
192 | &load_start)) { |
193 | puts ("Can't get image load address!\n"); | |
1372cce2 | 194 | show_boot_progress (-112); |
6986a385 | 195 | return 1; |
b13fb01a WD |
196 | } |
197 | break; | |
d5934ad7 MB |
198 | #endif |
199 | default: | |
200 | puts ("ERROR: unknown image format type!\n"); | |
47d1a6e1 WD |
201 | return 1; |
202 | } | |
d5934ad7 MB |
203 | |
204 | image_start = (ulong)os_hdr; | |
205 | load_end = 0; | |
9a4daad0 | 206 | type_name = genimg_get_type_name (type); |
47d1a6e1 WD |
207 | |
208 | /* | |
209 | * We have reached the point of no return: we are going to | |
210 | * overwrite all exception vector code, so we cannot easily | |
211 | * recover from any failures any more... | |
212 | */ | |
47d1a6e1 WD |
213 | iflag = disable_interrupts(); |
214 | ||
c7de829c WD |
215 | #ifdef CONFIG_AMIGAONEG3SE |
216 | /* | |
8bde7f77 | 217 | * We've possible left the caches enabled during |
c7de829c WD |
218 | * bios emulation, so turn them off again |
219 | */ | |
220 | icache_disable(); | |
221 | invalidate_l1_instruction_cache(); | |
222 | flush_data_cache(); | |
223 | dcache_disable(); | |
224 | #endif | |
225 | ||
d5934ad7 | 226 | switch (comp) { |
47d1a6e1 | 227 | case IH_COMP_NONE: |
d5934ad7 | 228 | if (load_start == (ulong)os_hdr) { |
42b73e8e | 229 | printf (" XIP %s ... ", type_name); |
47d1a6e1 | 230 | } else { |
42b73e8e | 231 | printf (" Loading %s ... ", type_name); |
47d1a6e1 | 232 | |
d5934ad7 | 233 | memmove_wd ((void *)load_start, |
f13e7b2e | 234 | (void *)os_data, os_len, CHUNKSZ); |
af13cdbc | 235 | |
7582438c | 236 | load_end = load_start + os_len; |
af13cdbc | 237 | puts("OK\n"); |
47d1a6e1 WD |
238 | } |
239 | break; | |
240 | case IH_COMP_GZIP: | |
42b73e8e | 241 | printf (" Uncompressing %s ... ", type_name); |
d5934ad7 | 242 | if (gunzip ((void *)load_start, unc_len, |
f13e7b2e | 243 | (uchar *)os_data, &os_len) != 0) { |
2682ce8a MB |
244 | puts ("GUNZIP: uncompress or overwrite error " |
245 | "- must RESET board to recover\n"); | |
fad63407 | 246 | show_boot_progress (-6); |
47d1a6e1 WD |
247 | do_reset (cmdtp, flag, argc, argv); |
248 | } | |
7582438c MB |
249 | |
250 | load_end = load_start + os_len; | |
47d1a6e1 | 251 | break; |
c29fdfc1 WD |
252 | #ifdef CONFIG_BZIP2 |
253 | case IH_COMP_BZIP2: | |
42b73e8e | 254 | printf (" Uncompressing %s ... ", type_name); |
5653fc33 WD |
255 | /* |
256 | * If we've got less than 4 MB of malloc() space, | |
257 | * use slower decompression algorithm which requires | |
258 | * at most 2300 KB of memory. | |
259 | */ | |
d5934ad7 | 260 | int i = BZ2_bzBuffToBuffDecompress ((char*)load_start, |
f13e7b2e MB |
261 | &unc_len, (char *)os_data, os_len, |
262 | CFG_MALLOC_LEN < (4096 * 1024), 0); | |
c29fdfc1 | 263 | if (i != BZ_OK) { |
2682ce8a MB |
264 | printf ("BUNZIP2: uncompress or overwrite error %d " |
265 | "- must RESET board to recover\n", i); | |
fad63407 | 266 | show_boot_progress (-6); |
c29fdfc1 WD |
267 | do_reset (cmdtp, flag, argc, argv); |
268 | } | |
7582438c MB |
269 | |
270 | load_end = load_start + unc_len; | |
c29fdfc1 WD |
271 | break; |
272 | #endif /* CONFIG_BZIP2 */ | |
47d1a6e1 WD |
273 | default: |
274 | if (iflag) | |
275 | enable_interrupts(); | |
d5934ad7 | 276 | printf ("Unimplemented compression type %d\n", comp); |
fad63407 | 277 | show_boot_progress (-7); |
47d1a6e1 WD |
278 | return 1; |
279 | } | |
4b9206ed | 280 | puts ("OK\n"); |
5cf746c3 | 281 | debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end); |
fad63407 | 282 | show_boot_progress (7); |
47d1a6e1 | 283 | |
7582438c MB |
284 | if ((load_start < image_end) && (load_end > image_start)) { |
285 | debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end); | |
286 | debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end); | |
47d1a6e1 | 287 | |
cb1c4896 MB |
288 | if (images.legacy_hdr_valid) { |
289 | if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI) | |
290 | puts ("WARNING: legacy format multi component " | |
291 | "image overwritten\n"); | |
292 | } else { | |
293 | puts ("ERROR: new format image overwritten - " | |
294 | "must RESET the board to recover\n"); | |
295 | show_boot_progress (-113); | |
296 | do_reset (cmdtp, flag, argc, argv); | |
297 | } | |
47d1a6e1 | 298 | } |
7582438c | 299 | |
fad63407 | 300 | show_boot_progress (8); |
47d1a6e1 | 301 | |
4ed6552f KG |
302 | lmb_reserve(&lmb, load_start, (load_end - load_start)); |
303 | ||
d5934ad7 | 304 | switch (os) { |
47d1a6e1 WD |
305 | default: /* handled by (original) Linux case */ |
306 | case IH_OS_LINUX: | |
f72da340 WD |
307 | #ifdef CONFIG_SILENT_CONSOLE |
308 | fixup_silent_linux(); | |
309 | #endif | |
8a5ea3e6 | 310 | do_bootm_linux (cmdtp, flag, argc, argv, &images); |
47d1a6e1 | 311 | break; |
1ee1180b | 312 | |
47d1a6e1 | 313 | case IH_OS_NETBSD: |
8a5ea3e6 | 314 | do_bootm_netbsd (cmdtp, flag, argc, argv, &images); |
47d1a6e1 | 315 | break; |
8bde7f77 | 316 | |
1f4bb37d WD |
317 | #ifdef CONFIG_LYNXKDI |
318 | case IH_OS_LYNXOS: | |
8a5ea3e6 | 319 | do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images); |
1f4bb37d WD |
320 | break; |
321 | #endif | |
322 | ||
d791b1dc | 323 | case IH_OS_RTEMS: |
8a5ea3e6 | 324 | do_bootm_rtems (cmdtp, flag, argc, argv, &images); |
d791b1dc | 325 | break; |
8bde7f77 | 326 | |
baa26db4 | 327 | #if defined(CONFIG_CMD_ELF) |
47d1a6e1 | 328 | case IH_OS_VXWORKS: |
8a5ea3e6 | 329 | do_bootm_vxworks (cmdtp, flag, argc, argv, &images); |
47d1a6e1 | 330 | break; |
f13e7b2e | 331 | |
47d1a6e1 | 332 | case IH_OS_QNX: |
8a5ea3e6 | 333 | do_bootm_qnxelf (cmdtp, flag, argc, argv, &images); |
47d1a6e1 | 334 | break; |
90253178 | 335 | #endif |
1ee1180b | 336 | |
7f70e853 WD |
337 | #ifdef CONFIG_ARTOS |
338 | case IH_OS_ARTOS: | |
8a5ea3e6 | 339 | do_bootm_artos (cmdtp, flag, argc, argv, &images); |
7f70e853 WD |
340 | break; |
341 | #endif | |
47d1a6e1 WD |
342 | } |
343 | ||
fad63407 | 344 | show_boot_progress (-9); |
47d1a6e1 | 345 | #ifdef DEBUG |
4b9206ed | 346 | puts ("\n## Control returned to monitor - resetting...\n"); |
a44a269a MB |
347 | if (images.autostart) |
348 | do_reset (cmdtp, flag, argc, argv); | |
47d1a6e1 | 349 | #endif |
a44a269a MB |
350 | if (!images.autostart && iflag) |
351 | enable_interrupts(); | |
352 | ||
47d1a6e1 WD |
353 | return 1; |
354 | } | |
355 | ||
1efd4360 | 356 | /** |
9a4daad0 MB |
357 | * image_get_kernel - verify legacy format kernel image |
358 | * @img_addr: in RAM address of the legacy format image to be verified | |
359 | * @verify: data CRC verification flag | |
1efd4360 | 360 | * |
9a4daad0 MB |
361 | * image_get_kernel() verifies legacy image integrity and returns pointer to |
362 | * legacy image header if image verification was completed successfully. | |
1efd4360 MB |
363 | * |
364 | * returns: | |
9a4daad0 MB |
365 | * pointer to a legacy image header if valid image was found |
366 | * otherwise return NULL | |
1efd4360 MB |
367 | */ |
368 | static image_header_t *image_get_kernel (ulong img_addr, int verify) | |
f72da340 | 369 | { |
1efd4360 | 370 | image_header_t *hdr = (image_header_t *)img_addr; |
f72da340 | 371 | |
1efd4360 MB |
372 | if (!image_check_magic(hdr)) { |
373 | puts ("Bad Magic Number\n"); | |
374 | show_boot_progress (-1); | |
375 | return NULL; | |
376 | } | |
377 | show_boot_progress (2); | |
f72da340 | 378 | |
1efd4360 MB |
379 | if (!image_check_hcrc (hdr)) { |
380 | puts ("Bad Header Checksum\n"); | |
381 | show_boot_progress (-2); | |
382 | return NULL; | |
383 | } | |
384 | ||
385 | show_boot_progress (3); | |
386 | image_print_contents (hdr); | |
387 | ||
388 | if (verify) { | |
389 | puts (" Verifying Checksum ... "); | |
390 | if (!image_check_dcrc (hdr)) { | |
391 | printf ("Bad Data CRC\n"); | |
392 | show_boot_progress (-3); | |
393 | return NULL; | |
f72da340 | 394 | } |
1efd4360 | 395 | puts ("OK\n"); |
f72da340 | 396 | } |
1efd4360 | 397 | show_boot_progress (4); |
f72da340 | 398 | |
1efd4360 MB |
399 | if (!image_check_target_arch (hdr)) { |
400 | printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr)); | |
401 | show_boot_progress (-4); | |
402 | return NULL; | |
403 | } | |
404 | return hdr; | |
f72da340 | 405 | } |
f72da340 | 406 | |
6986a385 MB |
407 | /** |
408 | * fit_check_kernel - verify FIT format kernel subimage | |
409 | * @fit_hdr: pointer to the FIT image header | |
410 | * os_noffset: kernel subimage node offset within FIT image | |
411 | * @verify: data CRC verification flag | |
412 | * | |
413 | * fit_check_kernel() verifies integrity of the kernel subimage and from | |
414 | * specified FIT image. | |
415 | * | |
416 | * returns: | |
417 | * 1, on success | |
418 | * 0, on failure | |
419 | */ | |
420 | #if defined (CONFIG_FIT) | |
421 | static int fit_check_kernel (const void *fit, int os_noffset, int verify) | |
47d1a6e1 | 422 | { |
6986a385 | 423 | fit_image_print (fit, os_noffset, " "); |
47d1a6e1 | 424 | |
6986a385 MB |
425 | if (verify) { |
426 | puts (" Verifying Hash Integrity ... "); | |
427 | if (!fit_image_check_hashes (fit, os_noffset)) { | |
428 | puts ("Bad Data Hash\n"); | |
1372cce2 | 429 | show_boot_progress (-104); |
6986a385 MB |
430 | return 0; |
431 | } | |
432 | puts ("OK\n"); | |
47d1a6e1 | 433 | } |
1372cce2 | 434 | show_boot_progress (105); |
47d1a6e1 | 435 | |
56f94be3 | 436 | #ifdef CONFIG_LOGBUFFER |
3d610186 | 437 | #ifndef CONFIG_ALT_LB_ADDR |
6aff3115 | 438 | kbd=gd->bd; |
228f29ac WD |
439 | /* Prevent initrd from overwriting logbuffer */ |
440 | if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD)) | |
441 | initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD; | |
442 | debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN); | |
3d610186 YT |
443 | #else |
444 | debug ("## Logbuffer at 0x%08lX ", CONFIG_ALT_LB_ADDR); | |
445 | #endif | |
56f94be3 | 446 | #endif |
6986a385 MB |
447 | if (!fit_image_check_target_arch (fit, os_noffset)) { |
448 | puts ("Unsupported Architecture\n"); | |
1372cce2 | 449 | show_boot_progress (-105); |
6986a385 MB |
450 | return 0; |
451 | } | |
56f94be3 | 452 | |
1372cce2 | 453 | show_boot_progress (106); |
6986a385 MB |
454 | if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) { |
455 | puts ("Not a kernel image\n"); | |
1372cce2 | 456 | show_boot_progress (-106); |
6986a385 MB |
457 | return 0; |
458 | } | |
47d1a6e1 | 459 | |
1372cce2 | 460 | show_boot_progress (107); |
6986a385 MB |
461 | return 1; |
462 | } | |
463 | #endif /* CONFIG_FIT */ | |
47d1a6e1 | 464 | |
5cf746c3 | 465 | /** |
9a4daad0 | 466 | * boot_get_kernel - find kernel image |
5cf746c3 MB |
467 | * @os_data: pointer to a ulong variable, will hold os data start address |
468 | * @os_len: pointer to a ulong variable, will hold os data length | |
469 | * | |
9a4daad0 | 470 | * boot_get_kernel() tries to find a kernel image, verifies its integrity |
5cf746c3 MB |
471 | * and locates kernel data. |
472 | * | |
473 | * returns: | |
474 | * pointer to image header if valid image was found, plus kernel start | |
475 | * address and length, otherwise NULL | |
476 | */ | |
9a4daad0 | 477 | static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
8a5ea3e6 | 478 | bootm_headers_t *images, ulong *os_data, ulong *os_len) |
5cf746c3 MB |
479 | { |
480 | image_header_t *hdr; | |
481 | ulong img_addr; | |
d5934ad7 MB |
482 | #if defined(CONFIG_FIT) |
483 | void *fit_hdr; | |
484 | const char *fit_uname_config = NULL; | |
485 | const char *fit_uname_kernel = NULL; | |
6986a385 MB |
486 | const void *data; |
487 | size_t len; | |
f773bea8 | 488 | int cfg_noffset; |
6986a385 | 489 | int os_noffset; |
d5934ad7 | 490 | #endif |
56f94be3 | 491 | |
d5934ad7 | 492 | /* find out kernel image address */ |
5cf746c3 MB |
493 | if (argc < 2) { |
494 | img_addr = load_addr; | |
d5934ad7 MB |
495 | debug ("* kernel: default image load address = 0x%08lx\n", |
496 | load_addr); | |
497 | #if defined(CONFIG_FIT) | |
498 | } else if (fit_parse_conf (argv[1], load_addr, &img_addr, | |
499 | &fit_uname_config)) { | |
500 | debug ("* kernel: config '%s' from image at 0x%08lx\n", | |
501 | fit_uname_config, img_addr); | |
502 | } else if (fit_parse_subimage (argv[1], load_addr, &img_addr, | |
503 | &fit_uname_kernel)) { | |
504 | debug ("* kernel: subimage '%s' from image at 0x%08lx\n", | |
505 | fit_uname_kernel, img_addr); | |
506 | #endif | |
5cf746c3 MB |
507 | } else { |
508 | img_addr = simple_strtoul(argv[1], NULL, 16); | |
d5934ad7 | 509 | debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr); |
5cf746c3 | 510 | } |
47d1a6e1 | 511 | |
5cf746c3 | 512 | show_boot_progress (1); |
56f94be3 | 513 | |
fff888a1 | 514 | /* copy from dataflash if needed */ |
9a4daad0 | 515 | img_addr = genimg_get_image (img_addr); |
5cf746c3 | 516 | |
d5934ad7 | 517 | /* check image type, for FIT images get FIT kernel node */ |
6986a385 | 518 | *os_data = *os_len = 0; |
9a4daad0 | 519 | switch (genimg_get_format ((void *)img_addr)) { |
d5934ad7 | 520 | case IMAGE_FORMAT_LEGACY: |
6986a385 MB |
521 | printf ("## Booting kernel from Legacy Image at %08lx ...\n", |
522 | img_addr); | |
1efd4360 MB |
523 | hdr = image_get_kernel (img_addr, images->verify); |
524 | if (!hdr) | |
d5934ad7 | 525 | return NULL; |
d5934ad7 MB |
526 | show_boot_progress (5); |
527 | ||
6986a385 | 528 | /* get os_data and os_len */ |
d5934ad7 MB |
529 | switch (image_get_type (hdr)) { |
530 | case IH_TYPE_KERNEL: | |
531 | *os_data = image_get_data (hdr); | |
532 | *os_len = image_get_data_size (hdr); | |
533 | break; | |
534 | case IH_TYPE_MULTI: | |
535 | image_multi_getimg (hdr, 0, os_data, os_len); | |
536 | break; | |
537 | default: | |
538 | printf ("Wrong Image Type for %s command\n", cmdtp->name); | |
539 | show_boot_progress (-5); | |
540 | return NULL; | |
541 | } | |
cb1c4896 MB |
542 | |
543 | /* | |
544 | * copy image header to allow for image overwrites during kernel | |
545 | * decompression. | |
546 | */ | |
547 | memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t)); | |
548 | ||
549 | /* save pointer to image header */ | |
d5934ad7 | 550 | images->legacy_hdr_os = hdr; |
47d1a6e1 | 551 | |
cb1c4896 | 552 | images->legacy_hdr_valid = 1; |
1372cce2 | 553 | show_boot_progress (6); |
5cf746c3 | 554 | break; |
d5934ad7 MB |
555 | #if defined(CONFIG_FIT) |
556 | case IMAGE_FORMAT_FIT: | |
557 | fit_hdr = (void *)img_addr; | |
6986a385 MB |
558 | printf ("## Booting kernel from FIT Image at %08lx ...\n", |
559 | img_addr); | |
560 | ||
561 | if (!fit_check_format (fit_hdr)) { | |
562 | puts ("Bad FIT kernel image format!\n"); | |
1372cce2 | 563 | show_boot_progress (-100); |
6986a385 MB |
564 | return NULL; |
565 | } | |
1372cce2 | 566 | show_boot_progress (100); |
47d1a6e1 | 567 | |
6986a385 MB |
568 | if (!fit_uname_kernel) { |
569 | /* | |
570 | * no kernel image node unit name, try to get config | |
571 | * node first. If config unit node name is NULL | |
572 | * fit_conf_get_node() will try to find default config node | |
573 | */ | |
1372cce2 | 574 | show_boot_progress (101); |
f773bea8 MB |
575 | cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config); |
576 | if (cfg_noffset < 0) { | |
1372cce2 | 577 | show_boot_progress (-101); |
6986a385 | 578 | return NULL; |
1372cce2 | 579 | } |
f773bea8 MB |
580 | /* save configuration uname provided in the first |
581 | * bootm argument | |
582 | */ | |
583 | images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL); | |
584 | printf (" Using '%s' configuration\n", images->fit_uname_cfg); | |
585 | show_boot_progress (103); | |
47d1a6e1 | 586 | |
f773bea8 | 587 | os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset); |
6986a385 MB |
588 | fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL); |
589 | } else { | |
590 | /* get kernel component image node offset */ | |
1372cce2 | 591 | show_boot_progress (102); |
6986a385 MB |
592 | os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel); |
593 | } | |
1372cce2 MB |
594 | if (os_noffset < 0) { |
595 | show_boot_progress (-103); | |
6986a385 | 596 | return NULL; |
1372cce2 | 597 | } |
47d1a6e1 | 598 | |
6986a385 | 599 | printf (" Trying '%s' kernel subimage\n", fit_uname_kernel); |
47d1a6e1 | 600 | |
1372cce2 | 601 | show_boot_progress (104); |
6986a385 MB |
602 | if (!fit_check_kernel (fit_hdr, os_noffset, images->verify)) |
603 | return NULL; | |
47d1a6e1 | 604 | |
6986a385 MB |
605 | /* get kernel image data address and length */ |
606 | if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) { | |
607 | puts ("Could not find kernel subimage data!\n"); | |
1372cce2 | 608 | show_boot_progress (-107); |
6986a385 MB |
609 | return NULL; |
610 | } | |
1372cce2 | 611 | show_boot_progress (108); |
47d1a6e1 | 612 | |
6986a385 MB |
613 | *os_len = len; |
614 | *os_data = (ulong)data; | |
615 | images->fit_hdr_os = fit_hdr; | |
616 | images->fit_uname_os = fit_uname_kernel; | |
3dfe1101 | 617 | images->fit_noffset_os = os_noffset; |
6986a385 | 618 | break; |
9c4c5ae3 | 619 | #endif |
5cf746c3 | 620 | default: |
d5934ad7 | 621 | printf ("Wrong Image Format for %s command\n", cmdtp->name); |
1372cce2 | 622 | show_boot_progress (-108); |
5cf746c3 | 623 | return NULL; |
47d1a6e1 WD |
624 | } |
625 | ||
6986a385 MB |
626 | debug (" kernel data at 0x%08lx, len = 0x%08lx (%d)\n", |
627 | *os_data, *os_len, *os_len); | |
47d1a6e1 | 628 | |
d5934ad7 | 629 | return (void *)img_addr; |
5cf746c3 | 630 | } |
98a9c4d4 | 631 | |
0d498393 | 632 | U_BOOT_CMD( |
1ee1180b MB |
633 | bootm, CFG_MAXARGS, 1, do_bootm, |
634 | "bootm - boot application image from memory\n", | |
635 | "[addr [arg ...]]\n - boot application image stored in memory\n" | |
636 | "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n" | |
637 | "\t'arg' can be the address of an initrd image\n" | |
4a2ad5ff | 638 | #if defined(CONFIG_OF_LIBFDT) |
98a9c4d4 | 639 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
5441f61a | 640 | "\ta third argument is required which is the address of the\n" |
98a9c4d4 MM |
641 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
642 | "\tuse a '-' for the second argument. If you do not pass a third\n" | |
643 | "\ta bd_info struct will be passed instead\n" | |
98a9c4d4 | 644 | #endif |
6986a385 MB |
645 | #if defined(CONFIG_FIT) |
646 | "\t\nFor the new multi component uImage format (FIT) addresses\n" | |
647 | "\tmust be extened to include component or configuration unit name:\n" | |
648 | "\taddr:<subimg_uname> - direct component image specification\n" | |
649 | "\taddr#<conf_uname> - configuration specification\n" | |
650 | "\tUse iminfo command to get the list of existing component\n" | |
651 | "\timages and configurations.\n" | |
652 | #endif | |
8bde7f77 | 653 | ); |
47d1a6e1 | 654 | |
1ee1180b MB |
655 | /*******************************************************************/ |
656 | /* bootd - boot default image */ | |
657 | /*******************************************************************/ | |
baa26db4 | 658 | #if defined(CONFIG_CMD_BOOTD) |
47d1a6e1 WD |
659 | int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
660 | { | |
661 | int rcode = 0; | |
47d1a6e1 | 662 | |
47d1a6e1 | 663 | #ifndef CFG_HUSH_PARSER |
1ee1180b MB |
664 | if (run_command (getenv ("bootcmd"), flag) < 0) |
665 | rcode = 1; | |
47d1a6e1 | 666 | #else |
1ee1180b MB |
667 | if (parse_string_outer (getenv ("bootcmd"), |
668 | FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0) | |
669 | rcode = 1; | |
47d1a6e1 WD |
670 | #endif |
671 | return rcode; | |
672 | } | |
47d1a6e1 | 673 | |
0d498393 | 674 | U_BOOT_CMD( |
1ee1180b MB |
675 | boot, 1, 1, do_bootd, |
676 | "boot - boot default, i.e., run 'bootcmd'\n", | |
9d2b18a0 WD |
677 | NULL |
678 | ); | |
47d1a6e1 | 679 | |
9d2b18a0 | 680 | /* keep old command name "bootd" for backward compatibility */ |
0d498393 | 681 | U_BOOT_CMD( |
1ee1180b MB |
682 | bootd, 1, 1, do_bootd, |
683 | "bootd - boot default, i.e., run 'bootcmd'\n", | |
8bde7f77 WD |
684 | NULL |
685 | ); | |
47d1a6e1 | 686 | |
47d1a6e1 | 687 | #endif |
47d1a6e1 | 688 | |
47d1a6e1 | 689 | |
1ee1180b MB |
690 | /*******************************************************************/ |
691 | /* iminfo - print header info for a requested image */ | |
692 | /*******************************************************************/ | |
baa26db4 | 693 | #if defined(CONFIG_CMD_IMI) |
1ee1180b | 694 | int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
47d1a6e1 WD |
695 | { |
696 | int arg; | |
697 | ulong addr; | |
1ee1180b | 698 | int rcode = 0; |
47d1a6e1 | 699 | |
47d1a6e1 WD |
700 | if (argc < 2) { |
701 | return image_info (load_addr); | |
702 | } | |
47d1a6e1 | 703 | |
1ee1180b MB |
704 | for (arg = 1; arg < argc; ++arg) { |
705 | addr = simple_strtoul (argv[arg], NULL, 16); | |
706 | if (image_info (addr) != 0) | |
707 | rcode = 1; | |
47d1a6e1 WD |
708 | } |
709 | return rcode; | |
710 | } | |
47d1a6e1 | 711 | |
47d1a6e1 WD |
712 | static int image_info (ulong addr) |
713 | { | |
d5934ad7 | 714 | void *hdr = (void *)addr; |
47d1a6e1 | 715 | |
47d1a6e1 | 716 | printf ("\n## Checking Image at %08lx ...\n", addr); |
47d1a6e1 | 717 | |
9a4daad0 | 718 | switch (genimg_get_format (hdr)) { |
d5934ad7 MB |
719 | case IMAGE_FORMAT_LEGACY: |
720 | puts (" Legacy image found\n"); | |
721 | if (!image_check_magic (hdr)) { | |
722 | puts (" Bad Magic Number\n"); | |
723 | return 1; | |
724 | } | |
47d1a6e1 | 725 | |
d5934ad7 MB |
726 | if (!image_check_hcrc (hdr)) { |
727 | puts (" Bad Header Checksum\n"); | |
728 | return 1; | |
47d1a6e1 WD |
729 | } |
730 | ||
d5934ad7 | 731 | image_print_contents (hdr); |
47d1a6e1 | 732 | |
d5934ad7 MB |
733 | puts (" Verifying Checksum ... "); |
734 | if (!image_check_dcrc (hdr)) { | |
735 | puts (" Bad Data CRC\n"); | |
736 | return 1; | |
47d1a6e1 | 737 | } |
d5934ad7 MB |
738 | puts ("OK\n"); |
739 | return 0; | |
740 | #if defined(CONFIG_FIT) | |
741 | case IMAGE_FORMAT_FIT: | |
742 | puts (" FIT image found\n"); | |
47d1a6e1 | 743 | |
e32fea6a MB |
744 | if (!fit_check_format (hdr)) { |
745 | puts ("Bad FIT image format!\n"); | |
746 | return 1; | |
47d1a6e1 WD |
747 | } |
748 | ||
e32fea6a | 749 | fit_print_contents (hdr); |
d5934ad7 MB |
750 | return 0; |
751 | #endif | |
752 | default: | |
753 | puts ("Unknown image format!\n"); | |
754 | break; | |
47d1a6e1 WD |
755 | } |
756 | ||
d5934ad7 | 757 | return 1; |
47d1a6e1 | 758 | } |
0d498393 WD |
759 | |
760 | U_BOOT_CMD( | |
761 | iminfo, CFG_MAXARGS, 1, do_iminfo, | |
8bde7f77 WD |
762 | "iminfo - print header information for application image\n", |
763 | "addr [addr ...]\n" | |
764 | " - print header information for application image starting at\n" | |
765 | " address 'addr' in memory; this includes verification of the\n" | |
766 | " image contents (magic number, header and payload checksums)\n" | |
767 | ); | |
25c751e9 | 768 | #endif |
87a449c8 | 769 | |
25c751e9 | 770 | |
1ee1180b MB |
771 | /*******************************************************************/ |
772 | /* imls - list all images found in flash */ | |
773 | /*******************************************************************/ | |
baa26db4 | 774 | #if defined(CONFIG_CMD_IMLS) |
27b207fd WD |
775 | int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
776 | { | |
777 | flash_info_t *info; | |
778 | int i, j; | |
d5934ad7 | 779 | void *hdr; |
25c751e9 | 780 | |
1ee1180b MB |
781 | for (i = 0, info = &flash_info[0]; |
782 | i < CFG_MAX_FLASH_BANKS; ++i, ++info) { | |
25c751e9 | 783 | |
27b207fd WD |
784 | if (info->flash_id == FLASH_UNKNOWN) |
785 | goto next_bank; | |
1ee1180b | 786 | for (j = 0; j < info->sector_count; ++j) { |
25c751e9 | 787 | |
d5934ad7 MB |
788 | hdr = (void *)info->start[j]; |
789 | if (!hdr) | |
b97a2a0a | 790 | goto next_sector; |
27b207fd | 791 | |
9a4daad0 | 792 | switch (genimg_get_format (hdr)) { |
d5934ad7 | 793 | case IMAGE_FORMAT_LEGACY: |
d5934ad7 MB |
794 | if (!image_check_hcrc (hdr)) |
795 | goto next_sector; | |
796 | ||
797 | printf ("Legacy Image at %08lX:\n", (ulong)hdr); | |
798 | image_print_contents (hdr); | |
799 | ||
800 | puts (" Verifying Checksum ... "); | |
801 | if (!image_check_dcrc (hdr)) { | |
802 | puts ("Bad Data CRC\n"); | |
803 | } else { | |
804 | puts ("OK\n"); | |
805 | } | |
806 | break; | |
807 | #if defined(CONFIG_FIT) | |
808 | case IMAGE_FORMAT_FIT: | |
e32fea6a MB |
809 | if (!fit_check_format (hdr)) |
810 | goto next_sector; | |
811 | ||
d5934ad7 | 812 | printf ("FIT Image at %08lX:\n", (ulong)hdr); |
e32fea6a | 813 | fit_print_contents (hdr); |
d5934ad7 | 814 | break; |
213bf8c8 | 815 | #endif |
d5934ad7 | 816 | default: |
27b207fd | 817 | goto next_sector; |
25c751e9 | 818 | } |
87a449c8 | 819 | |
bdccc4fe | 820 | next_sector: ; |
c76f951a | 821 | } |
bdccc4fe | 822 | next_bank: ; |
27b207fd | 823 | } |
c76f951a | 824 | |
27b207fd WD |
825 | return (0); |
826 | } | |
c76f951a | 827 | |
27b207fd WD |
828 | U_BOOT_CMD( |
829 | imls, 1, 1, do_imls, | |
830 | "imls - list all images found in flash\n", | |
831 | "\n" | |
832 | " - Prints information about all images found at sector\n" | |
833 | " boundaries in flash.\n" | |
834 | ); | |
98a9c4d4 | 835 | #endif |
47d1a6e1 | 836 | |
1ee1180b | 837 | /*******************************************************************/ |
5cf746c3 | 838 | /* helper routines */ |
1ee1180b | 839 | /*******************************************************************/ |
1ee1180b MB |
840 | #ifdef CONFIG_SILENT_CONSOLE |
841 | static void fixup_silent_linux () | |
842 | { | |
843 | char buf[256], *start, *end; | |
844 | char *cmdline = getenv ("bootargs"); | |
47d1a6e1 | 845 | |
1ee1180b MB |
846 | /* Only fix cmdline when requested */ |
847 | if (!(gd->flags & GD_FLG_SILENT)) | |
848 | return; | |
47d1a6e1 | 849 | |
1ee1180b MB |
850 | debug ("before silent fix-up: %s\n", cmdline); |
851 | if (cmdline) { | |
852 | if ((start = strstr (cmdline, "console=")) != NULL) { | |
853 | end = strchr (start, ' '); | |
854 | strncpy (buf, cmdline, (start - cmdline + 8)); | |
855 | if (end) | |
856 | strcpy (buf + (start - cmdline + 8), end); | |
857 | else | |
858 | buf[start - cmdline + 8] = '\0'; | |
859 | } else { | |
860 | strcpy (buf, cmdline); | |
861 | strcat (buf, " console="); | |
47d1a6e1 | 862 | } |
47d1a6e1 | 863 | } else { |
1ee1180b | 864 | strcpy (buf, "console="); |
e7902122 | 865 | } |
10aaf716 | 866 | |
1ee1180b MB |
867 | setenv ("bootargs", buf); |
868 | debug ("after silent fix-up: %s\n", buf); | |
869 | } | |
870 | #endif /* CONFIG_SILENT_CONSOLE */ | |
38eb508e | 871 | |
38eb508e | 872 | |
1ee1180b MB |
873 | /*******************************************************************/ |
874 | /* OS booting routines */ | |
875 | /*******************************************************************/ | |
c76f951a | 876 | |
1ee1180b | 877 | static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag, |
f13e7b2e | 878 | int argc, char *argv[], |
8a5ea3e6 | 879 | bootm_headers_t *images) |
d791b1dc | 880 | { |
1ee1180b | 881 | void (*loader)(bd_t *, image_header_t *, char *, char *); |
d5934ad7 | 882 | image_header_t *os_hdr, *hdr; |
f13e7b2e | 883 | ulong kernel_data, kernel_len; |
1ee1180b MB |
884 | char *consdev; |
885 | char *cmdline; | |
886 | ||
d5934ad7 MB |
887 | #if defined(CONFIG_FIT) |
888 | if (!images->legacy_hdr_valid) { | |
889 | fit_unsupported_reset ("NetBSD"); | |
890 | do_reset (cmdtp, flag, argc, argv); | |
38eb508e GVB |
891 | } |
892 | #endif | |
d5934ad7 | 893 | hdr = images->legacy_hdr_os; |
47d1a6e1 WD |
894 | |
895 | /* | |
896 | * Booting a (NetBSD) kernel image | |
897 | * | |
898 | * This process is pretty similar to a standalone application: | |
899 | * The (first part of an multi-) image must be a stage-2 loader, | |
900 | * which in turn is responsible for loading & invoking the actual | |
901 | * kernel. The only differences are the parameters being passed: | |
902 | * besides the board info strucure, the loader expects a command | |
903 | * line, the name of the console device, and (optionally) the | |
904 | * address of the original image header. | |
905 | */ | |
d5934ad7 | 906 | os_hdr = NULL; |
cb1c4896 | 907 | if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) { |
f13e7b2e MB |
908 | image_multi_getimg (hdr, 1, &kernel_data, &kernel_len); |
909 | if (kernel_len) | |
d5934ad7 | 910 | os_hdr = hdr; |
f13e7b2e | 911 | } |
47d1a6e1 WD |
912 | |
913 | consdev = ""; | |
914 | #if defined (CONFIG_8xx_CONS_SMC1) | |
915 | consdev = "smc1"; | |
916 | #elif defined (CONFIG_8xx_CONS_SMC2) | |
917 | consdev = "smc2"; | |
918 | #elif defined (CONFIG_8xx_CONS_SCC2) | |
919 | consdev = "scc2"; | |
920 | #elif defined (CONFIG_8xx_CONS_SCC3) | |
921 | consdev = "scc3"; | |
922 | #endif | |
923 | ||
924 | if (argc > 2) { | |
925 | ulong len; | |
926 | int i; | |
927 | ||
1ee1180b | 928 | for (i = 2, len = 0; i < argc; i += 1) |
47d1a6e1 WD |
929 | len += strlen (argv[i]) + 1; |
930 | cmdline = malloc (len); | |
931 | ||
1ee1180b | 932 | for (i = 2, len = 0; i < argc; i += 1) { |
47d1a6e1 WD |
933 | if (i > 2) |
934 | cmdline[len++] = ' '; | |
935 | strcpy (&cmdline[len], argv[i]); | |
936 | len += strlen (argv[i]); | |
937 | } | |
1ee1180b | 938 | } else if ((cmdline = getenv ("bootargs")) == NULL) { |
47d1a6e1 WD |
939 | cmdline = ""; |
940 | } | |
941 | ||
1ee1180b | 942 | loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr); |
47d1a6e1 WD |
943 | |
944 | printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n", | |
945 | (ulong)loader); | |
946 | ||
fad63407 | 947 | show_boot_progress (15); |
47d1a6e1 WD |
948 | |
949 | /* | |
950 | * NetBSD Stage-2 Loader Parameters: | |
951 | * r3: ptr to board info data | |
952 | * r4: image address | |
953 | * r5: console device | |
954 | * r6: boot args string | |
955 | */ | |
d5934ad7 | 956 | (*loader) (gd->bd, os_hdr, consdev, cmdline); |
47d1a6e1 WD |
957 | } |
958 | ||
1ee1180b MB |
959 | #ifdef CONFIG_LYNXKDI |
960 | static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag, | |
961 | int argc, char *argv[], | |
8a5ea3e6 | 962 | bootm_headers_t *images) |
1ee1180b | 963 | { |
cb1c4896 | 964 | image_header_t *hdr = &images->legacy_hdr_os_copy; |
d5934ad7 MB |
965 | |
966 | #if defined(CONFIG_FIT) | |
967 | if (!images->legacy_hdr_valid) { | |
968 | fit_unsupported_reset ("Lynx"); | |
969 | do_reset (cmdtp, flag, argc, argv); | |
970 | } | |
971 | #endif | |
972 | ||
973 | lynxkdi_boot ((image_header_t *)hdr); | |
1ee1180b MB |
974 | } |
975 | #endif /* CONFIG_LYNXKDI */ | |
976 | ||
977 | static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, | |
978 | int argc, char *argv[], | |
8a5ea3e6 | 979 | bootm_headers_t *images) |
1ee1180b | 980 | { |
cb1c4896 | 981 | image_header_t *hdr = &images->legacy_hdr_os_copy; |
1ee1180b | 982 | void (*entry_point)(bd_t *); |
d791b1dc | 983 | |
d5934ad7 MB |
984 | #if defined(CONFIG_FIT) |
985 | if (!images->legacy_hdr_valid) { | |
986 | fit_unsupported_reset ("RTEMS"); | |
987 | do_reset (cmdtp, flag, argc, argv); | |
988 | } | |
989 | #endif | |
990 | ||
b97a2a0a | 991 | entry_point = (void (*)(bd_t *))image_get_ep (hdr); |
d791b1dc WD |
992 | |
993 | printf ("## Transferring control to RTEMS (at address %08lx) ...\n", | |
994 | (ulong)entry_point); | |
995 | ||
fad63407 | 996 | show_boot_progress (15); |
d791b1dc WD |
997 | |
998 | /* | |
999 | * RTEMS Parameters: | |
1000 | * r3: ptr to board info data | |
1001 | */ | |
1ee1180b | 1002 | (*entry_point)(gd->bd); |
d791b1dc | 1003 | } |
7f70e853 | 1004 | |
baa26db4 | 1005 | #if defined(CONFIG_CMD_ELF) |
1ee1180b MB |
1006 | static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, |
1007 | int argc, char *argv[], | |
8a5ea3e6 | 1008 | bootm_headers_t *images) |
47d1a6e1 | 1009 | { |
47d1a6e1 | 1010 | char str[80]; |
cb1c4896 | 1011 | image_header_t *hdr = &images->legacy_hdr_os_copy; |
7f70e853 | 1012 | |
d5934ad7 | 1013 | #if defined(CONFIG_FIT) |
cb1c4896 | 1014 | if (!images->legacy_hdr_valid) { |
d5934ad7 MB |
1015 | fit_unsupported_reset ("VxWorks"); |
1016 | do_reset (cmdtp, flag, argc, argv); | |
1017 | } | |
1018 | #endif | |
47d1a6e1 | 1019 | |
b97a2a0a | 1020 | sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */ |
47d1a6e1 WD |
1021 | setenv("loadaddr", str); |
1022 | do_bootvx(cmdtp, 0, 0, NULL); | |
1023 | } | |
1024 | ||
f13e7b2e MB |
1025 | static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag, |
1026 | int argc, char *argv[], | |
8a5ea3e6 | 1027 | bootm_headers_t *images) |
47d1a6e1 | 1028 | { |
47d1a6e1 WD |
1029 | char *local_args[2]; |
1030 | char str[16]; | |
cb1c4896 | 1031 | image_header_t *hdr = &images->legacy_hdr_os_copy; |
d5934ad7 MB |
1032 | |
1033 | #if defined(CONFIG_FIT) | |
1034 | if (!images->legacy_hdr_valid) { | |
1035 | fit_unsupported_reset ("QNX"); | |
1036 | do_reset (cmdtp, flag, argc, argv); | |
1037 | } | |
1038 | #endif | |
47d1a6e1 | 1039 | |
b97a2a0a | 1040 | sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */ |
47d1a6e1 WD |
1041 | local_args[0] = argv[0]; |
1042 | local_args[1] = str; /* and provide it via the arguments */ | |
1043 | do_bootelf(cmdtp, 0, 2, local_args); | |
1044 | } | |
90253178 | 1045 | #endif |
1f4bb37d | 1046 | |
1ee1180b MB |
1047 | #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC) |
1048 | static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag, | |
1049 | int argc, char *argv[], | |
8a5ea3e6 | 1050 | bootm_headers_t *images) |
7f70e853 | 1051 | { |
7f70e853 WD |
1052 | ulong top; |
1053 | char *s, *cmdline; | |
1054 | char **fwenv, **ss; | |
1055 | int i, j, nxt, len, envno, envsz; | |
1056 | bd_t *kbd; | |
1057 | void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top); | |
cb1c4896 | 1058 | image_header_t *hdr = &images->legacy_hdr_os_copy; |
d5934ad7 MB |
1059 | |
1060 | #if defined(CONFIG_FIT) | |
1061 | if (!images->legacy_hdr_valid) { | |
1062 | fit_unsupported_reset ("ARTOS"); | |
1063 | do_reset (cmdtp, flag, argc, argv); | |
1064 | } | |
1065 | #endif | |
7f70e853 WD |
1066 | |
1067 | /* | |
1068 | * Booting an ARTOS kernel image + application | |
1069 | */ | |
1070 | ||
1071 | /* this used to be the top of memory, but was wrong... */ | |
1072 | #ifdef CONFIG_PPC | |
1073 | /* get stack pointer */ | |
1074 | asm volatile ("mr %0,1" : "=r"(top) ); | |
1075 | #endif | |
1076 | debug ("## Current stack ends at 0x%08lX ", top); | |
1077 | ||
1078 | top -= 2048; /* just to be sure */ | |
1079 | if (top > CFG_BOOTMAPSZ) | |
1080 | top = CFG_BOOTMAPSZ; | |
1081 | top &= ~0xF; | |
1082 | ||
1083 | debug ("=> set upper limit to 0x%08lX\n", top); | |
1084 | ||
1085 | /* first check the artos specific boot args, then the linux args*/ | |
1ee1180b | 1086 | if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL) |
7f70e853 WD |
1087 | s = ""; |
1088 | ||
1089 | /* get length of cmdline, and place it */ | |
1ee1180b | 1090 | len = strlen (s); |
7f70e853 WD |
1091 | top = (top - (len + 1)) & ~0xF; |
1092 | cmdline = (char *)top; | |
1093 | debug ("## cmdline at 0x%08lX ", top); | |
1ee1180b | 1094 | strcpy (cmdline, s); |
7f70e853 WD |
1095 | |
1096 | /* copy bdinfo */ | |
1ee1180b | 1097 | top = (top - sizeof (bd_t)) & ~0xF; |
7f70e853 WD |
1098 | debug ("## bd at 0x%08lX ", top); |
1099 | kbd = (bd_t *)top; | |
1ee1180b | 1100 | memcpy (kbd, gd->bd, sizeof (bd_t)); |
7f70e853 WD |
1101 | |
1102 | /* first find number of env entries, and their size */ | |
1103 | envno = 0; | |
1104 | envsz = 0; | |
1ee1180b MB |
1105 | for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) { |
1106 | for (nxt = i; env_get_char (nxt) != '\0'; ++nxt) | |
7f70e853 WD |
1107 | ; |
1108 | envno++; | |
1109 | envsz += (nxt - i) + 1; /* plus trailing zero */ | |
1110 | } | |
1111 | envno++; /* plus the terminating zero */ | |
1112 | debug ("## %u envvars total size %u ", envno, envsz); | |
1113 | ||
1ee1180b | 1114 | top = (top - sizeof (char **) * envno) & ~0xF; |
7f70e853 WD |
1115 | fwenv = (char **)top; |
1116 | debug ("## fwenv at 0x%08lX ", top); | |
1117 | ||
1118 | top = (top - envsz) & ~0xF; | |
1119 | s = (char *)top; | |
1120 | ss = fwenv; | |
1121 | ||
1122 | /* now copy them */ | |
1ee1180b MB |
1123 | for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) { |
1124 | for (nxt = i; env_get_char (nxt) != '\0'; ++nxt) | |
7f70e853 WD |
1125 | ; |
1126 | *ss++ = s; | |
1127 | for (j = i; j < nxt; ++j) | |
1ee1180b | 1128 | *s++ = env_get_char (j); |
7f70e853 WD |
1129 | *s++ = '\0'; |
1130 | } | |
1131 | *ss++ = NULL; /* terminate */ | |
1132 | ||
1ee1180b MB |
1133 | entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr); |
1134 | (*entry) (kbd, cmdline, fwenv, top); | |
47d1a6e1 | 1135 | } |
1f4bb37d | 1136 | #endif |