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