Skip to content

Instantly share code, notes, and snippets.

@feckert feckert/Convertierungs script Secret
Created Jan 29, 2020

Embed
What would you like to do?
Convertierung of dtb to yml files
#!/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:])
[[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
You can’t perform that action at this time.