blob: 6d32a411fdee5acf4e78f085a3987f19c8d770eb [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
Wolfgang Denkd87080b2006-03-31 18:32:53 +020033DECLARE_GLOBAL_DATA_PTR;
34
wdenk8bde7f72003-06-27 21:31:46 +000035/*cmd_boot.c*/
36extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
37
wdenkc6097192002-11-03 00:24:07 +000038#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
39 defined (CONFIG_CMDLINE_TAG) || \
40 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +000041 defined (CONFIG_SERIAL_TAG) || \
42 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +000043 defined (CONFIG_VFD) || \
44 defined (CONFIG_LCD)
wdenk5779d8d2003-12-06 23:55:10 +000045static void setup_start_tag (bd_t *bd);
46
wdenk699b13a2002-11-03 18:03:52 +000047# ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +000048static void setup_memory_tags (bd_t *bd);
wdenk699b13a2002-11-03 18:03:52 +000049# endif
wdenk5779d8d2003-12-06 23:55:10 +000050static void setup_commandline_tag (bd_t *bd, char *commandline);
51
wdenkc6097192002-11-03 00:24:07 +000052#if 0
wdenk5779d8d2003-12-06 23:55:10 +000053static void setup_ramdisk_tag (bd_t *bd);
wdenkc6097192002-11-03 00:24:07 +000054#endif
wdenk699b13a2002-11-03 18:03:52 +000055# ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +000056static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
57 ulong initrd_end);
wdenk699b13a2002-11-03 18:03:52 +000058# endif
wdenk5779d8d2003-12-06 23:55:10 +000059static void setup_end_tag (bd_t *bd);
60
wdenk8655b6f2004-10-09 23:25:58 +000061# if defined (CONFIG_VFD) || defined (CONFIG_LCD)
wdenk5779d8d2003-12-06 23:55:10 +000062static void setup_videolfb_tag (gd_t *gd);
wdenk699b13a2002-11-03 18:03:52 +000063# endif
wdenkc6097192002-11-03 00:24:07 +000064
65
66static struct tag *params;
67#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
68
wdenk5779d8d2003-12-06 23:55:10 +000069extern image_header_t header; /* from cmd_bootm.c */
wdenkc6097192002-11-03 00:24:07 +000070
71
wdenk5779d8d2003-12-06 23:55:10 +000072void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
73 ulong addr, ulong *len_ptr, int verify)
wdenkc6097192002-11-03 00:24:07 +000074{
wdenk5779d8d2003-12-06 23:55:10 +000075 ulong len = 0, checksum;
76 ulong initrd_start, initrd_end;
77 ulong data;
wdenka2663ea2003-12-07 18:32:37 +000078 void (*theKernel)(int zero, int arch, uint params);
wdenk5779d8d2003-12-06 23:55:10 +000079 image_header_t *hdr = &header;
80 bd_t *bd = gd->bd;
81
wdenkc6097192002-11-03 00:24:07 +000082#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +000083 char *commandline = getenv ("bootargs");
wdenkc6097192002-11-03 00:24:07 +000084#endif
85
wdenka2663ea2003-12-07 18:32:37 +000086 theKernel = (void (*)(int, int, uint))ntohl(hdr->ih_ep);
wdenkc6097192002-11-03 00:24:07 +000087
88 /*
wdenk5779d8d2003-12-06 23:55:10 +000089 * Check if there is an initrd image
wdenkc6097192002-11-03 00:24:07 +000090 */
wdenk5779d8d2003-12-06 23:55:10 +000091 if (argc >= 3) {
Heiko Schocherfad63402007-07-13 09:54:17 +020092 show_boot_progress (9);
wdenkc6097192002-11-03 00:24:07 +000093
wdenk5779d8d2003-12-06 23:55:10 +000094 addr = simple_strtoul (argv[2], NULL, 16);
wdenk384ae022002-11-05 00:17:55 +000095
wdenk5779d8d2003-12-06 23:55:10 +000096 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
97
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),
102 (char *) &header);
103 } else
104#endif
105 memcpy (&header, (char *) addr,
106 sizeof (image_header_t));
107
108 if (ntohl (hdr->ih_magic) != IH_MAGIC) {
109 printf ("Bad Magic Number\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200110 show_boot_progress (-10);
wdenk5779d8d2003-12-06 23:55:10 +0000111 do_reset (cmdtp, flag, argc, argv);
112 }
113
114 data = (ulong) & header;
115 len = sizeof (image_header_t);
116
117 checksum = ntohl (hdr->ih_hcrc);
118 hdr->ih_hcrc = 0;
119
Wolfgang Denkd52fb7e2006-03-11 22:53:33 +0100120 if (crc32 (0, (unsigned char *) data, len) != checksum) {
wdenk5779d8d2003-12-06 23:55:10 +0000121 printf ("Bad Header Checksum\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200122 show_boot_progress (-11);
wdenk5779d8d2003-12-06 23:55:10 +0000123 do_reset (cmdtp, flag, argc, argv);
124 }
125
Heiko Schocherfad63402007-07-13 09:54:17 +0200126 show_boot_progress (10);
wdenk5779d8d2003-12-06 23:55:10 +0000127
128 print_image_hdr (hdr);
129
130 data = addr + sizeof (image_header_t);
131 len = ntohl (hdr->ih_size);
132
133#ifdef CONFIG_HAS_DATAFLASH
134 if (addr_dataflash (addr)) {
135 read_dataflash (data, len, (char *) CFG_LOAD_ADDR);
136 data = CFG_LOAD_ADDR;
137 }
138#endif
139
140 if (verify) {
141 ulong csum = 0;
142
143 printf (" Verifying Checksum ... ");
Wolfgang Denkd52fb7e2006-03-11 22:53:33 +0100144 csum = crc32 (0, (unsigned char *) data, len);
wdenk5779d8d2003-12-06 23:55:10 +0000145 if (csum != ntohl (hdr->ih_dcrc)) {
146 printf ("Bad Data CRC\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200147 show_boot_progress (-12);
wdenk5779d8d2003-12-06 23:55:10 +0000148 do_reset (cmdtp, flag, argc, argv);
149 }
150 printf ("OK\n");
151 }
152
Heiko Schocherfad63402007-07-13 09:54:17 +0200153 show_boot_progress (11);
wdenk5779d8d2003-12-06 23:55:10 +0000154
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");
Heiko Schocherfad63402007-07-13 09:54:17 +0200159 show_boot_progress (-13);
wdenk5779d8d2003-12-06 23:55:10 +0000160 do_reset (cmdtp, flag, argc, argv);
161 }
162
Wolfgang Denkc570b2f2005-09-26 01:06:33 +0200163#if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
wdenk074cff02004-02-24 00:16:43 +0000164 /*
165 *we need to copy the ramdisk to SRAM to let Linux boot
166 */
167 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
168 data = ntohl(hdr->ih_load);
wdenka1f4a3d2004-07-11 22:19:26 +0000169#endif /* CONFIG_B2 || CONFIG_EVB4510 */
wdenk074cff02004-02-24 00:16:43 +0000170
wdenk5779d8d2003-12-06 23:55:10 +0000171 /*
172 * Now check if we have a multifile image
173 */
174 } else if ((hdr->ih_type == IH_TYPE_MULTI) && (len_ptr[1])) {
175 ulong tail = ntohl (len_ptr[0]) % 4;
176 int i;
177
Heiko Schocherfad63402007-07-13 09:54:17 +0200178 show_boot_progress (13);
wdenk5779d8d2003-12-06 23:55:10 +0000179
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)
184 data += 4;
185 /* add kernel length, and align */
186 data += ntohl (len_ptr[0]);
187 if (tail) {
188 data += 4 - tail;
189 }
190
191 len = ntohl (len_ptr[1]);
192
193 } else {
194 /*
195 * no initrd image
196 */
Heiko Schocherfad63402007-07-13 09:54:17 +0200197 show_boot_progress (14);
wdenk5779d8d2003-12-06 23:55:10 +0000198
199 len = data = 0;
wdenkc6097192002-11-03 00:24:07 +0000200 }
201
wdenkc6097192002-11-03 00:24:07 +0000202#ifdef DEBUG
wdenk5779d8d2003-12-06 23:55:10 +0000203 if (!data) {
204 printf ("No initrd\n");
205 }
wdenkc6097192002-11-03 00:24:07 +0000206#endif
207
wdenk5779d8d2003-12-06 23:55:10 +0000208 if (data) {
209 initrd_start = data;
210 initrd_end = initrd_start + len;
211 } else {
212 initrd_start = 0;
213 initrd_end = 0;
214 }
wdenkc6097192002-11-03 00:24:07 +0000215
Heiko Schocherfad63402007-07-13 09:54:17 +0200216 show_boot_progress (15);
wdenk384ae022002-11-05 00:17:55 +0000217
wdenk5779d8d2003-12-06 23:55:10 +0000218 debug ("## Transferring control to Linux (at address %08lx) ...\n",
219 (ulong) theKernel);
wdenkc6097192002-11-03 00:24:07 +0000220
221#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
222 defined (CONFIG_CMDLINE_TAG) || \
223 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000224 defined (CONFIG_SERIAL_TAG) || \
225 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +0000226 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +0000227 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000228 setup_start_tag (bd);
wdenkb6e4c402004-01-02 16:05:07 +0000229#ifdef CONFIG_SERIAL_TAG
230 setup_serial_tag (&params);
231#endif
232#ifdef CONFIG_REVISION_TAG
233 setup_revision_tag (&params);
234#endif
wdenkc6097192002-11-03 00:24:07 +0000235#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000236 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +0000237#endif
238#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000239 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +0000240#endif
241#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000242 if (initrd_start && initrd_end)
243 setup_initrd_tag (bd, initrd_start, initrd_end);
wdenkc6097192002-11-03 00:24:07 +0000244#endif
wdenk8655b6f2004-10-09 23:25:58 +0000245#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
wdenk5779d8d2003-12-06 23:55:10 +0000246 setup_videolfb_tag ((gd_t *) gd);
wdenkc6097192002-11-03 00:24:07 +0000247#endif
wdenk5779d8d2003-12-06 23:55:10 +0000248 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000249#endif
250
wdenk5779d8d2003-12-06 23:55:10 +0000251 /* we assume that the kernel is in place */
252 printf ("\nStarting kernel ...\n\n");
wdenkc6097192002-11-03 00:24:07 +0000253
wdenk232c1502004-03-12 00:14:09 +0000254#ifdef CONFIG_USB_DEVICE
255 {
256 extern void udc_disconnect (void);
257 udc_disconnect ();
258 }
259#endif
260
wdenk5779d8d2003-12-06 23:55:10 +0000261 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000262
wdenka2663ea2003-12-07 18:32:37 +0000263 theKernel (0, bd->bi_arch_number, bd->bi_boot_params);
wdenkc6097192002-11-03 00:24:07 +0000264}
265
266
267#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
268 defined (CONFIG_CMDLINE_TAG) || \
269 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000270 defined (CONFIG_SERIAL_TAG) || \
271 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +0000272 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +0000273 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000274static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000275{
wdenk5779d8d2003-12-06 23:55:10 +0000276 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000277
wdenk5779d8d2003-12-06 23:55:10 +0000278 params->hdr.tag = ATAG_CORE;
279 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000280
wdenk5779d8d2003-12-06 23:55:10 +0000281 params->u.core.flags = 0;
282 params->u.core.pagesize = 0;
283 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000284
wdenk5779d8d2003-12-06 23:55:10 +0000285 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000286}
287
288
wdenk699b13a2002-11-03 18:03:52 +0000289#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000290static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000291{
wdenk5779d8d2003-12-06 23:55:10 +0000292 int i;
wdenkc6097192002-11-03 00:24:07 +0000293
wdenk5779d8d2003-12-06 23:55:10 +0000294 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
295 params->hdr.tag = ATAG_MEM;
296 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000297
wdenk5779d8d2003-12-06 23:55:10 +0000298 params->u.mem.start = bd->bi_dram[i].start;
299 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000300
wdenk5779d8d2003-12-06 23:55:10 +0000301 params = tag_next (params);
302 }
wdenkc6097192002-11-03 00:24:07 +0000303}
wdenk5779d8d2003-12-06 23:55:10 +0000304#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000305
306
wdenk5779d8d2003-12-06 23:55:10 +0000307static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000308{
wdenk5779d8d2003-12-06 23:55:10 +0000309 char *p;
wdenkc6097192002-11-03 00:24:07 +0000310
wdenk109c0e32004-03-23 21:43:07 +0000311 if (!commandline)
312 return;
313
wdenk5779d8d2003-12-06 23:55:10 +0000314 /* eat leading white space */
315 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000316
wdenk5779d8d2003-12-06 23:55:10 +0000317 /* skip non-existent command lines so the kernel will still
318 * use its default command line.
319 */
320 if (*p == '\0')
321 return;
wdenkc6097192002-11-03 00:24:07 +0000322
wdenk5779d8d2003-12-06 23:55:10 +0000323 params->hdr.tag = ATAG_CMDLINE;
324 params->hdr.size =
325 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000326
wdenk5779d8d2003-12-06 23:55:10 +0000327 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000328
wdenk5779d8d2003-12-06 23:55:10 +0000329 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000330}
331
332
wdenk699b13a2002-11-03 18:03:52 +0000333#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000334static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000335{
wdenk5779d8d2003-12-06 23:55:10 +0000336 /* an ATAG_INITRD node tells the kernel where the compressed
337 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
338 */
wdenk498b8db2004-04-18 22:26:17 +0000339 params->hdr.tag = ATAG_INITRD2;
wdenk5779d8d2003-12-06 23:55:10 +0000340 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000341
wdenk5779d8d2003-12-06 23:55:10 +0000342 params->u.initrd.start = initrd_start;
343 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000344
wdenk5779d8d2003-12-06 23:55:10 +0000345 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000346}
wdenk5779d8d2003-12-06 23:55:10 +0000347#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000348
349
wdenk8655b6f2004-10-09 23:25:58 +0000350#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
351extern ulong calc_fbsize (void);
wdenk5779d8d2003-12-06 23:55:10 +0000352static void setup_videolfb_tag (gd_t *gd)
wdenkc6097192002-11-03 00:24:07 +0000353{
wdenk5779d8d2003-12-06 23:55:10 +0000354 /* 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 !
357 *
358 * We only use it to pass the address and size, the other entries
359 * in the tag_videolfb are not of interest.
360 */
361 params->hdr.tag = ATAG_VIDEOLFB;
362 params->hdr.size = tag_size (tag_videolfb);
wdenkc6097192002-11-03 00:24:07 +0000363
wdenk5779d8d2003-12-06 23:55:10 +0000364 params->u.videolfb.lfb_base = (u32) gd->fb_base;
wdenk8655b6f2004-10-09 23:25:58 +0000365 /* Fb size is calculated according to parameters for our panel
366 */
367 params->u.videolfb.lfb_size = calc_fbsize();
wdenkc6097192002-11-03 00:24:07 +0000368
wdenk5779d8d2003-12-06 23:55:10 +0000369 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000370}
wdenk8655b6f2004-10-09 23:25:58 +0000371#endif /* CONFIG_VFD || CONFIG_LCD */
wdenkc6097192002-11-03 00:24:07 +0000372
wdenk3a574cb2005-05-19 22:39:42 +0000373#ifdef CONFIG_SERIAL_TAG
374void setup_serial_tag (struct tag **tmp)
375{
376 struct tag *params = *tmp;
377 struct tag_serialnr serialnr;
378 void get_board_serial(struct tag_serialnr *serialnr);
379
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);
386 *tmp = params;
387}
388#endif
389
wdenk289f9322005-01-12 00:15:14 +0000390#ifdef CONFIG_REVISION_TAG
391void setup_revision_tag(struct tag **in_params)
392{
393 u32 rev = 0;
wdenk289f9322005-01-12 00:15:14 +0000394 u32 get_board_rev(void);
395
396 rev = get_board_rev();
wdenk289f9322005-01-12 00:15:14 +0000397 params->hdr.tag = ATAG_REVISION;
398 params->hdr.size = tag_size (tag_revision);
399 params->u.revision.rev = rev;
400 params = tag_next (params);
401}
402#endif /* CONFIG_REVISION_TAG */
403
404
wdenk5779d8d2003-12-06 23:55:10 +0000405static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000406{
wdenk5779d8d2003-12-06 23:55:10 +0000407 params->hdr.tag = ATAG_NONE;
408 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000409}
410
411#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */