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>
31 #include <fdt_support.h>
33 #ifdef CMDLINE_NEED_CONV
34 #include <asm/arch/endian_conv.h>
37 DECLARE_GLOBAL_DATA_PTR;
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);
46 # ifdef CONFIG_SETUP_MEMORY_TAGS
47 static void setup_memory_tags (bd_t *bd);
49 static void setup_commandline_tag (bd_t *bd, char *commandline);
51 # ifdef CONFIG_INITRD_TAG
52 static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
55 static void setup_end_tag (bd_t *bd);
57 static struct tag *params;
58 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
60 static ulong get_sp(void);
61 #if defined(CONFIG_OF_LIBFDT)
62 static int bootm_linux_fdt(int machid, bootm_headers_t *images);
65 void arch_lmb_reserve(struct lmb *lmb)
70 * Booting a (Linux) kernel image
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
79 debug("## Current stack ends at 0x%08lx ", sp);
81 /* adjust sp by 1K to be safe */
84 gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size - sp);
87 static void announce_and_cleanup(void)
89 printf("\nStarting kernel ...\n\n");
91 #ifdef CONFIG_USB_DEVICE
93 extern void udc_disconnect(void);
97 cleanup_before_linux();
100 int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
104 int machid = bd->bi_arch_number;
105 void (*kernel_entry)(int zero, int arch, uint params);
107 #ifdef CONFIG_CMDLINE_TAG
108 char *commandline = getenv ("bootargs");
111 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
114 s = getenv ("machid");
116 machid = simple_strtoul (s, NULL, 16);
117 printf ("Using machid 0x%x from environment\n", machid);
120 show_boot_progress (15);
122 #ifdef CONFIG_OF_LIBFDT
124 return bootm_linux_fdt(machid, images);
127 kernel_entry = (void (*)(int, int, uint))images->ep;
129 debug ("## Transferring control to Linux (at address %08lx) ...\n",
130 (ulong) kernel_entry);
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 (¶ms);
141 #ifdef CONFIG_REVISION_TAG
142 setup_revision_tag (¶ms);
144 #ifdef CONFIG_SETUP_MEMORY_TAGS
145 setup_memory_tags (bd);
147 #ifdef CONFIG_CMDLINE_TAG
148 setup_commandline_tag (bd, commandline);
150 #ifdef CONFIG_INITRD_TAG
151 if (images->rd_start && images->rd_end)
152 setup_initrd_tag (bd, images->rd_start, images->rd_end);
157 announce_and_cleanup();
159 kernel_entry(0, machid, bd->bi_boot_params);
160 /* does not return */
165 #if defined(CONFIG_OF_LIBFDT)
166 static int fixup_memory_node(void *blob)
170 u64 start[CONFIG_NR_DRAM_BANKS];
171 u64 size[CONFIG_NR_DRAM_BANKS];
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;
178 return fdt_fixup_memory_banks(blob, start, size, CONFIG_NR_DRAM_BANKS);
181 static int bootm_linux_fdt(int machid, bootm_headers_t *images)
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;
191 kernel_entry = (void (*)(int, int, void *))images->ep;
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);
199 debug("## Transferring control to Linux (at address %08lx) ...\n",
200 (ulong) kernel_entry);
202 fdt_chosen(*of_flat_tree, 1);
204 fixup_memory_node(*of_flat_tree);
206 fdt_initrd(*of_flat_tree, *initrd_start, *initrd_end, 1);
208 announce_and_cleanup();
210 #ifdef SPRD_EVM_TAG_ON
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);
221 unsigned int temp_cnt;
222 for(ijk=0;ijk<0xffffff;ijk++){
223 temp_cnt = *(volatile unsigned long *)0x87003004;
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));
232 kernel_entry(0, machid, *of_flat_tree);
233 /* does not return */
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)
246 params = (struct tag *) bd->bi_boot_params;
248 params->hdr.tag = ATAG_CORE;
249 params->hdr.size = tag_size (tag_core);
251 params->u.core.flags = 0;
252 params->u.core.pagesize = 0;
253 params->u.core.rootdev = 0;
255 params = tag_next (params);
259 #ifdef CONFIG_SETUP_MEMORY_TAGS
260 static void setup_memory_tags (bd_t *bd)
264 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
265 params->hdr.tag = ATAG_MEM;
266 params->hdr.size = tag_size (tag_mem32);
268 params->u.mem.start = bd->bi_dram[i].start;
269 params->u.mem.size = bd->bi_dram[i].size;
271 params = tag_next (params);
274 #endif /* CONFIG_SETUP_MEMORY_TAGS */
277 static void setup_commandline_tag (bd_t *bd, char *commandline)
284 /* eat leading white space */
285 for (p = commandline; *p == ' '; p++);
287 /* skip non-existent command lines so the kernel will still
288 * use its default command line.
293 params->hdr.tag = ATAG_CMDLINE;
295 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
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;
303 for(i=0;i<len_temp;i++){
304 INT_SWAP((*((uint32_t *)params->u.cmdline.cmdline +i)));
308 params = tag_next (params);
312 #ifdef CONFIG_INITRD_TAG
313 static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
315 /* an ATAG_INITRD node tells the kernel where the compressed
316 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
318 params->hdr.tag = ATAG_INITRD2;
319 params->hdr.size = tag_size (tag_initrd);
321 params->u.initrd.start = initrd_start;
322 params->u.initrd.size = initrd_end - initrd_start;
324 params = tag_next (params);
326 #endif /* CONFIG_INITRD_TAG */
328 #ifdef CONFIG_SERIAL_TAG
329 void setup_serial_tag (struct tag **tmp)
331 struct tag *params = *tmp;
332 struct tag_serialnr serialnr;
333 void get_board_serial(struct tag_serialnr *serialnr);
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);
345 #ifdef CONFIG_REVISION_TAG
346 void setup_revision_tag(struct tag **in_params)
349 u32 get_board_rev(void);
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);
357 #endif /* CONFIG_REVISION_TAG */
360 static void setup_end_tag (bd_t *bd)
362 params->hdr.tag = ATAG_NONE;
363 params->hdr.size = 0;
366 static ulong get_sp(void)
370 asm("mov %0, sp" : "=r"(ret) : );
374 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */