]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/mips/lib/bootm.c
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
11 #include <u-boot/zlib.h>
12 #include <asm/byteorder.h>
13 #include <asm/addrspace.h>
15 DECLARE_GLOBAL_DATA_PTR
;
17 #define LINUX_MAX_ENVS 256
18 #define LINUX_MAX_ARGS 256
20 static int linux_argc
;
21 static char **linux_argv
;
23 static char **linux_env
;
24 static char *linux_env_p
;
25 static int linux_env_idx
;
27 static void linux_params_init(ulong start
, char *commandline
);
28 static void linux_env_set(char *env_name
, char *env_val
);
30 static void boot_prep_linux(bootm_headers_t
*images
)
32 char *commandline
= getenv("bootargs");
36 linux_params_init(UNCACHED_SDRAM(gd
->bd
->bi_boot_params
), commandline
);
38 #ifdef CONFIG_MEMSIZE_IN_BYTES
39 sprintf(env_buf
, "%lu", (ulong
)gd
->ram_size
);
40 debug("## Giving linux memsize in bytes, %lu\n", (ulong
)gd
->ram_size
);
42 sprintf(env_buf
, "%lu", (ulong
)(gd
->ram_size
>> 20));
43 debug("## Giving linux memsize in MB, %lu\n",
44 (ulong
)(gd
->ram_size
>> 20));
45 #endif /* CONFIG_MEMSIZE_IN_BYTES */
47 linux_env_set("memsize", env_buf
);
49 sprintf(env_buf
, "0x%08X", (uint
) UNCACHED_SDRAM(images
->rd_start
));
50 linux_env_set("initrd_start", env_buf
);
52 sprintf(env_buf
, "0x%X", (uint
) (images
->rd_end
- images
->rd_start
));
53 linux_env_set("initrd_size", env_buf
);
55 sprintf(env_buf
, "0x%08X", (uint
) (gd
->bd
->bi_flashstart
));
56 linux_env_set("flash_start", env_buf
);
58 sprintf(env_buf
, "0x%X", (uint
) (gd
->bd
->bi_flashsize
));
59 linux_env_set("flash_size", env_buf
);
61 cp
= getenv("ethaddr");
63 linux_env_set("ethaddr", cp
);
65 cp
= getenv("eth1addr");
67 linux_env_set("eth1addr", cp
);
70 static void boot_jump_linux(bootm_headers_t
*images
)
72 void (*theKernel
) (int, char **, char **, int *);
74 /* find kernel entry point */
75 theKernel
= (void (*)(int, char **, char **, int *))images
->ep
;
77 debug("## Transferring control to Linux (at address %08lx) ...\n",
80 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
82 /* we assume that the kernel is in place */
83 printf("\nStarting kernel ...\n\n");
85 theKernel(linux_argc
, linux_argv
, linux_env
, 0);
88 int do_bootm_linux(int flag
, int argc
, char * const argv
[],
89 bootm_headers_t
*images
)
91 /* No need for those on MIPS */
92 if (flag
& BOOTM_STATE_OS_BD_T
|| flag
& BOOTM_STATE_OS_CMDLINE
)
95 if (flag
& BOOTM_STATE_OS_PREP
) {
96 boot_prep_linux(images
);
100 if (flag
& BOOTM_STATE_OS_GO
) {
101 boot_jump_linux(images
);
105 boot_prep_linux(images
);
106 boot_jump_linux(images
);
108 /* does not return */
112 static void linux_params_init(ulong start
, char *line
)
114 char *next
, *quote
, *argp
;
117 linux_argv
= (char **) start
;
119 argp
= (char *) (linux_argv
+ LINUX_MAX_ARGS
);
123 while (line
&& *line
&& linux_argc
< LINUX_MAX_ARGS
) {
124 quote
= strchr(line
, '"');
125 next
= strchr(line
, ' ');
127 while (next
&& quote
&& quote
< next
) {
128 /* we found a left quote before the next blank
129 * now we have to find the matching right quote
131 next
= strchr(quote
+ 1, '"');
133 quote
= strchr(next
+ 1, '"');
134 next
= strchr(next
+ 1, ' ');
139 next
= line
+ strlen(line
);
141 linux_argv
[linux_argc
] = argp
;
142 memcpy(argp
, line
, next
- line
);
143 argp
[next
- line
] = 0;
145 argp
+= next
- line
+ 1;
154 linux_env
= (char **) (((ulong
) argp
+ 15) & ~15);
156 linux_env_p
= (char *) (linux_env
+ LINUX_MAX_ENVS
);
160 static void linux_env_set(char *env_name
, char *env_val
)
162 if (linux_env_idx
< LINUX_MAX_ENVS
- 1) {
163 linux_env
[linux_env_idx
] = linux_env_p
;
165 strcpy(linux_env_p
, env_name
);
166 linux_env_p
+= strlen(env_name
);
168 strcpy(linux_env_p
, "=");
171 strcpy(linux_env_p
, env_val
);
172 linux_env_p
+= strlen(env_val
);
175 linux_env
[++linux_env_idx
] = 0;