2 * (C) Copyright 2000-2002
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,
34 #include <asm/byteorder.h>
35 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
39 #ifdef CFG_HUSH_PARSER
43 #ifdef CONFIG_SHOW_BOOT_PROGRESS
44 # include <status_led.h>
45 # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
47 # define SHOW_BOOT_PROGRESS(arg)
50 #ifdef CFG_INIT_RAM_LOCK
51 #include <asm/cache.h>
54 #ifdef CONFIG_LOGBUFFER
59 * Some systems (for example LWMON) have very short watchdog periods;
60 * we must make sure to split long operations like memmove() or
61 * crc32() into reasonable chunks.
63 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
64 # define CHUNKSZ (64 * 1024)
67 int gunzip (void *, int, unsigned char *, int *);
69 static void *zalloc(void *, unsigned, unsigned);
70 static void zfree(void *, void *, unsigned);
72 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
73 static int image_info (unsigned long addr);
75 static void print_type (image_header_t *hdr);
78 image_header_t *fake_header(image_header_t *hdr, void *ptr, int size);
82 * Continue booting an OS image; caller already has:
83 * - copied image header to global variable `header'
84 * - checked header magic number, checksums (both header & image),
85 * - verified image architecture (PPC) and type (KERNEL or MULTI),
86 * - loaded (first part of) image to header load address,
87 * - disabled interrupts.
89 typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag,
90 int argc, char *argv[],
91 ulong addr, /* of image to boot */
92 ulong *len_ptr, /* multi-file image length table */
93 int verify); /* getenv("verify")[0] != 'n' */
96 static boot_os_Fcn do_bootm_linux;
98 extern boot_os_Fcn do_bootm_linux;
100 static boot_os_Fcn do_bootm_netbsd;
101 static boot_os_Fcn do_bootm_rtems;
102 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
103 static boot_os_Fcn do_bootm_vxworks;
104 static boot_os_Fcn do_bootm_qnxelf;
105 int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
106 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
107 #endif /* CFG_CMD_ELF */
109 image_header_t header;
111 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
113 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
117 ulong data, len, checksum;
121 int (*appl)(cmd_tbl_t *, int, int, char *[]);
122 image_header_t *hdr = &header;
124 s = getenv ("verify");
125 verify = (s && (*s == 'n')) ? 0 : 1;
130 addr = simple_strtoul(argv[1], NULL, 16);
133 SHOW_BOOT_PROGRESS (1);
134 printf ("## Booting image at %08lx ...\n", addr);
136 /* Copy header so we can blank CRC field for re-calculation */
137 memmove (&header, (char *)addr, sizeof(image_header_t));
139 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
140 #ifdef __I386__ /* correct image format not implemented yet - fake it */
141 if (fake_header(hdr, (void*)addr, -1) != NULL) {
142 /* to compensate for the addition below */
143 addr -= sizeof(image_header_t);
145 * fake_header() does not fake the data crc
149 #endif /* __I386__ */
151 printf ("Bad Magic Number\n");
152 SHOW_BOOT_PROGRESS (-1);
156 SHOW_BOOT_PROGRESS (2);
158 data = (ulong)&header;
159 len = sizeof(image_header_t);
161 checksum = ntohl(hdr->ih_hcrc);
164 if (crc32 (0, (char *)data, len) != checksum) {
165 printf ("Bad Header Checksum\n");
166 SHOW_BOOT_PROGRESS (-2);
169 SHOW_BOOT_PROGRESS (3);
171 /* for multi-file images we need the data part, too */
172 print_image_hdr (hdr);
174 data = addr + sizeof(image_header_t);
175 len = ntohl(hdr->ih_size);
178 printf (" Verifying Checksum ... ");
179 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
180 printf ("Bad Data CRC\n");
181 SHOW_BOOT_PROGRESS (-3);
186 SHOW_BOOT_PROGRESS (4);
188 len_ptr = (ulong *)data;
191 if (hdr->ih_arch != IH_CPU_PPC)
192 #elif defined(__ARM__)
193 if (hdr->ih_arch != IH_CPU_ARM)
194 #elif defined(__I386__)
195 if (hdr->ih_arch != IH_CPU_I386)
196 #elif defined(__mips__)
197 if (hdr->ih_arch != IH_CPU_MIPS)
199 # error Unknown CPU type
202 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
203 SHOW_BOOT_PROGRESS (-4);
206 SHOW_BOOT_PROGRESS (5);
208 switch (hdr->ih_type) {
209 case IH_TYPE_STANDALONE: name = "Standalone Application";
211 case IH_TYPE_KERNEL: name = "Kernel Image";
213 case IH_TYPE_MULTI: name = "Multi-File Image";
214 len = ntohl(len_ptr[0]);
215 /* OS kernel is always the first image */
216 data += 8; /* kernel_len + terminator */
217 for (i=1; len_ptr[i]; ++i)
220 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
221 SHOW_BOOT_PROGRESS (-5);
224 SHOW_BOOT_PROGRESS (6);
227 * We have reached the point of no return: we are going to
228 * overwrite all exception vector code, so we cannot easily
229 * recover from any failures any more...
232 iflag = disable_interrupts();
234 #ifdef CONFIG_AMIGAONEG3SE
236 * We've possible left the caches enabled during
237 * bios emulation, so turn them off again
240 invalidate_l1_instruction_cache();
245 switch (hdr->ih_comp) {
247 if(ntohl(hdr->ih_load) == addr) {
248 printf (" XIP %s ... ", name);
250 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
252 void *to = (void *)ntohl(hdr->ih_load);
253 void *from = (void *)data;
255 printf (" Loading %s ... ", name);
258 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
260 memmove (to, from, tail);
265 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
266 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
267 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
271 printf (" Uncompressing %s ... ", name);
272 if (gunzip ((void *)ntohl(hdr->ih_load), 0x400000,
273 (uchar *)data, (int *)&len) != 0) {
274 printf ("GUNZIP ERROR - must RESET board to recover\n");
275 SHOW_BOOT_PROGRESS (-6);
276 do_reset (cmdtp, flag, argc, argv);
282 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
283 SHOW_BOOT_PROGRESS (-7);
287 SHOW_BOOT_PROGRESS (7);
289 switch (hdr->ih_type) {
290 case IH_TYPE_STANDALONE:
294 /* load (and uncompress), but don't start if "autostart"
297 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0))
299 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
300 (*appl)(cmdtp, flag, argc-1, &argv[1]);
309 printf ("Can't boot image type %d\n", hdr->ih_type);
310 SHOW_BOOT_PROGRESS (-8);
313 SHOW_BOOT_PROGRESS (8);
315 switch (hdr->ih_os) {
316 default: /* handled by (original) Linux case */
318 do_bootm_linux (cmdtp, flag, argc, argv,
319 addr, len_ptr, verify);
322 do_bootm_netbsd (cmdtp, flag, argc, argv,
323 addr, len_ptr, verify);
327 do_bootm_rtems (cmdtp, flag, argc, argv,
328 addr, len_ptr, verify);
331 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
333 do_bootm_vxworks (cmdtp, flag, argc, argv,
334 addr, len_ptr, verify);
337 do_bootm_qnxelf (cmdtp, flag, argc, argv,
338 addr, len_ptr, verify);
340 #endif /* CFG_CMD_ELF */
343 SHOW_BOOT_PROGRESS (-9);
345 printf ("\n## Control returned to monitor - resetting...\n");
346 do_reset (cmdtp, flag, argc, argv);
353 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
354 int argc, char *argv[],
359 DECLARE_GLOBAL_DATA_PTR;
363 ulong initrd_start, initrd_end;
364 ulong cmd_start, cmd_end;
370 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
371 image_header_t *hdr = &header;
373 if ((s = getenv ("initrd_high")) != NULL) {
374 /* a value of "no" or a similar string will act like 0,
375 * turning the "load high" feature off. This is intentional.
377 initrd_high = simple_strtoul(s, NULL, 16);
378 } else { /* not set, no restrictions to load high */
382 #ifdef CONFIG_LOGBUFFER
384 /* Prevent initrd from overwriting logbuffer */
385 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
386 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
387 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
391 * Booting a (Linux) kernel image
393 * Allocate space for command line and board info - the
394 * address should be as high as possible within the reach of
395 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
396 * memory, which means far enough below the current stack
400 asm( "mr %0,1": "=r"(sp) : );
402 debug ("## Current stack ends at 0x%08lX ", sp);
404 sp -= 2048; /* just to be sure */
405 if (sp > CFG_BOOTMAPSZ)
409 debug ("=> set upper limit to 0x%08lX\n", sp);
411 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
412 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
414 if ((s = getenv("bootargs")) == NULL)
419 cmd_start = (ulong)&cmdline[0];
420 cmd_end = cmd_start + strlen(cmdline);
425 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
427 do_bdinfo (NULL, 0, 0, NULL);
430 if ((s = getenv ("clocks_in_mhz")) != NULL) {
431 /* convert all clock information to MHz */
432 kbd->bi_intfreq /= 1000000L;
433 kbd->bi_busfreq /= 1000000L;
434 #if defined(CONFIG_8260)
435 kbd->bi_cpmfreq /= 1000000L;
436 kbd->bi_brgfreq /= 1000000L;
437 kbd->bi_sccfreq /= 1000000L;
438 kbd->bi_vco /= 1000000L;
439 #endif /* CONFIG_8260 */
442 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
445 * Check if there is an initrd image
448 SHOW_BOOT_PROGRESS (9);
450 addr = simple_strtoul(argv[2], NULL, 16);
452 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
454 /* Copy header so we can blank CRC field for re-calculation */
455 memmove (&header, (char *)addr, sizeof(image_header_t));
457 if (hdr->ih_magic != IH_MAGIC) {
458 printf ("Bad Magic Number\n");
459 SHOW_BOOT_PROGRESS (-10);
460 do_reset (cmdtp, flag, argc, argv);
463 data = (ulong)&header;
464 len = sizeof(image_header_t);
466 checksum = hdr->ih_hcrc;
469 if (crc32 (0, (char *)data, len) != checksum) {
470 printf ("Bad Header Checksum\n");
471 SHOW_BOOT_PROGRESS (-11);
472 do_reset (cmdtp, flag, argc, argv);
475 SHOW_BOOT_PROGRESS (10);
477 print_image_hdr (hdr);
479 data = addr + sizeof(image_header_t);
484 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
485 ulong cdata = data, edata = cdata + len;
486 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
488 printf (" Verifying Checksum ... ");
490 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
492 while (cdata < edata) {
493 ulong chunk = edata - cdata;
497 csum = crc32 (csum, (char *)cdata, chunk);
502 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
503 csum = crc32 (0, (char *)data, len);
504 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
506 if (csum != hdr->ih_dcrc) {
507 printf ("Bad Data CRC\n");
508 SHOW_BOOT_PROGRESS (-12);
509 do_reset (cmdtp, flag, argc, argv);
514 SHOW_BOOT_PROGRESS (11);
516 if ((hdr->ih_os != IH_OS_LINUX) ||
517 (hdr->ih_arch != IH_CPU_PPC) ||
518 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
519 printf ("No Linux PPC Ramdisk Image\n");
520 SHOW_BOOT_PROGRESS (-13);
521 do_reset (cmdtp, flag, argc, argv);
525 * Now check if we have a multifile image
527 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
528 u_long tail = ntohl(len_ptr[0]) % 4;
531 SHOW_BOOT_PROGRESS (13);
533 /* skip kernel length and terminator */
534 data = (ulong)(&len_ptr[2]);
535 /* skip any additional image length fields */
536 for (i=1; len_ptr[i]; ++i)
538 /* add kernel length, and align */
539 data += ntohl(len_ptr[0]);
544 len = ntohl(len_ptr[1]);
550 SHOW_BOOT_PROGRESS (14);
556 debug ("No initrd\n");
560 initrd_start = (ulong)kbd - len;
561 initrd_start &= ~(4096 - 1); /* align on page */
567 * the inital ramdisk does not need to be within
568 * CFG_BOOTMAPSZ as it is not accessed until after
569 * the mm system is initialised.
571 * do the stack bottom calculation again and see if
572 * the initrd will fit just below the monitor stack
573 * bottom without overwriting the area allocated
574 * above for command line args and board info.
576 asm( "mr %0,1": "=r"(nsp) : );
577 nsp -= 2048; /* just to be sure */
579 if (nsp > initrd_high) /* limit as specified */
582 nsp &= ~(4096 - 1); /* align on page */
587 SHOW_BOOT_PROGRESS (12);
589 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
590 data, data + len - 1, len, len);
592 initrd_end = initrd_start + len;
593 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
594 initrd_start, initrd_end);
595 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
598 void *to = (void *)initrd_start;
599 void *from = (void *)data;
602 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
604 memmove (to, from, tail);
610 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
611 memmove ((void *)initrd_start, (void *)data, len);
612 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
620 debug ("## Transferring control to Linux (at address %08lx) ...\n",
623 SHOW_BOOT_PROGRESS (15);
625 #ifdef CFG_INIT_RAM_LOCK
626 unlock_ram_in_cache();
629 * Linux Kernel Parameters:
630 * r3: ptr to board info data
631 * r4: initrd_start or 0 if no initrd
632 * r5: initrd_end - unused if r4 is 0
633 * r6: Start of command line string
634 * r7: End of command line string
636 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
638 #endif /* CONFIG_PPC */
641 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
642 int argc, char *argv[],
647 DECLARE_GLOBAL_DATA_PTR;
649 image_header_t *hdr = &header;
651 void (*loader)(bd_t *, image_header_t *, char *, char *);
652 image_header_t *img_addr;
658 * Booting a (NetBSD) kernel image
660 * This process is pretty similar to a standalone application:
661 * The (first part of an multi-) image must be a stage-2 loader,
662 * which in turn is responsible for loading & invoking the actual
663 * kernel. The only differences are the parameters being passed:
664 * besides the board info strucure, the loader expects a command
665 * line, the name of the console device, and (optionally) the
666 * address of the original image header.
670 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
671 img_addr = (image_header_t *) addr;
675 #if defined (CONFIG_8xx_CONS_SMC1)
677 #elif defined (CONFIG_8xx_CONS_SMC2)
679 #elif defined (CONFIG_8xx_CONS_SCC2)
681 #elif defined (CONFIG_8xx_CONS_SCC3)
689 for (i=2, len=0 ; i<argc ; i+=1)
690 len += strlen (argv[i]) + 1;
691 cmdline = malloc (len);
693 for (i=2, len=0 ; i<argc ; i+=1) {
695 cmdline[len++] = ' ';
696 strcpy (&cmdline[len], argv[i]);
697 len += strlen (argv[i]);
699 } else if ((cmdline = getenv("bootargs")) == NULL) {
703 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
705 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
708 SHOW_BOOT_PROGRESS (15);
711 * NetBSD Stage-2 Loader Parameters:
712 * r3: ptr to board info data
715 * r6: boot args string
717 (*loader) (gd->bd, img_addr, consdev, cmdline);
720 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
721 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
724 #ifndef CFG_HUSH_PARSER
725 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
727 if (parse_string_outer(getenv("bootcmd"),
728 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
734 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
735 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
742 return image_info (load_addr);
745 for (arg=1; arg <argc; ++arg) {
746 addr = simple_strtoul(argv[arg], NULL, 16);
747 if (image_info (addr) != 0) rcode = 1;
752 static int image_info (ulong addr)
754 ulong data, len, checksum;
755 image_header_t *hdr = &header;
757 printf ("\n## Checking Image at %08lx ...\n", addr);
759 /* Copy header so we can blank CRC field for re-calculation */
760 memmove (&header, (char *)addr, sizeof(image_header_t));
762 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
763 printf (" Bad Magic Number\n");
767 data = (ulong)&header;
768 len = sizeof(image_header_t);
770 checksum = ntohl(hdr->ih_hcrc);
773 if (crc32 (0, (char *)data, len) != checksum) {
774 printf (" Bad Header Checksum\n");
778 /* for multi-file images we need the data part, too */
779 print_image_hdr ((image_header_t *)addr);
781 data = addr + sizeof(image_header_t);
782 len = ntohl(hdr->ih_size);
784 printf (" Verifying Checksum ... ");
785 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
786 printf (" Bad Data CRC\n");
792 #endif /* CFG_CMD_IMI */
795 print_image_hdr (image_header_t *hdr)
797 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
798 time_t timestamp = (time_t)ntohl(hdr->ih_time);
802 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
803 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
804 to_tm (timestamp, &tm);
805 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
806 tm.tm_year, tm.tm_mon, tm.tm_mday,
807 tm.tm_hour, tm.tm_min, tm.tm_sec);
808 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
809 printf (" Image Type: "); print_type(hdr); printf ("\n");
810 printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
811 print_size (ntohl(hdr->ih_size), "\n");
812 printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
813 printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
815 if (hdr->ih_type == IH_TYPE_MULTI) {
818 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
820 printf (" Contents:\n");
821 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
822 printf (" Image %d: %8ld Bytes = ", i, len);
823 print_size (len, "\n");
830 print_type (image_header_t *hdr)
832 char *os, *arch, *type, *comp;
834 switch (hdr->ih_os) {
835 case IH_OS_INVALID: os = "Invalid OS"; break;
836 case IH_OS_NETBSD: os = "NetBSD"; break;
837 case IH_OS_LINUX: os = "Linux"; break;
838 case IH_OS_VXWORKS: os = "VxWorks"; break;
839 case IH_OS_QNX: os = "QNX"; break;
840 case IH_OS_U_BOOT: os = "U-Boot"; break;
841 case IH_OS_RTEMS: os = "RTEMS"; break;
842 default: os = "Unknown OS"; break;
845 switch (hdr->ih_arch) {
846 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
847 case IH_CPU_ALPHA: arch = "Alpha"; break;
848 case IH_CPU_ARM: arch = "ARM"; break;
849 case IH_CPU_I386: arch = "Intel x86"; break;
850 case IH_CPU_IA64: arch = "IA64"; break;
851 case IH_CPU_MIPS: arch = "MIPS"; break;
852 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
853 case IH_CPU_PPC: arch = "PowerPC"; break;
854 case IH_CPU_S390: arch = "IBM S390"; break;
855 case IH_CPU_SH: arch = "SuperH"; break;
856 case IH_CPU_SPARC: arch = "SPARC"; break;
857 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
858 default: arch = "Unknown Architecture"; break;
861 switch (hdr->ih_type) {
862 case IH_TYPE_INVALID: type = "Invalid Image"; break;
863 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
864 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
865 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
866 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
867 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
868 case IH_TYPE_SCRIPT: type = "Script"; break;
869 default: type = "Unknown Image"; break;
872 switch (hdr->ih_comp) {
873 case IH_COMP_NONE: comp = "uncompressed"; break;
874 case IH_COMP_GZIP: comp = "gzip compressed"; break;
875 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
876 default: comp = "unknown compression"; break;
879 printf ("%s %s %s (%s)", arch, os, type, comp);
882 #define ZALLOC_ALIGNMENT 16
884 static void *zalloc(void *x, unsigned items, unsigned size)
889 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
896 static void zfree(void *x, void *addr, unsigned nb)
902 #define EXTRA_FIELD 4
905 #define RESERVED 0xe0
909 int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
917 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
918 printf ("Error: Bad gzipped data\n");
921 if ((flags & EXTRA_FIELD) != 0)
922 i = 12 + src[10] + (src[11] << 8);
923 if ((flags & ORIG_NAME) != 0)
924 while (src[i++] != 0)
926 if ((flags & COMMENT) != 0)
927 while (src[i++] != 0)
929 if ((flags & HEAD_CRC) != 0)
932 printf ("Error: gunzip out of data in header\n");
938 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
939 s.outcb = (cb_func)WATCHDOG_RESET;
942 #endif /* CONFIG_HW_WATCHDOG */
944 r = inflateInit2(&s, -MAX_WBITS);
946 printf ("Error: inflateInit2() returned %d\n", r);
950 s.avail_in = *lenp - i;
952 s.avail_out = dstlen;
953 r = inflate(&s, Z_FINISH);
954 if (r != Z_OK && r != Z_STREAM_END) {
955 printf ("Error: inflate() returned %d\n", r);
958 *lenp = s.next_out - (unsigned char *) dst;
965 do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
966 ulong addr, ulong *len_ptr, int verify)
968 DECLARE_GLOBAL_DATA_PTR;
969 image_header_t *hdr = &header;
970 void (*entry_point)(bd_t *);
972 entry_point = (void (*)(bd_t *)) hdr->ih_ep;
974 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
977 SHOW_BOOT_PROGRESS (15);
981 * r3: ptr to board info data
984 (*entry_point ) ( gd->bd );
987 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
989 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
990 ulong addr, ulong *len_ptr, int verify)
992 image_header_t *hdr = &header;
995 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
996 setenv("loadaddr", str);
997 do_bootvx(cmdtp, 0, 0, NULL);
1001 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1002 ulong addr, ulong *len_ptr, int verify)
1004 image_header_t *hdr = &header;
1005 char *local_args[2];
1008 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1009 local_args[0] = argv[0];
1010 local_args[1] = str; /* and provide it via the arguments */
1011 do_bootelf(cmdtp, 0, 2, local_args);
1013 #endif /* CFG_CMD_ELF */