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 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
102 static boot_os_Fcn do_bootm_vxworks;
103 static boot_os_Fcn do_bootm_qnxelf;
104 int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
105 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
106 #endif /* CFG_CMD_ELF */
108 image_header_t header;
110 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
112 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
116 ulong data, len, checksum;
120 int (*appl)(cmd_tbl_t *, int, int, char *[]);
121 image_header_t *hdr = &header;
123 s = getenv ("verify");
124 verify = (s && (*s == 'n')) ? 0 : 1;
129 addr = simple_strtoul(argv[1], NULL, 16);
132 SHOW_BOOT_PROGRESS (1);
133 printf ("## Booting image at %08lx ...\n", addr);
135 /* Copy header so we can blank CRC field for re-calculation */
136 memmove (&header, (char *)addr, sizeof(image_header_t));
138 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
139 #ifdef __I386__ /* correct image format not implemented yet - fake it */
140 if (fake_header(hdr, (void*)addr, -1) != NULL) {
141 /* to compensate for the addition below */
142 addr -= sizeof(image_header_t);
144 * fake_header() does not fake the data crc
148 #endif /* __I386__ */
150 printf ("Bad Magic Number\n");
151 SHOW_BOOT_PROGRESS (-1);
155 SHOW_BOOT_PROGRESS (2);
157 data = (ulong)&header;
158 len = sizeof(image_header_t);
160 checksum = ntohl(hdr->ih_hcrc);
163 if (crc32 (0, (char *)data, len) != checksum) {
164 printf ("Bad Header Checksum\n");
165 SHOW_BOOT_PROGRESS (-2);
168 SHOW_BOOT_PROGRESS (3);
170 /* for multi-file images we need the data part, too */
171 print_image_hdr (hdr);
173 data = addr + sizeof(image_header_t);
174 len = ntohl(hdr->ih_size);
177 printf (" Verifying Checksum ... ");
178 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
179 printf ("Bad Data CRC\n");
180 SHOW_BOOT_PROGRESS (-3);
185 SHOW_BOOT_PROGRESS (4);
187 len_ptr = (ulong *)data;
190 if (hdr->ih_arch != IH_CPU_PPC)
191 #elif defined(__ARM__)
192 if (hdr->ih_arch != IH_CPU_ARM)
193 #elif defined(__I386__)
194 if (hdr->ih_arch != IH_CPU_I386)
195 #elif defined(__mips__)
196 if (hdr->ih_arch != IH_CPU_MIPS)
198 # error Unknown CPU type
201 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
202 SHOW_BOOT_PROGRESS (-4);
205 SHOW_BOOT_PROGRESS (5);
207 switch (hdr->ih_type) {
208 case IH_TYPE_STANDALONE: name = "Standalone Application";
210 case IH_TYPE_KERNEL: name = "Kernel Image";
212 case IH_TYPE_MULTI: name = "Multi-File Image";
213 len = ntohl(len_ptr[0]);
214 /* OS kernel is always the first image */
215 data += 8; /* kernel_len + terminator */
216 for (i=1; len_ptr[i]; ++i)
219 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
220 SHOW_BOOT_PROGRESS (-5);
223 SHOW_BOOT_PROGRESS (6);
226 * We have reached the point of no return: we are going to
227 * overwrite all exception vector code, so we cannot easily
228 * recover from any failures any more...
231 iflag = disable_interrupts();
233 #ifdef CONFIG_AMIGAONEG3SE
235 * We've possible left the caches enabled during
236 * bios emulation, so turn them off again
239 invalidate_l1_instruction_cache();
244 switch (hdr->ih_comp) {
246 if(ntohl(hdr->ih_load) == addr) {
247 printf (" XIP %s ... ", name);
249 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
251 void *to = (void *)ntohl(hdr->ih_load);
252 void *from = (void *)data;
254 printf (" Loading %s ... ", name);
257 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
259 memmove (to, from, tail);
264 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
265 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
266 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
270 printf (" Uncompressing %s ... ", name);
271 if (gunzip ((void *)ntohl(hdr->ih_load), 0x400000,
272 (uchar *)data, (int *)&len) != 0) {
273 printf ("GUNZIP ERROR - must RESET board to recover\n");
274 SHOW_BOOT_PROGRESS (-6);
275 do_reset (cmdtp, flag, argc, argv);
281 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
282 SHOW_BOOT_PROGRESS (-7);
286 SHOW_BOOT_PROGRESS (7);
288 switch (hdr->ih_type) {
289 case IH_TYPE_STANDALONE:
293 /* load (and uncompress), but don't start if "autostart"
296 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0))
298 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
299 (*appl)(cmdtp, flag, argc-1, &argv[1]);
308 printf ("Can't boot image type %d\n", hdr->ih_type);
309 SHOW_BOOT_PROGRESS (-8);
312 SHOW_BOOT_PROGRESS (8);
314 switch (hdr->ih_os) {
315 default: /* handled by (original) Linux case */
317 do_bootm_linux (cmdtp, flag, argc, argv,
318 addr, len_ptr, verify);
321 do_bootm_netbsd (cmdtp, flag, argc, argv,
322 addr, len_ptr, verify);
324 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
326 do_bootm_vxworks (cmdtp, flag, argc, argv,
327 addr, len_ptr, verify);
330 do_bootm_qnxelf (cmdtp, flag, argc, argv,
331 addr, len_ptr, verify);
333 #endif /* CFG_CMD_ELF */
336 SHOW_BOOT_PROGRESS (-9);
338 printf ("\n## Control returned to monitor - resetting...\n");
339 do_reset (cmdtp, flag, argc, argv);
346 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
347 int argc, char *argv[],
352 DECLARE_GLOBAL_DATA_PTR;
356 ulong initrd_start, initrd_end;
357 ulong cmd_start, cmd_end;
363 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
364 image_header_t *hdr = &header;
366 if ((s = getenv ("initrd_high")) != NULL) {
367 /* a value of "no" or a similar string will act like 0,
368 * turning the "load high" feature off. This is intentional.
370 initrd_high = simple_strtoul(s, NULL, 16);
371 } else { /* not set, no restrictions to load high */
375 #ifdef CONFIG_LOGBUFFER
377 /* Prevent initrd from overwriting logbuffer */
378 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
379 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
380 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
384 * Booting a (Linux) kernel image
386 * Allocate space for command line and board info - the
387 * address should be as high as possible within the reach of
388 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
389 * memory, which means far enough below the current stack
393 asm( "mr %0,1": "=r"(sp) : );
395 debug ("## Current stack ends at 0x%08lX ", sp);
397 sp -= 2048; /* just to be sure */
398 if (sp > CFG_BOOTMAPSZ)
402 debug ("=> set upper limit to 0x%08lX\n", sp);
404 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
405 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
407 if ((s = getenv("bootargs")) == NULL)
412 cmd_start = (ulong)&cmdline[0];
413 cmd_end = cmd_start + strlen(cmdline);
418 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
420 do_bdinfo (NULL, 0, 0, NULL);
423 if ((s = getenv ("clocks_in_mhz")) != NULL) {
424 /* convert all clock information to MHz */
425 kbd->bi_intfreq /= 1000000L;
426 kbd->bi_busfreq /= 1000000L;
427 #if defined(CONFIG_8260)
428 kbd->bi_cpmfreq /= 1000000L;
429 kbd->bi_brgfreq /= 1000000L;
430 kbd->bi_sccfreq /= 1000000L;
431 kbd->bi_vco /= 1000000L;
432 #endif /* CONFIG_8260 */
435 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
438 * Check if there is an initrd image
441 SHOW_BOOT_PROGRESS (9);
443 addr = simple_strtoul(argv[2], NULL, 16);
445 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
447 /* Copy header so we can blank CRC field for re-calculation */
448 memmove (&header, (char *)addr, sizeof(image_header_t));
450 if (hdr->ih_magic != IH_MAGIC) {
451 printf ("Bad Magic Number\n");
452 SHOW_BOOT_PROGRESS (-10);
453 do_reset (cmdtp, flag, argc, argv);
456 data = (ulong)&header;
457 len = sizeof(image_header_t);
459 checksum = hdr->ih_hcrc;
462 if (crc32 (0, (char *)data, len) != checksum) {
463 printf ("Bad Header Checksum\n");
464 SHOW_BOOT_PROGRESS (-11);
465 do_reset (cmdtp, flag, argc, argv);
468 SHOW_BOOT_PROGRESS (10);
470 print_image_hdr (hdr);
472 data = addr + sizeof(image_header_t);
477 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
478 ulong cdata = data, edata = cdata + len;
479 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
481 printf (" Verifying Checksum ... ");
483 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
485 while (cdata < edata) {
486 ulong chunk = edata - cdata;
490 csum = crc32 (csum, (char *)cdata, chunk);
495 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
496 csum = crc32 (0, (char *)data, len);
497 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
499 if (csum != hdr->ih_dcrc) {
500 printf ("Bad Data CRC\n");
501 SHOW_BOOT_PROGRESS (-12);
502 do_reset (cmdtp, flag, argc, argv);
507 SHOW_BOOT_PROGRESS (11);
509 if ((hdr->ih_os != IH_OS_LINUX) ||
510 (hdr->ih_arch != IH_CPU_PPC) ||
511 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
512 printf ("No Linux PPC Ramdisk Image\n");
513 SHOW_BOOT_PROGRESS (-13);
514 do_reset (cmdtp, flag, argc, argv);
518 * Now check if we have a multifile image
520 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
521 u_long tail = ntohl(len_ptr[0]) % 4;
524 SHOW_BOOT_PROGRESS (13);
526 /* skip kernel length and terminator */
527 data = (ulong)(&len_ptr[2]);
528 /* skip any additional image length fields */
529 for (i=1; len_ptr[i]; ++i)
531 /* add kernel length, and align */
532 data += ntohl(len_ptr[0]);
537 len = ntohl(len_ptr[1]);
543 SHOW_BOOT_PROGRESS (14);
549 debug ("No initrd\n");
553 initrd_start = (ulong)kbd - len;
554 initrd_start &= ~(4096 - 1); /* align on page */
560 * the inital ramdisk does not need to be within
561 * CFG_BOOTMAPSZ as it is not accessed until after
562 * the mm system is initialised.
564 * do the stack bottom calculation again and see if
565 * the initrd will fit just below the monitor stack
566 * bottom without overwriting the area allocated
567 * above for command line args and board info.
569 asm( "mr %0,1": "=r"(nsp) : );
570 nsp -= 2048; /* just to be sure */
572 if (nsp > initrd_high) /* limit as specified */
575 nsp &= ~(4096 - 1); /* align on page */
580 SHOW_BOOT_PROGRESS (12);
582 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
583 data, data + len - 1, len, len);
585 initrd_end = initrd_start + len;
586 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
587 initrd_start, initrd_end);
588 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
591 void *to = (void *)initrd_start;
592 void *from = (void *)data;
595 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
597 memmove (to, from, tail);
603 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
604 memmove ((void *)initrd_start, (void *)data, len);
605 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
613 debug ("## Transferring control to Linux (at address %08lx) ...\n",
616 SHOW_BOOT_PROGRESS (15);
618 #ifdef CFG_INIT_RAM_LOCK
619 unlock_ram_in_cache();
622 * Linux Kernel Parameters:
623 * r3: ptr to board info data
624 * r4: initrd_start or 0 if no initrd
625 * r5: initrd_end - unused if r4 is 0
626 * r6: Start of command line string
627 * r7: End of command line string
629 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
631 #endif /* CONFIG_PPC */
634 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
635 int argc, char *argv[],
640 DECLARE_GLOBAL_DATA_PTR;
642 image_header_t *hdr = &header;
644 void (*loader)(bd_t *, image_header_t *, char *, char *);
645 image_header_t *img_addr;
651 * Booting a (NetBSD) kernel image
653 * This process is pretty similar to a standalone application:
654 * The (first part of an multi-) image must be a stage-2 loader,
655 * which in turn is responsible for loading & invoking the actual
656 * kernel. The only differences are the parameters being passed:
657 * besides the board info strucure, the loader expects a command
658 * line, the name of the console device, and (optionally) the
659 * address of the original image header.
663 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
664 img_addr = (image_header_t *) addr;
668 #if defined (CONFIG_8xx_CONS_SMC1)
670 #elif defined (CONFIG_8xx_CONS_SMC2)
672 #elif defined (CONFIG_8xx_CONS_SCC2)
674 #elif defined (CONFIG_8xx_CONS_SCC3)
682 for (i=2, len=0 ; i<argc ; i+=1)
683 len += strlen (argv[i]) + 1;
684 cmdline = malloc (len);
686 for (i=2, len=0 ; i<argc ; i+=1) {
688 cmdline[len++] = ' ';
689 strcpy (&cmdline[len], argv[i]);
690 len += strlen (argv[i]);
692 } else if ((cmdline = getenv("bootargs")) == NULL) {
696 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
698 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
701 SHOW_BOOT_PROGRESS (15);
704 * NetBSD Stage-2 Loader Parameters:
705 * r3: ptr to board info data
708 * r6: boot args string
710 (*loader) (gd->bd, img_addr, consdev, cmdline);
713 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
714 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
717 #ifndef CFG_HUSH_PARSER
718 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
720 if (parse_string_outer(getenv("bootcmd"),
721 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
727 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
728 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
735 return image_info (load_addr);
738 for (arg=1; arg <argc; ++arg) {
739 addr = simple_strtoul(argv[arg], NULL, 16);
740 if (image_info (addr) != 0) rcode = 1;
745 static int image_info (ulong addr)
747 ulong data, len, checksum;
748 image_header_t *hdr = &header;
750 printf ("\n## Checking Image at %08lx ...\n", addr);
752 /* Copy header so we can blank CRC field for re-calculation */
753 memmove (&header, (char *)addr, sizeof(image_header_t));
755 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
756 printf (" Bad Magic Number\n");
760 data = (ulong)&header;
761 len = sizeof(image_header_t);
763 checksum = ntohl(hdr->ih_hcrc);
766 if (crc32 (0, (char *)data, len) != checksum) {
767 printf (" Bad Header Checksum\n");
771 /* for multi-file images we need the data part, too */
772 print_image_hdr ((image_header_t *)addr);
774 data = addr + sizeof(image_header_t);
775 len = ntohl(hdr->ih_size);
777 printf (" Verifying Checksum ... ");
778 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
779 printf (" Bad Data CRC\n");
785 #endif /* CFG_CMD_IMI */
788 print_image_hdr (image_header_t *hdr)
790 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
791 time_t timestamp = (time_t)ntohl(hdr->ih_time);
795 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
796 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
797 to_tm (timestamp, &tm);
798 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
799 tm.tm_year, tm.tm_mon, tm.tm_mday,
800 tm.tm_hour, tm.tm_min, tm.tm_sec);
801 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
802 printf (" Image Type: "); print_type(hdr); printf ("\n");
803 printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
804 print_size (ntohl(hdr->ih_size), "\n");
805 printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
806 printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
808 if (hdr->ih_type == IH_TYPE_MULTI) {
811 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
813 printf (" Contents:\n");
814 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
815 printf (" Image %d: %8ld Bytes = ", i, len);
816 print_size (len, "\n");
823 print_type (image_header_t *hdr)
825 char *os, *arch, *type, *comp;
827 switch (hdr->ih_os) {
828 case IH_OS_INVALID: os = "Invalid OS"; break;
829 case IH_OS_NETBSD: os = "NetBSD"; break;
830 case IH_OS_LINUX: os = "Linux"; break;
831 case IH_OS_VXWORKS: os = "VxWorks"; break;
832 case IH_OS_QNX: os = "QNX"; break;
833 case IH_OS_U_BOOT: os = "U-Boot"; break;
834 default: os = "Unknown OS"; break;
837 switch (hdr->ih_arch) {
838 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
839 case IH_CPU_ALPHA: arch = "Alpha"; break;
840 case IH_CPU_ARM: arch = "ARM"; break;
841 case IH_CPU_I386: arch = "Intel x86"; break;
842 case IH_CPU_IA64: arch = "IA64"; break;
843 case IH_CPU_MIPS: arch = "MIPS"; break;
844 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
845 case IH_CPU_PPC: arch = "PowerPC"; break;
846 case IH_CPU_S390: arch = "IBM S390"; break;
847 case IH_CPU_SH: arch = "SuperH"; break;
848 case IH_CPU_SPARC: arch = "SPARC"; break;
849 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
850 default: arch = "Unknown Architecture"; break;
853 switch (hdr->ih_type) {
854 case IH_TYPE_INVALID: type = "Invalid Image"; break;
855 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
856 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
857 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
858 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
859 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
860 case IH_TYPE_SCRIPT: type = "Script"; break;
861 default: type = "Unknown Image"; break;
864 switch (hdr->ih_comp) {
865 case IH_COMP_NONE: comp = "uncompressed"; break;
866 case IH_COMP_GZIP: comp = "gzip compressed"; break;
867 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
868 default: comp = "unknown compression"; break;
871 printf ("%s %s %s (%s)", arch, os, type, comp);
874 #define ZALLOC_ALIGNMENT 16
876 static void *zalloc(void *x, unsigned items, unsigned size)
881 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
888 static void zfree(void *x, void *addr, unsigned nb)
894 #define EXTRA_FIELD 4
897 #define RESERVED 0xe0
901 int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
909 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
910 printf ("Error: Bad gzipped data\n");
913 if ((flags & EXTRA_FIELD) != 0)
914 i = 12 + src[10] + (src[11] << 8);
915 if ((flags & ORIG_NAME) != 0)
916 while (src[i++] != 0)
918 if ((flags & COMMENT) != 0)
919 while (src[i++] != 0)
921 if ((flags & HEAD_CRC) != 0)
924 printf ("Error: gunzip out of data in header\n");
930 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
931 s.outcb = (cb_func)WATCHDOG_RESET;
934 #endif /* CONFIG_HW_WATCHDOG */
936 r = inflateInit2(&s, -MAX_WBITS);
938 printf ("Error: inflateInit2() returned %d\n", r);
942 s.avail_in = *lenp - i;
944 s.avail_out = dstlen;
945 r = inflate(&s, Z_FINISH);
946 if (r != Z_OK && r != Z_STREAM_END) {
947 printf ("Error: inflate() returned %d\n", r);
950 *lenp = s.next_out - (unsigned char *) dst;
956 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
958 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
959 ulong addr, ulong *len_ptr, int verify)
961 image_header_t *hdr = &header;
964 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
965 setenv("loadaddr", str);
966 do_bootvx(cmdtp, 0, 0, NULL);
970 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
971 ulong addr, ulong *len_ptr, int verify)
973 image_header_t *hdr = &header;
977 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
978 local_args[0] = argv[0];
979 local_args[1] = str; /* and provide it via the arguments */
980 do_bootelf(cmdtp, 0, 2, local_args);
982 #endif /* CFG_CMD_ELF */