scripts: dts: support multiple binding dirs in new scripts
gen_defines.py and edtlib.py were recently added in
commit 62d5741476
("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>
This commit is contained in:
parent
0440a815a9
commit
b8909439bf
2 changed files with 28 additions and 22 deletions
|
@ -90,26 +90,26 @@ class EDT:
|
||||||
dts_path:
|
dts_path:
|
||||||
The .dts path passed to __init__()
|
The .dts path passed to __init__()
|
||||||
|
|
||||||
bindings_dir:
|
bindings_dirs:
|
||||||
The bindings directory path passed to __init__()
|
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.
|
EDT constructor. This is the top-level entry point to the library.
|
||||||
|
|
||||||
dts:
|
dts:
|
||||||
Path to device tree .dts file
|
Path to device tree .dts file
|
||||||
|
|
||||||
bindings_dir:
|
bindings_dirs:
|
||||||
Path to directory containing bindings, in YAML format. This directory
|
List of paths to directories containing bindings, in YAML format.
|
||||||
is recursively searched for .yaml files.
|
These directories are recursively searched for .yaml files.
|
||||||
"""
|
"""
|
||||||
self.dts_path = dts
|
self.dts_path = dts
|
||||||
self.bindings_dir = bindings_dir
|
self.bindings_dirs = bindings_dirs
|
||||||
|
|
||||||
self._dt = DT(dts)
|
self._dt = DT(dts)
|
||||||
|
|
||||||
self._init_compat2binding(bindings_dir)
|
self._init_compat2binding(bindings_dirs)
|
||||||
self._init_devices()
|
self._init_devices()
|
||||||
|
|
||||||
def get_dev(self, path):
|
def get_dev(self, path):
|
||||||
|
@ -143,7 +143,7 @@ class EDT:
|
||||||
_err("{} in /chosen points to {}, which does not exist"
|
_err("{} in /chosen points to {}, which does not exist"
|
||||||
.format(name, path))
|
.format(name, path))
|
||||||
|
|
||||||
def _init_compat2binding(self, bindings_dir):
|
def _init_compat2binding(self, bindings_dirs):
|
||||||
# Creates self._compat2binding. This is a dictionary that maps
|
# Creates self._compat2binding. This is a dictionary that maps
|
||||||
# (<compatible>, <bus>) tuples (both strings) to (<binding>, <path>)
|
# (<compatible>, <bus>) tuples (both strings) to (<binding>, <path>)
|
||||||
# tuples. <binding> is the binding in parsed PyYAML format, and <path>
|
# tuples. <binding> is the binding in parsed PyYAML format, and <path>
|
||||||
|
@ -160,7 +160,7 @@ class EDT:
|
||||||
# are loaded.
|
# are loaded.
|
||||||
|
|
||||||
dt_compats = _dt_compats(self._dt)
|
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.
|
# Add '!include foo.yaml' handling.
|
||||||
#
|
#
|
||||||
|
@ -238,8 +238,8 @@ class EDT:
|
||||||
dev._init_clocks()
|
dev._init_clocks()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<EDT for '{}', binding directory '{}'>".format(
|
return "<EDT for '{}', binding directories '{}'>".format(
|
||||||
self.dts_path, self.bindings_dir)
|
self.dts_path, self.bindings_dirs)
|
||||||
|
|
||||||
|
|
||||||
class Device:
|
class Device:
|
||||||
|
@ -1009,14 +1009,19 @@ def _dt_compats(dt):
|
||||||
for compat in node.props["compatible"].to_strings()}
|
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
|
# Returns a list with the paths to all bindings (.yaml files) in
|
||||||
# 'bindings_dir'
|
# 'bindings_dirs'
|
||||||
|
|
||||||
return [os.path.join(root, filename)
|
binding_paths = []
|
||||||
for root, _, filenames in os.walk(bindings_dir)
|
|
||||||
for filename in filenames
|
for bindings_dir in bindings_dirs:
|
||||||
if filename.endswith(".yaml")]
|
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):
|
def _binding_compat(binding_path):
|
||||||
|
|
|
@ -31,7 +31,7 @@ def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
edt = edtlib.EDT(args.dts, args.bindings_dir)
|
edt = edtlib.EDT(args.dts, args.bindings_dirs)
|
||||||
except edtlib.EDTError as e:
|
except edtlib.EDTError as e:
|
||||||
sys.exit("device tree error: " + str(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("Generated by gen_defines.py", blank_before=False)
|
||||||
out_comment("DTS input file: " + args.dts, 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)
|
blank_before=False)
|
||||||
|
|
||||||
active_compats = set()
|
active_compats = set()
|
||||||
|
@ -114,8 +114,9 @@ def parse_args():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--dts", required=True, help="DTS file")
|
parser.add_argument("--dts", required=True, help="DTS file")
|
||||||
parser.add_argument("--bindings-dir", required=True,
|
parser.add_argument("--bindings-dirs", nargs='+', required=True,
|
||||||
help="directory with bindings in YAML format")
|
help="directory with bindings in YAML format, "
|
||||||
|
"we allow multiple")
|
||||||
parser.add_argument("--header-out", required=True,
|
parser.add_argument("--header-out", required=True,
|
||||||
help="path to write header to")
|
help="path to write header to")
|
||||||
parser.add_argument("--conf-out", required=True,
|
parser.add_argument("--conf-out", required=True,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue