blob: e96ea81527281a343a809fc46ee7a75f9f5762ae [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
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
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
169 /*
170 * Now check if we have a multifile image
171 */
172 } else if ((hdr->ih_type == IH_TYPE_MULTI) && (len_ptr[1])) {
173 ulong tail = ntohl (len_ptr[0]) % 4;
174 int i;
175
176 SHOW_BOOT_PROGRESS (13);
177
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)
182 data += 4;
183 /* add kernel length, and align */
184 data += ntohl (len_ptr[0]);
185 if (tail) {
186 data += 4 - tail;
187 }
188
189 len = ntohl (len_ptr[1]);
190
191 } else {
192 /*
193 * no initrd image
194 */
195 SHOW_BOOT_PROGRESS (14);
196
197 len = data = 0;
wdenkc6097192002-11-03 00:24:07 +0000198 }
199
wdenkc6097192002-11-03 00:24:07 +0000200#ifdef DEBUG
wdenk5779d8d2003-12-06 23:55:10 +0000201 if (!data) {
202 printf ("No initrd\n");
203 }
wdenkc6097192002-11-03 00:24:07 +0000204#endif
205
wdenk5779d8d2003-12-06 23:55:10 +0000206 if (data) {
207 initrd_start = data;
208 initrd_end = initrd_start + len;
209 } else {
210 initrd_start = 0;
211 initrd_end = 0;
212 }
wdenkc6097192002-11-03 00:24:07 +0000213
wdenk5779d8d2003-12-06 23:55:10 +0000214 SHOW_BOOT_PROGRESS (15);
wdenk384ae022002-11-05 00:17:55 +0000215
wdenk5779d8d2003-12-06 23:55:10 +0000216 debug ("## Transferring control to Linux (at address %08lx) ...\n",
217 (ulong) theKernel);
wdenkc6097192002-11-03 00:24:07 +0000218
219#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
220 defined (CONFIG_CMDLINE_TAG) || \
221 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000222 defined (CONFIG_SERIAL_TAG) || \
223 defined (CONFIG_REVISION_TAG) || \
wdenkc6097192002-11-03 00:24:07 +0000224 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000225 setup_start_tag (bd);
wdenkb6e4c402004-01-02 16:05:07 +0000226#ifdef CONFIG_SERIAL_TAG
227 setup_serial_tag (&params);
228#endif
229#ifdef CONFIG_REVISION_TAG
230 setup_revision_tag (&params);
231#endif
wdenkc6097192002-11-03 00:24:07 +0000232#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000233 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +0000234#endif
235#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000236 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +0000237#endif
238#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000239 if (initrd_start && initrd_end)
240 setup_initrd_tag (bd, initrd_start, initrd_end);
wdenkc6097192002-11-03 00:24:07 +0000241#endif
242#if defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000243 setup_videolfb_tag ((gd_t *) gd);
wdenkc6097192002-11-03 00:24:07 +0000244#endif
wdenk5779d8d2003-12-06 23:55:10 +0000245 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000246#endif
247
wdenk5779d8d2003-12-06 23:55:10 +0000248 /* we assume that the kernel is in place */
249 printf ("\nStarting kernel ...\n\n");
wdenkc6097192002-11-03 00:24:07 +0000250
wdenk5779d8d2003-12-06 23:55:10 +0000251 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000252
wdenka2663ea2003-12-07 18:32:37 +0000253 theKernel (0, bd->bi_arch_number, bd->bi_boot_params);
wdenkc6097192002-11-03 00:24:07 +0000254}
255
256
257#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
258 defined (CONFIG_CMDLINE_TAG) || \
259 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000260 defined (CONFIG_SERIAL_TAG) || \
261 defined (CONFIG_REVISION_TAG) || \
wdenkc6097192002-11-03 00:24:07 +0000262 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000263static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000264{
wdenk5779d8d2003-12-06 23:55:10 +0000265 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000266
wdenk5779d8d2003-12-06 23:55:10 +0000267 params->hdr.tag = ATAG_CORE;
268 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000269
wdenk5779d8d2003-12-06 23:55:10 +0000270 params->u.core.flags = 0;
271 params->u.core.pagesize = 0;
272 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000273
wdenk5779d8d2003-12-06 23:55:10 +0000274 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000275}
276
277
wdenk699b13a2002-11-03 18:03:52 +0000278#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000279static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000280{
wdenk5779d8d2003-12-06 23:55:10 +0000281 int i;
wdenkc6097192002-11-03 00:24:07 +0000282
wdenk5779d8d2003-12-06 23:55:10 +0000283 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
284 params->hdr.tag = ATAG_MEM;
285 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000286
wdenk5779d8d2003-12-06 23:55:10 +0000287 params->u.mem.start = bd->bi_dram[i].start;
288 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000289
wdenk5779d8d2003-12-06 23:55:10 +0000290 params = tag_next (params);
291 }
wdenkc6097192002-11-03 00:24:07 +0000292}
wdenk5779d8d2003-12-06 23:55:10 +0000293#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000294
295
wdenk5779d8d2003-12-06 23:55:10 +0000296static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000297{
wdenk5779d8d2003-12-06 23:55:10 +0000298 char *p;
wdenkc6097192002-11-03 00:24:07 +0000299
wdenk5779d8d2003-12-06 23:55:10 +0000300 /* eat leading white space */
301 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000302
wdenk5779d8d2003-12-06 23:55:10 +0000303 /* skip non-existent command lines so the kernel will still
304 * use its default command line.
305 */
306 if (*p == '\0')
307 return;
wdenkc6097192002-11-03 00:24:07 +0000308
wdenk5779d8d2003-12-06 23:55:10 +0000309 params->hdr.tag = ATAG_CMDLINE;
310 params->hdr.size =
311 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000312
wdenk5779d8d2003-12-06 23:55:10 +0000313 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000314
wdenk5779d8d2003-12-06 23:55:10 +0000315 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000316}
317
318
wdenk699b13a2002-11-03 18:03:52 +0000319#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000320static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000321{
wdenk5779d8d2003-12-06 23:55:10 +0000322 /* an ATAG_INITRD node tells the kernel where the compressed
323 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
324 */
325 params->hdr.tag = ATAG_INITRD2;
326 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000327
wdenk5779d8d2003-12-06 23:55:10 +0000328 params->u.initrd.start = initrd_start;
329 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000330
wdenk5779d8d2003-12-06 23:55:10 +0000331 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000332}
wdenk5779d8d2003-12-06 23:55:10 +0000333#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000334
335
wdenkc6097192002-11-03 00:24:07 +0000336#if defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000337static void setup_videolfb_tag (gd_t *gd)
wdenkc6097192002-11-03 00:24:07 +0000338{
wdenk5779d8d2003-12-06 23:55:10 +0000339 /* 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 !
342 *
343 * We only use it to pass the address and size, the other entries
344 * in the tag_videolfb are not of interest.
345 */
346 params->hdr.tag = ATAG_VIDEOLFB;
347 params->hdr.size = tag_size (tag_videolfb);
wdenkc6097192002-11-03 00:24:07 +0000348
wdenk5779d8d2003-12-06 23:55:10 +0000349 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;
wdenkc6097192002-11-03 00:24:07 +0000352
wdenk5779d8d2003-12-06 23:55:10 +0000353 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000354}
355#endif
356
wdenk5779d8d2003-12-06 23:55:10 +0000357static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000358{
wdenk5779d8d2003-12-06 23:55:10 +0000359 params->hdr.tag = ATAG_NONE;
360 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000361}
362
363#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */