glamo-mmc.patch
[u-boot-openmoko/mini2440.git] / common / cmd_bootm.c
blob8a454b80ea3ca985411e0afd0b6c8a07d12ad69f
1 /*
2 * (C) Copyright 2000-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
6 * project.
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,
21 * MA 02111-1307 USA
26 * Boot support
28 #include <common.h>
29 #include <watchdog.h>
30 #include <command.h>
31 #include <image.h>
32 #include <malloc.h>
33 #include <zlib.h>
34 #include <bzlib.h>
35 #include <environment.h>
36 #include <lmb.h>
37 #include <asm/byteorder.h>
39 #if defined(CONFIG_OF_LIBFDT)
40 #include <fdt.h>
41 #include <libfdt.h>
42 #include <fdt_support.h>
43 #endif
44 #if defined(CONFIG_OF_FLAT_TREE)
45 #include <ft_build.h>
46 #endif
48 void mmc_depower(void);
50 DECLARE_GLOBAL_DATA_PTR;
52 /*cmd_boot.c*/
53 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
55 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
56 #include <rtc.h>
57 #endif
59 #ifdef CFG_HUSH_PARSER
60 #include <hush.h>
61 #endif
63 DECLARE_GLOBAL_DATA_PTR;
65 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
66 #ifndef CFG_BOOTM_LEN
67 #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
68 #endif
70 #ifdef CONFIG_BZIP2
71 extern void bz_internal_error(int);
72 #endif
74 #if defined(CONFIG_CMD_IMI)
75 static int image_info (unsigned long addr);
76 #endif
78 #if defined(CONFIG_CMD_IMLS)
79 #include <flash.h>
80 extern flash_info_t flash_info[]; /* info for FLASH chips */
81 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
82 #endif
84 #ifdef CONFIG_SILENT_CONSOLE
85 static void fixup_silent_linux (void);
86 #endif
88 static image_header_t *image_get_kernel (ulong img_addr, int verify);
89 #if defined(CONFIG_FIT)
90 static int fit_check_kernel (const void *fit, int os_noffset, int verify);
91 #endif
93 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
94 bootm_headers_t *images, ulong *os_data, ulong *os_len);
95 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
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_fn (cmd_tbl_t *cmdtp, int flag,
106 int argc, char *argv[],
107 bootm_headers_t *images); /* pointers to os/initrd/fdt */
109 extern boot_os_fn do_bootm_linux;
110 static boot_os_fn do_bootm_netbsd;
111 #if defined(CONFIG_LYNXKDI)
112 static boot_os_fn do_bootm_lynxkdi;
113 extern void lynxkdi_boot (image_header_t *);
114 #endif
115 static boot_os_fn do_bootm_rtems;
116 #if defined(CONFIG_CMD_ELF)
117 static boot_os_fn do_bootm_vxworks;
118 static boot_os_fn do_bootm_qnxelf;
119 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
120 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
121 #endif
122 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
123 extern uchar (*env_get_char)(int); /* Returns a character from the environment */
124 static boot_os_fn do_bootm_artos;
125 #endif
127 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
128 static bootm_headers_t images; /* pointers to os/initrd/fdt images */
130 void __board_lmb_reserve(struct lmb *lmb)
132 /* please define platform specific board_lmb_reserve() */
134 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
137 /*******************************************************************/
138 /* bootm - boot application image from image in memory */
139 /*******************************************************************/
140 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
142 ulong iflag;
143 const char *type_name;
144 uint unc_len = CFG_BOOTM_LEN;
145 uint8_t comp, type, os;
147 void *os_hdr;
148 ulong os_data, os_len;
149 ulong image_start, image_end;
150 ulong load_start, load_end;
151 ulong mem_start, mem_size;
153 struct lmb lmb;
155 memset ((void *)&images, 0, sizeof (images));
156 images.verify = getenv_verify();
157 images.autostart = getenv_autostart();
158 images.lmb = &lmb;
160 lmb_init(&lmb);
162 mem_start = getenv_bootm_low();
163 mem_size = getenv_bootm_size();
165 lmb_add(&lmb, mem_start, mem_size);
167 board_lmb_reserve(&lmb);
169 /* get kernel image header, start address and length */
170 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
171 &images, &os_data, &os_len);
172 if (os_len == 0) {
173 puts ("ERROR: can't get kernel image!\n");
174 return 1;
177 /* get image parameters */
178 switch (genimg_get_format (os_hdr)) {
179 case IMAGE_FORMAT_LEGACY:
180 type = image_get_type (os_hdr);
181 comp = image_get_comp (os_hdr);
182 os = image_get_os (os_hdr);
184 image_end = image_get_image_end (os_hdr);
185 load_start = image_get_load (os_hdr);
186 break;
187 #if defined(CONFIG_FIT)
188 case IMAGE_FORMAT_FIT:
189 if (fit_image_get_type (images.fit_hdr_os,
190 images.fit_noffset_os, &type)) {
191 puts ("Can't get image type!\n");
192 show_boot_progress (-109);
193 return 1;
196 if (fit_image_get_comp (images.fit_hdr_os,
197 images.fit_noffset_os, &comp)) {
198 puts ("Can't get image compression!\n");
199 show_boot_progress (-110);
200 return 1;
203 if (fit_image_get_os (images.fit_hdr_os,
204 images.fit_noffset_os, &os)) {
205 puts ("Can't get image OS!\n");
206 show_boot_progress (-111);
207 return 1;
210 image_end = fit_get_end (images.fit_hdr_os);
212 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
213 &load_start)) {
214 puts ("Can't get image load address!\n");
215 show_boot_progress (-112);
216 return 1;
218 break;
219 #endif
220 default:
221 puts ("ERROR: unknown image format type!\n");
222 return 1;
225 image_start = (ulong)os_hdr;
226 load_end = 0;
227 type_name = genimg_get_type_name (type);
229 #ifdef CONFIG_DEPOWER_MMC_ON_BOOT
230 mmc_depower();
231 #endif
234 * We have reached the point of no return: we are going to
235 * overwrite all exception vector code, so we cannot easily
236 * recover from any failures any more...
238 iflag = disable_interrupts();
240 #ifdef CONFIG_AMIGAONEG3SE
242 * We've possible left the caches enabled during
243 * bios emulation, so turn them off again
245 icache_disable();
246 invalidate_l1_instruction_cache();
247 flush_data_cache();
248 dcache_disable();
249 #endif
251 switch (comp) {
252 case IH_COMP_NONE:
253 if (load_start == (ulong)os_hdr) {
254 printf (" XIP %s ... ", type_name);
255 } else {
256 printf (" Loading %s ... ", type_name);
258 memmove_wd ((void *)load_start,
259 (void *)os_data, os_len, CHUNKSZ);
261 load_end = load_start + os_len;
262 puts("OK\n");
264 break;
265 case IH_COMP_GZIP:
266 printf (" Uncompressing %s ... ", type_name);
267 if (gunzip ((void *)load_start, unc_len,
268 (uchar *)os_data, &os_len) != 0) {
269 puts ("GUNZIP: uncompress or overwrite error "
270 "- must RESET board to recover\n");
271 show_boot_progress (-6);
272 do_reset (cmdtp, flag, argc, argv);
275 load_end = load_start + os_len;
276 break;
277 #ifdef CONFIG_BZIP2
278 case IH_COMP_BZIP2:
279 printf (" Uncompressing %s ... ", type_name);
281 * If we've got less than 4 MB of malloc() space,
282 * use slower decompression algorithm which requires
283 * at most 2300 KB of memory.
285 int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
286 &unc_len, (char *)os_data, os_len,
287 CFG_MALLOC_LEN < (4096 * 1024), 0);
288 if (i != BZ_OK) {
289 printf ("BUNZIP2: uncompress or overwrite error %d "
290 "- must RESET board to recover\n", i);
291 show_boot_progress (-6);
292 do_reset (cmdtp, flag, argc, argv);
295 load_end = load_start + unc_len;
296 break;
297 #endif /* CONFIG_BZIP2 */
298 default:
299 if (iflag)
300 enable_interrupts();
301 printf ("Unimplemented compression type %d\n", comp);
302 show_boot_progress (-7);
303 return 1;
305 puts ("OK\n");
306 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
307 show_boot_progress (7);
309 if ((load_start < image_end) && (load_end > image_start)) {
310 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
311 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
313 puts ("ERROR: image overwritten - must RESET the board to recover.\n");
314 show_boot_progress (-113);
315 do_reset (cmdtp, flag, argc, argv);
318 show_boot_progress (8);
320 lmb_reserve(&lmb, load_start, (load_end - load_start));
322 switch (os) {
323 default: /* handled by (original) Linux case */
324 case IH_OS_LINUX:
325 #ifdef CONFIG_SILENT_CONSOLE
326 fixup_silent_linux();
327 #endif
328 do_bootm_linux (cmdtp, flag, argc, argv, &images);
329 break;
331 case IH_OS_NETBSD:
332 do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
333 break;
335 #ifdef CONFIG_LYNXKDI
336 case IH_OS_LYNXOS:
337 do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
338 break;
339 #endif
341 case IH_OS_RTEMS:
342 do_bootm_rtems (cmdtp, flag, argc, argv, &images);
343 break;
345 #if defined(CONFIG_CMD_ELF)
346 case IH_OS_VXWORKS:
347 do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
348 break;
350 case IH_OS_QNX:
351 do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
352 break;
353 #endif
355 #ifdef CONFIG_ARTOS
356 case IH_OS_ARTOS:
357 do_bootm_artos (cmdtp, flag, argc, argv, &images);
358 break;
359 #endif
362 show_boot_progress (-9);
363 #ifdef DEBUG
364 puts ("\n## Control returned to monitor - resetting...\n");
365 if (images.autostart)
366 do_reset (cmdtp, flag, argc, argv);
367 #endif
368 if (!images.autostart && iflag)
369 enable_interrupts();
371 return 1;
375 * image_get_kernel - verify legacy format kernel image
376 * @img_addr: in RAM address of the legacy format image to be verified
377 * @verify: data CRC verification flag
379 * image_get_kernel() verifies legacy image integrity and returns pointer to
380 * legacy image header if image verification was completed successfully.
382 * returns:
383 * pointer to a legacy image header if valid image was found
384 * otherwise return NULL
386 static image_header_t *image_get_kernel (ulong img_addr, int verify)
388 image_header_t *hdr = (image_header_t *)img_addr;
390 if (!image_check_magic(hdr)) {
391 puts ("Bad Magic Number\n");
392 show_boot_progress (-1);
393 return NULL;
395 show_boot_progress (2);
397 if (!image_check_hcrc (hdr)) {
398 puts ("Bad Header Checksum\n");
399 show_boot_progress (-2);
400 return NULL;
403 show_boot_progress (3);
404 image_print_contents (hdr);
406 if (verify) {
407 puts (" Verifying Checksum ... ");
408 if (!image_check_dcrc (hdr)) {
409 printf ("Bad Data CRC\n");
410 show_boot_progress (-3);
411 return NULL;
413 puts ("OK\n");
415 show_boot_progress (4);
417 if (!image_check_target_arch (hdr)) {
418 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
419 show_boot_progress (-4);
420 return NULL;
422 return hdr;
426 * fit_check_kernel - verify FIT format kernel subimage
427 * @fit_hdr: pointer to the FIT image header
428 * os_noffset: kernel subimage node offset within FIT image
429 * @verify: data CRC verification flag
431 * fit_check_kernel() verifies integrity of the kernel subimage and from
432 * specified FIT image.
434 * returns:
435 * 1, on success
436 * 0, on failure
438 #if defined (CONFIG_FIT)
439 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
441 fit_image_print (fit, os_noffset, " ");
443 if (verify) {
444 puts (" Verifying Hash Integrity ... ");
445 if (!fit_image_check_hashes (fit, os_noffset)) {
446 puts ("Bad Data Hash\n");
447 show_boot_progress (-104);
448 return 0;
450 puts ("OK\n");
452 show_boot_progress (105);
454 #ifdef CONFIG_LOGBUFFER
455 #ifndef CONFIG_ALT_LB_ADDR
456 kbd=gd->bd;
457 /* Prevent initrd from overwriting logbuffer */
458 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
459 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
460 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
461 #else
462 debug ("## Logbuffer at 0x%08lX ", CONFIG_ALT_LB_ADDR);
463 #endif
464 #endif
465 if (!fit_image_check_target_arch (fit, os_noffset)) {
466 puts ("Unsupported Architecture\n");
467 show_boot_progress (-105);
468 return 0;
471 show_boot_progress (106);
472 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
473 puts ("Not a kernel image\n");
474 show_boot_progress (-106);
475 return 0;
478 show_boot_progress (107);
479 return 1;
481 #endif /* CONFIG_FIT */
484 * boot_get_kernel - find kernel image
485 * @os_data: pointer to a ulong variable, will hold os data start address
486 * @os_len: pointer to a ulong variable, will hold os data length
488 * boot_get_kernel() tries to find a kernel image, verifies its integrity
489 * and locates kernel data.
491 * returns:
492 * pointer to image header if valid image was found, plus kernel start
493 * address and length, otherwise NULL
495 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
496 bootm_headers_t *images, ulong *os_data, ulong *os_len)
498 image_header_t *hdr;
499 ulong img_addr;
500 #if defined(CONFIG_FIT)
501 void *fit_hdr;
502 const char *fit_uname_config = NULL;
503 const char *fit_uname_kernel = NULL;
504 const void *data;
505 size_t len;
506 int cfg_noffset;
507 int os_noffset;
508 #endif
510 /* find out kernel image address */
511 if (argc < 2) {
512 img_addr = load_addr;
513 debug ("* kernel: default image load address = 0x%08lx\n",
514 load_addr);
515 #if defined(CONFIG_FIT)
516 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
517 &fit_uname_config)) {
518 debug ("* kernel: config '%s' from image at 0x%08lx\n",
519 fit_uname_config, img_addr);
520 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
521 &fit_uname_kernel)) {
522 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
523 fit_uname_kernel, img_addr);
524 #endif
525 } else {
526 img_addr = simple_strtoul(argv[1], NULL, 16);
527 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
530 show_boot_progress (1);
532 /* copy from dataflash if needed */
533 img_addr = genimg_get_image (img_addr);
535 /* check image type, for FIT images get FIT kernel node */
536 *os_data = *os_len = 0;
537 switch (genimg_get_format ((void *)img_addr)) {
538 case IMAGE_FORMAT_LEGACY:
539 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
540 img_addr);
541 hdr = image_get_kernel (img_addr, images->verify);
542 if (!hdr)
543 return NULL;
544 show_boot_progress (5);
546 /* get os_data and os_len */
547 switch (image_get_type (hdr)) {
548 case IH_TYPE_KERNEL:
549 *os_data = image_get_data (hdr);
550 *os_len = image_get_data_size (hdr);
551 break;
552 case IH_TYPE_MULTI:
553 image_multi_getimg (hdr, 0, os_data, os_len);
554 break;
555 default:
556 printf ("Wrong Image Type for %s command\n", cmdtp->name);
557 show_boot_progress (-5);
558 return NULL;
560 images->legacy_hdr_os = hdr;
561 images->legacy_hdr_valid = 1;
563 show_boot_progress (6);
564 break;
565 #if defined(CONFIG_FIT)
566 case IMAGE_FORMAT_FIT:
567 fit_hdr = (void *)img_addr;
568 printf ("## Booting kernel from FIT Image at %08lx ...\n",
569 img_addr);
571 if (!fit_check_format (fit_hdr)) {
572 puts ("Bad FIT kernel image format!\n");
573 show_boot_progress (-100);
574 return NULL;
576 show_boot_progress (100);
578 if (!fit_uname_kernel) {
580 * no kernel image node unit name, try to get config
581 * node first. If config unit node name is NULL
582 * fit_conf_get_node() will try to find default config node
584 show_boot_progress (101);
585 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
586 if (cfg_noffset < 0) {
587 show_boot_progress (-101);
588 return NULL;
590 /* save configuration uname provided in the first
591 * bootm argument
593 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
594 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
595 show_boot_progress (103);
597 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
598 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
599 } else {
600 /* get kernel component image node offset */
601 show_boot_progress (102);
602 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
604 if (os_noffset < 0) {
605 show_boot_progress (-103);
606 return NULL;
609 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
611 show_boot_progress (104);
612 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
613 return NULL;
615 /* get kernel image data address and length */
616 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
617 puts ("Could not find kernel subimage data!\n");
618 show_boot_progress (-107);
619 return NULL;
621 show_boot_progress (108);
623 *os_len = len;
624 *os_data = (ulong)data;
625 images->fit_hdr_os = fit_hdr;
626 images->fit_uname_os = fit_uname_kernel;
627 images->fit_noffset_os = os_noffset;
628 break;
629 #endif
630 default:
631 printf ("Wrong Image Format for %s command\n", cmdtp->name);
632 show_boot_progress (-108);
633 return NULL;
636 debug (" kernel data at 0x%08lx, len = 0x%08lx (%d)\n",
637 *os_data, *os_len, *os_len);
639 return (void *)img_addr;
642 U_BOOT_CMD(
643 bootm, CFG_MAXARGS, 1, do_bootm,
644 "bootm - boot application image from memory\n",
645 "[addr [arg ...]]\n - boot application image stored in memory\n"
646 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
647 "\t'arg' can be the address of an initrd image\n"
648 #if defined(CONFIG_OF_LIBFDT)
649 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
650 "\ta third argument is required which is the address of the\n"
651 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
652 "\tuse a '-' for the second argument. If you do not pass a third\n"
653 "\ta bd_info struct will be passed instead\n"
654 #endif
655 #if defined(CONFIG_FIT)
656 "\t\nFor the new multi component uImage format (FIT) addresses\n"
657 "\tmust be extened to include component or configuration unit name:\n"
658 "\taddr:<subimg_uname> - direct component image specification\n"
659 "\taddr#<conf_uname> - configuration specification\n"
660 "\tUse iminfo command to get the list of existing component\n"
661 "\timages and configurations.\n"
662 #endif
665 /*******************************************************************/
666 /* bootd - boot default image */
667 /*******************************************************************/
668 #if defined(CONFIG_CMD_BOOTD)
669 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
671 int rcode = 0;
673 #ifndef CFG_HUSH_PARSER
674 if (run_command (getenv ("bootcmd"), flag) < 0)
675 rcode = 1;
676 #else
677 if (parse_string_outer (getenv ("bootcmd"),
678 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
679 rcode = 1;
680 #endif
681 return rcode;
684 U_BOOT_CMD(
685 boot, 1, 1, do_bootd,
686 "boot - boot default, i.e., run 'bootcmd'\n",
687 NULL
690 /* keep old command name "bootd" for backward compatibility */
691 U_BOOT_CMD(
692 bootd, 1, 1, do_bootd,
693 "bootd - boot default, i.e., run 'bootcmd'\n",
694 NULL
697 #endif
700 /*******************************************************************/
701 /* iminfo - print header info for a requested image */
702 /*******************************************************************/
703 #if defined(CONFIG_CMD_IMI)
704 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
706 int arg;
707 ulong addr;
708 int rcode = 0;
710 if (argc < 2) {
711 return image_info (load_addr);
714 for (arg = 1; arg < argc; ++arg) {
715 addr = simple_strtoul (argv[arg], NULL, 16);
716 if (image_info (addr) != 0)
717 rcode = 1;
719 return rcode;
722 static int image_info (ulong addr)
724 void *hdr = (void *)addr;
726 printf ("\n## Checking Image at %08lx ...\n", addr);
728 switch (genimg_get_format (hdr)) {
729 case IMAGE_FORMAT_LEGACY:
730 puts (" Legacy image found\n");
731 if (!image_check_magic (hdr)) {
732 puts (" Bad Magic Number\n");
733 return 1;
736 if (!image_check_hcrc (hdr)) {
737 puts (" Bad Header Checksum\n");
738 return 1;
741 image_print_contents (hdr);
743 puts (" Verifying Checksum ... ");
744 if (!image_check_dcrc (hdr)) {
745 puts (" Bad Data CRC\n");
746 return 1;
748 puts ("OK\n");
749 return 0;
750 #if defined(CONFIG_FIT)
751 case IMAGE_FORMAT_FIT:
752 puts (" FIT image found\n");
754 if (!fit_check_format (hdr)) {
755 puts ("Bad FIT image format!\n");
756 return 1;
759 fit_print_contents (hdr);
760 return 0;
761 #endif
762 default:
763 puts ("Unknown image format!\n");
764 break;
767 return 1;
770 U_BOOT_CMD(
771 iminfo, CFG_MAXARGS, 1, do_iminfo,
772 "iminfo - print header information for application image\n",
773 "addr [addr ...]\n"
774 " - print header information for application image starting at\n"
775 " address 'addr' in memory; this includes verification of the\n"
776 " image contents (magic number, header and payload checksums)\n"
778 #endif
781 /*******************************************************************/
782 /* imls - list all images found in flash */
783 /*******************************************************************/
784 #if defined(CONFIG_CMD_IMLS)
785 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
787 flash_info_t *info;
788 int i, j;
789 void *hdr;
791 for (i = 0, info = &flash_info[0];
792 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
794 if (info->flash_id == FLASH_UNKNOWN)
795 goto next_bank;
796 for (j = 0; j < info->sector_count; ++j) {
798 hdr = (void *)info->start[j];
799 if (!hdr)
800 goto next_sector;
802 switch (genimg_get_format (hdr)) {
803 case IMAGE_FORMAT_LEGACY:
804 if (!image_check_hcrc (hdr))
805 goto next_sector;
807 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
808 image_print_contents (hdr);
810 puts (" Verifying Checksum ... ");
811 if (!image_check_dcrc (hdr)) {
812 puts ("Bad Data CRC\n");
813 } else {
814 puts ("OK\n");
816 break;
817 #if defined(CONFIG_FIT)
818 case IMAGE_FORMAT_FIT:
819 if (!fit_check_format (hdr))
820 goto next_sector;
822 printf ("FIT Image at %08lX:\n", (ulong)hdr);
823 fit_print_contents (hdr);
824 break;
825 #endif
826 default:
827 goto next_sector;
830 next_sector: ;
832 next_bank: ;
835 return (0);
838 U_BOOT_CMD(
839 imls, 1, 1, do_imls,
840 "imls - list all images found in flash\n",
841 "\n"
842 " - Prints information about all images found at sector\n"
843 " boundaries in flash.\n"
845 #endif
847 /*******************************************************************/
848 /* helper routines */
849 /*******************************************************************/
850 #ifdef CONFIG_SILENT_CONSOLE
851 static void fixup_silent_linux ()
853 char buf[256], *start, *end;
854 char *cmdline = getenv ("bootargs");
856 /* Only fix cmdline when requested */
857 if (!(gd->flags & GD_FLG_SILENT))
858 return;
860 debug ("before silent fix-up: %s\n", cmdline);
861 if (cmdline) {
862 if ((start = strstr (cmdline, "console=")) != NULL) {
863 end = strchr (start, ' ');
864 strncpy (buf, cmdline, (start - cmdline + 8));
865 if (end)
866 strcpy (buf + (start - cmdline + 8), end);
867 else
868 buf[start - cmdline + 8] = '\0';
869 } else {
870 strcpy (buf, cmdline);
871 strcat (buf, " console=");
873 } else {
874 strcpy (buf, "console=");
877 setenv ("bootargs", buf);
878 debug ("after silent fix-up: %s\n", buf);
880 #endif /* CONFIG_SILENT_CONSOLE */
883 /*******************************************************************/
884 /* OS booting routines */
885 /*******************************************************************/
887 static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
888 int argc, char *argv[],
889 bootm_headers_t *images)
891 void (*loader)(bd_t *, image_header_t *, char *, char *);
892 image_header_t *os_hdr, *hdr;
893 ulong kernel_data, kernel_len;
894 char *consdev;
895 char *cmdline;
897 #if defined(CONFIG_FIT)
898 if (!images->legacy_hdr_valid) {
899 fit_unsupported_reset ("NetBSD");
900 do_reset (cmdtp, flag, argc, argv);
902 #endif
903 hdr = images->legacy_hdr_os;
906 * Booting a (NetBSD) kernel image
908 * This process is pretty similar to a standalone application:
909 * The (first part of an multi-) image must be a stage-2 loader,
910 * which in turn is responsible for loading & invoking the actual
911 * kernel. The only differences are the parameters being passed:
912 * besides the board info strucure, the loader expects a command
913 * line, the name of the console device, and (optionally) the
914 * address of the original image header.
916 os_hdr = NULL;
917 if (image_check_type (hdr, IH_TYPE_MULTI)) {
918 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
919 if (kernel_len)
920 os_hdr = hdr;
923 consdev = "";
924 #if defined (CONFIG_8xx_CONS_SMC1)
925 consdev = "smc1";
926 #elif defined (CONFIG_8xx_CONS_SMC2)
927 consdev = "smc2";
928 #elif defined (CONFIG_8xx_CONS_SCC2)
929 consdev = "scc2";
930 #elif defined (CONFIG_8xx_CONS_SCC3)
931 consdev = "scc3";
932 #endif
934 if (argc > 2) {
935 ulong len;
936 int i;
938 for (i = 2, len = 0; i < argc; i += 1)
939 len += strlen (argv[i]) + 1;
940 cmdline = malloc (len);
942 for (i = 2, len = 0; i < argc; i += 1) {
943 if (i > 2)
944 cmdline[len++] = ' ';
945 strcpy (&cmdline[len], argv[i]);
946 len += strlen (argv[i]);
948 } else if ((cmdline = getenv ("bootargs")) == NULL) {
949 cmdline = "";
952 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
954 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
955 (ulong)loader);
957 show_boot_progress (15);
960 * NetBSD Stage-2 Loader Parameters:
961 * r3: ptr to board info data
962 * r4: image address
963 * r5: console device
964 * r6: boot args string
966 (*loader) (gd->bd, os_hdr, consdev, cmdline);
969 #ifdef CONFIG_LYNXKDI
970 static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
971 int argc, char *argv[],
972 bootm_headers_t *images)
974 image_header_t *hdr = images->legacy_hdr_os;
976 #if defined(CONFIG_FIT)
977 if (!images->legacy_hdr_valid) {
978 fit_unsupported_reset ("Lynx");
979 do_reset (cmdtp, flag, argc, argv);
981 #endif
983 lynxkdi_boot ((image_header_t *)hdr);
985 #endif /* CONFIG_LYNXKDI */
987 static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
988 int argc, char *argv[],
989 bootm_headers_t *images)
991 image_header_t *hdr = images->legacy_hdr_os;
992 void (*entry_point)(bd_t *);
994 #if defined(CONFIG_FIT)
995 if (!images->legacy_hdr_valid) {
996 fit_unsupported_reset ("RTEMS");
997 do_reset (cmdtp, flag, argc, argv);
999 #endif
1001 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
1003 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1004 (ulong)entry_point);
1006 show_boot_progress (15);
1009 * RTEMS Parameters:
1010 * r3: ptr to board info data
1012 (*entry_point)(gd->bd);
1015 #if defined(CONFIG_CMD_ELF)
1016 static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
1017 int argc, char *argv[],
1018 bootm_headers_t *images)
1020 char str[80];
1021 image_header_t *hdr = images->legacy_hdr_os;
1023 #if defined(CONFIG_FIT)
1024 if (hdr == NULL) {
1025 fit_unsupported_reset ("VxWorks");
1026 do_reset (cmdtp, flag, argc, argv);
1028 #endif
1030 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
1031 setenv("loadaddr", str);
1032 do_bootvx(cmdtp, 0, 0, NULL);
1035 static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
1036 int argc, char *argv[],
1037 bootm_headers_t *images)
1039 char *local_args[2];
1040 char str[16];
1041 image_header_t *hdr = images->legacy_hdr_os;
1043 #if defined(CONFIG_FIT)
1044 if (!images->legacy_hdr_valid) {
1045 fit_unsupported_reset ("QNX");
1046 do_reset (cmdtp, flag, argc, argv);
1048 #endif
1050 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
1051 local_args[0] = argv[0];
1052 local_args[1] = str; /* and provide it via the arguments */
1053 do_bootelf(cmdtp, 0, 2, local_args);
1055 #endif
1057 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
1058 static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
1059 int argc, char *argv[],
1060 bootm_headers_t *images)
1062 ulong top;
1063 char *s, *cmdline;
1064 char **fwenv, **ss;
1065 int i, j, nxt, len, envno, envsz;
1066 bd_t *kbd;
1067 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
1068 image_header_t *hdr = images->legacy_hdr_os;
1070 #if defined(CONFIG_FIT)
1071 if (!images->legacy_hdr_valid) {
1072 fit_unsupported_reset ("ARTOS");
1073 do_reset (cmdtp, flag, argc, argv);
1075 #endif
1078 * Booting an ARTOS kernel image + application
1081 /* this used to be the top of memory, but was wrong... */
1082 #ifdef CONFIG_PPC
1083 /* get stack pointer */
1084 asm volatile ("mr %0,1" : "=r"(top) );
1085 #endif
1086 debug ("## Current stack ends at 0x%08lX ", top);
1088 top -= 2048; /* just to be sure */
1089 if (top > CFG_BOOTMAPSZ)
1090 top = CFG_BOOTMAPSZ;
1091 top &= ~0xF;
1093 debug ("=> set upper limit to 0x%08lX\n", top);
1095 /* first check the artos specific boot args, then the linux args*/
1096 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
1097 s = "";
1099 /* get length of cmdline, and place it */
1100 len = strlen (s);
1101 top = (top - (len + 1)) & ~0xF;
1102 cmdline = (char *)top;
1103 debug ("## cmdline at 0x%08lX ", top);
1104 strcpy (cmdline, s);
1106 /* copy bdinfo */
1107 top = (top - sizeof (bd_t)) & ~0xF;
1108 debug ("## bd at 0x%08lX ", top);
1109 kbd = (bd_t *)top;
1110 memcpy (kbd, gd->bd, sizeof (bd_t));
1112 /* first find number of env entries, and their size */
1113 envno = 0;
1114 envsz = 0;
1115 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1116 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
1118 envno++;
1119 envsz += (nxt - i) + 1; /* plus trailing zero */
1121 envno++; /* plus the terminating zero */
1122 debug ("## %u envvars total size %u ", envno, envsz);
1124 top = (top - sizeof (char **) * envno) & ~0xF;
1125 fwenv = (char **)top;
1126 debug ("## fwenv at 0x%08lX ", top);
1128 top = (top - envsz) & ~0xF;
1129 s = (char *)top;
1130 ss = fwenv;
1132 /* now copy them */
1133 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1134 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
1136 *ss++ = s;
1137 for (j = i; j < nxt; ++j)
1138 *s++ = env_get_char (j);
1139 *s++ = '\0';
1141 *ss++ = NULL; /* terminate */
1143 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
1144 (*entry) (kbd, cmdline, fwenv, top);
1146 #endif