Grant Likely | aef4927 | 2014-02-11 13:56:32 +0000 | [diff] [blame] | 1 | The source tree contains the Device Tree Compiler (dtc) toolchain for |
| 2 | working with device tree source and binary files and also libfdt, a |
| 3 | utility library for reading and manipulating the binary format. |
| 4 | |
| 5 | DTC and LIBFDT are maintained by: |
| 6 | |
| 7 | David Gibson <david@gibson.dropbear.id.au> |
| 8 | Jon Loeliger <jdl@jdl.com> |
| 9 | |
Simon Glass | b40aa83 | 2017-03-17 16:14:32 -0600 | [diff] [blame] | 10 | |
| 11 | Python library |
| 12 | -------------- |
| 13 | |
| 14 | A Python library is also available. To build this you will need to install |
| 15 | swig and Python development files. On Debian distributions: |
| 16 | |
| 17 | sudo apt-get install swig python-dev |
| 18 | |
| 19 | The library provides an Fdt class which you can use like this: |
| 20 | |
| 21 | $ PYTHONPATH=../pylibfdt python |
| 22 | >>> import libfdt |
| 23 | >>> fdt = libfdt.Fdt(open('test_tree1.dtb').read()) |
| 24 | >>> node = fdt.path_offset('/subnode@1') |
| 25 | >>> print node |
| 26 | 124 |
| 27 | >>> prop_offset = fdt.first_property_offset(node) |
| 28 | >>> prop = fdt.get_property_by_offset(prop_offset) |
| 29 | >>> print '%s=%r' % (prop.name, prop.value) |
| 30 | compatible=bytearray(b'subnode1\x00') |
| 31 | >>> print '%s=%s' % (prop.name, prop.value) |
| 32 | compatible=subnode1 |
| 33 | >>> node2 = fdt.path_offset('/') |
| 34 | >>> print fdt.getprop(node2, 'compatible') |
| 35 | test_tree1 |
| 36 | |
| 37 | You will find tests in tests/pylibfdt_tests.py showing how to use each |
| 38 | method. Help is available using the Python help command, e.g.: |
| 39 | |
| 40 | $ cd pylibfdt |
| 41 | $ python -c "import libfdt; help(libfdt)" |
| 42 | |
| 43 | If you add new features, please check code coverage: |
| 44 | |
| 45 | $ sudo apt-get install python-pip python-pytest |
| 46 | $ sudo pip install coverage |
| 47 | $ cd tests |
| 48 | $ coverage run pylibfdt_tests.py |
| 49 | $ coverage html |
| 50 | # Open 'htmlcov/index.html' in your browser |
| 51 | |
| 52 | |
Simon Glass | 90db6d9 | 2017-04-07 15:51:32 -0600 | [diff] [blame] | 53 | To install the library via the normal setup.py method, use: |
Simon Glass | e91c652 | 2017-03-26 13:06:21 -0600 | [diff] [blame] | 54 | |
Simon Glass | 90db6d9 | 2017-04-07 15:51:32 -0600 | [diff] [blame] | 55 | ./pylibfdt/setup.py [--prefix=/path/to/install_dir] |
Simon Glass | e91c652 | 2017-03-26 13:06:21 -0600 | [diff] [blame] | 56 | |
Simon Glass | 90db6d9 | 2017-04-07 15:51:32 -0600 | [diff] [blame] | 57 | If --prefix is not provided, the default prefix is used, typically '/usr' |
| 58 | or '/usr/local'. See Python's distutils documentation for details. You can |
| 59 | also install via the Makefile if you like, but the above is more common. |
| 60 | |
| 61 | To install both libfdt and pylibfdt you can use: |
| 62 | |
| 63 | make install [SETUP_PREFIX=/path/to/install_dir] \ |
| 64 | [PREFIX=/path/to/install_dir] |
Simon Glass | e91c652 | 2017-03-26 13:06:21 -0600 | [diff] [blame] | 65 | |
Simon Glass | 8a892fd | 2017-03-26 13:06:18 -0600 | [diff] [blame] | 66 | To disable building the python library, even if swig and Python are available, |
| 67 | use: |
| 68 | |
| 69 | make NO_PYTHON=1 |
| 70 | |
| 71 | |
Simon Glass | b40aa83 | 2017-03-17 16:14:32 -0600 | [diff] [blame] | 72 | More work remains to support all of libfdt, including access to numeric |
| 73 | values. |
| 74 | |
| 75 | |
Grant Likely | aef4927 | 2014-02-11 13:56:32 +0000 | [diff] [blame] | 76 | Mailing list |
| 77 | ------------ |
| 78 | The following list is for discussion about dtc and libfdt implementation |
| 79 | mailto:devicetree-compiler@vger.kernel.org |
| 80 | |
| 81 | Core device tree bindings are discussed on the devicetree-spec list: |
| 82 | mailto:devicetree-spec@vger.kernel.org |