]> Git Repo - u-boot.git/blame - arch/nds32/lib/bootm.c
common: Move hang() to the same header as panic()
[u-boot.git] / arch / nds32 / lib / bootm.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
463d47f6
ML
2/*
3 * Copyright (C) 2011 Andes Technology Corporation
4 * Shawn Lin, Andes Technology Corporation <[email protected]>
5 * Macpaul Lin, Andes Technology Corporation <[email protected]>
463d47f6
ML
6 */
7
8#include <common.h>
9#include <command.h>
7b51b576 10#include <env.h>
29a4a9f1 11#include <hang.h>
463d47f6
ML
12#include <image.h>
13#include <u-boot/zlib.h>
14#include <asm/byteorder.h>
b841b6e9 15#include <asm/bootm.h>
463d47f6
ML
16
17DECLARE_GLOBAL_DATA_PTR;
18
19#if defined(CONFIG_SETUP_MEMORY_TAGS) || \
20 defined(CONFIG_CMDLINE_TAG) || \
21 defined(CONFIG_INITRD_TAG) || \
22 defined(CONFIG_SERIAL_TAG) || \
23 defined(CONFIG_REVISION_TAG)
24static void setup_start_tag(bd_t *bd);
25
26# ifdef CONFIG_SETUP_MEMORY_TAGS
27static void setup_memory_tags(bd_t *bd);
28# endif
29static void setup_commandline_tag(bd_t *bd, char *commandline);
30
31# ifdef CONFIG_INITRD_TAG
32static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end);
33# endif
34static void setup_end_tag(bd_t *bd);
35
36static struct tag *params;
37#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
38
39int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
40{
41 bd_t *bd = gd->bd;
42 char *s;
43 int machid = bd->bi_arch_number;
44 void (*theKernel)(int zero, int arch, uint params);
45
46#ifdef CONFIG_CMDLINE_TAG
00caae6d 47 char *commandline = env_get("bootargs");
463d47f6
ML
48#endif
49
2cb0e55a
AB
50 /*
51 * allow the PREP bootm subcommand, it is required for bootm to work
52 */
53 if (flag & BOOTM_STATE_OS_PREP)
54 return 0;
55
463d47f6
ML
56 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
57 return 1;
58
59 theKernel = (void (*)(int, int, uint))images->ep;
60
00caae6d 61 s = env_get("machid");
463d47f6
ML
62 if (s) {
63 machid = simple_strtoul(s, NULL, 16);
64 printf("Using machid 0x%x from environment\n", machid);
65 }
66
770605e4 67 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
463d47f6
ML
68
69 debug("## Transferring control to Linux (at address %08lx) ...\n",
70 (ulong)theKernel);
71
b841b6e9 72 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
73#ifdef CONFIG_OF_LIBFDT
74 debug("using: FDT\n");
75 if (image_setup_linux(images)) {
76 printf("FDT creation failed! hanging...");
77 hang();
78 }
79#endif
80 } else if (BOOTM_ENABLE_TAGS) {
463d47f6
ML
81#if defined(CONFIG_SETUP_MEMORY_TAGS) || \
82 defined(CONFIG_CMDLINE_TAG) || \
83 defined(CONFIG_INITRD_TAG) || \
84 defined(CONFIG_SERIAL_TAG) || \
85 defined(CONFIG_REVISION_TAG)
86 setup_start_tag(bd);
87#ifdef CONFIG_SERIAL_TAG
88 setup_serial_tag(&params);
89#endif
90#ifdef CONFIG_REVISION_TAG
91 setup_revision_tag(&params);
92#endif
93#ifdef CONFIG_SETUP_MEMORY_TAGS
94 setup_memory_tags(bd);
95#endif
96#ifdef CONFIG_CMDLINE_TAG
97 setup_commandline_tag(bd, commandline);
98#endif
99#ifdef CONFIG_INITRD_TAG
100 if (images->rd_start && images->rd_end)
101 setup_initrd_tag(bd, images->rd_start, images->rd_end);
102#endif
103 setup_end_tag(bd);
104#endif
105
106 /* we assume that the kernel is in place */
107 printf("\nStarting kernel ...\n\n");
108
109#ifdef CONFIG_USB_DEVICE
110 {
111 extern void udc_disconnect(void);
112 udc_disconnect();
113 }
114#endif
b841b6e9 115 }
463d47f6 116 cleanup_before_linux();
b841b6e9 117 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
118 theKernel(0, machid, (unsigned long)images->ft_addr);
119 else
120 theKernel(0, machid, bd->bi_boot_params);
463d47f6
ML
121 /* does not return */
122
123 return 1;
124}
125
463d47f6
ML
126#if defined(CONFIG_SETUP_MEMORY_TAGS) || \
127 defined(CONFIG_CMDLINE_TAG) || \
128 defined(CONFIG_INITRD_TAG) || \
129 defined(CONFIG_SERIAL_TAG) || \
130 defined(CONFIG_REVISION_TAG)
131static void setup_start_tag(bd_t *bd)
132{
133 params = (struct tag *)bd->bi_boot_params;
134
135 params->hdr.tag = ATAG_CORE;
136 params->hdr.size = tag_size(tag_core);
137
138 params->u.core.flags = 0;
139 params->u.core.pagesize = 0;
140 params->u.core.rootdev = 0;
141
142 params = tag_next(params);
143}
144
463d47f6
ML
145#ifdef CONFIG_SETUP_MEMORY_TAGS
146static void setup_memory_tags(bd_t *bd)
147{
148 int i;
149
150 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
151 params->hdr.tag = ATAG_MEM;
152 params->hdr.size = tag_size(tag_mem32);
153
154 params->u.mem.start = bd->bi_dram[i].start;
155 params->u.mem.size = bd->bi_dram[i].size;
156
157 params = tag_next(params);
158 }
159}
160#endif /* CONFIG_SETUP_MEMORY_TAGS */
161
463d47f6
ML
162static void setup_commandline_tag(bd_t *bd, char *commandline)
163{
164 char *p;
165
166 if (!commandline)
167 return;
168
169 /* eat leading white space */
170 for (p = commandline; *p == ' '; p++)
171 ;
172
173 /* skip non-existent command lines so the kernel will still
174 * use its default command line.
175 */
176 if (*p == '\0')
177 return;
178
179 params->hdr.tag = ATAG_CMDLINE;
180 params->hdr.size =
181 (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2;
182
183 strcpy(params->u.cmdline.cmdline, p)
184 ;
185
186 params = tag_next(params);
187}
188
463d47f6
ML
189#ifdef CONFIG_INITRD_TAG
190static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end)
191{
192 /* an ATAG_INITRD node tells the kernel where the compressed
193 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
194 */
195 params->hdr.tag = ATAG_INITRD2;
196 params->hdr.size = tag_size(tag_initrd);
197
198 params->u.initrd.start = initrd_start;
199 params->u.initrd.size = initrd_end - initrd_start;
200
201 params = tag_next(params);
202}
203#endif /* CONFIG_INITRD_TAG */
204
205#ifdef CONFIG_SERIAL_TAG
206void setup_serial_tag(struct tag **tmp)
207{
208 struct tag *params = *tmp;
209 struct tag_serialnr serialnr;
210 void get_board_serial(struct tag_serialnr *serialnr);
211
212 get_board_serial(&serialnr);
213 params->hdr.tag = ATAG_SERIAL;
214 params->hdr.size = tag_size(tag_serialnr);
215 params->u.serialnr.low = serialnr.low;
216 params->u.serialnr.high = serialnr.high;
217 params = tag_next(params);
218 *tmp = params;
219}
220#endif
221
222#ifdef CONFIG_REVISION_TAG
223void setup_revision_tag(struct tag **in_params)
224{
225 u32 rev = 0;
226 u32 get_board_rev(void);
227
228 rev = get_board_rev();
229 params->hdr.tag = ATAG_REVISION;
230 params->hdr.size = tag_size(tag_revision);
231 params->u.revision.rev = rev;
232 params = tag_next(params);
233}
234#endif /* CONFIG_REVISION_TAG */
235
463d47f6
ML
236static void setup_end_tag(bd_t *bd)
237{
238 params->hdr.tag = ATAG_NONE;
239 params->hdr.size = 0;
240}
241
242#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
This page took 0.23226 seconds and 4 git commands to generate.