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 static boot_os_Fcn do_bootm_netbsd;
121 static boot_os_Fcn do_bootm_rtems;
122 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
123 static boot_os_Fcn do_bootm_vxworks;
124 static boot_os_Fcn do_bootm_qnxelf;
125 int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
126 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
127 #endif /* CFG_CMD_ELF */
128 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
129 static boot_os_Fcn do_bootm_artos;
131 #ifdef CONFIG_LYNXKDI
132 static boot_os_Fcn do_bootm_lynxkdi;
133 extern void lynxkdi_boot( image_header_t * );
136 image_header_t header;
138 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
140 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
144 ulong data, len, checksum;
146 uint unc_len = 0x400000;
149 int (*appl)(cmd_tbl_t *, int, int, char *[]);
150 image_header_t *hdr = &header;
152 s = getenv ("verify");
153 verify = (s && (*s == 'n')) ? 0 : 1;
158 addr = simple_strtoul(argv[1], NULL, 16);
161 SHOW_BOOT_PROGRESS (1);
162 printf ("## Booting image at %08lx ...\n", addr);
164 /* Copy header so we can blank CRC field for re-calculation */
165 #ifdef CONFIG_HAS_DATAFLASH
166 if (addr_dataflash(addr)){
167 read_dataflash(addr, sizeof(image_header_t), (char *)&header);
170 memmove (&header, (char *)addr, sizeof(image_header_t));
172 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
173 #ifdef __I386__ /* correct image format not implemented yet - fake it */
174 if (fake_header(hdr, (void*)addr, -1) != NULL) {
175 /* to compensate for the addition below */
176 addr -= sizeof(image_header_t);
178 * fake_header() does not fake the data crc
182 #endif /* __I386__ */
184 printf ("Bad Magic Number\n");
185 SHOW_BOOT_PROGRESS (-1);
189 SHOW_BOOT_PROGRESS (2);
191 data = (ulong)&header;
192 len = sizeof(image_header_t);
194 checksum = ntohl(hdr->ih_hcrc);
197 if (crc32 (0, (char *)data, len) != checksum) {
198 printf ("Bad Header Checksum\n");
199 SHOW_BOOT_PROGRESS (-2);
202 SHOW_BOOT_PROGRESS (3);
204 /* for multi-file images we need the data part, too */
205 print_image_hdr (hdr);
207 data = addr + sizeof(image_header_t);
208 len = ntohl(hdr->ih_size);
210 #ifdef CONFIG_HAS_DATAFLASH
211 if (addr_dataflash(addr)){
212 read_dataflash(data, len, (char *)CFG_LOAD_ADDR);
213 data = CFG_LOAD_ADDR;
218 printf (" Verifying Checksum ... ");
219 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
220 printf ("Bad Data CRC\n");
221 SHOW_BOOT_PROGRESS (-3);
226 SHOW_BOOT_PROGRESS (4);
228 len_ptr = (ulong *)data;
231 if (hdr->ih_arch != IH_CPU_PPC)
232 #elif defined(__ARM__)
233 if (hdr->ih_arch != IH_CPU_ARM)
234 #elif defined(__I386__)
235 if (hdr->ih_arch != IH_CPU_I386)
236 #elif defined(__mips__)
237 if (hdr->ih_arch != IH_CPU_MIPS)
238 #elif defined(__nios__)
239 if (hdr->ih_arch != IH_CPU_NIOS)
241 # error Unknown CPU type
244 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
245 SHOW_BOOT_PROGRESS (-4);
248 SHOW_BOOT_PROGRESS (5);
250 switch (hdr->ih_type) {
251 case IH_TYPE_STANDALONE: name = "Standalone Application";
252 /* A second argument overwrites the load address */
254 hdr->ih_load = simple_strtoul(argv[2], NULL, 16);
257 case IH_TYPE_KERNEL: name = "Kernel Image";
259 case IH_TYPE_MULTI: name = "Multi-File Image";
260 len = ntohl(len_ptr[0]);
261 /* OS kernel is always the first image */
262 data += 8; /* kernel_len + terminator */
263 for (i=1; len_ptr[i]; ++i)
266 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
267 SHOW_BOOT_PROGRESS (-5);
270 SHOW_BOOT_PROGRESS (6);
273 * We have reached the point of no return: we are going to
274 * overwrite all exception vector code, so we cannot easily
275 * recover from any failures any more...
278 iflag = disable_interrupts();
280 #ifdef CONFIG_AMIGAONEG3SE
282 * We've possible left the caches enabled during
283 * bios emulation, so turn them off again
286 invalidate_l1_instruction_cache();
291 switch (hdr->ih_comp) {
293 if(ntohl(hdr->ih_load) == addr) {
294 printf (" XIP %s ... ", name);
296 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
298 void *to = (void *)ntohl(hdr->ih_load);
299 void *from = (void *)data;
301 printf (" Loading %s ... ", name);
304 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
306 memmove (to, from, tail);
311 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
312 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
313 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
317 printf (" Uncompressing %s ... ", name);
318 if (gunzip ((void *)ntohl(hdr->ih_load), unc_len,
319 (uchar *)data, (int *)&len) != 0) {
320 printf ("GUNZIP ERROR - must RESET board to recover\n");
321 SHOW_BOOT_PROGRESS (-6);
322 do_reset (cmdtp, flag, argc, argv);
327 printf (" Uncompressing %s ... ", name);
328 i = BZ2_bzBuffToBuffDecompress ((char*)ntohl(hdr->ih_load),
329 &unc_len, (char *)data, len, 0, 0);
331 printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
332 SHOW_BOOT_PROGRESS (-6);
334 do_reset (cmdtp, flag, argc, argv);
337 #endif /* CONFIG_BZIP2 */
341 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
342 SHOW_BOOT_PROGRESS (-7);
346 SHOW_BOOT_PROGRESS (7);
348 switch (hdr->ih_type) {
349 case IH_TYPE_STANDALONE:
353 /* load (and uncompress), but don't start if "autostart"
356 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) {
358 sprintf(buf, "%lX", len);
359 setenv("filesize", buf);
362 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
363 (*appl)(cmdtp, flag, argc-1, &argv[1]);
372 printf ("Can't boot image type %d\n", hdr->ih_type);
373 SHOW_BOOT_PROGRESS (-8);
376 SHOW_BOOT_PROGRESS (8);
378 switch (hdr->ih_os) {
379 default: /* handled by (original) Linux case */
381 do_bootm_linux (cmdtp, flag, argc, argv,
382 addr, len_ptr, verify);
385 do_bootm_netbsd (cmdtp, flag, argc, argv,
386 addr, len_ptr, verify);
389 #ifdef CONFIG_LYNXKDI
391 do_bootm_lynxkdi (cmdtp, flag, argc, argv,
392 addr, len_ptr, verify);
397 do_bootm_rtems (cmdtp, flag, argc, argv,
398 addr, len_ptr, verify);
401 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
403 do_bootm_vxworks (cmdtp, flag, argc, argv,
404 addr, len_ptr, verify);
407 do_bootm_qnxelf (cmdtp, flag, argc, argv,
408 addr, len_ptr, verify);
410 #endif /* CFG_CMD_ELF */
413 do_bootm_artos (cmdtp, flag, argc, argv,
414 addr, len_ptr, verify);
419 SHOW_BOOT_PROGRESS (-9);
421 printf ("\n## Control returned to monitor - resetting...\n");
422 do_reset (cmdtp, flag, argc, argv);
428 bootm, CFG_MAXARGS, 1, do_bootm,
429 "bootm - boot application image from memory\n",
430 "[addr [arg ...]]\n - boot application image stored in memory\n"
431 " passing arguments 'arg ...'; when booting a Linux kernel,\n"
432 " 'arg' can be the address of an initrd image\n"
437 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
438 int argc, char *argv[],
443 DECLARE_GLOBAL_DATA_PTR;
447 ulong initrd_start, initrd_end;
448 ulong cmd_start, cmd_end;
451 int initrd_copy_to_ram = 1;
455 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
456 image_header_t *hdr = &header;
458 if ((s = getenv ("initrd_high")) != NULL) {
459 /* a value of "no" or a similar string will act like 0,
460 * turning the "load high" feature off. This is intentional.
462 initrd_high = simple_strtoul(s, NULL, 16);
463 if (initrd_high == ~0)
464 initrd_copy_to_ram = 0;
465 } else { /* not set, no restrictions to load high */
469 #ifdef CONFIG_LOGBUFFER
471 /* Prevent initrd from overwriting logbuffer */
472 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
473 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
474 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
478 * Booting a (Linux) kernel image
480 * Allocate space for command line and board info - the
481 * address should be as high as possible within the reach of
482 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
483 * memory, which means far enough below the current stack
487 asm( "mr %0,1": "=r"(sp) : );
489 debug ("## Current stack ends at 0x%08lX ", sp);
491 sp -= 2048; /* just to be sure */
492 if (sp > CFG_BOOTMAPSZ)
496 debug ("=> set upper limit to 0x%08lX\n", sp);
498 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
499 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
501 if ((s = getenv("bootargs")) == NULL)
506 cmd_start = (ulong)&cmdline[0];
507 cmd_end = cmd_start + strlen(cmdline);
512 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
514 do_bdinfo (NULL, 0, 0, NULL);
517 if ((s = getenv ("clocks_in_mhz")) != NULL) {
518 /* convert all clock information to MHz */
519 kbd->bi_intfreq /= 1000000L;
520 kbd->bi_busfreq /= 1000000L;
521 #if defined(CONFIG_8260)
522 kbd->bi_cpmfreq /= 1000000L;
523 kbd->bi_brgfreq /= 1000000L;
524 kbd->bi_sccfreq /= 1000000L;
525 kbd->bi_vco /= 1000000L;
526 #endif /* CONFIG_8260 */
527 #if defined(CONFIG_MPC5XXXX)
528 kbd->bi_ipbfreq /= 1000000L;
529 kbd->bi_pcifreq /= 1000000L;
530 #endif /* CONFIG_MPC5XXXX */
533 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
536 * Check if there is an initrd image
539 SHOW_BOOT_PROGRESS (9);
541 addr = simple_strtoul(argv[2], NULL, 16);
543 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
545 /* Copy header so we can blank CRC field for re-calculation */
546 memmove (&header, (char *)addr, sizeof(image_header_t));
548 if (hdr->ih_magic != IH_MAGIC) {
549 printf ("Bad Magic Number\n");
550 SHOW_BOOT_PROGRESS (-10);
551 do_reset (cmdtp, flag, argc, argv);
554 data = (ulong)&header;
555 len = sizeof(image_header_t);
557 checksum = hdr->ih_hcrc;
560 if (crc32 (0, (char *)data, len) != checksum) {
561 printf ("Bad Header Checksum\n");
562 SHOW_BOOT_PROGRESS (-11);
563 do_reset (cmdtp, flag, argc, argv);
566 SHOW_BOOT_PROGRESS (10);
568 print_image_hdr (hdr);
570 data = addr + sizeof(image_header_t);
575 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
576 ulong cdata = data, edata = cdata + len;
577 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
579 printf (" Verifying Checksum ... ");
581 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
583 while (cdata < edata) {
584 ulong chunk = edata - cdata;
588 csum = crc32 (csum, (char *)cdata, chunk);
593 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
594 csum = crc32 (0, (char *)data, len);
595 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
597 if (csum != hdr->ih_dcrc) {
598 printf ("Bad Data CRC\n");
599 SHOW_BOOT_PROGRESS (-12);
600 do_reset (cmdtp, flag, argc, argv);
605 SHOW_BOOT_PROGRESS (11);
607 if ((hdr->ih_os != IH_OS_LINUX) ||
608 (hdr->ih_arch != IH_CPU_PPC) ||
609 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
610 printf ("No Linux PPC Ramdisk Image\n");
611 SHOW_BOOT_PROGRESS (-13);
612 do_reset (cmdtp, flag, argc, argv);
616 * Now check if we have a multifile image
618 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
619 u_long tail = ntohl(len_ptr[0]) % 4;
622 SHOW_BOOT_PROGRESS (13);
624 /* skip kernel length and terminator */
625 data = (ulong)(&len_ptr[2]);
626 /* skip any additional image length fields */
627 for (i=1; len_ptr[i]; ++i)
629 /* add kernel length, and align */
630 data += ntohl(len_ptr[0]);
635 len = ntohl(len_ptr[1]);
641 SHOW_BOOT_PROGRESS (14);
647 debug ("No initrd\n");
651 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
653 initrd_end = initrd_start + len;
655 initrd_start = (ulong)kbd - len;
656 initrd_start &= ~(4096 - 1); /* align on page */
662 * the inital ramdisk does not need to be within
663 * CFG_BOOTMAPSZ as it is not accessed until after
664 * the mm system is initialised.
666 * do the stack bottom calculation again and see if
667 * the initrd will fit just below the monitor stack
668 * bottom without overwriting the area allocated
669 * above for command line args and board info.
671 asm( "mr %0,1": "=r"(nsp) : );
672 nsp -= 2048; /* just to be sure */
674 if (nsp > initrd_high) /* limit as specified */
677 nsp &= ~(4096 - 1); /* align on page */
682 SHOW_BOOT_PROGRESS (12);
684 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
685 data, data + len - 1, len, len);
687 initrd_end = initrd_start + len;
688 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
689 initrd_start, initrd_end);
690 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
693 void *to = (void *)initrd_start;
694 void *from = (void *)data;
697 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
699 memmove (to, from, tail);
705 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
706 memmove ((void *)initrd_start, (void *)data, len);
707 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
716 debug ("## Transferring control to Linux (at address %08lx) ...\n",
719 SHOW_BOOT_PROGRESS (15);
721 #ifdef CFG_INIT_RAM_LOCK
722 unlock_ram_in_cache();
725 * Linux Kernel Parameters:
726 * r3: ptr to board info data
727 * r4: initrd_start or 0 if no initrd
728 * r5: initrd_end - unused if r4 is 0
729 * r6: Start of command line string
730 * r7: End of command line string
732 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
734 #endif /* CONFIG_PPC */
737 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
738 int argc, char *argv[],
743 DECLARE_GLOBAL_DATA_PTR;
745 image_header_t *hdr = &header;
747 void (*loader)(bd_t *, image_header_t *, char *, char *);
748 image_header_t *img_addr;
754 * Booting a (NetBSD) kernel image
756 * This process is pretty similar to a standalone application:
757 * The (first part of an multi-) image must be a stage-2 loader,
758 * which in turn is responsible for loading & invoking the actual
759 * kernel. The only differences are the parameters being passed:
760 * besides the board info strucure, the loader expects a command
761 * line, the name of the console device, and (optionally) the
762 * address of the original image header.
766 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
767 img_addr = (image_header_t *) addr;
771 #if defined (CONFIG_8xx_CONS_SMC1)
773 #elif defined (CONFIG_8xx_CONS_SMC2)
775 #elif defined (CONFIG_8xx_CONS_SCC2)
777 #elif defined (CONFIG_8xx_CONS_SCC3)
785 for (i=2, len=0 ; i<argc ; i+=1)
786 len += strlen (argv[i]) + 1;
787 cmdline = malloc (len);
789 for (i=2, len=0 ; i<argc ; i+=1) {
791 cmdline[len++] = ' ';
792 strcpy (&cmdline[len], argv[i]);
793 len += strlen (argv[i]);
795 } else if ((cmdline = getenv("bootargs")) == NULL) {
799 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
801 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
804 SHOW_BOOT_PROGRESS (15);
807 * NetBSD Stage-2 Loader Parameters:
808 * r3: ptr to board info data
811 * r6: boot args string
813 (*loader) (gd->bd, img_addr, consdev, cmdline);
816 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
818 /* Function that returns a character from the environment */
819 extern uchar (*env_get_char)(int);
822 do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
823 int argc, char *argv[],
828 DECLARE_GLOBAL_DATA_PTR;
832 int i, j, nxt, len, envno, envsz;
834 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
835 image_header_t *hdr = &header;
838 * Booting an ARTOS kernel image + application
841 /* this used to be the top of memory, but was wrong... */
843 /* get stack pointer */
844 asm volatile ("mr %0,1" : "=r"(top) );
846 debug ("## Current stack ends at 0x%08lX ", top);
848 top -= 2048; /* just to be sure */
849 if (top > CFG_BOOTMAPSZ)
853 debug ("=> set upper limit to 0x%08lX\n", top);
855 /* first check the artos specific boot args, then the linux args*/
856 if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
859 /* get length of cmdline, and place it */
861 top = (top - (len + 1)) & ~0xF;
862 cmdline = (char *)top;
863 debug ("## cmdline at 0x%08lX ", top);
867 top = (top - sizeof(bd_t)) & ~0xF;
868 debug ("## bd at 0x%08lX ", top);
870 memcpy(kbd, gd->bd, sizeof(bd_t));
872 /* first find number of env entries, and their size */
875 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
876 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
879 envsz += (nxt - i) + 1; /* plus trailing zero */
881 envno++; /* plus the terminating zero */
882 debug ("## %u envvars total size %u ", envno, envsz);
884 top = (top - sizeof(char **)*envno) & ~0xF;
885 fwenv = (char **)top;
886 debug ("## fwenv at 0x%08lX ", top);
888 top = (top - envsz) & ~0xF;
893 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
894 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
897 for (j = i; j < nxt; ++j)
898 *s++ = env_get_char(j);
901 *ss++ = NULL; /* terminate */
903 entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
904 (*entry)(kbd, cmdline, fwenv, top);
909 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
910 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
913 #ifndef CFG_HUSH_PARSER
914 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
916 if (parse_string_outer(getenv("bootcmd"),
917 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
923 boot, 1, 1, do_bootd,
924 "boot - boot default, i.e., run 'bootcmd'\n",
928 /* keep old command name "bootd" for backward compatibility */
930 bootd, 1, 1, do_bootd,
931 "bootd - boot default, i.e., run 'bootcmd'\n",
937 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
938 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
945 return image_info (load_addr);
948 for (arg=1; arg <argc; ++arg) {
949 addr = simple_strtoul(argv[arg], NULL, 16);
950 if (image_info (addr) != 0) rcode = 1;
955 static int image_info (ulong addr)
957 ulong data, len, checksum;
958 image_header_t *hdr = &header;
960 printf ("\n## Checking Image at %08lx ...\n", addr);
962 /* Copy header so we can blank CRC field for re-calculation */
963 memmove (&header, (char *)addr, sizeof(image_header_t));
965 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
966 printf (" Bad Magic Number\n");
970 data = (ulong)&header;
971 len = sizeof(image_header_t);
973 checksum = ntohl(hdr->ih_hcrc);
976 if (crc32 (0, (char *)data, len) != checksum) {
977 printf (" Bad Header Checksum\n");
981 /* for multi-file images we need the data part, too */
982 print_image_hdr ((image_header_t *)addr);
984 data = addr + sizeof(image_header_t);
985 len = ntohl(hdr->ih_size);
987 printf (" Verifying Checksum ... ");
988 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
989 printf (" Bad Data CRC\n");
997 iminfo, CFG_MAXARGS, 1, do_iminfo,
998 "iminfo - print header information for application image\n",
1000 " - print header information for application image starting at\n"
1001 " address 'addr' in memory; this includes verification of the\n"
1002 " image contents (magic number, header and payload checksums)\n"
1005 #endif /* CFG_CMD_IMI */
1007 #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
1008 /*-----------------------------------------------------------------------
1009 * List all images found in flash.
1011 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1015 image_header_t *hdr;
1018 for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
1019 if (info->flash_id == FLASH_UNKNOWN)
1021 for (j=0; j<CFG_MAX_FLASH_SECT; ++j) {
1023 if (!(hdr=(image_header_t *)info->start[j]) ||
1024 (ntohl(hdr->ih_magic) != IH_MAGIC))
1027 /* Copy header so we can blank CRC field for re-calculation */
1028 memmove (&header, (char *)hdr, sizeof(image_header_t));
1030 checksum = ntohl(header.ih_hcrc);
1033 if (crc32 (0, (char *)&header, sizeof(image_header_t))
1037 printf ("Image at %08lX:\n", (ulong)hdr);
1038 print_image_hdr( hdr );
1049 imls, 1, 1, do_imls,
1050 "imls - list all images found in flash\n",
1052 " - Prints information about all images found at sector\n"
1053 " boundaries in flash.\n"
1055 #endif /* CFG_CMD_IMLS */
1058 print_image_hdr (image_header_t *hdr)
1060 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1061 time_t timestamp = (time_t)ntohl(hdr->ih_time);
1065 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
1066 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1067 to_tm (timestamp, &tm);
1068 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
1069 tm.tm_year, tm.tm_mon, tm.tm_mday,
1070 tm.tm_hour, tm.tm_min, tm.tm_sec);
1071 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
1072 printf (" Image Type: "); print_type(hdr); printf ("\n");
1073 printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
1074 print_size (ntohl(hdr->ih_size), "\n");
1075 printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
1076 printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
1078 if (hdr->ih_type == IH_TYPE_MULTI) {
1081 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
1083 printf (" Contents:\n");
1084 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
1085 printf (" Image %d: %8ld Bytes = ", i, len);
1086 print_size (len, "\n");
1093 print_type (image_header_t *hdr)
1095 char *os, *arch, *type, *comp;
1097 switch (hdr->ih_os) {
1098 case IH_OS_INVALID: os = "Invalid OS"; break;
1099 case IH_OS_NETBSD: os = "NetBSD"; break;
1100 case IH_OS_LINUX: os = "Linux"; break;
1101 case IH_OS_VXWORKS: os = "VxWorks"; break;
1102 case IH_OS_QNX: os = "QNX"; break;
1103 case IH_OS_U_BOOT: os = "U-Boot"; break;
1104 case IH_OS_RTEMS: os = "RTEMS"; break;
1106 case IH_OS_ARTOS: os = "ARTOS"; break;
1108 #ifdef CONFIG_LYNXKDI
1109 case IH_OS_LYNXOS: os = "LynxOS"; break;
1111 default: os = "Unknown OS"; break;
1114 switch (hdr->ih_arch) {
1115 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
1116 case IH_CPU_ALPHA: arch = "Alpha"; break;
1117 case IH_CPU_ARM: arch = "ARM"; break;
1118 case IH_CPU_I386: arch = "Intel x86"; break;
1119 case IH_CPU_IA64: arch = "IA64"; break;
1120 case IH_CPU_MIPS: arch = "MIPS"; break;
1121 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
1122 case IH_CPU_PPC: arch = "PowerPC"; break;
1123 case IH_CPU_S390: arch = "IBM S390"; break;
1124 case IH_CPU_SH: arch = "SuperH"; break;
1125 case IH_CPU_SPARC: arch = "SPARC"; break;
1126 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
1127 case IH_CPU_M68K: arch = "M68K"; break;
1128 default: arch = "Unknown Architecture"; break;
1131 switch (hdr->ih_type) {
1132 case IH_TYPE_INVALID: type = "Invalid Image"; break;
1133 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
1134 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
1135 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
1136 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
1137 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
1138 case IH_TYPE_SCRIPT: type = "Script"; break;
1139 default: type = "Unknown Image"; break;
1142 switch (hdr->ih_comp) {
1143 case IH_COMP_NONE: comp = "uncompressed"; break;
1144 case IH_COMP_GZIP: comp = "gzip compressed"; break;
1145 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
1146 default: comp = "unknown compression"; break;
1149 printf ("%s %s %s (%s)", arch, os, type, comp);
1152 #define ZALLOC_ALIGNMENT 16
1154 static void *zalloc(void *x, unsigned items, unsigned size)
1159 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
1166 static void zfree(void *x, void *addr, unsigned nb)
1172 #define EXTRA_FIELD 4
1174 #define COMMENT 0x10
1175 #define RESERVED 0xe0
1179 int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
1187 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
1188 printf ("Error: Bad gzipped data\n");
1191 if ((flags & EXTRA_FIELD) != 0)
1192 i = 12 + src[10] + (src[11] << 8);
1193 if ((flags & ORIG_NAME) != 0)
1194 while (src[i++] != 0)
1196 if ((flags & COMMENT) != 0)
1197 while (src[i++] != 0)
1199 if ((flags & HEAD_CRC) != 0)
1202 printf ("Error: gunzip out of data in header\n");
1208 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1209 s.outcb = (cb_func)WATCHDOG_RESET;
1212 #endif /* CONFIG_HW_WATCHDOG */
1214 r = inflateInit2(&s, -MAX_WBITS);
1216 printf ("Error: inflateInit2() returned %d\n", r);
1219 s.next_in = src + i;
1220 s.avail_in = *lenp - i;
1222 s.avail_out = dstlen;
1223 r = inflate(&s, Z_FINISH);
1224 if (r != Z_OK && r != Z_STREAM_END) {
1225 printf ("Error: inflate() returned %d\n", r);
1228 *lenp = s.next_out - (unsigned char *) dst;
1235 void bz_internal_error(int errcode)
1237 printf ("BZIP2 internal error %d\n", errcode);
1239 #endif /* CONFIG_BZIP2 */
1242 do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1243 ulong addr, ulong *len_ptr, int verify)
1245 DECLARE_GLOBAL_DATA_PTR;
1246 image_header_t *hdr = &header;
1247 void (*entry_point)(bd_t *);
1249 entry_point = (void (*)(bd_t *)) hdr->ih_ep;
1251 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1252 (ulong)entry_point);
1254 SHOW_BOOT_PROGRESS (15);
1258 * r3: ptr to board info data
1261 (*entry_point ) ( gd->bd );
1264 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
1266 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1267 ulong addr, ulong *len_ptr, int verify)
1269 image_header_t *hdr = &header;
1272 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1273 setenv("loadaddr", str);
1274 do_bootvx(cmdtp, 0, 0, NULL);
1278 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1279 ulong addr, ulong *len_ptr, int verify)
1281 image_header_t *hdr = &header;
1282 char *local_args[2];
1285 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1286 local_args[0] = argv[0];
1287 local_args[1] = str; /* and provide it via the arguments */
1288 do_bootelf(cmdtp, 0, 2, local_args);
1290 #endif /* CFG_CMD_ELF */
1292 #ifdef CONFIG_LYNXKDI
1294 do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
1295 int argc, char *argv[],
1300 lynxkdi_boot( &header );
1303 #endif /* CONFIG_LYNXKDI */