2 * Copyright (C) 2011 Andes Technology Corporation
3 * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
4 * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <u-boot/zlib.h>
26 #include <asm/byteorder.h>
28 DECLARE_GLOBAL_DATA_PTR;
30 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
31 defined(CONFIG_CMDLINE_TAG) || \
32 defined(CONFIG_INITRD_TAG) || \
33 defined(CONFIG_SERIAL_TAG) || \
34 defined(CONFIG_REVISION_TAG)
35 static void setup_start_tag(bd_t *bd);
37 # ifdef CONFIG_SETUP_MEMORY_TAGS
38 static void setup_memory_tags(bd_t *bd);
40 static void setup_commandline_tag(bd_t *bd, char *commandline);
42 # ifdef CONFIG_INITRD_TAG
43 static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end);
45 static void setup_end_tag(bd_t *bd);
47 static struct tag *params;
48 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
50 int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
54 int machid = bd->bi_arch_number;
55 void (*theKernel)(int zero, int arch, uint params);
57 #ifdef CONFIG_CMDLINE_TAG
58 char *commandline = getenv("bootargs");
61 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
64 theKernel = (void (*)(int, int, uint))images->ep;
68 machid = simple_strtoul(s, NULL, 16);
69 printf("Using machid 0x%x from environment\n", machid);
72 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
74 debug("## Transferring control to Linux (at address %08lx) ...\n",
77 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
78 defined(CONFIG_CMDLINE_TAG) || \
79 defined(CONFIG_INITRD_TAG) || \
80 defined(CONFIG_SERIAL_TAG) || \
81 defined(CONFIG_REVISION_TAG)
83 #ifdef CONFIG_SERIAL_TAG
84 setup_serial_tag(¶ms);
86 #ifdef CONFIG_REVISION_TAG
87 setup_revision_tag(¶ms);
89 #ifdef CONFIG_SETUP_MEMORY_TAGS
90 setup_memory_tags(bd);
92 #ifdef CONFIG_CMDLINE_TAG
93 setup_commandline_tag(bd, commandline);
95 #ifdef CONFIG_INITRD_TAG
96 if (images->rd_start && images->rd_end)
97 setup_initrd_tag(bd, images->rd_start, images->rd_end);
102 /* we assume that the kernel is in place */
103 printf("\nStarting kernel ...\n\n");
105 #ifdef CONFIG_USB_DEVICE
107 extern void udc_disconnect(void);
112 cleanup_before_linux();
114 theKernel(0, machid, bd->bi_boot_params);
115 /* does not return */
121 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
122 defined(CONFIG_CMDLINE_TAG) || \
123 defined(CONFIG_INITRD_TAG) || \
124 defined(CONFIG_SERIAL_TAG) || \
125 defined(CONFIG_REVISION_TAG)
126 static void setup_start_tag(bd_t *bd)
128 params = (struct tag *)bd->bi_boot_params;
130 params->hdr.tag = ATAG_CORE;
131 params->hdr.size = tag_size(tag_core);
133 params->u.core.flags = 0;
134 params->u.core.pagesize = 0;
135 params->u.core.rootdev = 0;
137 params = tag_next(params);
141 #ifdef CONFIG_SETUP_MEMORY_TAGS
142 static void setup_memory_tags(bd_t *bd)
146 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
147 params->hdr.tag = ATAG_MEM;
148 params->hdr.size = tag_size(tag_mem32);
150 params->u.mem.start = bd->bi_dram[i].start;
151 params->u.mem.size = bd->bi_dram[i].size;
153 params = tag_next(params);
156 #endif /* CONFIG_SETUP_MEMORY_TAGS */
159 static void setup_commandline_tag(bd_t *bd, char *commandline)
166 /* eat leading white space */
167 for (p = commandline; *p == ' '; p++)
170 /* skip non-existent command lines so the kernel will still
171 * use its default command line.
176 params->hdr.tag = ATAG_CMDLINE;
178 (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2;
180 strcpy(params->u.cmdline.cmdline, p)
183 params = tag_next(params);
187 #ifdef CONFIG_INITRD_TAG
188 static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end)
190 /* an ATAG_INITRD node tells the kernel where the compressed
191 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
193 params->hdr.tag = ATAG_INITRD2;
194 params->hdr.size = tag_size(tag_initrd);
196 params->u.initrd.start = initrd_start;
197 params->u.initrd.size = initrd_end - initrd_start;
199 params = tag_next(params);
201 #endif /* CONFIG_INITRD_TAG */
203 #ifdef CONFIG_SERIAL_TAG
204 void setup_serial_tag(struct tag **tmp)
206 struct tag *params = *tmp;
207 struct tag_serialnr serialnr;
208 void get_board_serial(struct tag_serialnr *serialnr);
210 get_board_serial(&serialnr);
211 params->hdr.tag = ATAG_SERIAL;
212 params->hdr.size = tag_size(tag_serialnr);
213 params->u.serialnr.low = serialnr.low;
214 params->u.serialnr.high = serialnr.high;
215 params = tag_next(params);
220 #ifdef CONFIG_REVISION_TAG
221 void setup_revision_tag(struct tag **in_params)
224 u32 get_board_rev(void);
226 rev = get_board_rev();
227 params->hdr.tag = ATAG_REVISION;
228 params->hdr.size = tag_size(tag_revision);
229 params->u.revision.rev = rev;
230 params = tag_next(params);
232 #endif /* CONFIG_REVISION_TAG */
235 static void setup_end_tag(bd_t *bd)
237 params->hdr.tag = ATAG_NONE;
238 params->hdr.size = 0;
241 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */