3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
6 * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
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.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
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
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <u-boot/zlib.h>
28 #include <asm/byteorder.h>
30 DECLARE_GLOBAL_DATA_PTR;
32 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
33 defined (CONFIG_CMDLINE_TAG) || \
34 defined (CONFIG_INITRD_TAG) || \
35 defined (CONFIG_SERIAL_TAG) || \
36 defined (CONFIG_REVISION_TAG)
37 static void setup_start_tag (bd_t *bd);
39 # ifdef CONFIG_SETUP_MEMORY_TAGS
40 static void setup_memory_tags (bd_t *bd);
42 static void setup_commandline_tag (bd_t *bd, char *commandline);
44 # ifdef CONFIG_INITRD_TAG
45 static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
48 static void setup_end_tag (bd_t *bd);
50 static struct tag *params;
51 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
53 int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
57 int machid = bd->bi_arch_number;
58 void (*theKernel)(int zero, int arch, uint params);
60 #ifdef CONFIG_CMDLINE_TAG
61 char *commandline = getenv ("bootargs");
64 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
67 theKernel = (void (*)(int, int, uint))images->ep;
69 s = getenv ("machid");
71 machid = simple_strtoul (s, NULL, 16);
72 printf ("Using machid 0x%x from environment\n", machid);
75 show_boot_progress (15);
77 debug ("## Transferring control to Linux (at address %08lx) ...\n",
80 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
81 defined (CONFIG_CMDLINE_TAG) || \
82 defined (CONFIG_INITRD_TAG) || \
83 defined (CONFIG_SERIAL_TAG) || \
84 defined (CONFIG_REVISION_TAG)
86 #ifdef CONFIG_SERIAL_TAG
87 setup_serial_tag (¶ms);
89 #ifdef CONFIG_REVISION_TAG
90 setup_revision_tag (¶ms);
92 #ifdef CONFIG_SETUP_MEMORY_TAGS
93 setup_memory_tags (bd);
95 #ifdef CONFIG_CMDLINE_TAG
96 setup_commandline_tag (bd, commandline);
98 #ifdef CONFIG_INITRD_TAG
99 if (images->rd_start && images->rd_end)
100 setup_initrd_tag (bd, images->rd_start, images->rd_end);
105 /* we assume that the kernel is in place */
106 printf ("\nStarting kernel ...\n\n");
108 #ifdef CONFIG_USB_DEVICE
110 extern void udc_disconnect (void);
115 cleanup_before_linux ();
117 theKernel (0, machid, bd->bi_boot_params);
118 /* does not return */
124 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
125 defined (CONFIG_CMDLINE_TAG) || \
126 defined (CONFIG_INITRD_TAG) || \
127 defined (CONFIG_SERIAL_TAG) || \
128 defined (CONFIG_REVISION_TAG)
129 static void setup_start_tag (bd_t *bd)
131 params = (struct tag *) bd->bi_boot_params;
133 params->hdr.tag = ATAG_CORE;
134 params->hdr.size = tag_size (tag_core);
136 params->u.core.flags = 0;
137 params->u.core.pagesize = 0;
138 params->u.core.rootdev = 0;
140 params = tag_next (params);
144 #ifdef CONFIG_SETUP_MEMORY_TAGS
145 static void setup_memory_tags (bd_t *bd)
149 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
150 params->hdr.tag = ATAG_MEM;
151 params->hdr.size = tag_size (tag_mem32);
153 params->u.mem.start = bd->bi_dram[i].start;
154 params->u.mem.size = bd->bi_dram[i].size;
156 params = tag_next (params);
159 #endif /* CONFIG_SETUP_MEMORY_TAGS */
162 static void setup_commandline_tag (bd_t *bd, char *commandline)
169 /* eat leading white space */
170 for (p = commandline; *p == ' '; p++);
172 /* skip non-existent command lines so the kernel will still
173 * use its default command line.
178 params->hdr.tag = ATAG_CMDLINE;
180 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
182 strcpy (params->u.cmdline.cmdline, p);
184 params = tag_next (params);
188 #ifdef CONFIG_INITRD_TAG
189 static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
191 /* an ATAG_INITRD node tells the kernel where the compressed
192 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
194 params->hdr.tag = ATAG_INITRD2;
195 params->hdr.size = tag_size (tag_initrd);
197 params->u.initrd.start = initrd_start;
198 params->u.initrd.size = initrd_end - initrd_start;
200 params = tag_next (params);
202 #endif /* CONFIG_INITRD_TAG */
204 #ifdef CONFIG_SERIAL_TAG
205 void setup_serial_tag (struct tag **tmp)
207 struct tag *params = *tmp;
208 struct tag_serialnr serialnr;
209 void get_board_serial(struct tag_serialnr *serialnr);
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);
221 #ifdef CONFIG_REVISION_TAG
222 void setup_revision_tag(struct tag **in_params)
225 u32 get_board_rev(void);
227 rev = get_board_rev();
228 params->hdr.tag = ATAG_REVISION;
229 params->hdr.size = tag_size (tag_revision);
230 params->u.revision.rev = rev;
231 params = tag_next (params);
233 #endif /* CONFIG_REVISION_TAG */
236 static void setup_end_tag (bd_t *bd)
238 params->hdr.tag = ATAG_NONE;
239 params->hdr.size = 0;
242 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */