3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (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, MA 02111-1307 USA
29 #include <asm/byteorder.h>
30 #include <asm/zimage.h>
33 extern image_header_t header; /* from cmd_bootm.c */
36 image_header_t *fake_header(image_header_t *hdr, void *ptr, int size)
38 /* try each supported image type in order */
39 if (NULL != fake_zimage_header(hdr, ptr, size)) {
47 void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
48 ulong addr, ulong *len_ptr, int verify)
52 ulong len = 0, checksum;
53 ulong initrd_start, initrd_end;
55 image_header_t *hdr = &header;
58 * Check if there is an initrd image
61 addr = simple_strtoul(argv[2], NULL, 16);
63 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
65 /* Copy header so we can blank CRC field for re-calculation */
66 memcpy (&header, (char *)addr, sizeof(image_header_t));
68 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
69 printf ("Bad Magic Number\n");
70 do_reset (cmdtp, flag, argc, argv);
73 data = (ulong)&header;
74 len = sizeof(image_header_t);
76 checksum = ntohl(hdr->ih_hcrc);
79 if (crc32 (0, (char *)data, len) != checksum) {
80 printf ("Bad Header Checksum\n");
81 do_reset (cmdtp, flag, argc, argv);
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 do_reset (cmdtp, flag, argc, argv);
101 if ((hdr->ih_os != IH_OS_LINUX) ||
102 (hdr->ih_arch != IH_CPU_I386) ||
103 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
104 printf ("No Linux i386 Ramdisk Image\n");
105 do_reset (cmdtp, flag, argc, argv);
109 * Now check if we have a multifile image
111 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
112 ulong tail = ntohl(len_ptr[0]) % 4;
115 /* skip kernel length and terminator */
116 data = (ulong)(&len_ptr[2]);
117 /* skip any additional image length fields */
118 for (i=1; len_ptr[i]; ++i)
120 /* add kernel length, and align */
121 data += ntohl(len_ptr[0]);
126 len = ntohl(len_ptr[1]);
137 printf ("No initrd\n");
143 initrd_end = initrd_start + len;
144 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
145 initrd_start, initrd_end);
146 memmove ((void *)initrd_start, (void *)data, len);
153 base_ptr = load_zimage(addr + sizeof(image_header_t), ntohl(hdr->ih_size),
154 initrd_start, initrd_end-initrd_start, 0);
156 if (NULL == base_ptr) {
157 printf ("## Kernel loading failed ...\n");
158 do_reset(cmdtp, flag, argc, argv);
163 printf ("## Transferring control to Linux (at address %08x) ...\n",
167 /* we assume that the kernel is in place */
168 printf("\nStarting kernel ...\n\n");
170 boot_zimage(base_ptr);