[PATCH v2 00/45] dm: core: Support multiple device trees in ofnode

Simon Glass sjg at chromium.org
Wed Sep 7 04:26:48 CEST 2022


At present the ofnode interface is somewhat limited, in that it cannot
access the device tree provided by the OS, only the one used by U-Boot
itself (assuming these are separate). This prevents using ofnode functions
to handle device tree fixups, i.e. ft_board_setup() and the like.

The ofnode interface was introduced to allow a consistent API to access
the device tree, whether a flat tree or a live tree (OF_LIVE) is in use.

With the flat tree, adding nodes and properties at the start of the tree
(as often happens when writing to the /chosen node) requires copying a
lot of data for each operation. With live tree, such operations are
quite a bit faster, since there is no memory copying required. This has to
be weighed against the required memory allocation with OF_LIVE, as well
as the cost of unflattening and flattening the device tree which U-Boot
is running.

This series enables support for access to multiple device trees with the
ofnode interface. This is already available to some extent with OF_LIVE,
but some of the ofnode functions need changes to allow the tree to be
specified.

The mechanism works by using the top 1-4 bits of the device tree offset.
The sign bit is not affected, since negative values must be supported.

With this implemented, it becomes possible to use the ofnode interface
to do device tree fixups. The only current user is the EVT_FT_FIXUP
event.

This has two main benefits:

- ofnode can now be used everywhere, in preference to the libfdt calls
- live tree can eventually be used everywhere, with potential speed
  improvements when larger number of fixups are used

This series is only a step along the way. Firstly, while it is possible
to access the 'fix-up' tree using OF_LIVE, most of the fixup functions use
flat tree directly, rather than the ofnode interface. These need to be
updated. Also the tree must be flattened again before it is passed to the
OS. This is not currently implemented.

With OFNODE_MULTI_TREE disabled this has almost no effect on code size:
around 4 bytes if EVENT is enabled, 0 if not. With the feature enabled,
the increase is around 700 bytes, e.g. on venice2:

$ buildman -b ofn2a venice2 -sS --step 0
Summary of 2 commits for 1 boards (1 thread, 64 jobs per thread)
01: image: Drop some other #ifdefs in image-board.c
       arm:  w+   venice2
48: wip
       arm: (for 1/1 boards) all +668.0 text +668.0

This size increase is not too bad, considering the extra functionality,
but is too large to enable everywhere. So for now this features needs to
be opt-in only, based on EVENT.

Changes in v2:
- Return the existing node with -EEXIST
- Allow len to be passed in as -1
- Add a comment as to why strncmp() is not enough
- Add a comment why the len parameter is needed
- Add a comment why the new_name variable is used
- Add tests for the memory checks in of_add_subnode()
- Fix memory checks
- Fix 'property' comment
- Add lots more tests and a few other fixes
- Gosh that code was a mess
- Add new patch to rename ofnode_get_property_by_prop()
- Substantially expanded to improve the ofnode implementation/interface
- Added more ofnode tests
- Minor reworks of the ofnode internals, using oftree
- Added testing of memory-allocation failures

Simon Glass (45):
  image: Fix BOOTM_STATE values
  treewide: Drop bootm_headers_t typedef
  treewide: Drop image_info_t typedef
  treewide: Drop image_header_t typedef
  log: update the comment for log_msg_ret()
  sandbox: power: Update PMIC driver to use log
  event: Fix a typo in the EVENT help
  event: Allow multiple spy declarations for each event
  dm: core: Pass a root node to of_find_node_by_phandle()
  event: Pass the images to EVT_FT_FIXUP
  test: Fix missing livetree test runs
  test: Support testing malloc() failures
  dm: core: Document the livetree structures properly
  dm: core: Allow adding ofnode subnodes
  dm: core: Support writing a property to an empty node
  dm: core: Drop the const from ofnode
  test: Make a copy of the device tree before running a test
  test: Detect a change in the device tree
  test: Drop the UT_TESTF_LIVE_OR_FLAT flag
  sandbox: Add a function to load a relative file path
  sandbox: Support loading the other FDT
  sandbox: Support setting up the other FDT for testing
  sandbox: test: Provide an easy way to use the other FDT
  dm: core: Reduce code size with dev_of_offset()
  dm: core: Rename ofnode_get_first/next_property()
  dm: core: Rename ofnode_get_property_by_prop()
  dm: core: Avoid creating a name property when unflattening
  dm: core: Add a macro to iterate through properties
  dm: core: Drop ofnode_is_available()
  dm: core: Expand integer-reading tests
  dm: core: Provide a way to reset the device tree
  dm: core: Add an ofnode function to obtain the flat tree
  dm: core: Add ofnode functions to obtain an oftree
  dm: core: Add a way to look up a phandle in an oftree
  dm: core: Allow obtaining a node offset in the same tree
  dm: core: Split ofnode_path_root() into two functions
  dm: core: Add definitions for multiple ofnode trees
  dm: core: Add the ofnode multi-tree implementation
  dm: core: Complete phandle implementation using the other FDT
  dm: core: Update comments for default-FDT ofnode functions
  dm: core: Create a function to get a live tree in a test
  dm: core: Expand ofnode tests
  vbe: Allow test to run with live/flat tree
  dm: core: Allow copying ofnode property data when writing
  dm: core: Support copying properties with ofnode

 arch/arc/lib/bootm.c                      |   8 +-
 arch/arm/lib/bootm.c                      |  13 +-
 arch/arm/mach-aspeed/ast2600/spl.c        |   4 +-
 arch/arm/mach-imx/hab.c                   |   2 +-
 arch/arm/mach-imx/spl_imx_romapi.c        |   6 +-
 arch/arm/mach-k3/common.c                 |   2 +-
 arch/arm/mach-k3/sysfw-loader.c           |   6 +-
 arch/arm/mach-keystone/cmd_mon.c          |   6 +-
 arch/arm/mach-socfpga/board.c             |   2 +-
 arch/arm/mach-sunxi/spl_spi_sunxi.c       |   4 +-
 arch/arm/mach-tegra/xusb-padctl-common.c  |   2 +-
 arch/m68k/lib/bootm.c                     |   2 +-
 arch/microblaze/lib/bootm.c               |   6 +-
 arch/mips/lib/bootm.c                     |  16 +-
 arch/mips/mach-jz47xx/jz4780/jz4780.c     |   6 +-
 arch/mips/mach-mtmips/mt7621/spl/spl.c    |   4 +-
 arch/mips/mach-mtmips/mt7621/tpl/tpl.c    |   4 +-
 arch/nios2/lib/bootm.c                    |   2 +-
 arch/powerpc/lib/bootm.c                  |  16 +-
 arch/riscv/lib/andes_plic.c               |   2 +-
 arch/riscv/lib/bootm.c                    |   8 +-
 arch/riscv/lib/smp.c                      |   2 +-
 arch/sandbox/cpu/cpu.c                    |  34 +-
 arch/sandbox/cpu/start.c                  |  16 +-
 arch/sandbox/cpu/state.c                  |  48 ++
 arch/sandbox/dts/Makefile                 |   2 +-
 arch/sandbox/dts/other.dts                |  35 ++
 arch/sandbox/include/asm/malloc.h         |   1 +
 arch/sandbox/include/asm/state.h          |  30 +
 arch/sandbox/include/asm/test.h           |  19 +
 arch/sandbox/lib/bootm.c                  |   2 +-
 arch/sh/lib/bootm.c                       |   2 +-
 arch/x86/lib/bootm.c                      |   8 +-
 arch/xtensa/lib/bootm.c                   |   2 +-
 board/synopsys/hsdk/hsdk.c                |   2 +-
 board/ti/ks2_evm/board.c                  |   4 +-
 boot/boot_fit.c                           |   4 +-
 boot/bootm.c                              |  26 +-
 boot/bootm_os.c                           |  35 +-
 boot/image-android.c                      |   6 +-
 boot/image-board.c                        |  26 +-
 boot/image-fdt.c                          |  13 +-
 boot/image-fit.c                          |  16 +-
 boot/image.c                              |  14 +-
 boot/vbe_simple.c                         |   2 +-
 cmd/bootefi.c                             |   2 +-
 cmd/booti.c                               |   2 +-
 cmd/bootm.c                               |   4 +-
 cmd/bootz.c                               |   2 +-
 cmd/disk.c                                |   4 +-
 cmd/fpga.c                                |   2 +-
 cmd/nand.c                                |   4 +-
 cmd/source.c                              |   2 +-
 cmd/ximg.c                                |   4 +-
 common/Kconfig                            |   2 +-
 common/board_r.c                          |   2 +
 common/dlmalloc.c                         |  19 +
 common/spl/spl.c                          |  10 +-
 common/spl/spl_ext.c                      |   4 +-
 common/spl/spl_fat.c                      |   6 +-
 common/spl/spl_legacy.c                   |   8 +-
 common/spl/spl_mmc.c                      |   4 +-
 common/spl/spl_nand.c                     |   4 +-
 common/spl/spl_net.c                      |   2 +-
 common/spl/spl_nor.c                      |   8 +-
 common/spl/spl_onenand.c                  |   2 +-
 common/spl/spl_ram.c                      |   8 +-
 common/spl/spl_sata.c                     |   2 +-
 common/spl/spl_semihosting.c              |   4 +-
 common/spl/spl_spi.c                      |   6 +-
 common/spl/spl_ubi.c                      |   4 +-
 common/spl/spl_xip.c                      |   2 +-
 common/spl/spl_ymodem.c                   |  14 +-
 common/splash_source.c                    |   6 +-
 doc/develop/driver-model/livetree.rst     |  37 +-
 doc/uImage.FIT/source_file_format.txt     |   2 +-
 drivers/core/Kconfig                      |  24 +
 drivers/core/fdtaddr.c                    |  18 +-
 drivers/core/of_access.c                  |  83 ++-
 drivers/core/ofnode.c                     | 442 +++++++++++---
 drivers/core/read.c                       |   6 +-
 drivers/cpu/imx8_cpu.c                    |   2 +-
 drivers/cpu/riscv_cpu.c                   |   2 +-
 drivers/crypto/fsl/jr.c                   |   2 +-
 drivers/firmware/scmi/scmi_agent-uclass.c |   2 +-
 drivers/fpga/socfpga_arria10.c            |   4 +-
 drivers/mtd/mtdpart.c                     |   4 +-
 drivers/mtd/nand/raw/zynq_nand.c          |   2 +-
 drivers/net/fec_mxc.c                     |   2 +-
 drivers/net/fsl_enetc.c                   |   2 +-
 drivers/net/mscc_eswitch/felix_switch.c   |   2 +-
 drivers/net/sja1105.c                     |   2 +-
 drivers/net/ti/am65-cpsw-nuss.c           |   2 +-
 drivers/pci/pci-uclass.c                  |   2 +-
 drivers/pci/pci_mvebu.c                   |   2 +-
 drivers/pci/pci_tegra.c                   |   2 +-
 drivers/pci/pcie_mediatek.c               |   4 +-
 drivers/power/pmic/sandbox.c              |  10 +-
 drivers/usb/gadget/f_sdp.c                |   2 +-
 env/common.c                              |   6 +-
 include/asm-generic/global_data.h         |   4 +
 include/bootm.h                           |   6 +-
 include/configs/uniphier.h                |   2 +-
 include/dm/device.h                       |   6 +-
 include/dm/of.h                           |  15 +-
 include/dm/of_access.h                    |  29 +-
 include/dm/ofnode.h                       | 345 +++++++++--
 include/dm/ofnode_decl.h                  |  37 +-
 include/dm/read.h                         |   8 +-
 include/event.h                           |   6 +-
 include/image.h                           | 118 ++--
 include/log.h                             |   5 +-
 include/malloc.h                          |  12 +
 include/spl.h                             |   8 +-
 include/tee/optee.h                       |   4 +-
 include/test/test.h                       |  30 +-
 include/test/ut.h                         |   5 +
 lib/efi_loader/efi_dt_fixup.c             |   2 +-
 lib/fdtdec.c                              |   7 +-
 lib/of_live.c                             |   7 +-
 net/dsa-uclass.c                          |   2 +-
 scripts/event_dump.py                     |   4 +-
 test/boot/vbe_simple.c                    |  25 +-
 test/dm/ofnode.c                          | 696 +++++++++++++++++++++-
 test/dm/ofread.c                          |  11 +-
 test/image/spl_load.c                     |   4 +-
 test/test-main.c                          | 136 ++++-
 tools/binman/ftest.py                     |   4 +-
 tools/default_image.c                     |  31 +-
 tools/fit_image.c                         |   4 +-
 tools/imx8mimage.c                        |   8 +-
 tools/mkimage.c                           |   2 +-
 tools/mtk_image.c                         |  10 +-
 133 files changed, 2253 insertions(+), 621 deletions(-)
 create mode 100644 arch/sandbox/dts/other.dts

-- 
2.37.2.789.g6183377224-goog



More information about the U-Boot mailing list