blob: e5b8faa81d357c1259c76bf7a48a69a4970d5634 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002
3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
5 *
6 * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23
24#include <common.h>
25#include <command.h>
26#include <cmd_boot.h>
27#include <image.h>
28#include <zlib.h>
29#include <asm/byteorder.h>
30
31#include <asm/setup.h>
32#define tag_size(type) ((sizeof(struct tag_header) + sizeof(struct type)) >> 2)
33#define tag_next(t) ((struct tag *)((u32 *)(t) + (t)->hdr.size))
34
35#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
36 defined (CONFIG_CMDLINE_TAG) || \
37 defined (CONFIG_INITRD_TAG) || \
38 defined (CONFIG_VFD)
39static void setup_start_tag(bd_t *bd);
40static void setup_memory_tags(bd_t *bd);
41static void setup_commandline_tag(bd_t *bd, char *commandline);
42#if 0
43static void setup_ramdisk_tag(bd_t *bd);
44#endif
45static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end);
46static void setup_end_tag(bd_t *bd);
47#if defined (CONFIG_VFD)
48static void setup_videolfb_tag(gd_t *gd);
49#endif
50
51
52static struct tag *params;
53#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
54
55extern image_header_t header; /* from cmd_bootm.c */
56
57
58void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
59 ulong addr, ulong *len_ptr, int verify)
60{
61 DECLARE_GLOBAL_DATA_PTR;
62
63 ulong len = 0, checksum;
64 ulong initrd_start, initrd_end;
65 ulong data;
66 void (*theKernel)(int zero, int arch);
67 image_header_t *hdr = &header;
68 bd_t *bd = gd->bd;
69#ifdef CONFIG_CMDLINE_TAG
70 char *commandline = getenv("bootargs");
71#endif
72
73 theKernel = (void (*)(int, int))ntohl(hdr->ih_ep);
74
75 /*
76 * Check if there is an initrd image
77 */
78 if (argc >= 3) {
79 addr = simple_strtoul(argv[2], NULL, 16);
80
81 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
82
83 /* Copy header so we can blank CRC field for re-calculation */
84 memcpy (&header, (char *)addr, sizeof(image_header_t));
85
86 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
87 printf ("Bad Magic Number\n");
88 do_reset (cmdtp, flag, argc, argv);
89 }
90
91 data = (ulong)&header;
92 len = sizeof(image_header_t);
93
94 checksum = ntohl(hdr->ih_hcrc);
95 hdr->ih_hcrc = 0;
96
97 if (crc32 (0, (char *)data, len) != checksum) {
98 printf ("Bad Header Checksum\n");
99 do_reset (cmdtp, flag, argc, argv);
100 }
101
102 print_image_hdr (hdr);
103
104 data = addr + sizeof(image_header_t);
105 len = ntohl(hdr->ih_size);
106
107 if (verify) {
108 ulong csum = 0;
109
110 printf (" Verifying Checksum ... ");
111 csum = crc32 (0, (char *)data, len);
112 if (csum != ntohl(hdr->ih_dcrc)) {
113 printf ("Bad Data CRC\n");
114 do_reset (cmdtp, flag, argc, argv);
115 }
116 printf ("OK\n");
117 }
118
119 if ((hdr->ih_os != IH_OS_LINUX) ||
120 (hdr->ih_arch != IH_CPU_ARM) ||
121 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
122 printf ("No Linux ARM Ramdisk Image\n");
123 do_reset (cmdtp, flag, argc, argv);
124 }
125
126 /*
127 * Now check if we have a multifile image
128 */
129 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
130 ulong tail = ntohl(len_ptr[0]) % 4;
131 int i;
132
133 /* skip kernel length and terminator */
134 data = (ulong)(&len_ptr[2]);
135 /* skip any additional image length fields */
136 for (i=1; len_ptr[i]; ++i)
137 data += 4;
138 /* add kernel length, and align */
139 data += ntohl(len_ptr[0]);
140 if (tail) {
141 data += 4 - tail;
142 }
143
144 len = ntohl(len_ptr[1]);
145
146 } else {
147 /*
148 * no initrd image
149 */
150 data = 0;
151 }
152
153#ifdef DEBUG
154 if (!data) {
155 printf ("No initrd\n");
156 }
157#endif
158
159 if (data) {
160 initrd_start = data;
161 initrd_end = initrd_start + len;
162 } else {
163 initrd_start = 0;
164 initrd_end = 0;
165 }
166
167#ifdef DEBUG
168 printf ("## Transferring control to Linux (at address %08lx) ...\n",
169 (ulong)theKernel);
170#endif
171
172#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
173 defined (CONFIG_CMDLINE_TAG) || \
174 defined (CONFIG_INITRD_TAG) || \
175 defined (CONFIG_VFD)
176 setup_start_tag(bd);
177#ifdef CONFIG_SETUP_MEMORY_TAGS
178 setup_memory_tags(bd);
179#endif
180#ifdef CONFIG_CMDLINE_TAG
181 setup_commandline_tag(bd, commandline);
182#endif
183#ifdef CONFIG_INITRD_TAG
184 setup_initrd_tag(bd, initrd_start, initrd_end);
185#endif
186#if 0
187 setup_ramdisk_tag(bd);
188#endif
189#if defined (CONFIG_VFD)
190 setup_videolfb_tag(gd);
191#endif
192 setup_end_tag(bd);
193#endif
194
195 /* we assume that the kernel is in place */
196 printf("\nStarting kernel ...\n\n");
197
198 cleanup_before_linux();
199
200 theKernel(0, bd->bi_arch_number);
201}
202
203
204#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
205 defined (CONFIG_CMDLINE_TAG) || \
206 defined (CONFIG_INITRD_TAG) || \
207 defined (CONFIG_VFD)
208static void setup_start_tag(bd_t *bd)
209{
210 params = (struct tag *)bd->bi_boot_params;
211
212 params->hdr.tag = ATAG_CORE;
213 params->hdr.size = tag_size(tag_core);
214
215 params->u.core.flags = 0;
216 params->u.core.pagesize = 0;
217 params->u.core.rootdev = 0;
218
219 params = tag_next(params);
220}
221
222
223static void setup_memory_tags(bd_t *bd)
224{
225 int i;
226
227 for(i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
228 params->hdr.tag = ATAG_MEM;
229 params->hdr.size = tag_size(tag_mem32);
230
231 params->u.mem.start = bd->bi_dram[i].start;
232 params->u.mem.size = bd->bi_dram[i].size;
233
234 params = tag_next(params);
235 }
236}
237
238
239static void setup_commandline_tag(bd_t *bd, char *commandline)
240{
241 char *p;
242
243 /* eat leading white space */
244 for(p = commandline; *p == ' '; p++)
245 ;
246
247 /* skip non-existent command lines so the kernel will still
248 * use its default command line.
249 */
250 if(*p == '\0')
251 return;
252
253 params->hdr.tag = ATAG_CMDLINE;
254 params->hdr.size = (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2;
255
256 strcpy(params->u.cmdline.cmdline, p);
257
258 params = tag_next(params);
259}
260
261
262#ifndef ATAG_INITRD2
263#define ATAG_INITRD2 0x54420005
264#endif
265static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end)
266{
267 /* an ATAG_INITRD node tells the kernel where the compressed
268 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
269 */
270 params->hdr.tag = ATAG_INITRD2;
271 params->hdr.size = tag_size(tag_initrd);
272
273 params->u.initrd.start = initrd_start;
274 params->u.initrd.size = initrd_end - initrd_start;
275
276 params = tag_next(params);
277}
278
279
280#if 0
281static void setup_ramdisk_tag(bd_t *bd)
282{
283 /* an ATAG_RAMDISK node tells the kernel how large the
284 * decompressed ramdisk will become.
285 */
286 params->hdr.tag = ATAG_RAMDISK;
287 params->hdr.size = tag_size(tag_ramdisk);
288
289 params->u.ramdisk.start = 0;
290 /*params->u.ramdisk.size = RAMDISK_SIZE; */
291 params->u.ramdisk.flags = 1; /* automatically load ramdisk */
292
293 params = tag_next(params);
294}
295#endif /* 0 */
296
297#if defined (CONFIG_VFD)
298static void setup_videolfb_tag(gd_t *gd)
299{
300 /* An ATAG_VIDEOLFB node tells the kernel where and how large
301 * the framebuffer for video was allocated (among other things).
302 * Note that a _physical_ address is passed !
303 *
304 * We only use it to pass the address and size, the other entries
305 * in the tag_videolfb are not of interest.
306 */
307 params->hdr.tag = ATAG_VIDEOLFB;
308 params->hdr.size = tag_size(tag_videolfb);
309
310 params->u.videolfb.lfb_base = (u32)gd->fb_base;
311 /* 7168 = 256*4*56/8 - actually 2 pages (8192 bytes) are allocated */
312 params->u.videolfb.lfb_size = 7168;
313
314 params = tag_next(params);
315}
316#endif
317
318static void setup_end_tag(bd_t *bd)
319{
320 params->hdr.tag = ATAG_NONE;
321 params->hdr.size = 0;
322}
323
324#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */