blob: 772fa7f516a669bc7e986eab72d884d3bffc9bbf [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);
wdenk5779d8d2003-12-06 23:55:10 +000065
wdenkc6097192002-11-03 00:24:07 +000066#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +000067 char *commandline = getenv ("bootargs");
wdenkc6097192002-11-03 00:24:07 +000068#endif
69
Kumar Galac160a952008-08-15 08:24:36 -050070 theKernel = (void (*)(int, int, uint))images->ep;
wdenkc6097192002-11-03 00:24:07 +000071
Uwe Kleine-König3c234ef2008-01-30 09:08:49 +010072 s = getenv ("machid");
73 if (s) {
74 machid = simple_strtoul (s, NULL, 16);
75 printf ("Using machid 0x%x from environment\n", machid);
76 }
77
Heiko Schocherfad63402007-07-13 09:54:17 +020078 show_boot_progress (15);
wdenk384ae022002-11-05 00:17:55 +000079
wdenk5779d8d2003-12-06 23:55:10 +000080 debug ("## Transferring control to Linux (at address %08lx) ...\n",
81 (ulong) theKernel);
wdenkc6097192002-11-03 00:24:07 +000082
83#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
84 defined (CONFIG_CMDLINE_TAG) || \
85 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +000086 defined (CONFIG_SERIAL_TAG) || \
87 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +000088 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +000089 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +000090 setup_start_tag (bd);
wdenkb6e4c402004-01-02 16:05:07 +000091#ifdef CONFIG_SERIAL_TAG
92 setup_serial_tag (&params);
93#endif
94#ifdef CONFIG_REVISION_TAG
95 setup_revision_tag (&params);
96#endif
wdenkc6097192002-11-03 00:24:07 +000097#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +000098 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +000099#endif
100#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000101 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +0000102#endif
103#ifdef CONFIG_INITRD_TAG
Kumar Galac4f94192008-08-15 08:24:37 -0500104 if (images->rd_start && images->rd_end)
105 setup_initrd_tag (bd, images->rd_start, images->rd_end);
wdenkc6097192002-11-03 00:24:07 +0000106#endif
wdenk8655b6f2004-10-09 23:25:58 +0000107#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
wdenk5779d8d2003-12-06 23:55:10 +0000108 setup_videolfb_tag ((gd_t *) gd);
wdenkc6097192002-11-03 00:24:07 +0000109#endif
wdenk5779d8d2003-12-06 23:55:10 +0000110 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000111#endif
112
wdenk5779d8d2003-12-06 23:55:10 +0000113 /* we assume that the kernel is in place */
114 printf ("\nStarting kernel ...\n\n");
wdenkc6097192002-11-03 00:24:07 +0000115
wdenk232c1502004-03-12 00:14:09 +0000116#ifdef CONFIG_USB_DEVICE
117 {
118 extern void udc_disconnect (void);
119 udc_disconnect ();
120 }
121#endif
122
wdenk5779d8d2003-12-06 23:55:10 +0000123 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000124
Uwe Kleine-König3c234ef2008-01-30 09:08:49 +0100125 theKernel (0, machid, bd->bi_boot_params);
Marian Balakowiczcd7c5962008-03-12 10:33:00 +0100126 /* does not return */
Wolfgang Denk10551712008-09-08 23:26:22 +0200127
Kumar Gala40d7e992008-08-15 08:24:45 -0500128 return 1;
wdenkc6097192002-11-03 00:24:07 +0000129}
130
131
132#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
133 defined (CONFIG_CMDLINE_TAG) || \
134 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000135 defined (CONFIG_SERIAL_TAG) || \
136 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +0000137 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +0000138 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000139static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000140{
wdenk5779d8d2003-12-06 23:55:10 +0000141 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000142
wdenk5779d8d2003-12-06 23:55:10 +0000143 params->hdr.tag = ATAG_CORE;
144 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000145
wdenk5779d8d2003-12-06 23:55:10 +0000146 params->u.core.flags = 0;
147 params->u.core.pagesize = 0;
148 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000149
wdenk5779d8d2003-12-06 23:55:10 +0000150 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000151}
152
153
wdenk699b13a2002-11-03 18:03:52 +0000154#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000155static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000156{
wdenk5779d8d2003-12-06 23:55:10 +0000157 int i;
wdenkc6097192002-11-03 00:24:07 +0000158
wdenk5779d8d2003-12-06 23:55:10 +0000159 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
160 params->hdr.tag = ATAG_MEM;
161 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000162
wdenk5779d8d2003-12-06 23:55:10 +0000163 params->u.mem.start = bd->bi_dram[i].start;
164 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000165
wdenk5779d8d2003-12-06 23:55:10 +0000166 params = tag_next (params);
167 }
wdenkc6097192002-11-03 00:24:07 +0000168}
wdenk5779d8d2003-12-06 23:55:10 +0000169#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000170
171
wdenk5779d8d2003-12-06 23:55:10 +0000172static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000173{
wdenk5779d8d2003-12-06 23:55:10 +0000174 char *p;
wdenkc6097192002-11-03 00:24:07 +0000175
wdenk109c0e32004-03-23 21:43:07 +0000176 if (!commandline)
177 return;
178
wdenk5779d8d2003-12-06 23:55:10 +0000179 /* eat leading white space */
180 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000181
wdenk5779d8d2003-12-06 23:55:10 +0000182 /* skip non-existent command lines so the kernel will still
183 * use its default command line.
184 */
185 if (*p == '\0')
186 return;
wdenkc6097192002-11-03 00:24:07 +0000187
wdenk5779d8d2003-12-06 23:55:10 +0000188 params->hdr.tag = ATAG_CMDLINE;
189 params->hdr.size =
190 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000191
wdenk5779d8d2003-12-06 23:55:10 +0000192 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000193
wdenk5779d8d2003-12-06 23:55:10 +0000194 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000195}
196
197
wdenk699b13a2002-11-03 18:03:52 +0000198#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000199static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000200{
wdenk5779d8d2003-12-06 23:55:10 +0000201 /* an ATAG_INITRD node tells the kernel where the compressed
202 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
203 */
wdenk498b8db2004-04-18 22:26:17 +0000204 params->hdr.tag = ATAG_INITRD2;
wdenk5779d8d2003-12-06 23:55:10 +0000205 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000206
wdenk5779d8d2003-12-06 23:55:10 +0000207 params->u.initrd.start = initrd_start;
208 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000209
wdenk5779d8d2003-12-06 23:55:10 +0000210 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000211}
wdenk5779d8d2003-12-06 23:55:10 +0000212#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000213
214
wdenk8655b6f2004-10-09 23:25:58 +0000215#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
216extern ulong calc_fbsize (void);
wdenk5779d8d2003-12-06 23:55:10 +0000217static void setup_videolfb_tag (gd_t *gd)
wdenkc6097192002-11-03 00:24:07 +0000218{
wdenk5779d8d2003-12-06 23:55:10 +0000219 /* An ATAG_VIDEOLFB node tells the kernel where and how large
220 * the framebuffer for video was allocated (among other things).
221 * Note that a _physical_ address is passed !
222 *
223 * We only use it to pass the address and size, the other entries
224 * in the tag_videolfb are not of interest.
225 */
226 params->hdr.tag = ATAG_VIDEOLFB;
227 params->hdr.size = tag_size (tag_videolfb);
wdenkc6097192002-11-03 00:24:07 +0000228
wdenk5779d8d2003-12-06 23:55:10 +0000229 params->u.videolfb.lfb_base = (u32) gd->fb_base;
wdenk8655b6f2004-10-09 23:25:58 +0000230 /* Fb size is calculated according to parameters for our panel
231 */
232 params->u.videolfb.lfb_size = calc_fbsize();
wdenkc6097192002-11-03 00:24:07 +0000233
wdenk5779d8d2003-12-06 23:55:10 +0000234 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000235}
wdenk8655b6f2004-10-09 23:25:58 +0000236#endif /* CONFIG_VFD || CONFIG_LCD */
wdenkc6097192002-11-03 00:24:07 +0000237
wdenk3a574cb2005-05-19 22:39:42 +0000238#ifdef CONFIG_SERIAL_TAG
239void setup_serial_tag (struct tag **tmp)
240{
241 struct tag *params = *tmp;
242 struct tag_serialnr serialnr;
243 void get_board_serial(struct tag_serialnr *serialnr);
244
245 get_board_serial(&serialnr);
246 params->hdr.tag = ATAG_SERIAL;
247 params->hdr.size = tag_size (tag_serialnr);
248 params->u.serialnr.low = serialnr.low;
249 params->u.serialnr.high= serialnr.high;
250 params = tag_next (params);
251 *tmp = params;
252}
253#endif
254
wdenk289f9322005-01-12 00:15:14 +0000255#ifdef CONFIG_REVISION_TAG
256void setup_revision_tag(struct tag **in_params)
257{
258 u32 rev = 0;
wdenk289f9322005-01-12 00:15:14 +0000259 u32 get_board_rev(void);
260
261 rev = get_board_rev();
wdenk289f9322005-01-12 00:15:14 +0000262 params->hdr.tag = ATAG_REVISION;
263 params->hdr.size = tag_size (tag_revision);
264 params->u.revision.rev = rev;
265 params = tag_next (params);
266}
267#endif /* CONFIG_REVISION_TAG */
268
269
wdenk5779d8d2003-12-06 23:55:10 +0000270static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000271{
wdenk5779d8d2003-12-06 23:55:10 +0000272 params->hdr.tag = ATAG_NONE;
273 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000274}
275
276#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */