]>
git.ipfire.org Git - people/ms/u-boot.git/blob - lib_mips/bootm.c
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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
28 #include <asm/byteorder.h>
29 #include <asm/addrspace.h>
31 DECLARE_GLOBAL_DATA_PTR
;
33 #define LINUX_MAX_ENVS 256
34 #define LINUX_MAX_ARGS 256
36 extern int do_reset (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
38 static int linux_argc
;
39 static char ** linux_argv
;
41 static char ** linux_env
;
42 static char * linux_env_p
;
43 static int linux_env_idx
;
45 static void linux_params_init (ulong start
, char * commandline
);
46 static void linux_env_set (char * env_name
, char * env_val
);
49 void do_bootm_linux (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[],
50 image_header_t
*hdr
, int verify
)
52 ulong rd_data
, rd_len
;
53 ulong initrd_start
, initrd_end
;
54 image_header_t
*rd_hdr
;
56 void (*theKernel
) (int, char **, char **, int *);
57 char *commandline
= getenv ("bootargs");
61 (void (*)(int, char **, char **, int *))image_get_ep (hdr
);
64 * Check if there is an initrd image
67 show_boot_progress (9);
69 rd_hdr
= (image_header_t
*)simple_strtoul (argv
[2], NULL
, 16);
70 printf ("## Loading Ramdisk Image at %08lx ...\n", rd_hdr
);
72 if (!image_check_magic (rd_hdr
)) {
73 printf ("Bad Magic Number\n");
74 show_boot_progress (-10);
75 do_reset (cmdtp
, flag
, argc
, argv
);
78 if (!image_check_hcrc (rd_hdr
)) {
79 printf ("Bad Header Checksum\n");
80 show_boot_progress (-11);
81 do_reset (cmdtp
, flag
, argc
, argv
);
84 show_boot_progress (10);
85 print_image_hdr (rd_hdr
);
87 rd_data
= image_get_data (rd_hdr
);
88 rd_len
= image_get_data_size (rd_hdr
);
91 printf (" Verifying Checksum ... ");
92 if (!image_check_dcrc (rd_hdr
)) {
93 printf ("Bad Data CRC\n");
94 show_boot_progress (-12);
95 do_reset (cmdtp
, flag
, argc
, argv
);
100 show_boot_progress (11);
102 if (!image_check_os (rd_hdr
, IH_OS_LINUX
) ||
103 !image_check_arch (rd_hdr
, IH_ARCH_MIPS
) ||
104 !image_check_type (rd_hdr
, IH_TYPE_RAMDISK
)) {
105 printf ("No Linux MIPS Ramdisk Image\n");
106 show_boot_progress (-13);
107 do_reset (cmdtp
, flag
, argc
, argv
);
111 * Now check if we have a multifile image
113 } else if (image_check_type (hdr
, IH_TYPE_MULTI
)) {
115 * Get second entry data start address and len
117 show_boot_progress (13);
118 image_multi_getimg (hdr
, 1, &rd_data
, &rd_len
);
123 show_boot_progress (14);
125 rd_data
= rd_len
= 0;
130 printf ("No initrd\n");
135 initrd_start
= rd_data
;
136 initrd_end
= initrd_start
+ rd_len
;
142 show_boot_progress (15);
145 printf ("## Transferring control to Linux (at address %08lx) ...\n",
149 linux_params_init (UNCACHED_SDRAM (gd
->bd
->bi_boot_params
), commandline
);
151 #ifdef CONFIG_MEMSIZE_IN_BYTES
152 sprintf (env_buf
, "%lu", gd
->ram_size
);
154 printf ("## Giving linux memsize in bytes, %lu\n", gd
->ram_size
);
157 sprintf (env_buf
, "%lu", gd
->ram_size
>> 20);
159 printf ("## Giving linux memsize in MB, %lu\n", gd
->ram_size
>> 20);
161 #endif /* CONFIG_MEMSIZE_IN_BYTES */
163 linux_env_set ("memsize", env_buf
);
165 sprintf (env_buf
, "0x%08X", (uint
) UNCACHED_SDRAM (initrd_start
));
166 linux_env_set ("initrd_start", env_buf
);
168 sprintf (env_buf
, "0x%X", (uint
) (initrd_end
- initrd_start
));
169 linux_env_set ("initrd_size", env_buf
);
171 sprintf (env_buf
, "0x%08X", (uint
) (gd
->bd
->bi_flashstart
));
172 linux_env_set ("flash_start", env_buf
);
174 sprintf (env_buf
, "0x%X", (uint
) (gd
->bd
->bi_flashsize
));
175 linux_env_set ("flash_size", env_buf
);
177 /* we assume that the kernel is in place */
178 printf ("\nStarting kernel ...\n\n");
180 theKernel (linux_argc
, linux_argv
, linux_env
, 0);
183 static void linux_params_init (ulong start
, char *line
)
185 char *next
, *quote
, *argp
;
188 linux_argv
= (char **) start
;
190 argp
= (char *) (linux_argv
+ LINUX_MAX_ARGS
);
194 while (line
&& *line
&& linux_argc
< LINUX_MAX_ARGS
) {
195 quote
= strchr (line
, '"');
196 next
= strchr (line
, ' ');
198 while (next
!= NULL
&& quote
!= NULL
&& quote
< next
) {
199 /* we found a left quote before the next blank
200 * now we have to find the matching right quote
202 next
= strchr (quote
+ 1, '"');
204 quote
= strchr (next
+ 1, '"');
205 next
= strchr (next
+ 1, ' ');
210 next
= line
+ strlen (line
);
213 linux_argv
[linux_argc
] = argp
;
214 memcpy (argp
, line
, next
- line
);
215 argp
[next
- line
] = 0;
217 argp
+= next
- line
+ 1;
226 linux_env
= (char **) (((ulong
) argp
+ 15) & ~15);
228 linux_env_p
= (char *) (linux_env
+ LINUX_MAX_ENVS
);
232 static void linux_env_set (char *env_name
, char *env_val
)
234 if (linux_env_idx
< LINUX_MAX_ENVS
- 1) {
235 linux_env
[linux_env_idx
] = linux_env_p
;
237 strcpy (linux_env_p
, env_name
);
238 linux_env_p
+= strlen (env_name
);
240 strcpy (linux_env_p
, "=");
243 strcpy (linux_env_p
, env_val
);
244 linux_env_p
+= strlen (env_val
);
247 linux_env
[++linux_env_idx
] = 0;