blob: f9f702fff75db015fe98677e929c710f5a9b490d [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
wdenk29e7f5a2004-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
wdenk29e7f5a2004-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 Denk6405a152006-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) || \
wdenkbc01dd52004-01-02 16:05:07 +000035 defined (CONFIG_SERIAL_TAG) || \
36 defined (CONFIG_REVISION_TAG) || \
wdenk9ca7bbc2004-10-09 23:25:58 +000037 defined (CONFIG_VFD) || \
38 defined (CONFIG_LCD)
wdenk86765902003-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
wdenk86765902003-12-06 23:55:10 +000042static void setup_memory_tags (bd_t *bd);
wdenk699b13a2002-11-03 18:03:52 +000043# endif
wdenk86765902003-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
wdenk86765902003-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
wdenk86765902003-12-06 23:55:10 +000050static void setup_end_tag (bd_t *bd);
51
wdenk9ca7bbc2004-10-09 23:25:58 +000052# if defined (CONFIG_VFD) || defined (CONFIG_LCD)
wdenk86765902003-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 Balakowiczdbdd16a2008-02-04 08:28:09 +010059extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
60
wdenk86765902003-12-06 23:55:10 +000061void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +010062 bootm_headers_t *images)
wdenkc6097192002-11-03 00:24:07 +000063{
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +010064 bd_t *bd = gd->bd;
65 char *s;
66 int machid = bd->bi_arch_number;
67 void (*theKernel)(int zero, int arch, uint params);
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010068 int ret;
wdenk86765902003-12-06 23:55:10 +000069
wdenkc6097192002-11-03 00:24:07 +000070#ifdef CONFIG_CMDLINE_TAG
wdenk86765902003-12-06 23:55:10 +000071 char *commandline = getenv ("bootargs");
wdenkc6097192002-11-03 00:24:07 +000072#endif
73
Kumar Gala93467bc2008-08-15 08:24:36 -050074 theKernel = (void (*)(int, int, uint))images->ep;
wdenkc6097192002-11-03 00:24:07 +000075
Uwe Kleine-König533937d2008-01-30 09:08:49 +010076 s = getenv ("machid");
77 if (s) {
78 machid = simple_strtoul (s, NULL, 16);
79 printf ("Using machid 0x%x from environment\n", machid);
80 }
81
Heiko Schocher8a8ec532007-07-13 09:54:17 +020082 show_boot_progress (15);
wdenk384ae022002-11-05 00:17:55 +000083
wdenk86765902003-12-06 23:55:10 +000084 debug ("## Transferring control to Linux (at address %08lx) ...\n",
85 (ulong) theKernel);
wdenkc6097192002-11-03 00:24:07 +000086
87#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
88 defined (CONFIG_CMDLINE_TAG) || \
89 defined (CONFIG_INITRD_TAG) || \
wdenkbc01dd52004-01-02 16:05:07 +000090 defined (CONFIG_SERIAL_TAG) || \
91 defined (CONFIG_REVISION_TAG) || \
wdenk9ca7bbc2004-10-09 23:25:58 +000092 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +000093 defined (CONFIG_VFD)
wdenk86765902003-12-06 23:55:10 +000094 setup_start_tag (bd);
wdenkbc01dd52004-01-02 16:05:07 +000095#ifdef CONFIG_SERIAL_TAG
96 setup_serial_tag (&params);
97#endif
98#ifdef CONFIG_REVISION_TAG
99 setup_revision_tag (&params);
100#endif
wdenkc6097192002-11-03 00:24:07 +0000101#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk86765902003-12-06 23:55:10 +0000102 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +0000103#endif
104#ifdef CONFIG_CMDLINE_TAG
wdenk86765902003-12-06 23:55:10 +0000105 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +0000106#endif
107#ifdef CONFIG_INITRD_TAG
Kumar Galafffb1432008-08-15 08:24:37 -0500108 if (images->rd_start && images->rd_end)
109 setup_initrd_tag (bd, images->rd_start, images->rd_end);
wdenkc6097192002-11-03 00:24:07 +0000110#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000111#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
wdenk86765902003-12-06 23:55:10 +0000112 setup_videolfb_tag ((gd_t *) gd);
wdenkc6097192002-11-03 00:24:07 +0000113#endif
wdenk86765902003-12-06 23:55:10 +0000114 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000115#endif
116
wdenk86765902003-12-06 23:55:10 +0000117 /* we assume that the kernel is in place */
118 printf ("\nStarting kernel ...\n\n");
wdenkc6097192002-11-03 00:24:07 +0000119
wdenk29e7f5a2004-03-12 00:14:09 +0000120#ifdef CONFIG_USB_DEVICE
121 {
122 extern void udc_disconnect (void);
123 udc_disconnect ();
124 }
125#endif
126
wdenk86765902003-12-06 23:55:10 +0000127 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000128
Uwe Kleine-König533937d2008-01-30 09:08:49 +0100129 theKernel (0, machid, bd->bi_boot_params);
Marian Balakowiczdf8ff332008-03-12 10:33:00 +0100130 /* does not return */
131 return;
132
133error:
Kumar Gala026e4ac2008-08-11 09:20:53 -0500134 do_reset (cmdtp, flag, argc, argv);
Marian Balakowiczdf8ff332008-03-12 10:33:00 +0100135 return;
wdenkc6097192002-11-03 00:24:07 +0000136}
137
138
139#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
140 defined (CONFIG_CMDLINE_TAG) || \
141 defined (CONFIG_INITRD_TAG) || \
wdenkbc01dd52004-01-02 16:05:07 +0000142 defined (CONFIG_SERIAL_TAG) || \
143 defined (CONFIG_REVISION_TAG) || \
wdenk9ca7bbc2004-10-09 23:25:58 +0000144 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +0000145 defined (CONFIG_VFD)
wdenk86765902003-12-06 23:55:10 +0000146static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000147{
wdenk86765902003-12-06 23:55:10 +0000148 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000149
wdenk86765902003-12-06 23:55:10 +0000150 params->hdr.tag = ATAG_CORE;
151 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000152
wdenk86765902003-12-06 23:55:10 +0000153 params->u.core.flags = 0;
154 params->u.core.pagesize = 0;
155 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000156
wdenk86765902003-12-06 23:55:10 +0000157 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000158}
159
160
wdenk699b13a2002-11-03 18:03:52 +0000161#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk86765902003-12-06 23:55:10 +0000162static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000163{
wdenk86765902003-12-06 23:55:10 +0000164 int i;
wdenkc6097192002-11-03 00:24:07 +0000165
wdenk86765902003-12-06 23:55:10 +0000166 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
167 params->hdr.tag = ATAG_MEM;
168 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000169
wdenk86765902003-12-06 23:55:10 +0000170 params->u.mem.start = bd->bi_dram[i].start;
171 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000172
wdenk86765902003-12-06 23:55:10 +0000173 params = tag_next (params);
174 }
wdenkc6097192002-11-03 00:24:07 +0000175}
wdenk86765902003-12-06 23:55:10 +0000176#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000177
178
wdenk86765902003-12-06 23:55:10 +0000179static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000180{
wdenk86765902003-12-06 23:55:10 +0000181 char *p;
wdenkc6097192002-11-03 00:24:07 +0000182
wdenkf16b5162004-03-23 21:43:07 +0000183 if (!commandline)
184 return;
185
wdenk86765902003-12-06 23:55:10 +0000186 /* eat leading white space */
187 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000188
wdenk86765902003-12-06 23:55:10 +0000189 /* skip non-existent command lines so the kernel will still
190 * use its default command line.
191 */
192 if (*p == '\0')
193 return;
wdenkc6097192002-11-03 00:24:07 +0000194
wdenk86765902003-12-06 23:55:10 +0000195 params->hdr.tag = ATAG_CMDLINE;
196 params->hdr.size =
197 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000198
wdenk86765902003-12-06 23:55:10 +0000199 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000200
wdenk86765902003-12-06 23:55:10 +0000201 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000202}
203
204
wdenk699b13a2002-11-03 18:03:52 +0000205#ifdef CONFIG_INITRD_TAG
wdenk86765902003-12-06 23:55:10 +0000206static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000207{
wdenk86765902003-12-06 23:55:10 +0000208 /* an ATAG_INITRD node tells the kernel where the compressed
209 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
210 */
wdenk19c8fb72004-04-18 22:26:17 +0000211 params->hdr.tag = ATAG_INITRD2;
wdenk86765902003-12-06 23:55:10 +0000212 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000213
wdenk86765902003-12-06 23:55:10 +0000214 params->u.initrd.start = initrd_start;
215 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000216
wdenk86765902003-12-06 23:55:10 +0000217 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000218}
wdenk86765902003-12-06 23:55:10 +0000219#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000220
wdenkc6097192002-11-03 00:24:07 +0000221
wdenk9ca7bbc2004-10-09 23:25:58 +0000222#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
223extern ulong calc_fbsize (void);
wdenk86765902003-12-06 23:55:10 +0000224static void setup_videolfb_tag (gd_t *gd)
wdenkc6097192002-11-03 00:24:07 +0000225{
wdenk86765902003-12-06 23:55:10 +0000226 /* An ATAG_VIDEOLFB node tells the kernel where and how large
227 * the framebuffer for video was allocated (among other things).
228 * Note that a _physical_ address is passed !
229 *
230 * We only use it to pass the address and size, the other entries
231 * in the tag_videolfb are not of interest.
232 */
233 params->hdr.tag = ATAG_VIDEOLFB;
234 params->hdr.size = tag_size (tag_videolfb);
wdenkc6097192002-11-03 00:24:07 +0000235
wdenk86765902003-12-06 23:55:10 +0000236 params->u.videolfb.lfb_base = (u32) gd->fb_base;
wdenk9ca7bbc2004-10-09 23:25:58 +0000237 /* Fb size is calculated according to parameters for our panel
238 */
239 params->u.videolfb.lfb_size = calc_fbsize();
wdenkc6097192002-11-03 00:24:07 +0000240
wdenk86765902003-12-06 23:55:10 +0000241 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000242}
wdenk9ca7bbc2004-10-09 23:25:58 +0000243#endif /* CONFIG_VFD || CONFIG_LCD */
wdenkc6097192002-11-03 00:24:07 +0000244
wdenka21ad7b2005-05-19 22:39:42 +0000245#ifdef CONFIG_SERIAL_TAG
246void setup_serial_tag (struct tag **tmp)
247{
248 struct tag *params = *tmp;
249 struct tag_serialnr serialnr;
250 void get_board_serial(struct tag_serialnr *serialnr);
251
252 get_board_serial(&serialnr);
253 params->hdr.tag = ATAG_SERIAL;
254 params->hdr.size = tag_size (tag_serialnr);
255 params->u.serialnr.low = serialnr.low;
256 params->u.serialnr.high= serialnr.high;
257 params = tag_next (params);
258 *tmp = params;
259}
260#endif
261
wdenkcb99da52005-01-12 00:15:14 +0000262#ifdef CONFIG_REVISION_TAG
263void setup_revision_tag(struct tag **in_params)
264{
265 u32 rev = 0;
wdenkcb99da52005-01-12 00:15:14 +0000266 u32 get_board_rev(void);
267
268 rev = get_board_rev();
wdenkcb99da52005-01-12 00:15:14 +0000269 params->hdr.tag = ATAG_REVISION;
270 params->hdr.size = tag_size (tag_revision);
271 params->u.revision.rev = rev;
272 params = tag_next (params);
273}
274#endif /* CONFIG_REVISION_TAG */
275
276
wdenk86765902003-12-06 23:55:10 +0000277static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000278{
wdenk86765902003-12-06 23:55:10 +0000279 params->hdr.tag = ATAG_NONE;
280 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000281}
282
283#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */