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