blob: 68b58d4be89d71884231df5feef926a81d1376bd [file] [log] [blame]
wdenk12490652004-04-18 21:13:41 +00001/*
Michal Simek922ce202007-03-11 13:48:24 +01002 * (C) Copyright 2007 Michal Simek
wdenk12490652004-04-18 21:13:41 +00003 * (C) Copyright 2004 Atmark Techno, Inc.
4 *
Michal Simek922ce202007-03-11 13:48:24 +01005 * Michal SIMEK <monstr@monstr.eu>
wdenk12490652004-04-18 21:13:41 +00006 * Yasushi SHOJI <yashi@atmark-techno.com>
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
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.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Michal Simek922ce202007-03-11 13:48:24 +010018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenk12490652004-04-18 21:13:41 +000019 * GNU General Public License for more details.
20 *
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,
24 * MA 02111-1307 USA
25 */
26
27#include <common.h>
28#include <command.h>
Michal Simek922ce202007-03-11 13:48:24 +010029#include <image.h>
30#include <zlib.h>
31#include <asm/byteorder.h>
wdenk12490652004-04-18 21:13:41 +000032
Michal Simek922ce202007-03-11 13:48:24 +010033DECLARE_GLOBAL_DATA_PTR;
34
Michal Simek922ce202007-03-11 13:48:24 +010035extern image_header_t header; /* from cmd_bootm.c */
36/*cmd_boot.c*/
37extern int do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
38
39void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
40 ulong addr, ulong * len_ptr, int verify)
wdenk12490652004-04-18 21:13:41 +000041{
Michal Simek922ce202007-03-11 13:48:24 +010042 ulong len = 0, checksum;
43 ulong initrd_start, initrd_end;
44 ulong data;
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");
49 int i;
50
51 theKernel = (void (*)(char *))ntohl (hdr->ih_ep);
52
53 /* Check if there is an initrd image */
54 if (argc >= 3) {
Heiko Schocher8a8ec532007-07-13 09:54:17 +020055 show_boot_progress (9);
Michal Simek922ce202007-03-11 13:48:24 +010056
57 addr = simple_strtoul (argv[2], NULL, 16);
58
59 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
60
61 /* Copy header so we can blank CRC field for re-calculation */
62 memcpy (&header, (char *)addr, sizeof (image_header_t));
63
64 if (ntohl (hdr->ih_magic) != IH_MAGIC) {
65 printf ("Bad Magic Number\n");
Heiko Schocher8a8ec532007-07-13 09:54:17 +020066 show_boot_progress (-10);
Michal Simek922ce202007-03-11 13:48:24 +010067 do_reset (cmdtp, flag, argc, argv);
68 }
69
70 data = (ulong) & header;
71 len = sizeof (image_header_t);
72
73 checksum = ntohl (hdr->ih_hcrc);
74 hdr->ih_hcrc = 0;
75
76 if (crc32 (0, (char *)data, len) != checksum) {
77 printf ("Bad Header Checksum\n");
Heiko Schocher8a8ec532007-07-13 09:54:17 +020078 show_boot_progress (-11);
Michal Simek922ce202007-03-11 13:48:24 +010079 do_reset (cmdtp, flag, argc, argv);
80 }
81
Heiko Schocher8a8ec532007-07-13 09:54:17 +020082 show_boot_progress (10);
Michal Simek922ce202007-03-11 13:48:24 +010083
84 print_image_hdr (hdr);
85
86 data = addr + sizeof (image_header_t);
87 len = ntohl (hdr->ih_size);
88
89 if (verify) {
90 ulong csum = 0;
91
92 printf (" Verifying Checksum ... ");
93 csum = crc32 (0, (char *)data, len);
94 if (csum != ntohl (hdr->ih_dcrc)) {
95 printf ("Bad Data CRC\n");
Heiko Schocher8a8ec532007-07-13 09:54:17 +020096 show_boot_progress (-12);
Michal Simek922ce202007-03-11 13:48:24 +010097 do_reset (cmdtp, flag, argc, argv);
98 }
99 printf ("OK\n");
100 }
101
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200102 show_boot_progress (11);
Michal Simek922ce202007-03-11 13:48:24 +0100103
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");
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200108 show_boot_progress (-13);
Michal Simek922ce202007-03-11 13:48:24 +0100109 do_reset (cmdtp, flag, argc, argv);
110 }
111
112 /*
113 * Now check if we have a multifile image
114 */
115 } else if ((hdr->ih_type == IH_TYPE_MULTI) && (len_ptr[1])) {
116 ulong tail = ntohl (len_ptr[0]) % 4;
117
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200118 show_boot_progress (13);
Michal Simek922ce202007-03-11 13:48:24 +0100119
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)
124 data += 4;
125 /* add kernel length, and align */
126 data += ntohl (len_ptr[0]);
127 if (tail) {
128 data += 4 - tail;
129 }
130
131 len = ntohl (len_ptr[1]);
132
133 } else {
134 /*
135 * no initrd image
136 */
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200137 show_boot_progress (14);
Michal Simek922ce202007-03-11 13:48:24 +0100138
139 data = 0;
140 }
141
142#ifdef DEBUG
143 if (!data) {
144 printf ("No initrd\n");
145 }
146#endif
147
148 if (data) {
149 initrd_start = data;
150 initrd_end = initrd_start + len;
151 } else {
152 initrd_start = 0;
153 initrd_end = 0;
154 }
155
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200156 show_boot_progress (15);
Michal Simek922ce202007-03-11 13:48:24 +0100157
158#ifdef DEBUG
159 printf ("## Transferring control to Linux (at address %08lx) ...\n",
160 (ulong) theKernel);
161#endif
162
163 theKernel (commandline);
wdenk12490652004-04-18 21:13:41 +0000164}