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