]>
git.ipfire.org Git - people/ms/u-boot.git/blob - lib_arm/armlinux.c
3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
6 * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
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.
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.
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
28 #include <asm/byteorder.h>
29 #ifdef CONFIG_HAS_DATAFLASH
30 #include <dataflash.h>
33 DECLARE_GLOBAL_DATA_PTR
;
36 extern int do_reset (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
38 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
39 defined (CONFIG_CMDLINE_TAG) || \
40 defined (CONFIG_INITRD_TAG) || \
41 defined (CONFIG_SERIAL_TAG) || \
42 defined (CONFIG_REVISION_TAG) || \
43 defined (CONFIG_VFD) || \
45 static void setup_start_tag (bd_t
*bd
);
47 # ifdef CONFIG_SETUP_MEMORY_TAGS
48 static void setup_memory_tags (bd_t
*bd
);
50 static void setup_commandline_tag (bd_t
*bd
, char *commandline
);
53 static void setup_ramdisk_tag (bd_t
*bd
);
55 # ifdef CONFIG_INITRD_TAG
56 static void setup_initrd_tag (bd_t
*bd
, ulong initrd_start
,
59 static void setup_end_tag (bd_t
*bd
);
61 # if defined (CONFIG_VFD) || defined (CONFIG_LCD)
62 static void setup_videolfb_tag (gd_t
*gd
);
66 static struct tag
*params
;
67 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
69 extern image_header_t header
; /* from cmd_bootm.c */
72 void do_bootm_linux (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
73 ulong addr
, ulong
*len_ptr
, int verify
)
75 ulong len
= 0, checksum
;
76 ulong initrd_start
, initrd_end
;
78 void (*theKernel
)(int zero
, int arch
, uint params
);
79 image_header_t
*hdr
= &header
;
82 #ifdef CONFIG_CMDLINE_TAG
83 char *commandline
= getenv ("bootargs");
86 theKernel
= (void (*)(int, int, uint
))ntohl(hdr
->ih_ep
);
89 * Check if there is an initrd image
92 show_boot_progress (9);
94 addr
= simple_strtoul (argv
[2], NULL
, 16);
96 printf ("## Loading Ramdisk Image at %08lx ...\n", addr
);
98 /* Copy header so we can blank CRC field for re-calculation */
99 #ifdef CONFIG_HAS_DATAFLASH
100 if (addr_dataflash (addr
)) {
101 read_dataflash (addr
, sizeof (image_header_t
),
105 memcpy (&header
, (char *) addr
,
106 sizeof (image_header_t
));
108 if (ntohl (hdr
->ih_magic
) != IH_MAGIC
) {
109 printf ("Bad Magic Number\n");
110 show_boot_progress (-10);
111 do_reset (cmdtp
, flag
, argc
, argv
);
114 data
= (ulong
) & header
;
115 len
= sizeof (image_header_t
);
117 checksum
= ntohl (hdr
->ih_hcrc
);
120 if (crc32 (0, (unsigned char *) data
, len
) != checksum
) {
121 printf ("Bad Header Checksum\n");
122 show_boot_progress (-11);
123 do_reset (cmdtp
, flag
, argc
, argv
);
126 show_boot_progress (10);
128 print_image_hdr (hdr
);
130 data
= addr
+ sizeof (image_header_t
);
131 len
= ntohl (hdr
->ih_size
);
133 #ifdef CONFIG_HAS_DATAFLASH
134 if (addr_dataflash (addr
)) {
135 read_dataflash (data
, len
, (char *) CFG_LOAD_ADDR
);
136 data
= CFG_LOAD_ADDR
;
143 printf (" Verifying Checksum ... ");
144 csum
= crc32 (0, (unsigned char *) data
, len
);
145 if (csum
!= ntohl (hdr
->ih_dcrc
)) {
146 printf ("Bad Data CRC\n");
147 show_boot_progress (-12);
148 do_reset (cmdtp
, flag
, argc
, argv
);
153 show_boot_progress (11);
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");
159 show_boot_progress (-13);
160 do_reset (cmdtp
, flag
, argc
, argv
);
163 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
165 *we need to copy the ramdisk to SRAM to let Linux boot
167 memmove ((void *) ntohl(hdr
->ih_load
), (uchar
*)data
, len
);
168 data
= ntohl(hdr
->ih_load
);
169 #endif /* CONFIG_B2 || CONFIG_EVB4510 */
172 * Now check if we have a multifile image
174 } else if ((hdr
->ih_type
== IH_TYPE_MULTI
) && (len_ptr
[1])) {
175 ulong tail
= ntohl (len_ptr
[0]) % 4;
178 show_boot_progress (13);
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
)
185 /* add kernel length, and align */
186 data
+= ntohl (len_ptr
[0]);
191 len
= ntohl (len_ptr
[1]);
197 show_boot_progress (14);
204 printf ("No initrd\n");
210 initrd_end
= initrd_start
+ len
;
216 show_boot_progress (15);
218 debug ("## Transferring control to Linux (at address %08lx) ...\n",
221 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
222 defined (CONFIG_CMDLINE_TAG) || \
223 defined (CONFIG_INITRD_TAG) || \
224 defined (CONFIG_SERIAL_TAG) || \
225 defined (CONFIG_REVISION_TAG) || \
226 defined (CONFIG_LCD) || \
228 setup_start_tag (bd
);
229 #ifdef CONFIG_SERIAL_TAG
230 setup_serial_tag (¶ms
);
232 #ifdef CONFIG_REVISION_TAG
233 setup_revision_tag (¶ms
);
235 #ifdef CONFIG_SETUP_MEMORY_TAGS
236 setup_memory_tags (bd
);
238 #ifdef CONFIG_CMDLINE_TAG
239 setup_commandline_tag (bd
, commandline
);
241 #ifdef CONFIG_INITRD_TAG
242 if (initrd_start
&& initrd_end
)
243 setup_initrd_tag (bd
, initrd_start
, initrd_end
);
245 #if defined (CONFIG_VFD) || defined (CONFIG_LCD)
246 setup_videolfb_tag ((gd_t
*) gd
);
251 /* we assume that the kernel is in place */
252 printf ("\nStarting kernel ...\n\n");
254 #ifdef CONFIG_USB_DEVICE
256 extern void udc_disconnect (void);
261 cleanup_before_linux ();
263 theKernel (0, bd
->bi_arch_number
, bd
->bi_boot_params
);
267 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
268 defined (CONFIG_CMDLINE_TAG) || \
269 defined (CONFIG_INITRD_TAG) || \
270 defined (CONFIG_SERIAL_TAG) || \
271 defined (CONFIG_REVISION_TAG) || \
272 defined (CONFIG_LCD) || \
274 static void setup_start_tag (bd_t
*bd
)
276 params
= (struct tag
*) bd
->bi_boot_params
;
278 params
->hdr
.tag
= ATAG_CORE
;
279 params
->hdr
.size
= tag_size (tag_core
);
281 params
->u
.core
.flags
= 0;
282 params
->u
.core
.pagesize
= 0;
283 params
->u
.core
.rootdev
= 0;
285 params
= tag_next (params
);
289 #ifdef CONFIG_SETUP_MEMORY_TAGS
290 static void setup_memory_tags (bd_t
*bd
)
294 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
295 params
->hdr
.tag
= ATAG_MEM
;
296 params
->hdr
.size
= tag_size (tag_mem32
);
298 params
->u
.mem
.start
= bd
->bi_dram
[i
].start
;
299 params
->u
.mem
.size
= bd
->bi_dram
[i
].size
;
301 params
= tag_next (params
);
304 #endif /* CONFIG_SETUP_MEMORY_TAGS */
307 static void setup_commandline_tag (bd_t
*bd
, char *commandline
)
314 /* eat leading white space */
315 for (p
= commandline
; *p
== ' '; p
++);
317 /* skip non-existent command lines so the kernel will still
318 * use its default command line.
323 params
->hdr
.tag
= ATAG_CMDLINE
;
325 (sizeof (struct tag_header
) + strlen (p
) + 1 + 4) >> 2;
327 strcpy (params
->u
.cmdline
.cmdline
, p
);
329 params
= tag_next (params
);
333 #ifdef CONFIG_INITRD_TAG
334 static void setup_initrd_tag (bd_t
*bd
, ulong initrd_start
, ulong initrd_end
)
336 /* an ATAG_INITRD node tells the kernel where the compressed
337 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
339 params
->hdr
.tag
= ATAG_INITRD2
;
340 params
->hdr
.size
= tag_size (tag_initrd
);
342 params
->u
.initrd
.start
= initrd_start
;
343 params
->u
.initrd
.size
= initrd_end
- initrd_start
;
345 params
= tag_next (params
);
347 #endif /* CONFIG_INITRD_TAG */
350 #if defined (CONFIG_VFD) || defined (CONFIG_LCD)
351 extern ulong
calc_fbsize (void);
352 static void setup_videolfb_tag (gd_t
*gd
)
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 !
358 * We only use it to pass the address and size, the other entries
359 * in the tag_videolfb are not of interest.
361 params
->hdr
.tag
= ATAG_VIDEOLFB
;
362 params
->hdr
.size
= tag_size (tag_videolfb
);
364 params
->u
.videolfb
.lfb_base
= (u32
) gd
->fb_base
;
365 /* Fb size is calculated according to parameters for our panel
367 params
->u
.videolfb
.lfb_size
= calc_fbsize();
369 params
= tag_next (params
);
371 #endif /* CONFIG_VFD || CONFIG_LCD */
373 #ifdef CONFIG_SERIAL_TAG
374 void setup_serial_tag (struct tag
**tmp
)
376 struct tag
*params
= *tmp
;
377 struct tag_serialnr serialnr
;
378 void get_board_serial(struct tag_serialnr
*serialnr
);
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
);
390 #ifdef CONFIG_REVISION_TAG
391 void setup_revision_tag(struct tag
**in_params
)
394 u32
get_board_rev(void);
396 rev
= get_board_rev();
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
);
402 #endif /* CONFIG_REVISION_TAG */
405 static void setup_end_tag (bd_t
*bd
)
407 params
->hdr
.tag
= ATAG_NONE
;
408 params
->hdr
.size
= 0;
411 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */