44import json
55from 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
2626def 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
3138def 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