blob: 391168787a97cf0c1445e1bf1d9b54f26c2f152f [file] [log] [blame]
Marian Balakowicz5d3cc552008-01-08 18:11:43 +01001/*
2 * (C) Copyright 2008 Semihalf
3 *
4 * (C) Copyright 2000-2006
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
Marian Balakowicz75824382008-01-31 13:20:06 +010026#define DEBUG
27
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010028#include <common.h>
29#include <watchdog.h>
30#include <command.h>
31#include <image.h>
32#include <malloc.h>
33#include <zlib.h>
34#include <bzlib.h>
35#include <environment.h>
36#include <asm/byteorder.h>
37
38#if defined(CONFIG_OF_LIBFDT)
39#include <fdt.h>
40#include <libfdt.h>
41#include <fdt_support.h>
Marian Balakowiczd45d5a12008-01-08 18:11:43 +010042#elif defined(CONFIG_OF_FLAT_TREE)
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010043#include <ft_build.h>
44#endif
45
46#ifdef CONFIG_LOGBUFFER
47#include <logbuff.h>
48#endif
49
50#ifdef CFG_INIT_RAM_LOCK
51#include <asm/cache.h>
52#endif
53
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010054DECLARE_GLOBAL_DATA_PTR;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010055
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010056extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
57
58#if defined(CONFIG_CMD_BDI)
59extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
60#endif
61
62void __attribute__((noinline))
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010063do_bootm_linux(cmd_tbl_t *cmdtp, int flag,
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010064 int argc, char *argv[],
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010065 image_header_t *hdr,
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010066 int verify)
67{
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010068 ulong initrd_high;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010069 int initrd_copy_to_ram = 1;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010070 ulong initrd_start, initrd_end;
71 ulong rd_data, rd_len;
72 image_header_t *rd_hdr;
73
74 ulong cmd_start, cmd_end;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010075 char *cmdline;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010076
77 ulong sp;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010078 char *s;
79 bd_t *kbd;
80 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010081
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010082#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010083 image_header_t *fdt_hdr;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +010084 char *of_flat_tree = NULL;
85 ulong of_data = 0;
86#endif
87
88 if ((s = getenv ("initrd_high")) != NULL) {
89 /* a value of "no" or a similar string will act like 0,
90 * turning the "load high" feature off. This is intentional.
91 */
92 initrd_high = simple_strtoul(s, NULL, 16);
93 if (initrd_high == ~0)
94 initrd_copy_to_ram = 0;
95 } else { /* not set, no restrictions to load high */
96 initrd_high = ~0;
97 }
98
99#ifdef CONFIG_LOGBUFFER
100 kbd=gd->bd;
101 /* Prevent initrd from overwriting logbuffer */
102 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
103 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
104 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
105#endif
106
107 /*
108 * Booting a (Linux) kernel image
109 *
110 * Allocate space for command line and board info - the
111 * address should be as high as possible within the reach of
112 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
113 * memory, which means far enough below the current stack
114 * pointer.
115 */
116
117 asm( "mr %0,1": "=r"(sp) : );
118
119 debug ("## Current stack ends at 0x%08lX ", sp);
120
121 sp -= 2048; /* just to be sure */
122 if (sp > CFG_BOOTMAPSZ)
123 sp = CFG_BOOTMAPSZ;
124 sp &= ~0xF;
125
126 debug ("=> set upper limit to 0x%08lX\n", sp);
127
128 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
129 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
130
131 if ((s = getenv("bootargs")) == NULL)
132 s = "";
133
134 strcpy (cmdline, s);
135
136 cmd_start = (ulong)&cmdline[0];
137 cmd_end = cmd_start + strlen(cmdline);
138
139 *kbd = *(gd->bd);
140
141#ifdef DEBUG
142 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
143
144#if defined(CONFIG_CMD_BDI)
145 do_bdinfo (NULL, 0, 0, NULL);
146#endif
147#endif
148
149 if ((s = getenv ("clocks_in_mhz")) != NULL) {
150 /* convert all clock information to MHz */
151 kbd->bi_intfreq /= 1000000L;
152 kbd->bi_busfreq /= 1000000L;
153#if defined(CONFIG_MPC8220)
154 kbd->bi_inpfreq /= 1000000L;
155 kbd->bi_pcifreq /= 1000000L;
156 kbd->bi_pevfreq /= 1000000L;
157 kbd->bi_flbfreq /= 1000000L;
158 kbd->bi_vcofreq /= 1000000L;
159#endif
160#if defined(CONFIG_CPM2)
161 kbd->bi_cpmfreq /= 1000000L;
162 kbd->bi_brgfreq /= 1000000L;
163 kbd->bi_sccfreq /= 1000000L;
164 kbd->bi_vco /= 1000000L;
165#endif
166#if defined(CONFIG_MPC5xxx)
167 kbd->bi_ipbfreq /= 1000000L;
168 kbd->bi_pcifreq /= 1000000L;
169#endif /* CONFIG_MPC5xxx */
170 }
171
172 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr);
173
174 /*
175 * Check if there is an initrd image
176 */
177
178#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
179 /* Look for a '-' which indicates to ignore the ramdisk argument */
180 if (argc >= 3 && strcmp(argv[2], "-") == 0) {
181 debug ("Skipping initrd\n");
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100182 rd_len = rd_data = 0;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100183 }
184 else
185#endif
186 if (argc >= 3) {
187 debug ("Not skipping initrd\n");
188 show_boot_progress (9);
189
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100190 rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16);
191 printf ("## Loading RAMDisk Image at %08lx ...\n", (ulong)rd_hdr);
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100192
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100193 if (!image_check_magic (rd_hdr)) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100194 puts ("Bad Magic Number\n");
195 show_boot_progress (-10);
196 do_reset (cmdtp, flag, argc, argv);
197 }
198
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100199 if (!image_check_hcrc (rd_hdr)) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100200 puts ("Bad Header Checksum\n");
201 show_boot_progress (-11);
202 do_reset (cmdtp, flag, argc, argv);
203 }
204 show_boot_progress (10);
205
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100206 print_image_hdr (rd_hdr);
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100207
208 if (verify) {
209 puts (" Verifying Checksum ... ");
210
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100211 if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100212 puts ("Bad Data CRC\n");
213 show_boot_progress (-12);
214 do_reset (cmdtp, flag, argc, argv);
215 }
216 puts ("OK\n");
217 }
218
219 show_boot_progress (11);
220
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100221 if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
222 !image_check_arch (rd_hdr, IH_ARCH_PPC) ||
223 !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100224 puts ("No Linux PPC Ramdisk Image\n");
225 show_boot_progress (-13);
226 do_reset (cmdtp, flag, argc, argv);
227 }
228
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100229 rd_data = image_get_data (rd_hdr);
230 rd_len = image_get_data_size (rd_hdr);
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100231
232 /*
233 * Now check if we have a multifile image
234 */
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100235 } else if (image_check_type (hdr, IH_TYPE_MULTI)) {
236 /*
237 * Get second entry data start address and len
238 */
239 image_multi_getimg (hdr, 1, &rd_data, &rd_len);
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100240 show_boot_progress (13);
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100241 } else {
242 /*
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100243 * No initrd image
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100244 */
245 show_boot_progress (14);
246
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100247 rd_len = rd_data = 0;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100248 }
249
250#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
251 if(argc > 3) {
252 of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100253 fdt_hdr = (image_header_t *)of_flat_tree;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100254#if defined(CONFIG_OF_FLAT_TREE)
Marian Balakowicz958fc482008-01-08 18:11:44 +0100255 if (*((ulong *)(of_flat_tree)) == OF_DT_HEADER) {
Marian Balakowiczd45d5a12008-01-08 18:11:43 +0100256#elif defined(CONFIG_OF_LIBFDT)
Marian Balakowicz958fc482008-01-08 18:11:44 +0100257 if (fdt_check_header (of_flat_tree) == 0) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100258#endif
259#ifndef CFG_NO_FLASH
260 if (addr2info((ulong)of_flat_tree) != NULL)
261 of_data = (ulong)of_flat_tree;
262#endif
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100263 } else if (image_check_magic (fdt_hdr)) {
Marian Balakowicz75824382008-01-31 13:20:06 +0100264 ulong image_start, image_end;
265 ulong load_start, load_end;
266
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100267 printf ("## Flat Device Tree at %08lX\n", fdt_hdr);
268 print_image_hdr (fdt_hdr);
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100269
Marian Balakowicz75824382008-01-31 13:20:06 +0100270 image_start = (ulong)fdt_hdr;
271 image_end = image_get_image_end (fdt_hdr);
272
273 load_start = image_get_load (fdt_hdr);
274 load_end = load_start + image_get_data_size (fdt_hdr);
275
276 if ((load_start < image_end) && (load_end > image_start)) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100277 puts ("ERROR: fdt overwritten - "
278 "must RESET the board to recover.\n");
279 do_reset (cmdtp, flag, argc, argv);
280 }
281
282 puts (" Verifying Checksum ... ");
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100283 if (!image_check_hcrc (fdt_hdr)) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100284 puts ("ERROR: fdt header checksum invalid - "
285 "must RESET the board to recover.\n");
286 do_reset (cmdtp, flag, argc, argv);
287 }
288
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100289 if (!image_check_dcrc (fdt_hdr)) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100290 puts ("ERROR: fdt checksum invalid - "
291 "must RESET the board to recover.\n");
292 do_reset (cmdtp, flag, argc, argv);
293 }
294 puts ("OK\n");
295
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100296 if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100297 puts ("ERROR: uImage is not a fdt - "
298 "must RESET the board to recover.\n");
299 do_reset (cmdtp, flag, argc, argv);
300 }
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100301 if (image_get_comp (fdt_hdr) != IH_COMP_NONE) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100302 puts ("ERROR: uImage is compressed - "
303 "must RESET the board to recover.\n");
304 do_reset (cmdtp, flag, argc, argv);
305 }
306#if defined(CONFIG_OF_FLAT_TREE)
307 if (*((ulong *)(of_flat_tree + image_get_header_size ())) != OF_DT_HEADER) {
Marian Balakowiczd45d5a12008-01-08 18:11:43 +0100308#elif defined(CONFIG_OF_LIBFDT)
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100309 if (fdt_check_header (of_flat_tree + image_get_header_size ()) != 0) {
310#endif
311 puts ("ERROR: uImage data is not a fdt - "
312 "must RESET the board to recover.\n");
313 do_reset (cmdtp, flag, argc, argv);
314 }
315
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100316 memmove ((void *)image_get_load (fdt_hdr),
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100317 (void *)(of_flat_tree + image_get_header_size ()),
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100318 image_get_data_size (fdt_hdr));
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100319
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100320 of_flat_tree = (char *)image_get_load (fdt_hdr);
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100321 } else {
322 puts ("Did not find a flat Flat Device Tree.\n"
323 "Must RESET the board to recover.\n");
324 do_reset (cmdtp, flag, argc, argv);
325 }
326 printf (" Booting using the fdt at 0x%x\n",
327 of_flat_tree);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100328 } else if (image_check_type (hdr, IH_TYPE_MULTI)) {
329 ulong fdt_data, fdt_len;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100330
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100331 image_multi_getimg (hdr, 2, &fdt_data, &fdt_len);
332 if (fdt_len) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100333
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100334 of_flat_tree = (char *)fdt_data;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100335
336#ifndef CFG_NO_FLASH
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100337 /* move the blob if it is in flash (set of_data to !null) */
338 if (addr2info ((ulong)of_flat_tree) != NULL)
339 of_data = (ulong)of_flat_tree;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100340#endif
341
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100342#if defined(CONFIG_OF_FLAT_TREE)
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100343 if (*((ulong *)(of_flat_tree)) != OF_DT_HEADER) {
Marian Balakowiczd45d5a12008-01-08 18:11:43 +0100344#elif defined(CONFIG_OF_LIBFDT)
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100345 if (fdt_check_header (of_flat_tree) != 0) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100346#endif
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100347 puts ("ERROR: image is not a fdt - "
348 "must RESET the board to recover.\n");
349 do_reset (cmdtp, flag, argc, argv);
350 }
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100351
352#if defined(CONFIG_OF_FLAT_TREE)
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100353 if (((struct boot_param_header *)of_flat_tree)->totalsize != fdt_len) {
Marian Balakowiczd45d5a12008-01-08 18:11:43 +0100354#elif defined(CONFIG_OF_LIBFDT)
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100355 if (be32_to_cpu (fdt_totalsize (of_flat_tree)) != fdt_len) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100356#endif
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100357 puts ("ERROR: fdt size != image size - "
358 "must RESET the board to recover.\n");
359 do_reset (cmdtp, flag, argc, argv);
360 }
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100361 }
362 }
363#endif
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100364 if (!rd_data) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100365 debug ("No initrd\n");
366 }
367
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100368 if (rd_data) {
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100369 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100370 initrd_start = rd_data;
371 initrd_end = initrd_start + rd_len;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100372 } else {
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100373 initrd_start = (ulong)kbd - rd_len;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100374 initrd_start &= ~(4096 - 1); /* align on page */
375
376 if (initrd_high) {
377 ulong nsp;
378
379 /*
380 * the inital ramdisk does not need to be within
381 * CFG_BOOTMAPSZ as it is not accessed until after
382 * the mm system is initialised.
383 *
384 * do the stack bottom calculation again and see if
385 * the initrd will fit just below the monitor stack
386 * bottom without overwriting the area allocated
387 * above for command line args and board info.
388 */
389 asm( "mr %0,1": "=r"(nsp) : );
390 nsp -= 2048; /* just to be sure */
391 nsp &= ~0xF;
392 if (nsp > initrd_high) /* limit as specified */
393 nsp = initrd_high;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100394 nsp -= rd_len;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100395 nsp &= ~(4096 - 1); /* align on page */
396 if (nsp >= sp)
397 initrd_start = nsp;
398 }
399
400 show_boot_progress (12);
401
402 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100403 rd_data, rd_data + rd_len - 1, rd_len, rd_len);
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100404
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100405 initrd_end = initrd_start + rd_len;
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100406 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
407 initrd_start, initrd_end);
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100408
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100409 memmove_wd((void *)initrd_start,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100410 (void *)rd_data, rd_len, CHUNKSZ);
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100411
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100412 puts ("OK\n");
413 }
414 } else {
415 initrd_start = 0;
416 initrd_end = 0;
417 }
418
419#if defined(CONFIG_OF_LIBFDT)
420
421#ifdef CFG_BOOTMAPSZ
422 /*
423 * The blob must be within CFG_BOOTMAPSZ,
424 * so we flag it to be copied if it is not.
425 */
426 if (of_flat_tree >= (char *)CFG_BOOTMAPSZ)
427 of_data = (ulong)of_flat_tree;
428#endif
429
430 /* move of_flat_tree if needed */
431 if (of_data) {
432 int err;
433 ulong of_start, of_len;
434
435 of_len = be32_to_cpu(fdt_totalsize(of_data));
436
437 /* position on a 4K boundary before the kbd */
438 of_start = (ulong)kbd - of_len;
439 of_start &= ~(4096 - 1); /* align on page */
440 debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
441 of_data, of_data + of_len - 1, of_len, of_len);
442
443 of_flat_tree = (char *)of_start;
444 printf (" Loading Device Tree to %08lx, end %08lx ... ",
445 of_start, of_start + of_len - 1);
446 err = fdt_open_into((void *)of_data, (void *)of_start, of_len);
447 if (err != 0) {
448 puts ("ERROR: fdt move failed - "
449 "must RESET the board to recover.\n");
450 do_reset (cmdtp, flag, argc, argv);
451 }
452 puts ("OK\n");
453 }
454 /*
455 * Add the chosen node if it doesn't exist, add the env and bd_t
456 * if the user wants it (the logic is in the subroutines).
457 */
458 if (of_flat_tree) {
459 if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) {
460 puts ("ERROR: /chosen node create failed - "
461 "must RESET the board to recover.\n");
462 do_reset (cmdtp, flag, argc, argv);
463 }
464#ifdef CONFIG_OF_HAS_UBOOT_ENV
465 if (fdt_env(of_flat_tree) < 0) {
466 puts ("ERROR: /u-boot-env node create failed - "
467 "must RESET the board to recover.\n");
468 do_reset (cmdtp, flag, argc, argv);
469 }
470#endif
471#ifdef CONFIG_OF_HAS_BD_T
472 if (fdt_bd_t(of_flat_tree) < 0) {
473 puts ("ERROR: /bd_t node create failed - "
474 "must RESET the board to recover.\n");
475 do_reset (cmdtp, flag, argc, argv);
476 }
477#endif
478#ifdef CONFIG_OF_BOARD_SETUP
479 /* Call the board-specific fixup routine */
480 ft_board_setup(of_flat_tree, gd->bd);
481#endif
482 }
Marian Balakowiczd45d5a12008-01-08 18:11:43 +0100483
484#elif defined(CONFIG_OF_FLAT_TREE)
485
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100486#ifdef CFG_BOOTMAPSZ
487 /*
488 * The blob must be within CFG_BOOTMAPSZ,
489 * so we flag it to be copied if it is not.
490 */
491 if (of_flat_tree >= (char *)CFG_BOOTMAPSZ)
492 of_data = (ulong)of_flat_tree;
493#endif
494
495 /* move of_flat_tree if needed */
496 if (of_data) {
497 ulong of_start, of_len;
498 of_len = ((struct boot_param_header *)of_data)->totalsize;
499
500 /* provide extra 8k pad */
501 of_start = (ulong)kbd - of_len - 8192;
502 of_start &= ~(4096 - 1); /* align on page */
503 debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
504 of_data, of_data + of_len - 1, of_len, of_len);
505
506 of_flat_tree = (char *)of_start;
507 printf (" Loading Device Tree to %08lx, end %08lx ... ",
508 of_start, of_start + of_len - 1);
509 memmove ((void *)of_start, (void *)of_data, of_len);
510 puts ("OK\n");
511 }
512 /*
513 * Create the /chosen node and modify the blob with board specific
514 * values as needed.
515 */
516 ft_setup(of_flat_tree, kbd, initrd_start, initrd_end);
517 /* ft_dump_blob(of_flat_tree); */
Marian Balakowiczd45d5a12008-01-08 18:11:43 +0100518
519#endif /* #if defined(CONFIG_OF_LIBFDT) #elif defined(CONFIG_OF_FLAT_TREE) */
520
Marian Balakowicz5d3cc552008-01-08 18:11:43 +0100521 debug ("## Transferring control to Linux (at address %08lx) ...\n",
522 (ulong)kernel);
523
524 show_boot_progress (15);
525
526#if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
527 unlock_ram_in_cache();
528#endif
529
530#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
531 if (of_flat_tree) { /* device tree; boot new style */
532 /*
533 * Linux Kernel Parameters (passing device tree):
534 * r3: pointer to the fdt, followed by the board info data
535 * r4: physical pointer to the kernel itself
536 * r5: NULL
537 * r6: NULL
538 * r7: NULL
539 */
540 (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0);
541 /* does not return */
542 }
543#endif
544 /*
545 * Linux Kernel Parameters (passing board info data):
546 * r3: ptr to board info data
547 * r4: initrd_start or 0 if no initrd
548 * r5: initrd_end - unused if r4 is 0
549 * r6: Start of command line string
550 * r7: End of command line string
551 */
552 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
553 /* does not return */
554}