]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/mips/lib/bootm.c
MIPS: bootm: remove unused or redundant header files
[people/ms/u-boot.git] / arch / mips / lib / bootm.c
CommitLineData
c021880a
WD
1/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
c021880a
WD
6 */
7
8#include <common.h>
c021880a 9#include <image.h>
c021880a
WD
10#include <asm/addrspace.h>
11
d87080b7
WD
12DECLARE_GLOBAL_DATA_PTR;
13
c021880a
WD
14#define LINUX_MAX_ENVS 256
15#define LINUX_MAX_ARGS 256
16
7a9d109b
PB
17#if defined(CONFIG_MALTA)
18#define mips_boot_malta 1
b87493f4 19#else
7a9d109b 20#define mips_boot_malta 0
b87493f4
DS
21#endif
22
e51a6b7a
DS
23static int linux_argc;
24static char **linux_argv;
59e8cbdb 25static char *linux_argp;
c021880a 26
e51a6b7a
DS
27static char **linux_env;
28static char *linux_env_p;
29static int linux_env_idx;
c021880a 30
f66cc1e3
DS
31static ulong arch_get_sp(void)
32{
33 ulong ret;
34
35 __asm__ __volatile__("move %0, $sp" : "=r"(ret) : );
36
37 return ret;
38}
39
40void arch_lmb_reserve(struct lmb *lmb)
41{
42 ulong sp;
43
44 sp = arch_get_sp();
45 debug("## Current stack ends at 0x%08lx\n", sp);
46
47 /* adjust sp by 4K to be safe */
48 sp -= 4096;
49 lmb_reserve(lmb, sp, CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp);
50}
51
c9639421
DS
52static int boot_setup_linux(bootm_headers_t *images)
53{
54 int ret;
55 ulong rd_len;
56
57 rd_len = images->rd_end - images->rd_start;
58 ret = boot_ramdisk_high(&images->lmb, images->rd_start,
59 rd_len, &images->initrd_start, &images->initrd_end);
60 if (ret)
61 return ret;
62
63 return 0;
64}
65
59e8cbdb
DS
66static void linux_cmdline_init(void)
67{
68 linux_argc = 1;
69 linux_argv = (char **)UNCACHED_SDRAM(gd->bd->bi_boot_params);
70 linux_argv[0] = 0;
71 linux_argp = (char *)(linux_argv + LINUX_MAX_ARGS);
72}
73
74static void linux_cmdline_set(const char *value, size_t len)
75{
76 linux_argv[linux_argc] = linux_argp;
77 memcpy(linux_argp, value, len);
78 linux_argp[len] = 0;
79
80 linux_argp += len + 1;
81 linux_argc++;
82}
83
84static void linux_cmdline_dump(void)
85{
86 int i;
87
88 debug("## cmdline argv at 0x%p, argp at 0x%p\n",
89 linux_argv, linux_argp);
90
91 for (i = 1; i < linux_argc; i++)
92 debug(" arg %03d: %s\n", i, linux_argv[i]);
93}
94
95static void boot_cmdline_linux(bootm_headers_t *images)
96{
97 const char *bootargs, *next, *quote;
98
99 linux_cmdline_init();
100
101 bootargs = getenv("bootargs");
102 if (!bootargs)
103 return;
104
105 next = bootargs;
106
107 while (bootargs && *bootargs && linux_argc < LINUX_MAX_ARGS) {
108 quote = strchr(bootargs, '"');
109 next = strchr(bootargs, ' ');
110
111 while (next && quote && quote < next) {
112 /*
113 * we found a left quote before the next blank
114 * now we have to find the matching right quote
115 */
116 next = strchr(quote + 1, '"');
117 if (next) {
118 quote = strchr(next + 1, '"');
119 next = strchr(next + 1, ' ');
120 }
121 }
122
123 if (!next)
124 next = bootargs + strlen(bootargs);
125
126 linux_cmdline_set(bootargs, next - bootargs);
127
128 if (*next)
129 next++;
130
131 bootargs = next;
132 }
133
134 linux_cmdline_dump();
135}
136
15f8aa90
DS
137static void linux_env_init(void)
138{
139 linux_env = (char **)(((ulong) linux_argp + 15) & ~15);
140 linux_env[0] = 0;
141 linux_env_p = (char *)(linux_env + LINUX_MAX_ENVS);
142 linux_env_idx = 0;
143}
144
145static void linux_env_set(const char *env_name, const char *env_val)
146{
147 if (linux_env_idx < LINUX_MAX_ENVS - 1) {
148 linux_env[linux_env_idx] = linux_env_p;
149
150 strcpy(linux_env_p, env_name);
151 linux_env_p += strlen(env_name);
152
7a9d109b 153 if (mips_boot_malta) {
b87493f4
DS
154 linux_env_p++;
155 linux_env[++linux_env_idx] = linux_env_p;
156 } else {
157 *linux_env_p++ = '=';
158 }
15f8aa90
DS
159
160 strcpy(linux_env_p, env_val);
161 linux_env_p += strlen(env_val);
162
163 linux_env_p++;
164 linux_env[++linux_env_idx] = 0;
165 }
166}
167
0ea7213f 168static void boot_prep_linux(bootm_headers_t *images)
c021880a 169{
e51a6b7a 170 char env_buf[12];
15f8aa90 171 const char *cp;
6c154552 172 ulong rd_start, rd_size;
5da627a4
WD
173
174#ifdef CONFIG_MEMSIZE_IN_BYTES
e51a6b7a
DS
175 sprintf(env_buf, "%lu", (ulong)gd->ram_size);
176 debug("## Giving linux memsize in bytes, %lu\n", (ulong)gd->ram_size);
5da627a4 177#else
e51a6b7a
DS
178 sprintf(env_buf, "%lu", (ulong)(gd->ram_size >> 20));
179 debug("## Giving linux memsize in MB, %lu\n",
45bde489 180 (ulong)(gd->ram_size >> 20));
5da627a4 181#endif /* CONFIG_MEMSIZE_IN_BYTES */
c021880a 182
6c154552
DS
183 rd_start = UNCACHED_SDRAM(images->initrd_start);
184 rd_size = images->initrd_end - images->initrd_start;
185
15f8aa90
DS
186 linux_env_init();
187
e51a6b7a 188 linux_env_set("memsize", env_buf);
c021880a 189
6c154552 190 sprintf(env_buf, "0x%08lX", rd_start);
e51a6b7a 191 linux_env_set("initrd_start", env_buf);
c021880a 192
6c154552 193 sprintf(env_buf, "0x%lX", rd_size);
e51a6b7a 194 linux_env_set("initrd_size", env_buf);
c021880a 195
e51a6b7a
DS
196 sprintf(env_buf, "0x%08X", (uint) (gd->bd->bi_flashstart));
197 linux_env_set("flash_start", env_buf);
c021880a 198
e51a6b7a
DS
199 sprintf(env_buf, "0x%X", (uint) (gd->bd->bi_flashsize));
200 linux_env_set("flash_size", env_buf);
c021880a 201
e7c37452 202 cp = getenv("ethaddr");
e51a6b7a 203 if (cp)
e7c37452 204 linux_env_set("ethaddr", cp);
e7c37452
JM
205
206 cp = getenv("eth1addr");
e51a6b7a 207 if (cp)
e7c37452 208 linux_env_set("eth1addr", cp);
b87493f4 209
d18d49d7
PB
210 if (mips_boot_malta) {
211 sprintf(env_buf, "%un8r", gd->baudrate);
212 linux_env_set("modetty0", env_buf);
213 }
0ea7213f
GJ
214}
215
216static void boot_jump_linux(bootm_headers_t *images)
217{
c4b37847
DS
218 typedef void __noreturn (*kernel_entry_t)(int, ulong, ulong, ulong);
219 kernel_entry_t kernel = (kernel_entry_t) images->ep;
b87493f4 220 ulong linux_extra = 0;
0ea7213f 221
c4b37847 222 debug("## Transferring control to Linux (at address %p) ...\n", kernel);
0ea7213f
GJ
223
224 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
225
7a9d109b 226 if (mips_boot_malta)
b87493f4
DS
227 linux_extra = gd->ram_size;
228
0ea7213f
GJ
229 /* we assume that the kernel is in place */
230 printf("\nStarting kernel ...\n\n");
231
b87493f4 232 kernel(linux_argc, (ulong)linux_argv, (ulong)linux_env, linux_extra);
0ea7213f
GJ
233}
234
235int do_bootm_linux(int flag, int argc, char * const argv[],
236 bootm_headers_t *images)
237{
c9639421
DS
238 int ret;
239
9c170e2e 240 /* No need for those on MIPS */
59e8cbdb 241 if (flag & BOOTM_STATE_OS_BD_T)
9c170e2e
GJ
242 return -1;
243
59e8cbdb
DS
244 if (flag & BOOTM_STATE_OS_CMDLINE) {
245 boot_cmdline_linux(images);
246 return 0;
247 }
248
9c170e2e
GJ
249 if (flag & BOOTM_STATE_OS_PREP) {
250 boot_prep_linux(images);
251 return 0;
252 }
253
254 if (flag & BOOTM_STATE_OS_GO) {
255 boot_jump_linux(images);
256 return 0;
257 }
e7c37452 258
c9639421
DS
259 ret = boot_setup_linux(images);
260 if (ret)
261 return ret;
262
59e8cbdb 263 boot_cmdline_linux(images);
0ea7213f 264 boot_prep_linux(images);
e08634c7 265 boot_jump_linux(images);
c021880a 266
cd7c596e 267 /* does not return */
40d7e99d 268 return 1;
c021880a 269}