blob: 0b3d01e12fc3034b606d77f7fe82c2f87378a002 [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
33#include <asm/setup.h>
34#define tag_size(type) ((sizeof(struct tag_header) + sizeof(struct type)) >> 2)
35#define tag_next(t) ((struct tag *)((u32 *)(t) + (t)->hdr.size))
36
wdenk8bde7f72003-06-27 21:31:46 +000037/*cmd_boot.c*/
38extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
39
wdenkc6097192002-11-03 00:24:07 +000040#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
41 defined (CONFIG_CMDLINE_TAG) || \
42 defined (CONFIG_INITRD_TAG) || \
43 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +000044static void setup_start_tag (bd_t *bd);
45
wdenk699b13a2002-11-03 18:03:52 +000046# ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +000047static void setup_memory_tags (bd_t *bd);
wdenk699b13a2002-11-03 18:03:52 +000048# endif
wdenk5779d8d2003-12-06 23:55:10 +000049static void setup_commandline_tag (bd_t *bd, char *commandline);
50
wdenkc6097192002-11-03 00:24:07 +000051#if 0
wdenk5779d8d2003-12-06 23:55:10 +000052static void setup_ramdisk_tag (bd_t *bd);
wdenkc6097192002-11-03 00:24:07 +000053#endif
wdenk699b13a2002-11-03 18:03:52 +000054# ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +000055static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
56 ulong initrd_end);
wdenk699b13a2002-11-03 18:03:52 +000057# endif
wdenk5779d8d2003-12-06 23:55:10 +000058static void setup_end_tag (bd_t *bd);
59
wdenk699b13a2002-11-03 18:03:52 +000060# if defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +000061static void setup_videolfb_tag (gd_t *gd);
wdenk699b13a2002-11-03 18:03:52 +000062# endif
wdenkc6097192002-11-03 00:24:07 +000063
64
65static struct tag *params;
66#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
67
wdenk384ae022002-11-05 00:17:55 +000068#ifdef CONFIG_SHOW_BOOT_PROGRESS
69# include <status_led.h>
70# define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
71#else
72# define SHOW_BOOT_PROGRESS(arg)
73#endif
74
wdenk5779d8d2003-12-06 23:55:10 +000075extern image_header_t header; /* from cmd_bootm.c */
wdenkc6097192002-11-03 00:24:07 +000076
77
wdenk5779d8d2003-12-06 23:55:10 +000078void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
79 ulong addr, ulong *len_ptr, int verify)
wdenkc6097192002-11-03 00:24:07 +000080{
81 DECLARE_GLOBAL_DATA_PTR;
82
wdenk5779d8d2003-12-06 23:55:10 +000083 ulong len = 0, checksum;
84 ulong initrd_start, initrd_end;
85 ulong data;
86 void (*theKernel) (int zero, int arch);
87 image_header_t *hdr = &header;
88 bd_t *bd = gd->bd;
89
wdenkc6097192002-11-03 00:24:07 +000090#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +000091 char *commandline = getenv ("bootargs");
wdenkc6097192002-11-03 00:24:07 +000092#endif
93
wdenk5779d8d2003-12-06 23:55:10 +000094 theKernel = (void (*)(int, int)) ntohl (hdr->ih_ep);
wdenkc6097192002-11-03 00:24:07 +000095
96 /*
wdenk5779d8d2003-12-06 23:55:10 +000097 * Check if there is an initrd image
wdenkc6097192002-11-03 00:24:07 +000098 */
wdenk5779d8d2003-12-06 23:55:10 +000099 if (argc >= 3) {
100 SHOW_BOOT_PROGRESS (9);
wdenkc6097192002-11-03 00:24:07 +0000101
wdenk5779d8d2003-12-06 23:55:10 +0000102 addr = simple_strtoul (argv[2], NULL, 16);
wdenk384ae022002-11-05 00:17:55 +0000103
wdenk5779d8d2003-12-06 23:55:10 +0000104 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
105
106 /* Copy header so we can blank CRC field for re-calculation */
107#ifdef CONFIG_HAS_DATAFLASH
108 if (addr_dataflash (addr)) {
109 read_dataflash (addr, sizeof (image_header_t),
110 (char *) &header);
111 } else
112#endif
113 memcpy (&header, (char *) addr,
114 sizeof (image_header_t));
115
116 if (ntohl (hdr->ih_magic) != IH_MAGIC) {
117 printf ("Bad Magic Number\n");
118 SHOW_BOOT_PROGRESS (-10);
119 do_reset (cmdtp, flag, argc, argv);
120 }
121
122 data = (ulong) & header;
123 len = sizeof (image_header_t);
124
125 checksum = ntohl (hdr->ih_hcrc);
126 hdr->ih_hcrc = 0;
127
128 if (crc32 (0, (char *) data, len) != checksum) {
129 printf ("Bad Header Checksum\n");
130 SHOW_BOOT_PROGRESS (-11);
131 do_reset (cmdtp, flag, argc, argv);
132 }
133
134 SHOW_BOOT_PROGRESS (10);
135
136 print_image_hdr (hdr);
137
138 data = addr + sizeof (image_header_t);
139 len = ntohl (hdr->ih_size);
140
141#ifdef CONFIG_HAS_DATAFLASH
142 if (addr_dataflash (addr)) {
143 read_dataflash (data, len, (char *) CFG_LOAD_ADDR);
144 data = CFG_LOAD_ADDR;
145 }
146#endif
147
148 if (verify) {
149 ulong csum = 0;
150
151 printf (" Verifying Checksum ... ");
152 csum = crc32 (0, (char *) data, len);
153 if (csum != ntohl (hdr->ih_dcrc)) {
154 printf ("Bad Data CRC\n");
155 SHOW_BOOT_PROGRESS (-12);
156 do_reset (cmdtp, flag, argc, argv);
157 }
158 printf ("OK\n");
159 }
160
161 SHOW_BOOT_PROGRESS (11);
162
163 if ((hdr->ih_os != IH_OS_LINUX) ||
164 (hdr->ih_arch != IH_CPU_ARM) ||
165 (hdr->ih_type != IH_TYPE_RAMDISK)) {
166 printf ("No Linux ARM Ramdisk Image\n");
167 SHOW_BOOT_PROGRESS (-13);
168 do_reset (cmdtp, flag, argc, argv);
169 }
170
171 /*
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
178 SHOW_BOOT_PROGRESS (13);
179
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 */
197 SHOW_BOOT_PROGRESS (14);
198
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
wdenk5779d8d2003-12-06 23:55:10 +0000216 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) || \
224 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000225 setup_start_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000226#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000227 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +0000228#endif
229#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000230 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +0000231#endif
232#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000233 if (initrd_start && initrd_end)
234 setup_initrd_tag (bd, initrd_start, initrd_end);
wdenkc6097192002-11-03 00:24:07 +0000235#endif
236#if defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000237 setup_videolfb_tag ((gd_t *) gd);
wdenkc6097192002-11-03 00:24:07 +0000238#endif
wdenk5779d8d2003-12-06 23:55:10 +0000239 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000240#endif
241
wdenk5779d8d2003-12-06 23:55:10 +0000242 /* we assume that the kernel is in place */
243 printf ("\nStarting kernel ...\n\n");
wdenkc6097192002-11-03 00:24:07 +0000244
wdenk5779d8d2003-12-06 23:55:10 +0000245 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000246
wdenk5779d8d2003-12-06 23:55:10 +0000247 theKernel (0, bd->bi_arch_number);
wdenkc6097192002-11-03 00:24:07 +0000248}
249
250
251#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
252 defined (CONFIG_CMDLINE_TAG) || \
253 defined (CONFIG_INITRD_TAG) || \
254 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000255static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000256{
wdenk5779d8d2003-12-06 23:55:10 +0000257 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000258
wdenk5779d8d2003-12-06 23:55:10 +0000259 params->hdr.tag = ATAG_CORE;
260 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000261
wdenk5779d8d2003-12-06 23:55:10 +0000262 params->u.core.flags = 0;
263 params->u.core.pagesize = 0;
264 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000265
wdenk5779d8d2003-12-06 23:55:10 +0000266 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000267}
268
269
wdenk699b13a2002-11-03 18:03:52 +0000270#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000271static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000272{
wdenk5779d8d2003-12-06 23:55:10 +0000273 int i;
wdenkc6097192002-11-03 00:24:07 +0000274
wdenk5779d8d2003-12-06 23:55:10 +0000275 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
276 params->hdr.tag = ATAG_MEM;
277 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000278
wdenk5779d8d2003-12-06 23:55:10 +0000279 params->u.mem.start = bd->bi_dram[i].start;
280 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000281
wdenk5779d8d2003-12-06 23:55:10 +0000282 params = tag_next (params);
283 }
wdenkc6097192002-11-03 00:24:07 +0000284}
wdenk5779d8d2003-12-06 23:55:10 +0000285#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000286
287
wdenk5779d8d2003-12-06 23:55:10 +0000288static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000289{
wdenk5779d8d2003-12-06 23:55:10 +0000290 char *p;
wdenkc6097192002-11-03 00:24:07 +0000291
wdenk5779d8d2003-12-06 23:55:10 +0000292 /* eat leading white space */
293 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000294
wdenk5779d8d2003-12-06 23:55:10 +0000295 /* skip non-existent command lines so the kernel will still
296 * use its default command line.
297 */
298 if (*p == '\0')
299 return;
wdenkc6097192002-11-03 00:24:07 +0000300
wdenk5779d8d2003-12-06 23:55:10 +0000301 params->hdr.tag = ATAG_CMDLINE;
302 params->hdr.size =
303 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000304
wdenk5779d8d2003-12-06 23:55:10 +0000305 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000306
wdenk5779d8d2003-12-06 23:55:10 +0000307 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000308}
309
310
311#ifndef ATAG_INITRD2
312#define ATAG_INITRD2 0x54420005
313#endif
wdenk699b13a2002-11-03 18:03:52 +0000314
315#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000316static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000317{
wdenk5779d8d2003-12-06 23:55:10 +0000318 /* an ATAG_INITRD node tells the kernel where the compressed
319 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
320 */
321 params->hdr.tag = ATAG_INITRD2;
322 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000323
wdenk5779d8d2003-12-06 23:55:10 +0000324 params->u.initrd.start = initrd_start;
325 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000326
wdenk5779d8d2003-12-06 23:55:10 +0000327 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000328}
wdenk5779d8d2003-12-06 23:55:10 +0000329#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000330
331
wdenkc6097192002-11-03 00:24:07 +0000332#if defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000333static void setup_videolfb_tag (gd_t *gd)
wdenkc6097192002-11-03 00:24:07 +0000334{
wdenk5779d8d2003-12-06 23:55:10 +0000335 /* An ATAG_VIDEOLFB node tells the kernel where and how large
336 * the framebuffer for video was allocated (among other things).
337 * Note that a _physical_ address is passed !
338 *
339 * We only use it to pass the address and size, the other entries
340 * in the tag_videolfb are not of interest.
341 */
342 params->hdr.tag = ATAG_VIDEOLFB;
343 params->hdr.size = tag_size (tag_videolfb);
wdenkc6097192002-11-03 00:24:07 +0000344
wdenk5779d8d2003-12-06 23:55:10 +0000345 params->u.videolfb.lfb_base = (u32) gd->fb_base;
346 /* 7168 = 256*4*56/8 - actually 2 pages (8192 bytes) are allocated */
347 params->u.videolfb.lfb_size = 7168;
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}
351#endif
352
wdenk5779d8d2003-12-06 23:55:10 +0000353static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000354{
wdenk5779d8d2003-12-06 23:55:10 +0000355 params->hdr.tag = ATAG_NONE;
356 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000357}
358
359#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */