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 * Continue booting an OS image; caller already has:
75 * - copied image header to global variable `header'
76 * - checked header magic number, checksums (both header & image),
77 * - verified image architecture (PPC) and type (KERNEL or MULTI),
78 * - loaded (first part of) image to header load address,
79 * - disabled interrupts.
81 typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag,
82 int argc, char *argv[],
83 ulong addr, /* of image to boot */
84 ulong *len_ptr, /* multi-file image length table */
85 int verify); /* getenv("verify")[0] != 'n' */
88 static boot_os_Fcn do_bootm_linux;
90 extern boot_os_Fcn do_bootm_linux;
92 static boot_os_Fcn do_bootm_netbsd;
93 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
94 static boot_os_Fcn do_bootm_vxworks;
95 static boot_os_Fcn do_bootm_qnxelf;
96 int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
97 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
98 #endif /* CFG_CMD_ELF */
100 image_header_t header;
102 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
104 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
108 ulong data, len, checksum;
112 int (*appl)(cmd_tbl_t *, int, int, char *[]);
113 image_header_t *hdr = &header;
115 s = getenv ("verify");
116 verify = (s && (*s == 'n')) ? 0 : 1;
121 addr = simple_strtoul(argv[1], NULL, 16);
124 SHOW_BOOT_PROGRESS (1);
125 printf ("## Booting image at %08lx ...\n", addr);
127 /* Copy header so we can blank CRC field for re-calculation */
128 memmove (&header, (char *)addr, sizeof(image_header_t));
130 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
131 printf ("Bad Magic Number\n");
132 SHOW_BOOT_PROGRESS (-1);
135 SHOW_BOOT_PROGRESS (2);
137 data = (ulong)&header;
138 len = sizeof(image_header_t);
140 checksum = ntohl(hdr->ih_hcrc);
143 if (crc32 (0, (char *)data, len) != checksum) {
144 printf ("Bad Header Checksum\n");
145 SHOW_BOOT_PROGRESS (-2);
148 SHOW_BOOT_PROGRESS (3);
150 /* for multi-file images we need the data part, too */
151 print_image_hdr ((image_header_t *)addr);
153 data = addr + sizeof(image_header_t);
154 len = ntohl(hdr->ih_size);
157 printf (" Verifying Checksum ... ");
158 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
159 printf ("Bad Data CRC\n");
160 SHOW_BOOT_PROGRESS (-3);
165 SHOW_BOOT_PROGRESS (4);
167 len_ptr = (ulong *)data;
169 if (hdr->ih_arch != IH_CPU_PPC && hdr->ih_arch != IH_CPU_ARM) {
170 printf ("Unsupported Architecture\n");
171 SHOW_BOOT_PROGRESS (-4);
174 SHOW_BOOT_PROGRESS (5);
176 switch (hdr->ih_type) {
177 case IH_TYPE_STANDALONE: name = "Standalone Application";
179 case IH_TYPE_KERNEL: name = "Kernel Image";
181 case IH_TYPE_MULTI: name = "Multi-File Image";
182 len = ntohl(len_ptr[0]);
183 /* OS kernel is always the first image */
184 data += 8; /* kernel_len + terminator */
185 for (i=1; len_ptr[i]; ++i)
188 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
189 SHOW_BOOT_PROGRESS (-5);
192 SHOW_BOOT_PROGRESS (6);
195 * We have reached the point of no return: we are going to
196 * overwrite all exception vector code, so we cannot easily
197 * recover from any failures any more...
200 iflag = disable_interrupts();
202 switch (hdr->ih_comp) {
204 if(hdr->ih_load == addr) {
205 printf (" XIP %s ... ", name);
207 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
209 void *to = (void *)ntohl(hdr->ih_load);
210 void *from = (void *)data;
212 printf (" Loading %s ... ", name);
215 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
217 memmove (to, from, tail);
222 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
223 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
224 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
228 printf (" Uncompressing %s ... ", name);
229 if (gunzip ((void *)ntohl(hdr->ih_load), 0x400000,
230 (uchar *)data, (int *)&len) != 0) {
231 printf ("GUNZIP ERROR - must RESET board to recover\n");
232 SHOW_BOOT_PROGRESS (-6);
233 do_reset (cmdtp, flag, argc, argv);
239 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
240 SHOW_BOOT_PROGRESS (-7);
244 SHOW_BOOT_PROGRESS (7);
246 switch (hdr->ih_type) {
247 case IH_TYPE_STANDALONE:
248 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
252 (*appl)(cmdtp, flag, argc-1, &argv[1]);
261 printf ("Can't boot image type %d\n", hdr->ih_type);
262 SHOW_BOOT_PROGRESS (-8);
265 SHOW_BOOT_PROGRESS (8);
267 switch (hdr->ih_os) {
268 default: /* handled by (original) Linux case */
270 do_bootm_linux (cmdtp, flag, argc, argv,
271 addr, len_ptr, verify);
274 do_bootm_netbsd (cmdtp, flag, argc, argv,
275 addr, len_ptr, verify);
277 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
279 do_bootm_vxworks (cmdtp, flag, argc, argv,
280 addr, len_ptr, verify);
283 do_bootm_qnxelf (cmdtp, flag, argc, argv,
284 addr, len_ptr, verify);
286 #endif /* CFG_CMD_ELF */
289 SHOW_BOOT_PROGRESS (-9);
291 printf ("\n## Control returned to monitor - resetting...\n");
292 do_reset (cmdtp, flag, argc, argv);
299 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
300 int argc, char *argv[],
305 DECLARE_GLOBAL_DATA_PTR;
309 ulong initrd_start, initrd_end;
310 ulong cmd_start, cmd_end;
316 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
317 image_header_t *hdr = &header;
319 if ((s = getenv ("initrd_high")) != NULL) {
320 /* a value of "no" or a similar string will act like 0,
321 * turning the "load high" feature off. This is intentional.
323 initrd_high = simple_strtoul(s, NULL, 16);
324 } else { /* not set, no restrictions to load high */
328 #ifdef CONFIG_LOGBUFFER
330 if ((s = getenv ("logstart")) != NULL) {
331 kbd->bi_sramstart = simple_strtoul(s, NULL, 16);
332 /* Prevent initrd from overwriting logbuffer */
333 if (initrd_high < kbd->bi_sramstart)
334 initrd_high = kbd->bi_sramstart-1024;
336 debug ("## Logbuffer at 0x%08lX ", kbd->bi_sramstart);
340 * Booting a (Linux) kernel image
342 * Allocate space for command line and board info - the
343 * address should be as high as possible within the reach of
344 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
345 * memory, which means far enough below the current stack
349 asm( "mr %0,1": "=r"(sp) : );
351 debug ("## Current stack ends at 0x%08lX ", sp);
353 sp -= 2048; /* just to be sure */
354 if (sp > CFG_BOOTMAPSZ)
358 debug ("=> set upper limit to 0x%08lX\n", sp);
360 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
361 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
363 if ((s = getenv("bootargs")) == NULL)
368 cmd_start = (ulong)&cmdline[0];
369 cmd_end = cmd_start + strlen(cmdline);
374 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
376 do_bdinfo (NULL, 0, 0, NULL);
379 if ((s = getenv ("clocks_in_mhz")) != NULL) {
380 /* convert all clock information to MHz */
381 kbd->bi_intfreq /= 1000000L;
382 kbd->bi_busfreq /= 1000000L;
383 #if defined(CONFIG_8260)
384 kbd->bi_cpmfreq /= 1000000L;
385 kbd->bi_brgfreq /= 1000000L;
386 kbd->bi_sccfreq /= 1000000L;
387 kbd->bi_vco /= 1000000L;
388 #endif /* CONFIG_8260 */
391 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
394 * Check if there is an initrd image
397 SHOW_BOOT_PROGRESS (9);
399 addr = simple_strtoul(argv[2], NULL, 16);
401 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
403 /* Copy header so we can blank CRC field for re-calculation */
404 memmove (&header, (char *)addr, sizeof(image_header_t));
406 if (hdr->ih_magic != IH_MAGIC) {
407 printf ("Bad Magic Number\n");
408 SHOW_BOOT_PROGRESS (-10);
409 do_reset (cmdtp, flag, argc, argv);
412 data = (ulong)&header;
413 len = sizeof(image_header_t);
415 checksum = hdr->ih_hcrc;
418 if (crc32 (0, (char *)data, len) != checksum) {
419 printf ("Bad Header Checksum\n");
420 SHOW_BOOT_PROGRESS (-11);
421 do_reset (cmdtp, flag, argc, argv);
424 SHOW_BOOT_PROGRESS (10);
426 print_image_hdr (hdr);
428 data = addr + sizeof(image_header_t);
433 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
434 ulong cdata = data, edata = cdata + len;
435 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
437 printf (" Verifying Checksum ... ");
439 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
441 while (cdata < edata) {
442 ulong chunk = edata - cdata;
446 csum = crc32 (csum, (char *)cdata, chunk);
451 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
452 csum = crc32 (0, (char *)data, len);
453 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
455 if (csum != hdr->ih_dcrc) {
456 printf ("Bad Data CRC\n");
457 SHOW_BOOT_PROGRESS (-12);
458 do_reset (cmdtp, flag, argc, argv);
463 SHOW_BOOT_PROGRESS (11);
465 if ((hdr->ih_os != IH_OS_LINUX) ||
466 (hdr->ih_arch != IH_CPU_PPC) ||
467 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
468 printf ("No Linux PPC Ramdisk Image\n");
469 SHOW_BOOT_PROGRESS (-13);
470 do_reset (cmdtp, flag, argc, argv);
474 * Now check if we have a multifile image
476 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
477 u_long tail = ntohl(len_ptr[0]) % 4;
480 SHOW_BOOT_PROGRESS (13);
482 /* skip kernel length and terminator */
483 data = (ulong)(&len_ptr[2]);
484 /* skip any additional image length fields */
485 for (i=1; len_ptr[i]; ++i)
487 /* add kernel length, and align */
488 data += ntohl(len_ptr[0]);
493 len = ntohl(len_ptr[1]);
499 SHOW_BOOT_PROGRESS (14);
505 debug ("No initrd\n");
509 initrd_start = (ulong)kbd - len;
510 initrd_start &= ~(4096 - 1); /* align on page */
516 * the inital ramdisk does not need to be within
517 * CFG_BOOTMAPSZ as it is not accessed until after
518 * the mm system is initialised.
520 * do the stack bottom calculation again and see if
521 * the initrd will fit just below the monitor stack
522 * bottom without overwriting the area allocated
523 * above for command line args and board info.
525 asm( "mr %0,1": "=r"(nsp) : );
526 nsp -= 2048; /* just to be sure */
528 if (nsp > initrd_high) /* limit as specified */
531 nsp &= ~(4096 - 1); /* align on page */
536 SHOW_BOOT_PROGRESS (12);
538 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
539 data, data + len - 1, len, len);
541 initrd_end = initrd_start + len;
542 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
543 initrd_start, initrd_end);
544 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
547 void *to = (void *)initrd_start;
548 void *from = (void *)data;
551 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
553 memmove (to, from, tail);
559 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
560 memmove ((void *)initrd_start, (void *)data, len);
561 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
569 debug ("## Transferring control to Linux (at address %08lx) ...\n",
572 SHOW_BOOT_PROGRESS (15);
574 #ifdef CFG_INIT_RAM_LOCK
575 unlock_ram_in_cache();
578 * Linux Kernel Parameters:
579 * r3: ptr to board info data
580 * r4: initrd_start or 0 if no initrd
581 * r5: initrd_end - unused if r4 is 0
582 * r6: Start of command line string
583 * r7: End of command line string
585 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
587 #endif /* CONFIG_ARM */
590 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
591 int argc, char *argv[],
596 DECLARE_GLOBAL_DATA_PTR;
598 image_header_t *hdr = &header;
600 void (*loader)(bd_t *, image_header_t *, char *, char *);
601 image_header_t *img_addr;
607 * Booting a (NetBSD) kernel image
609 * This process is pretty similar to a standalone application:
610 * The (first part of an multi-) image must be a stage-2 loader,
611 * which in turn is responsible for loading & invoking the actual
612 * kernel. The only differences are the parameters being passed:
613 * besides the board info strucure, the loader expects a command
614 * line, the name of the console device, and (optionally) the
615 * address of the original image header.
619 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
620 img_addr = (image_header_t *) addr;
624 #if defined (CONFIG_8xx_CONS_SMC1)
626 #elif defined (CONFIG_8xx_CONS_SMC2)
628 #elif defined (CONFIG_8xx_CONS_SCC2)
630 #elif defined (CONFIG_8xx_CONS_SCC3)
638 for (i=2, len=0 ; i<argc ; i+=1)
639 len += strlen (argv[i]) + 1;
640 cmdline = malloc (len);
642 for (i=2, len=0 ; i<argc ; i+=1) {
644 cmdline[len++] = ' ';
645 strcpy (&cmdline[len], argv[i]);
646 len += strlen (argv[i]);
648 } else if ((cmdline = getenv("bootargs")) == NULL) {
652 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
654 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
657 SHOW_BOOT_PROGRESS (15);
660 * NetBSD Stage-2 Loader Parameters:
661 * r3: ptr to board info data
664 * r6: boot args string
666 (*loader) (gd->bd, img_addr, consdev, cmdline);
669 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
670 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
673 #ifndef CFG_HUSH_PARSER
674 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
676 if (parse_string_outer(getenv("bootcmd"),
677 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
683 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
684 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
691 return image_info (load_addr);
694 for (arg=1; arg <argc; ++arg) {
695 addr = simple_strtoul(argv[arg], NULL, 16);
696 if (image_info (addr) != 0) rcode = 1;
701 static int image_info (ulong addr)
703 ulong data, len, checksum;
704 image_header_t *hdr = &header;
706 printf ("\n## Checking Image at %08lx ...\n", addr);
708 /* Copy header so we can blank CRC field for re-calculation */
709 memmove (&header, (char *)addr, sizeof(image_header_t));
711 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
712 printf (" Bad Magic Number\n");
716 data = (ulong)&header;
717 len = sizeof(image_header_t);
719 checksum = ntohl(hdr->ih_hcrc);
722 if (crc32 (0, (char *)data, len) != checksum) {
723 printf (" Bad Header Checksum\n");
727 /* for multi-file images we need the data part, too */
728 print_image_hdr ((image_header_t *)addr);
730 data = addr + sizeof(image_header_t);
731 len = ntohl(hdr->ih_size);
733 printf (" Verifying Checksum ... ");
734 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
735 printf (" Bad Data CRC\n");
741 #endif /* CFG_CMD_IMI */
744 print_image_hdr (image_header_t *hdr)
746 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
747 time_t timestamp = (time_t)ntohl(hdr->ih_time);
751 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
752 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
753 to_tm (timestamp, &tm);
754 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
755 tm.tm_year, tm.tm_mon, tm.tm_mday,
756 tm.tm_hour, tm.tm_min, tm.tm_sec);
757 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
758 printf (" Image Type: "); print_type(hdr); printf ("\n");
759 printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
760 print_size (ntohl(hdr->ih_size), "\n");
761 printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
762 printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
764 if (hdr->ih_type == IH_TYPE_MULTI) {
767 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
769 printf (" Contents:\n");
770 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
771 printf (" Image %d: %8ld Bytes = ", i, len);
772 print_size (len, "\n");
779 print_type (image_header_t *hdr)
781 char *os, *arch, *type, *comp;
783 switch (hdr->ih_os) {
784 case IH_OS_INVALID: os = "Invalid OS"; break;
785 case IH_OS_NETBSD: os = "NetBSD"; break;
786 case IH_OS_LINUX: os = "Linux"; break;
787 case IH_OS_VXWORKS: os = "VxWorks"; break;
788 case IH_OS_QNX: os = "QNX"; break;
789 case IH_OS_U_BOOT: os = "U-Boot"; break;
790 default: os = "Unknown OS"; break;
793 switch (hdr->ih_arch) {
794 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
795 case IH_CPU_ALPHA: arch = "Alpha"; break;
796 case IH_CPU_ARM: arch = "ARM"; break;
797 case IH_CPU_I386: arch = "Intel x86"; break;
798 case IH_CPU_IA64: arch = "IA64"; break;
799 case IH_CPU_MIPS: arch = "MIPS"; break;
800 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
801 case IH_CPU_PPC: arch = "PowerPC"; break;
802 case IH_CPU_S390: arch = "IBM S390"; break;
803 case IH_CPU_SH: arch = "SuperH"; break;
804 case IH_CPU_SPARC: arch = "SPARC"; break;
805 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
806 default: arch = "Unknown Architecture"; break;
809 switch (hdr->ih_type) {
810 case IH_TYPE_INVALID: type = "Invalid Image"; break;
811 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
812 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
813 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
814 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
815 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
816 case IH_TYPE_SCRIPT: type = "Script"; break;
817 default: type = "Unknown Image"; break;
820 switch (hdr->ih_comp) {
821 case IH_COMP_NONE: comp = "uncompressed"; break;
822 case IH_COMP_GZIP: comp = "gzip compressed"; break;
823 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
824 default: comp = "unknown compression"; break;
827 printf ("%s %s %s (%s)", arch, os, type, comp);
830 #define ZALLOC_ALIGNMENT 16
832 static void *zalloc(void *x, unsigned items, unsigned size)
837 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
844 static void zfree(void *x, void *addr, unsigned nb)
850 #define EXTRA_FIELD 4
853 #define RESERVED 0xe0
857 int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
865 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
866 printf ("Error: Bad gzipped data\n");
869 if ((flags & EXTRA_FIELD) != 0)
870 i = 12 + src[10] + (src[11] << 8);
871 if ((flags & ORIG_NAME) != 0)
872 while (src[i++] != 0)
874 if ((flags & COMMENT) != 0)
875 while (src[i++] != 0)
877 if ((flags & HEAD_CRC) != 0)
880 printf ("Error: gunzip out of data in header\n");
886 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
887 s.outcb = (cb_func)WATCHDOG_RESET;
890 #endif /* CONFIG_HW_WATCHDOG */
892 r = inflateInit2(&s, -MAX_WBITS);
894 printf ("Error: inflateInit2() returned %d\n", r);
898 s.avail_in = *lenp - i;
900 s.avail_out = dstlen;
901 r = inflate(&s, Z_FINISH);
902 if (r != Z_OK && r != Z_STREAM_END) {
903 printf ("Error: inflate() returned %d\n", r);
906 *lenp = s.next_out - (unsigned char *) dst;
912 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
914 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
915 ulong addr, ulong *len_ptr, int verify)
917 image_header_t *hdr = &header;
920 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
921 setenv("loadaddr", str);
922 do_bootvx(cmdtp, 0, 0, NULL);
926 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
927 ulong addr, ulong *len_ptr, int verify)
929 image_header_t *hdr = &header;
933 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
934 local_args[0] = argv[0];
935 local_args[1] = str; /* and provide it via the arguments */
936 do_bootelf(cmdtp, 0, 2, local_args);
938 #endif /* CFG_CMD_ELF */