Last active
September 28, 2023 07:26
-
-
Save orangecms/2d014eb3a21123b4da89d13f974f7c6b to your computer and use it in GitHub Desktop.
Preprocess DTS includes and flatten the tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# https://stackoverflow.com/a/50658776 | |
_INC="-I include -I arch/riscv/include" | |
_TMP=/tmp/resolved.dts | |
_OUT=/tmp/recompiled.dts | |
cpp -nostdinc $_INC -undef -x assembler-with-cpp "$1" $_TMP | |
# sed -i '/^#.*/d' $_TMP | |
echo Preprocessed / resolved DTS: $_TMP | |
dtc -O dts -o $_OUT $_TMP | |
echo Recompiled / flattened DTS: $_OUT | |
echo "To compile a dtb, run:\n dtc -o out.dtb $_TMP" |
A handy little dts2svd
wrapper around the generator (adjust as needed):
#!/bin/sh
export PYTHONPATH="$HOME/firmware/dts-svd-etc/pydevicetree"
~/firmware/dts-svd-etc/cmsis-svd-generator/generate_svd.py $@
Passing the DTS from U-Boot as is fails resolving the includes:
dts2svd -d arch/riscv/dts/jh7100-visionfive.dts -o test.svd
Traceback (most recent call last):
File "/home/dama/firmware/dts-svd-etc/cmsis-svd-generator/generate_svd.py", line 139, in <module>
main(sys.argv[1:])
File "/home/dama/firmware/dts-svd-etc/cmsis-svd-generator/generate_svd.py", line 132, in main
dts = pydevicetree.Devicetree.parseFile(parsed_args.dts, followIncludes=True)
File "/home/dama/firmware/dts-svd-etc/pydevicetree/pydevicetree/ast/node.py", line 468, in parseFile
return parseTree(contents, dirname, followIncludes)
File "/home/dama/firmware/dts-svd-etc/pydevicetree/pydevicetree/source/parser.py", line 185, in parseTree
return Devicetree(parseElements(dts, pwd, followIncludes))
File "/home/dama/firmware/dts-svd-etc/pydevicetree/pydevicetree/source/parser.py", line 177, in parseElements
elements = grammar.devicetree.parseString(dts, parseAll=True)
File "/usr/lib/python3/dist-packages/pyparsing.py", line 1955, in parseString
raise exc
File "/usr/lib/python3/dist-packages/pyparsing.py", line 3814, in parseImpl
raise ParseException(instring, loc, self.errmsg, self)
pyparsing.ParseException: Expected end of text, found '#' (at char 130), (line:5, col:1)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Preprocess / resolve includes and precompile / flatten, example with a DTS in U-Boot:
To generate an SVD:
git clone https://github.com/sifive/pydevicetree git clone https://github.com/sifive/cmsis-svd-generator cd cmsis-svd-generator
Try parsing the resolved file:
PYTHONPATH="$(pwd)/../pydevicetree" ./generate_svd.py -d /tmp/resolved.dts -o jh7100-visionfive.svd
This runs into parsing errors at the moment:
Try parsing the recompiled / flattened DTS:
PYTHONPATH="$(pwd)/../pydevicetree" ./generate_svd.py -d /tmp/recompiled.dts -o jh7100-visionfive.svd
This yields errors as well: