Skip to content

Commit

Permalink
deviceTree: Allow applying dtoverlays for DT with no compatible string
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dhdhxji committed Oct 26, 2024
1 parent 0b4d07d commit 6305ca1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkgs/os-specific/linux/device-tree/apply_overlays.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
from pathlib import Path

from libfdt import Fdt, FdtException, FDT_ERR_NOSPACE, fdt_overlay_apply
from libfdt import Fdt, FdtException, FDT_ERR_NOSPACE, FDT_ERR_NOTFOUND, fdt_overlay_apply


@dataclass
Expand All @@ -25,7 +25,14 @@ def compatible(self):

def get_compatible(fdt):
root_offset = fdt.path_offset("/")
return set(fdt.getprop(root_offset, "compatible").as_stringlist())

try:
return set(fdt.getprop(root_offset, "compatible").as_stringlist())
except FdtException as e:
if e.err == -FDT_ERR_NOTFOUND:
return set()
else:
raise e


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

dt_compatible = get_compatible(dt)

for overlay in overlays_data:
if overlay.filter and overlay.filter not in str(rel_path):
print(f" Skipping overlay {overlay.name}: filter does not match")
continue

if not overlay.compatible.intersection(dt_compatible):
dt_compatible = get_compatible(dt)
if len(dt_compatible) == 0:
print(f" Device tree {rel_path} has no compatible string set. Assuming it's compatible with overlay")
elif not overlay.compatible.intersection(dt_compatible):
print(f" Skipping overlay {overlay.name}: {overlay.compatible} is incompatible with {dt_compatible}")
continue

Expand Down

0 comments on commit 6305ca1

Please sign in to comment.