Skip to content

Commit 6bc2048

Browse files
committed
deviceTree: Allow applying dtoverlays for DT with no compatible string
In some cases vendor provided .dts's do not have a `compatible` string set [example](https://github.com/raspberrypi/linux/blob/rpi-6.1.y/arch/arm/boot/dts/overlays/hat_map.dts). Trying to patch them with `apply_overlays.py` results in an exception (and therefore build error) even when the filter didn't match this .dtb. These changes allow patching .dtbs with no `compatible` set, assuming they are compatible with the overlay.
1 parent 973b380 commit 6bc2048

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

pkgs/os-specific/linux/device-tree/apply_overlays.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
from pathlib import Path
66

7-
from libfdt import Fdt, FdtException, FDT_ERR_NOSPACE, fdt_overlay_apply
7+
from libfdt import Fdt, FdtException, FDT_ERR_NOSPACE, FDT_ERR_NOTFOUND, fdt_overlay_apply
88

99

1010
@dataclass
@@ -25,7 +25,14 @@ def compatible(self):
2525

2626
def get_compatible(fdt):
2727
root_offset = fdt.path_offset("/")
28-
return set(fdt.getprop(root_offset, "compatible").as_stringlist())
28+
29+
try:
30+
return set(fdt.getprop(root_offset, "compatible").as_stringlist())
31+
except FdtException as e:
32+
if e.err == -FDT_ERR_NOTFOUND:
33+
return set()
34+
else:
35+
raise e
2936

3037

3138
def apply_overlay(dt: Fdt, dto: Fdt) -> Fdt:
@@ -77,14 +84,15 @@ def main():
7784
with source_dt.open("rb") as fd:
7885
dt = Fdt(fd.read())
7986

80-
dt_compatible = get_compatible(dt)
81-
8287
for overlay in overlays_data:
8388
if overlay.filter and overlay.filter not in str(rel_path):
8489
print(f" Skipping overlay {overlay.name}: filter does not match")
8590
continue
8691

87-
if not overlay.compatible.intersection(dt_compatible):
92+
dt_compatible = get_compatible(dt)
93+
if len(dt_compatible) == 0:
94+
print(f" Device tree {rel_path} has no compatible string set. Assuming it's compatible with overlay")
95+
elif not overlay.compatible.intersection(dt_compatible):
8896
print(f" Skipping overlay {overlay.name}: {overlay.compatible} is incompatible with {dt_compatible}")
8997
continue
9098

0 commit comments

Comments
 (0)