-
-
Save feckert/0776d7de4ef36404cd25f03816aa7ef2 to your computer and use it in GitHub Desktop.
Convertierung of dtb to yml files
This file contains 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
#!/usr/bin/env python3 | |
import fdt | |
import getopt | |
import os | |
import sys | |
import yaml | |
def main(argv): | |
inputdir = '' | |
outputdir = '' | |
filenames = [] | |
try: | |
opts, args = getopt.getopt(argv,"hi:o:",["input-dir=","output-dir="]) | |
except getopt.GetoptError: | |
print('device-info.py -i <inputdir> -o <outputdir>') | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
print('device-info.py -i <inputdir> -o <outputdir>') | |
sys.exit() | |
elif opt in ("-i", "--input-dir"): | |
inputdir = arg | |
elif opt in ("-o", "--output-dir"): | |
outputdir = arg | |
folder = os.fsencode(inputdir) | |
for file in os.listdir(folder): | |
filename = os.fsdecode(file) | |
if filename.endswith( ('.dtb') ): | |
filenames.append(os.path.splitext(filename)[0]) | |
filenames.sort() | |
for file in filenames: | |
info = {} | |
yml_file = file + ".yml" | |
yml_file = os.path.join(os.path.abspath(outputdir), yml_file) | |
dtb_file = file + ".dtb" | |
dtb_file = os.path.join(os.path.abspath(inputdir), dtb_file) | |
with open(dtb_file, "rb") as f: | |
print("Parse dtb: " + dtb_file) | |
dtb_data = f.read() | |
dtb = fdt.parse_dtb(dtb_data) | |
info['soc'] = dtb.get_property("compatible")[0] | |
info['model'] = dtb.get_property("model")[0] | |
with open(yml_file, 'w') as f: | |
print("Write yml: " + yml_file) | |
yaml.dump(info, f) | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
This file contains 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
[[source]] | |
name = "pypi" | |
url = "https://pypi.org/simple" | |
verify_ssl = true | |
[dev-packages] | |
[packages] | |
fdt = "*" | |
pyyaml = "*" | |
[requires] | |
python_version = "3.7" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment