]> git.ipfire.org Git - people/ms/u-boot.git/blame - lib_arm/bootm.c
ARM: add accessors functions
[people/ms/u-boot.git] / lib_arm / bootm.c
CommitLineData
c609719b
WD
1/*
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
232c150a 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c609719b
WD
16 * 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
232c150a 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
c609719b
WD
21 *
22 */
23
24#include <common.h>
25#include <command.h>
c609719b 26#include <image.h>
a31e091a 27#include <u-boot/zlib.h>
c609719b
WD
28#include <asm/byteorder.h>
29
d87080b7
WD
30DECLARE_GLOBAL_DATA_PTR;
31
c609719b
WD
32#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
33 defined (CONFIG_CMDLINE_TAG) || \
34 defined (CONFIG_INITRD_TAG) || \
b6e4c403
WD
35 defined (CONFIG_SERIAL_TAG) || \
36 defined (CONFIG_REVISION_TAG) || \
8655b6f8
WD
37 defined (CONFIG_VFD) || \
38 defined (CONFIG_LCD)
5779d8d9
WD
39static void setup_start_tag (bd_t *bd);
40
699b13a6 41# ifdef CONFIG_SETUP_MEMORY_TAGS
5779d8d9 42static void setup_memory_tags (bd_t *bd);
699b13a6 43# endif
5779d8d9
WD
44static void setup_commandline_tag (bd_t *bd, char *commandline);
45
699b13a6 46# ifdef CONFIG_INITRD_TAG
5779d8d9
WD
47static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
48 ulong initrd_end);
699b13a6 49# endif
5779d8d9
WD
50static void setup_end_tag (bd_t *bd);
51
8655b6f8 52# if defined (CONFIG_VFD) || defined (CONFIG_LCD)
5779d8d9 53static void setup_videolfb_tag (gd_t *gd);
699b13a6 54# endif
c609719b 55
c609719b
WD
56static struct tag *params;
57#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
58
40d7e99d 59int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
c609719b 60{
d5934ad7
MB
61 bd_t *bd = gd->bd;
62 char *s;
63 int machid = bd->bi_arch_number;
64 void (*theKernel)(int zero, int arch, uint params);
5779d8d9 65
c609719b 66#ifdef CONFIG_CMDLINE_TAG
5779d8d9 67 char *commandline = getenv ("bootargs");
c609719b
WD
68#endif
69
263b749e 70 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
49c3a861
KG
71 return 1;
72
c160a954 73 theKernel = (void (*)(int, int, uint))images->ep;
c609719b 74
3c234efa
UKK
75 s = getenv ("machid");
76 if (s) {
77 machid = simple_strtoul (s, NULL, 16);
78 printf ("Using machid 0x%x from environment\n", machid);
79 }
80
fad63407 81 show_boot_progress (15);
384ae025 82
5779d8d9
WD
83 debug ("## Transferring control to Linux (at address %08lx) ...\n",
84 (ulong) theKernel);
c609719b
WD
85
86#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
87 defined (CONFIG_CMDLINE_TAG) || \
88 defined (CONFIG_INITRD_TAG) || \
b6e4c403
WD
89 defined (CONFIG_SERIAL_TAG) || \
90 defined (CONFIG_REVISION_TAG) || \
8655b6f8 91 defined (CONFIG_LCD) || \
c609719b 92 defined (CONFIG_VFD)
5779d8d9 93 setup_start_tag (bd);
b6e4c403
WD
94#ifdef CONFIG_SERIAL_TAG
95 setup_serial_tag (&params);
96#endif
97#ifdef CONFIG_REVISION_TAG
98 setup_revision_tag (&params);
99#endif
c609719b 100#ifdef CONFIG_SETUP_MEMORY_TAGS
5779d8d9 101 setup_memory_tags (bd);
c609719b
WD
102#endif
103#ifdef CONFIG_CMDLINE_TAG
5779d8d9 104 setup_commandline_tag (bd, commandline);
c609719b
WD
105#endif
106#ifdef CONFIG_INITRD_TAG
c4f9419c
KG
107 if (images->rd_start && images->rd_end)
108 setup_initrd_tag (bd, images->rd_start, images->rd_end);
c609719b 109#endif
8655b6f8 110#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
5779d8d9 111 setup_videolfb_tag ((gd_t *) gd);
c609719b 112#endif
5779d8d9 113 setup_end_tag (bd);
c609719b
WD
114#endif
115
5779d8d9
WD
116 /* we assume that the kernel is in place */
117 printf ("\nStarting kernel ...\n\n");
c609719b 118
232c150a
WD
119#ifdef CONFIG_USB_DEVICE
120 {
121 extern void udc_disconnect (void);
122 udc_disconnect ();
123 }
124#endif
125
5779d8d9 126 cleanup_before_linux ();
c609719b 127
3c234efa 128 theKernel (0, machid, bd->bi_boot_params);
cd7c596e 129 /* does not return */
1055171e 130
40d7e99d 131 return 1;
c609719b
WD
132}
133
134
135#if defined (CONFIG_SETUP_MEMORY_TAGS) || \
136 defined (CONFIG_CMDLINE_TAG) || \
137 defined (CONFIG_INITRD_TAG) || \
b6e4c403
WD
138 defined (CONFIG_SERIAL_TAG) || \
139 defined (CONFIG_REVISION_TAG) || \
8655b6f8 140 defined (CONFIG_LCD) || \
c609719b 141 defined (CONFIG_VFD)
5779d8d9 142static void setup_start_tag (bd_t *bd)
c609719b 143{
5779d8d9 144 params = (struct tag *) bd->bi_boot_params;
c609719b 145
5779d8d9
WD
146 params->hdr.tag = ATAG_CORE;
147 params->hdr.size = tag_size (tag_core);
c609719b 148
5779d8d9
WD
149 params->u.core.flags = 0;
150 params->u.core.pagesize = 0;
151 params->u.core.rootdev = 0;
c609719b 152
5779d8d9 153 params = tag_next (params);
c609719b
WD
154}
155
156
699b13a6 157#ifdef CONFIG_SETUP_MEMORY_TAGS
5779d8d9 158static void setup_memory_tags (bd_t *bd)
c609719b 159{
5779d8d9 160 int i;
c609719b 161
5779d8d9
WD
162 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
163 params->hdr.tag = ATAG_MEM;
164 params->hdr.size = tag_size (tag_mem32);
c609719b 165
5779d8d9
WD
166 params->u.mem.start = bd->bi_dram[i].start;
167 params->u.mem.size = bd->bi_dram[i].size;
c609719b 168
5779d8d9
WD
169 params = tag_next (params);
170 }
c609719b 171}
5779d8d9 172#endif /* CONFIG_SETUP_MEMORY_TAGS */
c609719b
WD
173
174
5779d8d9 175static void setup_commandline_tag (bd_t *bd, char *commandline)
c609719b 176{
5779d8d9 177 char *p;
c609719b 178
109c0e3a
WD
179 if (!commandline)
180 return;
181
5779d8d9
WD
182 /* eat leading white space */
183 for (p = commandline; *p == ' '; p++);
c609719b 184
5779d8d9
WD
185 /* skip non-existent command lines so the kernel will still
186 * use its default command line.
187 */
188 if (*p == '\0')
189 return;
c609719b 190
5779d8d9
WD
191 params->hdr.tag = ATAG_CMDLINE;
192 params->hdr.size =
193 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
c609719b 194
5779d8d9 195 strcpy (params->u.cmdline.cmdline, p);
c609719b 196
5779d8d9 197 params = tag_next (params);
c609719b
WD
198}
199
200
699b13a6 201#ifdef CONFIG_INITRD_TAG
5779d8d9 202static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
c609719b 203{
5779d8d9
WD
204 /* an ATAG_INITRD node tells the kernel where the compressed
205 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
206 */
498b8db7 207 params->hdr.tag = ATAG_INITRD2;
5779d8d9 208 params->hdr.size = tag_size (tag_initrd);
c609719b 209
5779d8d9
WD
210 params->u.initrd.start = initrd_start;
211 params->u.initrd.size = initrd_end - initrd_start;
c609719b 212
5779d8d9 213 params = tag_next (params);
c609719b 214}
5779d8d9 215#endif /* CONFIG_INITRD_TAG */
c609719b
WD
216
217
8655b6f8
WD
218#if defined (CONFIG_VFD) || defined (CONFIG_LCD)
219extern ulong calc_fbsize (void);
5779d8d9 220static void setup_videolfb_tag (gd_t *gd)
c609719b 221{
5779d8d9
WD
222 /* An ATAG_VIDEOLFB node tells the kernel where and how large
223 * the framebuffer for video was allocated (among other things).
224 * Note that a _physical_ address is passed !
225 *
226 * We only use it to pass the address and size, the other entries
227 * in the tag_videolfb are not of interest.
228 */
229 params->hdr.tag = ATAG_VIDEOLFB;
230 params->hdr.size = tag_size (tag_videolfb);
c609719b 231
5779d8d9 232 params->u.videolfb.lfb_base = (u32) gd->fb_base;
8655b6f8
WD
233 /* Fb size is calculated according to parameters for our panel
234 */
235 params->u.videolfb.lfb_size = calc_fbsize();
c609719b 236
5779d8d9 237 params = tag_next (params);
c609719b 238}
8655b6f8 239#endif /* CONFIG_VFD || CONFIG_LCD */
c609719b 240
3a574cbe
WD
241#ifdef CONFIG_SERIAL_TAG
242void setup_serial_tag (struct tag **tmp)
243{
244 struct tag *params = *tmp;
245 struct tag_serialnr serialnr;
246 void get_board_serial(struct tag_serialnr *serialnr);
247
248 get_board_serial(&serialnr);
249 params->hdr.tag = ATAG_SERIAL;
250 params->hdr.size = tag_size (tag_serialnr);
251 params->u.serialnr.low = serialnr.low;
252 params->u.serialnr.high= serialnr.high;
253 params = tag_next (params);
254 *tmp = params;
255}
256#endif
257
289f932c
WD
258#ifdef CONFIG_REVISION_TAG
259void setup_revision_tag(struct tag **in_params)
260{
261 u32 rev = 0;
289f932c
WD
262 u32 get_board_rev(void);
263
264 rev = get_board_rev();
289f932c
WD
265 params->hdr.tag = ATAG_REVISION;
266 params->hdr.size = tag_size (tag_revision);
267 params->u.revision.rev = rev;
268 params = tag_next (params);
269}
270#endif /* CONFIG_REVISION_TAG */
271
272
5779d8d9 273static void setup_end_tag (bd_t *bd)
c609719b 274{
5779d8d9
WD
275 params->hdr.tag = ATAG_NONE;
276 params->hdr.size = 0;
c609719b
WD
277}
278
279#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */