blob: a48312a422c2790c705b481205a620ef0f0f0bab [file] [log] [blame]
Grant Likelyaef49272014-02-11 13:56:32 +00001The 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>
Pierre-Clément Tosief1978a2022-05-30 20:57:34 +01008Jon Loeliger <loeliger@gmail.com>
Grant Likelyaef49272014-02-11 13:56:32 +00009
Simon Glassb40aa832017-03-17 16:14:32 -060010
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
Luca Weiss95ce19c2019-08-17 23:25:32 +020017 sudo apt-get install swig python3-dev
Simon Glassb40aa832017-03-17 16:14:32 -060018
19The library provides an Fdt class which you can use like this:
20
Luca Weiss95ce19c2019-08-17 23:25:32 +020021$ PYTHONPATH=../pylibfdt python3
Simon Glassb40aa832017-03-17 16:14:32 -060022>>> import libfdt
Luca Weiss95ce19c2019-08-17 23:25:32 +020023>>> fdt = libfdt.Fdt(open('test_tree1.dtb', mode='rb').read())
Simon Glassb40aa832017-03-17 16:14:32 -060024>>> node = fdt.path_offset('/subnode@1')
Luca Weiss95ce19c2019-08-17 23:25:32 +020025>>> print(node)
Simon Glassb40aa832017-03-17 16:14:32 -060026124
27>>> prop_offset = fdt.first_property_offset(node)
28>>> prop = fdt.get_property_by_offset(prop_offset)
Luca Weiss95ce19c2019-08-17 23:25:32 +020029>>> print('%s=%s' % (prop.name, prop.as_str()))
Simon Glassb40aa832017-03-17 16:14:32 -060030compatible=subnode1
31>>> node2 = fdt.path_offset('/')
Luca Weiss95ce19c2019-08-17 23:25:32 +020032>>> print(fdt.getprop(node2, 'compatible').as_str())
Simon Glassb40aa832017-03-17 16:14:32 -060033test_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
Luca Weiss95ce19c2019-08-17 23:25:32 +020039 $ python3 -c "import libfdt; help(libfdt)"
Simon Glassb40aa832017-03-17 16:14:32 -060040
41If you add new features, please check code coverage:
42
Luca Weiss95ce19c2019-08-17 23:25:32 +020043 $ sudo apt-get install python3-coverage
Simon Glassb40aa832017-03-17 16:14:32 -060044 $ cd tests
Luca Weiss95ce19c2019-08-17 23:25:32 +020045 # It's just 'coverage' on most other distributions
46 $ python3-coverage run pylibfdt_tests.py
47 $ python3-coverage html
Simon Glassb40aa832017-03-17 16:14:32 -060048 # Open 'htmlcov/index.html' in your browser
49
50
Pierre-Clément Tosief1978a2022-05-30 20:57:34 +010051The library can be installed with pip from a local source tree:
Simon Glasse91c6522017-03-26 13:06:21 -060052
Pierre-Clément Tosief1978a2022-05-30 20:57:34 +010053 pip install . [--user|--prefix=/path/to/install_dir]
Simon Glasse91c6522017-03-26 13:06:21 -060054
Pierre-Clément Tosief1978a2022-05-30 20:57:34 +010055Or directly from a remote git repo:
56
57 pip install git+git://git.kernel.org/pub/scm/utils/dtc/dtc.git@main
58
59The install depends on libfdt shared library being installed on the host system
60first. Generally, using --user or --prefix is not necessary and pip will use the
61default location for the Python installation which varies if the user is root or
62not.
63
64You can also install everything via make if you like, but pip is recommended.
Simon Glass90db6d92017-04-07 15:51:32 -060065
66To install both libfdt and pylibfdt you can use:
67
Pierre-Clément Tosief1978a2022-05-30 20:57:34 +010068 make install [PREFIX=/path/to/install_dir]
Simon Glasse91c6522017-03-26 13:06:21 -060069
Simon Glass8a892fd2017-03-26 13:06:18 -060070To disable building the python library, even if swig and Python are available,
71use:
72
73 make NO_PYTHON=1
74
75
Simon Glassb40aa832017-03-17 16:14:32 -060076More work remains to support all of libfdt, including access to numeric
77values.
78
79
Pierre-Clément Tosief1978a2022-05-30 20:57:34 +010080Adding a new function to libfdt.h
81---------------------------------
82
83The shared library uses libfdt/version.lds to list the exported functions, so
84add your new function there. Check that your function works with pylibfdt. If
85it cannot be supported, put the declaration in libfdt.h behind #ifndef SWIG so
86that swig ignores it.
87
88
Simon Glass62d81232017-08-19 11:18:02 -060089Tests
90-----
91
92Test files are kept in the tests/ directory. Use 'make check' to build and run
93all tests.
94
95If you want to adjust a test file, be aware that tree_tree1.dts is compiled
96and checked against a binary tree from assembler macros in trees.S. So
97if you change that file you must change tree.S also.
98
99
Grant Likelyaef49272014-02-11 13:56:32 +0000100Mailing list
101------------
102The following list is for discussion about dtc and libfdt implementation
103mailto:devicetree-compiler@vger.kernel.org
104
105Core device tree bindings are discussed on the devicetree-spec list:
106mailto:devicetree-spec@vger.kernel.org