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
60 * Some systems (for example LWMON) have very short watchdog periods;
61 * we must make sure to split long operations like memmove() or
62 * crc32() into reasonable chunks.
64 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
65 # define CHUNKSZ (64 * 1024)
68 int gunzip (void *, int, unsigned char *, int *);
70 static void *zalloc(void *, unsigned, unsigned);
71 static void zfree(void *, void *, unsigned);
73 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
74 static int image_info (unsigned long addr);
76 static void print_type (image_header_t *hdr);
79 image_header_t *fake_header(image_header_t *hdr, void *ptr, int size);
83 * Continue booting an OS image; caller already has:
84 * - copied image header to global variable `header'
85 * - checked header magic number, checksums (both header & image),
86 * - verified image architecture (PPC) and type (KERNEL or MULTI),
87 * - loaded (first part of) image to header load address,
88 * - disabled interrupts.
90 typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag,
91 int argc, char *argv[],
92 ulong addr, /* of image to boot */
93 ulong *len_ptr, /* multi-file image length table */
94 int verify); /* getenv("verify")[0] != 'n' */
97 static boot_os_Fcn do_bootm_linux;
99 extern boot_os_Fcn do_bootm_linux;
101 static boot_os_Fcn do_bootm_netbsd;
102 static boot_os_Fcn do_bootm_rtems;
103 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
104 static boot_os_Fcn do_bootm_vxworks;
105 static boot_os_Fcn do_bootm_qnxelf;
106 int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
107 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
108 #endif /* CFG_CMD_ELF */
109 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
110 static boot_os_Fcn do_bootm_artos;
113 image_header_t header;
115 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
117 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
121 ulong data, len, checksum;
125 int (*appl)(cmd_tbl_t *, int, int, char *[]);
126 image_header_t *hdr = &header;
128 s = getenv ("verify");
129 verify = (s && (*s == 'n')) ? 0 : 1;
134 addr = simple_strtoul(argv[1], NULL, 16);
137 SHOW_BOOT_PROGRESS (1);
138 printf ("## Booting image at %08lx ...\n", addr);
140 /* Copy header so we can blank CRC field for re-calculation */
141 memmove (&header, (char *)addr, sizeof(image_header_t));
143 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
144 #ifdef __I386__ /* correct image format not implemented yet - fake it */
145 if (fake_header(hdr, (void*)addr, -1) != NULL) {
146 /* to compensate for the addition below */
147 addr -= sizeof(image_header_t);
149 * fake_header() does not fake the data crc
153 #endif /* __I386__ */
155 printf ("Bad Magic Number\n");
156 SHOW_BOOT_PROGRESS (-1);
160 SHOW_BOOT_PROGRESS (2);
162 data = (ulong)&header;
163 len = sizeof(image_header_t);
165 checksum = ntohl(hdr->ih_hcrc);
168 if (crc32 (0, (char *)data, len) != checksum) {
169 printf ("Bad Header Checksum\n");
170 SHOW_BOOT_PROGRESS (-2);
173 SHOW_BOOT_PROGRESS (3);
175 /* for multi-file images we need the data part, too */
176 print_image_hdr (hdr);
178 data = addr + sizeof(image_header_t);
179 len = ntohl(hdr->ih_size);
182 printf (" Verifying Checksum ... ");
183 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
184 printf ("Bad Data CRC\n");
185 SHOW_BOOT_PROGRESS (-3);
190 SHOW_BOOT_PROGRESS (4);
192 len_ptr = (ulong *)data;
195 if (hdr->ih_arch != IH_CPU_PPC)
196 #elif defined(__ARM__)
197 if (hdr->ih_arch != IH_CPU_ARM)
198 #elif defined(__I386__)
199 if (hdr->ih_arch != IH_CPU_I386)
200 #elif defined(__mips__)
201 if (hdr->ih_arch != IH_CPU_MIPS)
203 # error Unknown CPU type
206 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
207 SHOW_BOOT_PROGRESS (-4);
210 SHOW_BOOT_PROGRESS (5);
212 switch (hdr->ih_type) {
213 case IH_TYPE_STANDALONE: name = "Standalone Application";
215 case IH_TYPE_KERNEL: name = "Kernel Image";
217 case IH_TYPE_MULTI: name = "Multi-File Image";
218 len = ntohl(len_ptr[0]);
219 /* OS kernel is always the first image */
220 data += 8; /* kernel_len + terminator */
221 for (i=1; len_ptr[i]; ++i)
224 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
225 SHOW_BOOT_PROGRESS (-5);
228 SHOW_BOOT_PROGRESS (6);
231 * We have reached the point of no return: we are going to
232 * overwrite all exception vector code, so we cannot easily
233 * recover from any failures any more...
236 iflag = disable_interrupts();
238 #ifdef CONFIG_AMIGAONEG3SE
240 * We've possible left the caches enabled during
241 * bios emulation, so turn them off again
244 invalidate_l1_instruction_cache();
249 switch (hdr->ih_comp) {
251 if(ntohl(hdr->ih_load) == addr) {
252 printf (" XIP %s ... ", name);
254 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
256 void *to = (void *)ntohl(hdr->ih_load);
257 void *from = (void *)data;
259 printf (" Loading %s ... ", name);
262 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
264 memmove (to, from, tail);
269 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
270 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
271 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
275 printf (" Uncompressing %s ... ", name);
276 if (gunzip ((void *)ntohl(hdr->ih_load), 0x400000,
277 (uchar *)data, (int *)&len) != 0) {
278 printf ("GUNZIP ERROR - must RESET board to recover\n");
279 SHOW_BOOT_PROGRESS (-6);
280 do_reset (cmdtp, flag, argc, argv);
286 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
287 SHOW_BOOT_PROGRESS (-7);
291 SHOW_BOOT_PROGRESS (7);
293 switch (hdr->ih_type) {
294 case IH_TYPE_STANDALONE:
298 /* load (and uncompress), but don't start if "autostart"
301 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0))
303 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
304 (*appl)(cmdtp, flag, argc-1, &argv[1]);
313 printf ("Can't boot image type %d\n", hdr->ih_type);
314 SHOW_BOOT_PROGRESS (-8);
317 SHOW_BOOT_PROGRESS (8);
319 switch (hdr->ih_os) {
320 default: /* handled by (original) Linux case */
322 do_bootm_linux (cmdtp, flag, argc, argv,
323 addr, len_ptr, verify);
326 do_bootm_netbsd (cmdtp, flag, argc, argv,
327 addr, len_ptr, verify);
331 do_bootm_rtems (cmdtp, flag, argc, argv,
332 addr, len_ptr, verify);
335 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
337 do_bootm_vxworks (cmdtp, flag, argc, argv,
338 addr, len_ptr, verify);
341 do_bootm_qnxelf (cmdtp, flag, argc, argv,
342 addr, len_ptr, verify);
344 #endif /* CFG_CMD_ELF */
347 do_bootm_artos (cmdtp, flag, argc, argv,
348 addr, len_ptr, verify);
353 SHOW_BOOT_PROGRESS (-9);
355 printf ("\n## Control returned to monitor - resetting...\n");
356 do_reset (cmdtp, flag, argc, argv);
363 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
364 int argc, char *argv[],
369 DECLARE_GLOBAL_DATA_PTR;
373 ulong initrd_start, initrd_end;
374 ulong cmd_start, cmd_end;
380 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
381 image_header_t *hdr = &header;
383 if ((s = getenv ("initrd_high")) != NULL) {
384 /* a value of "no" or a similar string will act like 0,
385 * turning the "load high" feature off. This is intentional.
387 initrd_high = simple_strtoul(s, NULL, 16);
388 } else { /* not set, no restrictions to load high */
392 #ifdef CONFIG_LOGBUFFER
394 /* Prevent initrd from overwriting logbuffer */
395 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
396 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
397 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
401 * Booting a (Linux) kernel image
403 * Allocate space for command line and board info - the
404 * address should be as high as possible within the reach of
405 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
406 * memory, which means far enough below the current stack
410 asm( "mr %0,1": "=r"(sp) : );
412 debug ("## Current stack ends at 0x%08lX ", sp);
414 sp -= 2048; /* just to be sure */
415 if (sp > CFG_BOOTMAPSZ)
419 debug ("=> set upper limit to 0x%08lX\n", sp);
421 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
422 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
424 if ((s = getenv("bootargs")) == NULL)
429 cmd_start = (ulong)&cmdline[0];
430 cmd_end = cmd_start + strlen(cmdline);
435 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
437 do_bdinfo (NULL, 0, 0, NULL);
440 if ((s = getenv ("clocks_in_mhz")) != NULL) {
441 /* convert all clock information to MHz */
442 kbd->bi_intfreq /= 1000000L;
443 kbd->bi_busfreq /= 1000000L;
444 #if defined(CONFIG_8260)
445 kbd->bi_cpmfreq /= 1000000L;
446 kbd->bi_brgfreq /= 1000000L;
447 kbd->bi_sccfreq /= 1000000L;
448 kbd->bi_vco /= 1000000L;
449 #endif /* CONFIG_8260 */
452 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
455 * Check if there is an initrd image
458 SHOW_BOOT_PROGRESS (9);
460 addr = simple_strtoul(argv[2], NULL, 16);
462 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
464 /* Copy header so we can blank CRC field for re-calculation */
465 memmove (&header, (char *)addr, sizeof(image_header_t));
467 if (hdr->ih_magic != IH_MAGIC) {
468 printf ("Bad Magic Number\n");
469 SHOW_BOOT_PROGRESS (-10);
470 do_reset (cmdtp, flag, argc, argv);
473 data = (ulong)&header;
474 len = sizeof(image_header_t);
476 checksum = hdr->ih_hcrc;
479 if (crc32 (0, (char *)data, len) != checksum) {
480 printf ("Bad Header Checksum\n");
481 SHOW_BOOT_PROGRESS (-11);
482 do_reset (cmdtp, flag, argc, argv);
485 SHOW_BOOT_PROGRESS (10);
487 print_image_hdr (hdr);
489 data = addr + sizeof(image_header_t);
494 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
495 ulong cdata = data, edata = cdata + len;
496 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
498 printf (" Verifying Checksum ... ");
500 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
502 while (cdata < edata) {
503 ulong chunk = edata - cdata;
507 csum = crc32 (csum, (char *)cdata, chunk);
512 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
513 csum = crc32 (0, (char *)data, len);
514 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
516 if (csum != hdr->ih_dcrc) {
517 printf ("Bad Data CRC\n");
518 SHOW_BOOT_PROGRESS (-12);
519 do_reset (cmdtp, flag, argc, argv);
524 SHOW_BOOT_PROGRESS (11);
526 if ((hdr->ih_os != IH_OS_LINUX) ||
527 (hdr->ih_arch != IH_CPU_PPC) ||
528 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
529 printf ("No Linux PPC Ramdisk Image\n");
530 SHOW_BOOT_PROGRESS (-13);
531 do_reset (cmdtp, flag, argc, argv);
535 * Now check if we have a multifile image
537 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
538 u_long tail = ntohl(len_ptr[0]) % 4;
541 SHOW_BOOT_PROGRESS (13);
543 /* skip kernel length and terminator */
544 data = (ulong)(&len_ptr[2]);
545 /* skip any additional image length fields */
546 for (i=1; len_ptr[i]; ++i)
548 /* add kernel length, and align */
549 data += ntohl(len_ptr[0]);
554 len = ntohl(len_ptr[1]);
560 SHOW_BOOT_PROGRESS (14);
566 debug ("No initrd\n");
570 initrd_start = (ulong)kbd - len;
571 initrd_start &= ~(4096 - 1); /* align on page */
577 * the inital ramdisk does not need to be within
578 * CFG_BOOTMAPSZ as it is not accessed until after
579 * the mm system is initialised.
581 * do the stack bottom calculation again and see if
582 * the initrd will fit just below the monitor stack
583 * bottom without overwriting the area allocated
584 * above for command line args and board info.
586 asm( "mr %0,1": "=r"(nsp) : );
587 nsp -= 2048; /* just to be sure */
589 if (nsp > initrd_high) /* limit as specified */
592 nsp &= ~(4096 - 1); /* align on page */
597 SHOW_BOOT_PROGRESS (12);
599 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
600 data, data + len - 1, len, len);
602 initrd_end = initrd_start + len;
603 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
604 initrd_start, initrd_end);
605 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
608 void *to = (void *)initrd_start;
609 void *from = (void *)data;
612 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
614 memmove (to, from, tail);
620 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
621 memmove ((void *)initrd_start, (void *)data, len);
622 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
630 debug ("## Transferring control to Linux (at address %08lx) ...\n",
633 SHOW_BOOT_PROGRESS (15);
635 #ifdef CFG_INIT_RAM_LOCK
636 unlock_ram_in_cache();
639 * Linux Kernel Parameters:
640 * r3: ptr to board info data
641 * r4: initrd_start or 0 if no initrd
642 * r5: initrd_end - unused if r4 is 0
643 * r6: Start of command line string
644 * r7: End of command line string
646 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
648 #endif /* CONFIG_PPC */
651 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
652 int argc, char *argv[],
657 DECLARE_GLOBAL_DATA_PTR;
659 image_header_t *hdr = &header;
661 void (*loader)(bd_t *, image_header_t *, char *, char *);
662 image_header_t *img_addr;
668 * Booting a (NetBSD) kernel image
670 * This process is pretty similar to a standalone application:
671 * The (first part of an multi-) image must be a stage-2 loader,
672 * which in turn is responsible for loading & invoking the actual
673 * kernel. The only differences are the parameters being passed:
674 * besides the board info strucure, the loader expects a command
675 * line, the name of the console device, and (optionally) the
676 * address of the original image header.
680 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
681 img_addr = (image_header_t *) addr;
685 #if defined (CONFIG_8xx_CONS_SMC1)
687 #elif defined (CONFIG_8xx_CONS_SMC2)
689 #elif defined (CONFIG_8xx_CONS_SCC2)
691 #elif defined (CONFIG_8xx_CONS_SCC3)
699 for (i=2, len=0 ; i<argc ; i+=1)
700 len += strlen (argv[i]) + 1;
701 cmdline = malloc (len);
703 for (i=2, len=0 ; i<argc ; i+=1) {
705 cmdline[len++] = ' ';
706 strcpy (&cmdline[len], argv[i]);
707 len += strlen (argv[i]);
709 } else if ((cmdline = getenv("bootargs")) == NULL) {
713 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
715 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
718 SHOW_BOOT_PROGRESS (15);
721 * NetBSD Stage-2 Loader Parameters:
722 * r3: ptr to board info data
725 * r6: boot args string
727 (*loader) (gd->bd, img_addr, consdev, cmdline);
730 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
732 /* Function that returns a character from the environment */
733 extern uchar (*env_get_char)(int);
736 do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
737 int argc, char *argv[],
742 DECLARE_GLOBAL_DATA_PTR;
746 int i, j, nxt, len, envno, envsz;
748 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
749 image_header_t *hdr = &header;
752 * Booting an ARTOS kernel image + application
755 /* this used to be the top of memory, but was wrong... */
757 /* get stack pointer */
758 asm volatile ("mr %0,1" : "=r"(top) );
760 debug ("## Current stack ends at 0x%08lX ", top);
762 top -= 2048; /* just to be sure */
763 if (top > CFG_BOOTMAPSZ)
767 debug ("=> set upper limit to 0x%08lX\n", top);
769 /* first check the artos specific boot args, then the linux args*/
770 if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
773 /* get length of cmdline, and place it */
775 top = (top - (len + 1)) & ~0xF;
776 cmdline = (char *)top;
777 debug ("## cmdline at 0x%08lX ", top);
781 top = (top - sizeof(bd_t)) & ~0xF;
782 debug ("## bd at 0x%08lX ", top);
784 memcpy(kbd, gd->bd, sizeof(bd_t));
786 /* first find number of env entries, and their size */
789 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
790 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
793 envsz += (nxt - i) + 1; /* plus trailing zero */
795 envno++; /* plus the terminating zero */
796 debug ("## %u envvars total size %u ", envno, envsz);
798 top = (top - sizeof(char **)*envno) & ~0xF;
799 fwenv = (char **)top;
800 debug ("## fwenv at 0x%08lX ", top);
802 top = (top - envsz) & ~0xF;
807 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
808 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
811 for (j = i; j < nxt; ++j)
812 *s++ = env_get_char(j);
815 *ss++ = NULL; /* terminate */
817 entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
818 (*entry)(kbd, cmdline, fwenv, top);
823 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
824 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
827 #ifndef CFG_HUSH_PARSER
828 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
830 if (parse_string_outer(getenv("bootcmd"),
831 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
837 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
838 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
845 return image_info (load_addr);
848 for (arg=1; arg <argc; ++arg) {
849 addr = simple_strtoul(argv[arg], NULL, 16);
850 if (image_info (addr) != 0) rcode = 1;
855 static int image_info (ulong addr)
857 ulong data, len, checksum;
858 image_header_t *hdr = &header;
860 printf ("\n## Checking Image at %08lx ...\n", addr);
862 /* Copy header so we can blank CRC field for re-calculation */
863 memmove (&header, (char *)addr, sizeof(image_header_t));
865 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
866 printf (" Bad Magic Number\n");
870 data = (ulong)&header;
871 len = sizeof(image_header_t);
873 checksum = ntohl(hdr->ih_hcrc);
876 if (crc32 (0, (char *)data, len) != checksum) {
877 printf (" Bad Header Checksum\n");
881 /* for multi-file images we need the data part, too */
882 print_image_hdr ((image_header_t *)addr);
884 data = addr + sizeof(image_header_t);
885 len = ntohl(hdr->ih_size);
887 printf (" Verifying Checksum ... ");
888 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
889 printf (" Bad Data CRC\n");
895 #endif /* CFG_CMD_IMI */
898 print_image_hdr (image_header_t *hdr)
900 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
901 time_t timestamp = (time_t)ntohl(hdr->ih_time);
905 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
906 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
907 to_tm (timestamp, &tm);
908 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
909 tm.tm_year, tm.tm_mon, tm.tm_mday,
910 tm.tm_hour, tm.tm_min, tm.tm_sec);
911 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
912 printf (" Image Type: "); print_type(hdr); printf ("\n");
913 printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
914 print_size (ntohl(hdr->ih_size), "\n");
915 printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
916 printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
918 if (hdr->ih_type == IH_TYPE_MULTI) {
921 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
923 printf (" Contents:\n");
924 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
925 printf (" Image %d: %8ld Bytes = ", i, len);
926 print_size (len, "\n");
933 print_type (image_header_t *hdr)
935 char *os, *arch, *type, *comp;
937 switch (hdr->ih_os) {
938 case IH_OS_INVALID: os = "Invalid OS"; break;
939 case IH_OS_NETBSD: os = "NetBSD"; break;
940 case IH_OS_LINUX: os = "Linux"; break;
941 case IH_OS_VXWORKS: os = "VxWorks"; break;
942 case IH_OS_QNX: os = "QNX"; break;
943 case IH_OS_U_BOOT: os = "U-Boot"; break;
944 case IH_OS_RTEMS: os = "RTEMS"; break;
946 case IH_OS_ARTOS: os = "ARTOS"; break;
948 default: os = "Unknown OS"; break;
951 switch (hdr->ih_arch) {
952 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
953 case IH_CPU_ALPHA: arch = "Alpha"; break;
954 case IH_CPU_ARM: arch = "ARM"; break;
955 case IH_CPU_I386: arch = "Intel x86"; break;
956 case IH_CPU_IA64: arch = "IA64"; break;
957 case IH_CPU_MIPS: arch = "MIPS"; break;
958 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
959 case IH_CPU_PPC: arch = "PowerPC"; break;
960 case IH_CPU_S390: arch = "IBM S390"; break;
961 case IH_CPU_SH: arch = "SuperH"; break;
962 case IH_CPU_SPARC: arch = "SPARC"; break;
963 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
964 default: arch = "Unknown Architecture"; break;
967 switch (hdr->ih_type) {
968 case IH_TYPE_INVALID: type = "Invalid Image"; break;
969 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
970 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
971 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
972 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
973 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
974 case IH_TYPE_SCRIPT: type = "Script"; break;
975 default: type = "Unknown Image"; break;
978 switch (hdr->ih_comp) {
979 case IH_COMP_NONE: comp = "uncompressed"; break;
980 case IH_COMP_GZIP: comp = "gzip compressed"; break;
981 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
982 default: comp = "unknown compression"; break;
985 printf ("%s %s %s (%s)", arch, os, type, comp);
988 #define ZALLOC_ALIGNMENT 16
990 static void *zalloc(void *x, unsigned items, unsigned size)
995 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
1002 static void zfree(void *x, void *addr, unsigned nb)
1008 #define EXTRA_FIELD 4
1010 #define COMMENT 0x10
1011 #define RESERVED 0xe0
1015 int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
1023 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
1024 printf ("Error: Bad gzipped data\n");
1027 if ((flags & EXTRA_FIELD) != 0)
1028 i = 12 + src[10] + (src[11] << 8);
1029 if ((flags & ORIG_NAME) != 0)
1030 while (src[i++] != 0)
1032 if ((flags & COMMENT) != 0)
1033 while (src[i++] != 0)
1035 if ((flags & HEAD_CRC) != 0)
1038 printf ("Error: gunzip out of data in header\n");
1044 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1045 s.outcb = (cb_func)WATCHDOG_RESET;
1048 #endif /* CONFIG_HW_WATCHDOG */
1050 r = inflateInit2(&s, -MAX_WBITS);
1052 printf ("Error: inflateInit2() returned %d\n", r);
1055 s.next_in = src + i;
1056 s.avail_in = *lenp - i;
1058 s.avail_out = dstlen;
1059 r = inflate(&s, Z_FINISH);
1060 if (r != Z_OK && r != Z_STREAM_END) {
1061 printf ("Error: inflate() returned %d\n", r);
1064 *lenp = s.next_out - (unsigned char *) dst;
1071 do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1072 ulong addr, ulong *len_ptr, int verify)
1074 DECLARE_GLOBAL_DATA_PTR;
1075 image_header_t *hdr = &header;
1076 void (*entry_point)(bd_t *);
1078 entry_point = (void (*)(bd_t *)) hdr->ih_ep;
1080 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1081 (ulong)entry_point);
1083 SHOW_BOOT_PROGRESS (15);
1087 * r3: ptr to board info data
1090 (*entry_point ) ( gd->bd );
1093 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
1095 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1096 ulong addr, ulong *len_ptr, int verify)
1098 image_header_t *hdr = &header;
1101 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1102 setenv("loadaddr", str);
1103 do_bootvx(cmdtp, 0, 0, NULL);
1107 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1108 ulong addr, ulong *len_ptr, int verify)
1110 image_header_t *hdr = &header;
1111 char *local_args[2];
1114 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1115 local_args[0] = argv[0];
1116 local_args[1] = str; /* and provide it via the arguments */
1117 do_bootelf(cmdtp, 0, 2, local_args);
1119 #endif /* CFG_CMD_ELF */