blob: 8ba9f0c797a230e279eb2b737736158d06047a8a [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>
wdenk381669a2003-06-16 23:50:08 +000029#ifdef CONFIG_HAS_DATAFLASH
30#include <dataflash.h>
31#endif
wdenkc6097192002-11-03 00:24:07 +000032
wdenk57b2d802003-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) || \
wdenkbc01dd52004-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)
wdenk86765902003-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
wdenk86765902003-12-06 23:55:10 +000045static void setup_memory_tags (bd_t *bd);
wdenk699b13a2002-11-03 18:03:52 +000046# endif
wdenk86765902003-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
wdenk86765902003-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
wdenk86765902003-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
wdenk86765902003-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)
wdenk86765902003-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
wdenk86765902003-12-06 23:55:10 +000073extern image_header_t header; /* from cmd_bootm.c */
wdenkc6097192002-11-03 00:24:07 +000074
75
wdenk86765902003-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
wdenk86765902003-12-06 23:55:10 +000081 ulong len = 0, checksum;
82 ulong initrd_start, initrd_end;
83 ulong data;
wdenk4ea537d2003-12-07 18:32:37 +000084 void (*theKernel)(int zero, int arch, uint params);
wdenk86765902003-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
wdenk86765902003-12-06 23:55:10 +000089 char *commandline = getenv ("bootargs");
wdenkc6097192002-11-03 00:24:07 +000090#endif
91
wdenk4ea537d2003-12-07 18:32:37 +000092 theKernel = (void (*)(int, int, uint))ntohl(hdr->ih_ep);
wdenkc6097192002-11-03 00:24:07 +000093
wdenk86765902003-12-06 23:55:10 +000094 /*
95 * Check if there is an initrd image
96 */
97 if (argc >= 3) {
98 SHOW_BOOT_PROGRESS (9);
wdenk384ae022002-11-05 00:17:55 +000099
wdenk86765902003-12-06 23:55:10 +0000100 addr = simple_strtoul (argv[2], NULL, 16);
wdenkc6097192002-11-03 00:24:07 +0000101
wdenk86765902003-12-06 23:55:10 +0000102 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
wdenkc6097192002-11-03 00:24:07 +0000103
wdenk86765902003-12-06 23:55:10 +0000104 /* Copy header so we can blank CRC field for re-calculation */
wdenk381669a2003-06-16 23:50:08 +0000105#ifdef CONFIG_HAS_DATAFLASH
wdenk86765902003-12-06 23:55:10 +0000106 if (addr_dataflash (addr)) {
107 read_dataflash (addr, sizeof (image_header_t),
108 (char *) &header);
109 } else
wdenk57b2d802003-06-27 21:31:46 +0000110#endif
wdenk86765902003-12-06 23:55:10 +0000111 memcpy (&header, (char *) addr,
112 sizeof (image_header_t));
wdenkc6097192002-11-03 00:24:07 +0000113
wdenk86765902003-12-06 23:55:10 +0000114 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 }
wdenkc6097192002-11-03 00:24:07 +0000119
wdenk86765902003-12-06 23:55:10 +0000120 data = (ulong) & header;
121 len = sizeof (image_header_t);
wdenkc6097192002-11-03 00:24:07 +0000122
wdenk86765902003-12-06 23:55:10 +0000123 checksum = ntohl (hdr->ih_hcrc);
124 hdr->ih_hcrc = 0;
wdenkc6097192002-11-03 00:24:07 +0000125
wdenk86765902003-12-06 23:55:10 +0000126 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 }
wdenkc6097192002-11-03 00:24:07 +0000131
wdenk86765902003-12-06 23:55:10 +0000132 SHOW_BOOT_PROGRESS (10);
wdenk384ae022002-11-05 00:17:55 +0000133
wdenk86765902003-12-06 23:55:10 +0000134 print_image_hdr (hdr);
wdenkc6097192002-11-03 00:24:07 +0000135
wdenk86765902003-12-06 23:55:10 +0000136 data = addr + sizeof (image_header_t);
137 len = ntohl (hdr->ih_size);
wdenkc6097192002-11-03 00:24:07 +0000138
wdenk381669a2003-06-16 23:50:08 +0000139#ifdef CONFIG_HAS_DATAFLASH
wdenk86765902003-12-06 23:55:10 +0000140 if (addr_dataflash (addr)) {
141 read_dataflash (data, len, (char *) CFG_LOAD_ADDR);
142 data = CFG_LOAD_ADDR;
143 }
wdenk381669a2003-06-16 23:50:08 +0000144#endif
145
wdenk86765902003-12-06 23:55:10 +0000146 if (verify) {
147 ulong csum = 0;
wdenkc6097192002-11-03 00:24:07 +0000148
wdenk86765902003-12-06 23:55:10 +0000149 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 }
wdenkc6097192002-11-03 00:24:07 +0000158
wdenk86765902003-12-06 23:55:10 +0000159 SHOW_BOOT_PROGRESS (11);
wdenk384ae022002-11-05 00:17:55 +0000160
wdenk86765902003-12-06 23:55:10 +0000161 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 }
wdenkc6097192002-11-03 00:24:07 +0000168
wdenkb98ac282004-02-24 00:16:43 +0000169#ifdef CONFIG_B2
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);
175#endif /* CONFIG_B2 */
176
wdenk86765902003-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;
wdenkc6097192002-11-03 00:24:07 +0000183
wdenk86765902003-12-06 23:55:10 +0000184 SHOW_BOOT_PROGRESS (13);
wdenk384ae022002-11-05 00:17:55 +0000185
wdenk86765902003-12-06 23:55:10 +0000186 /* 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 }
wdenkc6097192002-11-03 00:24:07 +0000196
wdenk86765902003-12-06 23:55:10 +0000197 len = ntohl (len_ptr[1]);
wdenkc6097192002-11-03 00:24:07 +0000198
wdenk86765902003-12-06 23:55:10 +0000199 } else {
200 /*
201 * no initrd image
202 */
203 SHOW_BOOT_PROGRESS (14);
wdenk384ae022002-11-05 00:17:55 +0000204
wdenk86765902003-12-06 23:55:10 +0000205 len = data = 0;
206 }
wdenkc6097192002-11-03 00:24:07 +0000207
208#ifdef DEBUG
wdenk86765902003-12-06 23:55:10 +0000209 if (!data) {
210 printf ("No initrd\n");
211 }
wdenkc6097192002-11-03 00:24:07 +0000212#endif
213
wdenk86765902003-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
wdenk86765902003-12-06 23:55:10 +0000222 SHOW_BOOT_PROGRESS (15);
wdenk384ae022002-11-05 00:17:55 +0000223
wdenk86765902003-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) || \
wdenkbc01dd52004-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)
wdenk86765902003-12-06 23:55:10 +0000233 setup_start_tag (bd);
wdenkbc01dd52004-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
wdenk86765902003-12-06 23:55:10 +0000241 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +0000242#endif
243#ifdef CONFIG_CMDLINE_TAG
wdenk86765902003-12-06 23:55:10 +0000244 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +0000245#endif
246#ifdef CONFIG_INITRD_TAG
wdenk86765902003-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)
wdenk86765902003-12-06 23:55:10 +0000251 setup_videolfb_tag ((gd_t *) gd);
wdenkc6097192002-11-03 00:24:07 +0000252#endif
wdenk86765902003-12-06 23:55:10 +0000253 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000254#endif
255
wdenk86765902003-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
wdenk86765902003-12-06 23:55:10 +0000259 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000260
wdenk4ea537d2003-12-07 18:32:37 +0000261 theKernel (0, bd->bi_arch_number, bd->bi_boot_params);
wdenkc6097192002-11-03 00:24:07 +0000262}
263
264
265#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
266 defined (CONFIG_CMDLINE_TAG) || \
267 defined (CONFIG_INITRD_TAG) || \
wdenkbc01dd52004-01-02 16:05:07 +0000268 defined (CONFIG_SERIAL_TAG) || \
269 defined (CONFIG_REVISION_TAG) || \
wdenkc6097192002-11-03 00:24:07 +0000270 defined (CONFIG_VFD)
wdenk86765902003-12-06 23:55:10 +0000271static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000272{
wdenk86765902003-12-06 23:55:10 +0000273 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000274
wdenk86765902003-12-06 23:55:10 +0000275 params->hdr.tag = ATAG_CORE;
276 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000277
wdenk86765902003-12-06 23:55:10 +0000278 params->u.core.flags = 0;
279 params->u.core.pagesize = 0;
280 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000281
wdenk86765902003-12-06 23:55:10 +0000282 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000283}
284
285
wdenk699b13a2002-11-03 18:03:52 +0000286#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk86765902003-12-06 23:55:10 +0000287static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000288{
wdenk86765902003-12-06 23:55:10 +0000289 int i;
wdenkc6097192002-11-03 00:24:07 +0000290
wdenk86765902003-12-06 23:55:10 +0000291 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
292 params->hdr.tag = ATAG_MEM;
293 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000294
wdenk86765902003-12-06 23:55:10 +0000295 params->u.mem.start = bd->bi_dram[i].start;
296 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000297
wdenk86765902003-12-06 23:55:10 +0000298 params = tag_next (params);
299 }
wdenkc6097192002-11-03 00:24:07 +0000300}
wdenk86765902003-12-06 23:55:10 +0000301#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000302
303
wdenk86765902003-12-06 23:55:10 +0000304static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000305{
wdenk86765902003-12-06 23:55:10 +0000306 char *p;
wdenkc6097192002-11-03 00:24:07 +0000307
wdenk86765902003-12-06 23:55:10 +0000308 /* eat leading white space */
309 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000310
wdenk86765902003-12-06 23:55:10 +0000311 /* skip non-existent command lines so the kernel will still
312 * use its default command line.
313 */
314 if (*p == '\0')
315 return;
wdenkc6097192002-11-03 00:24:07 +0000316
wdenk86765902003-12-06 23:55:10 +0000317 params->hdr.tag = ATAG_CMDLINE;
318 params->hdr.size =
319 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000320
wdenk86765902003-12-06 23:55:10 +0000321 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000322
wdenk86765902003-12-06 23:55:10 +0000323 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000324}
325
326
wdenk699b13a2002-11-03 18:03:52 +0000327#ifdef CONFIG_INITRD_TAG
wdenk86765902003-12-06 23:55:10 +0000328static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000329{
wdenk86765902003-12-06 23:55:10 +0000330 /* an ATAG_INITRD node tells the kernel where the compressed
331 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
332 */
wdenkb98ac282004-02-24 00:16:43 +0000333 params->hdr.tag = ATAG_INITRD;
wdenk86765902003-12-06 23:55:10 +0000334 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000335
wdenk86765902003-12-06 23:55:10 +0000336 params->u.initrd.start = initrd_start;
337 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000338
wdenk86765902003-12-06 23:55:10 +0000339 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000340}
wdenk86765902003-12-06 23:55:10 +0000341#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000342
wdenkc6097192002-11-03 00:24:07 +0000343
344#if defined (CONFIG_VFD)
wdenk86765902003-12-06 23:55:10 +0000345static void setup_videolfb_tag (gd_t *gd)
wdenkc6097192002-11-03 00:24:07 +0000346{
wdenk86765902003-12-06 23:55:10 +0000347 /* An ATAG_VIDEOLFB node tells the kernel where and how large
348 * the framebuffer for video was allocated (among other things).
349 * Note that a _physical_ address is passed !
350 *
351 * We only use it to pass the address and size, the other entries
352 * in the tag_videolfb are not of interest.
353 */
354 params->hdr.tag = ATAG_VIDEOLFB;
355 params->hdr.size = tag_size (tag_videolfb);
wdenkc6097192002-11-03 00:24:07 +0000356
wdenk86765902003-12-06 23:55:10 +0000357 params->u.videolfb.lfb_base = (u32) gd->fb_base;
358 /* 7168 = 256*4*56/8 - actually 2 pages (8192 bytes) are allocated */
359 params->u.videolfb.lfb_size = 7168;
wdenkc6097192002-11-03 00:24:07 +0000360
wdenk86765902003-12-06 23:55:10 +0000361 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000362}
363#endif
364
wdenk86765902003-12-06 23:55:10 +0000365static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000366{
wdenk86765902003-12-06 23:55:10 +0000367 params->hdr.tag = ATAG_NONE;
368 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000369}
370
371#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */