README 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. DTC and LIBFDT are maintained by:
  5. David Gibson <david@gibson.dropbear.id.au>
  6. Jon Loeliger <loeliger@gmail.com>
  7. Python library
  8. --------------
  9. A Python library is also available. To build this you will need to install
  10. swig and Python development files. On Debian distributions:
  11. sudo apt-get install swig python3-dev
  12. The library provides an Fdt class which you can use like this:
  13. $ PYTHONPATH=../pylibfdt python3
  14. >>> import libfdt
  15. >>> fdt = libfdt.Fdt(open('test_tree1.dtb', mode='rb').read())
  16. >>> node = fdt.path_offset('/subnode@1')
  17. >>> print(node)
  18. 124
  19. >>> prop_offset = fdt.first_property_offset(node)
  20. >>> prop = fdt.get_property_by_offset(prop_offset)
  21. >>> print('%s=%s' % (prop.name, prop.as_str()))
  22. compatible=subnode1
  23. >>> node2 = fdt.path_offset('/')
  24. >>> print(fdt.getprop(node2, 'compatible').as_str())
  25. test_tree1
  26. You will find tests in tests/pylibfdt_tests.py showing how to use each
  27. method. Help is available using the Python help command, e.g.:
  28. $ cd pylibfdt
  29. $ python3 -c "import libfdt; help(libfdt)"
  30. If you add new features, please check code coverage:
  31. $ sudo apt-get install python3-coverage
  32. $ cd tests
  33. # It's just 'coverage' on most other distributions
  34. $ python3-coverage run pylibfdt_tests.py
  35. $ python3-coverage html
  36. # Open 'htmlcov/index.html' in your browser
  37. The library can be installed with pip from a local source tree:
  38. pip install . [--user|--prefix=/path/to/install_dir]
  39. Or directly from a remote git repo:
  40. pip install git+git://git.kernel.org/pub/scm/utils/dtc/dtc.git@main
  41. The install depends on libfdt shared library being installed on the host system
  42. first. Generally, using --user or --prefix is not necessary and pip will use the
  43. default location for the Python installation which varies if the user is root or
  44. not.
  45. You can also install everything via make if you like, but pip is recommended.
  46. To install both libfdt and pylibfdt you can use:
  47. make install [PREFIX=/path/to/install_dir]
  48. To disable building the python library, even if swig and Python are available,
  49. use:
  50. make NO_PYTHON=1
  51. More work remains to support all of libfdt, including access to numeric
  52. values.
  53. Adding a new function to libfdt.h
  54. ---------------------------------
  55. The shared library uses libfdt/version.lds to list the exported functions, so
  56. add your new function there. Check that your function works with pylibfdt. If
  57. it cannot be supported, put the declaration in libfdt.h behind #ifndef SWIG so
  58. that swig ignores it.
  59. Tests
  60. -----
  61. Test files are kept in the tests/ directory. Use 'make check' to build and run
  62. all tests.
  63. If you want to adjust a test file, be aware that tree_tree1.dts is compiled
  64. and checked against a binary tree from assembler macros in trees.S. So
  65. if you change that file you must change tree.S also.
  66. Mailing list
  67. ------------
  68. The following list is for discussion about dtc and libfdt implementation
  69. mailto:devicetree-compiler@vger.kernel.org
  70. Core device tree bindings are discussed on the devicetree-spec list:
  71. mailto:devicetree-spec@vger.kernel.org