blob: 310132126cd6d2d341ff7c31d25dab9213eb1792 [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>
Jean-Christophe PLAGNIOL-VILLARDa31e0912009-04-04 12:49:11 +020027#include <u-boot/zlib.h>
wdenkc6097192002-11-03 00:24:07 +000028#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) || \
Minkyu Kang47ea6ed2010-06-18 19:31:10 +090036 defined (CONFIG_REVISION_TAG)
wdenk5779d8d2003-12-06 23:55:10 +000037static void setup_start_tag (bd_t *bd);
38
wdenk699b13a2002-11-03 18:03:52 +000039# ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +000040static void setup_memory_tags (bd_t *bd);
wdenk699b13a2002-11-03 18:03:52 +000041# endif
wdenk5779d8d2003-12-06 23:55:10 +000042static void setup_commandline_tag (bd_t *bd, char *commandline);
43
wdenk699b13a2002-11-03 18:03:52 +000044# ifdef CONFIG_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +000045static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
46 ulong initrd_end);
wdenk699b13a2002-11-03 18:03:52 +000047# endif
wdenk5779d8d2003-12-06 23:55:10 +000048static void setup_end_tag (bd_t *bd);
49
wdenkc6097192002-11-03 00:24:07 +000050static struct tag *params;
51#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
52
Wolfgang Denk54841ab2010-06-28 22:00:46 +020053int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images)
wdenkc6097192002-11-03 00:24:07 +000054{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +010055 bd_t *bd = gd->bd;
56 char *s;
57 int machid = bd->bi_arch_number;
58 void (*theKernel)(int zero, int arch, uint params);
wdenk5779d8d2003-12-06 23:55:10 +000059
wdenkc6097192002-11-03 00:24:07 +000060#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +000061 char *commandline = getenv ("bootargs");
wdenkc6097192002-11-03 00:24:07 +000062#endif
63
Ilko Iliev263b7492008-11-09 15:53:14 +010064 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
Kumar Gala49c3a862008-10-21 17:25:45 -050065 return 1;
66
Kumar Galac160a952008-08-15 08:24:36 -050067 theKernel = (void (*)(int, int, uint))images->ep;
wdenkc6097192002-11-03 00:24:07 +000068
Uwe Kleine-König3c234ef2008-01-30 09:08:49 +010069 s = getenv ("machid");
70 if (s) {
71 machid = simple_strtoul (s, NULL, 16);
72 printf ("Using machid 0x%x from environment\n", machid);
73 }
74
Heiko Schocherfad63402007-07-13 09:54:17 +020075 show_boot_progress (15);
wdenk384ae022002-11-05 00:17:55 +000076
wdenk5779d8d2003-12-06 23:55:10 +000077 debug ("## Transferring control to Linux (at address %08lx) ...\n",
78 (ulong) theKernel);
wdenkc6097192002-11-03 00:24:07 +000079
80#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
81 defined (CONFIG_CMDLINE_TAG) || \
82 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +000083 defined (CONFIG_SERIAL_TAG) || \
Minkyu Kang47ea6ed2010-06-18 19:31:10 +090084 defined (CONFIG_REVISION_TAG)
wdenk5779d8d2003-12-06 23:55:10 +000085 setup_start_tag (bd);
wdenkb6e4c402004-01-02 16:05:07 +000086#ifdef CONFIG_SERIAL_TAG
87 setup_serial_tag (&params);
88#endif
89#ifdef CONFIG_REVISION_TAG
90 setup_revision_tag (&params);
91#endif
wdenkc6097192002-11-03 00:24:07 +000092#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +000093 setup_memory_tags (bd);
wdenkc6097192002-11-03 00:24:07 +000094#endif
95#ifdef CONFIG_CMDLINE_TAG
wdenk5779d8d2003-12-06 23:55:10 +000096 setup_commandline_tag (bd, commandline);
wdenkc6097192002-11-03 00:24:07 +000097#endif
98#ifdef CONFIG_INITRD_TAG
Kumar Galac4f94192008-08-15 08:24:37 -050099 if (images->rd_start && images->rd_end)
100 setup_initrd_tag (bd, images->rd_start, images->rd_end);
wdenkc6097192002-11-03 00:24:07 +0000101#endif
wdenk5779d8d2003-12-06 23:55:10 +0000102 setup_end_tag (bd);
wdenkc6097192002-11-03 00:24:07 +0000103#endif
104
wdenk5779d8d2003-12-06 23:55:10 +0000105 /* we assume that the kernel is in place */
106 printf ("\nStarting kernel ...\n\n");
wdenkc6097192002-11-03 00:24:07 +0000107
wdenk232c1502004-03-12 00:14:09 +0000108#ifdef CONFIG_USB_DEVICE
109 {
110 extern void udc_disconnect (void);
111 udc_disconnect ();
112 }
113#endif
114
wdenk5779d8d2003-12-06 23:55:10 +0000115 cleanup_before_linux ();
wdenkc6097192002-11-03 00:24:07 +0000116
Uwe Kleine-König3c234ef2008-01-30 09:08:49 +0100117 theKernel (0, machid, bd->bi_boot_params);
Marian Balakowiczcd7c5962008-03-12 10:33:00 +0100118 /* does not return */
Wolfgang Denk10551712008-09-08 23:26:22 +0200119
Kumar Gala40d7e992008-08-15 08:24:45 -0500120 return 1;
wdenkc6097192002-11-03 00:24:07 +0000121}
122
123
124#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
125 defined (CONFIG_CMDLINE_TAG) || \
126 defined (CONFIG_INITRD_TAG) || \
wdenkb6e4c402004-01-02 16:05:07 +0000127 defined (CONFIG_SERIAL_TAG) || \
Minkyu Kang47ea6ed2010-06-18 19:31:10 +0900128 defined (CONFIG_REVISION_TAG)
wdenk5779d8d2003-12-06 23:55:10 +0000129static void setup_start_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000130{
wdenk5779d8d2003-12-06 23:55:10 +0000131 params = (struct tag *) bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000132
wdenk5779d8d2003-12-06 23:55:10 +0000133 params->hdr.tag = ATAG_CORE;
134 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000135
wdenk5779d8d2003-12-06 23:55:10 +0000136 params->u.core.flags = 0;
137 params->u.core.pagesize = 0;
138 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000139
wdenk5779d8d2003-12-06 23:55:10 +0000140 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000141}
142
143
wdenk699b13a2002-11-03 18:03:52 +0000144#ifdef CONFIG_SETUP_MEMORY_TAGS
wdenk5779d8d2003-12-06 23:55:10 +0000145static void setup_memory_tags (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000146{
wdenk5779d8d2003-12-06 23:55:10 +0000147 int i;
wdenkc6097192002-11-03 00:24:07 +0000148
wdenk5779d8d2003-12-06 23:55:10 +0000149 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
150 params->hdr.tag = ATAG_MEM;
151 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000152
wdenk5779d8d2003-12-06 23:55:10 +0000153 params->u.mem.start = bd->bi_dram[i].start;
154 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000155
wdenk5779d8d2003-12-06 23:55:10 +0000156 params = tag_next (params);
157 }
wdenkc6097192002-11-03 00:24:07 +0000158}
wdenk5779d8d2003-12-06 23:55:10 +0000159#endif /* CONFIG_SETUP_MEMORY_TAGS */
wdenkc6097192002-11-03 00:24:07 +0000160
161
wdenk5779d8d2003-12-06 23:55:10 +0000162static void setup_commandline_tag (bd_t *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000163{
wdenk5779d8d2003-12-06 23:55:10 +0000164 char *p;
wdenkc6097192002-11-03 00:24:07 +0000165
wdenk109c0e32004-03-23 21:43:07 +0000166 if (!commandline)
167 return;
168
wdenk5779d8d2003-12-06 23:55:10 +0000169 /* eat leading white space */
170 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000171
wdenk5779d8d2003-12-06 23:55:10 +0000172 /* skip non-existent command lines so the kernel will still
173 * use its default command line.
174 */
175 if (*p == '\0')
176 return;
wdenkc6097192002-11-03 00:24:07 +0000177
wdenk5779d8d2003-12-06 23:55:10 +0000178 params->hdr.tag = ATAG_CMDLINE;
179 params->hdr.size =
180 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000181
wdenk5779d8d2003-12-06 23:55:10 +0000182 strcpy (params->u.cmdline.cmdline, p);
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_INITRD_TAG
wdenk5779d8d2003-12-06 23:55:10 +0000189static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000190{
wdenk5779d8d2003-12-06 23:55:10 +0000191 /* an ATAG_INITRD node tells the kernel where the compressed
192 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
193 */
wdenk498b8db2004-04-18 22:26:17 +0000194 params->hdr.tag = ATAG_INITRD2;
wdenk5779d8d2003-12-06 23:55:10 +0000195 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000196
wdenk5779d8d2003-12-06 23:55:10 +0000197 params->u.initrd.start = initrd_start;
198 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000199
wdenk5779d8d2003-12-06 23:55:10 +0000200 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000201}
wdenk5779d8d2003-12-06 23:55:10 +0000202#endif /* CONFIG_INITRD_TAG */
wdenkc6097192002-11-03 00:24:07 +0000203
wdenk3a574cb2005-05-19 22:39:42 +0000204#ifdef CONFIG_SERIAL_TAG
205void setup_serial_tag (struct tag **tmp)
206{
207 struct tag *params = *tmp;
208 struct tag_serialnr serialnr;
209 void get_board_serial(struct tag_serialnr *serialnr);
210
211 get_board_serial(&serialnr);
212 params->hdr.tag = ATAG_SERIAL;
213 params->hdr.size = tag_size (tag_serialnr);
214 params->u.serialnr.low = serialnr.low;
215 params->u.serialnr.high= serialnr.high;
216 params = tag_next (params);
217 *tmp = params;
218}
219#endif
220
wdenk289f9322005-01-12 00:15:14 +0000221#ifdef CONFIG_REVISION_TAG
222void setup_revision_tag(struct tag **in_params)
223{
224 u32 rev = 0;
wdenk289f9322005-01-12 00:15:14 +0000225 u32 get_board_rev(void);
226
227 rev = get_board_rev();
wdenk289f9322005-01-12 00:15:14 +0000228 params->hdr.tag = ATAG_REVISION;
229 params->hdr.size = tag_size (tag_revision);
230 params->u.revision.rev = rev;
231 params = tag_next (params);
232}
233#endif /* CONFIG_REVISION_TAG */
234
235
wdenk5779d8d2003-12-06 23:55:10 +0000236static void setup_end_tag (bd_t *bd)
wdenkc6097192002-11-03 00:24:07 +0000237{
wdenk5779d8d2003-12-06 23:55:10 +0000238 params->hdr.tag = ATAG_NONE;
239 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000240}
241
242#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */