]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/nds32/lib/bootm.c
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 * SPDX-License-Identifier: GPL-2.0+
12 #include <u-boot/zlib.h>
13 #include <asm/byteorder.h>
14 #include <asm/bootm.h>
15 #include <asm/setup.h>
17 DECLARE_GLOBAL_DATA_PTR
;
19 int arch_fixup_fdt(void *blob
)
25 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
26 defined(CONFIG_CMDLINE_TAG) || \
27 defined(CONFIG_INITRD_TAG) || \
28 defined(CONFIG_SERIAL_TAG) || \
29 defined(CONFIG_REVISION_TAG)
30 static void setup_start_tag(bd_t
*bd
);
32 # ifdef CONFIG_SETUP_MEMORY_TAGS
33 static void setup_memory_tags(bd_t
*bd
);
35 static void setup_commandline_tag(bd_t
*bd
, char *commandline
);
37 # ifdef CONFIG_INITRD_TAG
38 static void setup_initrd_tag(bd_t
*bd
, ulong initrd_start
, ulong initrd_end
);
40 static void setup_end_tag(bd_t
*bd
);
42 static struct tag
*params
;
43 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
45 int do_bootm_linux(int flag
, int argc
, char *argv
[], bootm_headers_t
*images
)
49 int machid
= bd
->bi_arch_number
;
50 void (*theKernel
)(int zero
, int arch
, uint params
);
52 #ifdef CONFIG_CMDLINE_TAG
53 char *commandline
= env_get("bootargs");
57 * allow the PREP bootm subcommand, it is required for bootm to work
59 if (flag
& BOOTM_STATE_OS_PREP
)
62 if ((flag
!= 0) && (flag
!= BOOTM_STATE_OS_GO
))
65 theKernel
= (void (*)(int, int, uint
))images
->ep
;
67 s
= env_get("machid");
69 machid
= simple_strtoul(s
, NULL
, 16);
70 printf("Using machid 0x%x from environment\n", machid
);
73 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
75 debug("## Transferring control to Linux (at address %08lx) ...\n",
78 if (IMAGE_ENABLE_OF_LIBFDT
&& images
->ft_len
) {
79 #ifdef CONFIG_OF_LIBFDT
80 debug("using: FDT\n");
81 if (image_setup_linux(images
)) {
82 printf("FDT creation failed! hanging...");
86 } else if (BOOTM_ENABLE_TAGS
) {
87 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
88 defined(CONFIG_CMDLINE_TAG) || \
89 defined(CONFIG_INITRD_TAG) || \
90 defined(CONFIG_SERIAL_TAG) || \
91 defined(CONFIG_REVISION_TAG)
93 #ifdef CONFIG_SERIAL_TAG
94 setup_serial_tag(¶ms
);
96 #ifdef CONFIG_REVISION_TAG
97 setup_revision_tag(¶ms
);
99 #ifdef CONFIG_SETUP_MEMORY_TAGS
100 setup_memory_tags(bd
);
102 #ifdef CONFIG_CMDLINE_TAG
103 setup_commandline_tag(bd
, commandline
);
105 #ifdef CONFIG_INITRD_TAG
106 if (images
->rd_start
&& images
->rd_end
)
107 setup_initrd_tag(bd
, images
->rd_start
, images
->rd_end
);
112 /* we assume that the kernel is in place */
113 printf("\nStarting kernel ...\n\n");
115 #ifdef CONFIG_USB_DEVICE
117 extern void udc_disconnect(void);
122 cleanup_before_linux();
123 if (IMAGE_ENABLE_OF_LIBFDT
&& images
->ft_len
)
124 theKernel(0, machid
, (unsigned long)images
->ft_addr
);
126 theKernel(0, machid
, bd
->bi_boot_params
);
127 /* does not return */
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 static void setup_start_tag(bd_t
*bd
)
139 params
= (struct tag
*)bd
->bi_boot_params
;
141 params
->hdr
.tag
= ATAG_CORE
;
142 params
->hdr
.size
= tag_size(tag_core
);
144 params
->u
.core
.flags
= 0;
145 params
->u
.core
.pagesize
= 0;
146 params
->u
.core
.rootdev
= 0;
148 params
= tag_next(params
);
151 #ifdef CONFIG_SETUP_MEMORY_TAGS
152 static void setup_memory_tags(bd_t
*bd
)
156 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
157 params
->hdr
.tag
= ATAG_MEM
;
158 params
->hdr
.size
= tag_size(tag_mem32
);
160 params
->u
.mem
.start
= bd
->bi_dram
[i
].start
;
161 params
->u
.mem
.size
= bd
->bi_dram
[i
].size
;
163 params
= tag_next(params
);
166 #endif /* CONFIG_SETUP_MEMORY_TAGS */
168 static void setup_commandline_tag(bd_t
*bd
, char *commandline
)
175 /* eat leading white space */
176 for (p
= commandline
; *p
== ' '; p
++)
179 /* skip non-existent command lines so the kernel will still
180 * use its default command line.
185 params
->hdr
.tag
= ATAG_CMDLINE
;
187 (sizeof(struct tag_header
) + strlen(p
) + 1 + 4) >> 2;
189 strcpy(params
->u
.cmdline
.cmdline
, p
)
192 params
= tag_next(params
);
195 #ifdef CONFIG_INITRD_TAG
196 static void setup_initrd_tag(bd_t
*bd
, ulong initrd_start
, ulong initrd_end
)
198 /* an ATAG_INITRD node tells the kernel where the compressed
199 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
201 params
->hdr
.tag
= ATAG_INITRD2
;
202 params
->hdr
.size
= tag_size(tag_initrd
);
204 params
->u
.initrd
.start
= initrd_start
;
205 params
->u
.initrd
.size
= initrd_end
- initrd_start
;
207 params
= tag_next(params
);
209 #endif /* CONFIG_INITRD_TAG */
211 #ifdef CONFIG_SERIAL_TAG
212 void setup_serial_tag(struct tag
**tmp
)
214 struct tag
*params
= *tmp
;
215 struct tag_serialnr serialnr
;
216 void get_board_serial(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
)
232 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 */