2 * (C) Copyright 2007 Michal Simek
3 * (C) Copyright 2004 Atmark Techno, Inc.
5 * Michal SIMEK <monstr@monstr.eu>
6 * Yasushi SHOJI <yashi@atmark-techno.com>
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #include <asm/byteorder.h>
33 DECLARE_GLOBAL_DATA_PTR;
35 extern image_header_t header; /* from cmd_bootm.c */
37 extern int do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
39 void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
40 ulong addr, ulong * len_ptr, int verify)
42 ulong len = 0, checksum;
43 ulong initrd_start, initrd_end;
45 /* First parameter is mapped to $r5 for kernel boot args */
46 void (*theKernel) (char *);
47 image_header_t *hdr = &header;
48 char *commandline = getenv ("bootargs");
51 theKernel = (void (*)(char *))ntohl (hdr->ih_ep);
53 /* Check if there is an initrd image */
55 show_boot_progress (9);
57 addr = simple_strtoul (argv[2], NULL, 16);
59 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
61 /* Copy header so we can blank CRC field for re-calculation */
62 memcpy (&header, (char *)addr, sizeof (image_header_t));
64 if (ntohl (hdr->ih_magic) != IH_MAGIC) {
65 printf ("Bad Magic Number\n");
66 show_boot_progress (-10);
67 do_reset (cmdtp, flag, argc, argv);
70 data = (ulong) & header;
71 len = sizeof (image_header_t);
73 checksum = ntohl (hdr->ih_hcrc);
76 if (crc32 (0, (char *)data, len) != checksum) {
77 printf ("Bad Header Checksum\n");
78 show_boot_progress (-11);
79 do_reset (cmdtp, flag, argc, argv);
82 show_boot_progress (10);
84 print_image_hdr (hdr);
86 data = addr + sizeof (image_header_t);
87 len = ntohl (hdr->ih_size);
92 printf (" Verifying Checksum ... ");
93 csum = crc32 (0, (char *)data, len);
94 if (csum != ntohl (hdr->ih_dcrc)) {
95 printf ("Bad Data CRC\n");
96 show_boot_progress (-12);
97 do_reset (cmdtp, flag, argc, argv);
102 show_boot_progress (11);
104 if ((hdr->ih_os != IH_OS_LINUX) ||
105 (hdr->ih_arch != IH_CPU_MICROBLAZE) ||
106 (hdr->ih_type != IH_TYPE_RAMDISK)) {
107 printf ("No Linux Microblaze Ramdisk Image\n");
108 show_boot_progress (-13);
109 do_reset (cmdtp, flag, argc, argv);
113 * Now check if we have a multifile image
115 } else if ((hdr->ih_type == IH_TYPE_MULTI) && (len_ptr[1])) {
116 ulong tail = ntohl (len_ptr[0]) % 4;
118 show_boot_progress (13);
120 /* skip kernel length and terminator */
121 data = (ulong) (&len_ptr[2]);
122 /* skip any additional image length fields */
123 for (i = 1; len_ptr[i]; ++i)
125 /* add kernel length, and align */
126 data += ntohl (len_ptr[0]);
131 len = ntohl (len_ptr[1]);
137 show_boot_progress (14);
144 printf ("No initrd\n");
150 initrd_end = initrd_start + len;
156 show_boot_progress (15);
159 printf ("## Transferring control to Linux (at address %08lx) ...\n",
163 theKernel (commandline);