Commit 13d06981a9829c9edcfd6f9f582d216fbaed95e5
Committed by
Tom Rini
1 parent
44d3a3066b
Exists in
master
and in
53 other branches
image: Add device tree setup to image library
This seems to be a common function for several architectures, so create a common function rather than duplicating the code in each arch. Also make an attempt to avoid introducing #ifdefs in the new code, partly by removing useless #ifdefs around function declarations in the image.h header. Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 6 changed files with 174 additions and 13 deletions Side-by-side Diff
common/image-fdt.c
... | ... | @@ -589,4 +589,66 @@ |
589 | 589 | *of_size = 0; |
590 | 590 | return 1; |
591 | 591 | } |
592 | + | |
593 | +/* | |
594 | + * Verify the device tree. | |
595 | + * | |
596 | + * This function is called after all device tree fix-ups have been enacted, | |
597 | + * so that the final device tree can be verified. The definition of "verified" | |
598 | + * is up to the specific implementation. However, it generally means that the | |
599 | + * addresses of some of the devices in the device tree are compared with the | |
600 | + * actual addresses at which U-Boot has placed them. | |
601 | + * | |
602 | + * Returns 1 on success, 0 on failure. If 0 is returned, U-boot will halt the | |
603 | + * boot process. | |
604 | + */ | |
605 | +__weak int ft_verify_fdt(void *fdt) | |
606 | +{ | |
607 | + return 1; | |
608 | +} | |
609 | + | |
610 | +__weak int arch_fixup_memory_node(void *blob) | |
611 | +{ | |
612 | + return 0; | |
613 | +} | |
614 | + | |
615 | +int image_setup_libfdt(bootm_headers_t *images, void *blob, | |
616 | + int of_size, struct lmb *lmb) | |
617 | +{ | |
618 | + ulong *initrd_start = &images->initrd_start; | |
619 | + ulong *initrd_end = &images->initrd_end; | |
620 | + int ret; | |
621 | + | |
622 | + if (fdt_chosen(blob, 1) < 0) { | |
623 | + puts("ERROR: /chosen node create failed"); | |
624 | + puts(" - must RESET the board to recover.\n"); | |
625 | + return -1; | |
626 | + } | |
627 | + arch_fixup_memory_node(blob); | |
628 | + if (IMAAGE_OF_BOARD_SETUP) | |
629 | + ft_board_setup(blob, gd->bd); | |
630 | + fdt_fixup_ethernet(blob); | |
631 | + | |
632 | + /* Delete the old LMB reservation */ | |
633 | + lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob, | |
634 | + (phys_size_t)fdt_totalsize(blob)); | |
635 | + | |
636 | + ret = fdt_resize(blob); | |
637 | + if (ret < 0) | |
638 | + return ret; | |
639 | + of_size = ret; | |
640 | + | |
641 | + if (*initrd_start && *initrd_end) { | |
642 | + of_size += FDT_RAMDISK_OVERHEAD; | |
643 | + fdt_set_totalsize(blob, of_size); | |
644 | + } | |
645 | + /* Create a new LMB reservation */ | |
646 | + lmb_reserve(lmb, (ulong)blob, of_size); | |
647 | + | |
648 | + fdt_initrd(blob, *initrd_start, *initrd_end, 1); | |
649 | + if (!ft_verify_fdt(blob)) | |
650 | + return -1; | |
651 | + | |
652 | + return 0; | |
653 | +} |
common/image.c
... | ... | @@ -70,6 +70,10 @@ |
70 | 70 | |
71 | 71 | #include <u-boot/crc.h> |
72 | 72 | |
73 | +#ifndef CONFIG_SYS_BARGSIZE | |
74 | +#define CONFIG_SYS_BARGSIZE 512 | |
75 | +#endif | |
76 | + | |
73 | 77 | static const table_entry_t uimage_arch[] = { |
74 | 78 | { IH_ARCH_INVALID, NULL, "Invalid ARCH", }, |
75 | 79 | { IH_ARCH_ALPHA, "alpha", "Alpha", }, |
... | ... | @@ -1223,5 +1227,51 @@ |
1223 | 1227 | return 0; |
1224 | 1228 | } |
1225 | 1229 | #endif /* CONFIG_SYS_BOOT_GET_KBD */ |
1230 | + | |
1231 | +#ifdef CONFIG_LMB | |
1232 | +int image_setup_linux(bootm_headers_t *images) | |
1233 | +{ | |
1234 | + ulong of_size = images->ft_len; | |
1235 | + char **of_flat_tree = &images->ft_addr; | |
1236 | + ulong *initrd_start = &images->initrd_start; | |
1237 | + ulong *initrd_end = &images->initrd_end; | |
1238 | + struct lmb *lmb = &images->lmb; | |
1239 | + ulong rd_len; | |
1240 | + int ret; | |
1241 | + | |
1242 | + if (IMAGE_ENABLE_OF_LIBFDT) | |
1243 | + boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree); | |
1244 | + | |
1245 | + if (IMAGE_BOOT_GET_CMDLINE) { | |
1246 | + ret = boot_get_cmdline(lmb, &images->cmdline_start, | |
1247 | + &images->cmdline_end); | |
1248 | + if (ret) { | |
1249 | + puts("ERROR with allocation of cmdline\n"); | |
1250 | + return ret; | |
1251 | + } | |
1252 | + } | |
1253 | + if (IMAGE_ENABLE_RAMDISK_HIGH) { | |
1254 | + rd_len = images->rd_end - images->rd_start; | |
1255 | + ret = boot_ramdisk_high(lmb, images->rd_start, rd_len, | |
1256 | + initrd_start, initrd_end); | |
1257 | + if (ret) | |
1258 | + return ret; | |
1259 | + } | |
1260 | + | |
1261 | + if (IMAGE_ENABLE_OF_LIBFDT) { | |
1262 | + ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size); | |
1263 | + if (ret) | |
1264 | + return ret; | |
1265 | + } | |
1266 | + | |
1267 | + if (IMAGE_ENABLE_OF_LIBFDT && of_size) { | |
1268 | + ret = image_setup_libfdt(images, *of_flat_tree, of_size, lmb); | |
1269 | + if (ret) | |
1270 | + return ret; | |
1271 | + } | |
1272 | + | |
1273 | + return 0; | |
1274 | +} | |
1275 | +#endif /* CONFIG_LMB */ | |
1226 | 1276 | #endif /* !USE_HOSTCC */ |
include/common.h
... | ... | @@ -340,6 +340,16 @@ |
340 | 340 | */ |
341 | 341 | void board_show_dram(ulong size); |
342 | 342 | |
343 | +/** | |
344 | + * arch_fixup_memory_node() - Write arch-specific memory information to fdt | |
345 | + * | |
346 | + * Defined in arch/$(ARCH)/lib/bootm.c | |
347 | + * | |
348 | + * @blob: FDT blob to write to | |
349 | + * @return 0 if ok, or -ve FDT_ERR_... on failure | |
350 | + */ | |
351 | +int arch_fixup_memory_node(void *blob); | |
352 | + | |
343 | 353 | /* common/flash.c */ |
344 | 354 | void flash_perror (int); |
345 | 355 |
include/fdt_support.h
... | ... | @@ -78,11 +78,9 @@ |
78 | 78 | int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose); |
79 | 79 | #endif |
80 | 80 | |
81 | -#ifdef CONFIG_OF_BOARD_SETUP | |
82 | 81 | void ft_board_setup(void *blob, bd_t *bd); |
83 | 82 | void ft_cpu_setup(void *blob, bd_t *bd); |
84 | 83 | void ft_pci_setup(void *blob, bd_t *bd); |
85 | -#endif | |
86 | 84 | |
87 | 85 | void set_working_fdt_addr(void *addr); |
88 | 86 | int fdt_resize(void *blob); |
include/image.h
... | ... | @@ -36,6 +36,9 @@ |
36 | 36 | #include "compiler.h" |
37 | 37 | #include <asm/byteorder.h> |
38 | 38 | |
39 | +/* Define this to avoid #ifdefs later on */ | |
40 | +struct lmb; | |
41 | + | |
39 | 42 | #ifdef USE_HOSTCC |
40 | 43 | |
41 | 44 | /* new uImage format support enabled on host */ |
42 | 45 | |
... | ... | @@ -92,8 +95,32 @@ |
92 | 95 | #define IMAGE_ENABLE_SHA1 0 |
93 | 96 | #endif |
94 | 97 | |
98 | +#endif /* CONFIG_FIT */ | |
99 | + | |
100 | +#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH | |
101 | +# define IMAGE_ENABLE_RAMDISK_HIGH 1 | |
102 | +#else | |
103 | +# define IMAGE_ENABLE_RAMDISK_HIGH 0 | |
95 | 104 | #endif |
96 | 105 | |
106 | +#ifdef CONFIG_OF_LIBFDT | |
107 | +# define IMAGE_ENABLE_OF_LIBFDT 1 | |
108 | +#else | |
109 | +# define IMAGE_ENABLE_OF_LIBFDT 0 | |
110 | +#endif | |
111 | + | |
112 | +#ifdef CONFIG_SYS_BOOT_GET_CMDLINE | |
113 | +# define IMAGE_BOOT_GET_CMDLINE 1 | |
114 | +#else | |
115 | +# define IMAGE_BOOT_GET_CMDLINE 0 | |
116 | +#endif | |
117 | + | |
118 | +#ifdef CONFIG_OF_BOARD_SETUP | |
119 | +# define IMAAGE_OF_BOARD_SETUP 1 | |
120 | +#else | |
121 | +# define IMAAGE_OF_BOARD_SETUP 0 | |
122 | +#endif | |
123 | + | |
97 | 124 | /* |
98 | 125 | * Operating System Codes |
99 | 126 | */ |
100 | 127 | |
... | ... | @@ -280,9 +307,7 @@ |
280 | 307 | |
281 | 308 | ulong rd_start, rd_end;/* ramdisk start/end */ |
282 | 309 | |
283 | -#ifdef CONFIG_OF_LIBFDT | |
284 | 310 | char *ft_addr; /* flat dev tree address */ |
285 | -#endif | |
286 | 311 | ulong ft_len; /* length of flat device tree */ |
287 | 312 | |
288 | 313 | ulong initrd_start; |
289 | 314 | |
290 | 315 | |
291 | 316 | |
292 | 317 | |
... | ... | @@ -390,21 +415,14 @@ |
390 | 415 | int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images, |
391 | 416 | uint8_t arch, ulong *rd_start, ulong *rd_end); |
392 | 417 | |
393 | - | |
394 | -#ifdef CONFIG_OF_LIBFDT | |
395 | 418 | int boot_get_fdt(int flag, int argc, char * const argv[], |
396 | 419 | bootm_headers_t *images, char **of_flat_tree, ulong *of_size); |
397 | 420 | void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob); |
398 | 421 | int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size); |
399 | -#endif | |
400 | 422 | |
401 | -#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH | |
402 | 423 | int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len, |
403 | 424 | ulong *initrd_start, ulong *initrd_end); |
404 | -#endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */ | |
405 | -#ifdef CONFIG_SYS_BOOT_GET_CMDLINE | |
406 | 425 | int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end); |
407 | -#endif /* CONFIG_SYS_BOOT_GET_CMDLINE */ | |
408 | 426 | #ifdef CONFIG_SYS_BOOT_GET_KBD |
409 | 427 | int boot_get_kbd(struct lmb *lmb, bd_t **kbd); |
410 | 428 | #endif /* CONFIG_SYS_BOOT_GET_KBD */ |
... | ... | @@ -545,6 +563,31 @@ |
545 | 563 | return image_check_arch(hdr, IH_ARCH_DEFAULT); |
546 | 564 | } |
547 | 565 | #endif /* USE_HOSTCC */ |
566 | + | |
567 | +/** | |
568 | + * Set up properties in the FDT | |
569 | + * | |
570 | + * This sets up properties in the FDT that is to be passed to linux. | |
571 | + * | |
572 | + * @images: Images information | |
573 | + * @blob: FDT to update | |
574 | + * @of_size: Size of the FDT | |
575 | + * @lmb: Points to logical memory block structure | |
576 | + * @return 0 if ok, <0 on failure | |
577 | + */ | |
578 | +int image_setup_libfdt(bootm_headers_t *images, void *blob, | |
579 | + int of_size, struct lmb *lmb); | |
580 | + | |
581 | +/** | |
582 | + * Set up the FDT to use for booting a kernel | |
583 | + * | |
584 | + * This performs ramdisk setup, sets up the FDT if required, and adds | |
585 | + * paramters to the FDT if libfdt is available. | |
586 | + * | |
587 | + * @param images Images information | |
588 | + * @return 0 if ok, <0 on failure | |
589 | + */ | |
590 | +int image_setup_linux(bootm_headers_t *images); | |
548 | 591 | |
549 | 592 | /*******************************************************************/ |
550 | 593 | /* New uImage format specific code (prefixed with fit_) */ |
include/lmb.h
1 | 1 | #ifndef _LINUX_LMB_H |
2 | 2 | #define _LINUX_LMB_H |
3 | 3 | #ifdef __KERNEL__ |
4 | -#ifdef CONFIG_LMB | |
5 | 4 | |
6 | 5 | #include <asm/types.h> |
7 | 6 | /* |
... | ... | @@ -57,7 +56,6 @@ |
57 | 56 | void board_lmb_reserve(struct lmb *lmb); |
58 | 57 | void arch_lmb_reserve(struct lmb *lmb); |
59 | 58 | |
60 | -#endif /* CONFIG_LMB */ | |
61 | 59 | #endif /* __KERNEL__ */ |
62 | 60 | |
63 | 61 | #endif /* _LINUX_LMB_H */ |
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614
-
mentioned in commit 3f6614