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
;
377 int initrd_copy_to_ram
= 1;
381 void (*kernel
)(bd_t
*, ulong
, ulong
, ulong
, ulong
);
382 image_header_t
*hdr
= &header
;
384 if ((s
= getenv ("initrd_high")) != NULL
) {
385 /* a value of "no" or a similar string will act like 0,
386 * turning the "load high" feature off. This is intentional.
388 initrd_high
= simple_strtoul(s
, NULL
, 16);
389 if (initrd_high
== ~0)
390 initrd_copy_to_ram
= 0;
391 } else { /* not set, no restrictions to load high */
395 #ifdef CONFIG_LOGBUFFER
397 /* Prevent initrd from overwriting logbuffer */
398 if (initrd_high
< (kbd
->bi_memsize
-LOGBUFF_LEN
-LOGBUFF_OVERHEAD
))
399 initrd_high
= kbd
->bi_memsize
-LOGBUFF_LEN
-LOGBUFF_OVERHEAD
;
400 debug ("## Logbuffer at 0x%08lX ", kbd
->bi_memsize
-LOGBUFF_LEN
);
404 * Booting a (Linux) kernel image
406 * Allocate space for command line and board info - the
407 * address should be as high as possible within the reach of
408 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
409 * memory, which means far enough below the current stack
413 asm( "mr %0,1": "=r"(sp
) : );
415 debug ("## Current stack ends at 0x%08lX ", sp
);
417 sp
-= 2048; /* just to be sure */
418 if (sp
> CFG_BOOTMAPSZ
)
422 debug ("=> set upper limit to 0x%08lX\n", sp
);
424 cmdline
= (char *)((sp
- CFG_BARGSIZE
) & ~0xF);
425 kbd
= (bd_t
*)(((ulong
)cmdline
- sizeof(bd_t
)) & ~0xF);
427 if ((s
= getenv("bootargs")) == NULL
)
432 cmd_start
= (ulong
)&cmdline
[0];
433 cmd_end
= cmd_start
+ strlen(cmdline
);
438 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start
, cmd_end
);
440 do_bdinfo (NULL
, 0, 0, NULL
);
443 if ((s
= getenv ("clocks_in_mhz")) != NULL
) {
444 /* convert all clock information to MHz */
445 kbd
->bi_intfreq
/= 1000000L;
446 kbd
->bi_busfreq
/= 1000000L;
447 #if defined(CONFIG_8260)
448 kbd
->bi_cpmfreq
/= 1000000L;
449 kbd
->bi_brgfreq
/= 1000000L;
450 kbd
->bi_sccfreq
/= 1000000L;
451 kbd
->bi_vco
/= 1000000L;
452 #endif /* CONFIG_8260 */
455 kernel
= (void (*)(bd_t
*, ulong
, ulong
, ulong
, ulong
))hdr
->ih_ep
;
458 * Check if there is an initrd image
461 SHOW_BOOT_PROGRESS (9);
463 addr
= simple_strtoul(argv
[2], NULL
, 16);
465 printf ("## Loading RAMDisk Image at %08lx ...\n", addr
);
467 /* Copy header so we can blank CRC field for re-calculation */
468 memmove (&header
, (char *)addr
, sizeof(image_header_t
));
470 if (hdr
->ih_magic
!= IH_MAGIC
) {
471 printf ("Bad Magic Number\n");
472 SHOW_BOOT_PROGRESS (-10);
473 do_reset (cmdtp
, flag
, argc
, argv
);
476 data
= (ulong
)&header
;
477 len
= sizeof(image_header_t
);
479 checksum
= hdr
->ih_hcrc
;
482 if (crc32 (0, (char *)data
, len
) != checksum
) {
483 printf ("Bad Header Checksum\n");
484 SHOW_BOOT_PROGRESS (-11);
485 do_reset (cmdtp
, flag
, argc
, argv
);
488 SHOW_BOOT_PROGRESS (10);
490 print_image_hdr (hdr
);
492 data
= addr
+ sizeof(image_header_t
);
497 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
498 ulong cdata
= data
, edata
= cdata
+ len
;
499 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
501 printf (" Verifying Checksum ... ");
503 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
505 while (cdata
< edata
) {
506 ulong chunk
= edata
- cdata
;
510 csum
= crc32 (csum
, (char *)cdata
, chunk
);
515 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
516 csum
= crc32 (0, (char *)data
, len
);
517 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
519 if (csum
!= hdr
->ih_dcrc
) {
520 printf ("Bad Data CRC\n");
521 SHOW_BOOT_PROGRESS (-12);
522 do_reset (cmdtp
, flag
, argc
, argv
);
527 SHOW_BOOT_PROGRESS (11);
529 if ((hdr
->ih_os
!= IH_OS_LINUX
) ||
530 (hdr
->ih_arch
!= IH_CPU_PPC
) ||
531 (hdr
->ih_type
!= IH_TYPE_RAMDISK
) ) {
532 printf ("No Linux PPC Ramdisk Image\n");
533 SHOW_BOOT_PROGRESS (-13);
534 do_reset (cmdtp
, flag
, argc
, argv
);
538 * Now check if we have a multifile image
540 } else if ((hdr
->ih_type
==IH_TYPE_MULTI
) && (len_ptr
[1])) {
541 u_long tail
= ntohl(len_ptr
[0]) % 4;
544 SHOW_BOOT_PROGRESS (13);
546 /* skip kernel length and terminator */
547 data
= (ulong
)(&len_ptr
[2]);
548 /* skip any additional image length fields */
549 for (i
=1; len_ptr
[i
]; ++i
)
551 /* add kernel length, and align */
552 data
+= ntohl(len_ptr
[0]);
557 len
= ntohl(len_ptr
[1]);
563 SHOW_BOOT_PROGRESS (14);
569 debug ("No initrd\n");
573 if (!initrd_copy_to_ram
) { /* zero-copy ramdisk support */
575 initrd_end
= initrd_start
+ len
;
577 initrd_start
= (ulong
)kbd
- len
;
578 initrd_start
&= ~(4096 - 1); /* align on page */
584 * the inital ramdisk does not need to be within
585 * CFG_BOOTMAPSZ as it is not accessed until after
586 * the mm system is initialised.
588 * do the stack bottom calculation again and see if
589 * the initrd will fit just below the monitor stack
590 * bottom without overwriting the area allocated
591 * above for command line args and board info.
593 asm( "mr %0,1": "=r"(nsp
) : );
594 nsp
-= 2048; /* just to be sure */
596 if (nsp
> initrd_high
) /* limit as specified */
599 nsp
&= ~(4096 - 1); /* align on page */
604 SHOW_BOOT_PROGRESS (12);
606 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
607 data
, data
+ len
- 1, len
, len
);
609 initrd_end
= initrd_start
+ len
;
610 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
611 initrd_start
, initrd_end
);
612 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
615 void *to
= (void *)initrd_start
;
616 void *from
= (void *)data
;
619 size_t tail
= (l
> CHUNKSZ
) ? CHUNKSZ
: l
;
621 memmove (to
, from
, tail
);
627 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
628 memmove ((void *)initrd_start
, (void *)data
, len
);
629 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
638 debug ("## Transferring control to Linux (at address %08lx) ...\n",
641 SHOW_BOOT_PROGRESS (15);
643 #ifdef CFG_INIT_RAM_LOCK
644 unlock_ram_in_cache();
647 * Linux Kernel Parameters:
648 * r3: ptr to board info data
649 * r4: initrd_start or 0 if no initrd
650 * r5: initrd_end - unused if r4 is 0
651 * r6: Start of command line string
652 * r7: End of command line string
654 (*kernel
) (kbd
, initrd_start
, initrd_end
, cmd_start
, cmd_end
);
656 #endif /* CONFIG_PPC */
659 do_bootm_netbsd (cmd_tbl_t
*cmdtp
, int flag
,
660 int argc
, char *argv
[],
665 DECLARE_GLOBAL_DATA_PTR
;
667 image_header_t
*hdr
= &header
;
669 void (*loader
)(bd_t
*, image_header_t
*, char *, char *);
670 image_header_t
*img_addr
;
676 * Booting a (NetBSD) kernel image
678 * This process is pretty similar to a standalone application:
679 * The (first part of an multi-) image must be a stage-2 loader,
680 * which in turn is responsible for loading & invoking the actual
681 * kernel. The only differences are the parameters being passed:
682 * besides the board info strucure, the loader expects a command
683 * line, the name of the console device, and (optionally) the
684 * address of the original image header.
688 if ((hdr
->ih_type
==IH_TYPE_MULTI
) && (len_ptr
[1]))
689 img_addr
= (image_header_t
*) addr
;
693 #if defined (CONFIG_8xx_CONS_SMC1)
695 #elif defined (CONFIG_8xx_CONS_SMC2)
697 #elif defined (CONFIG_8xx_CONS_SCC2)
699 #elif defined (CONFIG_8xx_CONS_SCC3)
707 for (i
=2, len
=0 ; i
<argc
; i
+=1)
708 len
+= strlen (argv
[i
]) + 1;
709 cmdline
= malloc (len
);
711 for (i
=2, len
=0 ; i
<argc
; i
+=1) {
713 cmdline
[len
++] = ' ';
714 strcpy (&cmdline
[len
], argv
[i
]);
715 len
+= strlen (argv
[i
]);
717 } else if ((cmdline
= getenv("bootargs")) == NULL
) {
721 loader
= (void (*)(bd_t
*, image_header_t
*, char *, char *)) hdr
->ih_ep
;
723 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
726 SHOW_BOOT_PROGRESS (15);
729 * NetBSD Stage-2 Loader Parameters:
730 * r3: ptr to board info data
733 * r6: boot args string
735 (*loader
) (gd
->bd
, img_addr
, consdev
, cmdline
);
738 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
740 /* Function that returns a character from the environment */
741 extern uchar (*env_get_char
)(int);
744 do_bootm_artos (cmd_tbl_t
*cmdtp
, int flag
,
745 int argc
, char *argv
[],
750 DECLARE_GLOBAL_DATA_PTR
;
754 int i
, j
, nxt
, len
, envno
, envsz
;
756 void (*entry
)(bd_t
*bd
, char *cmdline
, char **fwenv
, ulong top
);
757 image_header_t
*hdr
= &header
;
760 * Booting an ARTOS kernel image + application
763 /* this used to be the top of memory, but was wrong... */
765 /* get stack pointer */
766 asm volatile ("mr %0,1" : "=r"(top
) );
768 debug ("## Current stack ends at 0x%08lX ", top
);
770 top
-= 2048; /* just to be sure */
771 if (top
> CFG_BOOTMAPSZ
)
775 debug ("=> set upper limit to 0x%08lX\n", top
);
777 /* first check the artos specific boot args, then the linux args*/
778 if ((s
= getenv("abootargs")) == NULL
&& (s
= getenv("bootargs")) == NULL
)
781 /* get length of cmdline, and place it */
783 top
= (top
- (len
+ 1)) & ~0xF;
784 cmdline
= (char *)top
;
785 debug ("## cmdline at 0x%08lX ", top
);
789 top
= (top
- sizeof(bd_t
)) & ~0xF;
790 debug ("## bd at 0x%08lX ", top
);
792 memcpy(kbd
, gd
->bd
, sizeof(bd_t
));
794 /* first find number of env entries, and their size */
797 for (i
= 0; env_get_char(i
) != '\0'; i
= nxt
+ 1) {
798 for (nxt
= i
; env_get_char(nxt
) != '\0'; ++nxt
)
801 envsz
+= (nxt
- i
) + 1; /* plus trailing zero */
803 envno
++; /* plus the terminating zero */
804 debug ("## %u envvars total size %u ", envno
, envsz
);
806 top
= (top
- sizeof(char **)*envno
) & ~0xF;
807 fwenv
= (char **)top
;
808 debug ("## fwenv at 0x%08lX ", top
);
810 top
= (top
- envsz
) & ~0xF;
815 for (i
= 0; env_get_char(i
) != '\0'; i
= nxt
+ 1) {
816 for (nxt
= i
; env_get_char(nxt
) != '\0'; ++nxt
)
819 for (j
= i
; j
< nxt
; ++j
)
820 *s
++ = env_get_char(j
);
823 *ss
++ = NULL
; /* terminate */
825 entry
= (void (*)(bd_t
*, char *, char **, ulong
))ntohl(hdr
->ih_ep
);
826 (*entry
)(kbd
, cmdline
, fwenv
, top
);
831 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
832 int do_bootd (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
835 #ifndef CFG_HUSH_PARSER
836 if (run_command (getenv ("bootcmd"), flag
) < 0) rcode
= 1;
838 if (parse_string_outer(getenv("bootcmd"),
839 FLAG_PARSE_SEMICOLON
| FLAG_EXIT_FROM_LOOP
) != 0 ) rcode
= 1;
845 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
846 int do_iminfo ( cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
853 return image_info (load_addr
);
856 for (arg
=1; arg
<argc
; ++arg
) {
857 addr
= simple_strtoul(argv
[arg
], NULL
, 16);
858 if (image_info (addr
) != 0) rcode
= 1;
863 static int image_info (ulong addr
)
865 ulong data
, len
, checksum
;
866 image_header_t
*hdr
= &header
;
868 printf ("\n## Checking Image at %08lx ...\n", addr
);
870 /* Copy header so we can blank CRC field for re-calculation */
871 memmove (&header
, (char *)addr
, sizeof(image_header_t
));
873 if (ntohl(hdr
->ih_magic
) != IH_MAGIC
) {
874 printf (" Bad Magic Number\n");
878 data
= (ulong
)&header
;
879 len
= sizeof(image_header_t
);
881 checksum
= ntohl(hdr
->ih_hcrc
);
884 if (crc32 (0, (char *)data
, len
) != checksum
) {
885 printf (" Bad Header Checksum\n");
889 /* for multi-file images we need the data part, too */
890 print_image_hdr ((image_header_t
*)addr
);
892 data
= addr
+ sizeof(image_header_t
);
893 len
= ntohl(hdr
->ih_size
);
895 printf (" Verifying Checksum ... ");
896 if (crc32 (0, (char *)data
, len
) != ntohl(hdr
->ih_dcrc
)) {
897 printf (" Bad Data CRC\n");
903 #endif /* CFG_CMD_IMI */
906 print_image_hdr (image_header_t
*hdr
)
908 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
909 time_t timestamp
= (time_t)ntohl(hdr
->ih_time
);
913 printf (" Image Name: %.*s\n", IH_NMLEN
, hdr
->ih_name
);
914 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
915 to_tm (timestamp
, &tm
);
916 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
917 tm
.tm_year
, tm
.tm_mon
, tm
.tm_mday
,
918 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
);
919 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
920 printf (" Image Type: "); print_type(hdr
); printf ("\n");
921 printf (" Data Size: %d Bytes = ", ntohl(hdr
->ih_size
));
922 print_size (ntohl(hdr
->ih_size
), "\n");
923 printf (" Load Address: %08x\n", ntohl(hdr
->ih_load
));
924 printf (" Entry Point: %08x\n", ntohl(hdr
->ih_ep
));
926 if (hdr
->ih_type
== IH_TYPE_MULTI
) {
929 ulong
*len_ptr
= (ulong
*)((ulong
)hdr
+ sizeof(image_header_t
));
931 printf (" Contents:\n");
932 for (i
=0; (len
= ntohl(*len_ptr
)); ++i
, ++len_ptr
) {
933 printf (" Image %d: %8ld Bytes = ", i
, len
);
934 print_size (len
, "\n");
941 print_type (image_header_t
*hdr
)
943 char *os
, *arch
, *type
, *comp
;
945 switch (hdr
->ih_os
) {
946 case IH_OS_INVALID
: os
= "Invalid OS"; break;
947 case IH_OS_NETBSD
: os
= "NetBSD"; break;
948 case IH_OS_LINUX
: os
= "Linux"; break;
949 case IH_OS_VXWORKS
: os
= "VxWorks"; break;
950 case IH_OS_QNX
: os
= "QNX"; break;
951 case IH_OS_U_BOOT
: os
= "U-Boot"; break;
952 case IH_OS_RTEMS
: os
= "RTEMS"; break;
954 case IH_OS_ARTOS
: os
= "ARTOS"; break;
956 default: os
= "Unknown OS"; break;
959 switch (hdr
->ih_arch
) {
960 case IH_CPU_INVALID
: arch
= "Invalid CPU"; break;
961 case IH_CPU_ALPHA
: arch
= "Alpha"; break;
962 case IH_CPU_ARM
: arch
= "ARM"; break;
963 case IH_CPU_I386
: arch
= "Intel x86"; break;
964 case IH_CPU_IA64
: arch
= "IA64"; break;
965 case IH_CPU_MIPS
: arch
= "MIPS"; break;
966 case IH_CPU_MIPS64
: arch
= "MIPS 64 Bit"; break;
967 case IH_CPU_PPC
: arch
= "PowerPC"; break;
968 case IH_CPU_S390
: arch
= "IBM S390"; break;
969 case IH_CPU_SH
: arch
= "SuperH"; break;
970 case IH_CPU_SPARC
: arch
= "SPARC"; break;
971 case IH_CPU_SPARC64
: arch
= "SPARC 64 Bit"; break;
972 default: arch
= "Unknown Architecture"; break;
975 switch (hdr
->ih_type
) {
976 case IH_TYPE_INVALID
: type
= "Invalid Image"; break;
977 case IH_TYPE_STANDALONE
:type
= "Standalone Program"; break;
978 case IH_TYPE_KERNEL
: type
= "Kernel Image"; break;
979 case IH_TYPE_RAMDISK
: type
= "RAMDisk Image"; break;
980 case IH_TYPE_MULTI
: type
= "Multi-File Image"; break;
981 case IH_TYPE_FIRMWARE
: type
= "Firmware"; break;
982 case IH_TYPE_SCRIPT
: type
= "Script"; break;
983 default: type
= "Unknown Image"; break;
986 switch (hdr
->ih_comp
) {
987 case IH_COMP_NONE
: comp
= "uncompressed"; break;
988 case IH_COMP_GZIP
: comp
= "gzip compressed"; break;
989 case IH_COMP_BZIP2
: comp
= "bzip2 compressed"; break;
990 default: comp
= "unknown compression"; break;
993 printf ("%s %s %s (%s)", arch
, os
, type
, comp
);
996 #define ZALLOC_ALIGNMENT 16
998 static void *zalloc(void *x
, unsigned items
, unsigned size
)
1003 size
= (size
+ ZALLOC_ALIGNMENT
- 1) & ~(ZALLOC_ALIGNMENT
- 1);
1010 static void zfree(void *x
, void *addr
, unsigned nb
)
1016 #define EXTRA_FIELD 4
1018 #define COMMENT 0x10
1019 #define RESERVED 0xe0
1023 int gunzip(void *dst
, int dstlen
, unsigned char *src
, int *lenp
)
1031 if (src
[2] != DEFLATED
|| (flags
& RESERVED
) != 0) {
1032 printf ("Error: Bad gzipped data\n");
1035 if ((flags
& EXTRA_FIELD
) != 0)
1036 i
= 12 + src
[10] + (src
[11] << 8);
1037 if ((flags
& ORIG_NAME
) != 0)
1038 while (src
[i
++] != 0)
1040 if ((flags
& COMMENT
) != 0)
1041 while (src
[i
++] != 0)
1043 if ((flags
& HEAD_CRC
) != 0)
1046 printf ("Error: gunzip out of data in header\n");
1052 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1053 s
.outcb
= (cb_func
)WATCHDOG_RESET
;
1056 #endif /* CONFIG_HW_WATCHDOG */
1058 r
= inflateInit2(&s
, -MAX_WBITS
);
1060 printf ("Error: inflateInit2() returned %d\n", r
);
1063 s
.next_in
= src
+ i
;
1064 s
.avail_in
= *lenp
- i
;
1066 s
.avail_out
= dstlen
;
1067 r
= inflate(&s
, Z_FINISH
);
1068 if (r
!= Z_OK
&& r
!= Z_STREAM_END
) {
1069 printf ("Error: inflate() returned %d\n", r
);
1072 *lenp
= s
.next_out
- (unsigned char *) dst
;
1079 do_bootm_rtems (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
1080 ulong addr
, ulong
*len_ptr
, int verify
)
1082 DECLARE_GLOBAL_DATA_PTR
;
1083 image_header_t
*hdr
= &header
;
1084 void (*entry_point
)(bd_t
*);
1086 entry_point
= (void (*)(bd_t
*)) hdr
->ih_ep
;
1088 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1089 (ulong
)entry_point
);
1091 SHOW_BOOT_PROGRESS (15);
1095 * r3: ptr to board info data
1098 (*entry_point
) ( gd
->bd
);
1101 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
1103 do_bootm_vxworks (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
1104 ulong addr
, ulong
*len_ptr
, int verify
)
1106 image_header_t
*hdr
= &header
;
1109 sprintf(str
, "%x", hdr
->ih_ep
); /* write entry-point into string */
1110 setenv("loadaddr", str
);
1111 do_bootvx(cmdtp
, 0, 0, NULL
);
1115 do_bootm_qnxelf (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
1116 ulong addr
, ulong
*len_ptr
, int verify
)
1118 image_header_t
*hdr
= &header
;
1119 char *local_args
[2];
1122 sprintf(str
, "%x", hdr
->ih_ep
); /* write entry-point into string */
1123 local_args
[0] = argv
[0];
1124 local_args
[1] = str
; /* and provide it via the arguments */
1125 do_bootelf(cmdtp
, 0, 2, local_args
);
1127 #endif /* CFG_CMD_ELF */