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)
239 # error Unknown CPU type
242 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
243 SHOW_BOOT_PROGRESS (-4);
246 SHOW_BOOT_PROGRESS (5);
248 switch (hdr->ih_type) {
249 case IH_TYPE_STANDALONE: name = "Standalone Application";
251 case IH_TYPE_KERNEL: name = "Kernel Image";
253 case IH_TYPE_MULTI: name = "Multi-File Image";
254 len = ntohl(len_ptr[0]);
255 /* OS kernel is always the first image */
256 data += 8; /* kernel_len + terminator */
257 for (i=1; len_ptr[i]; ++i)
260 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
261 SHOW_BOOT_PROGRESS (-5);
264 SHOW_BOOT_PROGRESS (6);
267 * We have reached the point of no return: we are going to
268 * overwrite all exception vector code, so we cannot easily
269 * recover from any failures any more...
272 iflag = disable_interrupts();
274 #ifdef CONFIG_AMIGAONEG3SE
276 * We've possible left the caches enabled during
277 * bios emulation, so turn them off again
280 invalidate_l1_instruction_cache();
285 switch (hdr->ih_comp) {
287 if(ntohl(hdr->ih_load) == addr) {
288 printf (" XIP %s ... ", name);
290 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
292 void *to = (void *)ntohl(hdr->ih_load);
293 void *from = (void *)data;
295 printf (" Loading %s ... ", name);
298 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
300 memmove (to, from, tail);
305 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
306 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
307 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
311 printf (" Uncompressing %s ... ", name);
312 if (gunzip ((void *)ntohl(hdr->ih_load), unc_len,
313 (uchar *)data, (int *)&len) != 0) {
314 printf ("GUNZIP ERROR - must RESET board to recover\n");
315 SHOW_BOOT_PROGRESS (-6);
316 do_reset (cmdtp, flag, argc, argv);
321 printf (" Uncompressing %s ... ", name);
322 i = BZ2_bzBuffToBuffDecompress ((char*)ntohl(hdr->ih_load),
323 &unc_len, (char *)data, len, 0, 0);
325 printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
326 SHOW_BOOT_PROGRESS (-6);
328 do_reset (cmdtp, flag, argc, argv);
331 #endif /* CONFIG_BZIP2 */
335 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
336 SHOW_BOOT_PROGRESS (-7);
340 SHOW_BOOT_PROGRESS (7);
342 switch (hdr->ih_type) {
343 case IH_TYPE_STANDALONE:
347 /* load (and uncompress), but don't start if "autostart"
350 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0))
352 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
353 (*appl)(cmdtp, flag, argc-1, &argv[1]);
362 printf ("Can't boot image type %d\n", hdr->ih_type);
363 SHOW_BOOT_PROGRESS (-8);
366 SHOW_BOOT_PROGRESS (8);
368 switch (hdr->ih_os) {
369 default: /* handled by (original) Linux case */
371 do_bootm_linux (cmdtp, flag, argc, argv,
372 addr, len_ptr, verify);
375 do_bootm_netbsd (cmdtp, flag, argc, argv,
376 addr, len_ptr, verify);
379 #ifdef CONFIG_LYNXKDI
381 do_bootm_lynxkdi (cmdtp, flag, argc, argv,
382 addr, len_ptr, verify);
387 do_bootm_rtems (cmdtp, flag, argc, argv,
388 addr, len_ptr, verify);
391 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
393 do_bootm_vxworks (cmdtp, flag, argc, argv,
394 addr, len_ptr, verify);
397 do_bootm_qnxelf (cmdtp, flag, argc, argv,
398 addr, len_ptr, verify);
400 #endif /* CFG_CMD_ELF */
403 do_bootm_artos (cmdtp, flag, argc, argv,
404 addr, len_ptr, verify);
409 SHOW_BOOT_PROGRESS (-9);
411 printf ("\n## Control returned to monitor - resetting...\n");
412 do_reset (cmdtp, flag, argc, argv);
418 bootm, CFG_MAXARGS, 1, do_bootm,
419 "bootm - boot application image from memory\n",
420 "[addr [arg ...]]\n - boot application image stored in memory\n"
421 " passing arguments 'arg ...'; when booting a Linux kernel,\n"
422 " 'arg' can be the address of an initrd image\n"
427 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
428 int argc, char *argv[],
433 DECLARE_GLOBAL_DATA_PTR;
437 ulong initrd_start, initrd_end;
438 ulong cmd_start, cmd_end;
441 int initrd_copy_to_ram = 1;
445 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
446 image_header_t *hdr = &header;
448 if ((s = getenv ("initrd_high")) != NULL) {
449 /* a value of "no" or a similar string will act like 0,
450 * turning the "load high" feature off. This is intentional.
452 initrd_high = simple_strtoul(s, NULL, 16);
453 if (initrd_high == ~0)
454 initrd_copy_to_ram = 0;
455 } else { /* not set, no restrictions to load high */
459 #ifdef CONFIG_LOGBUFFER
461 /* Prevent initrd from overwriting logbuffer */
462 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
463 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
464 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
468 * Booting a (Linux) kernel image
470 * Allocate space for command line and board info - the
471 * address should be as high as possible within the reach of
472 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
473 * memory, which means far enough below the current stack
477 asm( "mr %0,1": "=r"(sp) : );
479 debug ("## Current stack ends at 0x%08lX ", sp);
481 sp -= 2048; /* just to be sure */
482 if (sp > CFG_BOOTMAPSZ)
486 debug ("=> set upper limit to 0x%08lX\n", sp);
488 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
489 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
491 if ((s = getenv("bootargs")) == NULL)
496 cmd_start = (ulong)&cmdline[0];
497 cmd_end = cmd_start + strlen(cmdline);
502 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
504 do_bdinfo (NULL, 0, 0, NULL);
507 if ((s = getenv ("clocks_in_mhz")) != NULL) {
508 /* convert all clock information to MHz */
509 kbd->bi_intfreq /= 1000000L;
510 kbd->bi_busfreq /= 1000000L;
511 #if defined(CONFIG_8260)
512 kbd->bi_cpmfreq /= 1000000L;
513 kbd->bi_brgfreq /= 1000000L;
514 kbd->bi_sccfreq /= 1000000L;
515 kbd->bi_vco /= 1000000L;
516 #endif /* CONFIG_8260 */
517 #if defined(CONFIG_MPC5XXXX)
518 kbd->bi_ipbfreq /= 1000000L;
519 kbd->bi_pcifreq /= 1000000L;
520 #endif /* CONFIG_MPC5XXXX */
523 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
526 * Check if there is an initrd image
529 SHOW_BOOT_PROGRESS (9);
531 addr = simple_strtoul(argv[2], NULL, 16);
533 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
535 /* Copy header so we can blank CRC field for re-calculation */
536 memmove (&header, (char *)addr, sizeof(image_header_t));
538 if (hdr->ih_magic != IH_MAGIC) {
539 printf ("Bad Magic Number\n");
540 SHOW_BOOT_PROGRESS (-10);
541 do_reset (cmdtp, flag, argc, argv);
544 data = (ulong)&header;
545 len = sizeof(image_header_t);
547 checksum = hdr->ih_hcrc;
550 if (crc32 (0, (char *)data, len) != checksum) {
551 printf ("Bad Header Checksum\n");
552 SHOW_BOOT_PROGRESS (-11);
553 do_reset (cmdtp, flag, argc, argv);
556 SHOW_BOOT_PROGRESS (10);
558 print_image_hdr (hdr);
560 data = addr + sizeof(image_header_t);
565 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
566 ulong cdata = data, edata = cdata + len;
567 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
569 printf (" Verifying Checksum ... ");
571 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
573 while (cdata < edata) {
574 ulong chunk = edata - cdata;
578 csum = crc32 (csum, (char *)cdata, chunk);
583 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
584 csum = crc32 (0, (char *)data, len);
585 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
587 if (csum != hdr->ih_dcrc) {
588 printf ("Bad Data CRC\n");
589 SHOW_BOOT_PROGRESS (-12);
590 do_reset (cmdtp, flag, argc, argv);
595 SHOW_BOOT_PROGRESS (11);
597 if ((hdr->ih_os != IH_OS_LINUX) ||
598 (hdr->ih_arch != IH_CPU_PPC) ||
599 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
600 printf ("No Linux PPC Ramdisk Image\n");
601 SHOW_BOOT_PROGRESS (-13);
602 do_reset (cmdtp, flag, argc, argv);
606 * Now check if we have a multifile image
608 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
609 u_long tail = ntohl(len_ptr[0]) % 4;
612 SHOW_BOOT_PROGRESS (13);
614 /* skip kernel length and terminator */
615 data = (ulong)(&len_ptr[2]);
616 /* skip any additional image length fields */
617 for (i=1; len_ptr[i]; ++i)
619 /* add kernel length, and align */
620 data += ntohl(len_ptr[0]);
625 len = ntohl(len_ptr[1]);
631 SHOW_BOOT_PROGRESS (14);
637 debug ("No initrd\n");
641 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
643 initrd_end = initrd_start + len;
645 initrd_start = (ulong)kbd - len;
646 initrd_start &= ~(4096 - 1); /* align on page */
652 * the inital ramdisk does not need to be within
653 * CFG_BOOTMAPSZ as it is not accessed until after
654 * the mm system is initialised.
656 * do the stack bottom calculation again and see if
657 * the initrd will fit just below the monitor stack
658 * bottom without overwriting the area allocated
659 * above for command line args and board info.
661 asm( "mr %0,1": "=r"(nsp) : );
662 nsp -= 2048; /* just to be sure */
664 if (nsp > initrd_high) /* limit as specified */
667 nsp &= ~(4096 - 1); /* align on page */
672 SHOW_BOOT_PROGRESS (12);
674 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
675 data, data + len - 1, len, len);
677 initrd_end = initrd_start + len;
678 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
679 initrd_start, initrd_end);
680 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
683 void *to = (void *)initrd_start;
684 void *from = (void *)data;
687 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
689 memmove (to, from, tail);
695 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
696 memmove ((void *)initrd_start, (void *)data, len);
697 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
706 debug ("## Transferring control to Linux (at address %08lx) ...\n",
709 SHOW_BOOT_PROGRESS (15);
711 #ifdef CFG_INIT_RAM_LOCK
712 unlock_ram_in_cache();
715 * Linux Kernel Parameters:
716 * r3: ptr to board info data
717 * r4: initrd_start or 0 if no initrd
718 * r5: initrd_end - unused if r4 is 0
719 * r6: Start of command line string
720 * r7: End of command line string
722 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
724 #endif /* CONFIG_PPC */
727 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
728 int argc, char *argv[],
733 DECLARE_GLOBAL_DATA_PTR;
735 image_header_t *hdr = &header;
737 void (*loader)(bd_t *, image_header_t *, char *, char *);
738 image_header_t *img_addr;
744 * Booting a (NetBSD) kernel image
746 * This process is pretty similar to a standalone application:
747 * The (first part of an multi-) image must be a stage-2 loader,
748 * which in turn is responsible for loading & invoking the actual
749 * kernel. The only differences are the parameters being passed:
750 * besides the board info strucure, the loader expects a command
751 * line, the name of the console device, and (optionally) the
752 * address of the original image header.
756 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
757 img_addr = (image_header_t *) addr;
761 #if defined (CONFIG_8xx_CONS_SMC1)
763 #elif defined (CONFIG_8xx_CONS_SMC2)
765 #elif defined (CONFIG_8xx_CONS_SCC2)
767 #elif defined (CONFIG_8xx_CONS_SCC3)
775 for (i=2, len=0 ; i<argc ; i+=1)
776 len += strlen (argv[i]) + 1;
777 cmdline = malloc (len);
779 for (i=2, len=0 ; i<argc ; i+=1) {
781 cmdline[len++] = ' ';
782 strcpy (&cmdline[len], argv[i]);
783 len += strlen (argv[i]);
785 } else if ((cmdline = getenv("bootargs")) == NULL) {
789 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
791 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
794 SHOW_BOOT_PROGRESS (15);
797 * NetBSD Stage-2 Loader Parameters:
798 * r3: ptr to board info data
801 * r6: boot args string
803 (*loader) (gd->bd, img_addr, consdev, cmdline);
806 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
808 /* Function that returns a character from the environment */
809 extern uchar (*env_get_char)(int);
812 do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
813 int argc, char *argv[],
818 DECLARE_GLOBAL_DATA_PTR;
822 int i, j, nxt, len, envno, envsz;
824 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
825 image_header_t *hdr = &header;
828 * Booting an ARTOS kernel image + application
831 /* this used to be the top of memory, but was wrong... */
833 /* get stack pointer */
834 asm volatile ("mr %0,1" : "=r"(top) );
836 debug ("## Current stack ends at 0x%08lX ", top);
838 top -= 2048; /* just to be sure */
839 if (top > CFG_BOOTMAPSZ)
843 debug ("=> set upper limit to 0x%08lX\n", top);
845 /* first check the artos specific boot args, then the linux args*/
846 if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
849 /* get length of cmdline, and place it */
851 top = (top - (len + 1)) & ~0xF;
852 cmdline = (char *)top;
853 debug ("## cmdline at 0x%08lX ", top);
857 top = (top - sizeof(bd_t)) & ~0xF;
858 debug ("## bd at 0x%08lX ", top);
860 memcpy(kbd, gd->bd, sizeof(bd_t));
862 /* first find number of env entries, and their size */
865 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
866 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
869 envsz += (nxt - i) + 1; /* plus trailing zero */
871 envno++; /* plus the terminating zero */
872 debug ("## %u envvars total size %u ", envno, envsz);
874 top = (top - sizeof(char **)*envno) & ~0xF;
875 fwenv = (char **)top;
876 debug ("## fwenv at 0x%08lX ", top);
878 top = (top - envsz) & ~0xF;
883 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
884 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
887 for (j = i; j < nxt; ++j)
888 *s++ = env_get_char(j);
891 *ss++ = NULL; /* terminate */
893 entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
894 (*entry)(kbd, cmdline, fwenv, top);
899 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
900 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
903 #ifndef CFG_HUSH_PARSER
904 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
906 if (parse_string_outer(getenv("bootcmd"),
907 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
913 boot, 1, 1, do_bootd,
914 "boot - boot default, i.e., run 'bootcmd'\n",
918 /* keep old command name "bootd" for backward compatibility */
920 bootd, 1, 1, do_bootd,
921 "bootd - boot default, i.e., run 'bootcmd'\n",
927 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
928 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
935 return image_info (load_addr);
938 for (arg=1; arg <argc; ++arg) {
939 addr = simple_strtoul(argv[arg], NULL, 16);
940 if (image_info (addr) != 0) rcode = 1;
945 static int image_info (ulong addr)
947 ulong data, len, checksum;
948 image_header_t *hdr = &header;
950 printf ("\n## Checking Image at %08lx ...\n", addr);
952 /* Copy header so we can blank CRC field for re-calculation */
953 memmove (&header, (char *)addr, sizeof(image_header_t));
955 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
956 printf (" Bad Magic Number\n");
960 data = (ulong)&header;
961 len = sizeof(image_header_t);
963 checksum = ntohl(hdr->ih_hcrc);
966 if (crc32 (0, (char *)data, len) != checksum) {
967 printf (" Bad Header Checksum\n");
971 /* for multi-file images we need the data part, too */
972 print_image_hdr ((image_header_t *)addr);
974 data = addr + sizeof(image_header_t);
975 len = ntohl(hdr->ih_size);
977 printf (" Verifying Checksum ... ");
978 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
979 printf (" Bad Data CRC\n");
987 iminfo, CFG_MAXARGS, 1, do_iminfo,
988 "iminfo - print header information for application image\n",
990 " - print header information for application image starting at\n"
991 " address 'addr' in memory; this includes verification of the\n"
992 " image contents (magic number, header and payload checksums)\n"
995 #endif /* CFG_CMD_IMI */
997 #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
998 /*-----------------------------------------------------------------------
999 * List all images found in flash.
1001 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1005 image_header_t *hdr;
1008 for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
1009 if (info->flash_id == FLASH_UNKNOWN)
1011 for (j=0; j<CFG_MAX_FLASH_SECT; ++j) {
1013 if (!(hdr=(image_header_t *)info->start[j]) ||
1014 (ntohl(hdr->ih_magic) != IH_MAGIC))
1017 /* Copy header so we can blank CRC field for re-calculation */
1018 memmove (&header, (char *)hdr, sizeof(image_header_t));
1020 checksum = ntohl(header.ih_hcrc);
1023 if (crc32 (0, (char *)&header, sizeof(image_header_t))
1027 printf ("Image at %08lX:\n", (ulong)hdr);
1028 print_image_hdr( hdr );
1039 imls, 1, 1, do_imls,
1040 "imls - list all images found in flash\n",
1042 " - Prints information about all images found at sector\n"
1043 " boundaries in flash.\n"
1045 #endif /* CFG_CMD_IMLS */
1048 print_image_hdr (image_header_t *hdr)
1050 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1051 time_t timestamp = (time_t)ntohl(hdr->ih_time);
1055 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
1056 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1057 to_tm (timestamp, &tm);
1058 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
1059 tm.tm_year, tm.tm_mon, tm.tm_mday,
1060 tm.tm_hour, tm.tm_min, tm.tm_sec);
1061 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
1062 printf (" Image Type: "); print_type(hdr); printf ("\n");
1063 printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
1064 print_size (ntohl(hdr->ih_size), "\n");
1065 printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
1066 printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
1068 if (hdr->ih_type == IH_TYPE_MULTI) {
1071 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
1073 printf (" Contents:\n");
1074 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
1075 printf (" Image %d: %8ld Bytes = ", i, len);
1076 print_size (len, "\n");
1083 print_type (image_header_t *hdr)
1085 char *os, *arch, *type, *comp;
1087 switch (hdr->ih_os) {
1088 case IH_OS_INVALID: os = "Invalid OS"; break;
1089 case IH_OS_NETBSD: os = "NetBSD"; break;
1090 case IH_OS_LINUX: os = "Linux"; break;
1091 case IH_OS_VXWORKS: os = "VxWorks"; break;
1092 case IH_OS_QNX: os = "QNX"; break;
1093 case IH_OS_U_BOOT: os = "U-Boot"; break;
1094 case IH_OS_RTEMS: os = "RTEMS"; break;
1096 case IH_OS_ARTOS: os = "ARTOS"; break;
1098 #ifdef CONFIG_LYNXKDI
1099 case IH_OS_LYNXOS: os = "LynxOS"; break;
1101 default: os = "Unknown OS"; break;
1104 switch (hdr->ih_arch) {
1105 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
1106 case IH_CPU_ALPHA: arch = "Alpha"; break;
1107 case IH_CPU_ARM: arch = "ARM"; break;
1108 case IH_CPU_I386: arch = "Intel x86"; break;
1109 case IH_CPU_IA64: arch = "IA64"; break;
1110 case IH_CPU_MIPS: arch = "MIPS"; break;
1111 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
1112 case IH_CPU_PPC: arch = "PowerPC"; break;
1113 case IH_CPU_S390: arch = "IBM S390"; break;
1114 case IH_CPU_SH: arch = "SuperH"; break;
1115 case IH_CPU_SPARC: arch = "SPARC"; break;
1116 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
1117 case IH_CPU_M68K: arch = "M68K"; break;
1118 default: arch = "Unknown Architecture"; break;
1121 switch (hdr->ih_type) {
1122 case IH_TYPE_INVALID: type = "Invalid Image"; break;
1123 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
1124 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
1125 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
1126 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
1127 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
1128 case IH_TYPE_SCRIPT: type = "Script"; break;
1129 default: type = "Unknown Image"; break;
1132 switch (hdr->ih_comp) {
1133 case IH_COMP_NONE: comp = "uncompressed"; break;
1134 case IH_COMP_GZIP: comp = "gzip compressed"; break;
1135 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
1136 default: comp = "unknown compression"; break;
1139 printf ("%s %s %s (%s)", arch, os, type, comp);
1142 #define ZALLOC_ALIGNMENT 16
1144 static void *zalloc(void *x, unsigned items, unsigned size)
1149 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
1156 static void zfree(void *x, void *addr, unsigned nb)
1162 #define EXTRA_FIELD 4
1164 #define COMMENT 0x10
1165 #define RESERVED 0xe0
1169 int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
1177 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
1178 printf ("Error: Bad gzipped data\n");
1181 if ((flags & EXTRA_FIELD) != 0)
1182 i = 12 + src[10] + (src[11] << 8);
1183 if ((flags & ORIG_NAME) != 0)
1184 while (src[i++] != 0)
1186 if ((flags & COMMENT) != 0)
1187 while (src[i++] != 0)
1189 if ((flags & HEAD_CRC) != 0)
1192 printf ("Error: gunzip out of data in header\n");
1198 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1199 s.outcb = (cb_func)WATCHDOG_RESET;
1202 #endif /* CONFIG_HW_WATCHDOG */
1204 r = inflateInit2(&s, -MAX_WBITS);
1206 printf ("Error: inflateInit2() returned %d\n", r);
1209 s.next_in = src + i;
1210 s.avail_in = *lenp - i;
1212 s.avail_out = dstlen;
1213 r = inflate(&s, Z_FINISH);
1214 if (r != Z_OK && r != Z_STREAM_END) {
1215 printf ("Error: inflate() returned %d\n", r);
1218 *lenp = s.next_out - (unsigned char *) dst;
1225 void bz_internal_error(int errcode)
1227 printf ("BZIP2 internal error %d\n", errcode);
1229 #endif /* CONFIG_BZIP2 */
1232 do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1233 ulong addr, ulong *len_ptr, int verify)
1235 DECLARE_GLOBAL_DATA_PTR;
1236 image_header_t *hdr = &header;
1237 void (*entry_point)(bd_t *);
1239 entry_point = (void (*)(bd_t *)) hdr->ih_ep;
1241 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1242 (ulong)entry_point);
1244 SHOW_BOOT_PROGRESS (15);
1248 * r3: ptr to board info data
1251 (*entry_point ) ( gd->bd );
1254 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
1256 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1257 ulong addr, ulong *len_ptr, int verify)
1259 image_header_t *hdr = &header;
1262 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1263 setenv("loadaddr", str);
1264 do_bootvx(cmdtp, 0, 0, NULL);
1268 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1269 ulong addr, ulong *len_ptr, int verify)
1271 image_header_t *hdr = &header;
1272 char *local_args[2];
1275 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1276 local_args[0] = argv[0];
1277 local_args[1] = str; /* and provide it via the arguments */
1278 do_bootelf(cmdtp, 0, 2, local_args);
1280 #endif /* CFG_CMD_ELF */
1282 #ifdef CONFIG_LYNXKDI
1284 do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
1285 int argc, char *argv[],
1290 lynxkdi_boot( &header );
1293 #endif /* CONFIG_LYNXKDI */