public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH v2 00/45] dm: core: Support multiple device trees in ofnode
@ 2022-09-07  2:26 Simon Glass
  2022-09-07  2:26 ` [PATCH v2 01/45] image: Fix BOOTM_STATE values Simon Glass
                   ` (44 more replies)
  0 siblings, 45 replies; 56+ messages in thread
From: Simon Glass @ 2022-09-07  2:26 UTC (permalink / raw)
  To: U-Boot Mailing List
  Cc: Kishon Vijay Abraham I, Michal Simek, Marek Behún, Tom Rini,
	Simon Glass, AKASHI Takahiro, Adrian Fiergolski,
	Alexandru Gagniuc, Alexey Brodkin, Alper Nebi Yasak,
	Anatolij Gustschin, Andre Przywara, Andrew Davis, Andrew Scull,
	Andrey Zhizhikin, Angelo Dureghello, Artem Lapkin,
	Ashok Reddy Soma, Aspeed BMC SW team, Balamanikandan Gunasundar,
	Bin Meng, Chia-Wei Wang, Chunfeng Yun, Daniel Golle,
	Daniel Schwierzeck, Dario Binacchi, Dzmitry Sankouski,
	Etienne Carriere, Eugeniy Paltsev, Ezequiel Garcia, Fabio Estevam,
	Frieder Schrempf, GSS_MTK_Uboot_upstream, Gaurav Jain,
	Gregory CLEMENT, Harald Seiler, Heiko Schocher, Heiko Thiery,
	Heinrich Schuchardt, Horatiu Vultur, Huan Wang, Ilias Apalodimas,
	Jaehoon Chung, Jagan Teki, Jan Kiszka, Jason Liu, Jens Wiklander,
	Joe Hershberger, Joel Stanley, Jérôme Carretero,
	Lars Povlsen, Leo, Lukasz Majewski, Lukasz Majewski, Mamta Shukla,
	Marek Vasut, Max Filippov, Michael Trimarchi,
	NXP i.MX U-Boot Team, Nobuhiro Iwamatsu, Oleksandr Suvorov,
	Ovidiu Panait, Ovidiu Panait, Pali Rohár, Patrice Chotard,
	Patrick Delaunay, Pavel Herrmann, Peng Fan, Peter Robinson,
	Philippe Reynes, Pierre-Clément Tosi, Ramon Fried,
	Rasmus Villemoes, Ricardo Salveti, Rick Chen, Ryan Chen,
	Ryder Lee, Samuel Holland, Sean Anderson, Sean Anderson,
	Simon Goldschmidt, Stefan Eichenberger, Stefan Roese,
	Stefano Babic, Thomas Chou, Thomas Huth, Tien Fong Chee,
	Tom Warren, Vaishnav Achath, Vignesh Raghavendra,
	Vitaly Andrianov, Vladimir Oltean, Weijie Gao, Wolfgang Denk,
	uboot-snps-arc

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


^ permalink raw reply	[flat|nested] 56+ messages in thread

