]>
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 | |
232c150a | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c609719b WD |
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 | |
232c150a | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
c609719b WD |
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 | 32 | |
d87080b7 WD |
33 | DECLARE_GLOBAL_DATA_PTR; |
34 | ||
8bde7f77 WD |
35 | /*cmd_boot.c*/ |
36 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); | |
37 | ||
c609719b WD |
38 | #if defined (CONFIG_SETUP_MEMORY_TAGS) || \ |
39 | defined (CONFIG_CMDLINE_TAG) || \ | |
40 | defined (CONFIG_INITRD_TAG) || \ | |
b6e4c403 WD |
41 | defined (CONFIG_SERIAL_TAG) || \ |
42 | defined (CONFIG_REVISION_TAG) || \ | |
8655b6f8 WD |
43 | defined (CONFIG_VFD) || \ |
44 | defined (CONFIG_LCD) | |
5779d8d9 WD |
45 | static void setup_start_tag (bd_t *bd); |
46 | ||
699b13a6 | 47 | # ifdef CONFIG_SETUP_MEMORY_TAGS |
5779d8d9 | 48 | static void setup_memory_tags (bd_t *bd); |
699b13a6 | 49 | # endif |
5779d8d9 WD |
50 | static void setup_commandline_tag (bd_t *bd, char *commandline); |
51 | ||
c609719b | 52 | #if 0 |
5779d8d9 | 53 | static void setup_ramdisk_tag (bd_t *bd); |
c609719b | 54 | #endif |
699b13a6 | 55 | # ifdef CONFIG_INITRD_TAG |
5779d8d9 WD |
56 | static void setup_initrd_tag (bd_t *bd, ulong initrd_start, |
57 | ulong initrd_end); | |
699b13a6 | 58 | # endif |
5779d8d9 WD |
59 | static void setup_end_tag (bd_t *bd); |
60 | ||
8655b6f8 | 61 | # if defined (CONFIG_VFD) || defined (CONFIG_LCD) |
5779d8d9 | 62 | static void setup_videolfb_tag (gd_t *gd); |
699b13a6 | 63 | # endif |
c609719b WD |
64 | |
65 | ||
66 | static struct tag *params; | |
67 | #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */ | |
68 | ||
5779d8d9 | 69 | extern image_header_t header; /* from cmd_bootm.c */ |
c609719b WD |
70 | |
71 | ||
5779d8d9 WD |
72 | void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
73 | ulong addr, ulong *len_ptr, int verify) | |
c609719b | 74 | { |
5779d8d9 WD |
75 | ulong len = 0, checksum; |
76 | ulong initrd_start, initrd_end; | |
77 | ulong data; | |
a2663ea4 | 78 | void (*theKernel)(int zero, int arch, uint params); |
5779d8d9 WD |
79 | image_header_t *hdr = &header; |
80 | bd_t *bd = gd->bd; | |
81 | ||
c609719b | 82 | #ifdef CONFIG_CMDLINE_TAG |
5779d8d9 | 83 | char *commandline = getenv ("bootargs"); |
c609719b WD |
84 | #endif |
85 | ||
a2663ea4 | 86 | theKernel = (void (*)(int, int, uint))ntohl(hdr->ih_ep); |
c609719b | 87 | |
5779d8d9 WD |
88 | /* |
89 | * Check if there is an initrd image | |
90 | */ | |
91 | if (argc >= 3) { | |
fad63407 | 92 | show_boot_progress (9); |
384ae025 | 93 | |
5779d8d9 | 94 | addr = simple_strtoul (argv[2], NULL, 16); |
c609719b | 95 | |
5779d8d9 | 96 | printf ("## Loading Ramdisk Image at %08lx ...\n", addr); |
c609719b | 97 | |
5779d8d9 | 98 | /* Copy header so we can blank CRC field for re-calculation */ |
2abbe075 | 99 | #ifdef CONFIG_HAS_DATAFLASH |
5779d8d9 WD |
100 | if (addr_dataflash (addr)) { |
101 | read_dataflash (addr, sizeof (image_header_t), | |
102 | (char *) &header); | |
103 | } else | |
8bde7f77 | 104 | #endif |
5779d8d9 WD |
105 | memcpy (&header, (char *) addr, |
106 | sizeof (image_header_t)); | |
c609719b | 107 | |
5779d8d9 WD |
108 | if (ntohl (hdr->ih_magic) != IH_MAGIC) { |
109 | printf ("Bad Magic Number\n"); | |
fad63407 | 110 | show_boot_progress (-10); |
5779d8d9 WD |
111 | do_reset (cmdtp, flag, argc, argv); |
112 | } | |
c609719b | 113 | |
5779d8d9 WD |
114 | data = (ulong) & header; |
115 | len = sizeof (image_header_t); | |
c609719b | 116 | |
5779d8d9 WD |
117 | checksum = ntohl (hdr->ih_hcrc); |
118 | hdr->ih_hcrc = 0; | |
c609719b | 119 | |
d52fb7e3 | 120 | if (crc32 (0, (unsigned char *) data, len) != checksum) { |
5779d8d9 | 121 | printf ("Bad Header Checksum\n"); |
fad63407 | 122 | show_boot_progress (-11); |
5779d8d9 WD |
123 | do_reset (cmdtp, flag, argc, argv); |
124 | } | |
c609719b | 125 | |
fad63407 | 126 | show_boot_progress (10); |
384ae025 | 127 | |
5779d8d9 | 128 | print_image_hdr (hdr); |
c609719b | 129 | |
5779d8d9 WD |
130 | data = addr + sizeof (image_header_t); |
131 | len = ntohl (hdr->ih_size); | |
c609719b | 132 | |
2abbe075 | 133 | #ifdef CONFIG_HAS_DATAFLASH |
5779d8d9 WD |
134 | if (addr_dataflash (addr)) { |
135 | read_dataflash (data, len, (char *) CFG_LOAD_ADDR); | |
136 | data = CFG_LOAD_ADDR; | |
137 | } | |
2abbe075 WD |
138 | #endif |
139 | ||
5779d8d9 WD |
140 | if (verify) { |
141 | ulong csum = 0; | |
142 | ||
143 | printf (" Verifying Checksum ... "); | |
d52fb7e3 | 144 | csum = crc32 (0, (unsigned char *) data, len); |
5779d8d9 WD |
145 | if (csum != ntohl (hdr->ih_dcrc)) { |
146 | printf ("Bad Data CRC\n"); | |
fad63407 | 147 | show_boot_progress (-12); |
5779d8d9 WD |
148 | do_reset (cmdtp, flag, argc, argv); |
149 | } | |
150 | printf ("OK\n"); | |
151 | } | |
152 | ||
fad63407 | 153 | show_boot_progress (11); |
5779d8d9 WD |
154 | |
155 | if ((hdr->ih_os != IH_OS_LINUX) || | |
156 | (hdr->ih_arch != IH_CPU_ARM) || | |
157 | (hdr->ih_type != IH_TYPE_RAMDISK)) { | |
158 | printf ("No Linux ARM Ramdisk Image\n"); | |
fad63407 | 159 | show_boot_progress (-13); |
5779d8d9 WD |
160 | do_reset (cmdtp, flag, argc, argv); |
161 | } | |
162 | ||
c570b2fd | 163 | #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO) |
074cff0d WD |
164 | /* |
165 | *we need to copy the ramdisk to SRAM to let Linux boot | |
166 | */ | |
167 | memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len); | |
168 | data = ntohl(hdr->ih_load); | |
a1f4a3dd | 169 | #endif /* CONFIG_B2 || CONFIG_EVB4510 */ |
074cff0d | 170 | |
5779d8d9 WD |
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 | ||
fad63407 | 178 | show_boot_progress (13); |
5779d8d9 WD |
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 | */ | |
fad63407 | 197 | show_boot_progress (14); |
5779d8d9 WD |
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 | |
fad63407 | 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) || \ | |
b6e4c403 WD |
224 | defined (CONFIG_SERIAL_TAG) || \ |
225 | defined (CONFIG_REVISION_TAG) || \ | |
8655b6f8 | 226 | defined (CONFIG_LCD) || \ |
c609719b | 227 | defined (CONFIG_VFD) |
5779d8d9 | 228 | setup_start_tag (bd); |
b6e4c403 WD |
229 | #ifdef CONFIG_SERIAL_TAG |
230 | setup_serial_tag (¶ms); | |
231 | #endif | |
232 | #ifdef CONFIG_REVISION_TAG | |
233 | setup_revision_tag (¶ms); | |
234 | #endif | |
c609719b | 235 | #ifdef CONFIG_SETUP_MEMORY_TAGS |
5779d8d9 | 236 | setup_memory_tags (bd); |
c609719b WD |
237 | #endif |
238 | #ifdef CONFIG_CMDLINE_TAG | |
5779d8d9 | 239 | setup_commandline_tag (bd, commandline); |
c609719b WD |
240 | #endif |
241 | #ifdef CONFIG_INITRD_TAG | |
5779d8d9 WD |
242 | if (initrd_start && initrd_end) |
243 | setup_initrd_tag (bd, initrd_start, initrd_end); | |
c609719b | 244 | #endif |
8655b6f8 | 245 | #if defined (CONFIG_VFD) || defined (CONFIG_LCD) |
5779d8d9 | 246 | setup_videolfb_tag ((gd_t *) gd); |
c609719b | 247 | #endif |
5779d8d9 | 248 | setup_end_tag (bd); |
c609719b WD |
249 | #endif |
250 | ||
5779d8d9 WD |
251 | /* we assume that the kernel is in place */ |
252 | printf ("\nStarting kernel ...\n\n"); | |
c609719b | 253 | |
232c150a WD |
254 | #ifdef CONFIG_USB_DEVICE |
255 | { | |
256 | extern void udc_disconnect (void); | |
257 | udc_disconnect (); | |
258 | } | |
259 | #endif | |
260 | ||
5779d8d9 | 261 | cleanup_before_linux (); |
c609719b | 262 | |
a2663ea4 | 263 | theKernel (0, bd->bi_arch_number, bd->bi_boot_params); |
c609719b WD |
264 | } |
265 | ||
266 | ||
267 | #if defined (CONFIG_SETUP_MEMORY_TAGS) || \ | |
268 | defined (CONFIG_CMDLINE_TAG) || \ | |
269 | defined (CONFIG_INITRD_TAG) || \ | |
b6e4c403 WD |
270 | defined (CONFIG_SERIAL_TAG) || \ |
271 | defined (CONFIG_REVISION_TAG) || \ | |
8655b6f8 | 272 | defined (CONFIG_LCD) || \ |
c609719b | 273 | defined (CONFIG_VFD) |
5779d8d9 | 274 | static void setup_start_tag (bd_t *bd) |
c609719b | 275 | { |
5779d8d9 | 276 | params = (struct tag *) bd->bi_boot_params; |
c609719b | 277 | |
5779d8d9 WD |
278 | params->hdr.tag = ATAG_CORE; |
279 | params->hdr.size = tag_size (tag_core); | |
c609719b | 280 | |
5779d8d9 WD |
281 | params->u.core.flags = 0; |
282 | params->u.core.pagesize = 0; | |
283 | params->u.core.rootdev = 0; | |
c609719b | 284 | |
5779d8d9 | 285 | params = tag_next (params); |
c609719b WD |
286 | } |
287 | ||
288 | ||
699b13a6 | 289 | #ifdef CONFIG_SETUP_MEMORY_TAGS |
5779d8d9 | 290 | static void setup_memory_tags (bd_t *bd) |
c609719b | 291 | { |
5779d8d9 | 292 | int i; |
c609719b | 293 | |
5779d8d9 WD |
294 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
295 | params->hdr.tag = ATAG_MEM; | |
296 | params->hdr.size = tag_size (tag_mem32); | |
c609719b | 297 | |
5779d8d9 WD |
298 | params->u.mem.start = bd->bi_dram[i].start; |
299 | params->u.mem.size = bd->bi_dram[i].size; | |
c609719b | 300 | |
5779d8d9 WD |
301 | params = tag_next (params); |
302 | } | |
c609719b | 303 | } |
5779d8d9 | 304 | #endif /* CONFIG_SETUP_MEMORY_TAGS */ |
c609719b WD |
305 | |
306 | ||
5779d8d9 | 307 | static void setup_commandline_tag (bd_t *bd, char *commandline) |
c609719b | 308 | { |
5779d8d9 | 309 | char *p; |
c609719b | 310 | |
109c0e3a WD |
311 | if (!commandline) |
312 | return; | |
313 | ||
5779d8d9 WD |
314 | /* eat leading white space */ |
315 | for (p = commandline; *p == ' '; p++); | |
c609719b | 316 | |
5779d8d9 WD |
317 | /* skip non-existent command lines so the kernel will still |
318 | * use its default command line. | |
319 | */ | |
320 | if (*p == '\0') | |
321 | return; | |
c609719b | 322 | |
5779d8d9 WD |
323 | params->hdr.tag = ATAG_CMDLINE; |
324 | params->hdr.size = | |
325 | (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2; | |
c609719b | 326 | |
5779d8d9 | 327 | strcpy (params->u.cmdline.cmdline, p); |
c609719b | 328 | |
5779d8d9 | 329 | params = tag_next (params); |
c609719b WD |
330 | } |
331 | ||
332 | ||
699b13a6 | 333 | #ifdef CONFIG_INITRD_TAG |
5779d8d9 | 334 | static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end) |
c609719b | 335 | { |
5779d8d9 WD |
336 | /* an ATAG_INITRD node tells the kernel where the compressed |
337 | * ramdisk can be found. ATAG_RDIMG is a better name, actually. | |
338 | */ | |
498b8db7 | 339 | params->hdr.tag = ATAG_INITRD2; |
5779d8d9 | 340 | params->hdr.size = tag_size (tag_initrd); |
c609719b | 341 | |
5779d8d9 WD |
342 | params->u.initrd.start = initrd_start; |
343 | params->u.initrd.size = initrd_end - initrd_start; | |
c609719b | 344 | |
5779d8d9 | 345 | params = tag_next (params); |
c609719b | 346 | } |
5779d8d9 | 347 | #endif /* CONFIG_INITRD_TAG */ |
c609719b WD |
348 | |
349 | ||
8655b6f8 WD |
350 | #if defined (CONFIG_VFD) || defined (CONFIG_LCD) |
351 | extern ulong calc_fbsize (void); | |
5779d8d9 | 352 | static void setup_videolfb_tag (gd_t *gd) |
c609719b | 353 | { |
5779d8d9 WD |
354 | /* An ATAG_VIDEOLFB node tells the kernel where and how large |
355 | * the framebuffer for video was allocated (among other things). | |
356 | * Note that a _physical_ address is passed ! | |
357 | * | |
358 | * We only use it to pass the address and size, the other entries | |
359 | * in the tag_videolfb are not of interest. | |
360 | */ | |
361 | params->hdr.tag = ATAG_VIDEOLFB; | |
362 | params->hdr.size = tag_size (tag_videolfb); | |
c609719b | 363 | |
5779d8d9 | 364 | params->u.videolfb.lfb_base = (u32) gd->fb_base; |
8655b6f8 WD |
365 | /* Fb size is calculated according to parameters for our panel |
366 | */ | |
367 | params->u.videolfb.lfb_size = calc_fbsize(); | |
c609719b | 368 | |
5779d8d9 | 369 | params = tag_next (params); |
c609719b | 370 | } |
8655b6f8 | 371 | #endif /* CONFIG_VFD || CONFIG_LCD */ |
c609719b | 372 | |
3a574cbe WD |
373 | #ifdef CONFIG_SERIAL_TAG |
374 | void setup_serial_tag (struct tag **tmp) | |
375 | { | |
376 | struct tag *params = *tmp; | |
377 | struct tag_serialnr serialnr; | |
378 | void get_board_serial(struct tag_serialnr *serialnr); | |
379 | ||
380 | get_board_serial(&serialnr); | |
381 | params->hdr.tag = ATAG_SERIAL; | |
382 | params->hdr.size = tag_size (tag_serialnr); | |
383 | params->u.serialnr.low = serialnr.low; | |
384 | params->u.serialnr.high= serialnr.high; | |
385 | params = tag_next (params); | |
386 | *tmp = params; | |
387 | } | |
388 | #endif | |
389 | ||
289f932c WD |
390 | #ifdef CONFIG_REVISION_TAG |
391 | void setup_revision_tag(struct tag **in_params) | |
392 | { | |
393 | u32 rev = 0; | |
289f932c WD |
394 | u32 get_board_rev(void); |
395 | ||
396 | rev = get_board_rev(); | |
289f932c WD |
397 | params->hdr.tag = ATAG_REVISION; |
398 | params->hdr.size = tag_size (tag_revision); | |
399 | params->u.revision.rev = rev; | |
400 | params = tag_next (params); | |
401 | } | |
402 | #endif /* CONFIG_REVISION_TAG */ | |
403 | ||
404 | ||
5779d8d9 | 405 | static void setup_end_tag (bd_t *bd) |
c609719b | 406 | { |
5779d8d9 WD |
407 | params->hdr.tag = ATAG_NONE; |
408 | params->hdr.size = 0; | |
c609719b WD |
409 | } |
410 | ||
411 | #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */ |