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,
33 #include <environment.h>
34 #include <asm/byteorder.h>
37 extern int do_reset (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
39 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
43 #ifdef CFG_HUSH_PARSER
47 #ifdef CONFIG_SHOW_BOOT_PROGRESS
48 # include <status_led.h>
49 # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
51 # define SHOW_BOOT_PROGRESS(arg)
54 #ifdef CFG_INIT_RAM_LOCK
55 #include <asm/cache.h>
58 #ifdef CONFIG_LOGBUFFER
62 #ifdef CONFIG_HAS_DATAFLASH
63 #include <dataflash.h>
67 * Some systems (for example LWMON) have very short watchdog periods;
68 * we must make sure to split long operations like memmove() or
69 * crc32() into reasonable chunks.
71 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
72 # define CHUNKSZ (64 * 1024)
75 int gunzip (void *, int, unsigned char *, int *);
77 static void *zalloc(void *, unsigned, unsigned);
78 static void zfree(void *, void *, unsigned);
80 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
81 static int image_info (unsigned long addr
);
84 #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
86 extern flash_info_t flash_info
[CFG_MAX_FLASH_BANKS
]; /* info for FLASH chips */
87 static int do_imls (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
90 static void print_type (image_header_t
*hdr
);
93 image_header_t
*fake_header(image_header_t
*hdr
, void *ptr
, int size
);
97 * Continue booting an OS image; caller already has:
98 * - copied image header to global variable `header'
99 * - checked header magic number, checksums (both header & image),
100 * - verified image architecture (PPC) and type (KERNEL or MULTI),
101 * - loaded (first part of) image to header load address,
102 * - disabled interrupts.
104 typedef void boot_os_Fcn (cmd_tbl_t
*cmdtp
, int flag
,
105 int argc
, char *argv
[],
106 ulong addr
, /* of image to boot */
107 ulong
*len_ptr
, /* multi-file image length table */
108 int verify
); /* getenv("verify")[0] != 'n' */
111 extern int do_bdinfo ( cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
115 static boot_os_Fcn do_bootm_linux
;
117 extern boot_os_Fcn do_bootm_linux
;
119 static boot_os_Fcn do_bootm_netbsd
;
120 static boot_os_Fcn do_bootm_rtems
;
121 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
122 static boot_os_Fcn do_bootm_vxworks
;
123 static boot_os_Fcn do_bootm_qnxelf
;
124 int do_bootvx ( cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[] );
125 int do_bootelf (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[] );
126 #endif /* CFG_CMD_ELF */
127 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
128 static boot_os_Fcn do_bootm_artos
;
130 #ifdef CONFIG_LYNXKDI
131 static boot_os_Fcn do_bootm_lynxkdi
;
132 extern void lynxkdi_boot( image_header_t
* );
135 image_header_t header
;
137 ulong load_addr
= CFG_LOAD_ADDR
; /* Default Load Address */
139 int do_bootm (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
143 ulong data
, len
, checksum
;
147 int (*appl
)(cmd_tbl_t
*, int, int, char *[]);
148 image_header_t
*hdr
= &header
;
150 s
= getenv ("verify");
151 verify
= (s
&& (*s
== 'n')) ? 0 : 1;
156 addr
= simple_strtoul(argv
[1], NULL
, 16);
159 SHOW_BOOT_PROGRESS (1);
160 printf ("## Booting image at %08lx ...\n", addr
);
162 /* Copy header so we can blank CRC field for re-calculation */
163 #ifdef CONFIG_HAS_DATAFLASH
164 if (addr_dataflash(addr
)){
165 read_dataflash(addr
, sizeof(image_header_t
), (char *)&header
);
168 memmove (&header
, (char *)addr
, sizeof(image_header_t
));
170 if (ntohl(hdr
->ih_magic
) != IH_MAGIC
) {
171 #ifdef __I386__ /* correct image format not implemented yet - fake it */
172 if (fake_header(hdr
, (void*)addr
, -1) != NULL
) {
173 /* to compensate for the addition below */
174 addr
-= sizeof(image_header_t
);
176 * fake_header() does not fake the data crc
180 #endif /* __I386__ */
182 printf ("Bad Magic Number\n");
183 SHOW_BOOT_PROGRESS (-1);
187 SHOW_BOOT_PROGRESS (2);
189 data
= (ulong
)&header
;
190 len
= sizeof(image_header_t
);
192 checksum
= ntohl(hdr
->ih_hcrc
);
195 if (crc32 (0, (char *)data
, len
) != checksum
) {
196 printf ("Bad Header Checksum\n");
197 SHOW_BOOT_PROGRESS (-2);
200 SHOW_BOOT_PROGRESS (3);
202 /* for multi-file images we need the data part, too */
203 print_image_hdr (hdr
);
205 data
= addr
+ sizeof(image_header_t
);
206 len
= ntohl(hdr
->ih_size
);
208 #ifdef CONFIG_HAS_DATAFLASH
209 if (addr_dataflash(addr
)){
210 read_dataflash(data
, len
, (char *)CFG_LOAD_ADDR
);
211 data
= CFG_LOAD_ADDR
;
216 printf (" Verifying Checksum ... ");
217 if (crc32 (0, (char *)data
, len
) != ntohl(hdr
->ih_dcrc
)) {
218 printf ("Bad Data CRC\n");
219 SHOW_BOOT_PROGRESS (-3);
224 SHOW_BOOT_PROGRESS (4);
226 len_ptr
= (ulong
*)data
;
229 if (hdr
->ih_arch
!= IH_CPU_PPC
)
230 #elif defined(__ARM__)
231 if (hdr
->ih_arch
!= IH_CPU_ARM
)
232 #elif defined(__I386__)
233 if (hdr
->ih_arch
!= IH_CPU_I386
)
234 #elif defined(__mips__)
235 if (hdr
->ih_arch
!= IH_CPU_MIPS
)
237 # error Unknown CPU type
240 printf ("Unsupported Architecture 0x%x\n", hdr
->ih_arch
);
241 SHOW_BOOT_PROGRESS (-4);
244 SHOW_BOOT_PROGRESS (5);
246 switch (hdr
->ih_type
) {
247 case IH_TYPE_STANDALONE
: name
= "Standalone Application";
249 case IH_TYPE_KERNEL
: name
= "Kernel Image";
251 case IH_TYPE_MULTI
: name
= "Multi-File Image";
252 len
= ntohl(len_ptr
[0]);
253 /* OS kernel is always the first image */
254 data
+= 8; /* kernel_len + terminator */
255 for (i
=1; len_ptr
[i
]; ++i
)
258 default: printf ("Wrong Image Type for %s command\n", cmdtp
->name
);
259 SHOW_BOOT_PROGRESS (-5);
262 SHOW_BOOT_PROGRESS (6);
265 * We have reached the point of no return: we are going to
266 * overwrite all exception vector code, so we cannot easily
267 * recover from any failures any more...
270 iflag
= disable_interrupts();
272 #ifdef CONFIG_AMIGAONEG3SE
274 * We've possible left the caches enabled during
275 * bios emulation, so turn them off again
278 invalidate_l1_instruction_cache();
283 switch (hdr
->ih_comp
) {
285 if(ntohl(hdr
->ih_load
) == addr
) {
286 printf (" XIP %s ... ", name
);
288 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
290 void *to
= (void *)ntohl(hdr
->ih_load
);
291 void *from
= (void *)data
;
293 printf (" Loading %s ... ", name
);
296 size_t tail
= (l
> CHUNKSZ
) ? CHUNKSZ
: l
;
298 memmove (to
, from
, tail
);
303 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
304 memmove ((void *) ntohl(hdr
->ih_load
), (uchar
*)data
, len
);
305 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
309 printf (" Uncompressing %s ... ", name
);
310 if (gunzip ((void *)ntohl(hdr
->ih_load
), 0x400000,
311 (uchar
*)data
, (int *)&len
) != 0) {
312 printf ("GUNZIP ERROR - must RESET board to recover\n");
313 SHOW_BOOT_PROGRESS (-6);
314 do_reset (cmdtp
, flag
, argc
, argv
);
320 printf ("Unimplemented compression type %d\n", hdr
->ih_comp
);
321 SHOW_BOOT_PROGRESS (-7);
325 SHOW_BOOT_PROGRESS (7);
327 switch (hdr
->ih_type
) {
328 case IH_TYPE_STANDALONE
:
332 /* load (and uncompress), but don't start if "autostart"
335 if (((s
= getenv("autostart")) != NULL
) && (strcmp(s
,"no") == 0))
337 appl
= (int (*)(cmd_tbl_t
*, int, int, char *[]))ntohl(hdr
->ih_ep
);
338 (*appl
)(cmdtp
, flag
, argc
-1, &argv
[1]);
347 printf ("Can't boot image type %d\n", hdr
->ih_type
);
348 SHOW_BOOT_PROGRESS (-8);
351 SHOW_BOOT_PROGRESS (8);
353 switch (hdr
->ih_os
) {
354 default: /* handled by (original) Linux case */
356 do_bootm_linux (cmdtp
, flag
, argc
, argv
,
357 addr
, len_ptr
, verify
);
360 do_bootm_netbsd (cmdtp
, flag
, argc
, argv
,
361 addr
, len_ptr
, verify
);
364 #ifdef CONFIG_LYNXKDI
366 do_bootm_lynxkdi (cmdtp
, flag
, argc
, argv
,
367 addr
, len_ptr
, verify
);
372 do_bootm_rtems (cmdtp
, flag
, argc
, argv
,
373 addr
, len_ptr
, verify
);
376 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
378 do_bootm_vxworks (cmdtp
, flag
, argc
, argv
,
379 addr
, len_ptr
, verify
);
382 do_bootm_qnxelf (cmdtp
, flag
, argc
, argv
,
383 addr
, len_ptr
, verify
);
385 #endif /* CFG_CMD_ELF */
388 do_bootm_artos (cmdtp
, flag
, argc
, argv
,
389 addr
, len_ptr
, verify
);
394 SHOW_BOOT_PROGRESS (-9);
396 printf ("\n## Control returned to monitor - resetting...\n");
397 do_reset (cmdtp
, flag
, argc
, argv
);
403 bootm
, CFG_MAXARGS
, 1, do_bootm
,
404 "bootm - boot application image from memory\n",
405 "[addr [arg ...]]\n - boot application image stored in memory\n"
406 " passing arguments 'arg ...'; when booting a Linux kernel,\n"
407 " 'arg' can be the address of an initrd image\n"
412 do_bootm_linux (cmd_tbl_t
*cmdtp
, int flag
,
413 int argc
, char *argv
[],
418 DECLARE_GLOBAL_DATA_PTR
;
422 ulong initrd_start
, initrd_end
;
423 ulong cmd_start
, cmd_end
;
426 int initrd_copy_to_ram
= 1;
430 void (*kernel
)(bd_t
*, ulong
, ulong
, ulong
, ulong
);
431 image_header_t
*hdr
= &header
;
433 if ((s
= getenv ("initrd_high")) != NULL
) {
434 /* a value of "no" or a similar string will act like 0,
435 * turning the "load high" feature off. This is intentional.
437 initrd_high
= simple_strtoul(s
, NULL
, 16);
438 if (initrd_high
== ~0)
439 initrd_copy_to_ram
= 0;
440 } else { /* not set, no restrictions to load high */
444 #ifdef CONFIG_LOGBUFFER
446 /* Prevent initrd from overwriting logbuffer */
447 if (initrd_high
< (kbd
->bi_memsize
-LOGBUFF_LEN
-LOGBUFF_OVERHEAD
))
448 initrd_high
= kbd
->bi_memsize
-LOGBUFF_LEN
-LOGBUFF_OVERHEAD
;
449 debug ("## Logbuffer at 0x%08lX ", kbd
->bi_memsize
-LOGBUFF_LEN
);
453 * Booting a (Linux) kernel image
455 * Allocate space for command line and board info - the
456 * address should be as high as possible within the reach of
457 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
458 * memory, which means far enough below the current stack
462 asm( "mr %0,1": "=r"(sp
) : );
464 debug ("## Current stack ends at 0x%08lX ", sp
);
466 sp
-= 2048; /* just to be sure */
467 if (sp
> CFG_BOOTMAPSZ
)
471 debug ("=> set upper limit to 0x%08lX\n", sp
);
473 cmdline
= (char *)((sp
- CFG_BARGSIZE
) & ~0xF);
474 kbd
= (bd_t
*)(((ulong
)cmdline
- sizeof(bd_t
)) & ~0xF);
476 if ((s
= getenv("bootargs")) == NULL
)
481 cmd_start
= (ulong
)&cmdline
[0];
482 cmd_end
= cmd_start
+ strlen(cmdline
);
487 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start
, cmd_end
);
489 do_bdinfo (NULL
, 0, 0, NULL
);
492 if ((s
= getenv ("clocks_in_mhz")) != NULL
) {
493 /* convert all clock information to MHz */
494 kbd
->bi_intfreq
/= 1000000L;
495 kbd
->bi_busfreq
/= 1000000L;
496 #if defined(CONFIG_8260)
497 kbd
->bi_cpmfreq
/= 1000000L;
498 kbd
->bi_brgfreq
/= 1000000L;
499 kbd
->bi_sccfreq
/= 1000000L;
500 kbd
->bi_vco
/= 1000000L;
501 #endif /* CONFIG_8260 */
502 #if defined(CONFIG_MPC5XXXX)
503 kbd
->bi_ipbfreq
/= 1000000L;
504 kbd
->bi_pcifreq
/= 1000000L;
505 #endif /* CONFIG_MPC5XXXX */
508 kernel
= (void (*)(bd_t
*, ulong
, ulong
, ulong
, ulong
))hdr
->ih_ep
;
511 * Check if there is an initrd image
514 SHOW_BOOT_PROGRESS (9);
516 addr
= simple_strtoul(argv
[2], NULL
, 16);
518 printf ("## Loading RAMDisk Image at %08lx ...\n", addr
);
520 /* Copy header so we can blank CRC field for re-calculation */
521 memmove (&header
, (char *)addr
, sizeof(image_header_t
));
523 if (hdr
->ih_magic
!= IH_MAGIC
) {
524 printf ("Bad Magic Number\n");
525 SHOW_BOOT_PROGRESS (-10);
526 do_reset (cmdtp
, flag
, argc
, argv
);
529 data
= (ulong
)&header
;
530 len
= sizeof(image_header_t
);
532 checksum
= hdr
->ih_hcrc
;
535 if (crc32 (0, (char *)data
, len
) != checksum
) {
536 printf ("Bad Header Checksum\n");
537 SHOW_BOOT_PROGRESS (-11);
538 do_reset (cmdtp
, flag
, argc
, argv
);
541 SHOW_BOOT_PROGRESS (10);
543 print_image_hdr (hdr
);
545 data
= addr
+ sizeof(image_header_t
);
550 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
551 ulong cdata
= data
, edata
= cdata
+ len
;
552 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
554 printf (" Verifying Checksum ... ");
556 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
558 while (cdata
< edata
) {
559 ulong chunk
= edata
- cdata
;
563 csum
= crc32 (csum
, (char *)cdata
, chunk
);
568 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
569 csum
= crc32 (0, (char *)data
, len
);
570 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
572 if (csum
!= hdr
->ih_dcrc
) {
573 printf ("Bad Data CRC\n");
574 SHOW_BOOT_PROGRESS (-12);
575 do_reset (cmdtp
, flag
, argc
, argv
);
580 SHOW_BOOT_PROGRESS (11);
582 if ((hdr
->ih_os
!= IH_OS_LINUX
) ||
583 (hdr
->ih_arch
!= IH_CPU_PPC
) ||
584 (hdr
->ih_type
!= IH_TYPE_RAMDISK
) ) {
585 printf ("No Linux PPC Ramdisk Image\n");
586 SHOW_BOOT_PROGRESS (-13);
587 do_reset (cmdtp
, flag
, argc
, argv
);
591 * Now check if we have a multifile image
593 } else if ((hdr
->ih_type
==IH_TYPE_MULTI
) && (len_ptr
[1])) {
594 u_long tail
= ntohl(len_ptr
[0]) % 4;
597 SHOW_BOOT_PROGRESS (13);
599 /* skip kernel length and terminator */
600 data
= (ulong
)(&len_ptr
[2]);
601 /* skip any additional image length fields */
602 for (i
=1; len_ptr
[i
]; ++i
)
604 /* add kernel length, and align */
605 data
+= ntohl(len_ptr
[0]);
610 len
= ntohl(len_ptr
[1]);
616 SHOW_BOOT_PROGRESS (14);
622 debug ("No initrd\n");
626 if (!initrd_copy_to_ram
) { /* zero-copy ramdisk support */
628 initrd_end
= initrd_start
+ len
;
630 initrd_start
= (ulong
)kbd
- len
;
631 initrd_start
&= ~(4096 - 1); /* align on page */
637 * the inital ramdisk does not need to be within
638 * CFG_BOOTMAPSZ as it is not accessed until after
639 * the mm system is initialised.
641 * do the stack bottom calculation again and see if
642 * the initrd will fit just below the monitor stack
643 * bottom without overwriting the area allocated
644 * above for command line args and board info.
646 asm( "mr %0,1": "=r"(nsp
) : );
647 nsp
-= 2048; /* just to be sure */
649 if (nsp
> initrd_high
) /* limit as specified */
652 nsp
&= ~(4096 - 1); /* align on page */
657 SHOW_BOOT_PROGRESS (12);
659 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
660 data
, data
+ len
- 1, len
, len
);
662 initrd_end
= initrd_start
+ len
;
663 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
664 initrd_start
, initrd_end
);
665 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
668 void *to
= (void *)initrd_start
;
669 void *from
= (void *)data
;
672 size_t tail
= (l
> CHUNKSZ
) ? CHUNKSZ
: l
;
674 memmove (to
, from
, tail
);
680 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
681 memmove ((void *)initrd_start
, (void *)data
, len
);
682 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
691 debug ("## Transferring control to Linux (at address %08lx) ...\n",
694 SHOW_BOOT_PROGRESS (15);
696 #ifdef CFG_INIT_RAM_LOCK
697 unlock_ram_in_cache();
700 * Linux Kernel Parameters:
701 * r3: ptr to board info data
702 * r4: initrd_start or 0 if no initrd
703 * r5: initrd_end - unused if r4 is 0
704 * r6: Start of command line string
705 * r7: End of command line string
707 (*kernel
) (kbd
, initrd_start
, initrd_end
, cmd_start
, cmd_end
);
709 #endif /* CONFIG_PPC */
712 do_bootm_netbsd (cmd_tbl_t
*cmdtp
, int flag
,
713 int argc
, char *argv
[],
718 DECLARE_GLOBAL_DATA_PTR
;
720 image_header_t
*hdr
= &header
;
722 void (*loader
)(bd_t
*, image_header_t
*, char *, char *);
723 image_header_t
*img_addr
;
729 * Booting a (NetBSD) kernel image
731 * This process is pretty similar to a standalone application:
732 * The (first part of an multi-) image must be a stage-2 loader,
733 * which in turn is responsible for loading & invoking the actual
734 * kernel. The only differences are the parameters being passed:
735 * besides the board info strucure, the loader expects a command
736 * line, the name of the console device, and (optionally) the
737 * address of the original image header.
741 if ((hdr
->ih_type
==IH_TYPE_MULTI
) && (len_ptr
[1]))
742 img_addr
= (image_header_t
*) addr
;
746 #if defined (CONFIG_8xx_CONS_SMC1)
748 #elif defined (CONFIG_8xx_CONS_SMC2)
750 #elif defined (CONFIG_8xx_CONS_SCC2)
752 #elif defined (CONFIG_8xx_CONS_SCC3)
760 for (i
=2, len
=0 ; i
<argc
; i
+=1)
761 len
+= strlen (argv
[i
]) + 1;
762 cmdline
= malloc (len
);
764 for (i
=2, len
=0 ; i
<argc
; i
+=1) {
766 cmdline
[len
++] = ' ';
767 strcpy (&cmdline
[len
], argv
[i
]);
768 len
+= strlen (argv
[i
]);
770 } else if ((cmdline
= getenv("bootargs")) == NULL
) {
774 loader
= (void (*)(bd_t
*, image_header_t
*, char *, char *)) hdr
->ih_ep
;
776 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
779 SHOW_BOOT_PROGRESS (15);
782 * NetBSD Stage-2 Loader Parameters:
783 * r3: ptr to board info data
786 * r6: boot args string
788 (*loader
) (gd
->bd
, img_addr
, consdev
, cmdline
);
791 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
793 /* Function that returns a character from the environment */
794 extern uchar (*env_get_char
)(int);
797 do_bootm_artos (cmd_tbl_t
*cmdtp
, int flag
,
798 int argc
, char *argv
[],
803 DECLARE_GLOBAL_DATA_PTR
;
807 int i
, j
, nxt
, len
, envno
, envsz
;
809 void (*entry
)(bd_t
*bd
, char *cmdline
, char **fwenv
, ulong top
);
810 image_header_t
*hdr
= &header
;
813 * Booting an ARTOS kernel image + application
816 /* this used to be the top of memory, but was wrong... */
818 /* get stack pointer */
819 asm volatile ("mr %0,1" : "=r"(top
) );
821 debug ("## Current stack ends at 0x%08lX ", top
);
823 top
-= 2048; /* just to be sure */
824 if (top
> CFG_BOOTMAPSZ
)
828 debug ("=> set upper limit to 0x%08lX\n", top
);
830 /* first check the artos specific boot args, then the linux args*/
831 if ((s
= getenv("abootargs")) == NULL
&& (s
= getenv("bootargs")) == NULL
)
834 /* get length of cmdline, and place it */
836 top
= (top
- (len
+ 1)) & ~0xF;
837 cmdline
= (char *)top
;
838 debug ("## cmdline at 0x%08lX ", top
);
842 top
= (top
- sizeof(bd_t
)) & ~0xF;
843 debug ("## bd at 0x%08lX ", top
);
845 memcpy(kbd
, gd
->bd
, sizeof(bd_t
));
847 /* first find number of env entries, and their size */
850 for (i
= 0; env_get_char(i
) != '\0'; i
= nxt
+ 1) {
851 for (nxt
= i
; env_get_char(nxt
) != '\0'; ++nxt
)
854 envsz
+= (nxt
- i
) + 1; /* plus trailing zero */
856 envno
++; /* plus the terminating zero */
857 debug ("## %u envvars total size %u ", envno
, envsz
);
859 top
= (top
- sizeof(char **)*envno
) & ~0xF;
860 fwenv
= (char **)top
;
861 debug ("## fwenv at 0x%08lX ", top
);
863 top
= (top
- envsz
) & ~0xF;
868 for (i
= 0; env_get_char(i
) != '\0'; i
= nxt
+ 1) {
869 for (nxt
= i
; env_get_char(nxt
) != '\0'; ++nxt
)
872 for (j
= i
; j
< nxt
; ++j
)
873 *s
++ = env_get_char(j
);
876 *ss
++ = NULL
; /* terminate */
878 entry
= (void (*)(bd_t
*, char *, char **, ulong
))ntohl(hdr
->ih_ep
);
879 (*entry
)(kbd
, cmdline
, fwenv
, top
);
884 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
885 int do_bootd (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
888 #ifndef CFG_HUSH_PARSER
889 if (run_command (getenv ("bootcmd"), flag
) < 0) rcode
= 1;
891 if (parse_string_outer(getenv("bootcmd"),
892 FLAG_PARSE_SEMICOLON
| FLAG_EXIT_FROM_LOOP
) != 0 ) rcode
= 1;
898 boot
, 1, 1, do_bootd
,
899 "boot - boot default, i.e., run 'bootcmd'\n",
903 /* keep old command name "bootd" for backward compatibility */
905 bootd
, 1, 1, do_bootd
,
906 "bootd - boot default, i.e., run 'bootcmd'\n",
912 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
913 int do_iminfo ( cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
920 return image_info (load_addr
);
923 for (arg
=1; arg
<argc
; ++arg
) {
924 addr
= simple_strtoul(argv
[arg
], NULL
, 16);
925 if (image_info (addr
) != 0) rcode
= 1;
930 static int image_info (ulong addr
)
932 ulong data
, len
, checksum
;
933 image_header_t
*hdr
= &header
;
935 printf ("\n## Checking Image at %08lx ...\n", addr
);
937 /* Copy header so we can blank CRC field for re-calculation */
938 memmove (&header
, (char *)addr
, sizeof(image_header_t
));
940 if (ntohl(hdr
->ih_magic
) != IH_MAGIC
) {
941 printf (" Bad Magic Number\n");
945 data
= (ulong
)&header
;
946 len
= sizeof(image_header_t
);
948 checksum
= ntohl(hdr
->ih_hcrc
);
951 if (crc32 (0, (char *)data
, len
) != checksum
) {
952 printf (" Bad Header Checksum\n");
956 /* for multi-file images we need the data part, too */
957 print_image_hdr ((image_header_t
*)addr
);
959 data
= addr
+ sizeof(image_header_t
);
960 len
= ntohl(hdr
->ih_size
);
962 printf (" Verifying Checksum ... ");
963 if (crc32 (0, (char *)data
, len
) != ntohl(hdr
->ih_dcrc
)) {
964 printf (" Bad Data CRC\n");
972 iminfo
, CFG_MAXARGS
, 1, do_iminfo
,
973 "iminfo - print header information for application image\n",
975 " - print header information for application image starting at\n"
976 " address 'addr' in memory; this includes verification of the\n"
977 " image contents (magic number, header and payload checksums)\n"
980 #endif /* CFG_CMD_IMI */
982 #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
983 /*-----------------------------------------------------------------------
984 * List all images found in flash.
986 int do_imls (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
993 for (i
=0, info
=&flash_info
[0]; i
<CFG_MAX_FLASH_BANKS
; ++i
, ++info
) {
994 if (info
->flash_id
== FLASH_UNKNOWN
)
996 for (j
=0; j
<CFG_MAX_FLASH_SECT
; ++j
) {
998 if (!(hdr
=(image_header_t
*)info
->start
[j
]) ||
999 (ntohl(hdr
->ih_magic
) != IH_MAGIC
))
1002 /* Copy header so we can blank CRC field for re-calculation */
1003 memmove (&header
, (char *)hdr
, sizeof(image_header_t
));
1005 checksum
= ntohl(header
.ih_hcrc
);
1008 if (crc32 (0, (char *)&header
, sizeof(image_header_t
))
1012 printf ("Image at %08lX:\n", (ulong
)hdr
);
1013 print_image_hdr( hdr
);
1024 imls
, 1, 1, do_imls
,
1025 "imls - list all images found in flash\n",
1027 " - Prints information about all images found at sector\n"
1028 " boundaries in flash.\n"
1030 #endif /* CFG_CMD_IMLS */
1033 print_image_hdr (image_header_t
*hdr
)
1035 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1036 time_t timestamp
= (time_t)ntohl(hdr
->ih_time
);
1040 printf (" Image Name: %.*s\n", IH_NMLEN
, hdr
->ih_name
);
1041 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1042 to_tm (timestamp
, &tm
);
1043 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
1044 tm
.tm_year
, tm
.tm_mon
, tm
.tm_mday
,
1045 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
);
1046 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
1047 printf (" Image Type: "); print_type(hdr
); printf ("\n");
1048 printf (" Data Size: %d Bytes = ", ntohl(hdr
->ih_size
));
1049 print_size (ntohl(hdr
->ih_size
), "\n");
1050 printf (" Load Address: %08x\n", ntohl(hdr
->ih_load
));
1051 printf (" Entry Point: %08x\n", ntohl(hdr
->ih_ep
));
1053 if (hdr
->ih_type
== IH_TYPE_MULTI
) {
1056 ulong
*len_ptr
= (ulong
*)((ulong
)hdr
+ sizeof(image_header_t
));
1058 printf (" Contents:\n");
1059 for (i
=0; (len
= ntohl(*len_ptr
)); ++i
, ++len_ptr
) {
1060 printf (" Image %d: %8ld Bytes = ", i
, len
);
1061 print_size (len
, "\n");
1068 print_type (image_header_t
*hdr
)
1070 char *os
, *arch
, *type
, *comp
;
1072 switch (hdr
->ih_os
) {
1073 case IH_OS_INVALID
: os
= "Invalid OS"; break;
1074 case IH_OS_NETBSD
: os
= "NetBSD"; break;
1075 case IH_OS_LINUX
: os
= "Linux"; break;
1076 case IH_OS_VXWORKS
: os
= "VxWorks"; break;
1077 case IH_OS_QNX
: os
= "QNX"; break;
1078 case IH_OS_U_BOOT
: os
= "U-Boot"; break;
1079 case IH_OS_RTEMS
: os
= "RTEMS"; break;
1081 case IH_OS_ARTOS
: os
= "ARTOS"; break;
1083 #ifdef CONFIG_LYNXKDI
1084 case IH_OS_LYNXOS
: os
= "LynxOS"; break;
1086 default: os
= "Unknown OS"; break;
1089 switch (hdr
->ih_arch
) {
1090 case IH_CPU_INVALID
: arch
= "Invalid CPU"; break;
1091 case IH_CPU_ALPHA
: arch
= "Alpha"; break;
1092 case IH_CPU_ARM
: arch
= "ARM"; break;
1093 case IH_CPU_I386
: arch
= "Intel x86"; break;
1094 case IH_CPU_IA64
: arch
= "IA64"; break;
1095 case IH_CPU_MIPS
: arch
= "MIPS"; break;
1096 case IH_CPU_MIPS64
: arch
= "MIPS 64 Bit"; break;
1097 case IH_CPU_PPC
: arch
= "PowerPC"; break;
1098 case IH_CPU_S390
: arch
= "IBM S390"; break;
1099 case IH_CPU_SH
: arch
= "SuperH"; break;
1100 case IH_CPU_SPARC
: arch
= "SPARC"; break;
1101 case IH_CPU_SPARC64
: arch
= "SPARC 64 Bit"; break;
1102 case IH_CPU_M68K
: arch
= "M68K"; break;
1103 default: arch
= "Unknown Architecture"; break;
1106 switch (hdr
->ih_type
) {
1107 case IH_TYPE_INVALID
: type
= "Invalid Image"; break;
1108 case IH_TYPE_STANDALONE
:type
= "Standalone Program"; break;
1109 case IH_TYPE_KERNEL
: type
= "Kernel Image"; break;
1110 case IH_TYPE_RAMDISK
: type
= "RAMDisk Image"; break;
1111 case IH_TYPE_MULTI
: type
= "Multi-File Image"; break;
1112 case IH_TYPE_FIRMWARE
: type
= "Firmware"; break;
1113 case IH_TYPE_SCRIPT
: type
= "Script"; break;
1114 default: type
= "Unknown Image"; break;
1117 switch (hdr
->ih_comp
) {
1118 case IH_COMP_NONE
: comp
= "uncompressed"; break;
1119 case IH_COMP_GZIP
: comp
= "gzip compressed"; break;
1120 case IH_COMP_BZIP2
: comp
= "bzip2 compressed"; break;
1121 default: comp
= "unknown compression"; break;
1124 printf ("%s %s %s (%s)", arch
, os
, type
, comp
);
1127 #define ZALLOC_ALIGNMENT 16
1129 static void *zalloc(void *x
, unsigned items
, unsigned size
)
1134 size
= (size
+ ZALLOC_ALIGNMENT
- 1) & ~(ZALLOC_ALIGNMENT
- 1);
1141 static void zfree(void *x
, void *addr
, unsigned nb
)
1147 #define EXTRA_FIELD 4
1149 #define COMMENT 0x10
1150 #define RESERVED 0xe0
1154 int gunzip(void *dst
, int dstlen
, unsigned char *src
, int *lenp
)
1162 if (src
[2] != DEFLATED
|| (flags
& RESERVED
) != 0) {
1163 printf ("Error: Bad gzipped data\n");
1166 if ((flags
& EXTRA_FIELD
) != 0)
1167 i
= 12 + src
[10] + (src
[11] << 8);
1168 if ((flags
& ORIG_NAME
) != 0)
1169 while (src
[i
++] != 0)
1171 if ((flags
& COMMENT
) != 0)
1172 while (src
[i
++] != 0)
1174 if ((flags
& HEAD_CRC
) != 0)
1177 printf ("Error: gunzip out of data in header\n");
1183 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1184 s
.outcb
= (cb_func
)WATCHDOG_RESET
;
1187 #endif /* CONFIG_HW_WATCHDOG */
1189 r
= inflateInit2(&s
, -MAX_WBITS
);
1191 printf ("Error: inflateInit2() returned %d\n", r
);
1194 s
.next_in
= src
+ i
;
1195 s
.avail_in
= *lenp
- i
;
1197 s
.avail_out
= dstlen
;
1198 r
= inflate(&s
, Z_FINISH
);
1199 if (r
!= Z_OK
&& r
!= Z_STREAM_END
) {
1200 printf ("Error: inflate() returned %d\n", r
);
1203 *lenp
= s
.next_out
- (unsigned char *) dst
;
1210 do_bootm_rtems (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
1211 ulong addr
, ulong
*len_ptr
, int verify
)
1213 DECLARE_GLOBAL_DATA_PTR
;
1214 image_header_t
*hdr
= &header
;
1215 void (*entry_point
)(bd_t
*);
1217 entry_point
= (void (*)(bd_t
*)) hdr
->ih_ep
;
1219 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1220 (ulong
)entry_point
);
1222 SHOW_BOOT_PROGRESS (15);
1226 * r3: ptr to board info data
1229 (*entry_point
) ( gd
->bd
);
1232 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
1234 do_bootm_vxworks (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
1235 ulong addr
, ulong
*len_ptr
, int verify
)
1237 image_header_t
*hdr
= &header
;
1240 sprintf(str
, "%x", hdr
->ih_ep
); /* write entry-point into string */
1241 setenv("loadaddr", str
);
1242 do_bootvx(cmdtp
, 0, 0, NULL
);
1246 do_bootm_qnxelf (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
1247 ulong addr
, ulong
*len_ptr
, int verify
)
1249 image_header_t
*hdr
= &header
;
1250 char *local_args
[2];
1253 sprintf(str
, "%x", hdr
->ih_ep
); /* write entry-point into string */
1254 local_args
[0] = argv
[0];
1255 local_args
[1] = str
; /* and provide it via the arguments */
1256 do_bootelf(cmdtp
, 0, 2, local_args
);
1258 #endif /* CFG_CMD_ELF */
1260 #ifdef CONFIG_LYNXKDI
1262 do_bootm_lynxkdi (cmd_tbl_t
*cmdtp
, int flag
,
1263 int argc
, char *argv
[],
1268 lynxkdi_boot( &header
);
1271 #endif /* CONFIG_LYNXKDI */