]> git.ipfire.org Git - people/ms/u-boot.git/blame - lib_mips/bootm.c
[new uImage] Add dual format uImage support framework
[people/ms/u-boot.git] / lib_mips / bootm.c
CommitLineData
c021880a
WD
1/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#include <common.h>
25#include <command.h>
c021880a
WD
26#include <image.h>
27#include <zlib.h>
28#include <asm/byteorder.h>
29#include <asm/addrspace.h>
30
d87080b7
WD
31DECLARE_GLOBAL_DATA_PTR;
32
c021880a
WD
33#define LINUX_MAX_ENVS 256
34#define LINUX_MAX_ARGS 256
35
c021880a
WD
36static int linux_argc;
37static char ** linux_argv;
38
39static char ** linux_env;
40static char * linux_env_p;
41static int linux_env_idx;
42
43static void linux_params_init (ulong start, char * commandline);
44static void linux_env_set (char * env_name, char * env_val);
45
d5934ad7 46extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
c021880a 47
5da627a4 48void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
d5934ad7 49 bootm_headers_t *images, int verify)
c021880a 50{
d5934ad7
MB
51 ulong initrd_start, initrd_end;
52 ulong ep = 0;
53 void (*theKernel) (int, char **, char **, int *);
54 char *commandline = getenv ("bootargs");
55 char env_buf[12];
f13e7b2e 56
d5934ad7
MB
57 /* find kernel entry point */
58 if (images->legacy_hdr_valid) {
59 ep = image_get_ep (images->legacy_hdr_os);
60#if defined(CONFIG_FIT)
61 } else if (images->fit_uname_os) {
62 fit_unsupported_reset ("MIPS linux bootm");
63 do_reset (cmdtp, flag, argc, argv);
64#endif
65 } else {
66 puts ("Could not find kernel entry point!\n");
67 do_reset (cmdtp, flag, argc, argv);
68 }
69 theKernel = (void (*)(int, char **, char **, int *))ep;
c021880a 70
d5934ad7 71 get_ramdisk (cmdtp, flag, argc, argv, images, verify,
5ad03eb3 72 IH_ARCH_MIPS, &initrd_start, &initrd_end);
c021880a 73
fad63407 74 show_boot_progress (15);
c021880a
WD
75
76#ifdef DEBUG
5da627a4
WD
77 printf ("## Transferring control to Linux (at address %08lx) ...\n",
78 (ulong) theKernel);
c021880a
WD
79#endif
80
a2663ea4 81 linux_params_init (UNCACHED_SDRAM (gd->bd->bi_boot_params), commandline);
5da627a4
WD
82
83#ifdef CONFIG_MEMSIZE_IN_BYTES
84 sprintf (env_buf, "%lu", gd->ram_size);
85#ifdef DEBUG
86 printf ("## Giving linux memsize in bytes, %lu\n", gd->ram_size);
87#endif
88#else
89 sprintf (env_buf, "%lu", gd->ram_size >> 20);
90#ifdef DEBUG
91 printf ("## Giving linux memsize in MB, %lu\n", gd->ram_size >> 20);
92#endif
93#endif /* CONFIG_MEMSIZE_IN_BYTES */
c021880a 94
5da627a4 95 linux_env_set ("memsize", env_buf);
c021880a 96
a2663ea4 97 sprintf (env_buf, "0x%08X", (uint) UNCACHED_SDRAM (initrd_start));
5da627a4 98 linux_env_set ("initrd_start", env_buf);
c021880a 99
5da627a4
WD
100 sprintf (env_buf, "0x%X", (uint) (initrd_end - initrd_start));
101 linux_env_set ("initrd_size", env_buf);
c021880a 102
5da627a4
WD
103 sprintf (env_buf, "0x%08X", (uint) (gd->bd->bi_flashstart));
104 linux_env_set ("flash_start", env_buf);
c021880a 105
5da627a4
WD
106 sprintf (env_buf, "0x%X", (uint) (gd->bd->bi_flashsize));
107 linux_env_set ("flash_size", env_buf);
c021880a 108
5da627a4
WD
109 /* we assume that the kernel is in place */
110 printf ("\nStarting kernel ...\n\n");
c021880a 111
5da627a4 112 theKernel (linux_argc, linux_argv, linux_env, 0);
c021880a
WD
113}
114
5da627a4 115static void linux_params_init (ulong start, char *line)
c021880a 116{
5da627a4 117 char *next, *quote, *argp;
8bde7f77 118
5da627a4
WD
119 linux_argc = 1;
120 linux_argv = (char **) start;
121 linux_argv[0] = 0;
122 argp = (char *) (linux_argv + LINUX_MAX_ARGS);
123
124 next = line;
c021880a 125
5da627a4
WD
126 while (line && *line && linux_argc < LINUX_MAX_ARGS) {
127 quote = strchr (line, '"');
128 next = strchr (line, ' ');
c021880a 129
5da627a4
WD
130 while (next != NULL && quote != NULL && quote < next) {
131 /* we found a left quote before the next blank
132 * now we have to find the matching right quote
133 */
134 next = strchr (quote + 1, '"');
135 if (next != NULL) {
136 quote = strchr (next + 1, '"');
137 next = strchr (next + 1, ' ');
138 }
139 }
8bde7f77 140
5da627a4
WD
141 if (next == NULL) {
142 next = line + strlen (line);
143 }
8bde7f77 144
5da627a4
WD
145 linux_argv[linux_argc] = argp;
146 memcpy (argp, line, next - line);
147 argp[next - line] = 0;
c021880a 148
5da627a4
WD
149 argp += next - line + 1;
150 linux_argc++;
151
152 if (*next)
153 next++;
154
155 line = next;
156 }
157
158 linux_env = (char **) (((ulong) argp + 15) & ~15);
159 linux_env[0] = 0;
160 linux_env_p = (char *) (linux_env + LINUX_MAX_ENVS);
161 linux_env_idx = 0;
c021880a
WD
162}
163
5da627a4 164static void linux_env_set (char *env_name, char *env_val)
c021880a 165{
5da627a4
WD
166 if (linux_env_idx < LINUX_MAX_ENVS - 1) {
167 linux_env[linux_env_idx] = linux_env_p;
c021880a 168
5da627a4
WD
169 strcpy (linux_env_p, env_name);
170 linux_env_p += strlen (env_name);
c021880a 171
5da627a4
WD
172 strcpy (linux_env_p, "=");
173 linux_env_p += 1;
c021880a 174
5da627a4
WD
175 strcpy (linux_env_p, env_val);
176 linux_env_p += strlen (env_val);
8bde7f77 177
5da627a4
WD
178 linux_env_p++;
179 linux_env[++linux_env_idx] = 0;
180 }
c021880a 181}