blob: 7dbde7df5cebef36dc349d4d3189d111bd940cf6 [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
Ilko Iliev263b7492008-11-09 15:53:14 +010070 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
Kumar Gala49c3a862008-10-21 17:25:45 -050071 return 1;
72
Kumar Galac160a952008-08-15 08:24:36 -050073 theKernel = (void (*)(int, int, uint))images->ep;
wdenkc6097192002-11-03 00:24:07 +000074
Uwe Kleine-König3c234ef2008-01-30 09:08:49 +010075 s = getenv ("machid");
76 if (s) {
77 machid = simple_strtoul (s, NULL, 16);
78 printf ("Using machid 0x%x from environment\n", machid);
79 }
80
Heiko Schocherfad63402007-07-13 09:54:17 +020081 show_boot_progress (15);
wdenk384ae022002-11-05 00:17:55 +000082
wdenk5779d8d2003-12-06 23:55:10 +000083 debug ("## Transferring control to Linux (at address %08lx) ...\n",
84 (ulong) theKernel);
wdenkc6097192002-11-03 00:24:07 +000085
86#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
87 defined (CONFIG_CMDLINE_TAG) || \
88 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +000089 defined (CONFIG_SERIAL_TAG) || \
90 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +000091 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +000092 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +000093 setup_start_tag (bd);
wdenkb6e4c402004-01-02 16:05:07 +000094#ifdef CONFIG_SERIAL_TAG
95 setup_serial_tag (&params);
96#endif
97#ifdef CONFIG_REVISION_TAG
98 setup_revision_tag (&params);
99#endif
wdenkc6097192002-11-03 00:24:07 +0000100#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000101 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +0000102#endif
103#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000104 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +0000105#endif
106#ifdef CONFIG_INITRD_TAG
Kumar Galac4f94192008-08-15 08:24:37 -0500107 if (images->rd_start && images->rd_end)
108 setup_initrd_tag (bd, images->rd_start, images->rd_end);
wdenkc6097192002-11-03 00:24:07 +0000109#endif
wdenk8655b6f2004-10-09 23:25:58 +0000110#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
wdenk5779d8d2003-12-06 23:55:10 +0000111 setup_videolfb_tag ((gd_t *) gd);
wdenkc6097192002-11-03 00:24:07 +0000112#endif
wdenk5779d8d2003-12-06 23:55:10 +0000113 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000114#endif
115
wdenk5779d8d2003-12-06 23:55:10 +0000116 /* we assume that the kernel is in place */
117 printf ("\nStarting kernel ...\n\n");
wdenkc6097192002-11-03 00:24:07 +0000118
wdenk232c1502004-03-12 00:14:09 +0000119#ifdef CONFIG_USB_DEVICE
120 {
121 extern void udc_disconnect (void);
122 udc_disconnect ();
123 }
124#endif
125
wdenk5779d8d2003-12-06 23:55:10 +0000126 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000127
Uwe Kleine-König3c234ef2008-01-30 09:08:49 +0100128 theKernel (0, machid, bd->bi_boot_params);
Marian Balakowiczcd7c5962008-03-12 10:33:00 +0100129 /* does not return */
Wolfgang Denk10551712008-09-08 23:26:22 +0200130
Kumar Gala40d7e992008-08-15 08:24:45 -0500131 return 1;
wdenkc6097192002-11-03 00:24:07 +0000132}
133
134
135#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
136 defined (CONFIG_CMDLINE_TAG) || \
137 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000138 defined (CONFIG_SERIAL_TAG) || \
139 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +0000140 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +0000141 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000142static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000143{
wdenk5779d8d2003-12-06 23:55:10 +0000144 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000145
wdenk5779d8d2003-12-06 23:55:10 +0000146 params->hdr.tag = ATAG_CORE;
147 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000148
wdenk5779d8d2003-12-06 23:55:10 +0000149 params->u.core.flags = 0;
150 params->u.core.pagesize = 0;
151 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000152
wdenk5779d8d2003-12-06 23:55:10 +0000153 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000154}
155
156
wdenk699b13a2002-11-03 18:03:52 +0000157#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000158static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000159{
wdenk5779d8d2003-12-06 23:55:10 +0000160 int i;
wdenkc6097192002-11-03 00:24:07 +0000161
wdenk5779d8d2003-12-06 23:55:10 +0000162 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
163 params->hdr.tag = ATAG_MEM;
164 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000165
wdenk5779d8d2003-12-06 23:55:10 +0000166 params->u.mem.start = bd->bi_dram[i].start;
167 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000168
wdenk5779d8d2003-12-06 23:55:10 +0000169 params = tag_next (params);
170 }
wdenkc6097192002-11-03 00:24:07 +0000171}
wdenk5779d8d2003-12-06 23:55:10 +0000172#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000173
174
wdenk5779d8d2003-12-06 23:55:10 +0000175static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000176{
wdenk5779d8d2003-12-06 23:55:10 +0000177 char *p;
wdenkc6097192002-11-03 00:24:07 +0000178
wdenk109c0e32004-03-23 21:43:07 +0000179 if (!commandline)
180 return;
181
wdenk5779d8d2003-12-06 23:55:10 +0000182 /* eat leading white space */
183 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000184
wdenk5779d8d2003-12-06 23:55:10 +0000185 /* skip non-existent command lines so the kernel will still
186 * use its default command line.
187 */
188 if (*p == '\0')
189 return;
wdenkc6097192002-11-03 00:24:07 +0000190
wdenk5779d8d2003-12-06 23:55:10 +0000191 params->hdr.tag = ATAG_CMDLINE;
192 params->hdr.size =
193 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000194
wdenk5779d8d2003-12-06 23:55:10 +0000195 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000196
wdenk5779d8d2003-12-06 23:55:10 +0000197 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000198}
199
200
wdenk699b13a2002-11-03 18:03:52 +0000201#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000202static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000203{
wdenk5779d8d2003-12-06 23:55:10 +0000204 /* an ATAG_INITRD node tells the kernel where the compressed
205 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
206 */
wdenk498b8db2004-04-18 22:26:17 +0000207 params->hdr.tag = ATAG_INITRD2;
wdenk5779d8d2003-12-06 23:55:10 +0000208 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000209
wdenk5779d8d2003-12-06 23:55:10 +0000210 params->u.initrd.start = initrd_start;
211 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000212
wdenk5779d8d2003-12-06 23:55:10 +0000213 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000214}
wdenk5779d8d2003-12-06 23:55:10 +0000215#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000216
217
wdenk8655b6f2004-10-09 23:25:58 +0000218#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
219extern ulong calc_fbsize (void);
wdenk5779d8d2003-12-06 23:55:10 +0000220static void setup_videolfb_tag (gd_t *gd)
wdenkc6097192002-11-03 00:24:07 +0000221{
wdenk5779d8d2003-12-06 23:55:10 +0000222 /* An ATAG_VIDEOLFB node tells the kernel where and how large
223 * the framebuffer for video was allocated (among other things).
224 * Note that a _physical_ address is passed !
225 *
226 * We only use it to pass the address and size, the other entries
227 * in the tag_videolfb are not of interest.
228 */
229 params->hdr.tag = ATAG_VIDEOLFB;
230 params->hdr.size = tag_size (tag_videolfb);
wdenkc6097192002-11-03 00:24:07 +0000231
wdenk5779d8d2003-12-06 23:55:10 +0000232 params->u.videolfb.lfb_base = (u32) gd->fb_base;
wdenk8655b6f2004-10-09 23:25:58 +0000233 /* Fb size is calculated according to parameters for our panel
234 */
235 params->u.videolfb.lfb_size = calc_fbsize();
wdenkc6097192002-11-03 00:24:07 +0000236
wdenk5779d8d2003-12-06 23:55:10 +0000237 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000238}
wdenk8655b6f2004-10-09 23:25:58 +0000239#endif /* CONFIG_VFD || CONFIG_LCD */
wdenkc6097192002-11-03 00:24:07 +0000240
wdenk3a574cb2005-05-19 22:39:42 +0000241#ifdef CONFIG_SERIAL_TAG
242void setup_serial_tag (struct tag **tmp)
243{
244 struct tag *params = *tmp;
245 struct tag_serialnr serialnr;
246 void get_board_serial(struct tag_serialnr *serialnr);
247
248 get_board_serial(&serialnr);
249 params->hdr.tag = ATAG_SERIAL;
250 params->hdr.size = tag_size (tag_serialnr);
251 params->u.serialnr.low = serialnr.low;
252 params->u.serialnr.high= serialnr.high;
253 params = tag_next (params);
254 *tmp = params;
255}
256#endif
257
wdenk289f9322005-01-12 00:15:14 +0000258#ifdef CONFIG_REVISION_TAG
259void setup_revision_tag(struct tag **in_params)
260{
261 u32 rev = 0;
wdenk289f9322005-01-12 00:15:14 +0000262 u32 get_board_rev(void);
263
264 rev = get_board_rev();
wdenk289f9322005-01-12 00:15:14 +0000265 params->hdr.tag = ATAG_REVISION;
266 params->hdr.size = tag_size (tag_revision);
267 params->u.revision.rev = rev;
268 params = tag_next (params);
269}
270#endif /* CONFIG_REVISION_TAG */
271
272
wdenk5779d8d2003-12-06 23:55:10 +0000273static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000274{
wdenk5779d8d2003-12-06 23:55:10 +0000275 params->hdr.tag = ATAG_NONE;
276 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000277}
278
279#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */