]>
Commit | Line | Data |
---|---|---|
5d3cc55e MB |
1 | /* |
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 | ||
7582438c MB |
26 | #define DEBUG |
27 | ||
5d3cc55e MB |
28 | #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> | |
d3c5eb6d MB |
42 | |
43 | static void fdt_error (const char *msg); | |
9a4daad0 | 44 | static int boot_get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
d2ced9eb | 45 | bootm_headers_t *images, char **of_flat_tree, ulong *of_size); |
9a4daad0 | 46 | static int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base, |
d2ced9eb MB |
47 | cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
48 | char **of_flat_tree, ulong *of_size); | |
5d3cc55e MB |
49 | #endif |
50 | ||
5d3cc55e MB |
51 | #ifdef CFG_INIT_RAM_LOCK |
52 | #include <asm/cache.h> | |
53 | #endif | |
54 | ||
5d3cc55e | 55 | DECLARE_GLOBAL_DATA_PTR; |
5d3cc55e | 56 | |
5d3cc55e | 57 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
e822d7fc | 58 | extern ulong get_effective_memsize(void); |
ceaed2b1 | 59 | static ulong get_sp (void); |
b6b0fe64 | 60 | static void set_clocks_in_mhz (bd_t *kbd); |
5d3cc55e | 61 | |
d3f2fa0d KG |
62 | #ifndef CFG_LINUX_LOWMEM_MAX_SIZE |
63 | #define CFG_LINUX_LOWMEM_MAX_SIZE (768*1024*1024) | |
64 | #endif | |
65 | ||
5d3cc55e | 66 | void __attribute__((noinline)) |
8a5ea3e6 MB |
67 | do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
68 | bootm_headers_t *images) | |
5d3cc55e | 69 | { |
e822d7fc | 70 | ulong sp; |
b6b0fe64 | 71 | |
f13e7b2e | 72 | ulong initrd_start, initrd_end; |
5ad03eb3 | 73 | ulong rd_data_start, rd_data_end, rd_len; |
d3f2fa0d | 74 | ulong size; |
f13e7b2e | 75 | |
e822d7fc | 76 | ulong cmd_start, cmd_end, bootmap_base; |
5d3cc55e | 77 | bd_t *kbd; |
d5934ad7 | 78 | ulong ep = 0; |
5d3cc55e | 79 | void (*kernel)(bd_t *, ulong, ulong, ulong, ulong); |
d2bc095a | 80 | int ret; |
27953493 | 81 | ulong of_size = 0; |
e822d7fc | 82 | struct lmb *lmb = images->lmb; |
f13e7b2e | 83 | |
4a2ad5ff | 84 | #if defined(CONFIG_OF_LIBFDT) |
d2ced9eb | 85 | char *of_flat_tree = NULL; |
5d3cc55e MB |
86 | #endif |
87 | ||
d3f2fa0d KG |
88 | bootmap_base = getenv_bootm_low(); |
89 | size = getenv_bootm_size(); | |
90 | ||
91 | #ifdef DEBUG | |
92 | if (((u64)bootmap_base + size) > (CFG_SDRAM_BASE + (u64)gd->ram_size)) | |
93 | puts("WARNING: bootm_low + bootm_size exceed total memory\n"); | |
94 | if ((bootmap_base + size) > get_effective_memsize()) | |
95 | puts("WARNING: bootm_low + bootm_size exceed eff. memory\n"); | |
96 | #endif | |
97 | ||
98 | size = min(size, get_effective_memsize()); | |
99 | size = min(size, CFG_LINUX_LOWMEM_MAX_SIZE); | |
100 | ||
101 | if (size < getenv_bootm_size()) { | |
102 | ulong base = bootmap_base + size; | |
103 | printf("WARNING: adjusting available memory to %x\n", size); | |
104 | lmb_reserve(lmb, base, getenv_bootm_size() - size); | |
105 | } | |
e822d7fc | 106 | |
5d3cc55e MB |
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 | */ | |
b6b0fe64 | 116 | sp = get_sp(); |
d3f2fa0d | 117 | debug ("## Current stack ends at 0x%08lx\n", sp); |
5d3cc55e | 118 | |
e822d7fc KG |
119 | /* adjust sp by 1K to be safe */ |
120 | sp -= 1024; | |
121 | lmb_reserve(lmb, sp, (CFG_SDRAM_BASE + get_effective_memsize() - sp)); | |
5d3cc55e | 122 | |
27953493 KG |
123 | #if defined(CONFIG_OF_LIBFDT) |
124 | /* find flattened device tree */ | |
9a4daad0 | 125 | ret = boot_get_fdt (cmdtp, flag, argc, argv, images, &of_flat_tree, &of_size); |
274cea2b KG |
126 | |
127 | if (ret) | |
128 | goto error; | |
27953493 | 129 | #endif |
5d3cc55e | 130 | |
27953493 KG |
131 | if (!of_size) { |
132 | /* allocate space and init command line */ | |
9a4daad0 | 133 | ret = boot_get_cmdline (lmb, &cmd_start, &cmd_end, bootmap_base); |
e822d7fc KG |
134 | if (ret) { |
135 | puts("ERROR with allocation of cmdline\n"); | |
136 | goto error; | |
137 | } | |
27953493 KG |
138 | |
139 | /* allocate space for kernel copy of board info */ | |
9a4daad0 | 140 | ret = boot_get_kbd (lmb, &kbd, bootmap_base); |
e822d7fc KG |
141 | if (ret) { |
142 | puts("ERROR with allocation of kernel bd\n"); | |
143 | goto error; | |
144 | } | |
27953493 KG |
145 | set_clocks_in_mhz(kbd); |
146 | } | |
5d3cc55e | 147 | |
d5934ad7 MB |
148 | /* find kernel entry point */ |
149 | if (images->legacy_hdr_valid) { | |
150 | ep = image_get_ep (images->legacy_hdr_os); | |
151 | #if defined(CONFIG_FIT) | |
152 | } else if (images->fit_uname_os) { | |
153 | fit_unsupported_reset ("PPC linux bootm"); | |
274cea2b | 154 | goto error; |
d5934ad7 MB |
155 | #endif |
156 | } else { | |
157 | puts ("Could not find kernel entry point!\n"); | |
274cea2b | 158 | goto error; |
d5934ad7 MB |
159 | } |
160 | kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ep; | |
5d3cc55e | 161 | |
ceaed2b1 | 162 | /* find ramdisk */ |
d985c849 MB |
163 | ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_PPC, |
164 | &rd_data_start, &rd_data_end); | |
274cea2b KG |
165 | if (ret) |
166 | goto error; | |
167 | ||
5ad03eb3 | 168 | rd_len = rd_data_end - rd_data_start; |
5d3cc55e | 169 | |
4a2ad5ff | 170 | #if defined(CONFIG_OF_LIBFDT) |
9a4daad0 | 171 | ret = boot_relocate_fdt (lmb, bootmap_base, |
e822d7fc | 172 | cmdtp, flag, argc, argv, &of_flat_tree, &of_size); |
5d3cc55e | 173 | |
5d3cc55e MB |
174 | /* |
175 | * Add the chosen node if it doesn't exist, add the env and bd_t | |
176 | * if the user wants it (the logic is in the subroutines). | |
177 | */ | |
d2ced9eb | 178 | if (of_size) { |
d2bc095a KG |
179 | /* pass in dummy initrd info, we'll fix up later */ |
180 | if (fdt_chosen(of_flat_tree, rd_data_start, rd_data_end, 0) < 0) { | |
d3c5eb6d | 181 | fdt_error ("/chosen node create failed"); |
274cea2b | 182 | goto error; |
5d3cc55e MB |
183 | } |
184 | #ifdef CONFIG_OF_HAS_UBOOT_ENV | |
185 | if (fdt_env(of_flat_tree) < 0) { | |
d3c5eb6d | 186 | fdt_error ("/u-boot-env node create failed"); |
274cea2b | 187 | goto error; |
5d3cc55e MB |
188 | } |
189 | #endif | |
190 | #ifdef CONFIG_OF_HAS_BD_T | |
191 | if (fdt_bd_t(of_flat_tree) < 0) { | |
d3c5eb6d | 192 | fdt_error ("/bd_t node create failed"); |
274cea2b | 193 | goto error; |
5d3cc55e MB |
194 | } |
195 | #endif | |
196 | #ifdef CONFIG_OF_BOARD_SETUP | |
197 | /* Call the board-specific fixup routine */ | |
198 | ft_board_setup(of_flat_tree, gd->bd); | |
199 | #endif | |
200 | } | |
4a2ad5ff | 201 | #endif /* CONFIG_OF_LIBFDT */ |
d45d5a18 | 202 | |
9a4daad0 | 203 | ret = boot_ramdisk_high (lmb, rd_data_start, rd_len, &initrd_start, &initrd_end); |
e822d7fc KG |
204 | if (ret) |
205 | goto error; | |
d2bc095a KG |
206 | |
207 | #if defined(CONFIG_OF_LIBFDT) | |
208 | /* fixup the initrd now that we know where it should be */ | |
209 | if ((of_flat_tree) && (initrd_start && initrd_end)) { | |
210 | uint64_t addr, size; | |
211 | int total = fdt_num_mem_rsv(of_flat_tree); | |
212 | int j; | |
213 | ||
214 | /* Look for the dummy entry and delete it */ | |
215 | for (j = 0; j < total; j++) { | |
216 | fdt_get_mem_rsv(of_flat_tree, j, &addr, &size); | |
217 | if (addr == rd_data_start) { | |
218 | fdt_del_mem_rsv(of_flat_tree, j); | |
219 | break; | |
220 | } | |
221 | } | |
222 | ||
223 | ret = fdt_add_mem_rsv(of_flat_tree, initrd_start, | |
224 | initrd_end - initrd_start + 1); | |
225 | if (ret < 0) { | |
226 | printf("fdt_chosen: %s\n", fdt_strerror(ret)); | |
274cea2b | 227 | goto error; |
d2bc095a KG |
228 | } |
229 | ||
230 | do_fixup_by_path_u32(of_flat_tree, "/chosen", | |
231 | "linux,initrd-start", initrd_start, 0); | |
232 | do_fixup_by_path_u32(of_flat_tree, "/chosen", | |
233 | "linux,initrd-end", initrd_end, 0); | |
234 | } | |
235 | #endif | |
5d3cc55e MB |
236 | debug ("## Transferring control to Linux (at address %08lx) ...\n", |
237 | (ulong)kernel); | |
238 | ||
239 | show_boot_progress (15); | |
240 | ||
241 | #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500) | |
242 | unlock_ram_in_cache(); | |
243 | #endif | |
75fa002c KG |
244 | if (!images->autostart) |
245 | return ; | |
5d3cc55e | 246 | |
4a2ad5ff | 247 | #if defined(CONFIG_OF_LIBFDT) |
5d3cc55e MB |
248 | if (of_flat_tree) { /* device tree; boot new style */ |
249 | /* | |
250 | * Linux Kernel Parameters (passing device tree): | |
251 | * r3: pointer to the fdt, followed by the board info data | |
252 | * r4: physical pointer to the kernel itself | |
253 | * r5: NULL | |
254 | * r6: NULL | |
255 | * r7: NULL | |
256 | */ | |
257 | (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0); | |
258 | /* does not return */ | |
259 | } | |
260 | #endif | |
261 | /* | |
262 | * Linux Kernel Parameters (passing board info data): | |
263 | * r3: ptr to board info data | |
264 | * r4: initrd_start or 0 if no initrd | |
265 | * r5: initrd_end - unused if r4 is 0 | |
266 | * r6: Start of command line string | |
267 | * r7: End of command line string | |
268 | */ | |
269 | (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); | |
270 | /* does not return */ | |
274cea2b KG |
271 | return ; |
272 | ||
273 | error: | |
75fa002c KG |
274 | if (images->autostart) |
275 | do_reset (cmdtp, flag, argc, argv); | |
274cea2b | 276 | return ; |
5d3cc55e | 277 | } |
d3c5eb6d | 278 | |
ceaed2b1 MB |
279 | static ulong get_sp (void) |
280 | { | |
281 | ulong sp; | |
282 | ||
283 | asm( "mr %0,1": "=r"(sp) : ); | |
284 | return sp; | |
285 | } | |
286 | ||
b6b0fe64 MB |
287 | static void set_clocks_in_mhz (bd_t *kbd) |
288 | { | |
289 | char *s; | |
290 | ||
291 | if ((s = getenv ("clocks_in_mhz")) != NULL) { | |
292 | /* convert all clock information to MHz */ | |
293 | kbd->bi_intfreq /= 1000000L; | |
294 | kbd->bi_busfreq /= 1000000L; | |
295 | #if defined(CONFIG_MPC8220) | |
296 | kbd->bi_inpfreq /= 1000000L; | |
297 | kbd->bi_pcifreq /= 1000000L; | |
298 | kbd->bi_pevfreq /= 1000000L; | |
299 | kbd->bi_flbfreq /= 1000000L; | |
300 | kbd->bi_vcofreq /= 1000000L; | |
301 | #endif | |
302 | #if defined(CONFIG_CPM2) | |
303 | kbd->bi_cpmfreq /= 1000000L; | |
304 | kbd->bi_brgfreq /= 1000000L; | |
305 | kbd->bi_sccfreq /= 1000000L; | |
306 | kbd->bi_vco /= 1000000L; | |
307 | #endif | |
308 | #if defined(CONFIG_MPC5xxx) | |
309 | kbd->bi_ipbfreq /= 1000000L; | |
310 | kbd->bi_pcifreq /= 1000000L; | |
311 | #endif /* CONFIG_MPC5xxx */ | |
312 | } | |
313 | } | |
314 | ||
d3c5eb6d MB |
315 | #if defined(CONFIG_OF_LIBFDT) |
316 | static void fdt_error (const char *msg) | |
317 | { | |
318 | puts ("ERROR: "); | |
319 | puts (msg); | |
320 | puts (" - must RESET the board to recover.\n"); | |
321 | } | |
7b325454 | 322 | |
ff0734cf MB |
323 | static image_header_t *image_get_fdt (ulong fdt_addr) |
324 | { | |
325 | image_header_t *fdt_hdr = (image_header_t *)fdt_addr; | |
326 | ||
327 | image_print_contents (fdt_hdr); | |
328 | ||
329 | puts (" Verifying Checksum ... "); | |
330 | if (!image_check_hcrc (fdt_hdr)) { | |
331 | fdt_error ("fdt header checksum invalid"); | |
332 | return NULL; | |
333 | } | |
334 | ||
335 | if (!image_check_dcrc (fdt_hdr)) { | |
336 | fdt_error ("fdt checksum invalid"); | |
337 | return NULL; | |
338 | } | |
339 | puts ("OK\n"); | |
340 | ||
341 | if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) { | |
342 | fdt_error ("uImage is not a fdt"); | |
343 | return NULL; | |
344 | } | |
345 | if (image_get_comp (fdt_hdr) != IH_COMP_NONE) { | |
346 | fdt_error ("uImage is compressed"); | |
347 | return NULL; | |
348 | } | |
349 | if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) { | |
350 | fdt_error ("uImage data is not a fdt"); | |
351 | return NULL; | |
352 | } | |
353 | return fdt_hdr; | |
354 | } | |
355 | ||
9a4daad0 | 356 | static int boot_get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
d2ced9eb | 357 | bootm_headers_t *images, char **of_flat_tree, ulong *of_size) |
7b325454 | 358 | { |
d5934ad7 | 359 | ulong fdt_addr; |
7b325454 | 360 | image_header_t *fdt_hdr; |
d5934ad7 | 361 | char *fdt_blob = NULL; |
d5934ad7 MB |
362 | ulong image_start, image_end; |
363 | ulong load_start, load_end; | |
364 | #if defined(CONFIG_FIT) | |
365 | void *fit_hdr; | |
366 | const char *fit_uname_config = NULL; | |
367 | const char *fit_uname_fdt = NULL; | |
368 | ulong default_addr; | |
369 | #endif | |
7b325454 | 370 | |
d5934ad7 MB |
371 | if (argc > 3) { |
372 | #if defined(CONFIG_FIT) | |
373 | /* | |
374 | * If the FDT blob comes from the FIT image and the FIT image | |
375 | * address is omitted in the command line argument, try to use | |
376 | * ramdisk or os FIT image address or default load address. | |
377 | */ | |
378 | if (images->fit_uname_rd) | |
379 | default_addr = (ulong)images->fit_hdr_rd; | |
380 | else if (images->fit_uname_os) | |
381 | default_addr = (ulong)images->fit_hdr_os; | |
382 | else | |
383 | default_addr = load_addr; | |
384 | ||
385 | if (fit_parse_conf (argv[3], default_addr, | |
386 | &fdt_addr, &fit_uname_config)) { | |
387 | debug ("* fdt: config '%s' from image at 0x%08lx\n", | |
388 | fit_uname_config, fdt_addr); | |
389 | } else if (fit_parse_subimage (argv[3], default_addr, | |
390 | &fdt_addr, &fit_uname_fdt)) { | |
391 | debug ("* fdt: subimage '%s' from image at 0x%08lx\n", | |
392 | fit_uname_fdt, fdt_addr); | |
393 | } else | |
394 | #endif | |
395 | { | |
396 | fdt_addr = simple_strtoul(argv[3], NULL, 16); | |
397 | debug ("* fdt: cmdline image address = 0x%08lx\n", | |
398 | fdt_addr); | |
399 | } | |
fff888a1 | 400 | |
d5934ad7 MB |
401 | debug ("## Checking for 'FDT'/'FDT image' at %08lx\n", |
402 | fdt_addr); | |
fff888a1 MB |
403 | |
404 | /* copy from dataflash if needed */ | |
9a4daad0 | 405 | fdt_addr = genimg_get_image (fdt_addr); |
7b325454 | 406 | |
d5934ad7 MB |
407 | /* |
408 | * Check if there is an FDT image at the | |
409 | * address provided in the second bootm argument | |
410 | * check image type, for FIT images get a FIT node. | |
411 | */ | |
9a4daad0 | 412 | switch (genimg_get_format ((void *)fdt_addr)) { |
d5934ad7 MB |
413 | case IMAGE_FORMAT_LEGACY: |
414 | debug ("* fdt: legacy format image\n"); | |
7b325454 | 415 | |
ff0734cf | 416 | /* verify fdt_addr points to a valid image header */ |
d5934ad7 | 417 | printf ("## Flattened Device Tree Legacy Image at %08lx\n", |
ff0734cf MB |
418 | fdt_addr); |
419 | fdt_hdr = image_get_fdt (fdt_addr); | |
420 | if (!fdt_hdr) | |
274cea2b | 421 | goto error; |
7b325454 | 422 | |
ff0734cf MB |
423 | /* |
424 | * move image data to the load address, | |
425 | * make sure we don't overwrite initial image | |
426 | */ | |
7b325454 MB |
427 | image_start = (ulong)fdt_hdr; |
428 | image_end = image_get_image_end (fdt_hdr); | |
429 | ||
430 | load_start = image_get_load (fdt_hdr); | |
431 | load_end = load_start + image_get_data_size (fdt_hdr); | |
432 | ||
433 | if ((load_start < image_end) && (load_end > image_start)) { | |
434 | fdt_error ("fdt overwritten"); | |
274cea2b | 435 | goto error; |
7b325454 | 436 | } |
7b325454 | 437 | memmove ((void *)image_get_load (fdt_hdr), |
ff0734cf MB |
438 | (void *)image_get_data (fdt_hdr), |
439 | image_get_data_size (fdt_hdr)); | |
7b325454 | 440 | |
d5934ad7 MB |
441 | fdt_blob = (char *)image_get_load (fdt_hdr); |
442 | break; | |
d5934ad7 | 443 | case IMAGE_FORMAT_FIT: |
4efbe9db MB |
444 | /* |
445 | * This case will catch both: new uImage format | |
446 | * (libfdt based) and raw FDT blob (also libfdt | |
447 | * based). | |
448 | */ | |
449 | #if defined(CONFIG_FIT) | |
450 | /* check FDT blob vs FIT blob */ | |
451 | if (0) { /* FIXME: call FIT format verification */ | |
d5934ad7 MB |
452 | /* |
453 | * FIT image | |
454 | */ | |
455 | fit_hdr = (void *)fdt_addr; | |
456 | debug ("* fdt: FIT format image\n"); | |
457 | fit_unsupported_reset ("PPC fdt"); | |
274cea2b | 458 | goto error; |
4efbe9db MB |
459 | } else |
460 | #endif | |
461 | { | |
d5934ad7 MB |
462 | /* |
463 | * FDT blob | |
464 | */ | |
4efbe9db | 465 | debug ("* fdt: raw FDT blob\n"); |
d5934ad7 MB |
466 | printf ("## Flattened Device Tree blob at %08lx\n", fdt_blob); |
467 | fdt_blob = (char *)fdt_addr; | |
468 | } | |
469 | break; | |
d5934ad7 MB |
470 | default: |
471 | fdt_error ("Did not find a cmdline Flattened Device Tree"); | |
274cea2b | 472 | goto error; |
7b325454 | 473 | } |
d5934ad7 MB |
474 | |
475 | printf (" Booting using the fdt blob at 0x%x\n", fdt_blob); | |
476 | ||
477 | } else if (images->legacy_hdr_valid && | |
478 | image_check_type (images->legacy_hdr_os, IH_TYPE_MULTI)) { | |
479 | ||
7b325454 MB |
480 | ulong fdt_data, fdt_len; |
481 | ||
d5934ad7 MB |
482 | /* |
483 | * Now check if we have a legacy multi-component image, | |
484 | * get second entry data start address and len. | |
485 | */ | |
7b325454 | 486 | printf ("## Flattened Device Tree from multi " |
d5934ad7 MB |
487 | "component Image at %08lX\n", |
488 | (ulong)images->legacy_hdr_os); | |
7b325454 | 489 | |
d5934ad7 | 490 | image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len); |
7b325454 MB |
491 | if (fdt_len) { |
492 | ||
d5934ad7 MB |
493 | fdt_blob = (char *)fdt_data; |
494 | printf (" Booting using the fdt at 0x%x\n", fdt_blob); | |
7b325454 | 495 | |
d5934ad7 | 496 | if (fdt_check_header (fdt_blob) != 0) { |
7b325454 | 497 | fdt_error ("image is not a fdt"); |
274cea2b | 498 | goto error; |
7b325454 MB |
499 | } |
500 | ||
d5934ad7 | 501 | if (be32_to_cpu (fdt_totalsize (fdt_blob)) != fdt_len) { |
7b325454 | 502 | fdt_error ("fdt size != image size"); |
274cea2b | 503 | goto error; |
7b325454 MB |
504 | } |
505 | } else { | |
d5934ad7 MB |
506 | fdt_error ("Did not find a Flattened Device Tree " |
507 | "in a legacy multi-component image"); | |
274cea2b | 508 | goto error; |
7b325454 | 509 | } |
d5934ad7 MB |
510 | } else { |
511 | debug ("## No Flattened Device Tree\n"); | |
512 | *of_flat_tree = NULL; | |
d2ced9eb | 513 | *of_size = 0; |
274cea2b | 514 | return 0; |
d2ced9eb MB |
515 | } |
516 | ||
517 | *of_flat_tree = fdt_blob; | |
518 | *of_size = be32_to_cpu (fdt_totalsize (fdt_blob)); | |
519 | debug (" of_flat_tree at 0x%08lx size 0x%08lx\n", | |
520 | *of_flat_tree, *of_size); | |
274cea2b KG |
521 | |
522 | return 0; | |
523 | ||
524 | error: | |
525 | do_reset (cmdtp, flag, argc, argv); | |
526 | return 1; | |
d2ced9eb MB |
527 | } |
528 | ||
9a4daad0 | 529 | static int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base, |
d2ced9eb MB |
530 | cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
531 | char **of_flat_tree, ulong *of_size) | |
532 | { | |
533 | char *fdt_blob = *of_flat_tree; | |
534 | ulong relocate = 0; | |
e822d7fc | 535 | ulong of_len = 0; |
d2ced9eb MB |
536 | |
537 | /* nothing to do */ | |
538 | if (*of_size == 0) | |
e822d7fc | 539 | return 0; |
d2ced9eb MB |
540 | |
541 | if (fdt_check_header (fdt_blob) != 0) { | |
542 | fdt_error ("image is not a fdt"); | |
274cea2b | 543 | goto error; |
7b325454 MB |
544 | } |
545 | ||
d5934ad7 | 546 | #ifndef CFG_NO_FLASH |
d2ced9eb | 547 | /* move the blob if it is in flash (set relocate) */ |
d5934ad7 | 548 | if (addr2info ((ulong)fdt_blob) != NULL) |
d2ced9eb | 549 | relocate = 1; |
d5934ad7 MB |
550 | #endif |
551 | ||
7b325454 MB |
552 | /* |
553 | * The blob must be within CFG_BOOTMAPSZ, | |
554 | * so we flag it to be copied if it is not. | |
555 | */ | |
d5934ad7 | 556 | if (fdt_blob >= (char *)CFG_BOOTMAPSZ) |
d2ced9eb | 557 | relocate = 1; |
e822d7fc | 558 | |
05e07b1e | 559 | of_len = be32_to_cpu (fdt_totalsize (fdt_blob)); |
7b325454 MB |
560 | |
561 | /* move flattend device tree if needed */ | |
d2ced9eb | 562 | if (relocate) { |
7b325454 | 563 | int err; |
e822d7fc | 564 | ulong of_start; |
7b325454 MB |
565 | |
566 | /* position on a 4K boundary before the alloc_current */ | |
e822d7fc KG |
567 | of_start = lmb_alloc_base(lmb, of_len, 0x1000, |
568 | (CFG_BOOTMAPSZ + bootmap_base)); | |
569 | ||
570 | if (of_start == 0) { | |
571 | puts("device tree - allocation error\n"); | |
572 | goto error; | |
573 | } | |
7b325454 MB |
574 | |
575 | debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", | |
d5934ad7 | 576 | (ulong)fdt_blob, (ulong)fdt_blob + of_len - 1, |
7b325454 MB |
577 | of_len, of_len); |
578 | ||
579 | printf (" Loading Device Tree to %08lx, end %08lx ... ", | |
580 | of_start, of_start + of_len - 1); | |
581 | ||
d5934ad7 | 582 | err = fdt_open_into (fdt_blob, (void *)of_start, of_len); |
7b325454 MB |
583 | if (err != 0) { |
584 | fdt_error ("fdt move failed"); | |
274cea2b | 585 | goto error; |
7b325454 MB |
586 | } |
587 | puts ("OK\n"); | |
588 | ||
589 | *of_flat_tree = (char *)of_start; | |
7b325454 | 590 | } else { |
d5934ad7 | 591 | *of_flat_tree = fdt_blob; |
e822d7fc | 592 | lmb_reserve(lmb, (ulong)fdt, of_len); |
7b325454 MB |
593 | } |
594 | ||
e822d7fc | 595 | return 0; |
274cea2b KG |
596 | |
597 | error: | |
274cea2b | 598 | return 1; |
7b325454 | 599 | } |
d3c5eb6d | 600 | #endif |