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 500 bytes, e.g. on venice2: buildman -b ofn 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 23: dm: core: Add the ofnode multi-tree implementation 24: wip arm: (for 1/1 boards) all +580.0 text +580.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. Simon Glass (21): image: Fix BOOTM_STATE values treewide: Drop bootm_headers_t typedef treewide: Drop image_info_t typedef treewide: Drop image_header_t typedef event: Fix a typo in the EVENT help dm: core: Pass a root node to of_find_node_by_phandle() event: Pass the images to EVT_FT_FIXUP 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 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: Add definitions for multiple ofnode trees dm: core: Reduce code size with dev_of_offset() dm: core: Add the ofnode multi-tree implementation 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/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/bootm.c | 8 +- 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 +- 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/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 | 30 ++- doc/uImage.FIT/source_file_format.txt | 2 +- drivers/core/Kconfig | 24 +++ drivers/core/fdtaddr.c | 18 +- drivers/core/of_access.c | 65 +++++- drivers/core/ofnode.c | 263 ++++++++++++++++++++----- drivers/fpga/socfpga_arria10.c | 4 +- drivers/usb/gadget/f_sdp.c | 2 +- include/asm-generic/global_data.h | 4 + include/bootm.h | 6 +- include/configs/uniphier.h | 2 +- include/dm/device.h | 6 +- include/dm/of_access.h | 16 +- include/dm/ofnode.h | 159 +++++++++++++-- include/dm/ofnode_decl.h | 31 ++- include/event.h | 2 + include/image.h | 118 +++++------ include/spl.h | 8 +- include/tee/optee.h | 4 +- include/test/test.h | 8 +- lib/efi_loader/efi_dt_fixup.c | 2 +- lib/fdtdec.c | 5 +- test/dm/ofnode.c | 30 ++- test/image/spl_load.c | 4 +- test/test-main.c | 89 ++++++++- 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 +- 92 files changed, 951 insertions(+), 411 deletions(-) -- 2.37.2.672.g94769d06f0-goog