blob: b838c374ac6aed033106b8ec91d100565eefab20 [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;
65 ulong ep = 0;
66 bd_t *bd = gd->bd;
67 char *s;
68 int machid = bd->bi_arch_number;
69 void (*theKernel)(int zero, int arch, uint params);
Marian Balakowiczcd7c5962008-03-12 10:33:00 +010070 int ret;
wdenk5779d8d2003-12-06 23:55:10 +000071
wdenkc6097192002-11-03 00:24:07 +000072#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +000073 char *commandline = getenv ("bootargs");
wdenkc6097192002-11-03 00:24:07 +000074#endif
75
Marian Balakowiczd5934ad2008-02-04 08:28:09 +010076 /* find kernel entry point */
77 if (images->legacy_hdr_valid) {
Marian Balakowiczcb1c4892008-04-11 11:07:49 +020078 ep = image_get_ep (&images->legacy_hdr_os_copy);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +010079#if defined(CONFIG_FIT)
80 } else if (images->fit_uname_os) {
Marian Balakowiczcd7c5962008-03-12 10:33:00 +010081 ret = fit_image_get_entry (images->fit_hdr_os,
82 images->fit_noffset_os, &ep);
83 if (ret) {
84 puts ("Can't get entry point property!\n");
85 goto error;
86 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +010087#endif
88 } else {
89 puts ("Could not find kernel entry point!\n");
Marian Balakowiczcd7c5962008-03-12 10:33:00 +010090 goto error;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +010091 }
92 theKernel = (void (*)(int, int, uint))ep;
wdenkc6097192002-11-03 00:24:07 +000093
Uwe Kleine-König3c234ef2008-01-30 09:08:49 +010094 s = getenv ("machid");
95 if (s) {
96 machid = simple_strtoul (s, NULL, 16);
97 printf ("Using machid 0x%x from environment\n", machid);
98 }
99
Marian Balakowiczd985c842008-03-12 10:14:38 +0100100 ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_ARM,
101 &initrd_start, &initrd_end);
102 if (ret)
Marian Balakowiczcd7c5962008-03-12 10:33:00 +0100103 goto error;
wdenkc6097192002-11-03 00:24:07 +0000104
Heiko Schocherfad63402007-07-13 09:54:17 +0200105 show_boot_progress (15);
wdenk384ae022002-11-05 00:17:55 +0000106
wdenk5779d8d2003-12-06 23:55:10 +0000107 debug ("## Transferring control to Linux (at address %08lx) ...\n",
108 (ulong) theKernel);
wdenkc6097192002-11-03 00:24:07 +0000109
110#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
111 defined (CONFIG_CMDLINE_TAG) || \
112 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000113 defined (CONFIG_SERIAL_TAG) || \
114 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +0000115 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +0000116 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000117 setup_start_tag (bd);
wdenkb6e4c402004-01-02 16:05:07 +0000118#ifdef CONFIG_SERIAL_TAG
119 setup_serial_tag (&params);
120#endif
121#ifdef CONFIG_REVISION_TAG
122 setup_revision_tag (&params);
123#endif
wdenkc6097192002-11-03 00:24:07 +0000124#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000125 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +0000126#endif
127#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000128 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +0000129#endif
130#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000131 if (initrd_start && initrd_end)
132 setup_initrd_tag (bd, initrd_start, initrd_end);
wdenkc6097192002-11-03 00:24:07 +0000133#endif
wdenk8655b6f2004-10-09 23:25:58 +0000134#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
wdenk5779d8d2003-12-06 23:55:10 +0000135 setup_videolfb_tag ((gd_t *) gd);
wdenkc6097192002-11-03 00:24:07 +0000136#endif
wdenk5779d8d2003-12-06 23:55:10 +0000137 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000138#endif
139
Kumar Gala75fa0022008-02-27 21:51:51 -0600140 if (!images->autostart)
141 return ;
142
wdenk5779d8d2003-12-06 23:55:10 +0000143 /* we assume that the kernel is in place */
144 printf ("\nStarting kernel ...\n\n");
wdenkc6097192002-11-03 00:24:07 +0000145
wdenk232c1502004-03-12 00:14:09 +0000146#ifdef CONFIG_USB_DEVICE
147 {
148 extern void udc_disconnect (void);
149 udc_disconnect ();
150 }
151#endif
152
wdenk5779d8d2003-12-06 23:55:10 +0000153 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000154
Uwe Kleine-König3c234ef2008-01-30 09:08:49 +0100155 theKernel (0, machid, bd->bi_boot_params);
Marian Balakowiczcd7c5962008-03-12 10:33:00 +0100156 /* does not return */
157 return;
158
159error:
160 if (images->autostart)
161 do_reset (cmdtp, flag, argc, argv);
162 return;
wdenkc6097192002-11-03 00:24:07 +0000163}
164
165
166#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
167 defined (CONFIG_CMDLINE_TAG) || \
168 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000169 defined (CONFIG_SERIAL_TAG) || \
170 defined (CONFIG_REVISION_TAG) || \
wdenk8655b6f2004-10-09 23:25:58 +0000171 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +0000172 defined (CONFIG_VFD)
wdenk5779d8d2003-12-06 23:55:10 +0000173static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000174{
wdenk5779d8d2003-12-06 23:55:10 +0000175 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000176
wdenk5779d8d2003-12-06 23:55:10 +0000177 params->hdr.tag = ATAG_CORE;
178 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000179
wdenk5779d8d2003-12-06 23:55:10 +0000180 params->u.core.flags = 0;
181 params->u.core.pagesize = 0;
182 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000183
wdenk5779d8d2003-12-06 23:55:10 +0000184 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000185}
186
187
wdenk699b13a2002-11-03 18:03:52 +0000188#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000189static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000190{
wdenk5779d8d2003-12-06 23:55:10 +0000191 int i;
wdenkc6097192002-11-03 00:24:07 +0000192
wdenk5779d8d2003-12-06 23:55:10 +0000193 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
194 params->hdr.tag = ATAG_MEM;
195 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000196
wdenk5779d8d2003-12-06 23:55:10 +0000197 params->u.mem.start = bd->bi_dram[i].start;
198 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000199
wdenk5779d8d2003-12-06 23:55:10 +0000200 params = tag_next (params);
201 }
wdenkc6097192002-11-03 00:24:07 +0000202}
wdenk5779d8d2003-12-06 23:55:10 +0000203#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000204
205
wdenk5779d8d2003-12-06 23:55:10 +0000206static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000207{
wdenk5779d8d2003-12-06 23:55:10 +0000208 char *p;
wdenkc6097192002-11-03 00:24:07 +0000209
wdenk109c0e32004-03-23 21:43:07 +0000210 if (!commandline)
211 return;
212
wdenk5779d8d2003-12-06 23:55:10 +0000213 /* eat leading white space */
214 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000215
wdenk5779d8d2003-12-06 23:55:10 +0000216 /* skip non-existent command lines so the kernel will still
217 * use its default command line.
218 */
219 if (*p == '\0')
220 return;
wdenkc6097192002-11-03 00:24:07 +0000221
wdenk5779d8d2003-12-06 23:55:10 +0000222 params->hdr.tag = ATAG_CMDLINE;
223 params->hdr.size =
224 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000225
wdenk5779d8d2003-12-06 23:55:10 +0000226 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000227
wdenk5779d8d2003-12-06 23:55:10 +0000228 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000229}
230
231
wdenk699b13a2002-11-03 18:03:52 +0000232#ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000233static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000234{
wdenk5779d8d2003-12-06 23:55:10 +0000235 /* an ATAG_INITRD node tells the kernel where the compressed
236 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
237 */
wdenk498b8db2004-04-18 22:26:17 +0000238 params->hdr.tag = ATAG_INITRD2;
wdenk5779d8d2003-12-06 23:55:10 +0000239 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000240
wdenk5779d8d2003-12-06 23:55:10 +0000241 params->u.initrd.start = initrd_start;
242 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000243
wdenk5779d8d2003-12-06 23:55:10 +0000244 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000245}
wdenk5779d8d2003-12-06 23:55:10 +0000246#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000247
248
wdenk8655b6f2004-10-09 23:25:58 +0000249#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
250extern ulong calc_fbsize (void);
wdenk5779d8d2003-12-06 23:55:10 +0000251static void setup_videolfb_tag (gd_t *gd)
wdenkc6097192002-11-03 00:24:07 +0000252{
wdenk5779d8d2003-12-06 23:55:10 +0000253 /* An ATAG_VIDEOLFB node tells the kernel where and how large
254 * the framebuffer for video was allocated (among other things).
255 * Note that a _physical_ address is passed !
256 *
257 * We only use it to pass the address and size, the other entries
258 * in the tag_videolfb are not of interest.
259 */
260 params->hdr.tag = ATAG_VIDEOLFB;
261 params->hdr.size = tag_size (tag_videolfb);
wdenkc6097192002-11-03 00:24:07 +0000262
wdenk5779d8d2003-12-06 23:55:10 +0000263 params->u.videolfb.lfb_base = (u32) gd->fb_base;
wdenk8655b6f2004-10-09 23:25:58 +0000264 /* Fb size is calculated according to parameters for our panel
265 */
266 params->u.videolfb.lfb_size = calc_fbsize();
wdenkc6097192002-11-03 00:24:07 +0000267
wdenk5779d8d2003-12-06 23:55:10 +0000268 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000269}
wdenk8655b6f2004-10-09 23:25:58 +0000270#endif /* CONFIG_VFD || CONFIG_LCD */
wdenkc6097192002-11-03 00:24:07 +0000271
wdenk3a574cb2005-05-19 22:39:42 +0000272#ifdef CONFIG_SERIAL_TAG
273void setup_serial_tag (struct tag **tmp)
274{
275 struct tag *params = *tmp;
276 struct tag_serialnr serialnr;
277 void get_board_serial(struct tag_serialnr *serialnr);
278
279 get_board_serial(&serialnr);
280 params->hdr.tag = ATAG_SERIAL;
281 params->hdr.size = tag_size (tag_serialnr);
282 params->u.serialnr.low = serialnr.low;
283 params->u.serialnr.high= serialnr.high;
284 params = tag_next (params);
285 *tmp = params;
286}
287#endif
288
wdenk289f9322005-01-12 00:15:14 +0000289#ifdef CONFIG_REVISION_TAG
290void setup_revision_tag(struct tag **in_params)
291{
292 u32 rev = 0;
wdenk289f9322005-01-12 00:15:14 +0000293 u32 get_board_rev(void);
294
295 rev = get_board_rev();
wdenk289f9322005-01-12 00:15:14 +0000296 params->hdr.tag = ATAG_REVISION;
297 params->hdr.size = tag_size (tag_revision);
298 params->u.revision.rev = rev;
299 params = tag_next (params);
300}
301#endif /* CONFIG_REVISION_TAG */
302
303
wdenk5779d8d2003-12-06 23:55:10 +0000304static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000305{
wdenk5779d8d2003-12-06 23:55:10 +0000306 params->hdr.tag = ATAG_NONE;
307 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000308}
309
310#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */