]>
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>
15 DECLARE_GLOBAL_DATA_PTR
;
17 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
18 defined(CONFIG_CMDLINE_TAG) || \
19 defined(CONFIG_INITRD_TAG) || \
20 defined(CONFIG_SERIAL_TAG) || \
21 defined(CONFIG_REVISION_TAG)
22 static void setup_start_tag(bd_t
*bd
);
24 # ifdef CONFIG_SETUP_MEMORY_TAGS
25 static void setup_memory_tags(bd_t
*bd
);
27 static void setup_commandline_tag(bd_t
*bd
, char *commandline
);
29 # ifdef CONFIG_INITRD_TAG
30 static void setup_initrd_tag(bd_t
*bd
, ulong initrd_start
, ulong initrd_end
);
32 static void setup_end_tag(bd_t
*bd
);
34 static struct tag
*params
;
35 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
37 int do_bootm_linux(int flag
, int argc
, char *argv
[], bootm_headers_t
*images
)
41 int machid
= bd
->bi_arch_number
;
42 void (*theKernel
)(int zero
, int arch
, uint params
);
44 #ifdef CONFIG_CMDLINE_TAG
45 char *commandline
= getenv("bootargs");
49 * allow the PREP bootm subcommand, it is required for bootm to work
51 if (flag
& BOOTM_STATE_OS_PREP
)
54 if ((flag
!= 0) && (flag
!= BOOTM_STATE_OS_GO
))
57 theKernel
= (void (*)(int, int, uint
))images
->ep
;
61 machid
= simple_strtoul(s
, NULL
, 16);
62 printf("Using machid 0x%x from environment\n", machid
);
65 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
67 debug("## Transferring control to Linux (at address %08lx) ...\n",
70 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
71 defined(CONFIG_CMDLINE_TAG) || \
72 defined(CONFIG_INITRD_TAG) || \
73 defined(CONFIG_SERIAL_TAG) || \
74 defined(CONFIG_REVISION_TAG)
76 #ifdef CONFIG_SERIAL_TAG
77 setup_serial_tag(¶ms
);
79 #ifdef CONFIG_REVISION_TAG
80 setup_revision_tag(¶ms
);
82 #ifdef CONFIG_SETUP_MEMORY_TAGS
83 setup_memory_tags(bd
);
85 #ifdef CONFIG_CMDLINE_TAG
86 setup_commandline_tag(bd
, commandline
);
88 #ifdef CONFIG_INITRD_TAG
89 if (images
->rd_start
&& images
->rd_end
)
90 setup_initrd_tag(bd
, images
->rd_start
, images
->rd_end
);
95 /* we assume that the kernel is in place */
96 printf("\nStarting kernel ...\n\n");
98 #ifdef CONFIG_USB_DEVICE
100 extern void udc_disconnect(void);
105 cleanup_before_linux();
107 theKernel(0, machid
, bd
->bi_boot_params
);
108 /* does not return */
114 #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
115 defined(CONFIG_CMDLINE_TAG) || \
116 defined(CONFIG_INITRD_TAG) || \
117 defined(CONFIG_SERIAL_TAG) || \
118 defined(CONFIG_REVISION_TAG)
119 static void setup_start_tag(bd_t
*bd
)
121 params
= (struct tag
*)bd
->bi_boot_params
;
123 params
->hdr
.tag
= ATAG_CORE
;
124 params
->hdr
.size
= tag_size(tag_core
);
126 params
->u
.core
.flags
= 0;
127 params
->u
.core
.pagesize
= 0;
128 params
->u
.core
.rootdev
= 0;
130 params
= tag_next(params
);
134 #ifdef CONFIG_SETUP_MEMORY_TAGS
135 static void setup_memory_tags(bd_t
*bd
)
139 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
140 params
->hdr
.tag
= ATAG_MEM
;
141 params
->hdr
.size
= tag_size(tag_mem32
);
143 params
->u
.mem
.start
= bd
->bi_dram
[i
].start
;
144 params
->u
.mem
.size
= bd
->bi_dram
[i
].size
;
146 params
= tag_next(params
);
149 #endif /* CONFIG_SETUP_MEMORY_TAGS */
152 static void setup_commandline_tag(bd_t
*bd
, char *commandline
)
159 /* eat leading white space */
160 for (p
= commandline
; *p
== ' '; p
++)
163 /* skip non-existent command lines so the kernel will still
164 * use its default command line.
169 params
->hdr
.tag
= ATAG_CMDLINE
;
171 (sizeof(struct tag_header
) + strlen(p
) + 1 + 4) >> 2;
173 strcpy(params
->u
.cmdline
.cmdline
, p
)
176 params
= tag_next(params
);
180 #ifdef CONFIG_INITRD_TAG
181 static void setup_initrd_tag(bd_t
*bd
, ulong initrd_start
, ulong initrd_end
)
183 /* an ATAG_INITRD node tells the kernel where the compressed
184 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
186 params
->hdr
.tag
= ATAG_INITRD2
;
187 params
->hdr
.size
= tag_size(tag_initrd
);
189 params
->u
.initrd
.start
= initrd_start
;
190 params
->u
.initrd
.size
= initrd_end
- initrd_start
;
192 params
= tag_next(params
);
194 #endif /* CONFIG_INITRD_TAG */
196 #ifdef CONFIG_SERIAL_TAG
197 void setup_serial_tag(struct tag
**tmp
)
199 struct tag
*params
= *tmp
;
200 struct tag_serialnr serialnr
;
201 void get_board_serial(struct tag_serialnr
*serialnr
);
203 get_board_serial(&serialnr
);
204 params
->hdr
.tag
= ATAG_SERIAL
;
205 params
->hdr
.size
= tag_size(tag_serialnr
);
206 params
->u
.serialnr
.low
= serialnr
.low
;
207 params
->u
.serialnr
.high
= serialnr
.high
;
208 params
= tag_next(params
);
213 #ifdef CONFIG_REVISION_TAG
214 void setup_revision_tag(struct tag
**in_params
)
217 u32
get_board_rev(void);
219 rev
= get_board_rev();
220 params
->hdr
.tag
= ATAG_REVISION
;
221 params
->hdr
.size
= tag_size(tag_revision
);
222 params
->u
.revision
.rev
= rev
;
223 params
= tag_next(params
);
225 #endif /* CONFIG_REVISION_TAG */
228 static void setup_end_tag(bd_t
*bd
)
230 params
->hdr
.tag
= ATAG_NONE
;
231 params
->hdr
.size
= 0;
234 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */