arm: bootm: remove the unused variables
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / lib / 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 <u-boot/zlib.h>
28 #include <asm/byteorder.h>
29 #include <fdt.h>
30 #include <libfdt.h>
31 #include <fdt_support.h>
32
33 #ifdef CMDLINE_NEED_CONV
34 #include <asm/arch/endian_conv.h>
35 #endif
36
37 DECLARE_GLOBAL_DATA_PTR;
38
39 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
40     defined (CONFIG_CMDLINE_TAG) || \
41     defined (CONFIG_INITRD_TAG) || \
42     defined (CONFIG_SERIAL_TAG) || \
43     defined (CONFIG_REVISION_TAG)
44 static void setup_start_tag (bd_t *bd);
45
46 # ifdef CONFIG_SETUP_MEMORY_TAGS
47 static void setup_memory_tags (bd_t *bd);
48 # endif
49 static void setup_commandline_tag (bd_t *bd, char *commandline);
50
51 # ifdef CONFIG_INITRD_TAG
52 static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
53                               ulong initrd_end);
54 # endif
55 static void setup_end_tag (bd_t *bd);
56
57 static struct tag *params;
58 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
59
60 static ulong get_sp(void);
61 #if defined(CONFIG_OF_LIBFDT)
62 static int bootm_linux_fdt(int machid, bootm_headers_t *images);
63 #endif
64
65 void arch_lmb_reserve(struct lmb *lmb)
66 {
67         ulong sp;
68
69         /*
70          * Booting a (Linux) kernel image
71          *
72          * Allocate space for command line and board info - the
73          * address should be as high as possible within the reach of
74          * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
75          * memory, which means far enough below the current stack
76          * pointer.
77          */
78         sp = get_sp();
79         debug("## Current stack ends at 0x%08lx ", sp);
80
81         /* adjust sp by 1K to be safe */
82         sp -= 1024;
83         lmb_reserve(lmb, sp,
84                     gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size - sp);
85 }
86
87 static void announce_and_cleanup(void)
88 {
89         printf("\nStarting kernel ...\n\n");
90
91 #ifdef CONFIG_USB_DEVICE
92         {
93                 extern void udc_disconnect(void);
94                 udc_disconnect();
95         }
96 #endif
97         cleanup_before_linux();
98 }
99
100 int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
101 {
102         bd_t    *bd = gd->bd;
103         char    *s;
104         int     machid = bd->bi_arch_number;
105         void    (*kernel_entry)(int zero, int arch, uint params);
106
107 #ifdef CONFIG_CMDLINE_TAG
108         char *commandline = getenv ("bootargs");
109 #endif
110
111         if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
112                 return 1;
113
114         s = getenv ("machid");
115         if (s) {
116                 machid = simple_strtoul (s, NULL, 16);
117                 printf ("Using machid 0x%x from environment\n", machid);
118         }
119
120         show_boot_progress (15);
121
122 #ifdef CONFIG_OF_LIBFDT
123         if (images->ft_len)
124                 return bootm_linux_fdt(machid, images);
125 #endif
126
127         kernel_entry = (void (*)(int, int, uint))images->ep;
128
129         debug ("## Transferring control to Linux (at address %08lx) ...\n",
130                (ulong) kernel_entry);
131
132 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
133     defined (CONFIG_CMDLINE_TAG) || \
134     defined (CONFIG_INITRD_TAG) || \
135     defined (CONFIG_SERIAL_TAG) || \
136     defined (CONFIG_REVISION_TAG)
137         setup_start_tag (bd);
138 #ifdef CONFIG_SERIAL_TAG
139         setup_serial_tag (&params);
140 #endif
141 #ifdef CONFIG_REVISION_TAG
142         setup_revision_tag (&params);
143 #endif
144 #ifdef CONFIG_SETUP_MEMORY_TAGS
145         setup_memory_tags (bd);
146 #endif
147 #ifdef CONFIG_CMDLINE_TAG
148         setup_commandline_tag (bd, commandline);
149 #endif
150 #ifdef CONFIG_INITRD_TAG
151         if (images->rd_start && images->rd_end)
152                 setup_initrd_tag (bd, images->rd_start, images->rd_end);
153 #endif
154         setup_end_tag(bd);
155 #endif
156
157         announce_and_cleanup();
158
159         kernel_entry(0, machid, bd->bi_boot_params);
160         /* does not return */
161
162         return 1;
163 }
164
165 #if defined(CONFIG_OF_LIBFDT)
166 static int fixup_memory_node(void *blob)
167 {
168         bd_t    *bd = gd->bd;
169         int bank;
170         u64 start[CONFIG_NR_DRAM_BANKS];
171         u64 size[CONFIG_NR_DRAM_BANKS];
172
173         for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
174                 start[bank] = bd->bi_dram[bank].start;
175                 size[bank] = bd->bi_dram[bank].size;
176         }
177
178         return fdt_fixup_memory_banks(blob, start, size, CONFIG_NR_DRAM_BANKS);
179 }
180
181 static int bootm_linux_fdt(int machid, bootm_headers_t *images)
182 {
183         ulong rd_len;
184         void (*kernel_entry)(int zero, int dt_machid, void *dtblob);
185         char **of_flat_tree = &images->ft_addr;
186         ulong *initrd_start = &images->initrd_start;
187         ulong *initrd_end = &images->initrd_end;
188         struct lmb *lmb = &images->lmb;
189         int ret;
190
191         kernel_entry = (void (*)(int, int, void *))images->ep;
192
193         rd_len = images->rd_end - images->rd_start;
194         ret = boot_ramdisk_high(lmb, images->rd_start, rd_len,
195                                 initrd_start, initrd_end);
196         if (ret)
197                 return ret;
198
199         debug("## Transferring control to Linux (at address %08lx) ...\n",
200                (ulong) kernel_entry);
201
202         fdt_chosen(*of_flat_tree, 1);
203
204         fixup_memory_node(*of_flat_tree);
205
206         fdt_initrd(*of_flat_tree, *initrd_start, *initrd_end, 1);
207
208         announce_and_cleanup();
209
210 #ifdef SPRD_EVM_TAG_ON
211         SPRD_EVM_TAG(17);
212         int ijk = 0;
213         int last = 0, now;
214         printf("boot steps evalution:\n");
215         for(ijk=0;ijk<18;ijk++){
216                 now = *((unsigned long *)SPRD_EVM_ADDR_START+ ijk);
217                 printf("%03d\taddr %x\t%lu\t%u\n", ijk,(unsigned long *)SPRD_EVM_ADDR_START+ ijk,now ,now-last);
218                 last = now;
219         }
220 #if 0
221         unsigned int temp_cnt;
222         for(ijk=0;ijk<0xffffff;ijk++){
223                 temp_cnt = *(volatile unsigned long *)0x87003004;
224                 udelay(1000);
225 (*(((unsigned long *)0x2000000)+ijk) = *(volatile unsigned long *)0x87003004);
226                 printf(" the cnt is %x\n", temp_cnt);
227                 printf(" [0x%08x] 0x%08x\n", ((unsigned int *)0x2000000)+ijk,*(((unsigned int *)0x2000000)+ijk));
228         }
229 #endif
230         while(1);
231 #endif
232         kernel_entry(0, machid, *of_flat_tree);
233         /* does not return */
234
235         return 1;
236 }
237 #endif
238
239 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
240     defined (CONFIG_CMDLINE_TAG) || \
241     defined (CONFIG_INITRD_TAG) || \
242     defined (CONFIG_SERIAL_TAG) || \
243     defined (CONFIG_REVISION_TAG)
244 static void setup_start_tag (bd_t *bd)
245 {
246         params = (struct tag *) bd->bi_boot_params;
247
248         params->hdr.tag = ATAG_CORE;
249         params->hdr.size = tag_size (tag_core);
250
251         params->u.core.flags = 0;
252         params->u.core.pagesize = 0;
253         params->u.core.rootdev = 0;
254
255         params = tag_next (params);
256 }
257
258
259 #ifdef CONFIG_SETUP_MEMORY_TAGS
260 static void setup_memory_tags (bd_t *bd)
261 {
262         int i;
263
264         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
265                 params->hdr.tag = ATAG_MEM;
266                 params->hdr.size = tag_size (tag_mem32);
267
268                 params->u.mem.start = bd->bi_dram[i].start;
269                 params->u.mem.size = bd->bi_dram[i].size;
270
271                 params = tag_next (params);
272         }
273 }
274 #endif /* CONFIG_SETUP_MEMORY_TAGS */
275
276
277 static void setup_commandline_tag (bd_t *bd, char *commandline)
278 {
279         char *p;
280
281         if (!commandline)
282                 return;
283
284         /* eat leading white space */
285         for (p = commandline; *p == ' '; p++);
286
287         /* skip non-existent command lines so the kernel will still
288          * use its default command line.
289          */
290         if (*p == '\0')
291                 return;
292
293         params->hdr.tag = ATAG_CMDLINE;
294         params->hdr.size =
295                 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
296
297         strcpy (params->u.cmdline.cmdline, p);
298 #ifdef CMDLINE_NEED_CONV
299         int i = 0, len_temp = 0;
300         len_temp = strlen(p);
301         len_temp = (len_temp +3) >> 2;
302
303         for(i=0;i<len_temp;i++){
304                 INT_SWAP((*((uint32_t *)params->u.cmdline.cmdline +i)));
305         }
306 #endif
307
308         params = tag_next (params);
309 }
310
311
312 #ifdef CONFIG_INITRD_TAG
313 static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
314 {
315         /* an ATAG_INITRD node tells the kernel where the compressed
316          * ramdisk can be found. ATAG_RDIMG is a better name, actually.
317          */
318         params->hdr.tag = ATAG_INITRD2;
319         params->hdr.size = tag_size (tag_initrd);
320
321         params->u.initrd.start = initrd_start;
322         params->u.initrd.size = initrd_end - initrd_start;
323
324         params = tag_next (params);
325 }
326 #endif /* CONFIG_INITRD_TAG */
327
328 #ifdef CONFIG_SERIAL_TAG
329 void setup_serial_tag (struct tag **tmp)
330 {
331         struct tag *params = *tmp;
332         struct tag_serialnr serialnr;
333         void get_board_serial(struct tag_serialnr *serialnr);
334
335         get_board_serial(&serialnr);
336         params->hdr.tag = ATAG_SERIAL;
337         params->hdr.size = tag_size (tag_serialnr);
338         params->u.serialnr.low = serialnr.low;
339         params->u.serialnr.high= serialnr.high;
340         params = tag_next (params);
341         *tmp = params;
342 }
343 #endif
344
345 #ifdef CONFIG_REVISION_TAG
346 void setup_revision_tag(struct tag **in_params)
347 {
348         u32 rev = 0;
349         u32 get_board_rev(void);
350
351         rev = get_board_rev();
352         params->hdr.tag = ATAG_REVISION;
353         params->hdr.size = tag_size (tag_revision);
354         params->u.revision.rev = rev;
355         params = tag_next (params);
356 }
357 #endif  /* CONFIG_REVISION_TAG */
358
359
360 static void setup_end_tag (bd_t *bd)
361 {
362         params->hdr.tag = ATAG_NONE;
363         params->hdr.size = 0;
364 }
365
366 static ulong get_sp(void)
367 {
368         ulong ret;
369
370         asm("mov %0, sp" : "=r"(ret) : );
371         return ret;
372 }
373
374 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */