Skip to content

Instantly share code, notes, and snippets.

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

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 = []
opts, args = getopt.getopt(argv,"hi:o:",["input-dir=","output-dir="])
except getopt.GetoptError:
print(' -i <inputdir> -o <outputdir>')
for opt, arg in opts:
if opt == '-h':
print(' -i <inputdir> -o <outputdir>')
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') ):
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 =
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__":
name = "pypi"
url = ""
verify_ssl = true
fdt = "*"
pyyaml = "*"
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.