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