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
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,
36 #include <environment.h>
37 #include <asm/byteorder.h>
39 #if defined(CONFIG_OF_LIBFDT)
42 #include <fdt_support.h>
44 #if defined(CONFIG_OF_FLAT_TREE)
48 DECLARE_GLOBAL_DATA_PTR;
51 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
53 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
57 #ifdef CFG_HUSH_PARSER
61 #ifdef CFG_INIT_RAM_LOCK
62 #include <asm/cache.h>
65 #ifdef CONFIG_LOGBUFFER
69 #ifdef CONFIG_HAS_DATAFLASH
70 #include <dataflash.h>
74 * Some systems (for example LWMON) have very short watchdog periods;
75 * we must make sure to split long operations like memmove() or
76 * crc32() into reasonable chunks.
78 #define CHUNKSZ (64 * 1024)
80 int gunzip (void *, int, unsigned char *, unsigned long *);
82 static void *zalloc(void *, unsigned, unsigned);
83 static void zfree(void *, void *, unsigned);
85 #if defined(CONFIG_CMD_IMI)
86 static int image_info (unsigned long addr);
89 #if defined(CONFIG_CMD_IMLS)
91 extern flash_info_t flash_info[]; /* info for FLASH chips */
92 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
95 static void print_type (image_header_t *hdr);
98 image_header_t *fake_header(image_header_t *hdr, void *ptr, int size);
102 * Continue booting an OS image; caller already has:
103 * - copied image header to global variable `header'
104 * - checked header magic number, checksums (both header & image),
105 * - verified image architecture (PPC) and type (KERNEL or MULTI),
106 * - loaded (first part of) image to header load address,
107 * - disabled interrupts.
109 typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag,
110 int argc, char *argv[],
111 ulong addr, /* of image to boot */
112 ulong *len_ptr, /* multi-file image length table */
113 int verify); /* getenv("verify")[0] != 'n' */
116 extern int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
120 static boot_os_Fcn do_bootm_linux;
122 extern boot_os_Fcn do_bootm_linux;
124 #ifdef CONFIG_SILENT_CONSOLE
125 static void fixup_silent_linux (void);
127 static boot_os_Fcn do_bootm_netbsd;
128 static boot_os_Fcn do_bootm_rtems;
129 #if defined(CONFIG_CMD_ELF)
130 static boot_os_Fcn do_bootm_vxworks;
131 static boot_os_Fcn do_bootm_qnxelf;
132 int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
133 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
135 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
136 static boot_os_Fcn do_bootm_artos;
138 #ifdef CONFIG_LYNXKDI
139 static boot_os_Fcn do_bootm_lynxkdi;
140 extern void lynxkdi_boot( image_header_t * );
143 #ifndef CFG_BOOTM_LEN
144 #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
147 image_header_t header;
149 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
151 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
157 uint unc_len = CFG_BOOTM_LEN;
160 int (*appl)(int, char *[]);
161 image_header_t *hdr = &header;
163 verify = getenv_verify ();
168 addr = simple_strtoul(argv[1], NULL, 16);
171 show_boot_progress (1);
172 printf ("## Booting image at %08lx ...\n", addr);
174 /* Copy header so we can blank CRC field for re-calculation */
175 #ifdef CONFIG_HAS_DATAFLASH
176 if (addr_dataflash(addr)){
177 read_dataflash (addr, image_get_header_size (), (char *)&header);
180 memmove (&header, (char *)addr, image_get_header_size ());
182 if (!image_check_magic (hdr)) {
183 #ifdef __I386__ /* correct image format not implemented yet - fake it */
184 if (fake_header(hdr, (void*)addr, -1) != NULL) {
185 /* to compensate for the addition below */
186 addr -= image_get_header_size ();
188 * fake_header() does not fake the data crc
192 #endif /* __I386__ */
194 puts ("Bad Magic Number\n");
195 show_boot_progress (-1);
199 show_boot_progress (2);
201 if (!image_check_hcrc (hdr)) {
202 puts ("Bad Header Checksum\n");
203 show_boot_progress (-2);
206 show_boot_progress (3);
208 #ifdef CONFIG_HAS_DATAFLASH
209 if (addr_dataflash(addr)){
210 len = image_get_image_size (hdr);
211 read_dataflash(addr, len, (char *)CFG_LOAD_ADDR);
212 addr = CFG_LOAD_ADDR;
217 /* for multi-file images we need the data part, too */
218 print_image_hdr ((image_header_t *)addr);
220 len = image_get_data_size (hdr);
221 data = addr + image_get_header_size ();
222 len_ptr = (ulong *)data;
225 puts (" Verifying Checksum ... ");
226 if (!image_check_dcrc ((image_header_t *)addr)) {
227 printf ("Bad Data CRC\n");
228 show_boot_progress (-3);
233 show_boot_progress (4);
235 if (!image_check_target_arch (hdr)) {
236 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
237 show_boot_progress (-4);
240 show_boot_progress (5);
242 switch (image_get_type (hdr)) {
243 case IH_TYPE_STANDALONE:
244 name = "Standalone Application";
245 /* A second argument overwrites the load address */
247 image_set_load (hdr, simple_strtoul (argv[2], NULL, 16));
251 name = "Kernel Image";
254 name = "Multi-File Image";
255 len = image_to_cpu (len_ptr[0]);
256 /* OS kernel is always the first image */
257 data += 8; /* kernel_len + terminator */
258 for (i=1; len_ptr[i]; ++i)
261 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
262 show_boot_progress (-5);
265 show_boot_progress (6);
268 * We have reached the point of no return: we are going to
269 * overwrite all exception vector code, so we cannot easily
270 * recover from any failures any more...
273 iflag = disable_interrupts();
275 #ifdef CONFIG_AMIGAONEG3SE
277 * We've possible left the caches enabled during
278 * bios emulation, so turn them off again
281 invalidate_l1_instruction_cache();
286 switch (image_get_comp (hdr)) {
288 if (image_get_load (hdr) == addr) {
289 printf (" XIP %s ... ", name);
291 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
293 void *to = (void *)image_get_load (hdr);
294 void *from = (void *)data;
296 printf (" Loading %s ... ", name);
299 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
301 memmove (to, from, tail);
306 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
307 memmove ((void *)image_get_load (hdr), (uchar *)data, len);
308 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
312 printf (" Uncompressing %s ... ", name);
313 if (gunzip ((void *)image_get_load (hdr), unc_len,
314 (uchar *)data, &len) != 0) {
315 puts ("GUNZIP ERROR - must RESET board to recover\n");
316 show_boot_progress (-6);
317 do_reset (cmdtp, flag, argc, argv);
322 printf (" Uncompressing %s ... ", name);
324 * If we've got less than 4 MB of malloc() space,
325 * use slower decompression algorithm which requires
326 * at most 2300 KB of memory.
328 i = BZ2_bzBuffToBuffDecompress ((char*)image_get_load (hdr),
329 &unc_len, (char *)data, len,
330 CFG_MALLOC_LEN < (4096 * 1024), 0);
332 printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
333 show_boot_progress (-6);
334 do_reset (cmdtp, flag, argc, argv);
337 #endif /* CONFIG_BZIP2 */
341 printf ("Unimplemented compression type %d\n", image_get_comp (hdr));
342 show_boot_progress (-7);
346 show_boot_progress (7);
348 switch (image_get_type (hdr)) {
349 case IH_TYPE_STANDALONE:
353 /* load (and uncompress), but don't start if "autostart"
356 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) {
358 sprintf(buf, "%lX", len);
359 setenv("filesize", buf);
362 appl = (int (*)(int, char *[]))image_get_ep (hdr);
363 (*appl)(argc-1, &argv[1]);
372 printf ("Can't boot image type %d\n", image_get_type (hdr));
373 show_boot_progress (-8);
376 show_boot_progress (8);
378 switch (image_get_os (hdr)) {
379 default: /* handled by (original) Linux case */
381 #ifdef CONFIG_SILENT_CONSOLE
382 fixup_silent_linux();
384 do_bootm_linux (cmdtp, flag, argc, argv,
385 addr, len_ptr, verify);
388 do_bootm_netbsd (cmdtp, flag, argc, argv,
389 addr, len_ptr, verify);
392 #ifdef CONFIG_LYNXKDI
394 do_bootm_lynxkdi (cmdtp, flag, argc, argv,
395 addr, len_ptr, verify);
400 do_bootm_rtems (cmdtp, flag, argc, argv,
401 addr, len_ptr, verify);
404 #if defined(CONFIG_CMD_ELF)
406 do_bootm_vxworks (cmdtp, flag, argc, argv,
407 addr, len_ptr, verify);
410 do_bootm_qnxelf (cmdtp, flag, argc, argv,
411 addr, len_ptr, verify);
416 do_bootm_artos (cmdtp, flag, argc, argv,
417 addr, len_ptr, verify);
422 show_boot_progress (-9);
424 puts ("\n## Control returned to monitor - resetting...\n");
425 do_reset (cmdtp, flag, argc, argv);
431 bootm, CFG_MAXARGS, 1, do_bootm,
432 "bootm - boot application image from memory\n",
433 "[addr [arg ...]]\n - boot application image stored in memory\n"
434 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
435 "\t'arg' can be the address of an initrd image\n"
436 #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
437 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
438 "\ta third argument is required which is the address of the\n"
439 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
440 "\tuse a '-' for the second argument. If you do not pass a third\n"
441 "\ta bd_info struct will be passed instead\n"
445 #ifdef CONFIG_SILENT_CONSOLE
447 fixup_silent_linux ()
449 char buf[256], *start, *end;
450 char *cmdline = getenv ("bootargs");
452 /* Only fix cmdline when requested */
453 if (!(gd->flags & GD_FLG_SILENT))
456 debug ("before silent fix-up: %s\n", cmdline);
458 if ((start = strstr (cmdline, "console=")) != NULL) {
459 end = strchr (start, ' ');
460 strncpy (buf, cmdline, (start - cmdline + 8));
462 strcpy (buf + (start - cmdline + 8), end);
464 buf[start - cmdline + 8] = '\0';
466 strcpy (buf, cmdline);
467 strcat (buf, " console=");
470 strcpy (buf, "console=");
473 setenv ("bootargs", buf);
474 debug ("after silent fix-up: %s\n", buf);
476 #endif /* CONFIG_SILENT_CONSOLE */
479 static void __attribute__((noinline))
480 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
481 int argc, char *argv[],
488 ulong initrd_start, initrd_end;
489 ulong cmd_start, cmd_end;
492 int initrd_copy_to_ram = 1;
496 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
497 image_header_t *hdr = &header;
498 #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
499 char *of_flat_tree = NULL;
503 if ((s = getenv ("initrd_high")) != NULL) {
504 /* a value of "no" or a similar string will act like 0,
505 * turning the "load high" feature off. This is intentional.
507 initrd_high = simple_strtoul(s, NULL, 16);
508 if (initrd_high == ~0)
509 initrd_copy_to_ram = 0;
510 } else { /* not set, no restrictions to load high */
514 #ifdef CONFIG_LOGBUFFER
516 /* Prevent initrd from overwriting logbuffer */
517 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
518 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
519 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
523 * Booting a (Linux) kernel image
525 * Allocate space for command line and board info - the
526 * address should be as high as possible within the reach of
527 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
528 * memory, which means far enough below the current stack
532 asm( "mr %0,1": "=r"(sp) : );
534 debug ("## Current stack ends at 0x%08lX ", sp);
536 sp -= 2048; /* just to be sure */
537 if (sp > CFG_BOOTMAPSZ)
541 debug ("=> set upper limit to 0x%08lX\n", sp);
543 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
544 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
546 if ((s = getenv("bootargs")) == NULL)
551 cmd_start = (ulong)&cmdline[0];
552 cmd_end = cmd_start + strlen(cmdline);
557 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
559 do_bdinfo (NULL, 0, 0, NULL);
562 if ((s = getenv ("clocks_in_mhz")) != NULL) {
563 /* convert all clock information to MHz */
564 kbd->bi_intfreq /= 1000000L;
565 kbd->bi_busfreq /= 1000000L;
566 #if defined(CONFIG_MPC8220)
567 kbd->bi_inpfreq /= 1000000L;
568 kbd->bi_pcifreq /= 1000000L;
569 kbd->bi_pevfreq /= 1000000L;
570 kbd->bi_flbfreq /= 1000000L;
571 kbd->bi_vcofreq /= 1000000L;
573 #if defined(CONFIG_CPM2)
574 kbd->bi_cpmfreq /= 1000000L;
575 kbd->bi_brgfreq /= 1000000L;
576 kbd->bi_sccfreq /= 1000000L;
577 kbd->bi_vco /= 1000000L;
579 #if defined(CONFIG_MPC5xxx)
580 kbd->bi_ipbfreq /= 1000000L;
581 kbd->bi_pcifreq /= 1000000L;
582 #endif /* CONFIG_MPC5xxx */
585 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr);
588 * Check if there is an initrd image
591 #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
592 /* Look for a '-' which indicates to ignore the ramdisk argument */
593 if (argc >= 3 && strcmp(argv[2], "-") == 0) {
594 debug ("Skipping initrd\n");
600 debug ("Not skipping initrd\n");
601 show_boot_progress (9);
603 addr = simple_strtoul(argv[2], NULL, 16);
605 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
606 hdr = (image_header_t *)addr;
608 if (!image_check_magic (hdr)) {
609 puts ("Bad Magic Number\n");
610 show_boot_progress (-10);
611 do_reset (cmdtp, flag, argc, argv);
614 if (!image_check_hcrc (hdr)) {
615 puts ("Bad Header Checksum\n");
616 show_boot_progress (-11);
617 do_reset (cmdtp, flag, argc, argv);
619 show_boot_progress (10);
621 print_image_hdr (hdr);
624 puts (" Verifying Checksum ... ");
626 if (!image_check_dcrc_wd (hdr, CHUNKSZ)) {
627 puts ("Bad Data CRC\n");
628 show_boot_progress (-12);
629 do_reset (cmdtp, flag, argc, argv);
634 show_boot_progress (11);
636 if (!image_check_os (hdr, IH_OS_LINUX) ||
637 !image_check_arch (hdr, IH_ARCH_PPC) ||
638 !image_check_type (hdr, IH_TYPE_RAMDISK)) {
639 puts ("No Linux PPC Ramdisk Image\n");
640 show_boot_progress (-13);
641 do_reset (cmdtp, flag, argc, argv);
644 data = image_get_data (hdr);
645 len = image_get_data_size (hdr);
648 * Now check if we have a multifile image
650 } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) {
651 u_long tail = image_to_cpu (len_ptr[0]) % 4;
654 show_boot_progress (13);
656 /* skip kernel length and terminator */
657 data = (ulong)(&len_ptr[2]);
658 /* skip any additional image length fields */
659 for (i=1; len_ptr[i]; ++i)
661 /* add kernel length, and align */
662 data += image_to_cpu (len_ptr[0]);
667 len = image_to_cpu (len_ptr[1]);
673 show_boot_progress (14);
678 #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
680 of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16);
681 hdr = (image_header_t *)of_flat_tree;
682 #if defined(CONFIG_OF_FLAT_TREE)
683 if (*((ulong *)(of_flat_tree + image_get_header_size ())) != OF_DT_HEADER) {
685 if (fdt_check_header (of_flat_tree + image_get_header_size ()) != 0) {
688 if (addr2info((ulong)of_flat_tree) != NULL)
689 of_data = (ulong)of_flat_tree;
691 } else if (image_check_magic (hdr)) {
692 printf("## Flat Device Tree at %08lX\n", hdr);
693 print_image_hdr (hdr);
695 if ((image_get_load (hdr) < ((unsigned long)hdr + image_get_image_size (hdr))) &&
696 ((image_get_load (hdr) + image_get_data_size (hdr)) > (unsigned long)hdr)) {
697 puts ("ERROR: fdt overwritten - "
698 "must RESET the board to recover.\n");
699 do_reset (cmdtp, flag, argc, argv);
702 puts (" Verifying Checksum ... ");
703 if (!image_check_hcrc (hdr)) {
704 puts ("ERROR: fdt header checksum invalid - "
705 "must RESET the board to recover.\n");
706 do_reset (cmdtp, flag, argc, argv);
709 if (!image_check_dcrc (hdr)) {
710 puts ("ERROR: fdt checksum invalid - "
711 "must RESET the board to recover.\n");
712 do_reset (cmdtp, flag, argc, argv);
716 if (!image_check_type (hdr, IH_TYPE_FLATDT)) {
717 puts ("ERROR: uImage is not a fdt - "
718 "must RESET the board to recover.\n");
719 do_reset (cmdtp, flag, argc, argv);
721 if (image_get_comp (hdr) != IH_COMP_NONE) {
722 puts ("ERROR: uImage is compressed - "
723 "must RESET the board to recover.\n");
724 do_reset (cmdtp, flag, argc, argv);
726 #if defined(CONFIG_OF_FLAT_TREE)
727 if (*((ulong *)(of_flat_tree + image_get_header_size ())) != OF_DT_HEADER) {
729 if (fdt_check_header (of_flat_tree + image_get_header_size ()) != 0) {
731 puts ("ERROR: uImage data is not a fdt - "
732 "must RESET the board to recover.\n");
733 do_reset (cmdtp, flag, argc, argv);
736 memmove ((void *)image_get_load (hdr),
737 (void *)(of_flat_tree + image_get_header_size ()),
738 image_get_data_size (hdr));
740 of_flat_tree = (char *)image_get_load (hdr);
742 puts ("Did not find a flat Flat Device Tree.\n"
743 "Must RESET the board to recover.\n");
744 do_reset (cmdtp, flag, argc, argv);
746 printf (" Booting using the fdt at 0x%x\n",
748 } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1]) && (len_ptr[2])) {
749 u_long tail = image_to_cpu (len_ptr[0]) % 4;
752 /* skip kernel length, initrd length, and terminator */
753 of_flat_tree = (char *)(&len_ptr[3]);
754 /* skip any additional image length fields */
755 for (i=2; len_ptr[i]; ++i)
757 /* add kernel length, and align */
758 of_flat_tree += image_to_cpu (len_ptr[0]);
760 of_flat_tree += 4 - tail;
763 /* add initrd length, and align */
764 tail = image_to_cpu (len_ptr[1]) % 4;
765 of_flat_tree += image_to_cpu (len_ptr[1]);
767 of_flat_tree += 4 - tail;
771 /* move the blob if it is in flash (set of_data to !null) */
772 if (addr2info ((ulong)of_flat_tree) != NULL)
773 of_data = (ulong)of_flat_tree;
777 #if defined(CONFIG_OF_FLAT_TREE)
778 if (*((ulong *)(of_flat_tree)) != OF_DT_HEADER) {
780 if (fdt_check_header (of_flat_tree) != 0) {
782 puts ("ERROR: image is not a fdt - "
783 "must RESET the board to recover.\n");
784 do_reset (cmdtp, flag, argc, argv);
787 #if defined(CONFIG_OF_FLAT_TREE)
788 if (((struct boot_param_header *)of_flat_tree)->totalsize !=
789 image_to_cpu (len_ptr[2])) {
791 if (be32_to_cpu (fdt_totalsize (of_flat_tree)) !=
792 image_to_cpu (len_ptr[2])) {
794 puts ("ERROR: fdt size != image size - "
795 "must RESET the board to recover.\n");
796 do_reset (cmdtp, flag, argc, argv);
801 debug ("No initrd\n");
805 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
807 initrd_end = initrd_start + len;
809 initrd_start = (ulong)kbd - len;
810 initrd_start &= ~(4096 - 1); /* align on page */
816 * the inital ramdisk does not need to be within
817 * CFG_BOOTMAPSZ as it is not accessed until after
818 * the mm system is initialised.
820 * do the stack bottom calculation again and see if
821 * the initrd will fit just below the monitor stack
822 * bottom without overwriting the area allocated
823 * above for command line args and board info.
825 asm( "mr %0,1": "=r"(nsp) : );
826 nsp -= 2048; /* just to be sure */
828 if (nsp > initrd_high) /* limit as specified */
831 nsp &= ~(4096 - 1); /* align on page */
836 show_boot_progress (12);
838 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
839 data, data + len - 1, len, len);
841 initrd_end = initrd_start + len;
842 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
843 initrd_start, initrd_end);
844 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
847 void *to = (void *)initrd_start;
848 void *from = (void *)data;
851 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
853 memmove (to, from, tail);
859 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
860 memmove ((void *)initrd_start, (void *)data, len);
861 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
869 #if defined(CONFIG_OF_LIBFDT)
873 * The blob must be within CFG_BOOTMAPSZ,
874 * so we flag it to be copied if it is not.
876 if (of_flat_tree >= (char *)CFG_BOOTMAPSZ)
877 of_data = (ulong)of_flat_tree;
880 /* move of_flat_tree if needed */
883 ulong of_start, of_len;
885 of_len = be32_to_cpu(fdt_totalsize(of_data));
887 /* position on a 4K boundary before the kbd */
888 of_start = (ulong)kbd - of_len;
889 of_start &= ~(4096 - 1); /* align on page */
890 debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
891 of_data, of_data + of_len - 1, of_len, of_len);
893 of_flat_tree = (char *)of_start;
894 printf (" Loading Device Tree to %08lx, end %08lx ... ",
895 of_start, of_start + of_len - 1);
896 err = fdt_open_into((void *)of_data, (void *)of_start, of_len);
898 puts ("ERROR: fdt move failed - "
899 "must RESET the board to recover.\n");
900 do_reset (cmdtp, flag, argc, argv);
905 * Add the chosen node if it doesn't exist, add the env and bd_t
906 * if the user wants it (the logic is in the subroutines).
909 if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) {
910 puts ("ERROR: /chosen node create failed - "
911 "must RESET the board to recover.\n");
912 do_reset (cmdtp, flag, argc, argv);
914 #ifdef CONFIG_OF_HAS_UBOOT_ENV
915 if (fdt_env(of_flat_tree) < 0) {
916 puts ("ERROR: /u-boot-env node create failed - "
917 "must RESET the board to recover.\n");
918 do_reset (cmdtp, flag, argc, argv);
921 #ifdef CONFIG_OF_HAS_BD_T
922 if (fdt_bd_t(of_flat_tree) < 0) {
923 puts ("ERROR: /bd_t node create failed - "
924 "must RESET the board to recover.\n");
925 do_reset (cmdtp, flag, argc, argv);
928 #ifdef CONFIG_OF_BOARD_SETUP
929 /* Call the board-specific fixup routine */
930 ft_board_setup(of_flat_tree, gd->bd);
933 #endif /* CONFIG_OF_LIBFDT */
934 #if defined(CONFIG_OF_FLAT_TREE)
937 * The blob must be within CFG_BOOTMAPSZ,
938 * so we flag it to be copied if it is not.
940 if (of_flat_tree >= (char *)CFG_BOOTMAPSZ)
941 of_data = (ulong)of_flat_tree;
944 /* move of_flat_tree if needed */
946 ulong of_start, of_len;
947 of_len = ((struct boot_param_header *)of_data)->totalsize;
949 /* provide extra 8k pad */
950 of_start = (ulong)kbd - of_len - 8192;
951 of_start &= ~(4096 - 1); /* align on page */
952 debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
953 of_data, of_data + of_len - 1, of_len, of_len);
955 of_flat_tree = (char *)of_start;
956 printf (" Loading Device Tree to %08lx, end %08lx ... ",
957 of_start, of_start + of_len - 1);
958 memmove ((void *)of_start, (void *)of_data, of_len);
962 * Create the /chosen node and modify the blob with board specific
965 ft_setup(of_flat_tree, kbd, initrd_start, initrd_end);
966 /* ft_dump_blob(of_flat_tree); */
968 debug ("## Transferring control to Linux (at address %08lx) ...\n",
971 show_boot_progress (15);
973 #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
974 unlock_ram_in_cache();
977 #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
978 if (of_flat_tree) { /* device tree; boot new style */
980 * Linux Kernel Parameters (passing device tree):
981 * r3: pointer to the fdt, followed by the board info data
982 * r4: physical pointer to the kernel itself
987 (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0);
988 /* does not return */
992 * Linux Kernel Parameters (passing board info data):
993 * r3: ptr to board info data
994 * r4: initrd_start or 0 if no initrd
995 * r5: initrd_end - unused if r4 is 0
996 * r6: Start of command line string
997 * r7: End of command line string
999 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
1000 /* does not return */
1002 #endif /* CONFIG_PPC */
1005 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
1006 int argc, char *argv[],
1011 image_header_t *hdr = &header;
1013 void (*loader)(bd_t *, image_header_t *, char *, char *);
1014 image_header_t *img_addr;
1020 * Booting a (NetBSD) kernel image
1022 * This process is pretty similar to a standalone application:
1023 * The (first part of an multi-) image must be a stage-2 loader,
1024 * which in turn is responsible for loading & invoking the actual
1025 * kernel. The only differences are the parameters being passed:
1026 * besides the board info strucure, the loader expects a command
1027 * line, the name of the console device, and (optionally) the
1028 * address of the original image header.
1032 if ((image_check_type (hdr, IH_TYPE_MULTI)) && (len_ptr[1]))
1033 img_addr = (image_header_t *) addr;
1037 #if defined (CONFIG_8xx_CONS_SMC1)
1039 #elif defined (CONFIG_8xx_CONS_SMC2)
1041 #elif defined (CONFIG_8xx_CONS_SCC2)
1043 #elif defined (CONFIG_8xx_CONS_SCC3)
1051 for (i=2, len=0 ; i<argc ; i+=1)
1052 len += strlen (argv[i]) + 1;
1053 cmdline = malloc (len);
1055 for (i=2, len=0 ; i<argc ; i+=1) {
1057 cmdline[len++] = ' ';
1058 strcpy (&cmdline[len], argv[i]);
1059 len += strlen (argv[i]);
1061 } else if ((cmdline = getenv("bootargs")) == NULL) {
1065 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
1067 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1070 show_boot_progress (15);
1073 * NetBSD Stage-2 Loader Parameters:
1074 * r3: ptr to board info data
1076 * r5: console device
1077 * r6: boot args string
1079 (*loader) (gd->bd, img_addr, consdev, cmdline);
1082 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
1084 /* Function that returns a character from the environment */
1085 extern uchar (*env_get_char)(int);
1088 do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
1089 int argc, char *argv[],
1097 int i, j, nxt, len, envno, envsz;
1099 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
1100 image_header_t *hdr = &header;
1103 * Booting an ARTOS kernel image + application
1106 /* this used to be the top of memory, but was wrong... */
1108 /* get stack pointer */
1109 asm volatile ("mr %0,1" : "=r"(top) );
1111 debug ("## Current stack ends at 0x%08lX ", top);
1113 top -= 2048; /* just to be sure */
1114 if (top > CFG_BOOTMAPSZ)
1115 top = CFG_BOOTMAPSZ;
1118 debug ("=> set upper limit to 0x%08lX\n", top);
1120 /* first check the artos specific boot args, then the linux args*/
1121 if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
1124 /* get length of cmdline, and place it */
1126 top = (top - (len + 1)) & ~0xF;
1127 cmdline = (char *)top;
1128 debug ("## cmdline at 0x%08lX ", top);
1132 top = (top - sizeof(bd_t)) & ~0xF;
1133 debug ("## bd at 0x%08lX ", top);
1135 memcpy(kbd, gd->bd, sizeof(bd_t));
1137 /* first find number of env entries, and their size */
1140 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
1141 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
1144 envsz += (nxt - i) + 1; /* plus trailing zero */
1146 envno++; /* plus the terminating zero */
1147 debug ("## %u envvars total size %u ", envno, envsz);
1149 top = (top - sizeof(char **)*envno) & ~0xF;
1150 fwenv = (char **)top;
1151 debug ("## fwenv at 0x%08lX ", top);
1153 top = (top - envsz) & ~0xF;
1158 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
1159 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
1162 for (j = i; j < nxt; ++j)
1163 *s++ = env_get_char(j);
1166 *ss++ = NULL; /* terminate */
1168 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
1169 (*entry)(kbd, cmdline, fwenv, top);
1174 #if defined(CONFIG_CMD_BOOTD)
1175 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1178 #ifndef CFG_HUSH_PARSER
1179 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
1181 if (parse_string_outer(getenv("bootcmd"),
1182 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
1188 boot, 1, 1, do_bootd,
1189 "boot - boot default, i.e., run 'bootcmd'\n",
1193 /* keep old command name "bootd" for backward compatibility */
1195 bootd, 1, 1, do_bootd,
1196 "bootd - boot default, i.e., run 'bootcmd'\n",
1202 #if defined(CONFIG_CMD_IMI)
1203 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1210 return image_info (load_addr);
1213 for (arg=1; arg <argc; ++arg) {
1214 addr = simple_strtoul(argv[arg], NULL, 16);
1215 if (image_info (addr) != 0) rcode = 1;
1220 static int image_info (ulong addr)
1222 image_header_t *hdr = (image_header_t *)addr;
1224 printf ("\n## Checking Image at %08lx ...\n", addr);
1226 if (!image_check_magic (hdr)) {
1227 puts (" Bad Magic Number\n");
1231 if (!image_check_hcrc (hdr)) {
1232 puts (" Bad Header Checksum\n");
1236 print_image_hdr (hdr);
1238 puts (" Verifying Checksum ... ");
1239 if (!image_check_dcrc (hdr)) {
1240 puts (" Bad Data CRC\n");
1248 iminfo, CFG_MAXARGS, 1, do_iminfo,
1249 "iminfo - print header information for application image\n",
1251 " - print header information for application image starting at\n"
1252 " address 'addr' in memory; this includes verification of the\n"
1253 " image contents (magic number, header and payload checksums)\n"
1258 #if defined(CONFIG_CMD_IMLS)
1259 /*-----------------------------------------------------------------------
1260 * List all images found in flash.
1262 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1266 image_header_t *hdr;
1268 for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
1269 if (info->flash_id == FLASH_UNKNOWN)
1271 for (j=0; j<info->sector_count; ++j) {
1273 hdr = (image_header_t *)info->start[j];
1275 if (!hdr || !image_check_magic (hdr))
1278 if (!image_check_hcrc (hdr))
1281 printf ("Image at %08lX:\n", (ulong)hdr);
1282 print_image_hdr (hdr);
1284 puts (" Verifying Checksum ... ");
1285 if (!image_check_dcrc (hdr)) {
1286 puts ("Bad Data CRC\n");
1299 imls, 1, 1, do_imls,
1300 "imls - list all images found in flash\n",
1302 " - Prints information about all images found at sector\n"
1303 " boundaries in flash.\n"
1308 print_image_hdr (image_header_t *hdr)
1310 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
1311 time_t timestamp = (time_t)image_get_time (hdr);
1315 printf (" Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr));
1316 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
1317 to_tm (timestamp, &tm);
1318 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
1319 tm.tm_year, tm.tm_mon, tm.tm_mday,
1320 tm.tm_hour, tm.tm_min, tm.tm_sec);
1322 puts (" Image Type: "); print_type(hdr);
1323 printf ("\n Data Size: %d Bytes = ", image_get_data_size (hdr));
1324 print_size (image_get_data_size (hdr), "\n");
1325 printf (" Load Address: %08x\n"
1326 " Entry Point: %08x\n",
1327 image_get_load (hdr), image_get_ep (hdr));
1329 if (image_check_type (hdr, IH_TYPE_MULTI)) {
1332 ulong *len_ptr = (ulong *)((ulong)hdr + image_get_header_size ());
1334 puts (" Contents:\n");
1335 for (i=0; (len = image_to_cpu (*len_ptr)); ++i, ++len_ptr) {
1336 printf (" Image %d: %8ld Bytes = ", i, len);
1337 print_size (len, "\n");
1344 print_type (image_header_t *hdr)
1346 char *os, *arch, *type, *comp;
1348 switch (image_get_os (hdr)) {
1349 case IH_OS_INVALID: os = "Invalid OS"; break;
1350 case IH_OS_NETBSD: os = "NetBSD"; break;
1351 case IH_OS_LINUX: os = "Linux"; break;
1352 case IH_OS_VXWORKS: os = "VxWorks"; break;
1353 case IH_OS_QNX: os = "QNX"; break;
1354 case IH_OS_U_BOOT: os = "U-Boot"; break;
1355 case IH_OS_RTEMS: os = "RTEMS"; break;
1357 case IH_OS_ARTOS: os = "ARTOS"; break;
1359 #ifdef CONFIG_LYNXKDI
1360 case IH_OS_LYNXOS: os = "LynxOS"; break;
1362 default: os = "Unknown OS"; break;
1365 switch (image_get_arch (hdr)) {
1366 case IH_ARCH_INVALID: arch = "Invalid CPU"; break;
1367 case IH_ARCH_ALPHA: arch = "Alpha"; break;
1368 case IH_ARCH_ARM: arch = "ARM"; break;
1369 case IH_ARCH_AVR32: arch = "AVR32"; break;
1370 case IH_ARCH_BLACKFIN: arch = "Blackfin"; break;
1371 case IH_ARCH_I386: arch = "Intel x86"; break;
1372 case IH_ARCH_IA64: arch = "IA64"; break;
1373 case IH_ARCH_M68K: arch = "M68K"; break;
1374 case IH_ARCH_MICROBLAZE:arch = "Microblaze"; break;
1375 case IH_ARCH_MIPS64: arch = "MIPS 64 Bit"; break;
1376 case IH_ARCH_MIPS: arch = "MIPS"; break;
1377 case IH_ARCH_NIOS2: arch = "Nios-II"; break;
1378 case IH_ARCH_NIOS: arch = "Nios"; break;
1379 case IH_ARCH_PPC: arch = "PowerPC"; break;
1380 case IH_ARCH_S390: arch = "IBM S390"; break;
1381 case IH_ARCH_SH: arch = "SuperH"; break;
1382 case IH_ARCH_SPARC64: arch = "SPARC 64 Bit"; break;
1383 case IH_ARCH_SPARC: arch = "SPARC"; break;
1384 default: arch = "Unknown Architecture"; break;
1387 switch (image_get_type (hdr)) {
1388 case IH_TYPE_INVALID: type = "Invalid Image"; break;
1389 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
1390 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
1391 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
1392 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
1393 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
1394 case IH_TYPE_SCRIPT: type = "Script"; break;
1395 case IH_TYPE_FLATDT: type = "Flat Device Tree"; break;
1396 default: type = "Unknown Image"; break;
1399 switch (image_get_comp (hdr)) {
1400 case IH_COMP_NONE: comp = "uncompressed"; break;
1401 case IH_COMP_GZIP: comp = "gzip compressed"; break;
1402 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
1403 default: comp = "unknown compression"; break;
1406 printf ("%s %s %s (%s)", arch, os, type, comp);
1409 #define ZALLOC_ALIGNMENT 16
1411 static void *zalloc(void *x, unsigned items, unsigned size)
1416 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
1423 static void zfree(void *x, void *addr, unsigned nb)
1429 #define EXTRA_FIELD 4
1431 #define COMMENT 0x10
1432 #define RESERVED 0xe0
1436 int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
1444 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
1445 puts ("Error: Bad gzipped data\n");
1448 if ((flags & EXTRA_FIELD) != 0)
1449 i = 12 + src[10] + (src[11] << 8);
1450 if ((flags & ORIG_NAME) != 0)
1451 while (src[i++] != 0)
1453 if ((flags & COMMENT) != 0)
1454 while (src[i++] != 0)
1456 if ((flags & HEAD_CRC) != 0)
1459 puts ("Error: gunzip out of data in header\n");
1465 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1466 s.outcb = (cb_func)WATCHDOG_RESET;
1469 #endif /* CONFIG_HW_WATCHDOG */
1471 r = inflateInit2(&s, -MAX_WBITS);
1473 printf ("Error: inflateInit2() returned %d\n", r);
1476 s.next_in = src + i;
1477 s.avail_in = *lenp - i;
1479 s.avail_out = dstlen;
1480 r = inflate(&s, Z_FINISH);
1481 if (r != Z_OK && r != Z_STREAM_END) {
1482 printf ("Error: inflate() returned %d\n", r);
1485 *lenp = s.next_out - (unsigned char *) dst;
1492 void bz_internal_error(int errcode)
1494 printf ("BZIP2 internal error %d\n", errcode);
1496 #endif /* CONFIG_BZIP2 */
1499 do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1500 ulong addr, ulong *len_ptr, int verify)
1502 image_header_t *hdr = &header;
1503 void (*entry_point)(bd_t *);
1505 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
1507 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1508 (ulong)entry_point);
1510 show_boot_progress (15);
1514 * r3: ptr to board info data
1517 (*entry_point ) ( gd->bd );
1520 #if defined(CONFIG_CMD_ELF)
1522 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1523 ulong addr, ulong *len_ptr, int verify)
1525 image_header_t *hdr = &header;
1528 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
1529 setenv("loadaddr", str);
1530 do_bootvx(cmdtp, 0, 0, NULL);
1534 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1535 ulong addr, ulong *len_ptr, int verify)
1537 image_header_t *hdr = &header;
1538 char *local_args[2];
1541 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
1542 local_args[0] = argv[0];
1543 local_args[1] = str; /* and provide it via the arguments */
1544 do_bootelf(cmdtp, 0, 2, local_args);
1548 #ifdef CONFIG_LYNXKDI
1550 do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
1551 int argc, char *argv[],
1556 lynxkdi_boot( &header );
1559 #endif /* CONFIG_LYNXKDI */