[U-Boot] [PATCH v3 00/72] dm: Add support for a 'live' device tree
Simon Glass
sjg at chromium.org
Fri May 19 02:08:50 UTC 2017
(this is series 2 of 3 for live tree support - the final series will
fully convert a real board and provide size comparisons)
So far U-Boot uses a 'flat' device tree, which means that it is decoded
on the fly as needed. This uses the libfdt library and avoids needing
extra memory for additional tables.
For some time there has been discussion about moving U-Boot to use a
'live' tree, where the device tree is decoded at start-up into a set of
hierarchical structures with pointers.
The advantages are:
- It is somewhat faster to access (in particular scanning and looking for a
parent)
- It permits the device tree to be changed at run-time (this is not
recommended with the flat device tree since devices store the offset
of their device tree node and updating the tree may invalidate that).
Enabling this feature could be useful for overlays, for example.
- It allows nodes to be referenced by a single pointer, instead of the
current device tree pointer plus offset
The disadvantages are:
- It requires more memory
- It takes (a little) time to build the live tree
- It adds more complexity under the hood, including an additional
abstraction layer
This series is an attempt to introduce a useful live tree feature into
U-Boot. There are many options and trade-offs. This series is the
culmination of quite a bit of thought and experimentation.
The approach used in this series is:
- Before relocation the flat tree is used, to avoid extra memory usage
and time. In general, there is not much access before relocation since
most drivers are not started up. So there is little benefit in having a
live tree
- After relocation the live tree is built. At this point the CPU should be
running quickly and there is plenty of memory. All available devices will
be bound so the overhead of building the live tree may be outweighed by
its greater efficiency.
As a simplification, this series supports only one tree or the other. When
the live tree is active, the flat tree cannot be used. That makes it easy
to know the current state and avoids confusion over mixing offset and node
pointers.
Some drivers will need to be used both before and after relocation. This
means that they must support both the flat and the live tree. To support
this, the concept of a node 'reference' is defined. A reference can hold
either a node offset (for the flat tree) or a node pointer (for the live
tree). This allows drivers to access values from the tree regardless of
which tree is in use.
In addition, since most device tree access happens in the context of a
device (struct udevice), a new 'dev_read' layer is provided to read device
tree configuration associated with a device. This encapsulates the details
of exactly how this information is read.
I have taken the view that code compatibility with Linux is desirable. So
the of_access.c file brings in code from Linux with very little
modification. As new access methods are needed we should be able to bring
in more code and avoid writing it ourselves in U-Boot.
Conversion of drivers and subsystems to support the live tree (as well as
flat tree) is fairly easy. Patch are included to add support to subsystems
for which tests exist, to ensure that 'make tests' still passes.
Future work will enable the live device tree on a real board and include
code size comparisons.
For now here is a code size comparison for firefly (within inlining of
ofnode which I intend to implement):
arm: (for 1/1 boards) all +268.0 bss -24.0 data -4.0 spl/u-boot-spl:all +240.0 spl/u-boot-spl:text +240.0 text +296.0
firefly-rk3288 : all +268 bss -24 data -4 spl/u-boot-spl:all +240 spl/u-boot-spl:text +240 text +296
u-boot: add: 18/-4, grow: 2/-22 bytes: 764/-490 (274)
function old new delta
gpio_request_tail - 132 +132
ofnode_parse_phandle_with_args - 66 +66
uclass_find_device_by_ofnode - 64 +64
ofnode_pre_reloc - 64 +64
ofnode_read_string - 52 +52
fdt_support_default_count_cells - 52 +52
ofnode_read_u32 - 48 +48
gpio_request_by_name 32 72 +40
ofnode_read_size - 34 +34
uclass_get_device_by_ofnode - 28 +28
ofnode_read_u32_array - 28 +28
ofnode_read_bool - 26 +26
ofnode_read_prop - 24 +24
ofnode_get_addr_size - 24 +24
ofnode_read_u32_default - 22 +22
ofnode_find_subnode - 18 +18
ofnode_next_subnode - 14 +14
ofnode_first_subnode - 14 +14
ofnode_get_name - 12 +12
dm_init_and_scan 42 44 +2
uclass_get_device_by_phandle 106 104 -2
spi_child_post_bind 32 30 -2
i2c_child_post_bind 32 30 -2
spi_post_probe 36 32 -4
spi_flash_scan 520 516 -4
serial_init 212 208 -4
i2c_post_probe 48 44 -4
clk_fixed_rate_ofdata_to_platdata 36 32 -4
act8846_bind 48 44 -4
simple_bus_post_bind 60 52 -8
lists_bind_fdt 240 232 -8
i2c_chip_ofdata_to_platdata 64 56 -8
clk_get_by_index 108 100 -8
usb_child_post_bind 92 80 -12
regmap_init_mem 228 216 -12
fixed_regulator_ofdata_to_platdata 108 96 -12
pmic_bind_children 158 144 -14
spi_slave_ofdata_to_platdata 256 240 -16
pinconfig_post_bind 136 116 -20
led_gpio_bind 108 88 -20
regulator_post_bind 148 124 -24
gpio_request_by_name_nodev 28 - -28
fdtdec_get_uint 30 - -30
regulator_pre_probe 220 184 -36
of_bus_default_count_cells 52 - -52
_gpio_request_by_name_nodev 152 - -152
spl-u-boot-spl: add: 8/-1, grow: 1/-5 bytes: 300/-56 (244)
function old new delta
ofnode_parse_phandle_with_args - 66 +66
uclass_find_device_by_ofnode - 64 +64
ofnode_read_u32 - 48 +48
ofnode_read_size - 34 +34
uclass_get_device_by_ofnode - 28 +28
ofnode_read_prop - 24 +24
ofnode_read_u32_default - 22 +22
ofnode_get_name - 12 +12
dm_init_and_scan 42 44 +2
dm_scan_fdt_node 96 94 -2
clk_fixed_rate_ofdata_to_platdata 36 32 -4
lists_bind_fdt 224 216 -8
clk_get_by_index 108 100 -8
regmap_init_mem 220 208 -12
device_bind 22 - -22
(no errors to report)
Changes in v3:
- Adjust header includes in ofnode.h to make it stand alone
- Fix up the fdtaddr.h header guard to avoid conflicts
- Clear the watchdog state also
- Add new patch to move pmic header out of config file
Changes in v2:
- Rewrite based on testing and refining the v1 series
- Convert various subsystems to enable sandbox tests to pass
Simon Glass (72):
dm: core: Set return value first in lists_bind_fdt()
Update WARN_ON() to return a value
dm: core: Add livetree definitions
dm: core: Add livetree access functions
dm: Add a function to create a 'live' device tree
dm: Build a live tree after relocation
dm: core: Rename of_device_is_compatible()
dm: core: Add operations on device tree references
dm: core: Add livetree address functions
fdt: Update fdt_get_base_address() to use const
dm: core: Add address operations on device tree references
dm: core: Add a place to put extra device-tree reading functions
dm: core: Add device-based 'read' functions to access DT
dm: core: Implement live tree 'read' functions
dm: core: Allow binding a device from a live tree
dm: core: Update lists_bind_fdt() to use ofnode
dm: core: Update device_bind_driver_to_node() to use ofnode
dm: core: Scan the live tree when setting up driver model
dm: core: Add a way to find a device by ofnode
dm: regmap: Add support for livetree
dm: simple-bus: Add support for livetree
dm: core: Update uclass_find_device_by_phandle() for livetree
sandbox: Add a way to reset sandbox state for tests
dm: test: Move test running code into a separate function
dm: test: Show the test filename when running
dm: test: Add support for running tests with livetree
dm: core: Run tests with both livetree and flat tree
dm: gpio: Refactor to prepare for live tree support
dm: gpio: Drop blank line in gpio_xlate_offs_flags() comment
dm: gpio: sandbox: Use dev_read...() functions to access DT
dm: gpio: Add live tree support
cros_ec: Fix debug() statement in ec_command_inptr()
cros_ec: Convert to support live tree
sandbox: Add a new sandbox_flattree board
test: Update 'make test' to run more tests
fdt: Rename a few functions in fdt_support
dm: Add more livetree helpers and definitions
string: Add strchrnul()
string: Add strcspn()
dm: i2c: Convert uclass to livetree
samsung: Move pmic header out of config file
dm: pmic: Convert uclass to livetree
sandbox: pmic: Convert pmic emulator to support livetree
dm: regulator: Convert regulator uclass to support livetree
dm: regulator: Update fixed regulator to support livetree.
dm: mmc: Convert uclass to livetree
dm: adc: Convert uclass to livetree
dm: usb: Convert uclass to livetree
sandbox: usb: Convert emulators to livetree
clk: Modify xlate() method for livetree
dm: clk: Update uclass to support livetree
dm: clk: fixed: Update to support livetree
dm: test: Separate out the bus DT offset test
dm: test: Disable the fdt_offset test with livetree
dm: phy: Update tests to use ut_asserteq()
dm: mailbox: Update uclass to support livetree
dm: phy: Update uclass to support livetree
sandbox: phy: Update driver for livetree
dm: power-domain: Update uclass to support livetree
dm: reset: Update uclass to support livetree
dm: pci: Update uclass to support livetree
dm: Update the I2C eeprom driver for livetree
cros_ec: Update the cros_ec keyboard driver to livetree
dm: spi: Convert uclass to livetree
dm: sandbox: i2c: Drop fdtdec.h header
dm: sandbox: i2c_rtc: Drop fdtdec.h header
dm: spi-flash: Convert uclass to livetree
dm: sandbox: spi: Convert driver to support livetree
dm: sandbox: sysreset: Convert driver to livetree
dm: test: Fix nit with position of backslash
dm: gpio: power: Convert pm8916 drivers to livetree
sandbox: Move to use live tree
arch/arm/cpu/armv8/fsl-layerscape/fdt.c | 4 +-
arch/arm/mach-tegra/tegra186/nvtboot_mem.c | 4 +-
arch/sandbox/cpu/state.c | 15 +-
arch/sandbox/include/asm/state.h | 7 +
board/qualcomm/dragonboard410c/dragonboard410c.c | 12 +-
board/samsung/common/board.c | 4 +-
board/samsung/common/exynos5-dt.c | 2 +-
board/samsung/common/misc.c | 1 +
board/sandbox/MAINTAINERS | 7 +
common/board_r.c | 12 +
common/fdt_support.c | 28 +-
configs/sandbox_defconfig | 1 +
configs/sandbox_flattree_defconfig | 179 ++++++
drivers/adc/adc-uclass.c | 14 +-
drivers/clk/at91/pmc.c | 4 +-
drivers/clk/at91/pmc.h | 2 +-
drivers/clk/clk-uclass.c | 14 +-
drivers/clk/clk_fixed_rate.c | 5 +-
drivers/clk/clk_stm32f7.c | 3 +-
drivers/core/Kconfig | 4 +
drivers/core/Makefile | 5 +
drivers/core/device.c | 20 +-
drivers/core/lists.c | 29 +-
drivers/core/of_access.c | 735 +++++++++++++++++++++++
drivers/core/of_addr.c | 359 +++++++++++
drivers/core/of_extra.c | 37 ++
drivers/core/ofnode.c | 579 ++++++++++++++++++
drivers/core/read.c | 140 +++++
drivers/core/regmap.c | 37 +-
drivers/core/root.c | 60 +-
drivers/core/simple-bus.c | 3 +-
drivers/core/uclass.c | 42 +-
drivers/cpu/cpu-uclass.c | 6 +-
drivers/firmware/psci.c | 4 +-
drivers/gpio/74x164_gpio.c | 2 +-
drivers/gpio/gpio-uclass.c | 82 +--
drivers/gpio/pca953x_gpio.c | 2 +-
drivers/gpio/pm8916_gpio.c | 8 +-
drivers/gpio/sandbox.c | 12 +-
drivers/gpio/sunxi_gpio.c | 2 +-
drivers/gpio/tegra186_gpio.c | 2 +-
drivers/gpio/tegra_gpio.c | 2 +-
drivers/i2c/i2c-uclass.c | 28 +-
drivers/i2c/muxes/i2c-mux-uclass.c | 11 +-
drivers/i2c/mxc_i2c.c | 12 +-
drivers/i2c/sandbox_i2c.c | 1 -
drivers/input/cros_ec_keyb.c | 24 +-
drivers/input/key_matrix.c | 19 +-
drivers/input/tegra-kbc.c | 3 +-
drivers/led/led_bcm6328.c | 2 +-
drivers/led/led_bcm6358.c | 2 +-
drivers/led/led_gpio.c | 13 +-
drivers/mailbox/mailbox-uclass.c | 20 +-
drivers/mailbox/tegra-hsp.c | 2 +-
drivers/misc/cros_ec.c | 36 +-
drivers/misc/cros_ec_sandbox.c | 23 +-
drivers/misc/i2c_eeprom_emul.c | 7 +-
drivers/misc/tegra186_bpmp.c | 6 +-
drivers/misc/tegra_car.c | 4 +-
drivers/mmc/fsl_esdhc.c | 6 +-
drivers/mmc/mmc-uclass.c | 3 +-
drivers/mmc/s5p_sdhci.c | 8 +-
drivers/mmc/xenon_sdhci.c | 2 +-
drivers/mtd/altera_qspi.c | 2 +-
drivers/mtd/cfi_flash.c | 2 +-
drivers/mtd/nand/sunxi_nand.c | 2 +-
drivers/mtd/nand/tegra_nand.c | 4 +-
drivers/mtd/pic32_flash.c | 2 +-
drivers/mtd/spi/sandbox.c | 6 +-
drivers/mtd/spi/spi_flash.c | 7 +-
drivers/net/altera_tse.c | 2 +-
drivers/net/cpsw-common.c | 4 +-
drivers/net/keystone_net.c | 6 +-
drivers/net/mvneta.c | 2 +-
drivers/net/pic32_eth.c | 3 +-
drivers/pci/pci-uclass.c | 26 +-
drivers/phy/marvell/comphy_core.c | 4 +-
drivers/phy/phy-uclass.c | 21 +-
drivers/phy/sandbox-phy.c | 3 +-
drivers/pinctrl/pinctrl-uclass.c | 15 +-
drivers/power/domain/power-domain-uclass.c | 19 +-
drivers/power/pmic/act8846.c | 8 +-
drivers/power/pmic/i2c_pmic_emul.c | 6 +-
drivers/power/pmic/lp873x.c | 12 +-
drivers/power/pmic/max77686.c | 8 +-
drivers/power/pmic/palmas.c | 16 +-
drivers/power/pmic/pfuze100.c | 8 +-
drivers/power/pmic/pm8916.c | 2 +-
drivers/power/pmic/pmic-uclass.c | 22 +-
drivers/power/pmic/rk8xx.c | 8 +-
drivers/power/pmic/s5m8767.c | 7 +-
drivers/power/pmic/sandbox.c | 2 +-
drivers/power/pmic/tps65090.c | 8 +-
drivers/power/regulator/fixed.c | 17 +-
drivers/power/regulator/regulator-uclass.c | 39 +-
drivers/reset/reset-uclass.c | 21 +-
drivers/rtc/i2c_rtc_emul.c | 1 -
drivers/serial/serial-uclass.c | 3 +-
drivers/sound/max98095.c | 2 +
drivers/sound/wm8994.c | 2 +-
drivers/spi/pic32_spi.c | 2 +-
drivers/spi/spi-uclass.c | 31 +-
drivers/sysreset/sysreset_sandbox.c | 2 +-
drivers/timer/timer-uclass.c | 3 +-
drivers/usb/emul/sandbox_flash.c | 4 +-
drivers/usb/emul/sandbox_hub.c | 3 +-
drivers/usb/host/ehci-marvell.c | 2 +-
drivers/usb/host/ehci-tegra.c | 7 +-
drivers/usb/host/ehci-vf.c | 5 +-
drivers/usb/host/usb-uclass.c | 8 +-
drivers/usb/host/xhci-rockchip.c | 2 +-
drivers/usb/musb-new/ti-musb.c | 2 +-
dts/Kconfig | 11 +
include/asm-generic/global_data.h | 3 +
include/asm-generic/gpio.h | 17 +-
include/clk-uclass.h | 5 +-
include/configs/trats2.h | 1 -
include/cros_ec.h | 8 +-
include/dm.h | 2 +
include/dm/device-internal.h | 10 +-
include/dm/device.h | 4 +-
include/dm/fdtaddr.h | 4 +-
include/dm/lists.h | 9 +-
include/dm/of.h | 142 +++++
include/dm/of_access.h | 347 +++++++++++
include/dm/of_addr.h | 64 ++
include/dm/of_extra.h | 46 ++
include/dm/ofnode.h | 488 ++++++++++++++-
include/dm/read.h | 439 ++++++++++++++
include/dm/root.h | 3 +-
include/dm/test.h | 2 +
include/dm/uclass-internal.h | 18 +
include/dm/uclass.h | 17 +
include/fdt_support.h | 6 +-
include/fdtdec.h | 34 --
include/generic-phy.h | 3 +-
include/i2c.h | 3 +-
include/key_matrix.h | 3 +-
include/linux/compat.h | 8 +-
include/linux/string.h | 28 +
include/mailbox-uclass.h | 2 +-
include/of_live.h | 24 +
include/power-domain-uclass.h | 2 +-
include/power/pmic.h | 2 +-
include/reset-uclass.h | 4 +-
include/spi.h | 2 +-
include/test/test.h | 4 +
include/test/ut.h | 2 +-
lib/Makefile | 1 +
lib/fdtdec.c | 33 +-
lib/of_live.c | 333 ++++++++++
lib/string.c | 32 +
test/dm/bus.c | 16 +-
test/dm/phy.c | 15 +-
test/dm/test-fdt.c | 3 +-
test/dm/test-main.c | 105 +++-
test/run | 8 +-
157 files changed, 4761 insertions(+), 667 deletions(-)
create mode 100644 configs/sandbox_flattree_defconfig
create mode 100644 drivers/core/of_access.c
create mode 100644 drivers/core/of_addr.c
create mode 100644 drivers/core/of_extra.c
create mode 100644 drivers/core/ofnode.c
create mode 100644 drivers/core/read.c
create mode 100644 include/dm/of.h
create mode 100644 include/dm/of_access.h
create mode 100644 include/dm/of_addr.h
create mode 100644 include/dm/of_extra.h
create mode 100644 include/dm/read.h
create mode 100644 include/of_live.h
create mode 100644 lib/of_live.c
--
2.13.0.303.g4ebf302169-goog
More information about the U-Boot
mailing list