blob: 6855d5f9494cf393310d59fd7e3f63efb6ea23fe [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
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
wdenk232c1502004-03-12 00:14:09 +000015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenkc6097192002-11-03 00:24:07 +000016 * 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
wdenk232c1502004-03-12 00:14:09 +000020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
wdenkc6097192002-11-03 00:24:07 +000021 *
22 */
23
24#include <common.h>
25#include <command.h>
wdenkc6097192002-11-03 00:24:07 +000026#include <image.h>
27#include <zlib.h>
28#include <asm/byteorder.h>
wdenk2abbe072003-06-16 23:50:08 +000029#ifdef CONFIG_HAS_DATAFLASH
30#include <dataflash.h>
31#endif
wdenkc6097192002-11-03 00:24:07 +000032
wdenk8bde7f72003-06-27 21:31:46 +000033/*cmd_boot.c*/
34extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
35
wdenkc6097192002-11-03 00:24:07 +000036#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
37 defined (CONFIG_CMDLINE_TAG) || \
38 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +000039 defined (CONFIG_SERIAL_TAG) || \
40 defined (CONFIG_REVISION_TAG) || \
wdenkc6097192002-11-03 00:24:07 +000041 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +000042static void setup_start_tag (bd_t *bd);
43
wdenk699b13a2002-11-03 18:03:52 +000044# ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +000045static void setup_memory_tags (bd_t *bd);
wdenk699b13a2002-11-03 18:03:52 +000046# endif
wdenk5779d8d2003-12-06 23:55:10 +000047static void setup_commandline_tag (bd_t *bd, char *commandline);
48
wdenkc6097192002-11-03 00:24:07 +000049#if 0
wdenk5779d8d2003-12-06 23:55:10 +000050static void setup_ramdisk_tag (bd_t *bd);
wdenkc6097192002-11-03 00:24:07 +000051#endif
wdenk699b13a2002-11-03 18:03:52 +000052# ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +000053static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
54 ulong initrd_end);
wdenk699b13a2002-11-03 18:03:52 +000055# endif
wdenk5779d8d2003-12-06 23:55:10 +000056static void setup_end_tag (bd_t *bd);
57
wdenk699b13a2002-11-03 18:03:52 +000058# if defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +000059static void setup_videolfb_tag (gd_t *gd);
wdenk699b13a2002-11-03 18:03:52 +000060# endif
wdenkc6097192002-11-03 00:24:07 +000061
62
63static struct tag *params;
64#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
65
wdenk384ae022002-11-05 00:17:55 +000066#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
wdenk5779d8d2003-12-06 23:55:10 +000073extern image_header_t header; /* from cmd_bootm.c */
wdenkc6097192002-11-03 00:24:07 +000074
75
wdenk5779d8d2003-12-06 23:55:10 +000076void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
77 ulong addr, ulong *len_ptr, int verify)
wdenkc6097192002-11-03 00:24:07 +000078{
79 DECLARE_GLOBAL_DATA_PTR;
80
wdenk5779d8d2003-12-06 23:55:10 +000081 ulong len = 0, checksum;
82 ulong initrd_start, initrd_end;
83 ulong data;
wdenka2663ea2003-12-07 18:32:37 +000084 void (*theKernel)(int zero, int arch, uint params);
wdenk5779d8d2003-12-06 23:55:10 +000085 image_header_t *hdr = &header;
86 bd_t *bd = gd->bd;
87
wdenkc6097192002-11-03 00:24:07 +000088#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +000089 char *commandline = getenv ("bootargs");
wdenkc6097192002-11-03 00:24:07 +000090#endif
91
wdenka2663ea2003-12-07 18:32:37 +000092 theKernel = (void (*)(int, int, uint))ntohl(hdr->ih_ep);
wdenkc6097192002-11-03 00:24:07 +000093
94 /*
wdenk5779d8d2003-12-06 23:55:10 +000095 * Check if there is an initrd image
wdenkc6097192002-11-03 00:24:07 +000096 */
wdenk5779d8d2003-12-06 23:55:10 +000097 if (argc >= 3) {
98 SHOW_BOOT_PROGRESS (9);
wdenkc6097192002-11-03 00:24:07 +000099
wdenk5779d8d2003-12-06 23:55:10 +0000100 addr = simple_strtoul (argv[2], NULL, 16);
wdenk384ae022002-11-05 00:17:55 +0000101
wdenk5779d8d2003-12-06 23:55:10 +0000102 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
103
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),
108 (char *) &header);
109 } else
110#endif
111 memcpy (&header, (char *) addr,
112 sizeof (image_header_t));
113
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 }
119
120 data = (ulong) & header;
121 len = sizeof (image_header_t);
122
123 checksum = ntohl (hdr->ih_hcrc);
124 hdr->ih_hcrc = 0;
125
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 }
131
132 SHOW_BOOT_PROGRESS (10);
133
134 print_image_hdr (hdr);
135
136 data = addr + sizeof (image_header_t);
137 len = ntohl (hdr->ih_size);
138
139#ifdef CONFIG_HAS_DATAFLASH
140 if (addr_dataflash (addr)) {
141 read_dataflash (data, len, (char *) CFG_LOAD_ADDR);
142 data = CFG_LOAD_ADDR;
143 }
144#endif
145
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
wdenka1f4a3d2004-07-11 22:19:26 +0000169#if defined(CONFIG_B2) || defined(CONFIG_EVB4510)
wdenk074cff02004-02-24 00:16:43 +0000170 /*
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);
wdenka1f4a3d2004-07-11 22:19:26 +0000175#endif /* CONFIG_B2 || CONFIG_EVB4510 */
wdenk074cff02004-02-24 00:16:43 +0000176
wdenk5779d8d2003-12-06 23:55:10 +0000177 /*
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;
wdenkc6097192002-11-03 00:24:07 +0000206 }
207
wdenkc6097192002-11-03 00:24:07 +0000208#ifdef DEBUG
wdenk5779d8d2003-12-06 23:55:10 +0000209 if (!data) {
210 printf ("No initrd\n");
211 }
wdenkc6097192002-11-03 00:24:07 +0000212#endif
213
wdenk5779d8d2003-12-06 23:55:10 +0000214 if (data) {
215 initrd_start = data;
216 initrd_end = initrd_start + len;
217 } else {
218 initrd_start = 0;
219 initrd_end = 0;
220 }
wdenkc6097192002-11-03 00:24:07 +0000221
wdenk5779d8d2003-12-06 23:55:10 +0000222 SHOW_BOOT_PROGRESS (15);
wdenk384ae022002-11-05 00:17:55 +0000223
wdenk5779d8d2003-12-06 23:55:10 +0000224 debug ("## Transferring control to Linux (at address %08lx) ...\n",
225 (ulong) theKernel);
wdenkc6097192002-11-03 00:24:07 +0000226
227#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
228 defined (CONFIG_CMDLINE_TAG) || \
229 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000230 defined (CONFIG_SERIAL_TAG) || \
231 defined (CONFIG_REVISION_TAG) || \
wdenkc6097192002-11-03 00:24:07 +0000232 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000233 setup_start_tag (bd);
wdenkb6e4c402004-01-02 16:05:07 +0000234#ifdef CONFIG_SERIAL_TAG
235 setup_serial_tag (&params);
236#endif
237#ifdef CONFIG_REVISION_TAG
238 setup_revision_tag (&params);
239#endif
wdenkc6097192002-11-03 00:24:07 +0000240#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000241 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +0000242#endif
243#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000244 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +0000245#endif
246#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000247 if (initrd_start && initrd_end)
248 setup_initrd_tag (bd, initrd_start, initrd_end);
wdenkc6097192002-11-03 00:24:07 +0000249#endif
250#if defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000251 setup_videolfb_tag ((gd_t *) gd);
wdenkc6097192002-11-03 00:24:07 +0000252#endif
wdenk5779d8d2003-12-06 23:55:10 +0000253 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000254#endif
255
wdenk5779d8d2003-12-06 23:55:10 +0000256 /* we assume that the kernel is in place */
257 printf ("\nStarting kernel ...\n\n");
wdenkc6097192002-11-03 00:24:07 +0000258
wdenk232c1502004-03-12 00:14:09 +0000259#ifdef CONFIG_USB_DEVICE
260 {
261 extern void udc_disconnect (void);
262 udc_disconnect ();
263 }
264#endif
265
wdenk5779d8d2003-12-06 23:55:10 +0000266 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000267
wdenka2663ea2003-12-07 18:32:37 +0000268 theKernel (0, bd->bi_arch_number, bd->bi_boot_params);
wdenkc6097192002-11-03 00:24:07 +0000269}
270
271
272#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
273 defined (CONFIG_CMDLINE_TAG) || \
274 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000275 defined (CONFIG_SERIAL_TAG) || \
276 defined (CONFIG_REVISION_TAG) || \
wdenkc6097192002-11-03 00:24:07 +0000277 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000278static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000279{
wdenk5779d8d2003-12-06 23:55:10 +0000280 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000281
wdenk5779d8d2003-12-06 23:55:10 +0000282 params->hdr.tag = ATAG_CORE;
283 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000284
wdenk5779d8d2003-12-06 23:55:10 +0000285 params->u.core.flags = 0;
286 params->u.core.pagesize = 0;
287 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000288
wdenk5779d8d2003-12-06 23:55:10 +0000289 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000290}
291
292
wdenk699b13a2002-11-03 18:03:52 +0000293#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000294static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000295{
wdenk5779d8d2003-12-06 23:55:10 +0000296 int i;
wdenkc6097192002-11-03 00:24:07 +0000297
wdenk5779d8d2003-12-06 23:55:10 +0000298 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
299 params->hdr.tag = ATAG_MEM;
300 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000301
wdenk5779d8d2003-12-06 23:55:10 +0000302 params->u.mem.start = bd->bi_dram[i].start;
303 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000304
wdenk5779d8d2003-12-06 23:55:10 +0000305 params = tag_next (params);
306 }
wdenkc6097192002-11-03 00:24:07 +0000307}
wdenk5779d8d2003-12-06 23:55:10 +0000308#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000309
310
wdenk5779d8d2003-12-06 23:55:10 +0000311static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000312{
wdenk5779d8d2003-12-06 23:55:10 +0000313 char *p;
wdenkc6097192002-11-03 00:24:07 +0000314
wdenk109c0e32004-03-23 21:43:07 +0000315 if (!commandline)
316 return;
317
wdenk5779d8d2003-12-06 23:55:10 +0000318 /* eat leading white space */
319 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000320
wdenk5779d8d2003-12-06 23:55:10 +0000321 /* skip non-existent command lines so the kernel will still
322 * use its default command line.
323 */
324 if (*p == '\0')
325 return;
wdenkc6097192002-11-03 00:24:07 +0000326
wdenk5779d8d2003-12-06 23:55:10 +0000327 params->hdr.tag = ATAG_CMDLINE;
328 params->hdr.size =
329 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000330
wdenk5779d8d2003-12-06 23:55:10 +0000331 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000332
wdenk5779d8d2003-12-06 23:55:10 +0000333 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000334}
335
336
wdenk699b13a2002-11-03 18:03:52 +0000337#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000338static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000339{
wdenk5779d8d2003-12-06 23:55:10 +0000340 /* an ATAG_INITRD node tells the kernel where the compressed
341 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
342 */
wdenk498b8db2004-04-18 22:26:17 +0000343 params->hdr.tag = ATAG_INITRD2;
wdenk5779d8d2003-12-06 23:55:10 +0000344 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000345
wdenk5779d8d2003-12-06 23:55:10 +0000346 params->u.initrd.start = initrd_start;
347 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000348
wdenk5779d8d2003-12-06 23:55:10 +0000349 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000350}
wdenk5779d8d2003-12-06 23:55:10 +0000351#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000352
353
wdenkc6097192002-11-03 00:24:07 +0000354#if defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000355static void setup_videolfb_tag (gd_t *gd)
wdenkc6097192002-11-03 00:24:07 +0000356{
wdenk5779d8d2003-12-06 23:55:10 +0000357 /* 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);
wdenkc6097192002-11-03 00:24:07 +0000366
wdenk5779d8d2003-12-06 23:55:10 +0000367 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;
wdenkc6097192002-11-03 00:24:07 +0000370
wdenk5779d8d2003-12-06 23:55:10 +0000371 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000372}
373#endif
374
wdenk5779d8d2003-12-06 23:55:10 +0000375static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000376{
wdenk5779d8d2003-12-06 23:55:10 +0000377 params->hdr.tag = ATAG_NONE;
378 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000379}
380
381#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */