1The source tree contains the Device Tree Compiler (dtc) toolchain for 2working with device tree source and binary files and also libfdt, a 3utility library for reading and manipulating the binary format. 4 5DTC and LIBFDT are maintained by: 6 7David Gibson <david@gibson.dropbear.id.au> 8Jon Loeliger <jdl@jdl.com> 9 10 11Python library 12-------------- 13 14A Python library is also available. To build this you will need to install 15swig and Python development files. On Debian distributions: 16 17 sudo apt-get install swig python3-dev 18 19The library provides an Fdt class which you can use like this: 20 21$ PYTHONPATH=../pylibfdt python3 22>>> import libfdt 23>>> fdt = libfdt.Fdt(open('test_tree1.dtb', mode='rb').read()) 24>>> node = fdt.path_offset('/subnode@1') 25>>> print(node) 26124 27>>> prop_offset = fdt.first_property_offset(node) 28>>> prop = fdt.get_property_by_offset(prop_offset) 29>>> print('%s=%s' % (prop.name, prop.as_str())) 30compatible=subnode1 31>>> node2 = fdt.path_offset('/') 32>>> print(fdt.getprop(node2, 'compatible').as_str()) 33test_tree1 34 35You will find tests in tests/pylibfdt_tests.py showing how to use each 36method. Help is available using the Python help command, e.g.: 37 38 $ cd pylibfdt 39 $ python3 -c "import libfdt; help(libfdt)" 40 41If you add new features, please check code coverage: 42 43 $ sudo apt-get install python3-coverage 44 $ cd tests 45 # It's just 'coverage' on most other distributions 46 $ python3-coverage run pylibfdt_tests.py 47 $ python3-coverage html 48 # Open 'htmlcov/index.html' in your browser 49 50 51To install the library via the normal setup.py method, use: 52 53 ./pylibfdt/setup.py install [--prefix=/path/to/install_dir] 54 55If --prefix is not provided, the default prefix is used, typically '/usr' 56or '/usr/local'. See Python's distutils documentation for details. You can 57also install via the Makefile if you like, but the above is more common. 58 59To install both libfdt and pylibfdt you can use: 60 61 make install [SETUP_PREFIX=/path/to/install_dir] \ 62 [PREFIX=/path/to/install_dir] 63 64To disable building the python library, even if swig and Python are available, 65use: 66 67 make NO_PYTHON=1 68 69 70More work remains to support all of libfdt, including access to numeric 71values. 72 73 74Tests 75----- 76 77Test files are kept in the tests/ directory. Use 'make check' to build and run 78all tests. 79 80If you want to adjust a test file, be aware that tree_tree1.dts is compiled 81and checked against a binary tree from assembler macros in trees.S. So 82if you change that file you must change tree.S also. 83 84 85Mailing list 86------------ 87The following list is for discussion about dtc and libfdt implementation 88mailto:devicetree-compiler@vger.kernel.org 89 90Core device tree bindings are discussed on the devicetree-spec list: 91mailto:devicetree-spec@vger.kernel.org 92