dts: make extract script take options
Use argeparse for options and add a fixup option to add on top of generated file. This was previously done in the top Makefile and was generated defines outside of the header main if statement. Jira: ZEP-2147 Change-Id: If65f34a11de27baa770d4ce0ef4fca2abbd30258 Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
294f845d6b
commit
6b081415d3
2 changed files with 44 additions and 17 deletions
13
Makefile
13
Makefile
|
@ -950,12 +950,15 @@ zephyr: $(zephyr-deps) $(KERNEL_BIN_NAME)
|
|||
ifeq ($(CONFIG_HAS_DTS),y)
|
||||
define filechk_generated_dts_board.h
|
||||
(echo "/* WARNING. THIS FILE IS AUTO-GENERATED. DO NOT MODIFY! */"; \
|
||||
$(ZEPHYR_BASE)/scripts/extract_dts_includes.py dts/$(ARCH)/$(BOARD_NAME).dts_compiled $(ZEPHYR_BASE)/dts/$(ARCH)/yaml; \
|
||||
if test -e $(ZEPHYR_BASE)/dts/$(ARCH)/$(BOARD_NAME).fixup; then \
|
||||
echo; echo; \
|
||||
echo "/* Following definitions fixup the generated include */"; \
|
||||
echo; \
|
||||
cat $(ZEPHYR_BASE)/dts/$(ARCH)/$(BOARD_NAME).fixup; \
|
||||
$(ZEPHYR_BASE)/scripts/extract_dts_includes.py \
|
||||
-d dts/$(ARCH)/$(BOARD_NAME).dts_compiled \
|
||||
-y $(ZEPHYR_BASE)/dts/$(ARCH)/yaml \
|
||||
-f $(ZEPHYR_BASE)/dts/$(ARCH)/$(BOARD_NAME).fixup; \
|
||||
else \
|
||||
$(ZEPHYR_BASE)/scripts/extract_dts_includes.py \
|
||||
-d dts/$(ARCH)/$(BOARD_NAME).dts_compiled \
|
||||
-y $(ZEPHYR_BASE)/dts/$(ARCH)/yaml; \
|
||||
fi; \
|
||||
)
|
||||
endef
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# vim: ai:ts=4:sw=4
|
||||
|
||||
import sys
|
||||
from os import walk
|
||||
import os
|
||||
import re
|
||||
import yaml
|
||||
import pprint
|
||||
import argparse
|
||||
|
||||
from devicetree import parse_file
|
||||
|
||||
|
@ -503,7 +507,7 @@ def print_key_value(k, v, tabstop):
|
|||
|
||||
return
|
||||
|
||||
def generate_include_file(defs):
|
||||
def generate_include_file(defs, fixup):
|
||||
compatible = reduced['/']['props']['compatible'][0]
|
||||
|
||||
sys.stdout.write("/**************************************************\n")
|
||||
|
@ -539,18 +543,40 @@ def generate_include_file(defs):
|
|||
print_key_value(prop, defs[node].get(prop), maxtabstop)
|
||||
sys.stdout.write("\n")
|
||||
|
||||
sys.stdout.write("#endif\n");
|
||||
if fixup and os.path.exists(fixup):
|
||||
sys.stdout.write("\n")
|
||||
sys.stdout.write("/* Following definitions fixup the generated include */\n")
|
||||
try:
|
||||
with open(fixup, "r") as fd:
|
||||
for line in fd.readlines():
|
||||
sys.stdout.write(line)
|
||||
sys.stdout.write("\n")
|
||||
except:
|
||||
raise Exception("Input file " + os.path.abspath(fixup) + " does not exist.")
|
||||
|
||||
def main(args):
|
||||
if len(args) < 2:
|
||||
print('Usage: %s filename.dts path_to_yaml' % args[0])
|
||||
sys.stdout.write("#endif\n")
|
||||
|
||||
def parse_arguments():
|
||||
|
||||
parser = argparse.ArgumentParser(description = __doc__,
|
||||
formatter_class = argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument("-d", "--dts", help="DTS file")
|
||||
parser.add_argument("-y", "--yaml", help="YAML file")
|
||||
parser.add_argument("-f", "--fixup", help="Fixup file")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
args = parse_arguments()
|
||||
if not args.dts or not args.yaml:
|
||||
print('Usage: %s -d filename.dts -y path_to_yaml' % sys.argv[0])
|
||||
return 1
|
||||
|
||||
try:
|
||||
with open(args[1], "r") as fd:
|
||||
with open(args.dts, "r") as fd:
|
||||
d = parse_file(fd)
|
||||
except:
|
||||
raise Exception("Input file " + os.path.abspath(args[1]) + " does not exist.")
|
||||
raise Exception("Input file " + os.path.abspath(args.dts) + " does not exist.")
|
||||
|
||||
# compress list to nodes w/ paths, add interrupt parent
|
||||
compress_nodes(d['/'], '/')
|
||||
|
@ -572,7 +598,7 @@ def main(args):
|
|||
|
||||
# scan YAML files and find the ones we are interested in
|
||||
yaml_files = []
|
||||
for (dirpath, dirnames, filenames) in walk(args[2]):
|
||||
for (dirpath, dirnames, filenames) in walk(args.yaml):
|
||||
yaml_files.extend([f for f in filenames if re.match('.*\.yaml\Z', f)])
|
||||
yaml_files = [dirpath + '/' + t for t in yaml_files]
|
||||
break
|
||||
|
@ -628,9 +654,7 @@ def main(args):
|
|||
extract_reg_prop(chosen['zephyr,sram'], None, defs, "CONFIG_SRAM", 1024)
|
||||
|
||||
# generate include file
|
||||
generate_include_file(defs)
|
||||
generate_include_file(defs, args.fixup)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# test1.py executed as script
|
||||
# do something
|
||||
sys.exit(main(sys.argv))
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue