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;
131 image_header_t header;
133 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
135 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
139 ulong data, len, checksum;
143 int (*appl)(cmd_tbl_t *, int, int, char *[]);
144 image_header_t *hdr = &header;
146 s = getenv ("verify");
147 verify = (s && (*s == 'n')) ? 0 : 1;
152 addr = simple_strtoul(argv[1], NULL, 16);
155 SHOW_BOOT_PROGRESS (1);
156 printf ("## Booting image at %08lx ...\n", addr);
158 /* Copy header so we can blank CRC field for re-calculation */
159 #ifdef CONFIG_HAS_DATAFLASH
160 if (addr_dataflash(addr)){
161 read_dataflash(addr, sizeof(image_header_t), (char *)&header);
164 memmove (&header, (char *)addr, sizeof(image_header_t));
166 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
167 #ifdef __I386__ /* correct image format not implemented yet - fake it */
168 if (fake_header(hdr, (void*)addr, -1) != NULL) {
169 /* to compensate for the addition below */
170 addr -= sizeof(image_header_t);
172 * fake_header() does not fake the data crc
176 #endif /* __I386__ */
178 printf ("Bad Magic Number\n");
179 SHOW_BOOT_PROGRESS (-1);
183 SHOW_BOOT_PROGRESS (2);
185 data = (ulong)&header;
186 len = sizeof(image_header_t);
188 checksum = ntohl(hdr->ih_hcrc);
191 if (crc32 (0, (char *)data, len) != checksum) {
192 printf ("Bad Header Checksum\n");
193 SHOW_BOOT_PROGRESS (-2);
196 SHOW_BOOT_PROGRESS (3);
198 /* for multi-file images we need the data part, too */
199 print_image_hdr (hdr);
201 data = addr + sizeof(image_header_t);
202 len = ntohl(hdr->ih_size);
204 #ifdef CONFIG_HAS_DATAFLASH
205 if (addr_dataflash(addr)){
206 read_dataflash(data, len, (char *)CFG_LOAD_ADDR);
207 data = CFG_LOAD_ADDR;
212 printf (" Verifying Checksum ... ");
213 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
214 printf ("Bad Data CRC\n");
215 SHOW_BOOT_PROGRESS (-3);
220 SHOW_BOOT_PROGRESS (4);
222 len_ptr = (ulong *)data;
225 if (hdr->ih_arch != IH_CPU_PPC)
226 #elif defined(__ARM__)
227 if (hdr->ih_arch != IH_CPU_ARM)
228 #elif defined(__I386__)
229 if (hdr->ih_arch != IH_CPU_I386)
230 #elif defined(__mips__)
231 if (hdr->ih_arch != IH_CPU_MIPS)
233 # error Unknown CPU type
236 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
237 SHOW_BOOT_PROGRESS (-4);
240 SHOW_BOOT_PROGRESS (5);
242 switch (hdr->ih_type) {
243 case IH_TYPE_STANDALONE: name = "Standalone Application";
245 case IH_TYPE_KERNEL: name = "Kernel Image";
247 case IH_TYPE_MULTI: name = "Multi-File Image";
248 len = ntohl(len_ptr[0]);
249 /* OS kernel is always the first image */
250 data += 8; /* kernel_len + terminator */
251 for (i=1; len_ptr[i]; ++i)
254 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
255 SHOW_BOOT_PROGRESS (-5);
258 SHOW_BOOT_PROGRESS (6);
261 * We have reached the point of no return: we are going to
262 * overwrite all exception vector code, so we cannot easily
263 * recover from any failures any more...
266 iflag = disable_interrupts();
268 #ifdef CONFIG_AMIGAONEG3SE
270 * We've possible left the caches enabled during
271 * bios emulation, so turn them off again
274 invalidate_l1_instruction_cache();
279 switch (hdr->ih_comp) {
281 if(ntohl(hdr->ih_load) == addr) {
282 printf (" XIP %s ... ", name);
284 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
286 void *to = (void *)ntohl(hdr->ih_load);
287 void *from = (void *)data;
289 printf (" Loading %s ... ", name);
292 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
294 memmove (to, from, tail);
299 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
300 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
301 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
305 printf (" Uncompressing %s ... ", name);
306 if (gunzip ((void *)ntohl(hdr->ih_load), 0x400000,
307 (uchar *)data, (int *)&len) != 0) {
308 printf ("GUNZIP ERROR - must RESET board to recover\n");
309 SHOW_BOOT_PROGRESS (-6);
310 do_reset (cmdtp, flag, argc, argv);
316 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
317 SHOW_BOOT_PROGRESS (-7);
321 SHOW_BOOT_PROGRESS (7);
323 switch (hdr->ih_type) {
324 case IH_TYPE_STANDALONE:
328 /* load (and uncompress), but don't start if "autostart"
331 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0))
333 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
334 (*appl)(cmdtp, flag, argc-1, &argv[1]);
343 printf ("Can't boot image type %d\n", hdr->ih_type);
344 SHOW_BOOT_PROGRESS (-8);
347 SHOW_BOOT_PROGRESS (8);
349 switch (hdr->ih_os) {
350 default: /* handled by (original) Linux case */
352 do_bootm_linux (cmdtp, flag, argc, argv,
353 addr, len_ptr, verify);
356 do_bootm_netbsd (cmdtp, flag, argc, argv,
357 addr, len_ptr, verify);
361 do_bootm_rtems (cmdtp, flag, argc, argv,
362 addr, len_ptr, verify);
365 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
367 do_bootm_vxworks (cmdtp, flag, argc, argv,
368 addr, len_ptr, verify);
371 do_bootm_qnxelf (cmdtp, flag, argc, argv,
372 addr, len_ptr, verify);
374 #endif /* CFG_CMD_ELF */
377 do_bootm_artos (cmdtp, flag, argc, argv,
378 addr, len_ptr, verify);
383 SHOW_BOOT_PROGRESS (-9);
385 printf ("\n## Control returned to monitor - resetting...\n");
386 do_reset (cmdtp, flag, argc, argv);
392 bootm, CFG_MAXARGS, 1, do_bootm,
393 "bootm - boot application image from memory\n",
394 "[addr [arg ...]]\n - boot application image stored in memory\n"
395 " passing arguments 'arg ...'; when booting a Linux kernel,\n"
396 " 'arg' can be the address of an initrd image\n"
401 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
402 int argc, char *argv[],
407 DECLARE_GLOBAL_DATA_PTR;
411 ulong initrd_start, initrd_end;
412 ulong cmd_start, cmd_end;
415 int initrd_copy_to_ram = 1;
419 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
420 image_header_t *hdr = &header;
422 if ((s = getenv ("initrd_high")) != NULL) {
423 /* a value of "no" or a similar string will act like 0,
424 * turning the "load high" feature off. This is intentional.
426 initrd_high = simple_strtoul(s, NULL, 16);
427 if (initrd_high == ~0)
428 initrd_copy_to_ram = 0;
429 } else { /* not set, no restrictions to load high */
433 #ifdef CONFIG_LOGBUFFER
435 /* Prevent initrd from overwriting logbuffer */
436 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
437 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
438 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
442 * Booting a (Linux) kernel image
444 * Allocate space for command line and board info - the
445 * address should be as high as possible within the reach of
446 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
447 * memory, which means far enough below the current stack
451 asm( "mr %0,1": "=r"(sp) : );
453 debug ("## Current stack ends at 0x%08lX ", sp);
455 sp -= 2048; /* just to be sure */
456 if (sp > CFG_BOOTMAPSZ)
460 debug ("=> set upper limit to 0x%08lX\n", sp);
462 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
463 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
465 if ((s = getenv("bootargs")) == NULL)
470 cmd_start = (ulong)&cmdline[0];
471 cmd_end = cmd_start + strlen(cmdline);
476 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
478 do_bdinfo (NULL, 0, 0, NULL);
481 if ((s = getenv ("clocks_in_mhz")) != NULL) {
482 /* convert all clock information to MHz */
483 kbd->bi_intfreq /= 1000000L;
484 kbd->bi_busfreq /= 1000000L;
485 #if defined(CONFIG_8260)
486 kbd->bi_cpmfreq /= 1000000L;
487 kbd->bi_brgfreq /= 1000000L;
488 kbd->bi_sccfreq /= 1000000L;
489 kbd->bi_vco /= 1000000L;
490 #endif /* CONFIG_8260 */
491 #if defined(CONFIG_MPC5XXXX)
492 kbd->bi_ipbfreq /= 1000000L;
493 kbd->bi_pcifreq /= 1000000L;
494 #endif /* CONFIG_MPC5XXXX */
497 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
500 * Check if there is an initrd image
503 SHOW_BOOT_PROGRESS (9);
505 addr = simple_strtoul(argv[2], NULL, 16);
507 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
509 /* Copy header so we can blank CRC field for re-calculation */
510 memmove (&header, (char *)addr, sizeof(image_header_t));
512 if (hdr->ih_magic != IH_MAGIC) {
513 printf ("Bad Magic Number\n");
514 SHOW_BOOT_PROGRESS (-10);
515 do_reset (cmdtp, flag, argc, argv);
518 data = (ulong)&header;
519 len = sizeof(image_header_t);
521 checksum = hdr->ih_hcrc;
524 if (crc32 (0, (char *)data, len) != checksum) {
525 printf ("Bad Header Checksum\n");
526 SHOW_BOOT_PROGRESS (-11);
527 do_reset (cmdtp, flag, argc, argv);
530 SHOW_BOOT_PROGRESS (10);
532 print_image_hdr (hdr);
534 data = addr + sizeof(image_header_t);
539 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
540 ulong cdata = data, edata = cdata + len;
541 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
543 printf (" Verifying Checksum ... ");
545 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
547 while (cdata < edata) {
548 ulong chunk = edata - cdata;
552 csum = crc32 (csum, (char *)cdata, chunk);
557 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
558 csum = crc32 (0, (char *)data, len);
559 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
561 if (csum != hdr->ih_dcrc) {
562 printf ("Bad Data CRC\n");
563 SHOW_BOOT_PROGRESS (-12);
564 do_reset (cmdtp, flag, argc, argv);
569 SHOW_BOOT_PROGRESS (11);
571 if ((hdr->ih_os != IH_OS_LINUX) ||
572 (hdr->ih_arch != IH_CPU_PPC) ||
573 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
574 printf ("No Linux PPC Ramdisk Image\n");
575 SHOW_BOOT_PROGRESS (-13);
576 do_reset (cmdtp, flag, argc, argv);
580 * Now check if we have a multifile image
582 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
583 u_long tail = ntohl(len_ptr[0]) % 4;
586 SHOW_BOOT_PROGRESS (13);
588 /* skip kernel length and terminator */
589 data = (ulong)(&len_ptr[2]);
590 /* skip any additional image length fields */
591 for (i=1; len_ptr[i]; ++i)
593 /* add kernel length, and align */
594 data += ntohl(len_ptr[0]);
599 len = ntohl(len_ptr[1]);
605 SHOW_BOOT_PROGRESS (14);
611 debug ("No initrd\n");
615 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
617 initrd_end = initrd_start + len;
619 initrd_start = (ulong)kbd - len;
620 initrd_start &= ~(4096 - 1); /* align on page */
626 * the inital ramdisk does not need to be within
627 * CFG_BOOTMAPSZ as it is not accessed until after
628 * the mm system is initialised.
630 * do the stack bottom calculation again and see if
631 * the initrd will fit just below the monitor stack
632 * bottom without overwriting the area allocated
633 * above for command line args and board info.
635 asm( "mr %0,1": "=r"(nsp) : );
636 nsp -= 2048; /* just to be sure */
638 if (nsp > initrd_high) /* limit as specified */
641 nsp &= ~(4096 - 1); /* align on page */
646 SHOW_BOOT_PROGRESS (12);
648 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
649 data, data + len - 1, len, len);
651 initrd_end = initrd_start + len;
652 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
653 initrd_start, initrd_end);
654 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
657 void *to = (void *)initrd_start;
658 void *from = (void *)data;
661 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
663 memmove (to, from, tail);
669 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
670 memmove ((void *)initrd_start, (void *)data, len);
671 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
680 debug ("## Transferring control to Linux (at address %08lx) ...\n",
683 SHOW_BOOT_PROGRESS (15);
685 #ifdef CFG_INIT_RAM_LOCK
686 unlock_ram_in_cache();
689 * Linux Kernel Parameters:
690 * r3: ptr to board info data
691 * r4: initrd_start or 0 if no initrd
692 * r5: initrd_end - unused if r4 is 0
693 * r6: Start of command line string
694 * r7: End of command line string
696 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
698 #endif /* CONFIG_PPC */
701 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
702 int argc, char *argv[],
707 DECLARE_GLOBAL_DATA_PTR;
709 image_header_t *hdr = &header;
711 void (*loader)(bd_t *, image_header_t *, char *, char *);
712 image_header_t *img_addr;
718 * Booting a (NetBSD) kernel image
720 * This process is pretty similar to a standalone application:
721 * The (first part of an multi-) image must be a stage-2 loader,
722 * which in turn is responsible for loading & invoking the actual
723 * kernel. The only differences are the parameters being passed:
724 * besides the board info strucure, the loader expects a command
725 * line, the name of the console device, and (optionally) the
726 * address of the original image header.
730 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
731 img_addr = (image_header_t *) addr;
735 #if defined (CONFIG_8xx_CONS_SMC1)
737 #elif defined (CONFIG_8xx_CONS_SMC2)
739 #elif defined (CONFIG_8xx_CONS_SCC2)
741 #elif defined (CONFIG_8xx_CONS_SCC3)
749 for (i=2, len=0 ; i<argc ; i+=1)
750 len += strlen (argv[i]) + 1;
751 cmdline = malloc (len);
753 for (i=2, len=0 ; i<argc ; i+=1) {
755 cmdline[len++] = ' ';
756 strcpy (&cmdline[len], argv[i]);
757 len += strlen (argv[i]);
759 } else if ((cmdline = getenv("bootargs")) == NULL) {
763 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
765 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
768 SHOW_BOOT_PROGRESS (15);
771 * NetBSD Stage-2 Loader Parameters:
772 * r3: ptr to board info data
775 * r6: boot args string
777 (*loader) (gd->bd, img_addr, consdev, cmdline);
780 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
782 /* Function that returns a character from the environment */
783 extern uchar (*env_get_char)(int);
786 do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
787 int argc, char *argv[],
792 DECLARE_GLOBAL_DATA_PTR;
796 int i, j, nxt, len, envno, envsz;
798 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
799 image_header_t *hdr = &header;
802 * Booting an ARTOS kernel image + application
805 /* this used to be the top of memory, but was wrong... */
807 /* get stack pointer */
808 asm volatile ("mr %0,1" : "=r"(top) );
810 debug ("## Current stack ends at 0x%08lX ", top);
812 top -= 2048; /* just to be sure */
813 if (top > CFG_BOOTMAPSZ)
817 debug ("=> set upper limit to 0x%08lX\n", top);
819 /* first check the artos specific boot args, then the linux args*/
820 if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
823 /* get length of cmdline, and place it */
825 top = (top - (len + 1)) & ~0xF;
826 cmdline = (char *)top;
827 debug ("## cmdline at 0x%08lX ", top);
831 top = (top - sizeof(bd_t)) & ~0xF;
832 debug ("## bd at 0x%08lX ", top);
834 memcpy(kbd, gd->bd, sizeof(bd_t));
836 /* first find number of env entries, and their size */
839 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
840 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
843 envsz += (nxt - i) + 1; /* plus trailing zero */
845 envno++; /* plus the terminating zero */
846 debug ("## %u envvars total size %u ", envno, envsz);
848 top = (top - sizeof(char **)*envno) & ~0xF;
849 fwenv = (char **)top;
850 debug ("## fwenv at 0x%08lX ", top);
852 top = (top - envsz) & ~0xF;
857 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
858 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
861 for (j = i; j < nxt; ++j)
862 *s++ = env_get_char(j);
865 *ss++ = NULL; /* terminate */
867 entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
868 (*entry)(kbd, cmdline, fwenv, top);
873 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
874 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
877 #ifndef CFG_HUSH_PARSER
878 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
880 if (parse_string_outer(getenv("bootcmd"),
881 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
887 boot, 1, 1, do_bootd,
888 "boot - boot default, i.e., run 'bootcmd'\n",
892 /* keep old command name "bootd" for backward compatibility */
894 bootd, 1, 1, do_bootd,
895 "bootd - boot default, i.e., run 'bootcmd'\n",
901 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
902 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
909 return image_info (load_addr);
912 for (arg=1; arg <argc; ++arg) {
913 addr = simple_strtoul(argv[arg], NULL, 16);
914 if (image_info (addr) != 0) rcode = 1;
919 static int image_info (ulong addr)
921 ulong data, len, checksum;
922 image_header_t *hdr = &header;
924 printf ("\n## Checking Image at %08lx ...\n", addr);
926 /* Copy header so we can blank CRC field for re-calculation */
927 memmove (&header, (char *)addr, sizeof(image_header_t));
929 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
930 printf (" Bad Magic Number\n");
934 data = (ulong)&header;
935 len = sizeof(image_header_t);
937 checksum = ntohl(hdr->ih_hcrc);
940 if (crc32 (0, (char *)data, len) != checksum) {
941 printf (" Bad Header Checksum\n");
945 /* for multi-file images we need the data part, too */
946 print_image_hdr ((image_header_t *)addr);
948 data = addr + sizeof(image_header_t);
949 len = ntohl(hdr->ih_size);
951 printf (" Verifying Checksum ... ");
952 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
953 printf (" Bad Data CRC\n");
961 iminfo, CFG_MAXARGS, 1, do_iminfo,
962 "iminfo - print header information for application image\n",
964 " - print header information for application image starting at\n"
965 " address 'addr' in memory; this includes verification of the\n"
966 " image contents (magic number, header and payload checksums)\n"
969 #endif /* CFG_CMD_IMI */
971 #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
972 /*-----------------------------------------------------------------------
973 * List all images found in flash.
975 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
982 for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
983 if (info->flash_id == FLASH_UNKNOWN)
985 for (j=0; j<CFG_MAX_FLASH_SECT; ++j) {
987 if (!(hdr=(image_header_t *)info->start[j]) ||
988 (ntohl(hdr->ih_magic) != IH_MAGIC))
991 /* Copy header so we can blank CRC field for re-calculation */
992 memmove (&header, (char *)hdr, sizeof(image_header_t));
994 checksum = ntohl(header.ih_hcrc);
997 if (crc32 (0, (char *)&header, sizeof(image_header_t))
1001 printf ("Image at %08lX:\n", (ulong)hdr);
1002 print_image_hdr( hdr );
1013 imls, 1, 1, do_imls,
1014 "imls - list all images found in flash\n",
1016 " - Prints information about all images found at sector\n"
1017 " boundaries in flash.\n"
1019 #endif /* CFG_CMD_IMLS */
1022 print_image_hdr (image_header_t *hdr)
1024 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1025 time_t timestamp = (time_t)ntohl(hdr->ih_time);
1029 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
1030 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1031 to_tm (timestamp, &tm);
1032 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
1033 tm.tm_year, tm.tm_mon, tm.tm_mday,
1034 tm.tm_hour, tm.tm_min, tm.tm_sec);
1035 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
1036 printf (" Image Type: "); print_type(hdr); printf ("\n");
1037 printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
1038 print_size (ntohl(hdr->ih_size), "\n");
1039 printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
1040 printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
1042 if (hdr->ih_type == IH_TYPE_MULTI) {
1045 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
1047 printf (" Contents:\n");
1048 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
1049 printf (" Image %d: %8ld Bytes = ", i, len);
1050 print_size (len, "\n");
1057 print_type (image_header_t *hdr)
1059 char *os, *arch, *type, *comp;
1061 switch (hdr->ih_os) {
1062 case IH_OS_INVALID: os = "Invalid OS"; break;
1063 case IH_OS_NETBSD: os = "NetBSD"; break;
1064 case IH_OS_LINUX: os = "Linux"; break;
1065 case IH_OS_VXWORKS: os = "VxWorks"; break;
1066 case IH_OS_QNX: os = "QNX"; break;
1067 case IH_OS_U_BOOT: os = "U-Boot"; break;
1068 case IH_OS_RTEMS: os = "RTEMS"; break;
1070 case IH_OS_ARTOS: os = "ARTOS"; break;
1072 default: os = "Unknown OS"; break;
1075 switch (hdr->ih_arch) {
1076 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
1077 case IH_CPU_ALPHA: arch = "Alpha"; break;
1078 case IH_CPU_ARM: arch = "ARM"; break;
1079 case IH_CPU_I386: arch = "Intel x86"; break;
1080 case IH_CPU_IA64: arch = "IA64"; break;
1081 case IH_CPU_MIPS: arch = "MIPS"; break;
1082 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
1083 case IH_CPU_PPC: arch = "PowerPC"; break;
1084 case IH_CPU_S390: arch = "IBM S390"; break;
1085 case IH_CPU_SH: arch = "SuperH"; break;
1086 case IH_CPU_SPARC: arch = "SPARC"; break;
1087 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
1088 case IH_CPU_M68K: arch = "M68K"; break;
1089 default: arch = "Unknown Architecture"; break;
1092 switch (hdr->ih_type) {
1093 case IH_TYPE_INVALID: type = "Invalid Image"; break;
1094 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
1095 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
1096 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
1097 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
1098 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
1099 case IH_TYPE_SCRIPT: type = "Script"; break;
1100 default: type = "Unknown Image"; break;
1103 switch (hdr->ih_comp) {
1104 case IH_COMP_NONE: comp = "uncompressed"; break;
1105 case IH_COMP_GZIP: comp = "gzip compressed"; break;
1106 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
1107 default: comp = "unknown compression"; break;
1110 printf ("%s %s %s (%s)", arch, os, type, comp);
1113 #define ZALLOC_ALIGNMENT 16
1115 static void *zalloc(void *x, unsigned items, unsigned size)
1120 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
1127 static void zfree(void *x, void *addr, unsigned nb)
1133 #define EXTRA_FIELD 4
1135 #define COMMENT 0x10
1136 #define RESERVED 0xe0
1140 int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
1148 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
1149 printf ("Error: Bad gzipped data\n");
1152 if ((flags & EXTRA_FIELD) != 0)
1153 i = 12 + src[10] + (src[11] << 8);
1154 if ((flags & ORIG_NAME) != 0)
1155 while (src[i++] != 0)
1157 if ((flags & COMMENT) != 0)
1158 while (src[i++] != 0)
1160 if ((flags & HEAD_CRC) != 0)
1163 printf ("Error: gunzip out of data in header\n");
1169 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1170 s.outcb = (cb_func)WATCHDOG_RESET;
1173 #endif /* CONFIG_HW_WATCHDOG */
1175 r = inflateInit2(&s, -MAX_WBITS);
1177 printf ("Error: inflateInit2() returned %d\n", r);
1180 s.next_in = src + i;
1181 s.avail_in = *lenp - i;
1183 s.avail_out = dstlen;
1184 r = inflate(&s, Z_FINISH);
1185 if (r != Z_OK && r != Z_STREAM_END) {
1186 printf ("Error: inflate() returned %d\n", r);
1189 *lenp = s.next_out - (unsigned char *) dst;
1196 do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1197 ulong addr, ulong *len_ptr, int verify)
1199 DECLARE_GLOBAL_DATA_PTR;
1200 image_header_t *hdr = &header;
1201 void (*entry_point)(bd_t *);
1203 entry_point = (void (*)(bd_t *)) hdr->ih_ep;
1205 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1206 (ulong)entry_point);
1208 SHOW_BOOT_PROGRESS (15);
1212 * r3: ptr to board info data
1215 (*entry_point ) ( gd->bd );
1218 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
1220 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1221 ulong addr, ulong *len_ptr, int verify)
1223 image_header_t *hdr = &header;
1226 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1227 setenv("loadaddr", str);
1228 do_bootvx(cmdtp, 0, 0, NULL);
1232 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1233 ulong addr, ulong *len_ptr, int verify)
1235 image_header_t *hdr = &header;
1236 char *local_args[2];
1239 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1240 local_args[0] = argv[0];
1241 local_args[1] = str; /* and provide it via the arguments */
1242 do_bootelf(cmdtp, 0, 2, local_args);
1244 #endif /* CFG_CMD_ELF */