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>
55 * Some systems (for example LWMON) have very short watchdog periods;
56 * we must make sure to split long operations like memmove() or
57 * crc32() into reasonable chunks.
59 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
60 # define CHUNKSZ (64 * 1024)
63 int gunzip (void *, int, unsigned char *, int *);
65 static void *zalloc(void *, unsigned, unsigned);
66 static void zfree(void *, void *, unsigned);
68 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
69 static int image_info (unsigned long addr);
71 static void print_type (image_header_t *hdr);
74 image_header_t *fake_header(image_header_t *hdr, void *ptr, int size);
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.
85 typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag,
86 int argc, char *argv[],
87 ulong addr, /* of image to boot */
88 ulong *len_ptr, /* multi-file image length table */
89 int verify); /* getenv("verify")[0] != 'n' */
92 static boot_os_Fcn do_bootm_linux;
94 extern boot_os_Fcn do_bootm_linux;
96 static boot_os_Fcn do_bootm_netbsd;
97 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
98 static boot_os_Fcn do_bootm_vxworks;
99 static boot_os_Fcn do_bootm_qnxelf;
100 int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
101 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
102 #endif /* CFG_CMD_ELF */
104 image_header_t header;
106 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
108 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
112 ulong data, len, checksum;
116 int (*appl)(cmd_tbl_t *, int, int, char *[]);
117 image_header_t *hdr = &header;
119 s = getenv ("verify");
120 verify = (s && (*s == 'n')) ? 0 : 1;
125 addr = simple_strtoul(argv[1], NULL, 16);
128 SHOW_BOOT_PROGRESS (1);
129 printf ("## Booting image at %08lx ...\n", addr);
131 /* Copy header so we can blank CRC field for re-calculation */
132 memmove (&header, (char *)addr, sizeof(image_header_t));
134 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
135 #ifdef __I386__ /* correct image format not implemented yet - fake it */
136 if (fake_header(hdr, (void*)addr, -1) != NULL) {
137 /* to compensate for the addition below */
138 addr -= sizeof(image_header_t);
140 * fake_header() does not fake the data crc
144 #endif /* __I386__ */
146 printf ("Bad Magic Number\n");
147 SHOW_BOOT_PROGRESS (-1);
151 SHOW_BOOT_PROGRESS (2);
153 data = (ulong)&header;
154 len = sizeof(image_header_t);
156 checksum = ntohl(hdr->ih_hcrc);
159 if (crc32 (0, (char *)data, len) != checksum) {
160 printf ("Bad Header Checksum\n");
161 SHOW_BOOT_PROGRESS (-2);
164 SHOW_BOOT_PROGRESS (3);
166 /* for multi-file images we need the data part, too */
167 print_image_hdr (hdr);
169 data = addr + sizeof(image_header_t);
170 len = ntohl(hdr->ih_size);
173 printf (" Verifying Checksum ... ");
174 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
175 printf ("Bad Data CRC\n");
176 SHOW_BOOT_PROGRESS (-3);
181 SHOW_BOOT_PROGRESS (4);
183 len_ptr = (ulong *)data;
186 if (hdr->ih_arch != IH_CPU_PPC)
187 #elif defined(__ARM__)
188 if (hdr->ih_arch != IH_CPU_ARM)
189 #elif defined(__I386__)
190 if (hdr->ih_arch != IH_CPU_I386)
192 # error Unknown CPU type
195 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
196 SHOW_BOOT_PROGRESS (-4);
199 SHOW_BOOT_PROGRESS (5);
201 switch (hdr->ih_type) {
202 case IH_TYPE_STANDALONE: name = "Standalone Application";
204 case IH_TYPE_KERNEL: name = "Kernel Image";
206 case IH_TYPE_MULTI: name = "Multi-File Image";
207 len = ntohl(len_ptr[0]);
208 /* OS kernel is always the first image */
209 data += 8; /* kernel_len + terminator */
210 for (i=1; len_ptr[i]; ++i)
213 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
214 SHOW_BOOT_PROGRESS (-5);
217 SHOW_BOOT_PROGRESS (6);
220 * We have reached the point of no return: we are going to
221 * overwrite all exception vector code, so we cannot easily
222 * recover from any failures any more...
225 iflag = disable_interrupts();
227 switch (hdr->ih_comp) {
229 if(ntohl(hdr->ih_load) == addr) {
230 printf (" XIP %s ... ", name);
232 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
234 void *to = (void *)ntohl(hdr->ih_load);
235 void *from = (void *)data;
237 printf (" Loading %s ... ", name);
240 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
242 memmove (to, from, tail);
247 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
248 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
249 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
253 printf (" Uncompressing %s ... ", name);
254 if (gunzip ((void *)ntohl(hdr->ih_load), 0x400000,
255 (uchar *)data, (int *)&len) != 0) {
256 printf ("GUNZIP ERROR - must RESET board to recover\n");
257 SHOW_BOOT_PROGRESS (-6);
258 do_reset (cmdtp, flag, argc, argv);
264 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
265 SHOW_BOOT_PROGRESS (-7);
269 SHOW_BOOT_PROGRESS (7);
271 switch (hdr->ih_type) {
272 case IH_TYPE_STANDALONE:
273 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
277 (*appl)(cmdtp, flag, argc-1, &argv[1]);
286 printf ("Can't boot image type %d\n", hdr->ih_type);
287 SHOW_BOOT_PROGRESS (-8);
290 SHOW_BOOT_PROGRESS (8);
292 switch (hdr->ih_os) {
293 default: /* handled by (original) Linux case */
295 do_bootm_linux (cmdtp, flag, argc, argv,
296 addr, len_ptr, verify);
299 do_bootm_netbsd (cmdtp, flag, argc, argv,
300 addr, len_ptr, verify);
302 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
304 do_bootm_vxworks (cmdtp, flag, argc, argv,
305 addr, len_ptr, verify);
308 do_bootm_qnxelf (cmdtp, flag, argc, argv,
309 addr, len_ptr, verify);
311 #endif /* CFG_CMD_ELF */
314 SHOW_BOOT_PROGRESS (-9);
316 printf ("\n## Control returned to monitor - resetting...\n");
317 do_reset (cmdtp, flag, argc, argv);
324 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
325 int argc, char *argv[],
330 DECLARE_GLOBAL_DATA_PTR;
334 ulong initrd_start, initrd_end;
335 ulong cmd_start, cmd_end;
341 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
342 image_header_t *hdr = &header;
344 if ((s = getenv ("initrd_high")) != NULL) {
345 /* a value of "no" or a similar string will act like 0,
346 * turning the "load high" feature off. This is intentional.
348 initrd_high = simple_strtoul(s, NULL, 16);
349 } else { /* not set, no restrictions to load high */
353 #ifdef CONFIG_LOGBUFFER
355 if ((s = getenv ("logstart")) != NULL) {
356 kbd->bi_sramstart = simple_strtoul(s, NULL, 16);
357 /* Prevent initrd from overwriting logbuffer */
358 if (initrd_high < kbd->bi_sramstart)
359 initrd_high = kbd->bi_sramstart-1024;
361 debug ("## Logbuffer at 0x%08lX ", kbd->bi_sramstart);
365 * Booting a (Linux) kernel image
367 * Allocate space for command line and board info - the
368 * address should be as high as possible within the reach of
369 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
370 * memory, which means far enough below the current stack
374 asm( "mr %0,1": "=r"(sp) : );
376 debug ("## Current stack ends at 0x%08lX ", sp);
378 sp -= 2048; /* just to be sure */
379 if (sp > CFG_BOOTMAPSZ)
383 debug ("=> set upper limit to 0x%08lX\n", sp);
385 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
386 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
388 if ((s = getenv("bootargs")) == NULL)
393 cmd_start = (ulong)&cmdline[0];
394 cmd_end = cmd_start + strlen(cmdline);
399 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
401 do_bdinfo (NULL, 0, 0, NULL);
404 if ((s = getenv ("clocks_in_mhz")) != NULL) {
405 /* convert all clock information to MHz */
406 kbd->bi_intfreq /= 1000000L;
407 kbd->bi_busfreq /= 1000000L;
408 #if defined(CONFIG_8260)
409 kbd->bi_cpmfreq /= 1000000L;
410 kbd->bi_brgfreq /= 1000000L;
411 kbd->bi_sccfreq /= 1000000L;
412 kbd->bi_vco /= 1000000L;
413 #endif /* CONFIG_8260 */
416 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
419 * Check if there is an initrd image
422 SHOW_BOOT_PROGRESS (9);
424 addr = simple_strtoul(argv[2], NULL, 16);
426 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
428 /* Copy header so we can blank CRC field for re-calculation */
429 memmove (&header, (char *)addr, sizeof(image_header_t));
431 if (hdr->ih_magic != IH_MAGIC) {
432 printf ("Bad Magic Number\n");
433 SHOW_BOOT_PROGRESS (-10);
434 do_reset (cmdtp, flag, argc, argv);
437 data = (ulong)&header;
438 len = sizeof(image_header_t);
440 checksum = hdr->ih_hcrc;
443 if (crc32 (0, (char *)data, len) != checksum) {
444 printf ("Bad Header Checksum\n");
445 SHOW_BOOT_PROGRESS (-11);
446 do_reset (cmdtp, flag, argc, argv);
449 SHOW_BOOT_PROGRESS (10);
451 print_image_hdr (hdr);
453 data = addr + sizeof(image_header_t);
458 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
459 ulong cdata = data, edata = cdata + len;
460 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
462 printf (" Verifying Checksum ... ");
464 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
466 while (cdata < edata) {
467 ulong chunk = edata - cdata;
471 csum = crc32 (csum, (char *)cdata, chunk);
476 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
477 csum = crc32 (0, (char *)data, len);
478 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
480 if (csum != hdr->ih_dcrc) {
481 printf ("Bad Data CRC\n");
482 SHOW_BOOT_PROGRESS (-12);
483 do_reset (cmdtp, flag, argc, argv);
488 SHOW_BOOT_PROGRESS (11);
490 if ((hdr->ih_os != IH_OS_LINUX) ||
491 (hdr->ih_arch != IH_CPU_PPC) ||
492 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
493 printf ("No Linux PPC Ramdisk Image\n");
494 SHOW_BOOT_PROGRESS (-13);
495 do_reset (cmdtp, flag, argc, argv);
499 * Now check if we have a multifile image
501 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
502 u_long tail = ntohl(len_ptr[0]) % 4;
505 SHOW_BOOT_PROGRESS (13);
507 /* skip kernel length and terminator */
508 data = (ulong)(&len_ptr[2]);
509 /* skip any additional image length fields */
510 for (i=1; len_ptr[i]; ++i)
512 /* add kernel length, and align */
513 data += ntohl(len_ptr[0]);
518 len = ntohl(len_ptr[1]);
524 SHOW_BOOT_PROGRESS (14);
530 debug ("No initrd\n");
534 initrd_start = (ulong)kbd - len;
535 initrd_start &= ~(4096 - 1); /* align on page */
541 * the inital ramdisk does not need to be within
542 * CFG_BOOTMAPSZ as it is not accessed until after
543 * the mm system is initialised.
545 * do the stack bottom calculation again and see if
546 * the initrd will fit just below the monitor stack
547 * bottom without overwriting the area allocated
548 * above for command line args and board info.
550 asm( "mr %0,1": "=r"(nsp) : );
551 nsp -= 2048; /* just to be sure */
553 if (nsp > initrd_high) /* limit as specified */
556 nsp &= ~(4096 - 1); /* align on page */
561 SHOW_BOOT_PROGRESS (12);
563 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
564 data, data + len - 1, len, len);
566 initrd_end = initrd_start + len;
567 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
568 initrd_start, initrd_end);
569 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
572 void *to = (void *)initrd_start;
573 void *from = (void *)data;
576 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
578 memmove (to, from, tail);
584 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
585 memmove ((void *)initrd_start, (void *)data, len);
586 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
594 debug ("## Transferring control to Linux (at address %08lx) ...\n",
597 SHOW_BOOT_PROGRESS (15);
599 #ifdef CFG_INIT_RAM_LOCK
600 unlock_ram_in_cache();
603 * Linux Kernel Parameters:
604 * r3: ptr to board info data
605 * r4: initrd_start or 0 if no initrd
606 * r5: initrd_end - unused if r4 is 0
607 * r6: Start of command line string
608 * r7: End of command line string
610 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
612 #endif /* CONFIG_ARM */
615 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
616 int argc, char *argv[],
621 DECLARE_GLOBAL_DATA_PTR;
623 image_header_t *hdr = &header;
625 void (*loader)(bd_t *, image_header_t *, char *, char *);
626 image_header_t *img_addr;
632 * Booting a (NetBSD) kernel image
634 * This process is pretty similar to a standalone application:
635 * The (first part of an multi-) image must be a stage-2 loader,
636 * which in turn is responsible for loading & invoking the actual
637 * kernel. The only differences are the parameters being passed:
638 * besides the board info strucure, the loader expects a command
639 * line, the name of the console device, and (optionally) the
640 * address of the original image header.
644 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
645 img_addr = (image_header_t *) addr;
649 #if defined (CONFIG_8xx_CONS_SMC1)
651 #elif defined (CONFIG_8xx_CONS_SMC2)
653 #elif defined (CONFIG_8xx_CONS_SCC2)
655 #elif defined (CONFIG_8xx_CONS_SCC3)
663 for (i=2, len=0 ; i<argc ; i+=1)
664 len += strlen (argv[i]) + 1;
665 cmdline = malloc (len);
667 for (i=2, len=0 ; i<argc ; i+=1) {
669 cmdline[len++] = ' ';
670 strcpy (&cmdline[len], argv[i]);
671 len += strlen (argv[i]);
673 } else if ((cmdline = getenv("bootargs")) == NULL) {
677 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
679 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
682 SHOW_BOOT_PROGRESS (15);
685 * NetBSD Stage-2 Loader Parameters:
686 * r3: ptr to board info data
689 * r6: boot args string
691 (*loader) (gd->bd, img_addr, consdev, cmdline);
694 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
695 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
698 #ifndef CFG_HUSH_PARSER
699 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
701 if (parse_string_outer(getenv("bootcmd"),
702 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
708 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
709 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
716 return image_info (load_addr);
719 for (arg=1; arg <argc; ++arg) {
720 addr = simple_strtoul(argv[arg], NULL, 16);
721 if (image_info (addr) != 0) rcode = 1;
726 static int image_info (ulong addr)
728 ulong data, len, checksum;
729 image_header_t *hdr = &header;
731 printf ("\n## Checking Image at %08lx ...\n", addr);
733 /* Copy header so we can blank CRC field for re-calculation */
734 memmove (&header, (char *)addr, sizeof(image_header_t));
736 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
737 printf (" Bad Magic Number\n");
741 data = (ulong)&header;
742 len = sizeof(image_header_t);
744 checksum = ntohl(hdr->ih_hcrc);
747 if (crc32 (0, (char *)data, len) != checksum) {
748 printf (" Bad Header Checksum\n");
752 /* for multi-file images we need the data part, too */
753 print_image_hdr ((image_header_t *)addr);
755 data = addr + sizeof(image_header_t);
756 len = ntohl(hdr->ih_size);
758 printf (" Verifying Checksum ... ");
759 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
760 printf (" Bad Data CRC\n");
766 #endif /* CFG_CMD_IMI */
769 print_image_hdr (image_header_t *hdr)
771 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
772 time_t timestamp = (time_t)ntohl(hdr->ih_time);
776 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
777 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
778 to_tm (timestamp, &tm);
779 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
780 tm.tm_year, tm.tm_mon, tm.tm_mday,
781 tm.tm_hour, tm.tm_min, tm.tm_sec);
782 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
783 printf (" Image Type: "); print_type(hdr); printf ("\n");
784 printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
785 print_size (ntohl(hdr->ih_size), "\n");
786 printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
787 printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
789 if (hdr->ih_type == IH_TYPE_MULTI) {
792 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
794 printf (" Contents:\n");
795 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
796 printf (" Image %d: %8ld Bytes = ", i, len);
797 print_size (len, "\n");
804 print_type (image_header_t *hdr)
806 char *os, *arch, *type, *comp;
808 switch (hdr->ih_os) {
809 case IH_OS_INVALID: os = "Invalid OS"; break;
810 case IH_OS_NETBSD: os = "NetBSD"; break;
811 case IH_OS_LINUX: os = "Linux"; break;
812 case IH_OS_VXWORKS: os = "VxWorks"; break;
813 case IH_OS_QNX: os = "QNX"; break;
814 case IH_OS_U_BOOT: os = "U-Boot"; break;
815 default: os = "Unknown OS"; break;
818 switch (hdr->ih_arch) {
819 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
820 case IH_CPU_ALPHA: arch = "Alpha"; break;
821 case IH_CPU_ARM: arch = "ARM"; break;
822 case IH_CPU_I386: arch = "Intel x86"; break;
823 case IH_CPU_IA64: arch = "IA64"; break;
824 case IH_CPU_MIPS: arch = "MIPS"; break;
825 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
826 case IH_CPU_PPC: arch = "PowerPC"; break;
827 case IH_CPU_S390: arch = "IBM S390"; break;
828 case IH_CPU_SH: arch = "SuperH"; break;
829 case IH_CPU_SPARC: arch = "SPARC"; break;
830 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
831 default: arch = "Unknown Architecture"; break;
834 switch (hdr->ih_type) {
835 case IH_TYPE_INVALID: type = "Invalid Image"; break;
836 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
837 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
838 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
839 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
840 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
841 case IH_TYPE_SCRIPT: type = "Script"; break;
842 default: type = "Unknown Image"; break;
845 switch (hdr->ih_comp) {
846 case IH_COMP_NONE: comp = "uncompressed"; break;
847 case IH_COMP_GZIP: comp = "gzip compressed"; break;
848 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
849 default: comp = "unknown compression"; break;
852 printf ("%s %s %s (%s)", arch, os, type, comp);
855 #define ZALLOC_ALIGNMENT 16
857 static void *zalloc(void *x, unsigned items, unsigned size)
862 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
869 static void zfree(void *x, void *addr, unsigned nb)
875 #define EXTRA_FIELD 4
878 #define RESERVED 0xe0
882 int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
890 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
891 printf ("Error: Bad gzipped data\n");
894 if ((flags & EXTRA_FIELD) != 0)
895 i = 12 + src[10] + (src[11] << 8);
896 if ((flags & ORIG_NAME) != 0)
897 while (src[i++] != 0)
899 if ((flags & COMMENT) != 0)
900 while (src[i++] != 0)
902 if ((flags & HEAD_CRC) != 0)
905 printf ("Error: gunzip out of data in header\n");
911 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
912 s.outcb = (cb_func)WATCHDOG_RESET;
915 #endif /* CONFIG_HW_WATCHDOG */
917 r = inflateInit2(&s, -MAX_WBITS);
919 printf ("Error: inflateInit2() returned %d\n", r);
923 s.avail_in = *lenp - i;
925 s.avail_out = dstlen;
926 r = inflate(&s, Z_FINISH);
927 if (r != Z_OK && r != Z_STREAM_END) {
928 printf ("Error: inflate() returned %d\n", r);
931 *lenp = s.next_out - (unsigned char *) dst;
937 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
939 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
940 ulong addr, ulong *len_ptr, int verify)
942 image_header_t *hdr = &header;
945 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
946 setenv("loadaddr", str);
947 do_bootvx(cmdtp, 0, 0, NULL);
951 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
952 ulong addr, ulong *len_ptr, int verify)
954 image_header_t *hdr = &header;
958 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
959 local_args[0] = argv[0];
960 local_args[1] = str; /* and provide it via the arguments */
961 do_bootelf(cmdtp, 0, 2, local_args);
963 #endif /* CFG_CMD_ELF */