Skip to contentSkip to conversation

devicetree.bbclass: Allow selection of dts files to build

PATCH Superseded Petr Kubizňák 2 participants 2 messages Apr 20, 2023 – Apr 21, 2023

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devicetree.bbclass: Allow selection of dts files to build

Add DT_FILES variable to allow the user of the class to select specific dts files to build. This is useful for packages featuring dts files for multiple machines.

Since many machine configs contain a list of dtb files (e.g. KERNEL_DEVICETREE), DT_FILES works with both dts and dtb files.

---
 meta/classes-recipe/devicetree.bbclass | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
meta/classes-recipe/devicetree.bbclass +9 -1
index ed2a92e447..fb73c44e22 100644
@@ -53,8 +53,10 @@ KERNEL_INCLUDE ??= " \
 
 DT_INCLUDE[doc] = "Search paths to be made available to both the device tree compiler and preprocessor for inclusion."
 DT_INCLUDE ?= "${DT_FILES_PATH} ${KERNEL_INCLUDE}"
-DT_FILES_PATH[doc] = "Defaults to source directory, can be used to select dts files that are not in source (e.g. generated)."
+DT_FILES_PATH[doc] = "Path to the directory containing dts files to build. Defaults to source directory."
 DT_FILES_PATH ?= "${S}"
+DT_FILES[doc] = "Space-separated list of dts or dtb files to build. If empty, all dts files are built."
+DT_FILES ?= ""
 
 DT_PADDING_SIZE[doc] = "Size of padding on the device tree blob, used as extra space typically for additional properties during boot."
 DT_PADDING_SIZE ??= "0x3000"
@@ -125,7 +127,10 @@ def devicetree_compile(dtspath, includes, d):
     subprocess.run(dtcargs, check = True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
 
 python devicetree_do_compile() {
+    import re
     includes = expand_includes("DT_INCLUDE", d)
+    dtfiles = d.getVar("DT_FILES")
+    filter = [ re.sub('dtb[o]?', 'dts', dtfile) for dtfile in dtfiles.split() ]
     listpath = d.getVar("DT_FILES_PATH")
     for dts in os.listdir(listpath):
         dtspath = os.path.join(listpath, dts)
@@ -134,6 +139,9 @@ python devicetree_do_compile() {
                 continue # skip non-.dts files and non-overlay files
         except:
             continue # skip if can't determine if overlay
+        if filter:
+            if not(dts in filter):
+                continue # skip if dts not in defined filter
         devicetree_compile(dtspath, includes, d)
 }
 
Signature · 1 line
2.30.2
#1 lore raw

Hello Petr,

Quoted 29 lines · On Thu, 20 Apr 2023 13:40:46 +0200 Petr Kubizňák <[email protected]> wrote:

Add DT_FILES variable to allow the user of the class to select specific dts files to build. This is useful for packages featuring dts files for multiple machines.

Since many machine configs contain a list of dtb files (e.g. KERNEL_DEVICETREE), DT_FILES works with both dts and dtb files.

---
 meta/classes-recipe/devicetree.bbclass | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
meta/classes-recipe/devicetree.bbclass +3 -1
index ed2a92e447..fb73c44e22 100644
@@ -53,8 +53,10 @@ KERNEL_INCLUDE ??= " \
 
 DT_INCLUDE[doc] = "Search paths to be made available to both the device tree compiler and preprocessor for inclusion."
 DT_INCLUDE ?= "${DT_FILES_PATH} ${KERNEL_INCLUDE}"
-DT_FILES_PATH[doc] = "Defaults to source directory, can be used to select dts files that are not in source (e.g. generated)."
+DT_FILES_PATH[doc] = "Path to the directory containing dts files to build. Defaults to source directory."
 DT_FILES_PATH ?= "${S}"
+DT_FILES[doc] = "Space-separated list of dts or dtb files to build. If empty, all dts files are built."
+DT_FILES ?= ""
 
 DT_PADDING_SIZE[doc] = "Size of padding on the device tree blob, used as extra space typically for additional properties during boot."
 DT_PADDING_SIZE ??= "0x3000"

meta/classes-recipe/devicetree.bbclass def devicetree_compile(dtspath, includes, d): · line 133

Quoted 7 lines
meta/classes-recipe/devicetree.bbclass +3 -0
@@ -125,7 +127,10 @@ def devicetree_compile(dtspath, includes, d):
     subprocess.run(dtcargs, check = True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
 
 python devicetree_do_compile() {
+    import re
     includes = expand_includes("DT_INCLUDE", d)
+    dtfiles = d.getVar("DT_FILES")
+    filter = [ re.sub('dtb[o]?', 'dts', dtfile) for dtfile in dtfiles.split() ]

I think the regexp be simplified as 'dtbo?', right?

Otherwise looks good.

Signature · 3 lines
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com