blob: 5660a503dc614d5fe3a7726364a0ccb320681340 [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>
29
Wolfgang Denkd87080b2006-03-31 18:32:53 +020030DECLARE_GLOBAL_DATA_PTR;
31
wdenkc6097192002-11-03 00:24:07 +000032#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
33 defined (CONFIG_CMDLINE_TAG) || \
34 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +000035 defined (CONFIG_SERIAL_TAG) || \
36 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +000037 defined (CONFIG_VFD) || \
38 defined (CONFIG_LCD)
wdenk5779d8d2003-12-06 23:55:10 +000039static void setup_start_tag (bd_t *bd);
40
wdenk699b13a2002-11-03 18:03:52 +000041# ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +000042static void setup_memory_tags (bd_t *bd);
wdenk699b13a2002-11-03 18:03:52 +000043# endif
wdenk5779d8d2003-12-06 23:55:10 +000044static void setup_commandline_tag (bd_t *bd, char *commandline);
45
wdenk699b13a2002-11-03 18:03:52 +000046# ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +000047static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
48 ulong initrd_end);
wdenk699b13a2002-11-03 18:03:52 +000049# endif
wdenk5779d8d2003-12-06 23:55:10 +000050static void setup_end_tag (bd_t *bd);
51
wdenk8655b6f2004-10-09 23:25:58 +000052# if defined (CONFIG_VFD) || defined (CONFIG_LCD)
wdenk5779d8d2003-12-06 23:55:10 +000053static void setup_videolfb_tag (gd_t *gd);
wdenk699b13a2002-11-03 18:03:52 +000054# endif
wdenkc6097192002-11-03 00:24:07 +000055
wdenkc6097192002-11-03 00:24:07 +000056static struct tag *params;
57#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
58
Marian Balakowiczd5934ad2008-02-04 08:28:09 +010059extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
60
wdenk5779d8d2003-12-06 23:55:10 +000061void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +010062 bootm_headers_t *images)
wdenkc6097192002-11-03 00:24:07 +000063{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +010064 ulong initrd_start, initrd_end;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +010065 bd_t *bd = gd->bd;
66 char *s;
67 int machid = bd->bi_arch_number;
68 void (*theKernel)(int zero, int arch, uint params);
Marian Balakowiczcd7c5962008-03-12 10:33:00 +010069 int ret;
wdenk5779d8d2003-12-06 23:55:10 +000070
wdenkc6097192002-11-03 00:24:07 +000071#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +000072 char *commandline = getenv ("bootargs");
wdenkc6097192002-11-03 00:24:07 +000073#endif
74
Kumar Galac160a952008-08-15 08:24:36 -050075 theKernel = (void (*)(int, int, uint))images->ep;
wdenkc6097192002-11-03 00:24:07 +000076
Uwe Kleine-König3c234ef2008-01-30 09:08:49 +010077 s = getenv ("machid");
78 if (s) {
79 machid = simple_strtoul (s, NULL, 16);
80 printf ("Using machid 0x%x from environment\n", machid);
81 }
82
Marian Balakowiczd985c842008-03-12 10:14:38 +010083 ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_ARM,
84 &initrd_start, &initrd_end);
85 if (ret)
Marian Balakowiczcd7c5962008-03-12 10:33:00 +010086 goto error;
wdenkc6097192002-11-03 00:24:07 +000087
Heiko Schocherfad63402007-07-13 09:54:17 +020088 show_boot_progress (15);
wdenk384ae022002-11-05 00:17:55 +000089
wdenk5779d8d2003-12-06 23:55:10 +000090 debug ("## Transferring control to Linux (at address %08lx) ...\n",
91 (ulong) theKernel);
wdenkc6097192002-11-03 00:24:07 +000092
93#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
94 defined (CONFIG_CMDLINE_TAG) || \
95 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +000096 defined (CONFIG_SERIAL_TAG) || \
97 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +000098 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +000099 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000100 setup_start_tag (bd);
wdenkb6e4c402004-01-02 16:05:07 +0000101#ifdef CONFIG_SERIAL_TAG
102 setup_serial_tag (&params);
103#endif
104#ifdef CONFIG_REVISION_TAG
105 setup_revision_tag (&params);
106#endif
wdenkc6097192002-11-03 00:24:07 +0000107#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000108 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +0000109#endif
110#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000111 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +0000112#endif
113#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000114 if (initrd_start && initrd_end)
115 setup_initrd_tag (bd, initrd_start, initrd_end);
wdenkc6097192002-11-03 00:24:07 +0000116#endif
wdenk8655b6f2004-10-09 23:25:58 +0000117#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
wdenk5779d8d2003-12-06 23:55:10 +0000118 setup_videolfb_tag ((gd_t *) gd);
wdenkc6097192002-11-03 00:24:07 +0000119#endif
wdenk5779d8d2003-12-06 23:55:10 +0000120 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000121#endif
122
wdenk5779d8d2003-12-06 23:55:10 +0000123 /* we assume that the kernel is in place */
124 printf ("\nStarting kernel ...\n\n");
wdenkc6097192002-11-03 00:24:07 +0000125
wdenk232c1502004-03-12 00:14:09 +0000126#ifdef CONFIG_USB_DEVICE
127 {
128 extern void udc_disconnect (void);
129 udc_disconnect ();
130 }
131#endif
132
wdenk5779d8d2003-12-06 23:55:10 +0000133 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000134
Uwe Kleine-König3c234ef2008-01-30 09:08:49 +0100135 theKernel (0, machid, bd->bi_boot_params);
Marian Balakowiczcd7c5962008-03-12 10:33:00 +0100136 /* does not return */
137 return;
138
139error:
Kumar Gala3216ca92008-08-11 09:20:53 -0500140 do_reset (cmdtp, flag, argc, argv);
Marian Balakowiczcd7c5962008-03-12 10:33:00 +0100141 return;
wdenkc6097192002-11-03 00:24:07 +0000142}
143
144
145#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
146 defined (CONFIG_CMDLINE_TAG) || \
147 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000148 defined (CONFIG_SERIAL_TAG) || \
149 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +0000150 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +0000151 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000152static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000153{
wdenk5779d8d2003-12-06 23:55:10 +0000154 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000155
wdenk5779d8d2003-12-06 23:55:10 +0000156 params->hdr.tag = ATAG_CORE;
157 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000158
wdenk5779d8d2003-12-06 23:55:10 +0000159 params->u.core.flags = 0;
160 params->u.core.pagesize = 0;
161 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000162
wdenk5779d8d2003-12-06 23:55:10 +0000163 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000164}
165
166
wdenk699b13a2002-11-03 18:03:52 +0000167#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000168static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000169{
wdenk5779d8d2003-12-06 23:55:10 +0000170 int i;
wdenkc6097192002-11-03 00:24:07 +0000171
wdenk5779d8d2003-12-06 23:55:10 +0000172 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
173 params->hdr.tag = ATAG_MEM;
174 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000175
wdenk5779d8d2003-12-06 23:55:10 +0000176 params->u.mem.start = bd->bi_dram[i].start;
177 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000178
wdenk5779d8d2003-12-06 23:55:10 +0000179 params = tag_next (params);
180 }
wdenkc6097192002-11-03 00:24:07 +0000181}
wdenk5779d8d2003-12-06 23:55:10 +0000182#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000183
184
wdenk5779d8d2003-12-06 23:55:10 +0000185static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000186{
wdenk5779d8d2003-12-06 23:55:10 +0000187 char *p;
wdenkc6097192002-11-03 00:24:07 +0000188
wdenk109c0e32004-03-23 21:43:07 +0000189 if (!commandline)
190 return;
191
wdenk5779d8d2003-12-06 23:55:10 +0000192 /* eat leading white space */
193 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000194
wdenk5779d8d2003-12-06 23:55:10 +0000195 /* skip non-existent command lines so the kernel will still
196 * use its default command line.
197 */
198 if (*p == '\0')
199 return;
wdenkc6097192002-11-03 00:24:07 +0000200
wdenk5779d8d2003-12-06 23:55:10 +0000201 params->hdr.tag = ATAG_CMDLINE;
202 params->hdr.size =
203 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000204
wdenk5779d8d2003-12-06 23:55:10 +0000205 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000206
wdenk5779d8d2003-12-06 23:55:10 +0000207 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000208}
209
210
wdenk699b13a2002-11-03 18:03:52 +0000211#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000212static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000213{
wdenk5779d8d2003-12-06 23:55:10 +0000214 /* an ATAG_INITRD node tells the kernel where the compressed
215 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
216 */
wdenk498b8db2004-04-18 22:26:17 +0000217 params->hdr.tag = ATAG_INITRD2;
wdenk5779d8d2003-12-06 23:55:10 +0000218 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000219
wdenk5779d8d2003-12-06 23:55:10 +0000220 params->u.initrd.start = initrd_start;
221 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000222
wdenk5779d8d2003-12-06 23:55:10 +0000223 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000224}
wdenk5779d8d2003-12-06 23:55:10 +0000225#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000226
227
wdenk8655b6f2004-10-09 23:25:58 +0000228#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
229extern ulong calc_fbsize (void);
wdenk5779d8d2003-12-06 23:55:10 +0000230static void setup_videolfb_tag (gd_t *gd)
wdenkc6097192002-11-03 00:24:07 +0000231{
wdenk5779d8d2003-12-06 23:55:10 +0000232 /* An ATAG_VIDEOLFB node tells the kernel where and how large
233 * the framebuffer for video was allocated (among other things).
234 * Note that a _physical_ address is passed !
235 *
236 * We only use it to pass the address and size, the other entries
237 * in the tag_videolfb are not of interest.
238 */
239 params->hdr.tag = ATAG_VIDEOLFB;
240 params->hdr.size = tag_size (tag_videolfb);
wdenkc6097192002-11-03 00:24:07 +0000241
wdenk5779d8d2003-12-06 23:55:10 +0000242 params->u.videolfb.lfb_base = (u32) gd->fb_base;
wdenk8655b6f2004-10-09 23:25:58 +0000243 /* Fb size is calculated according to parameters for our panel
244 */
245 params->u.videolfb.lfb_size = calc_fbsize();
wdenkc6097192002-11-03 00:24:07 +0000246
wdenk5779d8d2003-12-06 23:55:10 +0000247 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000248}
wdenk8655b6f2004-10-09 23:25:58 +0000249#endif /* CONFIG_VFD || CONFIG_LCD */
wdenkc6097192002-11-03 00:24:07 +0000250
wdenk3a574cb2005-05-19 22:39:42 +0000251#ifdef CONFIG_SERIAL_TAG
252void setup_serial_tag (struct tag **tmp)
253{
254 struct tag *params = *tmp;
255 struct tag_serialnr serialnr;
256 void get_board_serial(struct tag_serialnr *serialnr);
257
258 get_board_serial(&serialnr);
259 params->hdr.tag = ATAG_SERIAL;
260 params->hdr.size = tag_size (tag_serialnr);
261 params->u.serialnr.low = serialnr.low;
262 params->u.serialnr.high= serialnr.high;
263 params = tag_next (params);
264 *tmp = params;
265}
266#endif
267
wdenk289f9322005-01-12 00:15:14 +0000268#ifdef CONFIG_REVISION_TAG
269void setup_revision_tag(struct tag **in_params)
270{
271 u32 rev = 0;
wdenk289f9322005-01-12 00:15:14 +0000272 u32 get_board_rev(void);
273
274 rev = get_board_rev();
wdenk289f9322005-01-12 00:15:14 +0000275 params->hdr.tag = ATAG_REVISION;
276 params->hdr.size = tag_size (tag_revision);
277 params->u.revision.rev = rev;
278 params = tag_next (params);
279}
280#endif /* CONFIG_REVISION_TAG */
281
282
wdenk5779d8d2003-12-06 23:55:10 +0000283static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000284{
wdenk5779d8d2003-12-06 23:55:10 +0000285 params->hdr.tag = ATAG_NONE;
286 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000287}
288
289#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */