blob: 6b4a80723ff4bfce0ab331b9d52e08a64a032622 [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
wdenkc6097192002-11-03 00:24:07 +000046#if 0
wdenk86765902003-12-06 23:55:10 +000047static void setup_ramdisk_tag (bd_t *bd);
wdenkc6097192002-11-03 00:24:07 +000048#endif
wdenk699b13a2002-11-03 18:03:52 +000049# ifdef CONFIG_INITRD_TAG
wdenk86765902003-12-06 23:55:10 +000050static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
51 ulong initrd_end);
wdenk699b13a2002-11-03 18:03:52 +000052# endif
wdenk86765902003-12-06 23:55:10 +000053static void setup_end_tag (bd_t *bd);
54
wdenk9ca7bbc2004-10-09 23:25:58 +000055# if defined (CONFIG_VFD) || defined (CONFIG_LCD)
wdenk86765902003-12-06 23:55:10 +000056static void setup_videolfb_tag (gd_t *gd);
wdenk699b13a2002-11-03 18:03:52 +000057# endif
wdenkc6097192002-11-03 00:24:07 +000058
wdenkc6097192002-11-03 00:24:07 +000059static struct tag *params;
60#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
61
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +010062extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
63
wdenk86765902003-12-06 23:55:10 +000064void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +010065 bootm_headers_t *images)
wdenkc6097192002-11-03 00:24:07 +000066{
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +010067 ulong initrd_start, initrd_end;
68 ulong ep = 0;
69 bd_t *bd = gd->bd;
70 char *s;
71 int machid = bd->bi_arch_number;
72 void (*theKernel)(int zero, int arch, uint params);
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010073 int ret;
wdenk86765902003-12-06 23:55:10 +000074
wdenkc6097192002-11-03 00:24:07 +000075#ifdef CONFIG_CMDLINE_TAG
wdenk86765902003-12-06 23:55:10 +000076 char *commandline = getenv ("bootargs");
wdenkc6097192002-11-03 00:24:07 +000077#endif
78
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +010079 /* find kernel entry point */
80 if (images->legacy_hdr_valid) {
Marian Balakowiczab00e022008-04-11 11:07:49 +020081 ep = image_get_ep (&images->legacy_hdr_os_copy);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +010082#if defined(CONFIG_FIT)
83 } else if (images->fit_uname_os) {
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010084 ret = fit_image_get_entry (images->fit_hdr_os,
85 images->fit_noffset_os, &ep);
86 if (ret) {
87 puts ("Can't get entry point property!\n");
88 goto error;
89 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +010090#endif
91 } else {
92 puts ("Could not find kernel entry point!\n");
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010093 goto error;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +010094 }
95 theKernel = (void (*)(int, int, uint))ep;
wdenkc6097192002-11-03 00:24:07 +000096
Uwe Kleine-König533937d2008-01-30 09:08:49 +010097 s = getenv ("machid");
98 if (s) {
99 machid = simple_strtoul (s, NULL, 16);
100 printf ("Using machid 0x%x from environment\n", machid);
101 }
102
Marian Balakowicza0ffb422008-03-12 10:14:38 +0100103 ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_ARM,
104 &initrd_start, &initrd_end);
105 if (ret)
Marian Balakowiczdf8ff332008-03-12 10:33:00 +0100106 goto error;
wdenkc6097192002-11-03 00:24:07 +0000107
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200108 show_boot_progress (15);
wdenk384ae022002-11-05 00:17:55 +0000109
wdenk86765902003-12-06 23:55:10 +0000110 debug ("## Transferring control to Linux (at address %08lx) ...\n",
111 (ulong) theKernel);
wdenkc6097192002-11-03 00:24:07 +0000112
113#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
114 defined (CONFIG_CMDLINE_TAG) || \
115 defined (CONFIG_INITRD_TAG) || \
wdenkbc01dd52004-01-02 16:05:07 +0000116 defined (CONFIG_SERIAL_TAG) || \
117 defined (CONFIG_REVISION_TAG) || \
wdenk9ca7bbc2004-10-09 23:25:58 +0000118 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +0000119 defined (CONFIG_VFD)
wdenk86765902003-12-06 23:55:10 +0000120 setup_start_tag (bd);
wdenkbc01dd52004-01-02 16:05:07 +0000121#ifdef CONFIG_SERIAL_TAG
122 setup_serial_tag (&params);
123#endif
124#ifdef CONFIG_REVISION_TAG
125 setup_revision_tag (&params);
126#endif
wdenkc6097192002-11-03 00:24:07 +0000127#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk86765902003-12-06 23:55:10 +0000128 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +0000129#endif
130#ifdef CONFIG_CMDLINE_TAG
wdenk86765902003-12-06 23:55:10 +0000131 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +0000132#endif
133#ifdef CONFIG_INITRD_TAG
wdenk86765902003-12-06 23:55:10 +0000134 if (initrd_start && initrd_end)
135 setup_initrd_tag (bd, initrd_start, initrd_end);
wdenkc6097192002-11-03 00:24:07 +0000136#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000137#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
wdenk86765902003-12-06 23:55:10 +0000138 setup_videolfb_tag ((gd_t *) gd);
wdenkc6097192002-11-03 00:24:07 +0000139#endif
wdenk86765902003-12-06 23:55:10 +0000140 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000141#endif
142
Kumar Galaaa0826b2008-02-27 21:51:51 -0600143 if (!images->autostart)
144 return ;
145
wdenk86765902003-12-06 23:55:10 +0000146 /* we assume that the kernel is in place */
147 printf ("\nStarting kernel ...\n\n");
wdenkc6097192002-11-03 00:24:07 +0000148
wdenk29e7f5a2004-03-12 00:14:09 +0000149#ifdef CONFIG_USB_DEVICE
150 {
151 extern void udc_disconnect (void);
152 udc_disconnect ();
153 }
154#endif
155
wdenk86765902003-12-06 23:55:10 +0000156 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000157
Uwe Kleine-König533937d2008-01-30 09:08:49 +0100158 theKernel (0, machid, bd->bi_boot_params);
Marian Balakowiczdf8ff332008-03-12 10:33:00 +0100159 /* does not return */
160 return;
161
162error:
163 if (images->autostart)
164 do_reset (cmdtp, flag, argc, argv);
165 return;
wdenkc6097192002-11-03 00:24:07 +0000166}
167
168
169#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
170 defined (CONFIG_CMDLINE_TAG) || \
171 defined (CONFIG_INITRD_TAG) || \
wdenkbc01dd52004-01-02 16:05:07 +0000172 defined (CONFIG_SERIAL_TAG) || \
173 defined (CONFIG_REVISION_TAG) || \
wdenk9ca7bbc2004-10-09 23:25:58 +0000174 defined (CONFIG_LCD) || \
wdenkc6097192002-11-03 00:24:07 +0000175 defined (CONFIG_VFD)
wdenk86765902003-12-06 23:55:10 +0000176static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000177{
wdenk86765902003-12-06 23:55:10 +0000178 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000179
wdenk86765902003-12-06 23:55:10 +0000180 params->hdr.tag = ATAG_CORE;
181 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000182
wdenk86765902003-12-06 23:55:10 +0000183 params->u.core.flags = 0;
184 params->u.core.pagesize = 0;
185 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000186
wdenk86765902003-12-06 23:55:10 +0000187 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000188}
189
190
wdenk699b13a2002-11-03 18:03:52 +0000191#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk86765902003-12-06 23:55:10 +0000192static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000193{
wdenk86765902003-12-06 23:55:10 +0000194 int i;
wdenkc6097192002-11-03 00:24:07 +0000195
wdenk86765902003-12-06 23:55:10 +0000196 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
197 params->hdr.tag = ATAG_MEM;
198 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000199
wdenk86765902003-12-06 23:55:10 +0000200 params->u.mem.start = bd->bi_dram[i].start;
201 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000202
wdenk86765902003-12-06 23:55:10 +0000203 params = tag_next (params);
204 }
wdenkc6097192002-11-03 00:24:07 +0000205}
wdenk86765902003-12-06 23:55:10 +0000206#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000207
208
wdenk86765902003-12-06 23:55:10 +0000209static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000210{
wdenk86765902003-12-06 23:55:10 +0000211 char *p;
wdenkc6097192002-11-03 00:24:07 +0000212
wdenkf16b5162004-03-23 21:43:07 +0000213 if (!commandline)
214 return;
215
wdenk86765902003-12-06 23:55:10 +0000216 /* eat leading white space */
217 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000218
wdenk86765902003-12-06 23:55:10 +0000219 /* skip non-existent command lines so the kernel will still
220 * use its default command line.
221 */
222 if (*p == '\0')
223 return;
wdenkc6097192002-11-03 00:24:07 +0000224
wdenk86765902003-12-06 23:55:10 +0000225 params->hdr.tag = ATAG_CMDLINE;
226 params->hdr.size =
227 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000228
wdenk86765902003-12-06 23:55:10 +0000229 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000230
wdenk86765902003-12-06 23:55:10 +0000231 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000232}
233
234
wdenk699b13a2002-11-03 18:03:52 +0000235#ifdef CONFIG_INITRD_TAG
wdenk86765902003-12-06 23:55:10 +0000236static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000237{
wdenk86765902003-12-06 23:55:10 +0000238 /* an ATAG_INITRD node tells the kernel where the compressed
239 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
240 */
wdenk19c8fb72004-04-18 22:26:17 +0000241 params->hdr.tag = ATAG_INITRD2;
wdenk86765902003-12-06 23:55:10 +0000242 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000243
wdenk86765902003-12-06 23:55:10 +0000244 params->u.initrd.start = initrd_start;
245 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000246
wdenk86765902003-12-06 23:55:10 +0000247 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000248}
wdenk86765902003-12-06 23:55:10 +0000249#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000250
wdenkc6097192002-11-03 00:24:07 +0000251
wdenk9ca7bbc2004-10-09 23:25:58 +0000252#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
253extern ulong calc_fbsize (void);
wdenk86765902003-12-06 23:55:10 +0000254static void setup_videolfb_tag (gd_t *gd)
wdenkc6097192002-11-03 00:24:07 +0000255{
wdenk86765902003-12-06 23:55:10 +0000256 /* An ATAG_VIDEOLFB node tells the kernel where and how large
257 * the framebuffer for video was allocated (among other things).
258 * Note that a _physical_ address is passed !
259 *
260 * We only use it to pass the address and size, the other entries
261 * in the tag_videolfb are not of interest.
262 */
263 params->hdr.tag = ATAG_VIDEOLFB;
264 params->hdr.size = tag_size (tag_videolfb);
wdenkc6097192002-11-03 00:24:07 +0000265
wdenk86765902003-12-06 23:55:10 +0000266 params->u.videolfb.lfb_base = (u32) gd->fb_base;
wdenk9ca7bbc2004-10-09 23:25:58 +0000267 /* Fb size is calculated according to parameters for our panel
268 */
269 params->u.videolfb.lfb_size = calc_fbsize();
wdenkc6097192002-11-03 00:24:07 +0000270
wdenk86765902003-12-06 23:55:10 +0000271 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000272}
wdenk9ca7bbc2004-10-09 23:25:58 +0000273#endif /* CONFIG_VFD || CONFIG_LCD */
wdenkc6097192002-11-03 00:24:07 +0000274
wdenka21ad7b2005-05-19 22:39:42 +0000275#ifdef CONFIG_SERIAL_TAG
276void setup_serial_tag (struct tag **tmp)
277{
278 struct tag *params = *tmp;
279 struct tag_serialnr serialnr;
280 void get_board_serial(struct tag_serialnr *serialnr);
281
282 get_board_serial(&serialnr);
283 params->hdr.tag = ATAG_SERIAL;
284 params->hdr.size = tag_size (tag_serialnr);
285 params->u.serialnr.low = serialnr.low;
286 params->u.serialnr.high= serialnr.high;
287 params = tag_next (params);
288 *tmp = params;
289}
290#endif
291
wdenkcb99da52005-01-12 00:15:14 +0000292#ifdef CONFIG_REVISION_TAG
293void setup_revision_tag(struct tag **in_params)
294{
295 u32 rev = 0;
wdenkcb99da52005-01-12 00:15:14 +0000296 u32 get_board_rev(void);
297
298 rev = get_board_rev();
wdenkcb99da52005-01-12 00:15:14 +0000299 params->hdr.tag = ATAG_REVISION;
300 params->hdr.size = tag_size (tag_revision);
301 params->u.revision.rev = rev;
302 params = tag_next (params);
303}
304#endif /* CONFIG_REVISION_TAG */
305
306
wdenk86765902003-12-06 23:55:10 +0000307static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000308{
wdenk86765902003-12-06 23:55:10 +0000309 params->hdr.tag = ATAG_NONE;
310 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000311}
312
313#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */