[PATCH 00/20] dm: Enhance of-platdata to support parent devices
Simon Glass
sjg at chromium.org
Sat Oct 3 19:31:22 CEST 2020
At present dev_get_parent() always returns the root device with
of-platdata. This means that it is not possible to find the I2C bus for an
I2C device easily. In many cases this does not cause problems as there is
only a single I2C bus, but it is still inconsistent with U-Boot proper.
Worse is that because devices are not bound to the correct parent, they
will not have parent_platdata allocated correctly. Manual fix-ups are
required in the code.
This series adds support for parent devices with of-platdata.
Recent improvements to of-platadata have provided a function to obtain a
device based on its driver_info struct. This requires in generated C code
in dm_populate_phandle_data() which writes the udevice pointer into each
phandle value, since this cannot be known at build time.
This works well and fixes a big hole in of-platdata. But the
implementation has a few drawbacks: the need for generated code adds (very
slightly) to code size and it means that the SPL must sit in writable
memory. The latter can be considered a security risk and is not actually
supported on Intel Apollo Lake.
Another point is that in future of-platadata may support instantiation of
devices at build time. Pointer fix-ups could become quite taxing.
So this series adjusts the approach, storing an index (idx) to the
driver_info struct in the linker list instead. That index can be figured
out in dtoc and the value placed directly in the phandle struct. For
64-bit machines it is also smaller than a pointer. It requires a new table
(driver_rt) to be set up at runtime.
This series adds more SPL tests written in C, using the infrastructure in
the previous series (u-boot-dm/tes-working). A few clean-ups and a bug fix
resulting from these are included.
Finally, x86 is updated to use the parent support. For now, parent support
is behind a Kconfig option, but I expect this will become the default,
assuming that no major problems are found.
SPL size impact is fairly neural, slightly positive on chromebook_jerry
(Thumb-2) and slightly negative on rock64-rk3328 (aarch64):
aarch64: spl/u-boot-spl:all +39.0 spl/u-boot-spl:rodata -5.0
spl/u-boot-spl:text +44.0
arm: spl/u-boot-spl:all -49.0 spl/u-boot-spl:data -80.0
spl/u-boot-spl:text +36.0 spl/u-boot-spl:rodata -5.0
The increase in code size is due to lists_bind_drivers() having to do
multiple passes to ensure that parents are processed before children. This
could possible be reduced with a more complex linker list ordering
mechanism, but it would be a bit messy and that idea is not explored in
this series.
Simon Glass (20):
sandbox: Drop ad-hoc device declarations in SPL
dtoc: Document the return value of scan_structs()
dtoc: Order the structures internally by name
dm: core: Allow dm_warn() to be used in SPL
dtoc: Fix widening of int to bytes
dm: Add a C test for of-platdata properties
sandbox: Allow selection of SPL unit tests
dm: test: Drop of-platdata pytest
dm: test: Add a check that all devices have a dev value
dm: test: Add a test for of-platdata phandles
dm: Use an allocated array for run-time device info
sandbox: Fix up building for of-platdata
dm: Support parent devices with of-platdata
dm: Add a test for of-platdata parent information
dm: core: Convert #ifdef to if() in root.c
x86: apl: Enable SPI flash in TPL with APL_SPI_FLASH_BOOT
x86: apl: Take advantage of the of-platdata parent support
dm: Use driver_info index instead of pointer
dm: Don't allow U_BOOT_DEVICE() when of-platdata is used
dm: doc: Update the of-platadata documentation
arch/sandbox/cpu/spl.c | 14 +-
arch/sandbox/cpu/start.c | 16 +--
arch/sandbox/dts/sandbox.dts | 1 +
arch/sandbox/dts/sandbox.dtsi | 27 ++++
arch/sandbox/include/asm/state.h | 2 +-
arch/x86/cpu/apollolake/Kconfig | 2 +
arch/x86/cpu/apollolake/spl.c | 3 +-
board/sandbox/sandbox.c | 2 +
configs/sandbox_spl_defconfig | 5 +-
doc/driver-model/of-plat.rst | 42 +++---
drivers/clk/clk-uclass.c | 3 +-
drivers/clk/clk_fixed_rate.c | 4 +-
drivers/clk/clk_sandbox.c | 4 +-
drivers/core/Kconfig | 18 ++-
drivers/core/device.c | 23 +++-
drivers/core/lists.c | 70 +++++++++-
drivers/core/root.c | 29 ++--
drivers/core/util.c | 2 +-
drivers/i2c/Makefile | 2 +-
drivers/i2c/i2c-emul-uclass.c | 2 +
drivers/i2c/sandbox_i2c.c | 4 +-
drivers/misc/irq-uclass.c | 2 +-
drivers/misc/p2sb-uclass.c | 27 ++--
drivers/misc/spltest_sandbox.c | 35 -----
drivers/mmc/fsl_esdhc_imx.c | 7 +-
drivers/rtc/rtc-uclass.c | 2 +
drivers/rtc/sandbox_rtc.c | 4 +-
drivers/serial/sandbox.c | 3 +
drivers/spi/ich.c | 4 +-
drivers/sysreset/sysreset_sandbox.c | 2 +
dts/Kconfig | 18 +++
include/asm-generic/global_data.h | 13 ++
include/config_uncmd_spl.h | 1 -
include/dm/device-internal.h | 2 +-
include/dm/device.h | 14 ++
include/dm/platdata.h | 32 ++++-
include/dm/util.h | 2 +-
include/dt-structs.h | 6 +-
test/dm/of_platdata.c | 203 ++++++++++++++++++++++++++++
test/dm/test-main.c | 24 +++-
test/py/tests/test_ofplatdata.py | 47 -------
test/py/tests/test_spl.py | 5 +-
tools/dtoc/dtb_platdata.py | 63 +++++----
tools/dtoc/dtoc_test_simple.dts | 1 +
tools/dtoc/fdt.py | 9 ++
tools/dtoc/test_dtoc.py | 178 ++++++++++++++++--------
tools/dtoc/test_fdt.py | 10 ++
47 files changed, 705 insertions(+), 284 deletions(-)
--
2.28.0.806.g8561365e88-goog
More information about the U-Boot
mailing list