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>
5 * Rick Chen, Andes Technology Corporation <rick@andestech.com>
7 * SPDX-License-Identifier: GPL-2.0+
13 #include <u-boot/zlib.h>
14 #include <asm/byteorder.h>
15 #include <asm/bootm.h>
17 DECLARE_GLOBAL_DATA_PTR;
19 int arch_fixup_fdt(void *blob)
24 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
25 defined(CONFIG_CMDLINE_TAG) || \
26 defined(CONFIG_INITRD_TAG) || \
27 defined(CONFIG_SERIAL_TAG) || \
28 defined(CONFIG_REVISION_TAG)
29 static void setup_start_tag(bd_t *bd);
31 # ifdef CONFIG_SETUP_MEMORY_TAGS
32 static void setup_memory_tags(bd_t *bd);
34 static void setup_commandline_tag(bd_t *bd, char *commandline);
36 # ifdef CONFIG_INITRD_TAG
37 static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end);
39 static void setup_end_tag(bd_t *bd);
41 static struct tag *params;
42 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
44 int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
48 int machid = bd->bi_arch_number;
49 void (*theKernel)(int zero, int arch, uint params);
51 #ifdef CONFIG_CMDLINE_TAG
52 char *commandline = env_get("bootargs");
56 * allow the PREP bootm subcommand, it is required for bootm to work
58 if (flag & BOOTM_STATE_OS_PREP)
61 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
64 theKernel = (void (*)(int, int, uint))images->ep;
66 s = env_get("machid");
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 (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
78 #ifdef CONFIG_OF_LIBFDT
79 debug("using: FDT\n");
80 if (image_setup_linux(images)) {
81 printf("FDT creation failed! hanging...");
85 } else if (BOOTM_ENABLE_TAGS) {
86 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
87 defined(CONFIG_CMDLINE_TAG) || \
88 defined(CONFIG_INITRD_TAG) || \
89 defined(CONFIG_SERIAL_TAG) || \
90 defined(CONFIG_REVISION_TAG)
92 #ifdef CONFIG_SERIAL_TAG
93 setup_serial_tag(¶ms);
95 #ifdef CONFIG_REVISION_TAG
96 setup_revision_tag(¶ms);
98 #ifdef CONFIG_SETUP_MEMORY_TAGS
99 setup_memory_tags(bd);
101 #ifdef CONFIG_CMDLINE_TAG
102 setup_commandline_tag(bd, commandline);
104 #ifdef CONFIG_INITRD_TAG
105 if (images->rd_start && images->rd_end)
106 setup_initrd_tag(bd, images->rd_start, images->rd_end);
111 /* we assume that the kernel is in place */
112 printf("\nStarting kernel ...\n\n");
114 #ifdef CONFIG_USB_DEVICE
116 extern void udc_disconnect(void);
121 cleanup_before_linux();
122 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
123 theKernel(0, machid, (unsigned long)images->ft_addr);
125 theKernel(0, machid, bd->bi_boot_params);
126 /* does not return */
131 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
132 defined(CONFIG_CMDLINE_TAG) || \
133 defined(CONFIG_INITRD_TAG) || \
134 defined(CONFIG_SERIAL_TAG) || \
135 defined(CONFIG_REVISION_TAG)
136 static void setup_start_tag(bd_t *bd)
138 params = (struct tag *)bd->bi_boot_params;
140 params->hdr.tag = ATAG_CORE;
141 params->hdr.size = tag_size(tag_core);
143 params->u.core.flags = 0;
144 params->u.core.pagesize = 0;
145 params->u.core.rootdev = 0;
147 params = tag_next(params);
150 #ifdef CONFIG_SETUP_MEMORY_TAGS
151 static void setup_memory_tags(bd_t *bd)
155 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
156 params->hdr.tag = ATAG_MEM;
157 params->hdr.size = tag_size(tag_mem32);
159 params->u.mem.start = bd->bi_dram[i].start;
160 params->u.mem.size = bd->bi_dram[i].size;
162 params = tag_next(params);
165 #endif /* CONFIG_SETUP_MEMORY_TAGS */
167 static void setup_commandline_tag(bd_t *bd, char *commandline)
174 /* eat leading white space */
175 for (p = commandline; *p == ' '; p++)
178 /* skip non-existent command lines so the kernel will still
179 * use its default command line.
184 params->hdr.tag = ATAG_CMDLINE;
186 (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2;
188 strcpy(params->u.cmdline.cmdline, p)
191 params = tag_next(params);
194 #ifdef CONFIG_INITRD_TAG
195 static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end)
197 /* an ATAG_INITRD node tells the kernel where the compressed
198 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
200 params->hdr.tag = ATAG_INITRD2;
201 params->hdr.size = tag_size(tag_initrd);
203 params->u.initrd.start = initrd_start;
204 params->u.initrd.size = initrd_end - initrd_start;
206 params = tag_next(params);
208 #endif /* CONFIG_INITRD_TAG */
210 #ifdef CONFIG_SERIAL_TAG
211 void setup_serial_tag(struct tag **tmp)
213 void get_board_serial(struct tag_serialnr *serialnr);
215 struct tag_serialnr serialnr;
218 get_board_serial(&serialnr);
219 params->hdr.tag = ATAG_SERIAL;
220 params->hdr.size = tag_size(tag_serialnr);
221 params->u.serialnr.low = serialnr.low;
222 params->u.serialnr.high = serialnr.high;
223 params = tag_next(params);
228 #ifdef CONFIG_REVISION_TAG
229 void setup_revision_tag(struct tag **in_params)
231 u32 get_board_rev(void);
234 rev = get_board_rev();
235 params->hdr.tag = ATAG_REVISION;
236 params->hdr.size = tag_size(tag_revision);
237 params->u.revision.rev = rev;
238 params = tag_next(params);
240 #endif /* CONFIG_REVISION_TAG */
242 static void setup_end_tag(bd_t *bd)
244 params->hdr.tag = ATAG_NONE;
245 params->hdr.size = 0;
248 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */