summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Mangeac <Adrian.Mangeac@enea.com>2019-06-18 12:16:25 +0200
committerAdrian Dudau <Adrian.Dudau@enea.com>2019-06-20 19:00:33 +0200
commitd8258934dd81860e2707a4521e1bd4d166757449 (patch)
tree328b73d5c327656689c8b30b8f0e27ccaaa6cc7f
parent478b97a57b47a22624bff8e86e66a83d059c766f (diff)
downloadmeta-enea-bsp-arm-d8258934dd81860e2707a4521e1bd4d166757449.tar.gz
Import class from OE/thud
This is required by the xlilinx recipes to build the u-boot. Change-Id: I483eb23e8592a79989b82b7e1f511a03b50e168d Signed-off-by: Adrian Mangeac <Adrian.Mangeac@enea.com>
-rw-r--r--classes/devicetree.bbclass143
1 files changed, 143 insertions, 0 deletions
diff --git a/classes/devicetree.bbclass b/classes/devicetree.bbclass
new file mode 100644
index 0000000..8fe5a5e
--- /dev/null
+++ b/classes/devicetree.bbclass
@@ -0,0 +1,143 @@
1# This bbclass implements device tree compliation for user provided device tree
2# sources. The compilation of the device tree sources is the same as the kernel
3# device tree compilation process, this includes being able to include sources
4# from the kernel such as soc dtsi files or header files such as gpio.h. In
5# addition to device trees this bbclass also handles compilation of device tree
6# overlays.
7#
8# The output of this class behaves similar to how kernel-devicetree.bbclass
9# operates in that the output files are installed into /boot/devicetree.
10# However this class on purpose separates the deployed device trees into the
11# 'devicetree' subdirectory. This prevents clashes with the kernel-devicetree
12# output. Additionally the device trees are populated into the sysroot for
13# access via the sysroot from within other recipes.
14
15SECTION ?= "bsp"
16
17# The default inclusion of kernel device tree includes and headers means that
18# device trees built with them are at least GPLv2 (and in some cases dual
19# licensed). Default to GPLv2 if the recipe does not specify a license.
20LICENSE ?= "GPLv2"
21LIC_FILES_CHKSUM ?= "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6"
22
23INHIBIT_DEFAULT_DEPS = "1"
24DEPENDS += "dtc-native"
25
26inherit deploy kernel-arch
27
28COMPATIBLE_MACHINE ?= "^$"
29
30PACKAGE_ARCH = "${MACHINE_ARCH}"
31
32SYSROOT_DIRS += "/boot/devicetree"
33FILES_${PN} = "/boot/devicetree/*.dtb /boot/devicetree/*.dtbo"
34
35S = "${WORKDIR}"
36B = "${WORKDIR}/build"
37
38# Default kernel includes, these represent what are normally used for in-kernel
39# sources.
40KERNEL_INCLUDE ??= " \
41 ${STAGING_KERNEL_DIR}/arch/${ARCH}/boot/dts \
42 ${STAGING_KERNEL_DIR}/arch/${ARCH}/boot/dts/* \
43 ${STAGING_KERNEL_DIR}/scripts/dtc/include-prefixes \
44 "
45
46DT_INCLUDE[doc] = "Search paths to be made available to both the device tree compiler and preprocessor for inclusion."
47DT_INCLUDE ?= "${DT_FILES_PATH} ${KERNEL_INCLUDE}"
48DT_FILES_PATH[doc] = "Defaults to source directory, can be used to select dts files that are not in source (e.g. generated)."
49DT_FILES_PATH ?= "${S}"
50
51DT_PADDING_SIZE[doc] = "Size of padding on the device tree blob, used as extra space typically for additional properties during boot."
52DT_PADDING_SIZE ??= "0x3000"
53DT_RESERVED_MAP[doc] = "Number of reserved map entires."
54DT_RESERVED_MAP ??= "8"
55DT_BOOT_CPU[doc] = "The boot cpu, defaults to 0"
56DT_BOOT_CPU ??= "0"
57
58DTC_FLAGS ?= "-R ${DT_RESERVED_MAP} -b ${DT_BOOT_CPU}"
59DTC_PPFLAGS ?= "-nostdinc -undef -D__DTS__ -x assembler-with-cpp"
60DTC_BFLAGS ?= "-p ${DT_PADDING_SIZE}"
61DTC_OFLAGS ?= "-p 0 -@ -H epapr"
62
63python () {
64 if d.getVar("KERNEL_INCLUDE"):
65 # auto add dependency on kernel tree, but only if kernel include paths
66 # are specified.
67 d.appendVarFlag("do_compile", "depends", " virtual/kernel:do_configure")
68}
69
70def expand_includes(varname, d):
71 import glob
72 includes = set()
73 # expand all includes with glob
74 for i in (d.getVar(varname) or "").split():
75 for g in glob.glob(i):
76 if os.path.isdir(g): # only add directories to include path
77 includes.add(g)
78 return includes
79
80def devicetree_source_is_overlay(path):
81 # determine if a dts file is an overlay by checking if it uses "/plugin/;"
82 with open(path, "r") as f:
83 for i in f:
84 if i.startswith("/plugin/;"):
85 return True
86 return False
87
88def devicetree_compile(dtspath, includes, d):
89 import subprocess
90 dts = os.path.basename(dtspath)
91 dtname = os.path.splitext(dts)[0]
92 bb.note("Processing {0} [{1}]".format(dtname, dts))
93
94 # preprocess
95 ppargs = d.getVar("BUILD_CPP").split()
96 ppargs += (d.getVar("DTC_PPFLAGS") or "").split()
97 for i in includes:
98 ppargs.append("-I{0}".format(i))
99 ppargs += ["-o", "{0}.pp".format(dts), dtspath]
100 bb.note("Running {0}".format(" ".join(ppargs)))
101 subprocess.run(ppargs, check = True)
102
103 # determine if the file is an overlay or not (using the preprocessed file)
104 isoverlay = devicetree_source_is_overlay("{0}.pp".format(dts))
105
106 # compile
107 dtcargs = ["dtc"] + (d.getVar("DTC_FLAGS") or "").split()
108 if isoverlay:
109 dtcargs += (d.getVar("DTC_OFLAGS") or "").split()
110 else:
111 dtcargs += (d.getVar("DTC_BFLAGS") or "").split()
112 for i in includes:
113 dtcargs += ["-i", i]
114 dtcargs += ["-o", "{0}.{1}".format(dtname, "dtbo" if isoverlay else "dtb")]
115 dtcargs += ["-I", "dts", "-O", "dtb", "{0}.pp".format(dts)]
116 bb.note("Running {0}".format(" ".join(dtcargs)))
117 subprocess.run(dtcargs, check = True)
118
119python devicetree_do_compile() {
120 includes = expand_includes("DT_INCLUDE", d)
121 listpath = d.getVar("DT_FILES_PATH")
122 for dts in os.listdir(listpath):
123 if not dts.endswith(".dts"):
124 continue # skip non-.dts files
125 dtspath = os.path.join(listpath, dts)
126 devicetree_compile(dtspath, includes, d)
127}
128
129devicetree_do_install() {
130 for DTB_FILE in `ls *.dtb *.dtbo`; do
131 install -Dm 0644 ${B}/${DTB_FILE} ${D}/boot/devicetree/${DTB_FILE}
132 done
133}
134
135devicetree_do_deploy() {
136 for DTB_FILE in `ls *.dtb *.dtbo`; do
137 install -Dm 0644 ${B}/${DTB_FILE} ${DEPLOYDIR}/devicetree/${DTB_FILE}
138 done
139}
140addtask deploy before do_build after do_install
141
142EXPORT_FUNCTIONS do_compile do_install do_deploy
143