blob: 6c2f37e98151920469b09e76663613c0024381e7 [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
Kumar Gala40d7e992008-08-15 08:24:45 -050059int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
wdenkc6097192002-11-03 00:24:07 +000060{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +010061 bd_t *bd = gd->bd;
62 char *s;
63 int machid = bd->bi_arch_number;
64 void (*theKernel)(int zero, int arch, uint params);
Marian Balakowiczcd7c5962008-03-12 10:33:00 +010065 int ret;
wdenk5779d8d2003-12-06 23:55:10 +000066
wdenkc6097192002-11-03 00:24:07 +000067#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +000068 char *commandline = getenv ("bootargs");
wdenkc6097192002-11-03 00:24:07 +000069#endif
70
Kumar Galac160a952008-08-15 08:24:36 -050071 theKernel = (void (*)(int, int, uint))images->ep;
wdenkc6097192002-11-03 00:24:07 +000072
Uwe Kleine-König3c234ef2008-01-30 09:08:49 +010073 s = getenv ("machid");
74 if (s) {
75 machid = simple_strtoul (s, NULL, 16);
76 printf ("Using machid 0x%x from environment\n", machid);
77 }
78
Heiko Schocherfad63402007-07-13 09:54:17 +020079 show_boot_progress (15);
wdenk384ae022002-11-05 00:17:55 +000080
wdenk5779d8d2003-12-06 23:55:10 +000081 debug ("## Transferring control to Linux (at address %08lx) ...\n",
82 (ulong) theKernel);
wdenkc6097192002-11-03 00:24:07 +000083
84#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
85 defined (CONFIG_CMDLINE_TAG) || \
86 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +000087 defined (CONFIG_SERIAL_TAG) || \
88 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +000089 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +000090 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +000091 setup_start_tag (bd);
wdenkb6e4c402004-01-02 16:05:07 +000092#ifdef CONFIG_SERIAL_TAG
93 setup_serial_tag (&params);
94#endif
95#ifdef CONFIG_REVISION_TAG
96 setup_revision_tag (&params);
97#endif
wdenkc6097192002-11-03 00:24:07 +000098#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +000099 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +0000100#endif
101#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000102 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +0000103#endif
104#ifdef CONFIG_INITRD_TAG
Kumar Galac4f94192008-08-15 08:24:37 -0500105 if (images->rd_start && images->rd_end)
106 setup_initrd_tag (bd, images->rd_start, images->rd_end);
wdenkc6097192002-11-03 00:24:07 +0000107#endif
wdenk8655b6f2004-10-09 23:25:58 +0000108#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
wdenk5779d8d2003-12-06 23:55:10 +0000109 setup_videolfb_tag ((gd_t *) gd);
wdenkc6097192002-11-03 00:24:07 +0000110#endif
wdenk5779d8d2003-12-06 23:55:10 +0000111 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000112#endif
113
wdenk5779d8d2003-12-06 23:55:10 +0000114 /* we assume that the kernel is in place */
115 printf ("\nStarting kernel ...\n\n");
wdenkc6097192002-11-03 00:24:07 +0000116
wdenk232c1502004-03-12 00:14:09 +0000117#ifdef CONFIG_USB_DEVICE
118 {
119 extern void udc_disconnect (void);
120 udc_disconnect ();
121 }
122#endif
123
wdenk5779d8d2003-12-06 23:55:10 +0000124 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000125
Uwe Kleine-König3c234ef2008-01-30 09:08:49 +0100126 theKernel (0, machid, bd->bi_boot_params);
Marian Balakowiczcd7c5962008-03-12 10:33:00 +0100127 /* does not return */
Marian Balakowiczcd7c5962008-03-12 10:33:00 +0100128error:
Kumar Gala40d7e992008-08-15 08:24:45 -0500129 return 1;
wdenkc6097192002-11-03 00:24:07 +0000130}
131
132
133#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
134 defined (CONFIG_CMDLINE_TAG) || \
135 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000136 defined (CONFIG_SERIAL_TAG) || \
137 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +0000138 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +0000139 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000140static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000141{
wdenk5779d8d2003-12-06 23:55:10 +0000142 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000143
wdenk5779d8d2003-12-06 23:55:10 +0000144 params->hdr.tag = ATAG_CORE;
145 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000146
wdenk5779d8d2003-12-06 23:55:10 +0000147 params->u.core.flags = 0;
148 params->u.core.pagesize = 0;
149 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000150
wdenk5779d8d2003-12-06 23:55:10 +0000151 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000152}
153
154
wdenk699b13a2002-11-03 18:03:52 +0000155#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000156static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000157{
wdenk5779d8d2003-12-06 23:55:10 +0000158 int i;
wdenkc6097192002-11-03 00:24:07 +0000159
wdenk5779d8d2003-12-06 23:55:10 +0000160 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
161 params->hdr.tag = ATAG_MEM;
162 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000163
wdenk5779d8d2003-12-06 23:55:10 +0000164 params->u.mem.start = bd->bi_dram[i].start;
165 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000166
wdenk5779d8d2003-12-06 23:55:10 +0000167 params = tag_next (params);
168 }
wdenkc6097192002-11-03 00:24:07 +0000169}
wdenk5779d8d2003-12-06 23:55:10 +0000170#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000171
172
wdenk5779d8d2003-12-06 23:55:10 +0000173static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000174{
wdenk5779d8d2003-12-06 23:55:10 +0000175 char *p;
wdenkc6097192002-11-03 00:24:07 +0000176
wdenk109c0e32004-03-23 21:43:07 +0000177 if (!commandline)
178 return;
179
wdenk5779d8d2003-12-06 23:55:10 +0000180 /* eat leading white space */
181 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000182
wdenk5779d8d2003-12-06 23:55:10 +0000183 /* skip non-existent command lines so the kernel will still
184 * use its default command line.
185 */
186 if (*p == '\0')
187 return;
wdenkc6097192002-11-03 00:24:07 +0000188
wdenk5779d8d2003-12-06 23:55:10 +0000189 params->hdr.tag = ATAG_CMDLINE;
190 params->hdr.size =
191 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000192
wdenk5779d8d2003-12-06 23:55:10 +0000193 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000194
wdenk5779d8d2003-12-06 23:55:10 +0000195 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000196}
197
198
wdenk699b13a2002-11-03 18:03:52 +0000199#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000200static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000201{
wdenk5779d8d2003-12-06 23:55:10 +0000202 /* an ATAG_INITRD node tells the kernel where the compressed
203 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
204 */
wdenk498b8db2004-04-18 22:26:17 +0000205 params->hdr.tag = ATAG_INITRD2;
wdenk5779d8d2003-12-06 23:55:10 +0000206 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000207
wdenk5779d8d2003-12-06 23:55:10 +0000208 params->u.initrd.start = initrd_start;
209 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000210
wdenk5779d8d2003-12-06 23:55:10 +0000211 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000212}
wdenk5779d8d2003-12-06 23:55:10 +0000213#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000214
215
wdenk8655b6f2004-10-09 23:25:58 +0000216#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
217extern ulong calc_fbsize (void);
wdenk5779d8d2003-12-06 23:55:10 +0000218static void setup_videolfb_tag (gd_t *gd)
wdenkc6097192002-11-03 00:24:07 +0000219{
wdenk5779d8d2003-12-06 23:55:10 +0000220 /* An ATAG_VIDEOLFB node tells the kernel where and how large
221 * the framebuffer for video was allocated (among other things).
222 * Note that a _physical_ address is passed !
223 *
224 * We only use it to pass the address and size, the other entries
225 * in the tag_videolfb are not of interest.
226 */
227 params->hdr.tag = ATAG_VIDEOLFB;
228 params->hdr.size = tag_size (tag_videolfb);
wdenkc6097192002-11-03 00:24:07 +0000229
wdenk5779d8d2003-12-06 23:55:10 +0000230 params->u.videolfb.lfb_base = (u32) gd->fb_base;
wdenk8655b6f2004-10-09 23:25:58 +0000231 /* Fb size is calculated according to parameters for our panel
232 */
233 params->u.videolfb.lfb_size = calc_fbsize();
wdenkc6097192002-11-03 00:24:07 +0000234
wdenk5779d8d2003-12-06 23:55:10 +0000235 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000236}
wdenk8655b6f2004-10-09 23:25:58 +0000237#endif /* CONFIG_VFD || CONFIG_LCD */
wdenkc6097192002-11-03 00:24:07 +0000238
wdenk3a574cb2005-05-19 22:39:42 +0000239#ifdef CONFIG_SERIAL_TAG
240void setup_serial_tag (struct tag **tmp)
241{
242 struct tag *params = *tmp;
243 struct tag_serialnr serialnr;
244 void get_board_serial(struct tag_serialnr *serialnr);
245
246 get_board_serial(&serialnr);
247 params->hdr.tag = ATAG_SERIAL;
248 params->hdr.size = tag_size (tag_serialnr);
249 params->u.serialnr.low = serialnr.low;
250 params->u.serialnr.high= serialnr.high;
251 params = tag_next (params);
252 *tmp = params;
253}
254#endif
255
wdenk289f9322005-01-12 00:15:14 +0000256#ifdef CONFIG_REVISION_TAG
257void setup_revision_tag(struct tag **in_params)
258{
259 u32 rev = 0;
wdenk289f9322005-01-12 00:15:14 +0000260 u32 get_board_rev(void);
261
262 rev = get_board_rev();
wdenk289f9322005-01-12 00:15:14 +0000263 params->hdr.tag = ATAG_REVISION;
264 params->hdr.size = tag_size (tag_revision);
265 params->u.revision.rev = rev;
266 params = tag_next (params);
267}
268#endif /* CONFIG_REVISION_TAG */
269
270
wdenk5779d8d2003-12-06 23:55:10 +0000271static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000272{
wdenk5779d8d2003-12-06 23:55:10 +0000273 params->hdr.tag = ATAG_NONE;
274 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000275}
276
277#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */