Modified patch originates from Andy Green <andy@openmoko.com>
[u-boot-openmoko/mini2440.git] / common / cmd_bootm.c
blob057075a4d10d9bd493daae25576ef5f4d02efdfa
1 /*
2 * (C) Copyright 2000-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
6 * project.
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.
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.
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
26 * Boot support
28 #include <common.h>
29 #include <watchdog.h>
30 #include <command.h>
31 #include <image.h>
32 #include <malloc.h>
33 #include <zlib.h>
34 #include <bzlib.h>
35 #include <environment.h>
36 #include <lmb.h>
37 #include <asm/byteorder.h>
39 #if defined(CONFIG_OF_LIBFDT)
40 #include <fdt.h>
41 #include <libfdt.h>
42 #include <fdt_support.h>
43 #endif
44 #if defined(CONFIG_OF_FLAT_TREE)
45 #include <ft_build.h>
46 #endif
48 void mmc_depower(void);
50 DECLARE_GLOBAL_DATA_PTR;
52 /*cmd_boot.c*/
53 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
55 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
56 #include <rtc.h>
57 #endif
59 #ifdef CFG_HUSH_PARSER
60 #include <hush.h>
61 #endif
63 extern void udc_disable (void);
65 DECLARE_GLOBAL_DATA_PTR;
67 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
68 #ifndef CFG_BOOTM_LEN
69 #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
70 #endif
72 #ifdef CONFIG_BZIP2
73 extern void bz_internal_error(int);
74 #endif
76 #if defined(CONFIG_CMD_IMI)
77 static int image_info (unsigned long addr);
78 #endif
80 #if defined(CONFIG_CMD_IMLS)
81 #include <flash.h>
82 extern flash_info_t flash_info[]; /* info for FLASH chips */
83 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
84 #endif
86 #ifdef CONFIG_SILENT_CONSOLE
87 static void fixup_silent_linux (void);
88 #endif
90 static image_header_t *image_get_kernel (ulong img_addr, int verify);
91 #if defined(CONFIG_FIT)
92 static int fit_check_kernel (const void *fit, int os_noffset, int verify);
93 #endif
95 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
96 bootm_headers_t *images, ulong *os_data, ulong *os_len);
97 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
100 * Continue booting an OS image; caller already has:
101 * - copied image header to global variable `header'
102 * - checked header magic number, checksums (both header & image),
103 * - verified image architecture (PPC) and type (KERNEL or MULTI),
104 * - loaded (first part of) image to header load address,
105 * - disabled interrupts.
107 typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
108 int argc, char *argv[],
109 bootm_headers_t *images); /* pointers to os/initrd/fdt */
111 extern boot_os_fn do_bootm_linux;
112 static boot_os_fn do_bootm_netbsd;
113 #if defined(CONFIG_LYNXKDI)
114 static boot_os_fn do_bootm_lynxkdi;
115 extern void lynxkdi_boot (image_header_t *);
116 #endif
117 static boot_os_fn do_bootm_rtems;
118 #if defined(CONFIG_CMD_ELF)
119 static boot_os_fn do_bootm_vxworks;
120 static boot_os_fn do_bootm_qnxelf;
121 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
122 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
123 #endif
124 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
125 extern uchar (*env_get_char)(int); /* Returns a character from the environment */
126 static boot_os_fn do_bootm_artos;
127 #endif
129 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
130 static bootm_headers_t images; /* pointers to os/initrd/fdt images */
132 void __board_lmb_reserve(struct lmb *lmb)
134 /* please define platform specific board_lmb_reserve() */
136 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
139 /*******************************************************************/
140 /* bootm - boot application image from image in memory */
141 /*******************************************************************/
142 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
144 ulong iflag;
145 const char *type_name;
146 uint unc_len = CFG_BOOTM_LEN;
147 uint8_t comp, type, os;
149 void *os_hdr;
150 ulong os_data, os_len;
151 ulong image_start, image_end;
152 ulong load_start, load_end;
153 ulong mem_start, mem_size;
155 struct lmb lmb;
157 memset ((void *)&images, 0, sizeof (images));
158 images.verify = getenv_verify();
159 images.autostart = getenv_autostart();
160 images.lmb = &lmb;
162 lmb_init(&lmb);
164 mem_start = getenv_bootm_low();
165 mem_size = getenv_bootm_size();
167 lmb_add(&lmb, mem_start, mem_size);
169 board_lmb_reserve(&lmb);
171 /* get kernel image header, start address and length */
172 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
173 &images, &os_data, &os_len);
174 if (os_len == 0) {
175 puts ("ERROR: can't get kernel image!\n");
176 return 1;
179 /* get image parameters */
180 switch (genimg_get_format (os_hdr)) {
181 case IMAGE_FORMAT_LEGACY:
182 type = image_get_type (os_hdr);
183 comp = image_get_comp (os_hdr);
184 os = image_get_os (os_hdr);
186 image_end = image_get_image_end (os_hdr);
187 load_start = image_get_load (os_hdr);
188 break;
189 #if defined(CONFIG_FIT)
190 case IMAGE_FORMAT_FIT:
191 if (fit_image_get_type (images.fit_hdr_os,
192 images.fit_noffset_os, &type)) {
193 puts ("Can't get image type!\n");
194 show_boot_progress (-109);
195 return 1;
198 if (fit_image_get_comp (images.fit_hdr_os,
199 images.fit_noffset_os, &comp)) {
200 puts ("Can't get image compression!\n");
201 show_boot_progress (-110);
202 return 1;
205 if (fit_image_get_os (images.fit_hdr_os,
206 images.fit_noffset_os, &os)) {
207 puts ("Can't get image OS!\n");
208 show_boot_progress (-111);
209 return 1;
212 image_end = fit_get_end (images.fit_hdr_os);
214 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
215 &load_start)) {
216 puts ("Can't get image load address!\n");
217 show_boot_progress (-112);
218 return 1;
220 break;
221 #endif
222 default:
223 puts ("ERROR: unknown image format type!\n");
224 return 1;
227 image_start = (ulong)os_hdr;
228 load_end = 0;
229 type_name = genimg_get_type_name (type);
231 #ifdef CONFIG_DEPOWER_MMC_ON_BOOT
232 mmc_depower();
233 #endif
235 #if (defined(CONFIG_S3C2410) || defined(CONFIG_S3C2440) || \
236 defined(CONFIG_S3C2442) || defined(CONFIG_S3C2443)) && defined(CONFIG_USB_DEVICE)
237 udc_disable();
238 #endif
241 * We have reached the point of no return: we are going to
242 * overwrite all exception vector code, so we cannot easily
243 * recover from any failures any more...
245 iflag = disable_interrupts();
247 #ifdef CONFIG_AMIGAONEG3SE
249 * We've possible left the caches enabled during
250 * bios emulation, so turn them off again
252 icache_disable();
253 invalidate_l1_instruction_cache();
254 flush_data_cache();
255 dcache_disable();
256 #endif
258 switch (comp) {
259 case IH_COMP_NONE:
260 if (load_start == (ulong)os_hdr) {
261 printf (" XIP %s ... ", type_name);
262 } else {
263 printf (" Loading %s ... ", type_name);
265 memmove_wd ((void *)load_start,
266 (void *)os_data, os_len, CHUNKSZ);
268 load_end = load_start + os_len;
269 puts("OK\n");
271 break;
272 case IH_COMP_GZIP:
273 printf (" Uncompressing %s ... ", type_name);
274 if (gunzip ((void *)load_start, unc_len,
275 (uchar *)os_data, &os_len) != 0) {
276 puts ("GUNZIP: uncompress or overwrite error "
277 "- must RESET board to recover\n");
278 show_boot_progress (-6);
279 do_reset (cmdtp, flag, argc, argv);
282 load_end = load_start + os_len;
283 break;
284 #ifdef CONFIG_BZIP2
285 case IH_COMP_BZIP2:
286 printf (" Uncompressing %s ... ", type_name);
288 * If we've got less than 4 MB of malloc() space,
289 * use slower decompression algorithm which requires
290 * at most 2300 KB of memory.
292 int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
293 &unc_len, (char *)os_data, os_len,
294 CFG_MALLOC_LEN < (4096 * 1024), 0);
295 if (i != BZ_OK) {
296 printf ("BUNZIP2: uncompress or overwrite error %d "
297 "- must RESET board to recover\n", i);
298 show_boot_progress (-6);
299 do_reset (cmdtp, flag, argc, argv);
302 load_end = load_start + unc_len;
303 break;
304 #endif /* CONFIG_BZIP2 */
305 default:
306 if (iflag)
307 enable_interrupts();
308 printf ("Unimplemented compression type %d\n", comp);
309 show_boot_progress (-7);
310 return 1;
312 puts ("OK\n");
313 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
314 show_boot_progress (7);
316 if ((load_start < image_end) && (load_end > image_start)) {
317 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
318 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
320 puts ("ERROR: image overwritten - must RESET the board to recover.\n");
321 show_boot_progress (-113);
322 do_reset (cmdtp, flag, argc, argv);
325 show_boot_progress (8);
327 lmb_reserve(&lmb, load_start, (load_end - load_start));
329 switch (os) {
330 default: /* handled by (original) Linux case */
331 case IH_OS_LINUX:
332 #ifdef CONFIG_SILENT_CONSOLE
333 fixup_silent_linux();
334 #endif
335 do_bootm_linux (cmdtp, flag, argc, argv, &images);
336 break;
338 case IH_OS_NETBSD:
339 do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
340 break;
342 #ifdef CONFIG_LYNXKDI
343 case IH_OS_LYNXOS:
344 do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
345 break;
346 #endif
348 case IH_OS_RTEMS:
349 do_bootm_rtems (cmdtp, flag, argc, argv, &images);
350 break;
352 #if defined(CONFIG_CMD_ELF)
353 case IH_OS_VXWORKS:
354 do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
355 break;
357 case IH_OS_QNX:
358 do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
359 break;
360 #endif
362 #ifdef CONFIG_ARTOS
363 case IH_OS_ARTOS:
364 do_bootm_artos (cmdtp, flag, argc, argv, &images);
365 break;
366 #endif
369 show_boot_progress (-9);
370 #ifdef DEBUG
371 puts ("\n## Control returned to monitor - resetting...\n");
372 if (images.autostart)
373 do_reset (cmdtp, flag, argc, argv);
374 #endif
375 if (!images.autostart && iflag)
376 enable_interrupts();
378 return 1;
382 * image_get_kernel - verify legacy format kernel image
383 * @img_addr: in RAM address of the legacy format image to be verified
384 * @verify: data CRC verification flag
386 * image_get_kernel() verifies legacy image integrity and returns pointer to
387 * legacy image header if image verification was completed successfully.
389 * returns:
390 * pointer to a legacy image header if valid image was found
391 * otherwise return NULL
393 static image_header_t *image_get_kernel (ulong img_addr, int verify)
395 image_header_t *hdr = (image_header_t *)img_addr;
397 if (!image_check_magic(hdr)) {
398 puts ("Bad Magic Number\n");
399 show_boot_progress (-1);
400 return NULL;
402 show_boot_progress (2);
404 if (!image_check_hcrc (hdr)) {
405 puts ("Bad Header Checksum\n");
406 show_boot_progress (-2);
407 return NULL;
410 show_boot_progress (3);
411 image_print_contents (hdr);
413 if (verify) {
414 puts (" Verifying Checksum ... ");
415 if (!image_check_dcrc (hdr)) {
416 printf ("Bad Data CRC\n");
417 show_boot_progress (-3);
418 return NULL;
420 puts ("OK\n");
422 show_boot_progress (4);
424 if (!image_check_target_arch (hdr)) {
425 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
426 show_boot_progress (-4);
427 return NULL;
429 return hdr;
433 * fit_check_kernel - verify FIT format kernel subimage
434 * @fit_hdr: pointer to the FIT image header
435 * os_noffset: kernel subimage node offset within FIT image
436 * @verify: data CRC verification flag
438 * fit_check_kernel() verifies integrity of the kernel subimage and from
439 * specified FIT image.
441 * returns:
442 * 1, on success
443 * 0, on failure
445 #if defined (CONFIG_FIT)
446 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
448 fit_image_print (fit, os_noffset, " ");
450 if (verify) {
451 puts (" Verifying Hash Integrity ... ");
452 if (!fit_image_check_hashes (fit, os_noffset)) {
453 puts ("Bad Data Hash\n");
454 show_boot_progress (-104);
455 return 0;
457 puts ("OK\n");
459 show_boot_progress (105);
461 #ifdef CONFIG_LOGBUFFER
462 #ifndef CONFIG_ALT_LB_ADDR
463 kbd=gd->bd;
464 /* Prevent initrd from overwriting logbuffer */
465 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
466 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
467 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
468 #else
469 debug ("## Logbuffer at 0x%08lX ", CONFIG_ALT_LB_ADDR);
470 #endif
471 #endif
472 if (!fit_image_check_target_arch (fit, os_noffset)) {
473 puts ("Unsupported Architecture\n");
474 show_boot_progress (-105);
475 return 0;
478 show_boot_progress (106);
479 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
480 puts ("Not a kernel image\n");
481 show_boot_progress (-106);
482 return 0;
485 show_boot_progress (107);
486 return 1;
488 #endif /* CONFIG_FIT */
491 * boot_get_kernel - find kernel image
492 * @os_data: pointer to a ulong variable, will hold os data start address
493 * @os_len: pointer to a ulong variable, will hold os data length
495 * boot_get_kernel() tries to find a kernel image, verifies its integrity
496 * and locates kernel data.
498 * returns:
499 * pointer to image header if valid image was found, plus kernel start
500 * address and length, otherwise NULL
502 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
503 bootm_headers_t *images, ulong *os_data, ulong *os_len)
505 image_header_t *hdr;
506 ulong img_addr;
507 #if defined(CONFIG_FIT)
508 void *fit_hdr;
509 const char *fit_uname_config = NULL;
510 const char *fit_uname_kernel = NULL;
511 const void *data;
512 size_t len;
513 int cfg_noffset;
514 int os_noffset;
515 #endif
517 /* find out kernel image address */
518 if (argc < 2) {
519 img_addr = load_addr;
520 debug ("* kernel: default image load address = 0x%08lx\n",
521 load_addr);
522 #if defined(CONFIG_FIT)
523 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
524 &fit_uname_config)) {
525 debug ("* kernel: config '%s' from image at 0x%08lx\n",
526 fit_uname_config, img_addr);
527 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
528 &fit_uname_kernel)) {
529 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
530 fit_uname_kernel, img_addr);
531 #endif
532 } else {
533 img_addr = simple_strtoul(argv[1], NULL, 16);
534 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
537 show_boot_progress (1);
539 /* copy from dataflash if needed */
540 img_addr = genimg_get_image (img_addr);
542 /* check image type, for FIT images get FIT kernel node */
543 *os_data = *os_len = 0;
544 switch (genimg_get_format ((void *)img_addr)) {
545 case IMAGE_FORMAT_LEGACY:
546 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
547 img_addr);
548 hdr = image_get_kernel (img_addr, images->verify);
549 if (!hdr)
550 return NULL;
551 show_boot_progress (5);
553 /* get os_data and os_len */
554 switch (image_get_type (hdr)) {
555 case IH_TYPE_KERNEL:
556 *os_data = image_get_data (hdr);
557 *os_len = image_get_data_size (hdr);
558 break;
559 case IH_TYPE_MULTI:
560 image_multi_getimg (hdr, 0, os_data, os_len);
561 break;
562 default:
563 printf ("Wrong Image Type for %s command\n", cmdtp->name);
564 show_boot_progress (-5);
565 return NULL;
567 images->legacy_hdr_os = hdr;
568 images->legacy_hdr_valid = 1;
570 show_boot_progress (6);
571 break;
572 #if defined(CONFIG_FIT)
573 case IMAGE_FORMAT_FIT:
574 fit_hdr = (void *)img_addr;
575 printf ("## Booting kernel from FIT Image at %08lx ...\n",
576 img_addr);
578 if (!fit_check_format (fit_hdr)) {
579 puts ("Bad FIT kernel image format!\n");
580 show_boot_progress (-100);
581 return NULL;
583 show_boot_progress (100);
585 if (!fit_uname_kernel) {
587 * no kernel image node unit name, try to get config
588 * node first. If config unit node name is NULL
589 * fit_conf_get_node() will try to find default config node
591 show_boot_progress (101);
592 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
593 if (cfg_noffset < 0) {
594 show_boot_progress (-101);
595 return NULL;
597 /* save configuration uname provided in the first
598 * bootm argument
600 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
601 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
602 show_boot_progress (103);
604 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
605 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
606 } else {
607 /* get kernel component image node offset */
608 show_boot_progress (102);
609 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
611 if (os_noffset < 0) {
612 show_boot_progress (-103);
613 return NULL;
616 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
618 show_boot_progress (104);
619 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
620 return NULL;
622 /* get kernel image data address and length */
623 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
624 puts ("Could not find kernel subimage data!\n");
625 show_boot_progress (-107);
626 return NULL;
628 show_boot_progress (108);
630 *os_len = len;
631 *os_data = (ulong)data;
632 images->fit_hdr_os = fit_hdr;
633 images->fit_uname_os = fit_uname_kernel;
634 images->fit_noffset_os = os_noffset;
635 break;
636 #endif
637 default:
638 printf ("Wrong Image Format for %s command\n", cmdtp->name);
639 show_boot_progress (-108);
640 return NULL;
643 debug (" kernel data at 0x%08lx, len = 0x%08lx (%d)\n",
644 *os_data, *os_len, *os_len);
646 return (void *)img_addr;
649 U_BOOT_CMD(
650 bootm, CFG_MAXARGS, 1, do_bootm,
651 "bootm - boot application image from memory\n",
652 "[addr [arg ...]]\n - boot application image stored in memory\n"
653 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
654 "\t'arg' can be the address of an initrd image\n"
655 #if defined(CONFIG_OF_LIBFDT)
656 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
657 "\ta third argument is required which is the address of the\n"
658 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
659 "\tuse a '-' for the second argument. If you do not pass a third\n"
660 "\ta bd_info struct will be passed instead\n"
661 #endif
662 #if defined(CONFIG_FIT)
663 "\t\nFor the new multi component uImage format (FIT) addresses\n"
664 "\tmust be extened to include component or configuration unit name:\n"
665 "\taddr:<subimg_uname> - direct component image specification\n"
666 "\taddr#<conf_uname> - configuration specification\n"
667 "\tUse iminfo command to get the list of existing component\n"
668 "\timages and configurations.\n"
669 #endif
672 /*******************************************************************/
673 /* bootd - boot default image */
674 /*******************************************************************/
675 #if defined(CONFIG_CMD_BOOTD)
676 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
678 int rcode = 0;
680 #ifndef CFG_HUSH_PARSER
681 if (run_command (getenv ("bootcmd"), flag) < 0)
682 rcode = 1;
683 #else
684 if (parse_string_outer (getenv ("bootcmd"),
685 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
686 rcode = 1;
687 #endif
688 return rcode;
691 U_BOOT_CMD(
692 boot, 1, 1, do_bootd,
693 "boot - boot default, i.e., run 'bootcmd'\n",
694 NULL
697 /* keep old command name "bootd" for backward compatibility */
698 U_BOOT_CMD(
699 bootd, 1, 1, do_bootd,
700 "bootd - boot default, i.e., run 'bootcmd'\n",
701 NULL
704 #endif
707 /*******************************************************************/
708 /* iminfo - print header info for a requested image */
709 /*******************************************************************/
710 #if defined(CONFIG_CMD_IMI)
711 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
713 int arg;
714 ulong addr;
715 int rcode = 0;
717 if (argc < 2) {
718 return image_info (load_addr);
721 for (arg = 1; arg < argc; ++arg) {
722 addr = simple_strtoul (argv[arg], NULL, 16);
723 if (image_info (addr) != 0)
724 rcode = 1;
726 return rcode;
729 static int image_info (ulong addr)
731 void *hdr = (void *)addr;
733 printf ("\n## Checking Image at %08lx ...\n", addr);
735 switch (genimg_get_format (hdr)) {
736 case IMAGE_FORMAT_LEGACY:
737 puts (" Legacy image found\n");
738 if (!image_check_magic (hdr)) {
739 puts (" Bad Magic Number\n");
740 return 1;
743 if (!image_check_hcrc (hdr)) {
744 puts (" Bad Header Checksum\n");
745 return 1;
748 image_print_contents (hdr);
750 puts (" Verifying Checksum ... ");
751 if (!image_check_dcrc (hdr)) {
752 puts (" Bad Data CRC\n");
753 return 1;
755 puts ("OK\n");
756 return 0;
757 #if defined(CONFIG_FIT)
758 case IMAGE_FORMAT_FIT:
759 puts (" FIT image found\n");
761 if (!fit_check_format (hdr)) {
762 puts ("Bad FIT image format!\n");
763 return 1;
766 fit_print_contents (hdr);
767 return 0;
768 #endif
769 default:
770 puts ("Unknown image format!\n");
771 break;
774 return 1;
777 U_BOOT_CMD(
778 iminfo, CFG_MAXARGS, 1, do_iminfo,
779 "iminfo - print header information for application image\n",
780 "addr [addr ...]\n"
781 " - print header information for application image starting at\n"
782 " address 'addr' in memory; this includes verification of the\n"
783 " image contents (magic number, header and payload checksums)\n"
785 #endif
788 /*******************************************************************/
789 /* imls - list all images found in flash */
790 /*******************************************************************/
791 #if defined(CONFIG_CMD_IMLS)
792 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
794 flash_info_t *info;
795 int i, j;
796 void *hdr;
798 for (i = 0, info = &flash_info[0];
799 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
801 if (info->flash_id == FLASH_UNKNOWN)
802 goto next_bank;
803 for (j = 0; j < info->sector_count; ++j) {
805 hdr = (void *)info->start[j];
806 if (!hdr)
807 goto next_sector;
809 switch (genimg_get_format (hdr)) {
810 case IMAGE_FORMAT_LEGACY:
811 if (!image_check_hcrc (hdr))
812 goto next_sector;
814 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
815 image_print_contents (hdr);
817 puts (" Verifying Checksum ... ");
818 if (!image_check_dcrc (hdr)) {
819 puts ("Bad Data CRC\n");
820 } else {
821 puts ("OK\n");
823 break;
824 #if defined(CONFIG_FIT)
825 case IMAGE_FORMAT_FIT:
826 if (!fit_check_format (hdr))
827 goto next_sector;
829 printf ("FIT Image at %08lX:\n", (ulong)hdr);
830 fit_print_contents (hdr);
831 break;
832 #endif
833 default:
834 goto next_sector;
837 next_sector: ;
839 next_bank: ;
842 return (0);
845 U_BOOT_CMD(
846 imls, 1, 1, do_imls,
847 "imls - list all images found in flash\n",
848 "\n"
849 " - Prints information about all images found at sector\n"
850 " boundaries in flash.\n"
852 #endif
854 /*******************************************************************/
855 /* helper routines */
856 /*******************************************************************/
857 #ifdef CONFIG_SILENT_CONSOLE
858 static void fixup_silent_linux ()
860 char buf[256], *start, *end;
861 char *cmdline = getenv ("bootargs");
863 /* Only fix cmdline when requested */
864 if (!(gd->flags & GD_FLG_SILENT))
865 return;
867 debug ("before silent fix-up: %s\n", cmdline);
868 if (cmdline) {
869 if ((start = strstr (cmdline, "console=")) != NULL) {
870 end = strchr (start, ' ');
871 strncpy (buf, cmdline, (start - cmdline + 8));
872 if (end)
873 strcpy (buf + (start - cmdline + 8), end);
874 else
875 buf[start - cmdline + 8] = '\0';
876 } else {
877 strcpy (buf, cmdline);
878 strcat (buf, " console=");
880 } else {
881 strcpy (buf, "console=");
884 setenv ("bootargs", buf);
885 debug ("after silent fix-up: %s\n", buf);
887 #endif /* CONFIG_SILENT_CONSOLE */
890 /*******************************************************************/
891 /* OS booting routines */
892 /*******************************************************************/
894 static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
895 int argc, char *argv[],
896 bootm_headers_t *images)
898 void (*loader)(bd_t *, image_header_t *, char *, char *);
899 image_header_t *os_hdr, *hdr;
900 ulong kernel_data, kernel_len;
901 char *consdev;
902 char *cmdline;
904 #if defined(CONFIG_FIT)
905 if (!images->legacy_hdr_valid) {
906 fit_unsupported_reset ("NetBSD");
907 do_reset (cmdtp, flag, argc, argv);
909 #endif
910 hdr = images->legacy_hdr_os;
913 * Booting a (NetBSD) kernel image
915 * This process is pretty similar to a standalone application:
916 * The (first part of an multi-) image must be a stage-2 loader,
917 * which in turn is responsible for loading & invoking the actual
918 * kernel. The only differences are the parameters being passed:
919 * besides the board info strucure, the loader expects a command
920 * line, the name of the console device, and (optionally) the
921 * address of the original image header.
923 os_hdr = NULL;
924 if (image_check_type (hdr, IH_TYPE_MULTI)) {
925 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
926 if (kernel_len)
927 os_hdr = hdr;
930 consdev = "";
931 #if defined (CONFIG_8xx_CONS_SMC1)
932 consdev = "smc1";
933 #elif defined (CONFIG_8xx_CONS_SMC2)
934 consdev = "smc2";
935 #elif defined (CONFIG_8xx_CONS_SCC2)
936 consdev = "scc2";
937 #elif defined (CONFIG_8xx_CONS_SCC3)
938 consdev = "scc3";
939 #endif
941 if (argc > 2) {
942 ulong len;
943 int i;
945 for (i = 2, len = 0; i < argc; i += 1)
946 len += strlen (argv[i]) + 1;
947 cmdline = malloc (len);
949 for (i = 2, len = 0; i < argc; i += 1) {
950 if (i > 2)
951 cmdline[len++] = ' ';
952 strcpy (&cmdline[len], argv[i]);
953 len += strlen (argv[i]);
955 } else if ((cmdline = getenv ("bootargs")) == NULL) {
956 cmdline = "";
959 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
961 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
962 (ulong)loader);
964 show_boot_progress (15);
967 * NetBSD Stage-2 Loader Parameters:
968 * r3: ptr to board info data
969 * r4: image address
970 * r5: console device
971 * r6: boot args string
973 (*loader) (gd->bd, os_hdr, consdev, cmdline);
976 #ifdef CONFIG_LYNXKDI
977 static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
978 int argc, char *argv[],
979 bootm_headers_t *images)
981 image_header_t *hdr = images->legacy_hdr_os;
983 #if defined(CONFIG_FIT)
984 if (!images->legacy_hdr_valid) {
985 fit_unsupported_reset ("Lynx");
986 do_reset (cmdtp, flag, argc, argv);
988 #endif
990 lynxkdi_boot ((image_header_t *)hdr);
992 #endif /* CONFIG_LYNXKDI */
994 static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
995 int argc, char *argv[],
996 bootm_headers_t *images)
998 image_header_t *hdr = images->legacy_hdr_os;
999 void (*entry_point)(bd_t *);
1001 #if defined(CONFIG_FIT)
1002 if (!images->legacy_hdr_valid) {
1003 fit_unsupported_reset ("RTEMS");
1004 do_reset (cmdtp, flag, argc, argv);
1006 #endif
1008 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
1010 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1011 (ulong)entry_point);
1013 show_boot_progress (15);
1016 * RTEMS Parameters:
1017 * r3: ptr to board info data
1019 (*entry_point)(gd->bd);
1022 #if defined(CONFIG_CMD_ELF)
1023 static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
1024 int argc, char *argv[],
1025 bootm_headers_t *images)
1027 char str[80];
1028 image_header_t *hdr = images->legacy_hdr_os;
1030 #if defined(CONFIG_FIT)
1031 if (hdr == NULL) {
1032 fit_unsupported_reset ("VxWorks");
1033 do_reset (cmdtp, flag, argc, argv);
1035 #endif
1037 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
1038 setenv("loadaddr", str);
1039 do_bootvx(cmdtp, 0, 0, NULL);
1042 static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
1043 int argc, char *argv[],
1044 bootm_headers_t *images)
1046 char *local_args[2];
1047 char str[16];
1048 image_header_t *hdr = images->legacy_hdr_os;
1050 #if defined(CONFIG_FIT)
1051 if (!images->legacy_hdr_valid) {
1052 fit_unsupported_reset ("QNX");
1053 do_reset (cmdtp, flag, argc, argv);
1055 #endif
1057 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
1058 local_args[0] = argv[0];
1059 local_args[1] = str; /* and provide it via the arguments */
1060 do_bootelf(cmdtp, 0, 2, local_args);
1062 #endif
1064 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
1065 static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
1066 int argc, char *argv[],
1067 bootm_headers_t *images)
1069 ulong top;
1070 char *s, *cmdline;
1071 char **fwenv, **ss;
1072 int i, j, nxt, len, envno, envsz;
1073 bd_t *kbd;
1074 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
1075 image_header_t *hdr = images->legacy_hdr_os;
1077 #if defined(CONFIG_FIT)
1078 if (!images->legacy_hdr_valid) {
1079 fit_unsupported_reset ("ARTOS");
1080 do_reset (cmdtp, flag, argc, argv);
1082 #endif
1085 * Booting an ARTOS kernel image + application
1088 /* this used to be the top of memory, but was wrong... */
1089 #ifdef CONFIG_PPC
1090 /* get stack pointer */
1091 asm volatile ("mr %0,1" : "=r"(top) );
1092 #endif
1093 debug ("## Current stack ends at 0x%08lX ", top);
1095 top -= 2048; /* just to be sure */
1096 if (top > CFG_BOOTMAPSZ)
1097 top = CFG_BOOTMAPSZ;
1098 top &= ~0xF;
1100 debug ("=> set upper limit to 0x%08lX\n", top);
1102 /* first check the artos specific boot args, then the linux args*/
1103 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
1104 s = "";
1106 /* get length of cmdline, and place it */
1107 len = strlen (s);
1108 top = (top - (len + 1)) & ~0xF;
1109 cmdline = (char *)top;
1110 debug ("## cmdline at 0x%08lX ", top);
1111 strcpy (cmdline, s);
1113 /* copy bdinfo */
1114 top = (top - sizeof (bd_t)) & ~0xF;
1115 debug ("## bd at 0x%08lX ", top);
1116 kbd = (bd_t *)top;
1117 memcpy (kbd, gd->bd, sizeof (bd_t));
1119 /* first find number of env entries, and their size */
1120 envno = 0;
1121 envsz = 0;
1122 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1123 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
1125 envno++;
1126 envsz += (nxt - i) + 1; /* plus trailing zero */
1128 envno++; /* plus the terminating zero */
1129 debug ("## %u envvars total size %u ", envno, envsz);
1131 top = (top - sizeof (char **) * envno) & ~0xF;
1132 fwenv = (char **)top;
1133 debug ("## fwenv at 0x%08lX ", top);
1135 top = (top - envsz) & ~0xF;
1136 s = (char *)top;
1137 ss = fwenv;
1139 /* now copy them */
1140 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1141 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
1143 *ss++ = s;
1144 for (j = i; j < nxt; ++j)
1145 *s++ = env_get_char (j);
1146 *s++ = '\0';
1148 *ss++ = NULL; /* terminate */
1150 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
1151 (*entry) (kbd, cmdline, fwenv, top);
1153 #endif