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);
83 static void print_type (image_header_t *hdr);
86 image_header_t *fake_header(image_header_t *hdr, void *ptr, int size);
90 * Continue booting an OS image; caller already has:
91 * - copied image header to global variable `header'
92 * - checked header magic number, checksums (both header & image),
93 * - verified image architecture (PPC) and type (KERNEL or MULTI),
94 * - loaded (first part of) image to header load address,
95 * - disabled interrupts.
97 typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag,
98 int argc, char *argv[],
99 ulong addr, /* of image to boot */
100 ulong *len_ptr, /* multi-file image length table */
101 int verify); /* getenv("verify")[0] != 'n' */
104 extern int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
108 static boot_os_Fcn do_bootm_linux;
110 extern boot_os_Fcn do_bootm_linux;
112 static boot_os_Fcn do_bootm_netbsd;
113 static boot_os_Fcn do_bootm_rtems;
114 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
115 static boot_os_Fcn do_bootm_vxworks;
116 static boot_os_Fcn do_bootm_qnxelf;
117 int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
118 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
119 #endif /* CFG_CMD_ELF */
120 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
121 static boot_os_Fcn do_bootm_artos;
124 image_header_t header;
126 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
128 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
132 ulong data, len, checksum;
136 int (*appl)(cmd_tbl_t *, int, int, char *[]);
137 image_header_t *hdr = &header;
139 s = getenv ("verify");
140 verify = (s && (*s == 'n')) ? 0 : 1;
145 addr = simple_strtoul(argv[1], NULL, 16);
148 SHOW_BOOT_PROGRESS (1);
149 printf ("## Booting image at %08lx ...\n", addr);
151 /* Copy header so we can blank CRC field for re-calculation */
152 #ifdef CONFIG_HAS_DATAFLASH
153 if (addr_dataflash(addr)){
154 read_dataflash(addr, sizeof(image_header_t), (char *)&header);
157 memmove (&header, (char *)addr, sizeof(image_header_t));
159 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
160 #ifdef __I386__ /* correct image format not implemented yet - fake it */
161 if (fake_header(hdr, (void*)addr, -1) != NULL) {
162 /* to compensate for the addition below */
163 addr -= sizeof(image_header_t);
165 * fake_header() does not fake the data crc
169 #endif /* __I386__ */
171 printf ("Bad Magic Number\n");
172 SHOW_BOOT_PROGRESS (-1);
176 SHOW_BOOT_PROGRESS (2);
178 data = (ulong)&header;
179 len = sizeof(image_header_t);
181 checksum = ntohl(hdr->ih_hcrc);
184 if (crc32 (0, (char *)data, len) != checksum) {
185 printf ("Bad Header Checksum\n");
186 SHOW_BOOT_PROGRESS (-2);
189 SHOW_BOOT_PROGRESS (3);
191 /* for multi-file images we need the data part, too */
192 print_image_hdr (hdr);
194 data = addr + sizeof(image_header_t);
195 len = ntohl(hdr->ih_size);
197 #ifdef CONFIG_HAS_DATAFLASH
198 if (addr_dataflash(addr)){
199 read_dataflash(data, len, (char *)CFG_LOAD_ADDR);
200 data = CFG_LOAD_ADDR;
205 printf (" Verifying Checksum ... ");
206 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
207 printf ("Bad Data CRC\n");
208 SHOW_BOOT_PROGRESS (-3);
213 SHOW_BOOT_PROGRESS (4);
215 len_ptr = (ulong *)data;
218 if (hdr->ih_arch != IH_CPU_PPC)
219 #elif defined(__ARM__)
220 if (hdr->ih_arch != IH_CPU_ARM)
221 #elif defined(__I386__)
222 if (hdr->ih_arch != IH_CPU_I386)
223 #elif defined(__mips__)
224 if (hdr->ih_arch != IH_CPU_MIPS)
226 # error Unknown CPU type
229 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
230 SHOW_BOOT_PROGRESS (-4);
233 SHOW_BOOT_PROGRESS (5);
235 switch (hdr->ih_type) {
236 case IH_TYPE_STANDALONE: name = "Standalone Application";
238 case IH_TYPE_KERNEL: name = "Kernel Image";
240 case IH_TYPE_MULTI: name = "Multi-File Image";
241 len = ntohl(len_ptr[0]);
242 /* OS kernel is always the first image */
243 data += 8; /* kernel_len + terminator */
244 for (i=1; len_ptr[i]; ++i)
247 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
248 SHOW_BOOT_PROGRESS (-5);
251 SHOW_BOOT_PROGRESS (6);
254 * We have reached the point of no return: we are going to
255 * overwrite all exception vector code, so we cannot easily
256 * recover from any failures any more...
259 iflag = disable_interrupts();
261 #ifdef CONFIG_AMIGAONEG3SE
263 * We've possible left the caches enabled during
264 * bios emulation, so turn them off again
267 invalidate_l1_instruction_cache();
272 switch (hdr->ih_comp) {
274 if(ntohl(hdr->ih_load) == addr) {
275 printf (" XIP %s ... ", name);
277 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
279 void *to = (void *)ntohl(hdr->ih_load);
280 void *from = (void *)data;
282 printf (" Loading %s ... ", name);
285 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
287 memmove (to, from, tail);
292 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
293 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
294 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
298 printf (" Uncompressing %s ... ", name);
299 if (gunzip ((void *)ntohl(hdr->ih_load), 0x400000,
300 (uchar *)data, (int *)&len) != 0) {
301 printf ("GUNZIP ERROR - must RESET board to recover\n");
302 SHOW_BOOT_PROGRESS (-6);
303 do_reset (cmdtp, flag, argc, argv);
309 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
310 SHOW_BOOT_PROGRESS (-7);
314 SHOW_BOOT_PROGRESS (7);
316 switch (hdr->ih_type) {
317 case IH_TYPE_STANDALONE:
321 /* load (and uncompress), but don't start if "autostart"
324 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0))
326 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
327 (*appl)(cmdtp, flag, argc-1, &argv[1]);
336 printf ("Can't boot image type %d\n", hdr->ih_type);
337 SHOW_BOOT_PROGRESS (-8);
340 SHOW_BOOT_PROGRESS (8);
342 switch (hdr->ih_os) {
343 default: /* handled by (original) Linux case */
345 do_bootm_linux (cmdtp, flag, argc, argv,
346 addr, len_ptr, verify);
349 do_bootm_netbsd (cmdtp, flag, argc, argv,
350 addr, len_ptr, verify);
354 do_bootm_rtems (cmdtp, flag, argc, argv,
355 addr, len_ptr, verify);
358 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
360 do_bootm_vxworks (cmdtp, flag, argc, argv,
361 addr, len_ptr, verify);
364 do_bootm_qnxelf (cmdtp, flag, argc, argv,
365 addr, len_ptr, verify);
367 #endif /* CFG_CMD_ELF */
370 do_bootm_artos (cmdtp, flag, argc, argv,
371 addr, len_ptr, verify);
376 SHOW_BOOT_PROGRESS (-9);
378 printf ("\n## Control returned to monitor - resetting...\n");
379 do_reset (cmdtp, flag, argc, argv);
385 bootm, CFG_MAXARGS, 1, do_bootm,
386 "bootm - boot application image from memory\n",
387 "[addr [arg ...]]\n - boot application image stored in memory\n"
388 " passing arguments 'arg ...'; when booting a Linux kernel,\n"
389 " 'arg' can be the address of an initrd image\n"
394 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
395 int argc, char *argv[],
400 DECLARE_GLOBAL_DATA_PTR;
404 ulong initrd_start, initrd_end;
405 ulong cmd_start, cmd_end;
408 int initrd_copy_to_ram = 1;
412 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
413 image_header_t *hdr = &header;
415 if ((s = getenv ("initrd_high")) != NULL) {
416 /* a value of "no" or a similar string will act like 0,
417 * turning the "load high" feature off. This is intentional.
419 initrd_high = simple_strtoul(s, NULL, 16);
420 if (initrd_high == ~0)
421 initrd_copy_to_ram = 0;
422 } else { /* not set, no restrictions to load high */
426 #ifdef CONFIG_LOGBUFFER
428 /* Prevent initrd from overwriting logbuffer */
429 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
430 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
431 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
435 * Booting a (Linux) kernel image
437 * Allocate space for command line and board info - the
438 * address should be as high as possible within the reach of
439 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
440 * memory, which means far enough below the current stack
444 asm( "mr %0,1": "=r"(sp) : );
446 debug ("## Current stack ends at 0x%08lX ", sp);
448 sp -= 2048; /* just to be sure */
449 if (sp > CFG_BOOTMAPSZ)
453 debug ("=> set upper limit to 0x%08lX\n", sp);
455 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
456 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
458 if ((s = getenv("bootargs")) == NULL)
463 cmd_start = (ulong)&cmdline[0];
464 cmd_end = cmd_start + strlen(cmdline);
469 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
471 do_bdinfo (NULL, 0, 0, NULL);
474 if ((s = getenv ("clocks_in_mhz")) != NULL) {
475 /* convert all clock information to MHz */
476 kbd->bi_intfreq /= 1000000L;
477 kbd->bi_busfreq /= 1000000L;
478 #if defined(CONFIG_8260)
479 kbd->bi_cpmfreq /= 1000000L;
480 kbd->bi_brgfreq /= 1000000L;
481 kbd->bi_sccfreq /= 1000000L;
482 kbd->bi_vco /= 1000000L;
483 #endif /* CONFIG_8260 */
484 #if defined(CONFIG_MPC5XXXX)
485 kbd->bi_ipbfreq /= 1000000L;
486 kbd->bi_pcifreq /= 1000000L;
487 #endif /* CONFIG_MPC5XXXX */
490 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
493 * Check if there is an initrd image
496 SHOW_BOOT_PROGRESS (9);
498 addr = simple_strtoul(argv[2], NULL, 16);
500 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
502 /* Copy header so we can blank CRC field for re-calculation */
503 memmove (&header, (char *)addr, sizeof(image_header_t));
505 if (hdr->ih_magic != IH_MAGIC) {
506 printf ("Bad Magic Number\n");
507 SHOW_BOOT_PROGRESS (-10);
508 do_reset (cmdtp, flag, argc, argv);
511 data = (ulong)&header;
512 len = sizeof(image_header_t);
514 checksum = hdr->ih_hcrc;
517 if (crc32 (0, (char *)data, len) != checksum) {
518 printf ("Bad Header Checksum\n");
519 SHOW_BOOT_PROGRESS (-11);
520 do_reset (cmdtp, flag, argc, argv);
523 SHOW_BOOT_PROGRESS (10);
525 print_image_hdr (hdr);
527 data = addr + sizeof(image_header_t);
532 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
533 ulong cdata = data, edata = cdata + len;
534 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
536 printf (" Verifying Checksum ... ");
538 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
540 while (cdata < edata) {
541 ulong chunk = edata - cdata;
545 csum = crc32 (csum, (char *)cdata, chunk);
550 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
551 csum = crc32 (0, (char *)data, len);
552 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
554 if (csum != hdr->ih_dcrc) {
555 printf ("Bad Data CRC\n");
556 SHOW_BOOT_PROGRESS (-12);
557 do_reset (cmdtp, flag, argc, argv);
562 SHOW_BOOT_PROGRESS (11);
564 if ((hdr->ih_os != IH_OS_LINUX) ||
565 (hdr->ih_arch != IH_CPU_PPC) ||
566 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
567 printf ("No Linux PPC Ramdisk Image\n");
568 SHOW_BOOT_PROGRESS (-13);
569 do_reset (cmdtp, flag, argc, argv);
573 * Now check if we have a multifile image
575 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
576 u_long tail = ntohl(len_ptr[0]) % 4;
579 SHOW_BOOT_PROGRESS (13);
581 /* skip kernel length and terminator */
582 data = (ulong)(&len_ptr[2]);
583 /* skip any additional image length fields */
584 for (i=1; len_ptr[i]; ++i)
586 /* add kernel length, and align */
587 data += ntohl(len_ptr[0]);
592 len = ntohl(len_ptr[1]);
598 SHOW_BOOT_PROGRESS (14);
604 debug ("No initrd\n");
608 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
610 initrd_end = initrd_start + len;
612 initrd_start = (ulong)kbd - len;
613 initrd_start &= ~(4096 - 1); /* align on page */
619 * the inital ramdisk does not need to be within
620 * CFG_BOOTMAPSZ as it is not accessed until after
621 * the mm system is initialised.
623 * do the stack bottom calculation again and see if
624 * the initrd will fit just below the monitor stack
625 * bottom without overwriting the area allocated
626 * above for command line args and board info.
628 asm( "mr %0,1": "=r"(nsp) : );
629 nsp -= 2048; /* just to be sure */
631 if (nsp > initrd_high) /* limit as specified */
634 nsp &= ~(4096 - 1); /* align on page */
639 SHOW_BOOT_PROGRESS (12);
641 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
642 data, data + len - 1, len, len);
644 initrd_end = initrd_start + len;
645 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
646 initrd_start, initrd_end);
647 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
650 void *to = (void *)initrd_start;
651 void *from = (void *)data;
654 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
656 memmove (to, from, tail);
662 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
663 memmove ((void *)initrd_start, (void *)data, len);
664 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
673 debug ("## Transferring control to Linux (at address %08lx) ...\n",
676 SHOW_BOOT_PROGRESS (15);
678 #ifdef CFG_INIT_RAM_LOCK
679 unlock_ram_in_cache();
682 * Linux Kernel Parameters:
683 * r3: ptr to board info data
684 * r4: initrd_start or 0 if no initrd
685 * r5: initrd_end - unused if r4 is 0
686 * r6: Start of command line string
687 * r7: End of command line string
689 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
691 #endif /* CONFIG_PPC */
694 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
695 int argc, char *argv[],
700 DECLARE_GLOBAL_DATA_PTR;
702 image_header_t *hdr = &header;
704 void (*loader)(bd_t *, image_header_t *, char *, char *);
705 image_header_t *img_addr;
711 * Booting a (NetBSD) kernel image
713 * This process is pretty similar to a standalone application:
714 * The (first part of an multi-) image must be a stage-2 loader,
715 * which in turn is responsible for loading & invoking the actual
716 * kernel. The only differences are the parameters being passed:
717 * besides the board info strucure, the loader expects a command
718 * line, the name of the console device, and (optionally) the
719 * address of the original image header.
723 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
724 img_addr = (image_header_t *) addr;
728 #if defined (CONFIG_8xx_CONS_SMC1)
730 #elif defined (CONFIG_8xx_CONS_SMC2)
732 #elif defined (CONFIG_8xx_CONS_SCC2)
734 #elif defined (CONFIG_8xx_CONS_SCC3)
742 for (i=2, len=0 ; i<argc ; i+=1)
743 len += strlen (argv[i]) + 1;
744 cmdline = malloc (len);
746 for (i=2, len=0 ; i<argc ; i+=1) {
748 cmdline[len++] = ' ';
749 strcpy (&cmdline[len], argv[i]);
750 len += strlen (argv[i]);
752 } else if ((cmdline = getenv("bootargs")) == NULL) {
756 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
758 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
761 SHOW_BOOT_PROGRESS (15);
764 * NetBSD Stage-2 Loader Parameters:
765 * r3: ptr to board info data
768 * r6: boot args string
770 (*loader) (gd->bd, img_addr, consdev, cmdline);
773 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
775 /* Function that returns a character from the environment */
776 extern uchar (*env_get_char)(int);
779 do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
780 int argc, char *argv[],
785 DECLARE_GLOBAL_DATA_PTR;
789 int i, j, nxt, len, envno, envsz;
791 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
792 image_header_t *hdr = &header;
795 * Booting an ARTOS kernel image + application
798 /* this used to be the top of memory, but was wrong... */
800 /* get stack pointer */
801 asm volatile ("mr %0,1" : "=r"(top) );
803 debug ("## Current stack ends at 0x%08lX ", top);
805 top -= 2048; /* just to be sure */
806 if (top > CFG_BOOTMAPSZ)
810 debug ("=> set upper limit to 0x%08lX\n", top);
812 /* first check the artos specific boot args, then the linux args*/
813 if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
816 /* get length of cmdline, and place it */
818 top = (top - (len + 1)) & ~0xF;
819 cmdline = (char *)top;
820 debug ("## cmdline at 0x%08lX ", top);
824 top = (top - sizeof(bd_t)) & ~0xF;
825 debug ("## bd at 0x%08lX ", top);
827 memcpy(kbd, gd->bd, sizeof(bd_t));
829 /* first find number of env entries, and their size */
832 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
833 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
836 envsz += (nxt - i) + 1; /* plus trailing zero */
838 envno++; /* plus the terminating zero */
839 debug ("## %u envvars total size %u ", envno, envsz);
841 top = (top - sizeof(char **)*envno) & ~0xF;
842 fwenv = (char **)top;
843 debug ("## fwenv at 0x%08lX ", top);
845 top = (top - envsz) & ~0xF;
850 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
851 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
854 for (j = i; j < nxt; ++j)
855 *s++ = env_get_char(j);
858 *ss++ = NULL; /* terminate */
860 entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
861 (*entry)(kbd, cmdline, fwenv, top);
866 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
867 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
870 #ifndef CFG_HUSH_PARSER
871 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
873 if (parse_string_outer(getenv("bootcmd"),
874 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
880 boot, 1, 1, do_bootd,
881 "boot - boot default, i.e., run 'bootcmd'\n",
885 /* keep old command name "bootd" for backward compatibility */
887 bootd, 1, 1, do_bootd,
888 "bootd - boot default, i.e., run 'bootcmd'\n",
894 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
895 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
902 return image_info (load_addr);
905 for (arg=1; arg <argc; ++arg) {
906 addr = simple_strtoul(argv[arg], NULL, 16);
907 if (image_info (addr) != 0) rcode = 1;
912 static int image_info (ulong addr)
914 ulong data, len, checksum;
915 image_header_t *hdr = &header;
917 printf ("\n## Checking Image at %08lx ...\n", addr);
919 /* Copy header so we can blank CRC field for re-calculation */
920 memmove (&header, (char *)addr, sizeof(image_header_t));
922 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
923 printf (" Bad Magic Number\n");
927 data = (ulong)&header;
928 len = sizeof(image_header_t);
930 checksum = ntohl(hdr->ih_hcrc);
933 if (crc32 (0, (char *)data, len) != checksum) {
934 printf (" Bad Header Checksum\n");
938 /* for multi-file images we need the data part, too */
939 print_image_hdr ((image_header_t *)addr);
941 data = addr + sizeof(image_header_t);
942 len = ntohl(hdr->ih_size);
944 printf (" Verifying Checksum ... ");
945 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
946 printf (" Bad Data CRC\n");
954 iminfo, CFG_MAXARGS, 1, do_iminfo,
955 "iminfo - print header information for application image\n",
957 " - print header information for application image starting at\n"
958 " address 'addr' in memory; this includes verification of the\n"
959 " image contents (magic number, header and payload checksums)\n"
962 #endif /* CFG_CMD_IMI */
965 print_image_hdr (image_header_t *hdr)
967 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
968 time_t timestamp = (time_t)ntohl(hdr->ih_time);
972 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
973 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
974 to_tm (timestamp, &tm);
975 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
976 tm.tm_year, tm.tm_mon, tm.tm_mday,
977 tm.tm_hour, tm.tm_min, tm.tm_sec);
978 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
979 printf (" Image Type: "); print_type(hdr); printf ("\n");
980 printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
981 print_size (ntohl(hdr->ih_size), "\n");
982 printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
983 printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
985 if (hdr->ih_type == IH_TYPE_MULTI) {
988 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
990 printf (" Contents:\n");
991 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
992 printf (" Image %d: %8ld Bytes = ", i, len);
993 print_size (len, "\n");
1000 print_type (image_header_t *hdr)
1002 char *os, *arch, *type, *comp;
1004 switch (hdr->ih_os) {
1005 case IH_OS_INVALID: os = "Invalid OS"; break;
1006 case IH_OS_NETBSD: os = "NetBSD"; break;
1007 case IH_OS_LINUX: os = "Linux"; break;
1008 case IH_OS_VXWORKS: os = "VxWorks"; break;
1009 case IH_OS_QNX: os = "QNX"; break;
1010 case IH_OS_U_BOOT: os = "U-Boot"; break;
1011 case IH_OS_RTEMS: os = "RTEMS"; break;
1013 case IH_OS_ARTOS: os = "ARTOS"; break;
1015 default: os = "Unknown OS"; break;
1018 switch (hdr->ih_arch) {
1019 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
1020 case IH_CPU_ALPHA: arch = "Alpha"; break;
1021 case IH_CPU_ARM: arch = "ARM"; break;
1022 case IH_CPU_I386: arch = "Intel x86"; break;
1023 case IH_CPU_IA64: arch = "IA64"; break;
1024 case IH_CPU_MIPS: arch = "MIPS"; break;
1025 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
1026 case IH_CPU_PPC: arch = "PowerPC"; break;
1027 case IH_CPU_S390: arch = "IBM S390"; break;
1028 case IH_CPU_SH: arch = "SuperH"; break;
1029 case IH_CPU_SPARC: arch = "SPARC"; break;
1030 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
1031 case IH_CPU_M68K: arch = "M68K"; break;
1032 default: arch = "Unknown Architecture"; break;
1035 switch (hdr->ih_type) {
1036 case IH_TYPE_INVALID: type = "Invalid Image"; break;
1037 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
1038 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
1039 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
1040 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
1041 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
1042 case IH_TYPE_SCRIPT: type = "Script"; break;
1043 default: type = "Unknown Image"; break;
1046 switch (hdr->ih_comp) {
1047 case IH_COMP_NONE: comp = "uncompressed"; break;
1048 case IH_COMP_GZIP: comp = "gzip compressed"; break;
1049 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
1050 default: comp = "unknown compression"; break;
1053 printf ("%s %s %s (%s)", arch, os, type, comp);
1056 #define ZALLOC_ALIGNMENT 16
1058 static void *zalloc(void *x, unsigned items, unsigned size)
1063 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
1070 static void zfree(void *x, void *addr, unsigned nb)
1076 #define EXTRA_FIELD 4
1078 #define COMMENT 0x10
1079 #define RESERVED 0xe0
1083 int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
1091 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
1092 printf ("Error: Bad gzipped data\n");
1095 if ((flags & EXTRA_FIELD) != 0)
1096 i = 12 + src[10] + (src[11] << 8);
1097 if ((flags & ORIG_NAME) != 0)
1098 while (src[i++] != 0)
1100 if ((flags & COMMENT) != 0)
1101 while (src[i++] != 0)
1103 if ((flags & HEAD_CRC) != 0)
1106 printf ("Error: gunzip out of data in header\n");
1112 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1113 s.outcb = (cb_func)WATCHDOG_RESET;
1116 #endif /* CONFIG_HW_WATCHDOG */
1118 r = inflateInit2(&s, -MAX_WBITS);
1120 printf ("Error: inflateInit2() returned %d\n", r);
1123 s.next_in = src + i;
1124 s.avail_in = *lenp - i;
1126 s.avail_out = dstlen;
1127 r = inflate(&s, Z_FINISH);
1128 if (r != Z_OK && r != Z_STREAM_END) {
1129 printf ("Error: inflate() returned %d\n", r);
1132 *lenp = s.next_out - (unsigned char *) dst;
1139 do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1140 ulong addr, ulong *len_ptr, int verify)
1142 DECLARE_GLOBAL_DATA_PTR;
1143 image_header_t *hdr = &header;
1144 void (*entry_point)(bd_t *);
1146 entry_point = (void (*)(bd_t *)) hdr->ih_ep;
1148 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1149 (ulong)entry_point);
1151 SHOW_BOOT_PROGRESS (15);
1155 * r3: ptr to board info data
1158 (*entry_point ) ( gd->bd );
1161 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
1163 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1164 ulong addr, ulong *len_ptr, int verify)
1166 image_header_t *hdr = &header;
1169 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1170 setenv("loadaddr", str);
1171 do_bootvx(cmdtp, 0, 0, NULL);
1175 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1176 ulong addr, ulong *len_ptr, int verify)
1178 image_header_t *hdr = &header;
1179 char *local_args[2];
1182 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1183 local_args[0] = argv[0];
1184 local_args[1] = str; /* and provide it via the arguments */
1185 do_bootelf(cmdtp, 0, 2, local_args);
1187 #endif /* CFG_CMD_ELF */