Package: fdt
Flattened Device Tree Python ModuleThis python module is usable for manipulation withDevice Tree Dataand primary was
created forimxsb toolSome parts in this module have been inspired from:https://github.com/superna9999/pyfdtproject.InstallationpipinstallfdtTo install the latest version from master branch execute in shell following command:pipinstall-Uhttps://github.com/molejar/pyFDT/archive/master.zipIn case of development, install it from cloned sources:gitclonehttps://github.com/molejar/pyFDT.gitcdpyFDT
pipinstall-U-e.NOTE:You may run into a permissions issues running these commands. Here are a few options how to fix it:Run withsudoto installfdtand dependencies globallySpecify the--useroption to install locally into your home directory (export "~/.local/bin" into PATH variable if haven't).Run the command in avirtualenvlocal to a specific project working set.Usagefdtmodule has intuitive and self describing API, what is presented in following example. Many of general requirements
for manipulation with FDT Nodes, Properties and dts/dtb files are already implemented.importfdt#-----------------------------------------------# convert *.dtb to *.dts# ----------------------------------------------withopen("example.dtb","rb")asf:dtb_data=f.read()dt1=fdt.parse_dtb(dtb_data)withopen("example.dts","w")asf:f.write(dt1.to_dts())#-----------------------------------------------# convert *.dts to *.dtb# ----------------------------------------------withopen("example.dts","r")asf:dts_text=f.read()dt2=fdt.parse_dts(dts_text)withopen("example.dtb","wb")asf:f.write(dt2.to_dtb(version=17))#-----------------------------------------------# add new Node into dt2# ----------------------------------------------# create node instancenode=fdt.Node('test_node1')# add propertiesnode.append(fdt.Property('basic_property'))node.append(fdt.PropStrings('string_property','value1','value2'))node.append(fdt.PropWords('words_property',0x80000000))node.append(fdt.PropBytes('bytes_property',0x00,0x01,0x02))# PropBytes constructor take also complex data object as bytes() or bytearray()node.append(fdt.PropBytes('bytes_property2',data=b"\x00\x01\x02"))# add created node into root path of dt2dt2.add_item(node)# use set_property method to update or create new propertydt2.set_property('words_property',[0,1],path='/test_node1')dt2.set_property('bytes_property',b"\x00\x01",path='/test_node1')dt2.set_property('string_property',['value1','value2','value3'],path='/test_node1')# use search method for find all string properties and then update ititems=dt2.search("",itype=fdt.ItemType.PROP_STRINGS,path="/test_node1")foriteminitems:item.data=['value1','value2']#-----------------------------------------------# merge dt2 into dt1# ----------------------------------------------dt1.merge(dt2)withopen("merged.dtb","wb")asf:f.write(dt1.to_dtb(version=17))#-----------------------------------------------# diff two fdt objects# ----------------------------------------------out=fdt.diff(dt1,dt2)print(out[0])# same in dt1 and dt2print(out[1])# specific for dt1print(out[2])# specific for dt2[ pydtc ] ToolThe python device tree converterpydtcis a tool for conversion *.dts to *.dtb and vice versa. Is distributed
together withfdtmodule. This tool can be in some cases used as replacement ofdevice tree compiler.$pydtc-h

usage:pydtc[-h][-v]{pack,unpack,merge,diff}...

FlatDeviceTree(FDT)toolformanipulationwith*.dtband*.dtsfiles

positionalarguments:{pack,unpack,merge,diff}packPack*.dtsintobinaryblob(*.dtb)unpackUnpack*.dtbintoreadableformat(*.dts)mergeMergemorefilesin*.dtbor*.dtsformatdiffComparetwofilesin*.dtbor*.dtsformat

optionalarguments:-h,--helpshowthishelpmessageandexit-v,--versionshowprogram'sversionnumberandexit$ pydtc unpack [-h] [-s TAB_SIZE] [-o DTS_FILE] dtb_fileUnpack Device Tree from binary blob *.dtb into readable text file *.dtsdtb_file- Single DTB file withdtbextensionoptional arguments:-h, --help- Show this help message and exit-s TAB_SIZE- Tabulator Size-o DTS_FILE- Output path/file name (*.dts)Example:pydtcunpacktest.dtbDTSsavedas:test.dts$ pydtc pack [-h] [-v VERSION] [-l LC_VERSION] [-c CPU_ID] [-p] [-o DTB_FILE] dts_filePack Device Tree from readable text file *.dts into binary blob *.dtbdts_file- Single DTS file as *.dtsoptional arguments:-h, --help- Show this help message and exit-v VERSION- DTB Version-l LC_VERSION- DTB Last Compatible Version-c CPU_ID- Boot CPU ID-p- Update phandle-o DTB_FILE- Output path/file name (*.dtb)Example:pydtcpack-v17test.dtsDTBsavedas:test.dtb$ pydtc merge [-h] [-t {auto,dts,dtb}] [-s TAB_SIZE] out_file in_files [in_files ...]Merge two and more *.dtb or *.dts files into one *.dts fileout_file- The output file name with *.dts extensionin_files- Two or more input files with *.dtb or *.dts extensionoptional arguments:-h, --help- Show this help message and exit-t {auto,dts,dtb}- Input file type: 'auto', 'dts', 'dtb' (default: auto)-s TAB_SIZE- Tabulator SizeExample:pydtcmergeout.dtstest1.dtbtest2.dtbOutputsavedas:out.dts$ pydtc diff [-h] [-t {auto,dts,dtb}] [-o OUT_DIR] in_file1 in_file2Compare two dtb/dts files and generate 3 dts files (same in 1 and 2, specific for 1, specific for 2)in_file1- Input file 1in_file2- Input file 2optional arguments:-h, --help- Show this help message and exit-t {auto,dts,dtb}- Input file type: 'auto', 'dts', 'dtb' (default: auto)-o OUT_DIR- Output directory (default: diff_out)Example:pydtcdifftest1.dtbtest2.dtbOutputsavedinto:diff_out