end of thread, other threads:[~2022-09-30 19:53 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-07  2:26 [PATCH v2 00/45] dm: core: Support multiple device trees in ofnode Simon Glass
2022-09-07  2:26 ` [PATCH v2 01/45] image: Fix BOOTM_STATE values Simon Glass
2022-09-30 19:52   ` Tom Rini
2022-09-07  2:26 ` [PATCH v2 02/45] treewide: Drop bootm_headers_t typedef Simon Glass
2022-09-07  2:26 ` [PATCH v2 03/45] treewide: Drop image_info_t typedef Simon Glass
2022-09-07  2:26 ` [PATCH v2 04/45] treewide: Drop image_header_t typedef Simon Glass
2022-09-07  2:26 ` [PATCH v2 05/45] log: update the comment for log_msg_ret() Simon Glass
2022-09-07  2:26 ` [PATCH v2 06/45] sandbox: power: Update PMIC driver to use log Simon Glass
2022-09-08 11:36   ` Jaehoon Chung
2022-09-07  2:26 ` [PATCH v2 07/45] event: Fix a typo in the EVENT help Simon Glass
2022-09-07  2:26 ` [PATCH v2 08/45] event: Allow multiple spy declarations for each event Simon Glass
2022-09-07  2:26 ` [PATCH v2 09/45] dm: core: Pass a root node to of_find_node_by_phandle() Simon Glass
2022-09-07  2:26 ` [PATCH v2 10/45] event: Pass the images to EVT_FT_FIXUP Simon Glass
2022-09-07  2:26 ` [PATCH v2 11/45] test: Fix missing livetree test runs Simon Glass
2022-09-07  2:27 ` [PATCH v2 12/45] test: Support testing malloc() failures Simon Glass
2022-09-28 17:17   ` Sean Anderson
2022-09-28 21:06     ` Simon Glass
2022-09-28 21:50       ` Sean Anderson
2022-09-29  2:36         ` Simon Glass
2022-09-29  4:02           ` Sean Anderson
2022-09-29 12:42             ` Tom Rini
2022-09-07  2:27 ` [PATCH v2 13/45] dm: core: Document the livetree structures properly Simon Glass
2022-09-07  2:27 ` [PATCH v2 14/45] dm: core: Allow adding ofnode subnodes Simon Glass
2022-09-07  2:27 ` [PATCH v2 15/45] dm: core: Support writing a property to an empty node Simon Glass
2022-09-07  2:27 ` [PATCH v2 16/45] dm: core: Drop the const from ofnode Simon Glass
2022-09-07  2:27 ` [PATCH v2 17/45] test: Make a copy of the device tree before running a test Simon Glass
2022-09-07  2:27 ` [PATCH v2 18/45] test: Detect a change in the device tree Simon Glass
2022-09-07  2:27 ` [PATCH v2 19/45] test: Drop the UT_TESTF_LIVE_OR_FLAT flag Simon Glass
2022-09-07  2:27 ` [PATCH v2 20/45] sandbox: Add a function to load a relative file path Simon Glass
2022-09-07  2:27 ` [PATCH v2 21/45] sandbox: Support loading the other FDT Simon Glass
2022-09-07  2:27 ` [PATCH v2 22/45] sandbox: Support setting up the other FDT for testing Simon Glass
2022-09-07  2:27 ` [PATCH v2 23/45] sandbox: test: Provide an easy way to use the other FDT Simon Glass
2022-09-07  2:27 ` [PATCH v2 24/45] dm: core: Reduce code size with dev_of_offset() Simon Glass
2022-09-07  2:27 ` [PATCH v2 25/45] dm: core: Rename ofnode_get_first/next_property() Simon Glass
2022-09-07  2:27 ` [PATCH v2 26/45] dm: core: Rename ofnode_get_property_by_prop() Simon Glass
2022-09-07  2:27 ` [PATCH v2 27/45] dm: core: Avoid creating a name property when unflattening Simon Glass
2022-09-07  2:27 ` [PATCH v2 28/45] dm: core: Add a macro to iterate through properties Simon Glass
2022-09-07  2:27 ` [PATCH v2 29/45] dm: core: Drop ofnode_is_available() Simon Glass
2022-09-07  2:27 ` [PATCH v2 30/45] dm: core: Expand integer-reading tests Simon Glass
2022-09-29 23:13   ` Tom Rini
2022-09-29 23:55     ` Simon Glass
2022-09-07  2:27 ` [PATCH v2 31/45] dm: core: Provide a way to reset the device tree Simon Glass
2022-09-07  2:27 ` [PATCH v2 32/45] dm: core: Add an ofnode function to obtain the flat tree Simon Glass
2022-09-07  2:27 ` [PATCH v2 33/45] dm: core: Add ofnode functions to obtain an oftree Simon Glass
2022-09-07  2:27 ` [PATCH v2 34/45] dm: core: Add a way to look up a phandle in " Simon Glass
2022-09-07  2:27 ` [PATCH v2 35/45] dm: core: Allow obtaining a node offset in the same tree Simon Glass
2022-09-07  2:27 ` [PATCH v2 36/45] dm: core: Split ofnode_path_root() into two functions Simon Glass
2022-09-07  2:27 ` [PATCH v2 37/45] dm: core: Add definitions for multiple ofnode trees Simon Glass
2022-09-07  2:27 ` [PATCH v2 38/45] dm: core: Add the ofnode multi-tree implementation Simon Glass
2022-09-07  2:27 ` [PATCH v2 39/45] dm: core: Complete phandle implementation using the other FDT Simon Glass
2022-09-07  2:27 ` [PATCH v2 40/45] dm: core: Update comments for default-FDT ofnode functions Simon Glass
2022-09-07  2:27 ` [PATCH v2 41/45] dm: core: Create a function to get a live tree in a test Simon Glass
2022-09-07  2:27 ` [PATCH v2 42/45] dm: core: Expand ofnode tests Simon Glass
2022-09-07  2:27 ` [PATCH v2 43/45] vbe: Allow test to run with live/flat tree Simon Glass
2022-09-07  2:27 ` [PATCH v2 44/45] dm: core: Allow copying ofnode property data when writing Simon Glass
2022-09-07  2:27 ` [PATCH v2 45/45] dm: core: Support copying properties with ofnode Simon Glass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox