Skip to content
Permalink
Browse files

scripts: dts: support multiple binding dirs in new scripts

gen_defines.py and edtlib.py were recently added in
commit 62d5741 ("dts: Add new DTS/binding parser").

The old extract_dts_includes.py script allowed for multiple
dts bindings dirs.  Let's add that functionality to the new
scripts as well.

Signed-off-by: Michael Scott <mike@foundries.io>
  • Loading branch information...
mike-scott authored and galak committed Aug 2, 2019
1 parent 0440a81 commit b8909439bf6e11a7bebf779d046c5158b9c5040a
Showing with 28 additions and 22 deletions.
  1. +23 −18 scripts/dts/edtlib.py
  2. +5 −4 scripts/dts/gen_defines.py
@@ -90,26 +90,26 @@ class EDT:
dts_path:
The .dts path passed to __init__()
bindings_dir:
The bindings directory path passed to __init__()
bindings_dirs:
The bindings directory paths passed to __init__()
"""
def __init__(self, dts, bindings_dir):
def __init__(self, dts, bindings_dirs):
"""
EDT constructor. This is the top-level entry point to the library.
dts:
Path to device tree .dts file
bindings_dir:
Path to directory containing bindings, in YAML format. This directory
is recursively searched for .yaml files.
bindings_dirs:
List of paths to directories containing bindings, in YAML format.
These directories are recursively searched for .yaml files.
"""
self.dts_path = dts
self.bindings_dir = bindings_dir
self.bindings_dirs = bindings_dirs

self._dt = DT(dts)

self._init_compat2binding(bindings_dir)
self._init_compat2binding(bindings_dirs)
self._init_devices()

def get_dev(self, path):
@@ -143,7 +143,7 @@ def chosen_dev(self, name):
_err("{} in /chosen points to {}, which does not exist"
.format(name, path))

def _init_compat2binding(self, bindings_dir):
def _init_compat2binding(self, bindings_dirs):
# Creates self._compat2binding. This is a dictionary that maps
# (<compatible>, <bus>) tuples (both strings) to (<binding>, <path>)
# tuples. <binding> is the binding in parsed PyYAML format, and <path>
@@ -160,7 +160,7 @@ def _init_compat2binding(self, bindings_dir):
# are loaded.

dt_compats = _dt_compats(self._dt)
self._binding_paths = _binding_paths(bindings_dir)
self._binding_paths = _binding_paths(bindings_dirs)

# Add '!include foo.yaml' handling.
#
@@ -238,8 +238,8 @@ def _init_devices(self):
dev._init_clocks()

def __repr__(self):
return "<EDT for '{}', binding directory '{}'>".format(
self.dts_path, self.bindings_dir)
return "<EDT for '{}', binding directories '{}'>".format(
self.dts_path, self.bindings_dirs)


class Device:
@@ -1009,14 +1009,19 @@ def _dt_compats(dt):
for compat in node.props["compatible"].to_strings()}


def _binding_paths(bindings_dir):
def _binding_paths(bindings_dirs):
# Returns a list with the paths to all bindings (.yaml files) in
# 'bindings_dir'
# 'bindings_dirs'

return [os.path.join(root, filename)
for root, _, filenames in os.walk(bindings_dir)
for filename in filenames
if filename.endswith(".yaml")]
binding_paths = []

for bindings_dir in bindings_dirs:
for root, _, filenames in os.walk(bindings_dir):
for filename in filenames:
if filename.endswith(".yaml"):
binding_paths.append(os.path.join(root, filename))

return binding_paths


def _binding_compat(binding_path):
@@ -31,7 +31,7 @@ def main():
args = parse_args()

try:
edt = edtlib.EDT(args.dts, args.bindings_dir)
edt = edtlib.EDT(args.dts, args.bindings_dirs)
except edtlib.EDTError as e:
sys.exit("device tree error: " + str(e))

@@ -40,7 +40,7 @@ def main():

out_comment("Generated by gen_defines.py", blank_before=False)
out_comment("DTS input file: " + args.dts, blank_before=False)
out_comment("Directory with bindings: " + args.bindings_dir,
out_comment("Directories with bindings: " + ", ".join(args.bindings_dirs),
blank_before=False)

active_compats = set()
@@ -114,8 +114,9 @@ def parse_args():

parser = argparse.ArgumentParser()
parser.add_argument("--dts", required=True, help="DTS file")
parser.add_argument("--bindings-dir", required=True,
help="directory with bindings in YAML format")
parser.add_argument("--bindings-dirs", nargs='+', required=True,
help="directory with bindings in YAML format, "
"we allow multiple")
parser.add_argument("--header-out", required=True,
help="path to write header to")
parser.add_argument("--conf-out", required=True,

0 comments on commit b890943

Please sign in to comment.
You can’t perform that action at this time.