]>
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>
34 extern int do_reset (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
36 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
37 defined (CONFIG_CMDLINE_TAG) || \
38 defined (CONFIG_INITRD_TAG) || \
39 defined (CONFIG_SERIAL_TAG) || \
40 defined (CONFIG_REVISION_TAG) || \
42 static void setup_start_tag (bd_t
*bd
);
44 # ifdef CONFIG_SETUP_MEMORY_TAGS
45 static void setup_memory_tags (bd_t
*bd
);
47 static void setup_commandline_tag (bd_t
*bd
, char *commandline
);
50 static void setup_ramdisk_tag (bd_t
*bd
);
52 # ifdef CONFIG_INITRD_TAG
53 static void setup_initrd_tag (bd_t
*bd
, ulong initrd_start
,
56 static void setup_end_tag (bd_t
*bd
);
58 # if defined (CONFIG_VFD)
59 static void setup_videolfb_tag (gd_t
*gd
);
63 static struct tag
*params
;
64 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
66 #ifdef CONFIG_SHOW_BOOT_PROGRESS
67 # include <status_led.h>
68 # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
70 # define SHOW_BOOT_PROGRESS(arg)
73 extern image_header_t header
; /* from cmd_bootm.c */
76 void do_bootm_linux (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
77 ulong addr
, ulong
*len_ptr
, int verify
)
79 DECLARE_GLOBAL_DATA_PTR
;
81 ulong len
= 0, checksum
;
82 ulong initrd_start
, initrd_end
;
84 void (*theKernel
)(int zero
, int arch
, uint params
);
85 image_header_t
*hdr
= &header
;
88 #ifdef CONFIG_CMDLINE_TAG
89 char *commandline
= getenv ("bootargs");
92 theKernel
= (void (*)(int, int, uint
))ntohl(hdr
->ih_ep
);
95 * Check if there is an initrd image
98 SHOW_BOOT_PROGRESS (9);
100 addr
= simple_strtoul (argv
[2], NULL
, 16);
102 printf ("## Loading Ramdisk Image at %08lx ...\n", addr
);
104 /* Copy header so we can blank CRC field for re-calculation */
105 #ifdef CONFIG_HAS_DATAFLASH
106 if (addr_dataflash (addr
)) {
107 read_dataflash (addr
, sizeof (image_header_t
),
111 memcpy (&header
, (char *) addr
,
112 sizeof (image_header_t
));
114 if (ntohl (hdr
->ih_magic
) != IH_MAGIC
) {
115 printf ("Bad Magic Number\n");
116 SHOW_BOOT_PROGRESS (-10);
117 do_reset (cmdtp
, flag
, argc
, argv
);
120 data
= (ulong
) & header
;
121 len
= sizeof (image_header_t
);
123 checksum
= ntohl (hdr
->ih_hcrc
);
126 if (crc32 (0, (char *) data
, len
) != checksum
) {
127 printf ("Bad Header Checksum\n");
128 SHOW_BOOT_PROGRESS (-11);
129 do_reset (cmdtp
, flag
, argc
, argv
);
132 SHOW_BOOT_PROGRESS (10);
134 print_image_hdr (hdr
);
136 data
= addr
+ sizeof (image_header_t
);
137 len
= ntohl (hdr
->ih_size
);
139 #ifdef CONFIG_HAS_DATAFLASH
140 if (addr_dataflash (addr
)) {
141 read_dataflash (data
, len
, (char *) CFG_LOAD_ADDR
);
142 data
= CFG_LOAD_ADDR
;
149 printf (" Verifying Checksum ... ");
150 csum
= crc32 (0, (char *) data
, len
);
151 if (csum
!= ntohl (hdr
->ih_dcrc
)) {
152 printf ("Bad Data CRC\n");
153 SHOW_BOOT_PROGRESS (-12);
154 do_reset (cmdtp
, flag
, argc
, argv
);
159 SHOW_BOOT_PROGRESS (11);
161 if ((hdr
->ih_os
!= IH_OS_LINUX
) ||
162 (hdr
->ih_arch
!= IH_CPU_ARM
) ||
163 (hdr
->ih_type
!= IH_TYPE_RAMDISK
)) {
164 printf ("No Linux ARM Ramdisk Image\n");
165 SHOW_BOOT_PROGRESS (-13);
166 do_reset (cmdtp
, flag
, argc
, argv
);
170 * Now check if we have a multifile image
172 } else if ((hdr
->ih_type
== IH_TYPE_MULTI
) && (len_ptr
[1])) {
173 ulong tail
= ntohl (len_ptr
[0]) % 4;
176 SHOW_BOOT_PROGRESS (13);
178 /* skip kernel length and terminator */
179 data
= (ulong
) (&len_ptr
[2]);
180 /* skip any additional image length fields */
181 for (i
= 1; len_ptr
[i
]; ++i
)
183 /* add kernel length, and align */
184 data
+= ntohl (len_ptr
[0]);
189 len
= ntohl (len_ptr
[1]);
195 SHOW_BOOT_PROGRESS (14);
202 printf ("No initrd\n");
208 initrd_end
= initrd_start
+ len
;
214 SHOW_BOOT_PROGRESS (15);
216 debug ("## Transferring control to Linux (at address %08lx) ...\n",
219 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
220 defined (CONFIG_CMDLINE_TAG) || \
221 defined (CONFIG_INITRD_TAG) || \
222 defined (CONFIG_SERIAL_TAG) || \
223 defined (CONFIG_REVISION_TAG) || \
225 setup_start_tag (bd
);
226 #ifdef CONFIG_SERIAL_TAG
227 setup_serial_tag (¶ms
);
229 #ifdef CONFIG_REVISION_TAG
230 setup_revision_tag (¶ms
);
232 #ifdef CONFIG_SETUP_MEMORY_TAGS
233 setup_memory_tags (bd
);
235 #ifdef CONFIG_CMDLINE_TAG
236 setup_commandline_tag (bd
, commandline
);
238 #ifdef CONFIG_INITRD_TAG
239 if (initrd_start
&& initrd_end
)
240 setup_initrd_tag (bd
, initrd_start
, initrd_end
);
242 #if defined (CONFIG_VFD)
243 setup_videolfb_tag ((gd_t
*) gd
);
248 /* we assume that the kernel is in place */
249 printf ("\nStarting kernel ...\n\n");
251 cleanup_before_linux ();
253 theKernel (0, bd
->bi_arch_number
, bd
->bi_boot_params
);
257 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
258 defined (CONFIG_CMDLINE_TAG) || \
259 defined (CONFIG_INITRD_TAG) || \
260 defined (CONFIG_SERIAL_TAG) || \
261 defined (CONFIG_REVISION_TAG) || \
263 static void setup_start_tag (bd_t
*bd
)
265 params
= (struct tag
*) bd
->bi_boot_params
;
267 params
->hdr
.tag
= ATAG_CORE
;
268 params
->hdr
.size
= tag_size (tag_core
);
270 params
->u
.core
.flags
= 0;
271 params
->u
.core
.pagesize
= 0;
272 params
->u
.core
.rootdev
= 0;
274 params
= tag_next (params
);
278 #ifdef CONFIG_SETUP_MEMORY_TAGS
279 static void setup_memory_tags (bd_t
*bd
)
283 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
284 params
->hdr
.tag
= ATAG_MEM
;
285 params
->hdr
.size
= tag_size (tag_mem32
);
287 params
->u
.mem
.start
= bd
->bi_dram
[i
].start
;
288 params
->u
.mem
.size
= bd
->bi_dram
[i
].size
;
290 params
= tag_next (params
);
293 #endif /* CONFIG_SETUP_MEMORY_TAGS */
296 static void setup_commandline_tag (bd_t
*bd
, char *commandline
)
300 /* eat leading white space */
301 for (p
= commandline
; *p
== ' '; p
++);
303 /* skip non-existent command lines so the kernel will still
304 * use its default command line.
309 params
->hdr
.tag
= ATAG_CMDLINE
;
311 (sizeof (struct tag_header
) + strlen (p
) + 1 + 4) >> 2;
313 strcpy (params
->u
.cmdline
.cmdline
, p
);
315 params
= tag_next (params
);
319 #ifdef CONFIG_INITRD_TAG
320 static void setup_initrd_tag (bd_t
*bd
, ulong initrd_start
, ulong initrd_end
)
322 /* an ATAG_INITRD node tells the kernel where the compressed
323 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
325 params
->hdr
.tag
= ATAG_INITRD2
;
326 params
->hdr
.size
= tag_size (tag_initrd
);
328 params
->u
.initrd
.start
= initrd_start
;
329 params
->u
.initrd
.size
= initrd_end
- initrd_start
;
331 params
= tag_next (params
);
333 #endif /* CONFIG_INITRD_TAG */
336 #if defined (CONFIG_VFD)
337 static void setup_videolfb_tag (gd_t
*gd
)
339 /* An ATAG_VIDEOLFB node tells the kernel where and how large
340 * the framebuffer for video was allocated (among other things).
341 * Note that a _physical_ address is passed !
343 * We only use it to pass the address and size, the other entries
344 * in the tag_videolfb are not of interest.
346 params
->hdr
.tag
= ATAG_VIDEOLFB
;
347 params
->hdr
.size
= tag_size (tag_videolfb
);
349 params
->u
.videolfb
.lfb_base
= (u32
) gd
->fb_base
;
350 /* 7168 = 256*4*56/8 - actually 2 pages (8192 bytes) are allocated */
351 params
->u
.videolfb
.lfb_size
= 7168;
353 params
= tag_next (params
);
357 static void setup_end_tag (bd_t
*bd
)
359 params
->hdr
.tag
= ATAG_NONE
;
360 params
->hdr
.size
= 0;
363 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */