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>
38 extern int do_reset (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
40 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
44 #ifdef CFG_HUSH_PARSER
48 #ifdef CONFIG_SHOW_BOOT_PROGRESS
49 # include <status_led.h>
50 # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
52 # define SHOW_BOOT_PROGRESS(arg)
55 #ifdef CFG_INIT_RAM_LOCK
56 #include <asm/cache.h>
59 #ifdef CONFIG_LOGBUFFER
63 #ifdef CONFIG_HAS_DATAFLASH
64 #include <dataflash.h>
68 * Some systems (for example LWMON) have very short watchdog periods;
69 * we must make sure to split long operations like memmove() or
70 * crc32() into reasonable chunks.
72 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
73 # define CHUNKSZ (64 * 1024)
76 int gunzip (void *, int, unsigned char *, int *);
78 static void *zalloc(void *, unsigned, unsigned);
79 static void zfree(void *, void *, unsigned);
81 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
82 static int image_info (unsigned long addr
);
85 #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
87 extern flash_info_t flash_info
[CFG_MAX_FLASH_BANKS
]; /* info for FLASH chips */
88 static int do_imls (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
91 static void print_type (image_header_t
*hdr
);
94 image_header_t
*fake_header(image_header_t
*hdr
, void *ptr
, int size
);
98 * Continue booting an OS image; caller already has:
99 * - copied image header to global variable `header'
100 * - checked header magic number, checksums (both header & image),
101 * - verified image architecture (PPC) and type (KERNEL or MULTI),
102 * - loaded (first part of) image to header load address,
103 * - disabled interrupts.
105 typedef void boot_os_Fcn (cmd_tbl_t
*cmdtp
, int flag
,
106 int argc
, char *argv
[],
107 ulong addr
, /* of image to boot */
108 ulong
*len_ptr
, /* multi-file image length table */
109 int verify
); /* getenv("verify")[0] != 'n' */
112 extern int do_bdinfo ( cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
116 static boot_os_Fcn do_bootm_linux
;
118 extern boot_os_Fcn do_bootm_linux
;
120 #ifdef CONFIG_SILENT_CONSOLE
121 static void fixup_silent_linux (void);
123 static boot_os_Fcn do_bootm_netbsd
;
124 static boot_os_Fcn do_bootm_rtems
;
125 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
126 static boot_os_Fcn do_bootm_vxworks
;
127 static boot_os_Fcn do_bootm_qnxelf
;
128 int do_bootvx ( cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[] );
129 int do_bootelf (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[] );
130 #endif /* CFG_CMD_ELF */
131 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
132 static boot_os_Fcn do_bootm_artos
;
134 #ifdef CONFIG_LYNXKDI
135 static boot_os_Fcn do_bootm_lynxkdi
;
136 extern void lynxkdi_boot( image_header_t
* );
139 image_header_t header
;
141 ulong load_addr
= CFG_LOAD_ADDR
; /* Default Load Address */
143 int do_bootm (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
147 ulong data
, len
, checksum
;
149 uint unc_len
= 0x400000;
152 int (*appl
)(int, char *[]);
153 image_header_t
*hdr
= &header
;
155 s
= getenv ("verify");
156 verify
= (s
&& (*s
== 'n')) ? 0 : 1;
161 addr
= simple_strtoul(argv
[1], NULL
, 16);
164 SHOW_BOOT_PROGRESS (1);
165 printf ("## Booting image at %08lx ...\n", addr
);
167 /* Copy header so we can blank CRC field for re-calculation */
168 #ifdef CONFIG_HAS_DATAFLASH
169 if (addr_dataflash(addr
)){
170 read_dataflash(addr
, sizeof(image_header_t
), (char *)&header
);
173 memmove (&header
, (char *)addr
, sizeof(image_header_t
));
175 if (ntohl(hdr
->ih_magic
) != IH_MAGIC
) {
176 #ifdef __I386__ /* correct image format not implemented yet - fake it */
177 if (fake_header(hdr
, (void*)addr
, -1) != NULL
) {
178 /* to compensate for the addition below */
179 addr
-= sizeof(image_header_t
);
181 * fake_header() does not fake the data crc
185 #endif /* __I386__ */
187 printf ("Bad Magic Number\n");
188 SHOW_BOOT_PROGRESS (-1);
192 SHOW_BOOT_PROGRESS (2);
194 data
= (ulong
)&header
;
195 len
= sizeof(image_header_t
);
197 checksum
= ntohl(hdr
->ih_hcrc
);
200 if (crc32 (0, (char *)data
, len
) != checksum
) {
201 printf ("Bad Header Checksum\n");
202 SHOW_BOOT_PROGRESS (-2);
205 SHOW_BOOT_PROGRESS (3);
207 /* for multi-file images we need the data part, too */
208 print_image_hdr ((image_header_t
*)addr
);
210 data
= addr
+ sizeof(image_header_t
);
211 len
= ntohl(hdr
->ih_size
);
213 #ifdef CONFIG_HAS_DATAFLASH
214 if (addr_dataflash(addr
)){
215 read_dataflash(data
, len
, (char *)CFG_LOAD_ADDR
);
216 data
= CFG_LOAD_ADDR
;
221 printf (" Verifying Checksum ... ");
222 if (crc32 (0, (char *)data
, len
) != ntohl(hdr
->ih_dcrc
)) {
223 printf ("Bad Data CRC\n");
224 SHOW_BOOT_PROGRESS (-3);
229 SHOW_BOOT_PROGRESS (4);
231 len_ptr
= (ulong
*)data
;
234 if (hdr
->ih_arch
!= IH_CPU_PPC
)
235 #elif defined(__ARM__)
236 if (hdr
->ih_arch
!= IH_CPU_ARM
)
237 #elif defined(__I386__)
238 if (hdr
->ih_arch
!= IH_CPU_I386
)
239 #elif defined(__mips__)
240 if (hdr
->ih_arch
!= IH_CPU_MIPS
)
241 #elif defined(__nios__)
242 if (hdr
->ih_arch
!= IH_CPU_NIOS
)
243 #elif defined(__M68K__)
244 if (hdr
->ih_arch
!= IH_CPU_M68K
)
246 # error Unknown CPU type
249 printf ("Unsupported Architecture 0x%x\n", hdr
->ih_arch
);
250 SHOW_BOOT_PROGRESS (-4);
253 SHOW_BOOT_PROGRESS (5);
255 switch (hdr
->ih_type
) {
256 case IH_TYPE_STANDALONE
:
257 name
= "Standalone Application";
258 /* A second argument overwrites the load address */
260 hdr
->ih_load
= simple_strtoul(argv
[2], NULL
, 16);
264 name
= "Kernel Image";
267 name
= "Multi-File Image";
268 len
= ntohl(len_ptr
[0]);
269 /* OS kernel is always the first image */
270 data
+= 8; /* kernel_len + terminator */
271 for (i
=1; len_ptr
[i
]; ++i
)
274 default: printf ("Wrong Image Type for %s command\n", cmdtp
->name
);
275 SHOW_BOOT_PROGRESS (-5);
278 SHOW_BOOT_PROGRESS (6);
281 * We have reached the point of no return: we are going to
282 * overwrite all exception vector code, so we cannot easily
283 * recover from any failures any more...
286 iflag
= disable_interrupts();
288 #ifdef CONFIG_AMIGAONEG3SE
290 * We've possible left the caches enabled during
291 * bios emulation, so turn them off again
294 invalidate_l1_instruction_cache();
299 switch (hdr
->ih_comp
) {
301 if(ntohl(hdr
->ih_load
) == addr
) {
302 printf (" XIP %s ... ", name
);
304 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
306 void *to
= (void *)ntohl(hdr
->ih_load
);
307 void *from
= (void *)data
;
309 printf (" Loading %s ... ", name
);
312 size_t tail
= (l
> CHUNKSZ
) ? CHUNKSZ
: l
;
314 memmove (to
, from
, tail
);
319 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
320 memmove ((void *) ntohl(hdr
->ih_load
), (uchar
*)data
, len
);
321 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
325 printf (" Uncompressing %s ... ", name
);
326 if (gunzip ((void *)ntohl(hdr
->ih_load
), unc_len
,
327 (uchar
*)data
, (int *)&len
) != 0) {
328 printf ("GUNZIP ERROR - must RESET board to recover\n");
329 SHOW_BOOT_PROGRESS (-6);
330 do_reset (cmdtp
, flag
, argc
, argv
);
335 printf (" Uncompressing %s ... ", name
);
336 i
= BZ2_bzBuffToBuffDecompress ((char*)ntohl(hdr
->ih_load
),
337 &unc_len
, (char *)data
, len
, 0, 0);
339 printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i
);
340 SHOW_BOOT_PROGRESS (-6);
342 do_reset (cmdtp
, flag
, argc
, argv
);
345 #endif /* CONFIG_BZIP2 */
349 printf ("Unimplemented compression type %d\n", hdr
->ih_comp
);
350 SHOW_BOOT_PROGRESS (-7);
354 SHOW_BOOT_PROGRESS (7);
356 switch (hdr
->ih_type
) {
357 case IH_TYPE_STANDALONE
:
361 /* load (and uncompress), but don't start if "autostart"
364 if (((s
= getenv("autostart")) != NULL
) && (strcmp(s
,"no") == 0)) {
366 sprintf(buf
, "%lX", len
);
367 setenv("filesize", buf
);
370 appl
= (int (*)(int, char *[]))ntohl(hdr
->ih_ep
);
371 (*appl
)(argc
-1, &argv
[1]);
380 printf ("Can't boot image type %d\n", hdr
->ih_type
);
381 SHOW_BOOT_PROGRESS (-8);
384 SHOW_BOOT_PROGRESS (8);
386 switch (hdr
->ih_os
) {
387 default: /* handled by (original) Linux case */
389 #ifdef CONFIG_SILENT_CONSOLE
390 fixup_silent_linux();
392 do_bootm_linux (cmdtp
, flag
, argc
, argv
,
393 addr
, len_ptr
, verify
);
396 do_bootm_netbsd (cmdtp
, flag
, argc
, argv
,
397 addr
, len_ptr
, verify
);
400 #ifdef CONFIG_LYNXKDI
402 do_bootm_lynxkdi (cmdtp
, flag
, argc
, argv
,
403 addr
, len_ptr
, verify
);
408 do_bootm_rtems (cmdtp
, flag
, argc
, argv
,
409 addr
, len_ptr
, verify
);
412 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
414 do_bootm_vxworks (cmdtp
, flag
, argc
, argv
,
415 addr
, len_ptr
, verify
);
418 do_bootm_qnxelf (cmdtp
, flag
, argc
, argv
,
419 addr
, len_ptr
, verify
);
421 #endif /* CFG_CMD_ELF */
424 do_bootm_artos (cmdtp
, flag
, argc
, argv
,
425 addr
, len_ptr
, verify
);
430 SHOW_BOOT_PROGRESS (-9);
432 printf ("\n## Control returned to monitor - resetting...\n");
433 do_reset (cmdtp
, flag
, argc
, argv
);
439 bootm
, CFG_MAXARGS
, 1, do_bootm
,
440 "bootm - boot application image from memory\n",
441 "[addr [arg ...]]\n - boot application image stored in memory\n"
442 " passing arguments 'arg ...'; when booting a Linux kernel,\n"
443 " 'arg' can be the address of an initrd image\n"
446 #ifdef CONFIG_SILENT_CONSOLE
448 fixup_silent_linux ()
450 DECLARE_GLOBAL_DATA_PTR
;
451 char buf
[256], *start
, *end
;
452 char *cmdline
= getenv ("bootargs");
454 /* Only fix cmdline when requested */
455 if (!(gd
->flags
& GD_FLG_SILENT
))
458 debug ("before silent fix-up: %s\n", cmdline
);
460 if ((start
= strstr (cmdline
, "console=")) != NULL
) {
461 end
= strchr (start
, ' ');
462 strncpy (buf
, cmdline
, (start
- cmdline
+ 8));
464 strcpy (buf
+ (start
- cmdline
+ 8), end
);
466 buf
[start
- cmdline
+ 8] = '\0';
468 strcpy (buf
, cmdline
);
469 strcat (buf
, " console=");
472 strcpy (buf
, "console=");
475 setenv ("bootargs", buf
);
476 debug ("after silent fix-up: %s\n", buf
);
478 #endif /* CONFIG_SILENT_CONSOLE */
482 do_bootm_linux (cmd_tbl_t
*cmdtp
, int flag
,
483 int argc
, char *argv
[],
488 DECLARE_GLOBAL_DATA_PTR
;
492 ulong initrd_start
, initrd_end
;
493 ulong cmd_start
, cmd_end
;
496 int initrd_copy_to_ram
= 1;
500 void (*kernel
)(bd_t
*, ulong
, ulong
, ulong
, ulong
);
501 image_header_t
*hdr
= &header
;
503 if ((s
= getenv ("initrd_high")) != NULL
) {
504 /* a value of "no" or a similar string will act like 0,
505 * turning the "load high" feature off. This is intentional.
507 initrd_high
= simple_strtoul(s
, NULL
, 16);
508 if (initrd_high
== ~0)
509 initrd_copy_to_ram
= 0;
510 } else { /* not set, no restrictions to load high */
514 #ifdef CONFIG_LOGBUFFER
516 /* Prevent initrd from overwriting logbuffer */
517 if (initrd_high
< (kbd
->bi_memsize
-LOGBUFF_LEN
-LOGBUFF_OVERHEAD
))
518 initrd_high
= kbd
->bi_memsize
-LOGBUFF_LEN
-LOGBUFF_OVERHEAD
;
519 debug ("## Logbuffer at 0x%08lX ", kbd
->bi_memsize
-LOGBUFF_LEN
);
523 * Booting a (Linux) kernel image
525 * Allocate space for command line and board info - the
526 * address should be as high as possible within the reach of
527 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
528 * memory, which means far enough below the current stack
532 asm( "mr %0,1": "=r"(sp
) : );
534 debug ("## Current stack ends at 0x%08lX ", sp
);
536 sp
-= 2048; /* just to be sure */
537 if (sp
> CFG_BOOTMAPSZ
)
541 debug ("=> set upper limit to 0x%08lX\n", sp
);
543 cmdline
= (char *)((sp
- CFG_BARGSIZE
) & ~0xF);
544 kbd
= (bd_t
*)(((ulong
)cmdline
- sizeof(bd_t
)) & ~0xF);
546 if ((s
= getenv("bootargs")) == NULL
)
551 cmd_start
= (ulong
)&cmdline
[0];
552 cmd_end
= cmd_start
+ strlen(cmdline
);
557 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start
, cmd_end
);
559 do_bdinfo (NULL
, 0, 0, NULL
);
562 if ((s
= getenv ("clocks_in_mhz")) != NULL
) {
563 /* convert all clock information to MHz */
564 kbd
->bi_intfreq
/= 1000000L;
565 kbd
->bi_busfreq
/= 1000000L;
566 #if defined(CONFIG_8260) || defined(CONFIG_MPC8560)
567 kbd
->bi_cpmfreq
/= 1000000L;
568 kbd
->bi_brgfreq
/= 1000000L;
569 kbd
->bi_sccfreq
/= 1000000L;
570 kbd
->bi_vco
/= 1000000L;
571 #endif /* CONFIG_8260 */
572 #if defined(CONFIG_MPC5XXX)
573 kbd
->bi_ipbfreq
/= 1000000L;
574 kbd
->bi_pcifreq
/= 1000000L;
575 #endif /* CONFIG_MPC5XXX */
578 kernel
= (void (*)(bd_t
*, ulong
, ulong
, ulong
, ulong
))hdr
->ih_ep
;
581 * Check if there is an initrd image
584 SHOW_BOOT_PROGRESS (9);
586 addr
= simple_strtoul(argv
[2], NULL
, 16);
588 printf ("## Loading RAMDisk Image at %08lx ...\n", addr
);
590 /* Copy header so we can blank CRC field for re-calculation */
591 memmove (&header
, (char *)addr
, sizeof(image_header_t
));
593 if (hdr
->ih_magic
!= IH_MAGIC
) {
594 printf ("Bad Magic Number\n");
595 SHOW_BOOT_PROGRESS (-10);
596 do_reset (cmdtp
, flag
, argc
, argv
);
599 data
= (ulong
)&header
;
600 len
= sizeof(image_header_t
);
602 checksum
= hdr
->ih_hcrc
;
605 if (crc32 (0, (char *)data
, len
) != checksum
) {
606 printf ("Bad Header Checksum\n");
607 SHOW_BOOT_PROGRESS (-11);
608 do_reset (cmdtp
, flag
, argc
, argv
);
611 SHOW_BOOT_PROGRESS (10);
613 print_image_hdr (hdr
);
615 data
= addr
+ sizeof(image_header_t
);
620 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
621 ulong cdata
= data
, edata
= cdata
+ len
;
622 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
624 printf (" Verifying Checksum ... ");
626 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
628 while (cdata
< edata
) {
629 ulong chunk
= edata
- cdata
;
633 csum
= crc32 (csum
, (char *)cdata
, chunk
);
638 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
639 csum
= crc32 (0, (char *)data
, len
);
640 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
642 if (csum
!= hdr
->ih_dcrc
) {
643 printf ("Bad Data CRC\n");
644 SHOW_BOOT_PROGRESS (-12);
645 do_reset (cmdtp
, flag
, argc
, argv
);
650 SHOW_BOOT_PROGRESS (11);
652 if ((hdr
->ih_os
!= IH_OS_LINUX
) ||
653 (hdr
->ih_arch
!= IH_CPU_PPC
) ||
654 (hdr
->ih_type
!= IH_TYPE_RAMDISK
) ) {
655 printf ("No Linux PPC Ramdisk Image\n");
656 SHOW_BOOT_PROGRESS (-13);
657 do_reset (cmdtp
, flag
, argc
, argv
);
661 * Now check if we have a multifile image
663 } else if ((hdr
->ih_type
==IH_TYPE_MULTI
) && (len_ptr
[1])) {
664 u_long tail
= ntohl(len_ptr
[0]) % 4;
667 SHOW_BOOT_PROGRESS (13);
669 /* skip kernel length and terminator */
670 data
= (ulong
)(&len_ptr
[2]);
671 /* skip any additional image length fields */
672 for (i
=1; len_ptr
[i
]; ++i
)
674 /* add kernel length, and align */
675 data
+= ntohl(len_ptr
[0]);
680 len
= ntohl(len_ptr
[1]);
686 SHOW_BOOT_PROGRESS (14);
692 debug ("No initrd\n");
696 if (!initrd_copy_to_ram
) { /* zero-copy ramdisk support */
698 initrd_end
= initrd_start
+ len
;
700 initrd_start
= (ulong
)kbd
- len
;
701 initrd_start
&= ~(4096 - 1); /* align on page */
707 * the inital ramdisk does not need to be within
708 * CFG_BOOTMAPSZ as it is not accessed until after
709 * the mm system is initialised.
711 * do the stack bottom calculation again and see if
712 * the initrd will fit just below the monitor stack
713 * bottom without overwriting the area allocated
714 * above for command line args and board info.
716 asm( "mr %0,1": "=r"(nsp
) : );
717 nsp
-= 2048; /* just to be sure */
719 if (nsp
> initrd_high
) /* limit as specified */
722 nsp
&= ~(4096 - 1); /* align on page */
727 SHOW_BOOT_PROGRESS (12);
729 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
730 data
, data
+ len
- 1, len
, len
);
732 initrd_end
= initrd_start
+ len
;
733 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
734 initrd_start
, initrd_end
);
735 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
738 void *to
= (void *)initrd_start
;
739 void *from
= (void *)data
;
742 size_t tail
= (l
> CHUNKSZ
) ? CHUNKSZ
: l
;
744 memmove (to
, from
, tail
);
750 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
751 memmove ((void *)initrd_start
, (void *)data
, len
);
752 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
761 debug ("## Transferring control to Linux (at address %08lx) ...\n",
764 SHOW_BOOT_PROGRESS (15);
766 #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
767 unlock_ram_in_cache();
770 * Linux Kernel Parameters:
771 * r3: ptr to board info data
772 * r4: initrd_start or 0 if no initrd
773 * r5: initrd_end - unused if r4 is 0
774 * r6: Start of command line string
775 * r7: End of command line string
777 (*kernel
) (kbd
, initrd_start
, initrd_end
, cmd_start
, cmd_end
);
779 #endif /* CONFIG_PPC */
782 do_bootm_netbsd (cmd_tbl_t
*cmdtp
, int flag
,
783 int argc
, char *argv
[],
788 DECLARE_GLOBAL_DATA_PTR
;
790 image_header_t
*hdr
= &header
;
792 void (*loader
)(bd_t
*, image_header_t
*, char *, char *);
793 image_header_t
*img_addr
;
799 * Booting a (NetBSD) kernel image
801 * This process is pretty similar to a standalone application:
802 * The (first part of an multi-) image must be a stage-2 loader,
803 * which in turn is responsible for loading & invoking the actual
804 * kernel. The only differences are the parameters being passed:
805 * besides the board info strucure, the loader expects a command
806 * line, the name of the console device, and (optionally) the
807 * address of the original image header.
811 if ((hdr
->ih_type
==IH_TYPE_MULTI
) && (len_ptr
[1]))
812 img_addr
= (image_header_t
*) addr
;
816 #if defined (CONFIG_8xx_CONS_SMC1)
818 #elif defined (CONFIG_8xx_CONS_SMC2)
820 #elif defined (CONFIG_8xx_CONS_SCC2)
822 #elif defined (CONFIG_8xx_CONS_SCC3)
830 for (i
=2, len
=0 ; i
<argc
; i
+=1)
831 len
+= strlen (argv
[i
]) + 1;
832 cmdline
= malloc (len
);
834 for (i
=2, len
=0 ; i
<argc
; i
+=1) {
836 cmdline
[len
++] = ' ';
837 strcpy (&cmdline
[len
], argv
[i
]);
838 len
+= strlen (argv
[i
]);
840 } else if ((cmdline
= getenv("bootargs")) == NULL
) {
844 loader
= (void (*)(bd_t
*, image_header_t
*, char *, char *)) hdr
->ih_ep
;
846 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
849 SHOW_BOOT_PROGRESS (15);
852 * NetBSD Stage-2 Loader Parameters:
853 * r3: ptr to board info data
856 * r6: boot args string
858 (*loader
) (gd
->bd
, img_addr
, consdev
, cmdline
);
861 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
863 /* Function that returns a character from the environment */
864 extern uchar (*env_get_char
)(int);
867 do_bootm_artos (cmd_tbl_t
*cmdtp
, int flag
,
868 int argc
, char *argv
[],
873 DECLARE_GLOBAL_DATA_PTR
;
877 int i
, j
, nxt
, len
, envno
, envsz
;
879 void (*entry
)(bd_t
*bd
, char *cmdline
, char **fwenv
, ulong top
);
880 image_header_t
*hdr
= &header
;
883 * Booting an ARTOS kernel image + application
886 /* this used to be the top of memory, but was wrong... */
888 /* get stack pointer */
889 asm volatile ("mr %0,1" : "=r"(top
) );
891 debug ("## Current stack ends at 0x%08lX ", top
);
893 top
-= 2048; /* just to be sure */
894 if (top
> CFG_BOOTMAPSZ
)
898 debug ("=> set upper limit to 0x%08lX\n", top
);
900 /* first check the artos specific boot args, then the linux args*/
901 if ((s
= getenv("abootargs")) == NULL
&& (s
= getenv("bootargs")) == NULL
)
904 /* get length of cmdline, and place it */
906 top
= (top
- (len
+ 1)) & ~0xF;
907 cmdline
= (char *)top
;
908 debug ("## cmdline at 0x%08lX ", top
);
912 top
= (top
- sizeof(bd_t
)) & ~0xF;
913 debug ("## bd at 0x%08lX ", top
);
915 memcpy(kbd
, gd
->bd
, sizeof(bd_t
));
917 /* first find number of env entries, and their size */
920 for (i
= 0; env_get_char(i
) != '\0'; i
= nxt
+ 1) {
921 for (nxt
= i
; env_get_char(nxt
) != '\0'; ++nxt
)
924 envsz
+= (nxt
- i
) + 1; /* plus trailing zero */
926 envno
++; /* plus the terminating zero */
927 debug ("## %u envvars total size %u ", envno
, envsz
);
929 top
= (top
- sizeof(char **)*envno
) & ~0xF;
930 fwenv
= (char **)top
;
931 debug ("## fwenv at 0x%08lX ", top
);
933 top
= (top
- envsz
) & ~0xF;
938 for (i
= 0; env_get_char(i
) != '\0'; i
= nxt
+ 1) {
939 for (nxt
= i
; env_get_char(nxt
) != '\0'; ++nxt
)
942 for (j
= i
; j
< nxt
; ++j
)
943 *s
++ = env_get_char(j
);
946 *ss
++ = NULL
; /* terminate */
948 entry
= (void (*)(bd_t
*, char *, char **, ulong
))ntohl(hdr
->ih_ep
);
949 (*entry
)(kbd
, cmdline
, fwenv
, top
);
954 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
955 int do_bootd (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
958 #ifndef CFG_HUSH_PARSER
959 if (run_command (getenv ("bootcmd"), flag
) < 0) rcode
= 1;
961 if (parse_string_outer(getenv("bootcmd"),
962 FLAG_PARSE_SEMICOLON
| FLAG_EXIT_FROM_LOOP
) != 0 ) rcode
= 1;
968 boot
, 1, 1, do_bootd
,
969 "boot - boot default, i.e., run 'bootcmd'\n",
973 /* keep old command name "bootd" for backward compatibility */
975 bootd
, 1, 1, do_bootd
,
976 "bootd - boot default, i.e., run 'bootcmd'\n",
982 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
983 int do_iminfo ( cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
990 return image_info (load_addr
);
993 for (arg
=1; arg
<argc
; ++arg
) {
994 addr
= simple_strtoul(argv
[arg
], NULL
, 16);
995 if (image_info (addr
) != 0) rcode
= 1;
1000 static int image_info (ulong addr
)
1002 ulong data
, len
, checksum
;
1003 image_header_t
*hdr
= &header
;
1005 printf ("\n## Checking Image at %08lx ...\n", addr
);
1007 /* Copy header so we can blank CRC field for re-calculation */
1008 memmove (&header
, (char *)addr
, sizeof(image_header_t
));
1010 if (ntohl(hdr
->ih_magic
) != IH_MAGIC
) {
1011 printf (" Bad Magic Number\n");
1015 data
= (ulong
)&header
;
1016 len
= sizeof(image_header_t
);
1018 checksum
= ntohl(hdr
->ih_hcrc
);
1021 if (crc32 (0, (char *)data
, len
) != checksum
) {
1022 printf (" Bad Header Checksum\n");
1026 /* for multi-file images we need the data part, too */
1027 print_image_hdr ((image_header_t
*)addr
);
1029 data
= addr
+ sizeof(image_header_t
);
1030 len
= ntohl(hdr
->ih_size
);
1032 printf (" Verifying Checksum ... ");
1033 if (crc32 (0, (char *)data
, len
) != ntohl(hdr
->ih_dcrc
)) {
1034 printf (" Bad Data CRC\n");
1042 iminfo
, CFG_MAXARGS
, 1, do_iminfo
,
1043 "iminfo - print header information for application image\n",
1045 " - print header information for application image starting at\n"
1046 " address 'addr' in memory; this includes verification of the\n"
1047 " image contents (magic number, header and payload checksums)\n"
1050 #endif /* CFG_CMD_IMI */
1052 #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
1053 /*-----------------------------------------------------------------------
1054 * List all images found in flash.
1056 int do_imls (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
1060 image_header_t
*hdr
;
1061 ulong data
, len
, checksum
;
1063 for (i
=0, info
=&flash_info
[0]; i
<CFG_MAX_FLASH_BANKS
; ++i
, ++info
) {
1064 if (info
->flash_id
== FLASH_UNKNOWN
)
1066 for (j
=0; j
<CFG_MAX_FLASH_SECT
; ++j
) {
1068 if (!(hdr
=(image_header_t
*)info
->start
[j
]) ||
1069 (ntohl(hdr
->ih_magic
) != IH_MAGIC
))
1072 /* Copy header so we can blank CRC field for re-calculation */
1073 memmove (&header
, (char *)hdr
, sizeof(image_header_t
));
1075 checksum
= ntohl(header
.ih_hcrc
);
1078 if (crc32 (0, (char *)&header
, sizeof(image_header_t
))
1082 printf ("Image at %08lX:\n", (ulong
)hdr
);
1083 print_image_hdr( hdr
);
1085 data
= (ulong
)hdr
+ sizeof(image_header_t
);
1086 len
= ntohl(hdr
->ih_size
);
1088 printf (" Verifying Checksum ... ");
1089 if (crc32 (0, (char *)data
, len
) != ntohl(hdr
->ih_dcrc
)) {
1090 printf (" Bad Data CRC\n");
1102 imls
, 1, 1, do_imls
,
1103 "imls - list all images found in flash\n",
1105 " - Prints information about all images found at sector\n"
1106 " boundaries in flash.\n"
1108 #endif /* CFG_CMD_IMLS */
1111 print_image_hdr (image_header_t
*hdr
)
1113 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1114 time_t timestamp
= (time_t)ntohl(hdr
->ih_time
);
1118 printf (" Image Name: %.*s\n", IH_NMLEN
, hdr
->ih_name
);
1119 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1120 to_tm (timestamp
, &tm
);
1121 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
1122 tm
.tm_year
, tm
.tm_mon
, tm
.tm_mday
,
1123 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
);
1124 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
1125 printf (" Image Type: "); print_type(hdr
); printf ("\n");
1126 printf (" Data Size: %d Bytes = ", ntohl(hdr
->ih_size
));
1127 print_size (ntohl(hdr
->ih_size
), "\n");
1128 printf (" Load Address: %08x\n", ntohl(hdr
->ih_load
));
1129 printf (" Entry Point: %08x\n", ntohl(hdr
->ih_ep
));
1131 if (hdr
->ih_type
== IH_TYPE_MULTI
) {
1134 ulong
*len_ptr
= (ulong
*)((ulong
)hdr
+ sizeof(image_header_t
));
1136 printf (" Contents:\n");
1137 for (i
=0; (len
= ntohl(*len_ptr
)); ++i
, ++len_ptr
) {
1138 printf (" Image %d: %8ld Bytes = ", i
, len
);
1139 print_size (len
, "\n");
1146 print_type (image_header_t
*hdr
)
1148 char *os
, *arch
, *type
, *comp
;
1150 switch (hdr
->ih_os
) {
1151 case IH_OS_INVALID
: os
= "Invalid OS"; break;
1152 case IH_OS_NETBSD
: os
= "NetBSD"; break;
1153 case IH_OS_LINUX
: os
= "Linux"; break;
1154 case IH_OS_VXWORKS
: os
= "VxWorks"; break;
1155 case IH_OS_QNX
: os
= "QNX"; break;
1156 case IH_OS_U_BOOT
: os
= "U-Boot"; break;
1157 case IH_OS_RTEMS
: os
= "RTEMS"; break;
1159 case IH_OS_ARTOS
: os
= "ARTOS"; break;
1161 #ifdef CONFIG_LYNXKDI
1162 case IH_OS_LYNXOS
: os
= "LynxOS"; break;
1164 default: os
= "Unknown OS"; break;
1167 switch (hdr
->ih_arch
) {
1168 case IH_CPU_INVALID
: arch
= "Invalid CPU"; break;
1169 case IH_CPU_ALPHA
: arch
= "Alpha"; break;
1170 case IH_CPU_ARM
: arch
= "ARM"; break;
1171 case IH_CPU_I386
: arch
= "Intel x86"; break;
1172 case IH_CPU_IA64
: arch
= "IA64"; break;
1173 case IH_CPU_MIPS
: arch
= "MIPS"; break;
1174 case IH_CPU_MIPS64
: arch
= "MIPS 64 Bit"; break;
1175 case IH_CPU_PPC
: arch
= "PowerPC"; break;
1176 case IH_CPU_S390
: arch
= "IBM S390"; break;
1177 case IH_CPU_SH
: arch
= "SuperH"; break;
1178 case IH_CPU_SPARC
: arch
= "SPARC"; break;
1179 case IH_CPU_SPARC64
: arch
= "SPARC 64 Bit"; break;
1180 case IH_CPU_M68K
: arch
= "M68K"; break;
1181 default: arch
= "Unknown Architecture"; break;
1184 switch (hdr
->ih_type
) {
1185 case IH_TYPE_INVALID
: type
= "Invalid Image"; break;
1186 case IH_TYPE_STANDALONE
:type
= "Standalone Program"; break;
1187 case IH_TYPE_KERNEL
: type
= "Kernel Image"; break;
1188 case IH_TYPE_RAMDISK
: type
= "RAMDisk Image"; break;
1189 case IH_TYPE_MULTI
: type
= "Multi-File Image"; break;
1190 case IH_TYPE_FIRMWARE
: type
= "Firmware"; break;
1191 case IH_TYPE_SCRIPT
: type
= "Script"; break;
1192 default: type
= "Unknown Image"; break;
1195 switch (hdr
->ih_comp
) {
1196 case IH_COMP_NONE
: comp
= "uncompressed"; break;
1197 case IH_COMP_GZIP
: comp
= "gzip compressed"; break;
1198 case IH_COMP_BZIP2
: comp
= "bzip2 compressed"; break;
1199 default: comp
= "unknown compression"; break;
1202 printf ("%s %s %s (%s)", arch
, os
, type
, comp
);
1205 #define ZALLOC_ALIGNMENT 16
1207 static void *zalloc(void *x
, unsigned items
, unsigned size
)
1212 size
= (size
+ ZALLOC_ALIGNMENT
- 1) & ~(ZALLOC_ALIGNMENT
- 1);
1219 static void zfree(void *x
, void *addr
, unsigned nb
)
1225 #define EXTRA_FIELD 4
1227 #define COMMENT 0x10
1228 #define RESERVED 0xe0
1232 int gunzip(void *dst
, int dstlen
, unsigned char *src
, int *lenp
)
1240 if (src
[2] != DEFLATED
|| (flags
& RESERVED
) != 0) {
1241 printf ("Error: Bad gzipped data\n");
1244 if ((flags
& EXTRA_FIELD
) != 0)
1245 i
= 12 + src
[10] + (src
[11] << 8);
1246 if ((flags
& ORIG_NAME
) != 0)
1247 while (src
[i
++] != 0)
1249 if ((flags
& COMMENT
) != 0)
1250 while (src
[i
++] != 0)
1252 if ((flags
& HEAD_CRC
) != 0)
1255 printf ("Error: gunzip out of data in header\n");
1261 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1262 s
.outcb
= (cb_func
)WATCHDOG_RESET
;
1265 #endif /* CONFIG_HW_WATCHDOG */
1267 r
= inflateInit2(&s
, -MAX_WBITS
);
1269 printf ("Error: inflateInit2() returned %d\n", r
);
1272 s
.next_in
= src
+ i
;
1273 s
.avail_in
= *lenp
- i
;
1275 s
.avail_out
= dstlen
;
1276 r
= inflate(&s
, Z_FINISH
);
1277 if (r
!= Z_OK
&& r
!= Z_STREAM_END
) {
1278 printf ("Error: inflate() returned %d\n", r
);
1281 *lenp
= s
.next_out
- (unsigned char *) dst
;
1288 void bz_internal_error(int errcode
)
1290 printf ("BZIP2 internal error %d\n", errcode
);
1292 #endif /* CONFIG_BZIP2 */
1295 do_bootm_rtems (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
1296 ulong addr
, ulong
*len_ptr
, int verify
)
1298 DECLARE_GLOBAL_DATA_PTR
;
1299 image_header_t
*hdr
= &header
;
1300 void (*entry_point
)(bd_t
*);
1302 entry_point
= (void (*)(bd_t
*)) hdr
->ih_ep
;
1304 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1305 (ulong
)entry_point
);
1307 SHOW_BOOT_PROGRESS (15);
1311 * r3: ptr to board info data
1314 (*entry_point
) ( gd
->bd
);
1317 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
1319 do_bootm_vxworks (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
1320 ulong addr
, ulong
*len_ptr
, int verify
)
1322 image_header_t
*hdr
= &header
;
1325 sprintf(str
, "%x", hdr
->ih_ep
); /* write entry-point into string */
1326 setenv("loadaddr", str
);
1327 do_bootvx(cmdtp
, 0, 0, NULL
);
1331 do_bootm_qnxelf (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
1332 ulong addr
, ulong
*len_ptr
, int verify
)
1334 image_header_t
*hdr
= &header
;
1335 char *local_args
[2];
1338 sprintf(str
, "%x", hdr
->ih_ep
); /* write entry-point into string */
1339 local_args
[0] = argv
[0];
1340 local_args
[1] = str
; /* and provide it via the arguments */
1341 do_bootelf(cmdtp
, 0, 2, local_args
);
1343 #endif /* CFG_CMD_ELF */
1345 #ifdef CONFIG_LYNXKDI
1347 do_bootm_lynxkdi (cmd_tbl_t
*cmdtp
, int flag
,
1348 int argc
, char *argv
[],
1353 lynxkdi_boot( &header
);
1356 #endif /* CONFIG_LYNXKDI */