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 *, unsigned long *);
78 static void *zalloc(void *, unsigned, unsigned);
79 static void zfree(void *, void *, unsigned);
81 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
82 static int image_info (unsigned long addr);
85 #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
87 extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
88 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
91 static void print_type (image_header_t *hdr);
94 image_header_t *fake_header(image_header_t *hdr, void *ptr, int size);
98 * Continue booting an OS image; caller already has:
99 * - copied image header to global variable `header'
100 * - checked header magic number, checksums (both header & image),
101 * - verified image architecture (PPC) and type (KERNEL or MULTI),
102 * - loaded (first part of) image to header load address,
103 * - disabled interrupts.
105 typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag,
106 int argc, char *argv[],
107 ulong addr, /* of image to boot */
108 ulong *len_ptr, /* multi-file image length table */
109 int verify); /* getenv("verify")[0] != 'n' */
112 extern int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
116 static boot_os_Fcn do_bootm_linux;
118 extern boot_os_Fcn do_bootm_linux;
120 #ifdef CONFIG_SILENT_CONSOLE
121 static void fixup_silent_linux (void);
123 static boot_os_Fcn do_bootm_netbsd;
124 static boot_os_Fcn do_bootm_rtems;
125 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
126 static boot_os_Fcn do_bootm_vxworks;
127 static boot_os_Fcn do_bootm_qnxelf;
128 int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
129 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
130 #endif /* CFG_CMD_ELF */
131 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
132 static boot_os_Fcn do_bootm_artos;
134 #ifdef CONFIG_LYNXKDI
135 static boot_os_Fcn do_bootm_lynxkdi;
136 extern void lynxkdi_boot( image_header_t * );
139 image_header_t header;
141 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
143 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
147 ulong data, len, checksum;
149 uint unc_len = 0x400000;
152 int (*appl)(int, char *[]);
153 image_header_t *hdr = &header;
155 s = getenv ("verify");
156 verify = (s && (*s == 'n')) ? 0 : 1;
161 addr = simple_strtoul(argv[1], NULL, 16);
164 SHOW_BOOT_PROGRESS (1);
165 printf ("## Booting image at %08lx ...\n", addr);
167 /* Copy header so we can blank CRC field for re-calculation */
168 #ifdef CONFIG_HAS_DATAFLASH
169 if (addr_dataflash(addr)){
170 read_dataflash(addr, sizeof(image_header_t), (char *)&header);
173 memmove (&header, (char *)addr, sizeof(image_header_t));
175 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
176 #ifdef __I386__ /* correct image format not implemented yet - fake it */
177 if (fake_header(hdr, (void*)addr, -1) != NULL) {
178 /* to compensate for the addition below */
179 addr -= sizeof(image_header_t);
181 * fake_header() does not fake the data crc
185 #endif /* __I386__ */
187 puts ("Bad Magic Number\n");
188 SHOW_BOOT_PROGRESS (-1);
192 SHOW_BOOT_PROGRESS (2);
194 data = (ulong)&header;
195 len = sizeof(image_header_t);
197 checksum = ntohl(hdr->ih_hcrc);
200 if (crc32 (0, (char *)data, len) != checksum) {
201 puts ("Bad Header Checksum\n");
202 SHOW_BOOT_PROGRESS (-2);
205 SHOW_BOOT_PROGRESS (3);
207 #ifdef CONFIG_HAS_DATAFLASH
208 if (addr_dataflash(addr)){
209 len = ntohl(hdr->ih_size) + sizeof(image_header_t);
210 read_dataflash(addr, len, (char *)CFG_LOAD_ADDR);
211 addr = CFG_LOAD_ADDR;
216 /* for multi-file images we need the data part, too */
217 print_image_hdr ((image_header_t *)addr);
219 data = addr + sizeof(image_header_t);
220 len = ntohl(hdr->ih_size);
223 puts (" Verifying Checksum ... ");
224 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
225 printf ("Bad Data CRC\n");
226 SHOW_BOOT_PROGRESS (-3);
231 SHOW_BOOT_PROGRESS (4);
233 len_ptr = (ulong *)data;
236 if (hdr->ih_arch != IH_CPU_PPC)
237 #elif defined(__ARM__)
238 if (hdr->ih_arch != IH_CPU_ARM)
239 #elif defined(__I386__)
240 if (hdr->ih_arch != IH_CPU_I386)
241 #elif defined(__mips__)
242 if (hdr->ih_arch != IH_CPU_MIPS)
243 #elif defined(__nios__)
244 if (hdr->ih_arch != IH_CPU_NIOS)
245 #elif defined(__M68K__)
246 if (hdr->ih_arch != IH_CPU_M68K)
247 #elif defined(__microblaze__)
248 if (hdr->ih_arch != IH_CPU_MICROBLAZE)
249 #elif defined(__nios2__)
250 if (hdr->ih_arch != IH_CPU_NIOS2)
252 # error Unknown CPU type
255 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
256 SHOW_BOOT_PROGRESS (-4);
259 SHOW_BOOT_PROGRESS (5);
261 switch (hdr->ih_type) {
262 case IH_TYPE_STANDALONE:
263 name = "Standalone Application";
264 /* A second argument overwrites the load address */
266 hdr->ih_load = htonl(simple_strtoul(argv[2], NULL, 16));
270 name = "Kernel Image";
273 name = "Multi-File Image";
274 len = ntohl(len_ptr[0]);
275 /* OS kernel is always the first image */
276 data += 8; /* kernel_len + terminator */
277 for (i=1; len_ptr[i]; ++i)
280 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
281 SHOW_BOOT_PROGRESS (-5);
284 SHOW_BOOT_PROGRESS (6);
287 * We have reached the point of no return: we are going to
288 * overwrite all exception vector code, so we cannot easily
289 * recover from any failures any more...
292 iflag = disable_interrupts();
294 #ifdef CONFIG_AMIGAONEG3SE
296 * We've possible left the caches enabled during
297 * bios emulation, so turn them off again
300 invalidate_l1_instruction_cache();
305 switch (hdr->ih_comp) {
307 if(ntohl(hdr->ih_load) == addr) {
308 printf (" XIP %s ... ", name);
310 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
312 void *to = (void *)ntohl(hdr->ih_load);
313 void *from = (void *)data;
315 printf (" Loading %s ... ", name);
318 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
320 memmove (to, from, tail);
325 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
326 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
327 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
331 printf (" Uncompressing %s ... ", name);
332 if (gunzip ((void *)ntohl(hdr->ih_load), unc_len,
333 (uchar *)data, &len) != 0) {
334 puts ("GUNZIP ERROR - must RESET board to recover\n");
335 SHOW_BOOT_PROGRESS (-6);
336 do_reset (cmdtp, flag, argc, argv);
341 printf (" Uncompressing %s ... ", name);
343 * If we've got less than 4 MB of malloc() space,
344 * use slower decompression algorithm which requires
345 * at most 2300 KB of memory.
347 i = BZ2_bzBuffToBuffDecompress ((char*)ntohl(hdr->ih_load),
348 &unc_len, (char *)data, len,
349 CFG_MALLOC_LEN < (4096 * 1024), 0);
351 printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
352 SHOW_BOOT_PROGRESS (-6);
354 do_reset (cmdtp, flag, argc, argv);
357 #endif /* CONFIG_BZIP2 */
361 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
362 SHOW_BOOT_PROGRESS (-7);
366 SHOW_BOOT_PROGRESS (7);
368 switch (hdr->ih_type) {
369 case IH_TYPE_STANDALONE:
373 /* load (and uncompress), but don't start if "autostart"
376 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) {
378 sprintf(buf, "%lX", len);
379 setenv("filesize", buf);
382 appl = (int (*)(int, char *[]))ntohl(hdr->ih_ep);
383 (*appl)(argc-1, &argv[1]);
392 printf ("Can't boot image type %d\n", hdr->ih_type);
393 SHOW_BOOT_PROGRESS (-8);
396 SHOW_BOOT_PROGRESS (8);
398 switch (hdr->ih_os) {
399 default: /* handled by (original) Linux case */
401 #ifdef CONFIG_SILENT_CONSOLE
402 fixup_silent_linux();
404 do_bootm_linux (cmdtp, flag, argc, argv,
405 addr, len_ptr, verify);
408 do_bootm_netbsd (cmdtp, flag, argc, argv,
409 addr, len_ptr, verify);
412 #ifdef CONFIG_LYNXKDI
414 do_bootm_lynxkdi (cmdtp, flag, argc, argv,
415 addr, len_ptr, verify);
420 do_bootm_rtems (cmdtp, flag, argc, argv,
421 addr, len_ptr, verify);
424 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
426 do_bootm_vxworks (cmdtp, flag, argc, argv,
427 addr, len_ptr, verify);
430 do_bootm_qnxelf (cmdtp, flag, argc, argv,
431 addr, len_ptr, verify);
433 #endif /* CFG_CMD_ELF */
436 do_bootm_artos (cmdtp, flag, argc, argv,
437 addr, len_ptr, verify);
442 SHOW_BOOT_PROGRESS (-9);
444 puts ("\n## Control returned to monitor - resetting...\n");
445 do_reset (cmdtp, flag, argc, argv);
451 bootm, CFG_MAXARGS, 1, do_bootm,
452 "bootm - boot application image from memory\n",
453 "[addr [arg ...]]\n - boot application image stored in memory\n"
454 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
455 "\t'arg' can be the address of an initrd image\n"
458 #ifdef CONFIG_SILENT_CONSOLE
460 fixup_silent_linux ()
462 DECLARE_GLOBAL_DATA_PTR;
463 char buf[256], *start, *end;
464 char *cmdline = getenv ("bootargs");
466 /* Only fix cmdline when requested */
467 if (!(gd->flags & GD_FLG_SILENT))
470 debug ("before silent fix-up: %s\n", cmdline);
472 if ((start = strstr (cmdline, "console=")) != NULL) {
473 end = strchr (start, ' ');
474 strncpy (buf, cmdline, (start - cmdline + 8));
476 strcpy (buf + (start - cmdline + 8), end);
478 buf[start - cmdline + 8] = '\0';
480 strcpy (buf, cmdline);
481 strcat (buf, " console=");
484 strcpy (buf, "console=");
487 setenv ("bootargs", buf);
488 debug ("after silent fix-up: %s\n", buf);
490 #endif /* CONFIG_SILENT_CONSOLE */
494 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
495 int argc, char *argv[],
500 DECLARE_GLOBAL_DATA_PTR;
504 ulong initrd_start, initrd_end;
505 ulong cmd_start, cmd_end;
508 int initrd_copy_to_ram = 1;
512 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
513 image_header_t *hdr = &header;
515 if ((s = getenv ("initrd_high")) != NULL) {
516 /* a value of "no" or a similar string will act like 0,
517 * turning the "load high" feature off. This is intentional.
519 initrd_high = simple_strtoul(s, NULL, 16);
520 if (initrd_high == ~0)
521 initrd_copy_to_ram = 0;
522 } else { /* not set, no restrictions to load high */
526 #ifdef CONFIG_LOGBUFFER
528 /* Prevent initrd from overwriting logbuffer */
529 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
530 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
531 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
535 * Booting a (Linux) kernel image
537 * Allocate space for command line and board info - the
538 * address should be as high as possible within the reach of
539 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
540 * memory, which means far enough below the current stack
544 asm( "mr %0,1": "=r"(sp) : );
546 debug ("## Current stack ends at 0x%08lX ", sp);
548 sp -= 2048; /* just to be sure */
549 if (sp > CFG_BOOTMAPSZ)
553 debug ("=> set upper limit to 0x%08lX\n", sp);
555 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
556 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
558 if ((s = getenv("bootargs")) == NULL)
563 cmd_start = (ulong)&cmdline[0];
564 cmd_end = cmd_start + strlen(cmdline);
569 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
571 do_bdinfo (NULL, 0, 0, NULL);
574 if ((s = getenv ("clocks_in_mhz")) != NULL) {
575 /* convert all clock information to MHz */
576 kbd->bi_intfreq /= 1000000L;
577 kbd->bi_busfreq /= 1000000L;
578 #if defined(CONFIG_MPC8220)
579 kbd->bi_inpfreq /= 1000000L;
580 kbd->bi_pcifreq /= 1000000L;
581 kbd->bi_pevfreq /= 1000000L;
582 kbd->bi_flbfreq /= 1000000L;
583 kbd->bi_vcofreq /= 1000000L;
585 #if defined(CONFIG_CPM2)
586 kbd->bi_cpmfreq /= 1000000L;
587 kbd->bi_brgfreq /= 1000000L;
588 kbd->bi_sccfreq /= 1000000L;
589 kbd->bi_vco /= 1000000L;
591 #if defined(CONFIG_MPC5xxx)
592 kbd->bi_ipbfreq /= 1000000L;
593 kbd->bi_pcifreq /= 1000000L;
594 #endif /* CONFIG_MPC5xxx */
597 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
600 * Check if there is an initrd image
603 SHOW_BOOT_PROGRESS (9);
605 addr = simple_strtoul(argv[2], NULL, 16);
607 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
609 /* Copy header so we can blank CRC field for re-calculation */
610 memmove (&header, (char *)addr, sizeof(image_header_t));
612 if (hdr->ih_magic != IH_MAGIC) {
613 puts ("Bad Magic Number\n");
614 SHOW_BOOT_PROGRESS (-10);
615 do_reset (cmdtp, flag, argc, argv);
618 data = (ulong)&header;
619 len = sizeof(image_header_t);
621 checksum = hdr->ih_hcrc;
624 if (crc32 (0, (char *)data, len) != checksum) {
625 puts ("Bad Header Checksum\n");
626 SHOW_BOOT_PROGRESS (-11);
627 do_reset (cmdtp, flag, argc, argv);
630 SHOW_BOOT_PROGRESS (10);
632 print_image_hdr (hdr);
634 data = addr + sizeof(image_header_t);
639 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
640 ulong cdata = data, edata = cdata + len;
641 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
643 puts (" Verifying Checksum ... ");
645 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
647 while (cdata < edata) {
648 ulong chunk = edata - cdata;
652 csum = crc32 (csum, (char *)cdata, chunk);
657 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
658 csum = crc32 (0, (char *)data, len);
659 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
661 if (csum != hdr->ih_dcrc) {
662 puts ("Bad Data CRC\n");
663 SHOW_BOOT_PROGRESS (-12);
664 do_reset (cmdtp, flag, argc, argv);
669 SHOW_BOOT_PROGRESS (11);
671 if ((hdr->ih_os != IH_OS_LINUX) ||
672 (hdr->ih_arch != IH_CPU_PPC) ||
673 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
674 puts ("No Linux PPC Ramdisk Image\n");
675 SHOW_BOOT_PROGRESS (-13);
676 do_reset (cmdtp, flag, argc, argv);
680 * Now check if we have a multifile image
682 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
683 u_long tail = ntohl(len_ptr[0]) % 4;
686 SHOW_BOOT_PROGRESS (13);
688 /* skip kernel length and terminator */
689 data = (ulong)(&len_ptr[2]);
690 /* skip any additional image length fields */
691 for (i=1; len_ptr[i]; ++i)
693 /* add kernel length, and align */
694 data += ntohl(len_ptr[0]);
699 len = ntohl(len_ptr[1]);
705 SHOW_BOOT_PROGRESS (14);
711 debug ("No initrd\n");
715 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
717 initrd_end = initrd_start + len;
719 initrd_start = (ulong)kbd - len;
720 initrd_start &= ~(4096 - 1); /* align on page */
726 * the inital ramdisk does not need to be within
727 * CFG_BOOTMAPSZ as it is not accessed until after
728 * the mm system is initialised.
730 * do the stack bottom calculation again and see if
731 * the initrd will fit just below the monitor stack
732 * bottom without overwriting the area allocated
733 * above for command line args and board info.
735 asm( "mr %0,1": "=r"(nsp) : );
736 nsp -= 2048; /* just to be sure */
738 if (nsp > initrd_high) /* limit as specified */
741 nsp &= ~(4096 - 1); /* align on page */
746 SHOW_BOOT_PROGRESS (12);
748 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
749 data, data + len - 1, len, len);
751 initrd_end = initrd_start + len;
752 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
753 initrd_start, initrd_end);
754 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
757 void *to = (void *)initrd_start;
758 void *from = (void *)data;
761 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
763 memmove (to, from, tail);
769 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
770 memmove ((void *)initrd_start, (void *)data, len);
771 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
780 debug ("## Transferring control to Linux (at address %08lx) ...\n",
783 SHOW_BOOT_PROGRESS (15);
785 #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
786 unlock_ram_in_cache();
789 * Linux Kernel Parameters:
790 * r3: ptr to board info data
791 * r4: initrd_start or 0 if no initrd
792 * r5: initrd_end - unused if r4 is 0
793 * r6: Start of command line string
794 * r7: End of command line string
796 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
798 #endif /* CONFIG_PPC */
801 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
802 int argc, char *argv[],
807 DECLARE_GLOBAL_DATA_PTR;
809 image_header_t *hdr = &header;
811 void (*loader)(bd_t *, image_header_t *, char *, char *);
812 image_header_t *img_addr;
818 * Booting a (NetBSD) kernel image
820 * This process is pretty similar to a standalone application:
821 * The (first part of an multi-) image must be a stage-2 loader,
822 * which in turn is responsible for loading & invoking the actual
823 * kernel. The only differences are the parameters being passed:
824 * besides the board info strucure, the loader expects a command
825 * line, the name of the console device, and (optionally) the
826 * address of the original image header.
830 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
831 img_addr = (image_header_t *) addr;
835 #if defined (CONFIG_8xx_CONS_SMC1)
837 #elif defined (CONFIG_8xx_CONS_SMC2)
839 #elif defined (CONFIG_8xx_CONS_SCC2)
841 #elif defined (CONFIG_8xx_CONS_SCC3)
849 for (i=2, len=0 ; i<argc ; i+=1)
850 len += strlen (argv[i]) + 1;
851 cmdline = malloc (len);
853 for (i=2, len=0 ; i<argc ; i+=1) {
855 cmdline[len++] = ' ';
856 strcpy (&cmdline[len], argv[i]);
857 len += strlen (argv[i]);
859 } else if ((cmdline = getenv("bootargs")) == NULL) {
863 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
865 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
868 SHOW_BOOT_PROGRESS (15);
871 * NetBSD Stage-2 Loader Parameters:
872 * r3: ptr to board info data
875 * r6: boot args string
877 (*loader) (gd->bd, img_addr, consdev, cmdline);
880 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
882 /* Function that returns a character from the environment */
883 extern uchar (*env_get_char)(int);
886 do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
887 int argc, char *argv[],
892 DECLARE_GLOBAL_DATA_PTR;
896 int i, j, nxt, len, envno, envsz;
898 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
899 image_header_t *hdr = &header;
902 * Booting an ARTOS kernel image + application
905 /* this used to be the top of memory, but was wrong... */
907 /* get stack pointer */
908 asm volatile ("mr %0,1" : "=r"(top) );
910 debug ("## Current stack ends at 0x%08lX ", top);
912 top -= 2048; /* just to be sure */
913 if (top > CFG_BOOTMAPSZ)
917 debug ("=> set upper limit to 0x%08lX\n", top);
919 /* first check the artos specific boot args, then the linux args*/
920 if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
923 /* get length of cmdline, and place it */
925 top = (top - (len + 1)) & ~0xF;
926 cmdline = (char *)top;
927 debug ("## cmdline at 0x%08lX ", top);
931 top = (top - sizeof(bd_t)) & ~0xF;
932 debug ("## bd at 0x%08lX ", top);
934 memcpy(kbd, gd->bd, sizeof(bd_t));
936 /* first find number of env entries, and their size */
939 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
940 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
943 envsz += (nxt - i) + 1; /* plus trailing zero */
945 envno++; /* plus the terminating zero */
946 debug ("## %u envvars total size %u ", envno, envsz);
948 top = (top - sizeof(char **)*envno) & ~0xF;
949 fwenv = (char **)top;
950 debug ("## fwenv at 0x%08lX ", top);
952 top = (top - envsz) & ~0xF;
957 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
958 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
961 for (j = i; j < nxt; ++j)
962 *s++ = env_get_char(j);
965 *ss++ = NULL; /* terminate */
967 entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
968 (*entry)(kbd, cmdline, fwenv, top);
973 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
974 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
977 #ifndef CFG_HUSH_PARSER
978 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
980 if (parse_string_outer(getenv("bootcmd"),
981 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
987 boot, 1, 1, do_bootd,
988 "boot - boot default, i.e., run 'bootcmd'\n",
992 /* keep old command name "bootd" for backward compatibility */
994 bootd, 1, 1, do_bootd,
995 "bootd - boot default, i.e., run 'bootcmd'\n",
1001 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
1002 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1009 return image_info (load_addr);
1012 for (arg=1; arg <argc; ++arg) {
1013 addr = simple_strtoul(argv[arg], NULL, 16);
1014 if (image_info (addr) != 0) rcode = 1;
1019 static int image_info (ulong addr)
1021 ulong data, len, checksum;
1022 image_header_t *hdr = &header;
1024 printf ("\n## Checking Image at %08lx ...\n", addr);
1026 /* Copy header so we can blank CRC field for re-calculation */
1027 memmove (&header, (char *)addr, sizeof(image_header_t));
1029 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
1030 puts (" Bad Magic Number\n");
1034 data = (ulong)&header;
1035 len = sizeof(image_header_t);
1037 checksum = ntohl(hdr->ih_hcrc);
1040 if (crc32 (0, (char *)data, len) != checksum) {
1041 puts (" Bad Header Checksum\n");
1045 /* for multi-file images we need the data part, too */
1046 print_image_hdr ((image_header_t *)addr);
1048 data = addr + sizeof(image_header_t);
1049 len = ntohl(hdr->ih_size);
1051 puts (" Verifying Checksum ... ");
1052 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
1053 puts (" Bad Data CRC\n");
1061 iminfo, CFG_MAXARGS, 1, do_iminfo,
1062 "iminfo - print header information for application image\n",
1064 " - print header information for application image starting at\n"
1065 " address 'addr' in memory; this includes verification of the\n"
1066 " image contents (magic number, header and payload checksums)\n"
1069 #endif /* CFG_CMD_IMI */
1071 #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
1072 /*-----------------------------------------------------------------------
1073 * List all images found in flash.
1075 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1079 image_header_t *hdr;
1080 ulong data, len, checksum;
1082 for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
1083 if (info->flash_id == FLASH_UNKNOWN)
1085 for (j=0; j<CFG_MAX_FLASH_SECT; ++j) {
1087 if (!(hdr=(image_header_t *)info->start[j]) ||
1088 (ntohl(hdr->ih_magic) != IH_MAGIC))
1091 /* Copy header so we can blank CRC field for re-calculation */
1092 memmove (&header, (char *)hdr, sizeof(image_header_t));
1094 checksum = ntohl(header.ih_hcrc);
1097 if (crc32 (0, (char *)&header, sizeof(image_header_t))
1101 printf ("Image at %08lX:\n", (ulong)hdr);
1102 print_image_hdr( hdr );
1104 data = (ulong)hdr + sizeof(image_header_t);
1105 len = ntohl(hdr->ih_size);
1107 puts (" Verifying Checksum ... ");
1108 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
1109 puts (" Bad Data CRC\n");
1121 imls, 1, 1, do_imls,
1122 "imls - list all images found in flash\n",
1124 " - Prints information about all images found at sector\n"
1125 " boundaries in flash.\n"
1127 #endif /* CFG_CMD_IMLS */
1130 print_image_hdr (image_header_t *hdr)
1132 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1133 time_t timestamp = (time_t)ntohl(hdr->ih_time);
1137 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
1138 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1139 to_tm (timestamp, &tm);
1140 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
1141 tm.tm_year, tm.tm_mon, tm.tm_mday,
1142 tm.tm_hour, tm.tm_min, tm.tm_sec);
1143 #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
1144 puts (" Image Type: "); print_type(hdr);
1145 printf ("\n Data Size: %d Bytes = ", ntohl(hdr->ih_size));
1146 print_size (ntohl(hdr->ih_size), "\n");
1147 printf (" Load Address: %08x\n"
1148 " Entry Point: %08x\n",
1149 ntohl(hdr->ih_load), ntohl(hdr->ih_ep));
1151 if (hdr->ih_type == IH_TYPE_MULTI) {
1154 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
1156 puts (" Contents:\n");
1157 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
1158 printf (" Image %d: %8ld Bytes = ", i, len);
1159 print_size (len, "\n");
1166 print_type (image_header_t *hdr)
1168 char *os, *arch, *type, *comp;
1170 switch (hdr->ih_os) {
1171 case IH_OS_INVALID: os = "Invalid OS"; break;
1172 case IH_OS_NETBSD: os = "NetBSD"; break;
1173 case IH_OS_LINUX: os = "Linux"; break;
1174 case IH_OS_VXWORKS: os = "VxWorks"; break;
1175 case IH_OS_QNX: os = "QNX"; break;
1176 case IH_OS_U_BOOT: os = "U-Boot"; break;
1177 case IH_OS_RTEMS: os = "RTEMS"; break;
1179 case IH_OS_ARTOS: os = "ARTOS"; break;
1181 #ifdef CONFIG_LYNXKDI
1182 case IH_OS_LYNXOS: os = "LynxOS"; break;
1184 default: os = "Unknown OS"; break;
1187 switch (hdr->ih_arch) {
1188 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
1189 case IH_CPU_ALPHA: arch = "Alpha"; break;
1190 case IH_CPU_ARM: arch = "ARM"; break;
1191 case IH_CPU_I386: arch = "Intel x86"; break;
1192 case IH_CPU_IA64: arch = "IA64"; break;
1193 case IH_CPU_MIPS: arch = "MIPS"; break;
1194 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
1195 case IH_CPU_PPC: arch = "PowerPC"; break;
1196 case IH_CPU_S390: arch = "IBM S390"; break;
1197 case IH_CPU_SH: arch = "SuperH"; break;
1198 case IH_CPU_SPARC: arch = "SPARC"; break;
1199 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
1200 case IH_CPU_M68K: arch = "M68K"; break;
1201 case IH_CPU_MICROBLAZE: arch = "Microblaze"; break;
1202 case IH_CPU_NIOS: arch = "Nios"; break;
1203 case IH_CPU_NIOS2: arch = "Nios-II"; break;
1204 default: arch = "Unknown Architecture"; break;
1207 switch (hdr->ih_type) {
1208 case IH_TYPE_INVALID: type = "Invalid Image"; break;
1209 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
1210 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
1211 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
1212 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
1213 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
1214 case IH_TYPE_SCRIPT: type = "Script"; break;
1215 default: type = "Unknown Image"; break;
1218 switch (hdr->ih_comp) {
1219 case IH_COMP_NONE: comp = "uncompressed"; break;
1220 case IH_COMP_GZIP: comp = "gzip compressed"; break;
1221 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
1222 default: comp = "unknown compression"; break;
1225 printf ("%s %s %s (%s)", arch, os, type, comp);
1228 #define ZALLOC_ALIGNMENT 16
1230 static void *zalloc(void *x, unsigned items, unsigned size)
1235 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
1242 static void zfree(void *x, void *addr, unsigned nb)
1248 #define EXTRA_FIELD 4
1250 #define COMMENT 0x10
1251 #define RESERVED 0xe0
1255 int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
1263 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
1264 puts ("Error: Bad gzipped data\n");
1267 if ((flags & EXTRA_FIELD) != 0)
1268 i = 12 + src[10] + (src[11] << 8);
1269 if ((flags & ORIG_NAME) != 0)
1270 while (src[i++] != 0)
1272 if ((flags & COMMENT) != 0)
1273 while (src[i++] != 0)
1275 if ((flags & HEAD_CRC) != 0)
1278 puts ("Error: gunzip out of data in header\n");
1284 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1285 s.outcb = (cb_func)WATCHDOG_RESET;
1288 #endif /* CONFIG_HW_WATCHDOG */
1290 r = inflateInit2(&s, -MAX_WBITS);
1292 printf ("Error: inflateInit2() returned %d\n", r);
1295 s.next_in = src + i;
1296 s.avail_in = *lenp - i;
1298 s.avail_out = dstlen;
1299 r = inflate(&s, Z_FINISH);
1300 if (r != Z_OK && r != Z_STREAM_END) {
1301 printf ("Error: inflate() returned %d\n", r);
1304 *lenp = s.next_out - (unsigned char *) dst;
1311 void bz_internal_error(int errcode)
1313 printf ("BZIP2 internal error %d\n", errcode);
1315 #endif /* CONFIG_BZIP2 */
1318 do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1319 ulong addr, ulong *len_ptr, int verify)
1321 DECLARE_GLOBAL_DATA_PTR;
1322 image_header_t *hdr = &header;
1323 void (*entry_point)(bd_t *);
1325 entry_point = (void (*)(bd_t *)) hdr->ih_ep;
1327 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1328 (ulong)entry_point);
1330 SHOW_BOOT_PROGRESS (15);
1334 * r3: ptr to board info data
1337 (*entry_point ) ( gd->bd );
1340 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
1342 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1343 ulong addr, ulong *len_ptr, int verify)
1345 image_header_t *hdr = &header;
1348 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1349 setenv("loadaddr", str);
1350 do_bootvx(cmdtp, 0, 0, NULL);
1354 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1355 ulong addr, ulong *len_ptr, int verify)
1357 image_header_t *hdr = &header;
1358 char *local_args[2];
1361 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1362 local_args[0] = argv[0];
1363 local_args[1] = str; /* and provide it via the arguments */
1364 do_bootelf(cmdtp, 0, 2, local_args);
1366 #endif /* CFG_CMD_ELF */
1368 #ifdef CONFIG_LYNXKDI
1370 do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
1371 int argc, char *argv[],
1376 lynxkdi_boot( &header );
1379 #endif /* CONFIG_LYNXKDI */