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 <environment.h>
35 #include <asm/byteorder.h>
36 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
40 #ifdef CFG_HUSH_PARSER
44 #ifdef CONFIG_SHOW_BOOT_PROGRESS
45 # include <status_led.h>
46 # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
48 # define SHOW_BOOT_PROGRESS(arg)
51 #ifdef CFG_INIT_RAM_LOCK
52 #include <asm/cache.h>
55 #ifdef CONFIG_LOGBUFFER
59 #ifdef CONFIG_HAS_DATAFLASH
60 #include <dataflash.h>
64 * Some systems (for example LWMON) have very short watchdog periods;
65 * we must make sure to split long operations like memmove() or
66 * crc32() into reasonable chunks.
68 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
69 # define CHUNKSZ (64 * 1024)
72 int gunzip (void *, int, unsigned char *, int *);
74 static void *zalloc(void *, unsigned, unsigned);
75 static void zfree(void *, void *, unsigned);
77 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
78 static int image_info (unsigned long addr);
80 static void print_type (image_header_t *hdr);
83 image_header_t *fake_header(image_header_t *hdr, void *ptr, int size);
87 * Continue booting an OS image; caller already has:
88 * - copied image header to global variable `header'
89 * - checked header magic number, checksums (both header & image),
90 * - verified image architecture (PPC) and type (KERNEL or MULTI),
91 * - loaded (first part of) image to header load address,
92 * - disabled interrupts.
94 typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag,
95 int argc, char *argv[],
96 ulong addr, /* of image to boot */
97 ulong *len_ptr, /* multi-file image length table */
98 int verify); /* getenv("verify")[0] != 'n' */
101 static boot_os_Fcn do_bootm_linux;
103 extern boot_os_Fcn do_bootm_linux;
105 static boot_os_Fcn do_bootm_netbsd;
106 static boot_os_Fcn do_bootm_rtems;
107 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
108 static boot_os_Fcn do_bootm_vxworks;
109 static boot_os_Fcn do_bootm_qnxelf;
110 int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
111 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
112 #endif /* CFG_CMD_ELF */
113 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
114 static boot_os_Fcn do_bootm_artos;
117 image_header_t header;
119 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
121 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
125 ulong data, len, checksum;
129 int (*appl)(cmd_tbl_t *, int, int, char *[]);
130 image_header_t *hdr = &header;
132 s = getenv ("verify");
133 verify = (s && (*s == 'n')) ? 0 : 1;
138 addr = simple_strtoul(argv[1], NULL, 16);
141 SHOW_BOOT_PROGRESS (1);
142 printf ("## Booting image at %08lx ...\n", addr);
144 /* Copy header so we can blank CRC field for re-calculation */
145 #ifdef CONFIG_HAS_DATAFLASH
146 if (addr_dataflash(addr)){
147 read_dataflash(addr, sizeof(image_header_t), (char *)&header);
150 memmove (&header, (char *)addr, sizeof(image_header_t));
152 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
153 #ifdef __I386__ /* correct image format not implemented yet - fake it */
154 if (fake_header(hdr, (void*)addr, -1) != NULL) {
155 /* to compensate for the addition below */
156 addr -= sizeof(image_header_t);
158 * fake_header() does not fake the data crc
162 #endif /* __I386__ */
164 printf ("Bad Magic Number\n");
165 SHOW_BOOT_PROGRESS (-1);
169 SHOW_BOOT_PROGRESS (2);
171 data = (ulong)&header;
172 len = sizeof(image_header_t);
174 checksum = ntohl(hdr->ih_hcrc);
177 if (crc32 (0, (char *)data, len) != checksum) {
178 printf ("Bad Header Checksum\n");
179 SHOW_BOOT_PROGRESS (-2);
182 SHOW_BOOT_PROGRESS (3);
184 /* for multi-file images we need the data part, too */
185 print_image_hdr (hdr);
187 data = addr + sizeof(image_header_t);
188 len = ntohl(hdr->ih_size);
190 #ifdef CONFIG_HAS_DATAFLASH
191 if (addr_dataflash(addr)){
192 read_dataflash(data, len, (char *)CFG_LOAD_ADDR);
193 data = CFG_LOAD_ADDR;
198 printf (" Verifying Checksum ... ");
199 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
200 printf ("Bad Data CRC\n");
201 SHOW_BOOT_PROGRESS (-3);
206 SHOW_BOOT_PROGRESS (4);
208 len_ptr = (ulong *)data;
211 if (hdr->ih_arch != IH_CPU_PPC)
212 #elif defined(__ARM__)
213 if (hdr->ih_arch != IH_CPU_ARM)
214 #elif defined(__I386__)
215 if (hdr->ih_arch != IH_CPU_I386)
216 #elif defined(__mips__)
217 if (hdr->ih_arch != IH_CPU_MIPS)
219 # error Unknown CPU type
222 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
223 SHOW_BOOT_PROGRESS (-4);
226 SHOW_BOOT_PROGRESS (5);
228 switch (hdr->ih_type) {
229 case IH_TYPE_STANDALONE: name = "Standalone Application";
231 case IH_TYPE_KERNEL: name = "Kernel Image";
233 case IH_TYPE_MULTI: name = "Multi-File Image";
234 len = ntohl(len_ptr[0]);
235 /* OS kernel is always the first image */
236 data += 8; /* kernel_len + terminator */
237 for (i=1; len_ptr[i]; ++i)
240 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
241 SHOW_BOOT_PROGRESS (-5);
244 SHOW_BOOT_PROGRESS (6);
247 * We have reached the point of no return: we are going to
248 * overwrite all exception vector code, so we cannot easily
249 * recover from any failures any more...
252 iflag = disable_interrupts();
254 #ifdef CONFIG_AMIGAONEG3SE
256 * We've possible left the caches enabled during
257 * bios emulation, so turn them off again
260 invalidate_l1_instruction_cache();
265 switch (hdr->ih_comp) {
267 if(ntohl(hdr->ih_load) == addr) {
268 printf (" XIP %s ... ", name);
270 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
272 void *to = (void *)ntohl(hdr->ih_load);
273 void *from = (void *)data;
275 printf (" Loading %s ... ", name);
278 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
280 memmove (to, from, tail);
285 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
286 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
287 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
291 printf (" Uncompressing %s ... ", name);
292 if (gunzip ((void *)ntohl(hdr->ih_load), 0x400000,
293 (uchar *)data, (int *)&len) != 0) {
294 printf ("GUNZIP ERROR - must RESET board to recover\n");
295 SHOW_BOOT_PROGRESS (-6);
296 do_reset (cmdtp, flag, argc, argv);
302 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
303 SHOW_BOOT_PROGRESS (-7);
307 SHOW_BOOT_PROGRESS (7);
309 switch (hdr->ih_type) {
310 case IH_TYPE_STANDALONE:
314 /* load (and uncompress), but don't start if "autostart"
317 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0))
319 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
320 (*appl)(cmdtp, flag, argc-1, &argv[1]);
329 printf ("Can't boot image type %d\n", hdr->ih_type);
330 SHOW_BOOT_PROGRESS (-8);
333 SHOW_BOOT_PROGRESS (8);
335 switch (hdr->ih_os) {
336 default: /* handled by (original) Linux case */
338 do_bootm_linux (cmdtp, flag, argc, argv,
339 addr, len_ptr, verify);
342 do_bootm_netbsd (cmdtp, flag, argc, argv,
343 addr, len_ptr, verify);
347 do_bootm_rtems (cmdtp, flag, argc, argv,
348 addr, len_ptr, verify);
351 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
353 do_bootm_vxworks (cmdtp, flag, argc, argv,
354 addr, len_ptr, verify);
357 do_bootm_qnxelf (cmdtp, flag, argc, argv,
358 addr, len_ptr, verify);
360 #endif /* CFG_CMD_ELF */
363 do_bootm_artos (cmdtp, flag, argc, argv,
364 addr, len_ptr, verify);
369 SHOW_BOOT_PROGRESS (-9);
371 printf ("\n## Control returned to monitor - resetting...\n");
372 do_reset (cmdtp, flag, argc, argv);
379 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
380 int argc, char *argv[],
385 DECLARE_GLOBAL_DATA_PTR;
389 ulong initrd_start, initrd_end;
390 ulong cmd_start, cmd_end;
393 int initrd_copy_to_ram = 1;
397 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
398 image_header_t *hdr = &header;
400 if ((s = getenv ("initrd_high")) != NULL) {
401 /* a value of "no" or a similar string will act like 0,
402 * turning the "load high" feature off. This is intentional.
404 initrd_high = simple_strtoul(s, NULL, 16);
405 if (initrd_high == ~0)
406 initrd_copy_to_ram = 0;
407 } else { /* not set, no restrictions to load high */
411 #ifdef CONFIG_LOGBUFFER
413 /* Prevent initrd from overwriting logbuffer */
414 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
415 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
416 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
420 * Booting a (Linux) kernel image
422 * Allocate space for command line and board info - the
423 * address should be as high as possible within the reach of
424 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
425 * memory, which means far enough below the current stack
429 asm( "mr %0,1": "=r"(sp) : );
431 debug ("## Current stack ends at 0x%08lX ", sp);
433 sp -= 2048; /* just to be sure */
434 if (sp > CFG_BOOTMAPSZ)
438 debug ("=> set upper limit to 0x%08lX\n", sp);
440 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
441 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
443 if ((s = getenv("bootargs")) == NULL)
448 cmd_start = (ulong)&cmdline[0];
449 cmd_end = cmd_start + strlen(cmdline);
454 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
456 do_bdinfo (NULL, 0, 0, NULL);
459 if ((s = getenv ("clocks_in_mhz")) != NULL) {
460 /* convert all clock information to MHz */
461 kbd->bi_intfreq /= 1000000L;
462 kbd->bi_busfreq /= 1000000L;
463 #if defined(CONFIG_8260)
464 kbd->bi_cpmfreq /= 1000000L;
465 kbd->bi_brgfreq /= 1000000L;
466 kbd->bi_sccfreq /= 1000000L;
467 kbd->bi_vco /= 1000000L;
468 #endif /* CONFIG_8260 */
471 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
474 * Check if there is an initrd image
477 SHOW_BOOT_PROGRESS (9);
479 addr = simple_strtoul(argv[2], NULL, 16);
481 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
483 /* Copy header so we can blank CRC field for re-calculation */
484 memmove (&header, (char *)addr, sizeof(image_header_t));
486 if (hdr->ih_magic != IH_MAGIC) {
487 printf ("Bad Magic Number\n");
488 SHOW_BOOT_PROGRESS (-10);
489 do_reset (cmdtp, flag, argc, argv);
492 data = (ulong)&header;
493 len = sizeof(image_header_t);
495 checksum = hdr->ih_hcrc;
498 if (crc32 (0, (char *)data, len) != checksum) {
499 printf ("Bad Header Checksum\n");
500 SHOW_BOOT_PROGRESS (-11);
501 do_reset (cmdtp, flag, argc, argv);
504 SHOW_BOOT_PROGRESS (10);
506 print_image_hdr (hdr);
508 data = addr + sizeof(image_header_t);
513 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
514 ulong cdata = data, edata = cdata + len;
515 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
517 printf (" Verifying Checksum ... ");
519 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
521 while (cdata < edata) {
522 ulong chunk = edata - cdata;
526 csum = crc32 (csum, (char *)cdata, chunk);
531 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
532 csum = crc32 (0, (char *)data, len);
533 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
535 if (csum != hdr->ih_dcrc) {
536 printf ("Bad Data CRC\n");
537 SHOW_BOOT_PROGRESS (-12);
538 do_reset (cmdtp, flag, argc, argv);
543 SHOW_BOOT_PROGRESS (11);
545 if ((hdr->ih_os != IH_OS_LINUX) ||
546 (hdr->ih_arch != IH_CPU_PPC) ||
547 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
548 printf ("No Linux PPC Ramdisk Image\n");
549 SHOW_BOOT_PROGRESS (-13);
550 do_reset (cmdtp, flag, argc, argv);
554 * Now check if we have a multifile image
556 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
557 u_long tail = ntohl(len_ptr[0]) % 4;
560 SHOW_BOOT_PROGRESS (13);
562 /* skip kernel length and terminator */
563 data = (ulong)(&len_ptr[2]);
564 /* skip any additional image length fields */
565 for (i=1; len_ptr[i]; ++i)
567 /* add kernel length, and align */
568 data += ntohl(len_ptr[0]);
573 len = ntohl(len_ptr[1]);
579 SHOW_BOOT_PROGRESS (14);
585 debug ("No initrd\n");
589 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
591 initrd_end = initrd_start + len;
593 initrd_start = (ulong)kbd - len;
594 initrd_start &= ~(4096 - 1); /* align on page */
600 * the inital ramdisk does not need to be within
601 * CFG_BOOTMAPSZ as it is not accessed until after
602 * the mm system is initialised.
604 * do the stack bottom calculation again and see if
605 * the initrd will fit just below the monitor stack
606 * bottom without overwriting the area allocated
607 * above for command line args and board info.
609 asm( "mr %0,1": "=r"(nsp) : );
610 nsp -= 2048; /* just to be sure */
612 if (nsp > initrd_high) /* limit as specified */
615 nsp &= ~(4096 - 1); /* align on page */
620 SHOW_BOOT_PROGRESS (12);
622 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
623 data, data + len - 1, len, len);
625 initrd_end = initrd_start + len;
626 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
627 initrd_start, initrd_end);
628 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
631 void *to = (void *)initrd_start;
632 void *from = (void *)data;
635 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
637 memmove (to, from, tail);
643 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
644 memmove ((void *)initrd_start, (void *)data, len);
645 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
654 debug ("## Transferring control to Linux (at address %08lx) ...\n",
657 SHOW_BOOT_PROGRESS (15);
659 #ifdef CFG_INIT_RAM_LOCK
660 unlock_ram_in_cache();
663 * Linux Kernel Parameters:
664 * r3: ptr to board info data
665 * r4: initrd_start or 0 if no initrd
666 * r5: initrd_end - unused if r4 is 0
667 * r6: Start of command line string
668 * r7: End of command line string
670 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
672 #endif /* CONFIG_PPC */
675 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
676 int argc, char *argv[],
681 DECLARE_GLOBAL_DATA_PTR;
683 image_header_t *hdr = &header;
685 void (*loader)(bd_t *, image_header_t *, char *, char *);
686 image_header_t *img_addr;
692 * Booting a (NetBSD) kernel image
694 * This process is pretty similar to a standalone application:
695 * The (first part of an multi-) image must be a stage-2 loader,
696 * which in turn is responsible for loading & invoking the actual
697 * kernel. The only differences are the parameters being passed:
698 * besides the board info strucure, the loader expects a command
699 * line, the name of the console device, and (optionally) the
700 * address of the original image header.
704 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
705 img_addr = (image_header_t *) addr;
709 #if defined (CONFIG_8xx_CONS_SMC1)
711 #elif defined (CONFIG_8xx_CONS_SMC2)
713 #elif defined (CONFIG_8xx_CONS_SCC2)
715 #elif defined (CONFIG_8xx_CONS_SCC3)
723 for (i=2, len=0 ; i<argc ; i+=1)
724 len += strlen (argv[i]) + 1;
725 cmdline = malloc (len);
727 for (i=2, len=0 ; i<argc ; i+=1) {
729 cmdline[len++] = ' ';
730 strcpy (&cmdline[len], argv[i]);
731 len += strlen (argv[i]);
733 } else if ((cmdline = getenv("bootargs")) == NULL) {
737 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
739 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
742 SHOW_BOOT_PROGRESS (15);
745 * NetBSD Stage-2 Loader Parameters:
746 * r3: ptr to board info data
749 * r6: boot args string
751 (*loader) (gd->bd, img_addr, consdev, cmdline);
754 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
756 /* Function that returns a character from the environment */
757 extern uchar (*env_get_char)(int);
760 do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
761 int argc, char *argv[],
766 DECLARE_GLOBAL_DATA_PTR;
770 int i, j, nxt, len, envno, envsz;
772 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
773 image_header_t *hdr = &header;
776 * Booting an ARTOS kernel image + application
779 /* this used to be the top of memory, but was wrong... */
781 /* get stack pointer */
782 asm volatile ("mr %0,1" : "=r"(top) );
784 debug ("## Current stack ends at 0x%08lX ", top);
786 top -= 2048; /* just to be sure */
787 if (top > CFG_BOOTMAPSZ)
791 debug ("=> set upper limit to 0x%08lX\n", top);
793 /* first check the artos specific boot args, then the linux args*/
794 if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
797 /* get length of cmdline, and place it */
799 top = (top - (len + 1)) & ~0xF;
800 cmdline = (char *)top;
801 debug ("## cmdline at 0x%08lX ", top);
805 top = (top - sizeof(bd_t)) & ~0xF;
806 debug ("## bd at 0x%08lX ", top);
808 memcpy(kbd, gd->bd, sizeof(bd_t));
810 /* first find number of env entries, and their size */
813 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
814 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
817 envsz += (nxt - i) + 1; /* plus trailing zero */
819 envno++; /* plus the terminating zero */
820 debug ("## %u envvars total size %u ", envno, envsz);
822 top = (top - sizeof(char **)*envno) & ~0xF;
823 fwenv = (char **)top;
824 debug ("## fwenv at 0x%08lX ", top);
826 top = (top - envsz) & ~0xF;
831 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
832 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
835 for (j = i; j < nxt; ++j)
836 *s++ = env_get_char(j);
839 *ss++ = NULL; /* terminate */
841 entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
842 (*entry)(kbd, cmdline, fwenv, top);
847 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
848 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
851 #ifndef CFG_HUSH_PARSER
852 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
854 if (parse_string_outer(getenv("bootcmd"),
855 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
861 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
862 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
869 return image_info (load_addr);
872 for (arg=1; arg <argc; ++arg) {
873 addr = simple_strtoul(argv[arg], NULL, 16);
874 if (image_info (addr) != 0) rcode = 1;
879 static int image_info (ulong addr)
881 ulong data, len, checksum;
882 image_header_t *hdr = &header;
884 printf ("\n## Checking Image at %08lx ...\n", addr);
886 /* Copy header so we can blank CRC field for re-calculation */
887 memmove (&header, (char *)addr, sizeof(image_header_t));
889 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
890 printf (" Bad Magic Number\n");
894 data = (ulong)&header;
895 len = sizeof(image_header_t);
897 checksum = ntohl(hdr->ih_hcrc);
900 if (crc32 (0, (char *)data, len) != checksum) {
901 printf (" Bad Header Checksum\n");
905 /* for multi-file images we need the data part, too */
906 print_image_hdr ((image_header_t *)addr);
908 data = addr + sizeof(image_header_t);
909 len = ntohl(hdr->ih_size);
911 printf (" Verifying Checksum ... ");
912 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
913 printf (" Bad Data CRC\n");
919 #endif /* CFG_CMD_IMI */
922 print_image_hdr (image_header_t *hdr)
924 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
925 time_t timestamp = (time_t)ntohl(hdr->ih_time);
929 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
930 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
931 to_tm (timestamp, &tm);
932 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
933 tm.tm_year, tm.tm_mon, tm.tm_mday,
934 tm.tm_hour, tm.tm_min, tm.tm_sec);
935 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
936 printf (" Image Type: "); print_type(hdr); printf ("\n");
937 printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
938 print_size (ntohl(hdr->ih_size), "\n");
939 printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
940 printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
942 if (hdr->ih_type == IH_TYPE_MULTI) {
945 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
947 printf (" Contents:\n");
948 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
949 printf (" Image %d: %8ld Bytes = ", i, len);
950 print_size (len, "\n");
957 print_type (image_header_t *hdr)
959 char *os, *arch, *type, *comp;
961 switch (hdr->ih_os) {
962 case IH_OS_INVALID: os = "Invalid OS"; break;
963 case IH_OS_NETBSD: os = "NetBSD"; break;
964 case IH_OS_LINUX: os = "Linux"; break;
965 case IH_OS_VXWORKS: os = "VxWorks"; break;
966 case IH_OS_QNX: os = "QNX"; break;
967 case IH_OS_U_BOOT: os = "U-Boot"; break;
968 case IH_OS_RTEMS: os = "RTEMS"; break;
970 case IH_OS_ARTOS: os = "ARTOS"; break;
972 default: os = "Unknown OS"; break;
975 switch (hdr->ih_arch) {
976 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
977 case IH_CPU_ALPHA: arch = "Alpha"; break;
978 case IH_CPU_ARM: arch = "ARM"; break;
979 case IH_CPU_I386: arch = "Intel x86"; break;
980 case IH_CPU_IA64: arch = "IA64"; break;
981 case IH_CPU_MIPS: arch = "MIPS"; break;
982 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
983 case IH_CPU_PPC: arch = "PowerPC"; break;
984 case IH_CPU_S390: arch = "IBM S390"; break;
985 case IH_CPU_SH: arch = "SuperH"; break;
986 case IH_CPU_SPARC: arch = "SPARC"; break;
987 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
988 default: arch = "Unknown Architecture"; break;
991 switch (hdr->ih_type) {
992 case IH_TYPE_INVALID: type = "Invalid Image"; break;
993 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
994 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
995 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
996 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
997 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
998 case IH_TYPE_SCRIPT: type = "Script"; break;
999 default: type = "Unknown Image"; break;
1002 switch (hdr->ih_comp) {
1003 case IH_COMP_NONE: comp = "uncompressed"; break;
1004 case IH_COMP_GZIP: comp = "gzip compressed"; break;
1005 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
1006 default: comp = "unknown compression"; break;
1009 printf ("%s %s %s (%s)", arch, os, type, comp);
1012 #define ZALLOC_ALIGNMENT 16
1014 static void *zalloc(void *x, unsigned items, unsigned size)
1019 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
1026 static void zfree(void *x, void *addr, unsigned nb)
1032 #define EXTRA_FIELD 4
1034 #define COMMENT 0x10
1035 #define RESERVED 0xe0
1039 int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
1047 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
1048 printf ("Error: Bad gzipped data\n");
1051 if ((flags & EXTRA_FIELD) != 0)
1052 i = 12 + src[10] + (src[11] << 8);
1053 if ((flags & ORIG_NAME) != 0)
1054 while (src[i++] != 0)
1056 if ((flags & COMMENT) != 0)
1057 while (src[i++] != 0)
1059 if ((flags & HEAD_CRC) != 0)
1062 printf ("Error: gunzip out of data in header\n");
1068 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1069 s.outcb = (cb_func)WATCHDOG_RESET;
1072 #endif /* CONFIG_HW_WATCHDOG */
1074 r = inflateInit2(&s, -MAX_WBITS);
1076 printf ("Error: inflateInit2() returned %d\n", r);
1079 s.next_in = src + i;
1080 s.avail_in = *lenp - i;
1082 s.avail_out = dstlen;
1083 r = inflate(&s, Z_FINISH);
1084 if (r != Z_OK && r != Z_STREAM_END) {
1085 printf ("Error: inflate() returned %d\n", r);
1088 *lenp = s.next_out - (unsigned char *) dst;
1095 do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1096 ulong addr, ulong *len_ptr, int verify)
1098 DECLARE_GLOBAL_DATA_PTR;
1099 image_header_t *hdr = &header;
1100 void (*entry_point)(bd_t *);
1102 entry_point = (void (*)(bd_t *)) hdr->ih_ep;
1104 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1105 (ulong)entry_point);
1107 SHOW_BOOT_PROGRESS (15);
1111 * r3: ptr to board info data
1114 (*entry_point ) ( gd->bd );
1117 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
1119 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1120 ulong addr, ulong *len_ptr, int verify)
1122 image_header_t *hdr = &header;
1125 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1126 setenv("loadaddr", str);
1127 do_bootvx(cmdtp, 0, 0, NULL);
1131 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1132 ulong addr, ulong *len_ptr, int verify)
1134 image_header_t *hdr = &header;
1135 char *local_args[2];
1138 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1139 local_args[0] = argv[0];
1140 local_args[1] = str; /* and provide it via the arguments */
1141 do_bootelf(cmdtp, 0, 2, local_args);
1143 #endif /* CFG_CMD_ELF */