dm: rockchip: sandbox: Add support for compiled-in platform data
Subsystems (9)
v3 cover dm: rockchip: sandbox: Add support for compiled-in platform data
Note: This v3 series adds a test and fixes a few bugs found in generation of of-platdata.
This series provides a way to compile in the contents of a device tree as C code into U-Boot, implementing an idea that Tom Rini came up with. It is intended to deal with extremely tight environments where there is not enough space for the ~3KB device tree code overhead. Examples include SPL where there is only 16KB of available RAM yet a full MMC stack is required.
To provide a reasonable test environment, SPL support is added to sandbox, through a new 'sandbox_spl' target. A new tool 'dtoc' converts device tree data to C code (and structure definitions).
To check its effectiveness for a real application, the v2 series includes support for enabling of-platdata for a rockchip board (firefly-rk3288). The results are as follows:
Code Data u-boot-spl.bin size of-platdata disabled 23159 1624 28864 of-platdata enabled 19093 2616 21761
Overall the saving is 7103 bytes, about 7KB. Approximately 4KB of this comes from removing the device tree data from SPL although this is offset by the size of the of-platdata itself (around 1KB). On top of this effective 3KB reduction, another ~3KB reduction comes from dropping libfdt and a further 1KB from dropping unused setup and driver-model code.
Clearly this approach does have value. Looked at with a favourable light it provides the best of both worlds: configuration using standard device tree bindings without the run-time overhead.
Looking under the hood shows a less rosy picture. Effectively we end up with a new set of C structures which must be handled by the driver. This series suggests a suitable approach for dealing with this (see of-plat.txt) which is workable. However there are a number of serious caveats. See that file for details.
Thsi feature should be used sparingly. Rockchip is to some extent an unusual
case: lots of features (leading to a large SPL device tree size of 4KB), no MMC stack available to SPL from the internal ROM* and a very limited maximum SPL code size. Most SoCs will not benefit from this.
However, for an SoC with very small SRAM where only a few drivers are needed in SPL (such as serial and MMC) then of-platdata could provide a useful benefit, without a significant increase in complexity.
With the v3 series this feature is ready for use. It is available at u-boot-dm/dt-working.
The dtoc tool might be better renamed fdttoc (which is clumsy) or fdt2c. Ideas welcome.
Summary of changes in this series:
- New sandbox_spl board
- Generation of C code from device tree (dtoc tool)
- Conversion of some core driver-model uclasses to support of-platdata
- Conversion of firefly-rk3288 to use of-platdata
- Some minor additions to the test/py framework
* Note that the rockchip internal ROM does include an MMC stack but it only permits loading of data in its own format, outside control of U-Boot.
Changes in v3:
- Rebase to master
- Print out the of-platdata contents for testing
- Update to the new clock API
- Update comments a little
- Add GetEmpty() to obtain an empty/zero value of a given type
- Process the structs in a first pass, to correct bugs in widening
- Fix handling of boolean value (no impact, but it is more correct)
- Enhance widening to handle array size changes
- Don't try to expand when there is no of-platdata
- Add new patch to avoid bringing in the eeprom emulator in SPL
- Rebase to master
- Rebase to master
- Add new patch to handle testing with the sandbox_spl board
- Add new patch to note which console produced unexpected output
- Add new patch to provide a way to get early console output
- Add new patch to start sandbox SPL when enabled
- Add new patch to test of-platdata
- Add a test for of-platdata
Changes in v2:
- Add a comment to the effect that 64-bit machines are not supported
- Add support for rockchip
- Various minor enhancements to the v1 implementation
Simon Glass (62):
sandbox: Don't print a warning for CONFIG_I2C_COMPAT
README: Remove CONFIG_SYS_MALLOC_F_LEN comment
spl: Drop include of i2c.h
Makefile: Allow the SPL final link rule to be overridden
sandbox: Allow chaining from SPL to U-Boot proper
sandbox: Support building an SPL image
sandbox: Correct header file order in cpu.c
sandbox: Add some missing headers in cpu.c
sandbox: Don't use PCI in SPL
sandbox: Don't include the main loop in SPL
sandbox: Add basic SPL implementation
sandbox: Don't use IDE and iotrace in SPL
sandbox: serial: Don't sync video in SPL
sandbox: Add a new sandbox_spl board
sandbox: Add a test device that uses of-platdata
dm: spl: Don't set up device tree with of-platdata
dm: Makefile: Build of-platdata before SPL
dm: core: Don't use device tree with of-platdata
dm: regmap: Add a dummy implementation for of-platdata
dm: syscon: Add support for of-platdata
dm: sandbox: Add a simple driver to test of-platdata
dm: Add a header that provides access to the of-platdata structs
dm: clk: Add support for of-platdata
dm: serial: Add support for of-platdata
dm: Don't include fdtdec functions when of-platdata is enabled
dm: Add an option to enable the of-platdata feature
dm: Add a README for of-platdata
dm: Add a library to provide simple device-tree access
dm: Add a tool to generate C code from a device tree
dm: Makefile: Build of-platdata files when the feature is enabled
dm: Add a more efficient libfdt library
Only build the libfdt python module if 'swig' is available
tiny-printf: Support assert()
dm: spl: Bind in all devices in SPL with of-platdata
dm: core: Rename DM_NAME_ALLOCED to DM_FLAG_NAME_ALLOCED
dtoc: Ignore the u-boot,dm-pre-reloc property
dm: Don't attach the device tree to SPL with of-platdata
dm: core: Expand platdata for of-platdata devices
sandbox: Don't bring in the eeprom emulator in SPL
dm: sandbox: Enable of-platdata for sandbox_spl
dm: core: Move regmap allocation into a separate function
dm: core: Add an implementation of regmap_init_mem_platdata()
dm: serial: ns16550: Update to support of-platdata
rockchip: serial: Add an of-platdata driver for rockchip
rockchip: Update the sdram-channel property to support of-platdata
rockchip: mmc: Move all DT decoding to ofdata_to_platdata()
rockchip: mmc: Update the driver to support of-platdata
rockchip: clk: Move all DT decoding to ofdata_to_platdata()
rockchip: clk: Update the rk3288 driver to support of-platdata
rockchip: pinctrl: Update the rk3288 driver to support of-platdata
rockchip: Move the MMC setup check earlier
rockchip: Don't use spl_boot_device() with of-platdata
rockchip: syscon: Update to work with of-platdata
rockchip: sdram: Move all DT decoding to ofdata_to_platdata()
rockchip: sdram: Update the driver to support of-platdata
rockchip: Use of-platdata for firefly-rk3288
test/py: Handle testing with the sandbox_spl board test/py: Note which console produced unexpected output test/py: Provide a way to get early console output test/py: Start sandbox SPL when enabled
dm: Add a test for of-platdata
dm: Update the of-platdata README for the new features
Makefile | 5 +- README | 3 - arch/arm/dts/rk3288-firefly.dts | 3 +- arch/arm/include/asm/arch-rockchip/sdram.h | 14 +- arch/arm/mach-rockchip/rk3288-board-spl.c | 25 +- arch/arm/mach-rockchip/rk3288/sdram_rk3288.c | 130 +++++++-- arch/arm/mach-rockchip/rk3288/syscon_rk3288.c | 38 +++ arch/sandbox/Kconfig | 7 +- arch/sandbox/config.mk | 5 + arch/sandbox/cpu/Makefile | 1 + arch/sandbox/cpu/cpu.c | 6 +- arch/sandbox/cpu/os.c | 51 ++++ arch/sandbox/cpu/spl.c | 68 +++++ arch/sandbox/cpu/start.c | 2 + arch/sandbox/cpu/u-boot-spl.lds | 24 ++ arch/sandbox/dts/sandbox.dts | 31 ++ arch/sandbox/include/asm/spl.h | 23 ++ arch/sandbox/lib/Makefile | 2 + board/sandbox/MAINTAINERS | 7 + common/spl/spl.c | 6 +- configs/firefly-rk3288_defconfig | 3 + configs/sandbox_spl_defconfig | 183 ++++++++++++ doc/driver-model/of-plat.txt | 310 ++++++++++++++++++++ drivers/clk/clk-uclass.c | 22 +- drivers/clk/clk_fixed_rate.c | 2 + drivers/clk/clk_rk3288.c | 33 ++- drivers/core/device-remove.c | 2 +- drivers/core/device.c | 47 ++- drivers/core/lists.c | 2 +- drivers/core/regmap.c | 57 +++- drivers/core/root.c | 4 +- drivers/core/syscon-uclass.c | 13 + drivers/misc/Makefile | 7 + drivers/misc/spltest_sandbox.c | 53 ++++ drivers/mmc/rockchip_dw_mmc.c | 59 ++-- drivers/pinctrl/rockchip/pinctrl_rk3288.c | 8 +- drivers/serial/Kconfig | 9 + drivers/serial/Makefile | 3 + drivers/serial/ns16550.c | 4 +- drivers/serial/sandbox.c | 2 + drivers/serial/serial-uclass.c | 8 +- drivers/serial/serial_rockchip.c | 43 +++ dts/Kconfig | 21 ++ include/clk.h | 4 + include/configs/sandbox.h | 4 + include/configs/sandbox_spl.h | 20 ++ include/dm/device.h | 6 +- include/dm/platdata.h | 5 + include/dt-structs.h | 19 ++ include/os.h | 25 ++ include/regmap.h | 16 ++ include/syscon.h | 11 + lib/Makefile | 5 +- lib/libfdt/libfdt.swig | 89 ++++++ lib/libfdt/setup.py | 38 +++ lib/libfdt/test_libfdt.py | 14 + lib/tiny-printf.c | 9 + scripts/Makefile.host | 9 +- scripts/Makefile.spl | 47 ++- test/py/conftest.py | 2 +- test/py/tests/test_ofplatdata.py | 42 +++ test/py/u_boot_console_base.py | 12 +- test/py/u_boot_console_sandbox.py | 6 +- test/py/u_boot_spawn.py | 13 + tools/Makefile | 14 + tools/dtoc/.gitignore | 1 + tools/dtoc/dtoc | 1 + tools/dtoc/dtoc.py | 394 ++++++++++++++++++++++++++ tools/dtoc/fdt.py | 180 ++++++++++++ tools/dtoc/fdt_fallback.py | 207 ++++++++++++++ tools/dtoc/fdt_util.py | 86 ++++++ 71 files changed, 2495 insertions(+), 130 deletions(-) create mode 100644 arch/sandbox/cpu/spl.c create mode 100644 arch/sandbox/cpu/u-boot-spl.lds create mode 100644 arch/sandbox/include/asm/spl.h create mode 100644 configs/sandbox_spl_defconfig create mode 100644 doc/driver-model/of-plat.txt create mode 100644 drivers/misc/spltest_sandbox.c create mode 100644 drivers/serial/serial_rockchip.c create mode 100644 include/configs/sandbox_spl.h create mode 100644 include/dt-structs.h create mode 100644 lib/libfdt/libfdt.swig create mode 100644 lib/libfdt/setup.py create mode 100644 lib/libfdt/test_libfdt.py create mode 100644 test/py/tests/test_ofplatdata.py create mode 100644 tools/dtoc/.gitignore create mode 120000 tools/dtoc/dtoc create mode 100755 tools/dtoc/dtoc.py create mode 100644 tools/dtoc/fdt.py create mode 100644 tools/dtoc/fdt_fallback.py create mode 100644 tools/dtoc/fdt_util.py
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 1/62 sandbox: Don't print a warning for CONFIG_I2C_COMPAT
Sandbox includes this code to provide build coverage. While we retain this feature we should have sandbox build it. Sandbox does not in fact use the I2C compatibility mode. Showing a warning for sandbox is just confusing, since no conversion is expected.
Drop the warning for sandbox.
---
Changes in v3: None
Changes in v2: None
Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -801,7 +801,7 @@ quiet_cmd_pad_cat = CAT $@ cmd_pad_cat = $(cmd_objcopy) && $(append) || rm -f $@ all: $(ALL-y) -ifeq ($(CONFIG_DM_I2C_COMPAT),y) +ifeq ($(CONFIG_DM_I2C_COMPAT)$(CONFIG_SANDBOX),y) @echo "===================== WARNING ======================" @echo "This board uses CONFIG_DM_I2C_COMPAT. Please remove" @echo "(possibly in a subsequent patch in your series)"
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 1/62 sandbox: Don't print a warning for CONFIG_I2C_COMPAT
Quoted 7 lines · Simon Glass
Sandbox includes this code to provide build coverage. While we retain this feature we should have sandbox build it. Sandbox does not in fact use the I2C compatibility mode. Showing a warning for sandbox is just confusing, since no conversion is expected.
Drop the warning for sandbox.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: NoneMakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 2/62 README: Remove CONFIG_SYS_MALLOC_F_LEN comment
In reply to Simon GlassThis option is now widely available, so remove the comment that it is only available on ARM and sandbox.
---
Changes in v3: None
Changes in v2: None
README | 3 --- 1 file changed, 3 deletions(-)
README +0 -3
@@ -3835,9 +3835,6 @@ Configuration Settings: The memory will be freed (or in fact just forgotten) when U-Boot relocates itself. - Pre-relocation malloc() is only supported on ARM and sandbox - at present but is fairly easy to enable for other archs. - - CONFIG_SYS_MALLOC_SIMPLE Provides a simple and small malloc() and calloc() for those boards which do not use the full malloc in SPL (which is
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 2/62 README: Remove CONFIG_SYS_MALLOC_F_LEN comment
Quoted 11 lines · Simon Glass
This option is now widely available, so remove the comment that it is only available on ARM and sandbox.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: NoneREADME | 3 --- 1 file changed, 3 deletions(-)
Applied to u-boot-dm
PATCH v3 3/62 spl: Drop include of i2c.h
In reply to Simon GlassThis file does not appear to use I2C, so drop this include.
---
Changes in v3: None
Changes in v2: None
common/spl/spl.c | 1 - 1 file changed, 1 deletion(-)
common/spl/spl.c +0 -1
@@ -13,7 +13,6 @@#include <nand.h> #include <fat.h> #include <version.h> -#include <i2c.h> #include <image.h> #include <malloc.h> #include <dm/root.h>
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 3/62 spl: Drop include of i2c.h
Quoted 10 lines · Simon Glass
This file does not appear to use I2C, so drop this include.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonecommon/spl/spl.c | 1 - 1 file changed, 1 deletion(-)
Applied to u-boot-dm
PATCH v3 4/62 Makefile: Allow the SPL final link rule to be overridden
In reply to Simon GlassOverriding the final link rule is possible with U-Boot proper. It us used to create a sandbox image links with host libraries. To build a sandbox SPL image we need the same feature for SPL.
To support this, update the SPL link rule so sandbox can override it.
---
Changes in v3: None
Changes in v2: None
scripts/Makefile.spl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
scripts/Makefile.spl +4 -2
@@ -241,8 +241,10 @@ cmd_mksunxiboot = $(objtree)/tools/mksunxiboot $< $@ $(obj)/sunxi-spl.bin: $(obj)/$(SPL_BIN).bin FORCE $(call if_changed,mksunxiboot) -quiet_cmd_u-boot-spl = LD $@ - cmd_u-boot-spl = (cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \ +# Rule to link u-boot-spl +# May be overridden by arch/$(ARCH)/config.mk +quiet_cmd_u-boot-spl ?= LD $@ + cmd_u-boot-spl ?= (cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \ $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \ $(patsubst $(obj)/%,%,$(u-boot-spl-main)) --end-group \ $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN))
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 4/62 Makefile: Allow the SPL final link rule to be overridden
Quoted 6 lines · Simon Glass
Overriding the final link rule is possible with U-Boot proper. It us used to create a sandbox image links with host libraries. To build a sandbox SPL image we need the same feature for SPL.
To support this, update the SPL link rule so sandbox can override it.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonescripts/Makefile.spl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Applied to u-boot-dm
PATCH v3 5/62 sandbox: Allow chaining from SPL to U-Boot proper
In reply to Simon GlassSPL is expected to load and run U-Boot. This needs to work with sandbox also. Provide a function to locate the U-Boot image, and another to start it. This allows SPL to function on sandbox as it does on other archs.
---
Changes in v3: None
Changes in v2: None
arch/sandbox/cpu/os.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/os.h | 25 +++++++++++++++++++++++++ 2 files changed, 76 insertions(+)
arch/sandbox/cpu/os.c +51 -0
@@ -541,6 +541,57 @@ int os_jump_to_image(const void *dest, int size)return unlink (fname); } +int os_find_u_boot (char *fname,int maxlen) +{ +struct sandbox_state *state =state_get_current (); +const char *progname = state->argv[0 ]; +int len =strlen (progname); +char *p; +int fd; + +if (len >= maxlen || len <4 ) +return -ENOSPC ; + +/* Look for 'u-boot' in the same directory as 'u-boot-spl' */ +strcpy (fname, progname); +if (!strcmp (fname + len -4 ,"-spl" )) { + fname[len -4 ] ='\0' ; + fd =os_open (fname,O_RDONLY ); +if (fd >=0 ) { +close (fd); +return 0 ; + } + } + +/* Look for 'u-boot' in the parent directory of spl/ */ + p =strstr (fname,"/spl/" ); +if (p) { +strcpy (p, p +4 ); + fd =os_open (fname,O_RDONLY ); +if (fd >=0 ) { +close (fd); +return 0 ; + } + } + +return -ENOENT ; +} + +int os_spl_to_uboot (const char *fname) +{ +struct sandbox_state *state =state_get_current (); +char *argv[state->argc +1 ]; +int ret; + +memcpy (argv, state->argv,sizeof (char *) * (state->argc +1 )); + argv[0 ] = (char *)fname; + ret =execv (fname, argv); +if (ret) +return ret; + +return unlink (fname); +} +void os_localtime (struct rtc_time *rt) {time_t t =time (NULL );
include/os.h +25 -0
@@ -287,6 +287,31 @@ int os_read_ram_buf(const char *fname);int os_jump_to_image (const void *dest,int size);/** +* os_find_u_boot() - Determine the path to U-Boot proper +* +* This function is intended to be called from within sandbox SPL. It uses +* a few heuristics to find U-Boot proper. Normally it is either in the same +* directory, or the directory above (since u-boot-spl is normally in an +* spl/ subdirectory when built). +* +* @fname: Place to put full path to U-Boot +* @maxlen: Maximum size of @fname +* @return 0 if OK, -NOSPC if the filename is too large, -ENOENT if not found +*/ +int os_find_u_boot (char *fname,int maxlen); + +/** +* os_spl_to_uboot() - Run U-Boot proper +* +* When called from SPL, this runs U-Boot proper. The filename is obtained by +* calling os_find_u_boot(). +* +* @fname: Full pathname to U-Boot executable +* @return 0 if OK, -ve on error +*/ +int os_spl_to_uboot (const char *fname); + +/** * Read the current system time * * This reads the current Local Time and places it into the provided
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 5/62 sandbox: Allow chaining from SPL to U-Boot proper
Quoted 5 lines · Simon Glass
SPL is expected to load and run U-Boot. This needs to work with sandbox also. Provide a function to locate the U-Boot image, and another to start it. This allows SPL to function on sandbox as it does on other archs.
Signed-off-by Simon Glass <[email protected]>
Quoted 8 lines
---
Changes in v3: None
Changes in v2: Nonearch/sandbox/cpu/os.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/os.h | 25 +++++++++++++++++++++++++ 2 files changed, 76 insertions(+)
Applied to u-boot-dm
PATCH v3 6/62 sandbox: Support building an SPL image
In reply to Simon GlassWhen building an SPL image, override the link flags so that it uses the system libraries. This is similar to the way the non-SPL image is built.
---
Changes in v3: None
Changes in v2: None
arch/sandbox/config.mk | 5 +++++ 1 file changed, 5 insertions(+)
arch/sandbox/config.mk +5 -0
@@ -20,4 +20,9 @@ cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds \ -Wl,--start-group $(u-boot-main) -Wl,--end-group \ $(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map +cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \ + -Wl,--start-group $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \ + $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) -Wl,--end-group \ + $(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot-spl.map -Wl,--gc-sections) + CONFIG_ARCH_DEVICE_TREE := sandbox
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 6/62 sandbox: Support building an SPL image
Quoted 11 lines · Simon Glass
When building an SPL image, override the link flags so that it uses the system libraries. This is similar to the way the non-SPL image is built.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/sandbox/config.mk | 5 +++++ 1 file changed, 5 insertions(+)
Applied to u-boot-dm
PATCH v3 7/62 sandbox: Correct header file order in cpu.c
In reply to Simon GlassThe dm/ file should go at the end. Move it.
---
Changes in v3: None
Changes in v2: None
arch/sandbox/cpu/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sandbox/cpu/cpu.c +1 -1
@@ -4,10 +4,10 @@*/ #define DEBUG #include <common.h> -#include <dm/root.h> #include <os.h> #include <asm/io.h> #include <asm/state.h> +#include <dm/root.h> DECLARE_GLOBAL_DATA_PTR ;
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 7/62 sandbox: Correct header file order in cpu.c
Quoted 10 lines · Simon Glass
The dm/ file should go at the end. Move it.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/sandbox/cpu/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 8/62 sandbox: Add some missing headers in cpu.c
In reply to Simon GlassThese headers are needed in case they are not transitively included.
---
Changes in v3: None
Changes in v2: None
arch/sandbox/cpu/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
arch/sandbox/cpu/cpu.c +2 -0
@@ -4,6 +4,8 @@*/ #define DEBUG #include <common.h> +#include <errno.h> +#include <libfdt.h> #include <os.h> #include <asm/io.h> #include <asm/state.h>
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 8/62 sandbox: Add some missing headers in cpu.c
Quoted 10 lines · Simon Glass
These headers are needed in case they are not transitively included.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/sandbox/cpu/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
Applied to u-boot-dm
PATCH v3 9/62 sandbox: Don't use PCI in SPL
In reply to Simon GlassPCI is not supported in SPL for sandbox, so avoid using it.
---
Changes in v3: None
Changes in v2: None
arch/sandbox/cpu/cpu.c | 2 +- arch/sandbox/lib/Makefile | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
arch/sandbox/cpu/cpu.c +1 -1
@@ -57,7 +57,7 @@ int cleanup_before_linux_select(int flags)void *map_physmem (phys_addr_t paddr,unsigned long len,unsigned long flags) { -#ifdef CONFIG_PCI +#if defined(CONFIG_PCI ) && !defined(CONFIG_SPL_BUILD )unsigned long plen = len;void *ptr;
arch/sandbox/lib/Makefile +2 -0
@@ -8,5 +8,7 @@ # obj-y += interrupts.o +ifndef CONFIG_SPL_BUILD obj-$(CONFIG_PCI) += pci_io.o +endif obj-$(CONFIG_CMD_BOOTM) += bootm.o
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 9/62 sandbox: Don't use PCI in SPL
Quoted 11 lines · Simon Glass
PCI is not supported in SPL for sandbox, so avoid using it.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/sandbox/cpu/cpu.c | 2 +- arch/sandbox/lib/Makefile | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 10/62 sandbox: Don't include the main loop in SPL
In reply to Simon GlassSPL does not have a command interface so we should not include the main loop code.
---
Changes in v3: None
Changes in v2: None
arch/sandbox/cpu/start.c | 2 ++ 1 file changed, 2 insertions(+)
arch/sandbox/cpu/start.c +2 -0
@@ -73,6 +73,7 @@ static int sandbox_cmdline_cb_help(struct sandbox_state *state, const char *arg) }SANDBOX_CMDLINE_OPT_SHORT (help,'h' ,0 ,"Display help" ); +#ifndef CONFIG_SPL_BUILD int sandbox_main_loop_init (void ) {struct sandbox_state *state =state_get_current ();
@@ -97,6 +98,7 @@ int sandbox_main_loop_init(void) return 0; } +#endif static int sandbox_cmdline_cb_boot (struct sandbox_state *state,const char *arg)
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 10/62 sandbox: Don't include the main loop in SPL
Quoted 11 lines · Simon Glass
SPL does not have a command interface so we should not include the main loop code.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/sandbox/cpu/start.c | 2 ++ 1 file changed, 2 insertions(+)
Applied to u-boot-dm
PATCH v3 11/62 sandbox: Add basic SPL implementation
In reply to Simon GlassAdd an sandbox implementation for the generic SPL framework. This supports locating and running U-Boot proper.
---
Changes in v3: None
Changes in v2: None
arch/sandbox/cpu/Makefile | 1 + arch/sandbox/cpu/spl.c | 51 ++++++++++++++++++++++++++++++++++++++++++ arch/sandbox/include/asm/spl.h | 23 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 arch/sandbox/cpu/spl.c create mode 100644 arch/sandbox/include/asm/spl.h
arch/sandbox/cpu/Makefile +1 -0
@@ -8,6 +8,7 @@ # obj-y := cpu.o os.o start.o state.o +obj-$(CONFIG_SPL_BUILD) += spl.o obj-$(CONFIG_ETH_SANDBOX_RAW) += eth-raw-os.o obj-$(CONFIG_SANDBOX_SDL) += sdl.o
arch/sandbox/cpu/spl.c new file +51 -0
51 lines not on this page · raw message
arch/sandbox/include/asm/spl.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Copyright (c) 2016 Google, Inc +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __asm_spl_h +#define __asm_spl_h + +#define CONFIG_SPL_BOARD_LOAD_IMAGE + +/** +* Board-specific load method for boards that have a special way of loading +* U-Boot, which does not fit with the existing SPL code. +* +* @return 0 on success, negative errno value on failure. +*/ +int spl_board_load_image (void ); + +enum { +BOOT_DEVICE_BOARD , +}; + +#endif
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 11/62 sandbox: Add basic SPL implementation
Quoted 9 lines · Simon Glass
Add an sandbox implementation for the generic SPL framework. This supports locating and running U-Boot proper.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: None
Quoted 6 lines
arch/sandbox/cpu/Makefile | 1 + arch/sandbox/cpu/spl.c | 51 ++++++++++++++++++++++++++++++++++++++++++ arch/sandbox/include/asm/spl.h | 23 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 arch/sandbox/cpu/spl.c create mode 100644 arch/sandbox/include/asm/spl.h
Applied to u-boot-dm
PATCH v3 12/62 sandbox: Don't use IDE and iotrace in SPL
In reply to Simon GlassThese functions are not supported in SPL, so drop them.
---
Changes in v3: None
Changes in v2: None
include/configs/sandbox.h | 4 ++++ 1 file changed, 4 insertions(+)
include/configs/sandbox.h +4 -0
@@ -16,8 +16,10 @@#endif +#ifndef CONFIG_SPL_BUILD #define CONFIG_IO_TRACE #define CONFIG_CMD_IOTRACE +#endif #ifndef CONFIG_TIMER #define CONFIG_SYS_TIMER_RATE 1000000
@@ -192,6 +194,7 @@#define CONFIG_CMD_LZMADEC #define CONFIG_CMD_DATE +#ifndef CONFIG_SPL_BUILD #define CONFIG_CMD_IDE #define CONFIG_SYS_IDE_MAXBUS 1#define CONFIG_SYS_ATA_IDE0_OFFSET 0
@@ -201,6 +204,7 @@#define CONFIG_SYS_ATA_REG_OFFSET 1#define CONFIG_SYS_ATA_ALT_OFFSET 2#define CONFIG_SYS_ATA_STRIDE 4 +#endif #define CONFIG_SCSI #define CONFIG_SCSI_AHCI_PLAT
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 12/62 sandbox: Don't use IDE and iotrace in SPL
Quoted 10 lines · Simon Glass
These functions are not supported in SPL, so drop them.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Noneinclude/configs/sandbox.h | 4 ++++ 1 file changed, 4 insertions(+)
Applied to u-boot-dm
PATCH v3 13/62 sandbox: serial: Don't sync video in SPL
In reply to Simon GlassSPL does not support an LCD display so there is no need to sync the video when there is serial output.
---
Changes in v3: None
Changes in v2: None
drivers/serial/sandbox.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/serial/sandbox.c +2 -0
@@ -115,7 +115,9 @@ static int sandbox_serial_pending(struct udevice *dev, bool input)return 0 ;os_usleep (100 ); +#ifndef CONFIG_SPL_BUILD video_sync_all (); +#endif if (next_index == serial_buf_read)return 1 ;/* buffer full */
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 13/62 sandbox: serial: Don't sync video in SPL
Quoted 11 lines · Simon Glass
SPL does not support an LCD display so there is no need to sync the video when there is serial output.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/serial/sandbox.c | 2 ++ 1 file changed, 2 insertions(+)
Applied to u-boot-dm
PATCH v3 14/62 sandbox: Add a new sandbox_spl board
In reply to Simon GlassIt is useful to be able to build SPL for sandbox. It provides additional build coverage and allows SPL features to be tested in sandbox. However it does not need worthwhile to always create an SPL build. It nearly doubles the build time and the feature is (so far) seldom used.
So for now, create a separate build target for sandbox SPL. This allows experimentation with this new feature without impacting existing workflows.
---
Changes in v3:
- Rebase to master
Changes in v2: None
arch/sandbox/Kconfig | 7 +- arch/sandbox/cpu/u-boot-spl.lds | 24 ++++++ board/sandbox/MAINTAINERS | 7 ++ configs/sandbox_spl_defconfig | 182 ++++++++++++++++++++++++++++++++++++++++ include/configs/sandbox_spl.h | 18 ++++ 5 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 arch/sandbox/cpu/u-boot-spl.lds create mode 100644 configs/sandbox_spl_defconfig create mode 100644 include/configs/sandbox_spl.h
arch/sandbox/Kconfig +6 -1
@@ -10,8 +10,13 @@ config SYS_BOARD config SYS_CPU default "sandbox" +config SANDBOX_SPL + bool "Enable SPL for sandbox" + select SUPPORT_SPL + config SYS_CONFIG_NAME - default "sandbox" + default "sandbox_spl" if SANDBOX_SPL + default "sandbox" if !SANDBOX_SPL config PCI bool "PCI support"
arch/sandbox/cpu/u-boot-spl.lds new file +24 -0
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2011-2012 The Chromium OS Authors. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +SECTIONS +{ + + . = ALIGN(4); + .u_boot_list : { + KEEP(*(SORT(.u_boot_list*))); + } + + __u_boot_sandbox_option_start = .; + _u_boot_sandbox_getopt : { *(.u_boot_sandbox_getopt) } + __u_boot_sandbox_option_end = .; + + __bss_start = .; +} + +INSERT BEFORE .data;
board/sandbox/MAINTAINERS +7 -0
@@ -11,3 +11,10 @@ S: Maintained F: board/sandbox/ F: include/configs/sandbox.h F: configs/sandbox_noblk_defconfig + +SANDBOX SPL BOARD +M: Simon Glass <[email protected]> +S: Maintained +F: board/sandbox/ +F: include/configs/sandbox_spl.h +F: configs/sandbox_spl_defconfig
configs/sandbox_spl_defconfig new file +182 -0
182 lines not on this page · raw message
include/configs/sandbox_spl.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Copyright (c) 2016 Google, Inc +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __SANDBOX_SPL_CONFIG_H +#define __SANDBOX_SPL_CONFIG_H + +#include <configs/sandbox.h> + +#define CONFIG_SPL_DRIVERS_MISC_SUPPORT +#define CONFIG_SPL_ENV_SUPPORT +#define CONFIG_SPL_FRAMEWORK +#define CONFIG_SPL_LIBCOMMON_SUPPORT +#define CONFIG_SPL_LIBGENERIC_SUPPORT +#define CONFIG_SPL_SERIAL_SUPPORT + +#endif
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 14/62 sandbox: Add a new sandbox_spl board
Quoted 16 lines · Simon Glass
It is useful to be able to build SPL for sandbox. It provides additional build coverage and allows SPL features to be tested in sandbox. However it does not need worthwhile to always create an SPL build. It nearly doubles the build time and the feature is (so far) seldom used.
So for now, create a separate build target for sandbox SPL. This allows experimentation with this new feature without impacting existing workflows.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Rebase to masterChanges in v2: None
Quoted 9 lines
arch/sandbox/Kconfig | 7 +- arch/sandbox/cpu/u-boot-spl.lds | 24 ++++++ board/sandbox/MAINTAINERS | 7 ++ configs/sandbox_spl_defconfig | 182 ++++++++++++++++++++++++++++++++++++++++ include/configs/sandbox_spl.h | 18 ++++ 5 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 arch/sandbox/cpu/u-boot-spl.lds create mode 100644 configs/sandbox_spl_defconfig create mode 100644 include/configs/sandbox_spl.h
Applied to u-boot-dm
PATCH v3 15/62 sandbox: Add a test device that uses of-platdata
In reply to Simon GlassStart up the test devices. These print out of-platdata contents, providing a check that the of-platdata feature is working correctly.
The device-tree changes are made to sandbox.dts rather than test.dts. since the former controls the of-platdata generation.
---
Changes in v3: None
Changes in v2: None
arch/sandbox/cpu/spl.c | 17 +++++++++++++++++ arch/sandbox/dts/sandbox.dts | 31 +++++++++++++++++++++++++++++++ include/configs/sandbox_spl.h | 2 ++ 3 files changed, 50 insertions(+)
arch/sandbox/cpu/spl.c +17 -0
@@ -6,6 +6,7 @@#include <common.h> #include <dm.h> #include <os.h> +#include <spl.h> #include <asm/spl.h> #include <asm/state.h>
@@ -49,3 +50,19 @@ int spl_board_load_image(void)/* Hopefully this will not return */ return os_spl_to_uboot (fname); } + +void spl_board_init (void ) +{ +struct udevice *dev; + +preloader_console_init (); + +/* +* Scan all the devices so that we can output their platform data. See +* sandbox_spl_probe(). +*/ +for (uclass_first_device (UCLASS_MISC , &dev); + dev; +uclass_next_device (&dev)) + ; +}
arch/sandbox/dts/sandbox.dts +31 -0
@@ -172,6 +172,37 @@ }; }; + spl-test { + u-boot,dm-pre-reloc; + compatible = "sandbox,spl-test"; + boolval; + intval = <1>; + intarray = <2 3 4>; + byteval = [05]; + bytearray = [06]; + longbytearray = [09 0a 0b 0c 0d 0e 0f 10 11]; + stringval = "message"; + stringarray = "multi-word", "message"; + }; + + spl-test2 { + u-boot,dm-pre-reloc; + compatible = "sandbox,spl-test"; + intval = <3>; + intarray = <5>; + byteval = [08]; + bytearray = [01 23 34]; + longbytearray = [09 0a 0b 0c]; + stringval = "message2"; + stringarray = "another", "multi-word", "message"; + }; + + spl-test3 { + u-boot,dm-pre-reloc; + compatible = "sandbox,spl-test"; + stringarray = "one"; + }; + square { compatible = "demo-shape"; colour = "blue";
include/configs/sandbox_spl.h +2 -0
@@ -8,6 +8,8 @@#include <configs/sandbox.h> +#define CONFIG_SPL_BOARD_INIT +#define CONFIG_SPL_DRIVERS_MISC_SUPPORT #define CONFIG_SPL_ENV_SUPPORT #define CONFIG_SPL_FRAMEWORK
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 15/62 sandbox: Add a test device that uses of-platdata
Quoted 9 lines · Simon Glass
Start up the test devices. These print out of-platdata contents, providing a check that the of-platdata feature is working correctly.
The device-tree changes are made to
sandbox.dtsrather thantest.dts. since the former controls the of-platdata generation.Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v3: None
Changes in v2: Nonearch/sandbox/cpu/spl.c | 17 +++++++++++++++++ arch/sandbox/dts/sandbox.dts | 31 +++++++++++++++++++++++++++++++ include/configs/sandbox_spl.h | 2 ++ 3 files changed, 50 insertions(+)
Applied to u-boot-dm
PATCH v3 16/62 dm: spl: Don't set up device tree with of-platdata
In reply to Simon GlassWhen this feature is enabled, we should not access the device tree.
---
Changes in v3: None
Changes in v2: None
common/spl/spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/spl/spl.c +1 -1
@@ -202,7 +202,7 @@ int spl_init(void) gd->malloc_limit =CONFIG_SYS_MALLOC_F_LEN ; gd->malloc_ptr =0 ;#endif -if (CONFIG_IS_ENABLED (OF_CONTROL )) { +if (CONFIG_IS_ENABLED (OF_CONTROL ) && !CONFIG_IS_ENABLED (OF_PLATDATA )) { ret =fdtdec_setup ();if (ret) {debug ("fdtdec_setup() returned error %d\n" , ret);
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 16/62 dm: spl: Don't set up device tree with of-platdata
Quoted 10 lines · Simon Glass
When this feature is enabled, we should not access the device tree.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonecommon/spl/spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 17/62 dm: Makefile: Build of-platdata before SPL
In reply to Simon GlassSince SPL needs the of-platdata structures, build these before starting to build any SPL components.
---
Changes in v3: None
Changes in v2: None
Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Makefile +2 -1
@@ -1318,7 +1318,8 @@ u-boot.lds: $(LDSCRIPT) prepare FORCE spl/u-boot-spl.bin: spl/u-boot-spl @: -spl/u-boot-spl: tools prepare $(if $(CONFIG_OF_SEPARATE),dts/dt.dtb) +spl/u-boot-spl: tools prepare \ + $(if $(CONFIG_OF_SEPARATE)$(CONFIG_SPL_OF_PLATDATA),dts/dt.dtb) $(Q)$(MAKE) obj=spl -f $(srctree)/scripts/Makefile.spl all spl/sunxi-spl.bin: spl/u-boot-spl
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 17/62 dm: Makefile: Build of-platdata before SPL
Quoted 11 lines · Simon Glass
Since SPL needs the of-platdata structures, build these before starting to build any SPL components.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: NoneMakefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 18/62 dm: core: Don't use device tree with of-platdata
In reply to Simon GlassWhen CONFIG_SPL_OF_PLATDATA is enabled we should not access the device tree. Remove all references to this in the core driver-model code.
---
Changes in v3: None
Changes in v2: None
drivers/core/device.c | 2 +- drivers/core/lists.c | 2 +- drivers/core/root.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/core/device.c +1 -1
@@ -607,7 +607,7 @@ const char *dev_get_uclass_name(struct udevice *dev)fdt_addr_t dev_get_addr_index (struct udevice *dev,int index) { -#if CONFIG_IS_ENABLED (OF_CONTROL ) +#if CONFIG_IS_ENABLED (OF_CONTROL ) && !CONFIG_IS_ENABLED (OF_PLATDATA )fdt_addr_t addr;if (CONFIG_IS_ENABLED (OF_TRANSLATE )) {
drivers/core/lists.c +1 -1
@@ -99,7 +99,7 @@ int device_bind_driver_to_node(struct udevice *parent, const char *drv_name,return 0 ; } -#if CONFIG_IS_ENABLED (OF_CONTROL ) +#if CONFIG_IS_ENABLED (OF_CONTROL ) && !CONFIG_IS_ENABLED (OF_PLATDATA )/** * driver_check_compatible() - Check if a driver is compatible with this node *
drivers/core/root.c +2 -2
@@ -188,7 +188,7 @@ int dm_scan_platdata(bool pre_reloc_only)return ret; } -#if CONFIG_IS_ENABLED (OF_CONTROL ) +#if CONFIG_IS_ENABLED (OF_CONTROL ) && !CONFIG_IS_ENABLED (OF_PLATDATA )int dm_scan_fdt_node (struct udevice *parent,const void *blob,int offset,bool pre_reloc_only) {
@@ -244,7 +244,7 @@ int dm_init_and_scan(bool pre_reloc_only)return ret; } -if (CONFIG_IS_ENABLED (OF_CONTROL )) { +if (CONFIG_IS_ENABLED (OF_CONTROL ) && !CONFIG_IS_ENABLED (OF_PLATDATA )) { ret =dm_scan_fdt (gd->fdt_blob, pre_reloc_only);if (ret) {debug ("dm_scan_fdt() failed: %d\n" , ret);
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 18/62 dm: core: Don't use device tree with of-platdata
Quoted 6 lines · Simon Glass
When
CONFIG_SPL_OF_PLATDATAis enabled we should not access the device tree. Remove all references to this in the core driver-model code.Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v3: None
Changes in v2: Nonedrivers/core/device.c | 2 +- drivers/core/lists.c | 2 +- drivers/core/root.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
Applied to u-boot-dm
PATCH v3 19/62 dm: regmap: Add a dummy implementation for of-platdata
In reply to Simon GlassAdd a placeholder for now so that this code will compile. It currently does nothing.
---
Changes in v3: None
Changes in v2: None
drivers/core/regmap.c | 9 +++++++++ include/regmap.h | 3 +++ 2 files changed, 12 insertions(+)
drivers/core/regmap.c +9 -0
@@ -15,6 +15,14 @@DECLARE_GLOBAL_DATA_PTR ; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +int regmap_init_mem_platdata (struct udevice *dev,fdt32_t *reg,int size, +struct regmap **mapp) +{ +/* TODO(sjg at chromium.org): Implement this when needed */ +return 0 ; +} +#else int regmap_init_mem (struct udevice *dev,struct regmap **mapp) {const void *blob = gd->fdt_blob;
@@ -64,6 +72,7 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp) return 0; } +#endif void *regmap_get_range (struct regmap *map,unsigned int range_num) {
include/regmap.h +3 -0
@@ -56,6 +56,9 @@ int regmap_read(struct regmap *map, uint offset, uint *valp);*/ int regmap_init_mem (struct udevice *dev,struct regmap **mapp); +int regmap_init_mem_platdata (struct udevice *dev,fdt32_t *reg,int size, +struct regmap **mapp); +/** * regmap_get_range() - Obtain the base memory address of a regmap range *
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 19/62 dm: regmap: Add a dummy implementation for of-platdata
Quoted 4 lines · Simon Glass
Add a placeholder for now so that this code will compile. It currently does nothing.
Signed-off-by Simon Glass <[email protected]>
Quoted 8 lines
---
Changes in v3: None
Changes in v2: Nonedrivers/core/regmap.c | 9 +++++++++ include/regmap.h | 3 +++ 2 files changed, 12 insertions(+)
Applied to u-boot-dm
PATCH v3 20/62 dm: syscon: Add support for of-platdata
In reply to Simon GlassProvide a new function which can cope with obtaining information from of-platdata instead of the device tree.
---
Changes in v3: None
Changes in v2:
- Add a comment to the effect that 64-bit machines are not supported
drivers/core/syscon-uclass.c | 13 +++++++++++++ include/syscon.h | 11 +++++++++++ 2 files changed, 24 insertions(+)
drivers/core/syscon-uclass.c +13 -0
@@ -29,7 +29,20 @@ static int syscon_pre_probe(struct udevice *dev) {struct syscon_uc_info *priv =dev_get_uclass_priv (dev); +/* +* With OF_PLATDATA we really have no way of knowing the format of +* the device-specific platform data. So we assume that it starts with +* a 'reg' member, and this holds a single address and size. Drivers +* using OF_PLATDATA will need to ensure that this is true. +*/ +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +struct syscon_base_platdata *plat =dev_get_platdata (dev); + +return regmap_init_mem_platdata (dev, plat->reg,ARRAY_SIZE (plat->reg), + &priv->regmap); +#else return regmap_init_mem (dev, &priv->regmap); +#endif }int syscon_get_by_driver_data (ulong driver_data,struct udevice **devp)
include/syscon.h +11 -0
@@ -23,6 +23,17 @@ struct syscon_ops {#define syscon_get_ops (dev) ((struct syscon_ops *)(dev)->driver->ops) +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +/* +* We don't support 64-bit machines. If they are so resource-contrained that +* they need to use OF_PLATDATA, something is horribly wrong with the +* education of our hardware engineers. +*/ +struct syscon_base_platdata { +u32 reg[2 ]; +}; +#endif +/** * syscon_get_regmap() - Get access to a register map *
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 20/62 dm: syscon: Add support for of-platdata
Quoted 6 lines · Simon Glass
Provide a new function which can cope with obtaining information from of-platdata instead of the device tree.
Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v3: None
Changes in v2:
- Add a comment to the effect that 64-bit machines are not supporteddrivers/core/syscon-uclass.c | 13 +++++++++++++ include/syscon.h | 11 +++++++++++ 2 files changed, 24 insertions(+)
Applied to u-boot-dm
PATCH v3 21/62 dm: sandbox: Add a simple driver to test of-platdata
In reply to Simon GlassAdd a driver which uses of-platdata to obtain its platform data. This can be used to test the feature in sandbox. It displays the contents of its platform data.
---
Changes in v3:
- Print out the of-platdata contents for testing
Changes in v2: None
drivers/misc/Makefile | 5 ++++ drivers/misc/spltest_sandbox.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 drivers/misc/spltest_sandbox.c
drivers/misc/Makefile +5 -0
@@ -35,6 +35,11 @@ obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o obj-$(CONFIG_SMSC_SIO1007) += smsc_sio1007.o obj-$(CONFIG_STATUS_LED) += status_led.o obj-$(CONFIG_SANDBOX) += swap_case.o +ifdef CONFIG_SPL_OF_PLATDATA +ifdef CONFIG_SPL_BUILD +obj-$(CONFIG_SANDBOX) += spltest_sandbox.o +endif +endif obj-$(CONFIG_SANDBOX) += syscon_sandbox.o obj-$(CONFIG_TWL4030_LED) += twl4030_led.o obj-$(CONFIG_FSL_IFC) += fsl_ifc.o
drivers/misc/spltest_sandbox.c new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 21/62 dm: sandbox: Add a simple driver to test of-platdata
Quoted 10 lines · Simon Glass
Add a driver which uses of-platdata to obtain its platform data. This can be used to test the feature in sandbox. It displays the contents of its platform data.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Print out the of-platdata contents for testing
Quoted 6 lines
Changes in v2: None
drivers/misc/Makefile | 5 ++++ drivers/misc/spltest_sandbox.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 drivers/misc/spltest_sandbox.c
Applied to u-boot-dm
PATCH v3 22/62 dm: Add a header that provides access to the of-platdata structs
In reply to Simon GlassThis header can be included from anywhere, but will only pull in the of-platdata struct definitions when this feature is enabled (and only in SPL).
---
Changes in v3: None
Changes in v2: None
include/dt-structs.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 include/dt-structs.h
include/dt-structs.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* Copyright (c) 2016 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __DT_STTUCTS +#define __DT_STTUCTS + +/* These structures may only be used in SPL */ +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +struct phandle_2_cell { +const void *node; +int id; +}; +#include <generated/dt-structs.h> +#endif + +#endif
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 22/62 dm: Add a header that provides access to the of-platdata structs
Quoted 5 lines · Simon Glass
This header can be included from anywhere, but will only pull in the of-platdata struct definitions when this feature is enabled (and only in SPL).
Signed-off-by Simon Glass <[email protected]>
Quoted 8 lines
---
Changes in v3: None
Changes in v2: Noneinclude/dt-structs.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 include/dt-structs.h
Applied to u-boot-dm
PATCH v3 23/62 dm: clk: Add support for of-platdata
In reply to Simon GlassAdd support for this feature in the core clock code.
---
Changes in v3:
- Update to the new clock API
Changes in v2: None
drivers/clk/clk-uclass.c | 22 ++++++++++++++++++++-- drivers/clk/clk_fixed_rate.c | 2 ++ include/clk.h | 4 ++++ 3 files changed, 26 insertions(+), 2 deletions(-)
drivers/clk/clk-uclass.c +20 -2
@@ -10,6 +10,7 @@#include <clk.h> #include <clk-uclass.h> #include <dm.h> +#include <dt-structs.h> #include <errno.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -21,6 +22,22 @@ static inline struct clk_ops *clk_dev_ops(struct udevice *dev) #if CONFIG_IS_ENABLED(OF_CONTROL) #ifdef CONFIG_SPL_BUILD +# if CONFIG_IS_ENABLED(OF_PLATDATA) +int clk_get_by_index_platdata(struct udevice *dev, int index, + struct phandle_2_cell *cells, struct clk *clk) +{ + int ret; + + if (index != 0) + return -ENOSYS; + ret = uclass_get_device(UCLASS_CLK, 0, &clk->dev); + if (ret) + return ret; + clk->id = cells[0].id; + + return 0; +} +# else int clk_get_by_index(struct udevice *dev, int index, struct clk *clk) { int ret;
@@ -39,6 +56,7 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk) clk->id = cell[1 ]; return 0; } +# endif /* OF_PLATDATA */ int clk_get_by_name (struct udevice *dev,const char *name,struct clk *clk) {
@@ -117,8 +135,8 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk)return clk_get_by_index (dev, index, clk); } -#endif -#endif +#endif /* CONFIG_SPL_BUILD */ +#endif /* OF_CONTROL */ int clk_request (struct udevice *dev,struct clk *clk) {
drivers/clk/clk_fixed_rate.c +2 -0
@@ -30,9 +30,11 @@ const struct clk_ops clk_fixed_rate_ops = {static int clk_fixed_rate_ofdata_to_platdata (struct udevice *dev) { +#if !CONFIG_IS_ENABLED (OF_PLATDATA )to_clk_fixed_rate (dev)->fixed_rate =fdtdec_get_int (gd->fdt_blob, dev->of_offset,"clock-frequency" ,0 ); +#endif return 0 ; }
include/clk.h +4 -0
@@ -60,6 +60,10 @@ struct clk { };#if CONFIG_IS_ENABLED (OF_CONTROL ) +struct phandle_2_cell ; +int clk_get_by_index_platdata (struct udevice *dev,int index, +struct phandle_2_cell *cells,struct clk *clk); +/** * clock_get_by_index - Get/request a clock by integer index. *
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 23/62 dm: clk: Add support for of-platdata
Quoted 8 lines · Simon Glass
Add support for this feature in the core clock code.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Update to the new clock API
Quoted 6 lines
Changes in v2: None
drivers/clk/clk-uclass.c | 22 ++++++++++++++++++++-- drivers/clk/clk_fixed_rate.c | 2 ++ include/clk.h | 4 ++++ 3 files changed, 26 insertions(+), 2 deletions(-)
Applied to u-boot-dm
PATCH v3 24/62 dm: serial: Add support for of-platdata
In reply to Simon GlassWhen this feature is enabled, we cannot access the device tree to find out which serial device to use. Just use the first serial driver we find.
---
Changes in v3: None
Changes in v2: None
drivers/serial/serial-uclass.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/serial/serial-uclass.c +7 -1
@@ -33,7 +33,13 @@ static void serial_find_console_or_panic(void)struct udevice *dev;int node; -if (CONFIG_IS_ENABLED (OF_CONTROL ) && blob) { +if (CONFIG_IS_ENABLED (OF_PLATDATA )) { +uclass_first_device (UCLASS_SERIAL , &dev); +if (dev) { + gd->cur_serial_dev = dev; +return ; + } + }else if (CONFIG_IS_ENABLED (OF_CONTROL ) && blob) {/* Check for a chosen console */ node =fdtdec_get_chosen_node (blob,"stdout-path" );if (node <0 ) {
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 24/62 dm: serial: Add support for of-platdata
Quoted 11 lines · Simon Glass
When this feature is enabled, we cannot access the device tree to find out which serial device to use. Just use the first serial driver we find.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/serial/serial-uclass.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 25/62 dm: Don't include fdtdec functions when of-platdata is enabled
In reply to Simon GlassWe cannot access the device tree in this case, so avoid compiling in the various device-tree helper functions.
---
Changes in v3: None
Changes in v2: None
lib/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
lib/Makefile +2 -3
@@ -48,11 +48,10 @@ obj-$(CONFIG_$(SPL_)SHA1) += sha1.o obj-$(CONFIG_$(SPL_)SHA256) += sha256.o obj-$(CONFIG_$(SPL_)OF_LIBFDT) += libfdt/ -ifdef CONFIG_SPL_OF_CONTROL -obj-$(CONFIG_OF_LIBFDT) += libfdt/ -endif +ifneq ($(CONFIG_SPL_BUILD)$(CONFIG_SPL_OF_PLATDATA),yy) obj-$(CONFIG_$(SPL_)OF_CONTROL) += fdtdec_common.o obj-$(CONFIG_$(SPL_)OF_CONTROL) += fdtdec.o +endif ifdef CONFIG_SPL_BUILD obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16.o
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 25/62 dm: Don't include fdtdec functions when of-platdata is enabled
Quoted 11 lines · Simon Glass
We cannot access the device tree in this case, so avoid compiling in the various device-tree helper functions.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonelib/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
Applied to u-boot-dm
PATCH v3 26/62 dm: Add an option to enable the of-platdata feature
In reply to Simon GlassAdd a Kconfig option to enable this feature.
---
Changes in v3: None
Changes in v2: None
dts/Kconfig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
dts/Kconfig +21 -0
@@ -85,4 +85,25 @@ config OF_SPL_REMOVE_PROPS can be discarded. This option defines the list of properties to discard. +config SPL_OF_PLATDATA + bool "Generate platform data for use in SPL" + depends on SPL_OF_CONTROL + help + For very constrained SPL environments the overhead of decoding + device tree nodes and converting their contents into platform data + is too large. This overhead includes libfdt code as well as the + device tree contents itself. The latter is fairly compact, but the + former can add 3KB or more to a Thumb 2 Image. + + This option enables generation of platform data from the device + tree as C code. This code creates devices using U_BOOT_DEVICE() + declarations. The benefit is that it allows driver code to access + the platform data directly in C structures, avoidin the libfdt + overhead. + + This option works by generating C structure declarations for each + compatible string, then adding platform data and U_BOOT_DEVICE + declarations for each node. See README.platdata for more + information. + endmenu
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 26/62 dm: Add an option to enable the of-platdata feature
Quoted 10 lines · Simon Glass
Add a
Kconfigoption to enable this feature.Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedts/Kconfig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
Applied to u-boot-dm
PATCH v3 27/62 dm: Add a README for of-platdata
In reply to Simon GlassAdd documentation on how this works, including the benefits and drawbacks.
---
Changes in v3: None
Changes in v2: None
doc/driver-model/of-plat.txt | 268 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100644 doc/driver-model/of-plat.txt
doc/driver-model/of-plat.txt new file +268 -0
@@ -0,0 +1,268 @@ +Driver Model Compiled-in Device Tree / Platform Data +==================================================== + + +Introduction +------------ + +Device tree is the standard configuration method in U-Boot. It is used to +define what devices are in the system and provide configuration information +to these devices. + +The overhead of adding device tree access to U-Boot is fairly modest, +approximately 3KB on Thumb 2 (plus the size of the DT itself). This means +that in most cases it is best to use device tree for configuration. + +However there are some very constrained environments where U-Boot needs to +work. These include SPL with severe memory limitations. For example, some +SoCs require a 16KB SPL image which must include a full MMC stack. In this +case the overhead of device tree access may be too great. + +It is possible to create platform data manually by defining C structures +for it, and referencing that data in a U_BOOT_DEVICE() declaration. This +bypasses the use of device tree completely, but is an available option for +SPL. + +As an alternative, a new 'of-platdata' feature is provided. This converts +device tree contents into C code which can be compiled into the SPL binary. +This saves the 3KB of code overhead and perhaps a few hundred more bytes due +to more efficient storage of the data. + + +Caveats +------- + +There are many problems with this features. It should only be used when +stricly necessary. Notable problems include: + + - Device tree does not describe data types but the C code must define a + type for each property. Thesee are guessed using heuristics which + are wrong in several fairly common cases. For example an 8-byte value + is considered to be a 2-item integer array, and is byte-swapped. A + boolean value that is not present means 'false', but cannot be + included in the structures since there is generally no mention of it + in the device tree file. + + - Naming of nodes and properties is automatic. This means that they follow + the naming in the device tree, which may result in C identifiers that + look a bit strange + + - It is not possible to find a value given a property name. Code must use + the associated C member variable directly in the code. This makes + the code less robust in the face of device-tree changes. It also + makes it very unlikely that your driver code will be useful for more + than one SoC. Even if the code is common, each SoC will end up with + a different C struct and format for the platform data. + + - The platform data is provided to drivers as a C structure. The driver + must use the same structure to access the data. Since a driver + normally also supports device tree it must use #ifdef to separate + out this code, since the structures are only available in SPL. + + +How it works +------------ + +The feature is enabled by CONFIG SPL_OF_PLATDATA. This is only available +in SPL and should be tested with: + + #if CONFIG_IS_ENABLED(SPL_OF_PLATDATA) + +A new tool called 'dtoc' converts a device tree file either into a set of +struct declarations, one for each compatible node, or a set of +U_BOOT_DEVICE() declarations along with the actual platform data for each +device. As an example, consider this MMC node: + + sdmmc: dwmmc at ff0c0000 { + compatible = "rockchip,rk3288-dw-mshc"; + clock-freq-min-max = <400000 150000000>; + clocks = <&cru HCLK_SDMMC>, <&cru SCLK_SDMMC>, + <&cru SCLK_SDMMC_DRV>, <&cru SCLK_SDMMC_SAMPLE>; + clock-names = "biu", "ciu", "ciu_drv", "ciu_sample"; + fifo-depth = <0x100>; + interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>; + reg = <0xff0c0000 0x4000>; + bus-width = <4>; + cap-mmc-highspeed; + cap-sd-highspeed; + card-detect-delay = <200>; + disable-wp; + num-slots = <1>; + pinctrl-names = "default"; + pinctrl-0 = <&sdmmc_clk>, <&sdmmc_cmd>, <&sdmmc_cd>, <&sdmmc_bus4>; + vmmc-supply = <&vcc_sd>; + status = "okay"; + u-boot,dm-pre-reloc; + }; + + +Some of these properties are dropped by U-Boot under control of the +CONFIG_OF_SPL_REMOVE_PROPS option. The rest are processed. This will produce +the following C struct declaration: + +struct dtd_rockchip_rk3288_dw_mshc { + fdt32_t bus_width; + bool cap_mmc_highspeed; + bool cap_sd_highspeed; + fdt32_t card_detect_delay; + fdt32_t clock_freq_min_max[2]; + struct phandle_2_cell clocks[4]; + bool disable_wp; + fdt32_t fifo_depth; + fdt32_t interrupts[3]; + fdt32_t num_slots; + fdt32_t reg[2]; + bool u_boot_dm_pre_reloc; + fdt32_t vmmc_supply; +}; + +and the following device declaration: + +static struct dtd_rockchip_rk3288_dw_mshc dtv_dwmmc_at_ff0c0000 = { + .fifo_depth = 0x100, + .cap_sd_highspeed = true, + .interrupts = {0x0, 0x20, 0x4}, + .clock_freq_min_max = {0x61a80, 0x8f0d180}, + .vmmc_supply = 0xb, + .num_slots = 0x1, + .clocks = {{&dtv_clock_controller_at_ff760000, 456}, {&dtv_clock_controller_at_ff760000, 68}, {&dtv_clock_controller_at_ff760000, 114}, {&dtv_clock_controller_at_ff760000, 118}}, + .cap_mmc_highspeed = true, + .disable_wp = true, + .bus_width = 0x4, + .u_boot_dm_pre_reloc = true, + .reg = {0xff0c0000, 0x4000}, + .card_detect_delay = 0xc8, +}; +U_BOOT_DEVICE(dwmmc_at_ff0c0000) = { + .name = "rockchip_rk3288_dw_mshc", + .platdata = &dtv_dwmmc_at_ff0c0000, +}; + +The device is then instantiated at run-time and the platform data can be +accessed using: + + struct udevice *dev; + struct dtd_rockchip_rk3288_dw_mshc *plat = dev_get_platdata(dev); + +This avoids the code overhead of converting the device tree data to +platform data in the driver. The ofdata_to_platdata() method should +therefore do nothing in such a driver. + + +How to structure your driver +---------------------------- + +Drivers should always support device tree as an option. The of-platdata +feature is intended as a add-on to existing drivers. + +Your driver should directly access the platdata struct in its probe() +method. The existing device tree decoding logic should be kept in the +ofdata_to_platdata() and wrapped with #ifdef. + +For example: + + #include <dt-structs.h> + + struct mmc_platdata { + #if CONFIG_IS_ENABLED(SPL_OF_PLATDATA) + /* Put this first */ + struct dtd_mmc dtplat; + #endif + /* + * Other fields can go here, to be filled in by decoding from + * the device tree. They will point to random memory in the + * of-plat case. + */ + int fifo_depth; + }; + + static int mmc_ofdata_to_platdata(struct udevice *dev) + { + #if !CONFIG_IS_ENABLED(SPL_OF_PLATDATA) + struct mmc_platdata *plat = dev_get_platdata(dev); + const void *blob = gd->fdt_blob; + int node = dev->of_offset; + + plat->fifo_depth = fdtdec_get_int(blob, node, "fifo-depth", 0); + #endif + + return 0; + } + + static int mmc_probe(struct udevice *dev) + { + struct mmc_platdata *plat = dev_get_platdata(dev); + #if CONFIG_IS_ENABLED(SPL_OF_PLATDATA) + struct dtd_mmc *dtplat = &plat->dtplat; + + /* Set up the device from the dtplat data */ + writel(dtplat->fifo_depth, ...) + #else + /* Set up the device from the plat data */ + writel(plat->fifo_depth, ...) + #endif + } + + static const struct udevice_id mmc_ids[] = { + { .compatible = "vendor,mmc" }, + { } + }; + + U_BOOT_DRIVER(mmc_drv) = { + .name = "mmc", + .id = UCLASS_MMC, + .of_match = mmc_ids, + .ofdata_to_platdata = mmc_ofdata_to_platdata, + .probe = mmc_probe, + .priv_auto_alloc_size = sizeof(struct mmc_priv), + .platdata_auto_alloc_size = sizeof(struct mmc_platdata), + }; + + +In the case where SPL_OF_PLATDATA is enabled, platdata_auto_alloc_size is +ignored, and the platform data points to the C structure data. In the case +where device tree is used, the platform data is allocated, and starts +zeroed. In this case the ofdata_to_platdata() method should set up the +platform data. + +SPL must use either of-platdata or device tree. Drivers cannot use both. +The device tree becomes in accessible when CONFIG_SPL_OF_PLATDATA is enabled, +since the device-tree access code is not compiled in. + + +Internals +--------- + +The dt-structs.h file includes the generated file +(include/generated//dt-structs.h) if CONFIG_SPL_OF_PLATDATA is enabled. +Otherwise (such as in U-Boot proper) these structs are not available. This +prevents them being used inadvertently. + +The dt-platdata.c file contains the device declarations and is is built in +spl/dt-platdata.c. + +Some phandles (thsoe that are recognised as such) are converted into +points to platform data. This pointer can potentially be used to access the +referenced device (by searching for the pointer value). This feature is not +yet implemented, however. + +The beginnings of a libfdt Python module are provided. So far this only +implements a subset of the features. + +The 'swig' tool is needed to build the libfdt Python module. + + +Future work +----------- +- Add unit tests +- Add a sandbox_spl functional test +- Consider programmatically reading binding files instead of device tree + contents +- Drop the device tree data from the SPL image +- Complete the phandle feature +- Get this running on a Rockchip board +- Move to using a full Python libfdt module + +-- +Simon Glass <[email protected]> +6/6/16
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 27/62 dm: Add a README for of-platdata
Quoted 11 lines · Simon Glass
Add documentation on how this works, including the benefits and drawbacks.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedoc/driver-model/of-plat.txt | 268 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100644 doc/driver-model/of-plat.txt
Applied to u-boot-dm
PATCH v3 28/62 dm: Add a library to provide simple device-tree access
In reply to Simon GlassThis Python library provides a way to access the contents of the device tree. It uses fdtget, so is inefficient for larger device tree files.
---
Changes in v3:
- Update comments a little
- Add GetEmpty() to obtain an empty/zero value of a given type
Changes in v2: None
tools/dtoc/.gitignore | 1 + tools/dtoc/fdt_fallback.py | 207 +++++++++++++++++++++++++++++++++++++++++++++ tools/dtoc/fdt_util.py | 86 +++++++++++++++++++ 3 files changed, 294 insertions(+) create mode 100644 tools/dtoc/.gitignore create mode 100644 tools/dtoc/fdt_fallback.py create mode 100644 tools/dtoc/fdt_util.py
tools/dtoc/.gitignore new file +1 -0
@@ -0,0 +1 @@ +*.pyc
tools/dtoc/fdt_fallback.py new file +207 -0
207 lines not on this page · raw message
tools/dtoc/fdt_util.py new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 28/62 dm: Add a library to provide simple device-tree access
Quoted 12 lines · Simon Glass
This Python library provides a way to access the contents of the device tree. It uses fdtget, so is inefficient for larger device tree files.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Update comments a little
- AddGetEmpty()to obtain an empty/zero value of a given typeChanges in v2: None
Quoted 7 lines
tools/dtoc/.gitignore | 1 + tools/dtoc/fdt_fallback.py | 207 +++++++++++++++++++++++++++++++++++++++++++++ tools/dtoc/fdt_util.py | 86 +++++++++++++++++++ 3 files changed, 294 insertions(+) create mode 100644 tools/dtoc/.gitignore create mode 100644 tools/dtoc/fdt_fallback.py create mode 100644 tools/dtoc/fdt_util.py
Applied to u-boot-dm
PATCH v3 29/62 dm: Add a tool to generate C code from a device tree
In reply to Simon GlassThis tool can produce C struct definitions and C platform data tables. This is used to support the of-platdata feature.
---
Changes in v3:
- Process the structs in a first pass, to correct bugs in widening
Changes in v2: None
tools/dtoc/dtoc | 1 + tools/dtoc/dtoc.py | 391 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 392 insertions(+) create mode 120000 tools/dtoc/dtoc create mode 100755 tools/dtoc/dtoc.py
tools/dtoc/dtoc new file +1 -0
@@ -0,0 +1 @@ +dtoc.py
tools/dtoc/dtoc.py new file +391 -0
391 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 29/62 dm: Add a tool to generate C code from a device tree
Quoted 9 lines · Simon Glass
This tool can produce C struct definitions and C platform data tables. This is used to support the of-platdata feature.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Process the structs in a first pass, to correct bugs in widening
Quoted 7 lines
Changes in v2: None
tools/dtoc/dtoc | 1 + tools/dtoc/dtoc.py | 391 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 392 insertions(+) create mode 120000 tools/dtoc/dtoc create mode 100755 tools/dtoc/dtoc.py
Applied to u-boot-dm
PATCH v3 30/62 dm: Makefile: Build of-platdata files when the feature is enabled
In reply to Simon GlassUpdate the Makefile to call dtoc to create the C header and source files, then build these into the image.
---
Changes in v3: None
Changes in v2: None
scripts/Makefile.spl | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-)
scripts/Makefile.spl +36 -3
@@ -45,6 +45,7 @@ LDFLAGS_FINAL += --gc-sections # FIX ME cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \ $(NOSTDINC_FLAGS) +c_flags := $(KBUILD_CFLAGS) $(cpp_flags) HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n)
@@ -76,6 +77,9 @@ endif u-boot-spl-init := $(head-y) u-boot-spl-main := $(libs-y) +ifdef CONFIG_SPL_OF_PLATDATA +u-boot-spl-platdata := $(obj)/dts/dt-platdata.o +endif # Linker Script ifdef CONFIG_SPL_LDSCRIPT
@@ -207,6 +211,32 @@ cmd_cpp_cfg = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) -ansi \ $(obj)/$(SPL_BIN).cfg: include/config.h FORCE $(call if_changed,cpp_cfg) +pythonpath = PYTHONPATH=tools + +quiet_cmd_dtocc = DTOC C $@ +cmd_dtocc = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ platdata + +quiet_cmd_dtoch = DTOC H $@ +cmd_dtoch = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ struct + +quiet_cmd_plat = PLAT $@ +cmd_plat = $(CC) $(c_flags) -c $< -o $@ + +$(obj)/dts/dt-platdata.o: $(obj)/dts/dt-platdata.c include/generated/dt-structs.h + $(call if_changed,plat) + +PHONY += dts_dir +dts_dir: + $(shell [ -d $(obj)/dts ] || mkdir -p $(obj)/dts) + +include/generated/dt-structs.h: $(obj)/$(SPL_BIN).dtb dts_dir dtoc + $(call if_changed,dtoch) + +$(obj)/dts/dt-platdata.c: $(obj)/$(SPL_BIN).dtb dts_dir dtoc + $(call if_changed,dtocc) + +dtoc: #$(objtree)/tools/_libfdt.so + ifdef CONFIG_SAMSUNG ifdef CONFIG_VAR_SIZE_SPL VAR_SIZE_PARAM = --vs
@@ -246,16 +276,19 @@ $(obj)/sunxi-spl.bin: $(obj)/$(SPL_BIN).bin FORCE quiet_cmd_u-boot-spl ?= LD $@ cmd_u-boot-spl ?= (cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \ $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \ - $(patsubst $(obj)/%,%,$(u-boot-spl-main)) --end-group \ + $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \ + $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \ + --end-group \ $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN)) -$(obj)/$(SPL_BIN): $(u-boot-spl-init) $(u-boot-spl-main) $(obj)/u-boot-spl.lds FORCE +$(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \ + $(u-boot-spl-main) $(obj)/u-boot-spl.lds FORCE $(call if_changed,u-boot-spl) $(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ; PHONY += $(u-boot-spl-dirs) -$(u-boot-spl-dirs): +$(u-boot-spl-dirs): $(u-boot-spl-platdata) $(Q)$(MAKE) $(build)=$@ quiet_cmd_cpp_lds = LDS $@
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 30/62 dm: Makefile: Build of-platdata files when the feature is enabled
Quoted 11 lines · Simon Glass
Update the
Makefileto call dtoc to create the C header and source files, then build these into the image.Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonescripts/Makefile.spl | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-)
Applied to u-boot-dm
PATCH v3 31/62 dm: Add a more efficient libfdt library
In reply to Simon GlassAdd a Python version of the libfdt library which contains enough features to support the dtoc tool. This is only a very bare-bones implementation. It requires the 'swig' to build.
---
Changes in v3:
- Fix handling of boolean value (no impact, but it is more correct)
- Enhance widening to handle array size changes
Changes in v2: None
lib/libfdt/libfdt.swig | 89 +++++++++++++++++++++++ lib/libfdt/setup.py | 38 ++++++++++ lib/libfdt/test_libfdt.py | 14 ++++ scripts/Makefile.host | 9 ++- tools/Makefile | 11 +++ tools/dtoc/fdt.py | 180 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 339 insertions(+), 2 deletions(-) create mode 100644 lib/libfdt/libfdt.swig create mode 100644 lib/libfdt/setup.py create mode 100644 lib/libfdt/test_libfdt.py create mode 100644 tools/dtoc/fdt.py
lib/libfdt/libfdt.swig new file +89 -0
@@ -0,0 +1,89 @@ +/* File: libfdt.i */ +%module libfdt + +%{ +#define SWIG_FILE_WITH_INIT +#include "libfdt.h" +%} + +%pythoncode %{ +def Raise(errnum): + raise ValueError('Error %s' % fdt_strerror(errnum)) + +def Name(fdt, offset): + name, len = fdt_get_name(fdt, offset) + return name + +def String(fdt, offset): + offset = fdt32_to_cpu(offset) + name = fdt_string(fdt, offset) + return name + +def swap32(x): + return (((x << 24) & 0xFF000000) | + ((x << 8) & 0x00FF0000) | + ((x >> 8) & 0x0000FF00) | + ((x >> 24) & 0x000000FF)) + +def fdt32_to_cpu(x): + return swap32(x) + +def Data(prop): + set_prop(prop) + return get_prop_data() +%} + +%include "typemaps.i" +%include "cstring.i" + +%typemap(in) void* = char*; + +typedef int fdt32_t; + +struct fdt_property { + fdt32_t tag; + fdt32_t len; + fdt32_t nameoff; + char data[0]; +}; + +/* + * This is a work-around since I'm not sure of a better way to copy out the + * contents of a string. This is used in dtoc/GetProps(). The intent is to + * pass in a pointer to a property and access the data field at the end of + * it. Ideally the Data() function above would be able to do this directly, + * but I'm not sure how to do that. + */ +#pragma SWIG nowarn=454 +%inline %{ + static struct fdt_property *cur_prop; + + void set_prop(struct fdt_property *prop) { + cur_prop = prop; + } +%} + +%cstring_output_allocate_size(char **s, int *sz, free(*$1)); +%inline %{ + void get_prop_data(char **s, int *sz) { + *sz = fdt32_to_cpu(cur_prop->len); + *s = (char *)malloc(*sz); + if (!*s) + *sz = 0; + else + memcpy(*s, cur_prop + 1, *sz); + } +%} + +const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); +int fdt_path_offset(const void *fdt, const char *path); +int fdt_first_property_offset(const void *fdt, int nodeoffset); +int fdt_next_property_offset(const void *fdt, int offset); +const char *fdt_strerror(int errval); +const struct fdt_property *fdt_get_property_by_offset(const void *fdt, + int offset, + int *OUTPUT); +const char *fdt_get_name(const void *fdt, int nodeoffset, int *OUTPUT); +const char *fdt_string(const void *fdt, int stroffset); +int fdt_first_subnode(const void *fdt, int offset); +int fdt_next_subnode(const void *fdt, int offset);
lib/libfdt/setup.py new file +38 -0
@@ -0,0 +1,38 @@ +#!/usr/bin/env python + +""" +setup.py file for SWIG libfdt +""" + +from distutils.core import setup, Extension +import os +import sys + +# Don't cross-compile - always use the host compiler. +del os.environ['CROSS_COMPILE'] +del os.environ['CC'] + +progname = sys.argv[0] +cflags = sys.argv[1] +files = sys.argv[2:] + +if cflags: + cflags = [flag for flag in cflags.split(' ') if flag] +else: + cflags = None + +libfdt_module = Extension( + '_libfdt', + sources = files, + extra_compile_args = cflags +) + +sys.argv = [progname, '--quiet', 'build_ext', '--inplace'] + +setup (name = 'libfdt', + version = '0.1', + author = "SWIG Docs", + description = """Simple swig libfdt from docs""", + ext_modules = [libfdt_module], + py_modules = ["libfdt"], + )
lib/libfdt/test_libfdt.py new file +14 -0
@@ -0,0 +1,14 @@ +#!/usr/bin/python + +import os +import sys + +our_path = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(our_path, '../../b/sandbox_spl/tools')) + +import libfdt + +with open('b/sandbox_spl/u-boot.dtb') as fd: + fdt = fd.read() + +print libfdt.fdt_path_offset(fdt, "/aliases")
scripts/Makefile.host +7 -2
@@ -28,12 +28,16 @@ __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m)) # C code # Executables compiled from a single .c file host-csingle := $(foreach m,$(__hostprogs), \ - $(if $($(m)-objs)$($(m)-cxxobjs),,$(m))) + $(if $($(m)-objs)$($(m)-cxxobjs)$($(m)-sharedobjs),,$(m))) # C executables linked based on several .o files host-cmulti := $(foreach m,$(__hostprogs),\ $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m)))) +# Shared object libraries +host-shared := $(foreach m,$(__hostprogs),\ + $(if $($(m)-sharedobjs),$(m)))) + # Object (.o) files compiled from .c files host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs)))
@@ -59,6 +63,7 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti)) host-cobjs := $(addprefix $(obj)/,$(host-cobjs)) host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti)) host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs)) +host-shared := $(addprefix $(obj)/,$(host-shared)) host-objdirs := $(addprefix $(obj)/,$(host-objdirs)) obj-dirs += $(host-objdirs)
@@ -128,4 +133,4 @@ $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE $(call if_changed_dep,host-cxxobjs) targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\ - $(host-cxxmulti) $(host-cxxobjs) + $(host-cxxmulti) $(host-cxxobjs) $(host-shared)
tools/Makefile +11 -0
@@ -107,6 +107,17 @@ mkimage-objs := $(dumpimage-mkimage-objs) mkimage.o fit_info-objs := $(dumpimage-mkimage-objs) fit_info.o fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o +hostprogs-$(CONFIG_SPL_OF_PLATDATA) += _libfdt.so +_libfdt.so-sharedobjs += $(LIBFDT_OBJS) +libfdt: + +tools/_libfdt.so: $(patsubst %.o,%.c,$(LIBFDT_OBJS)) tools/libfdt_wrap.c + python $(srctree)/lib/libfdt/setup.py "$(_hostc_flags)" $^ + mv _libfdt.so $@ + +tools/libfdt_wrap.c: $(srctree)/lib/libfdt/libfdt.swig + swig -python -o $@ $< + # TODO(sjg at chromium.org): Is this correct on Mac OS? ifneq ($(CONFIG_MX23)$(CONFIG_MX28),)
tools/dtoc/fdt.py new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 31/62 dm: Add a more efficient libfdt library
Quoted 13 lines · Simon Glass
Add a Python version of the libfdt library which contains enough features to support the dtoc tool. This is only a very bare-bones implementation. It requires the 'swig' to build.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Fix handling of boolean value (no impact, but it is more correct)
- Enhance widening to handle array size changesChanges in v2: None
Quoted 11 lines
lib/libfdt/libfdt.swig | 89 +++++++++++++++++++++++ lib/libfdt/setup.py | 38 ++++++++++ lib/libfdt/test_libfdt.py | 14 ++++ scripts/Makefile.host | 9 ++- tools/Makefile | 11 +++ tools/dtoc/fdt.py | 180 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 339 insertions(+), 2 deletions(-) create mode 100644 lib/libfdt/libfdt.swig create mode 100644 lib/libfdt/setup.py create mode 100644 lib/libfdt/test_libfdt.py create mode 100644 tools/dtoc/fdt.py
Applied to u-boot-dm
PATCH v3 32/62 Only build the libfdt python module if 'swig' is available
In reply to Simon GlassWhen swig is not available, we can still build correctly. So make this optional. Add a comment about how to enable this build.
---
Changes in v3: None
Changes in v2: None
tools/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/Makefile +4 -1
@@ -107,7 +107,10 @@ mkimage-objs := $(dumpimage-mkimage-objs) mkimage.o fit_info-objs := $(dumpimage-mkimage-objs) fit_info.o fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o -hostprogs-$(CONFIG_SPL_OF_PLATDATA) += _libfdt.so +# Build a libfdt Python module if swig is available +# Use 'sudo apt-get install swig libpython-dev' to enable this +hostprogs-$(CONFIG_SPL_OF_PLATDATA) += \ + $(if $(shell which swig),_libfdt.so) _libfdt.so-sharedobjs += $(LIBFDT_OBJS) libfdt:
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 32/62 Only build the libfdt python module if 'swig' is available
Quoted 11 lines · Simon Glass
When swig is not available, we can still build correctly. So make this optional. Add a comment about how to enable this build.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonetools/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 33/62 tiny-printf: Support assert()
In reply to Simon GlassAt present assert() is not supported with tiny-printf, so when DEBUG is enabled a build error is generated for each assert().
Add an __assert_fail() function to correct this. It prints a message and then hangs.
---
Changes in v3: None
Changes in v2: None
lib/tiny-printf.c | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/tiny-printf.c +9 -0
@@ -180,3 +180,12 @@ int snprintf(char *buf, size_t size, const char *fmt, ...)return ret; } + +void __assert_fail (const char *assertion,const char *file,unsigned line, +const char *function) +{ +/* This will not return */ +printf ("%s:%u: %s: Assertion `%s' failed." , file, line, function, + assertion); +hang (); +}
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 33/62 tiny-printf: Support assert()
Quoted 6 lines · Simon Glass
At present
assert()is not supported with tiny-printf, so when DEBUG is enabled a build error is generated for eachassert().Add an
__assert_fail()function to correct this. It prints a message and then hangs.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonelib/tiny-printf.c | 9 +++++++++ 1 file changed, 9 insertions(+)
Applied to u-boot-dm
PATCH v3 34/62 dm: spl: Bind in all devices in SPL with of-platdata
In reply to Simon GlassWhen CONFIG_OF_PLATDATA is enabled, we cannot use the u-boot,dm-pre-reloc device tree property since the device tree is not available. However, dt-platdata.c only includes devices which would have been present in the device tree, and we can assume that all such devices are needed for SPL. If they were not needed, they would have been omitted to save space.
So in this case, bind all devices regardless of the u-boot,dm-pre-reloc setting. This avoids needing to add a DM_FLAG_PRE_RELOC to every driver, thus affecting U-Boot proper also.
---
Changes in v3: None
Changes in v2: None
common/spl/spl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
common/spl/spl.c +2 -1
@@ -210,7 +210,8 @@ int spl_init(void) } }if (IS_ENABLED (CONFIG_SPL_DM )) { - ret =dm_init_and_scan (true); +/* With CONFIG_OF_PLATDATA, bring in all devices */ + ret =dm_init_and_scan (!CONFIG_IS_ENABLED (OF_PLATDATA ));if (ret) {debug ("dm_init_and_scan() returned error %d\n" , ret);return ret;
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 34/62 dm: spl: Bind in all devices in SPL with of-platdata
Quoted 10 lines · Simon Glass
When
CONFIG_OF_PLATDATAis enabled, we cannot use the u-boot,dm-pre-reloc device tree property since the device tree is not available. However,dt-platdata.conly includes devices which would have been present in the device tree, and we can assume that all such devices are needed for SPL. If they were not needed, they would have been omitted to save space.So in this case, bind all devices regardless of the u-boot,dm-pre-reloc setting. This avoids needing to add a
DM_FLAG_PRE_RELOCto every driver, thus affecting U-Boot proper also.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonecommon/spl/spl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 35/62 dm: core: Rename DM_NAME_ALLOCED to DM_FLAG_NAME_ALLOCED
In reply to Simon GlassThis is a flag. Adjust the name to be consistent with the other flags.
---
Changes in v3: None
Changes in v2: None
drivers/core/device-remove.c | 2 +- drivers/core/device.c | 2 +- include/dm/device.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/core/device-remove.c +1 -1
@@ -112,7 +112,7 @@ int device_unbind(struct udevice *dev)devres_release_all (dev); -if (dev->flags &DM_NAME_ALLOCED ) +if (dev->flags &DM_FLAG_NAME_ALLOCED )free ((char *)dev->name);free (dev);
drivers/core/device.c +1 -1
@@ -727,7 +727,7 @@ bool device_is_last_sibling(struct udevice *dev)void device_set_name_alloced (struct udevice *dev) { - dev->flags |=DM_NAME_ALLOCED ; + dev->flags |=DM_FLAG_NAME_ALLOCED ; }int device_set_name (struct udevice *dev,const char *name)
include/dm/device.h +2 -2
@@ -42,7 +42,7 @@ struct driver_info;#define DM_FLAG_BOUND (1 << 6)/* Device name is allocated and should be freed on unbind() */ -#define DM_NAME_ALLOCED (1 << 7) +#define DM_FLAG_NAME_ALLOCED (1 << 7)/** * struct udevice - An instance of a driver
@@ -540,7 +540,7 @@ int device_set_name(struct udevice *dev, const char *name);/** * device_set_name_alloced() - note that a device name is allocated * -* This sets the DM_NAME_ALLOCED flag for the device, so that when it is +* This sets the DM_FLAG_NAME_ALLOCED flag for the device, so that when it is * unbound the name will be freed. This avoids memory leaks. * * @dev: Device to update
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 35/62 dm: core: Rename DM_NAME_ALLOCED to DM_FLAG_NAME_ALLOCED
Quoted 5 lines · Simon Glass
This is a flag. Adjust the name to be consistent with the other flags.
Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v3: None
Changes in v2: Nonedrivers/core/device-remove.c | 2 +- drivers/core/device.c | 2 +- include/dm/device.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
Applied to u-boot-dm
PATCH v3 36/62 dtoc: Ignore the u-boot, dm-pre-reloc property
In reply to Simon GlassThis property is not useful for of-platdata, so omit it.
---
Changes in v3: None
Changes in v2: None
tools/dtoc/dtoc.py | 1 + 1 file changed, 1 insertion(+)
tools/dtoc/dtoc.py +1 -0
@@ -40,6 +40,7 @@ PROP_IGNORE_LIST = [ 'linux,phandle', "status", 'phandle', + 'u-boot,dm-pre-reloc', ] # C type declarations for the tyues we support
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 36/62 dtoc: Ignore the u-boot, dm-pre-reloc property
Quoted 10 lines · Simon Glass
This property is not useful for of-platdata, so omit it.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonetools/dtoc/dtoc.py | 1 + 1 file changed, 1 insertion(+)
Applied to u-boot-dm
PATCH v3 37/62 dm: Don't attach the device tree to SPL with of-platdata
In reply to Simon GlassWhen of-platdata is used in SPL we don't use the device tree. So there is no point in attaching it. Adjust the Makefile to skip attaching the device tree when of-platdata is enabled.
---
Changes in v3: None
Changes in v2: None
scripts/Makefile.spl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.spl +1 -1
@@ -173,7 +173,7 @@ cmd_cat = cat $(filter-out $(PHONY), $^) > $@ quiet_cmd_copy = COPY $@ cmd_copy = cp $< $@ -ifeq ($(CONFIG_SPL_OF_CONTROL)$(CONFIG_OF_SEPARATE),yy) +ifeq ($(CONFIG_SPL_OF_CONTROL)$(CONFIG_OF_SEPARATE)$(CONFIG_SPL_OF_PLATDATA),yy) $(obj)/$(SPL_BIN)-dtb.bin: $(obj)/$(SPL_BIN)-nodtb.bin $(obj)/$(SPL_BIN)-pad.bin \ $(obj)/$(SPL_BIN).dtb FORCE $(call if_changed,cat)
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 37/62 dm: Don't attach the device tree to SPL with of-platdata
Quoted 4 lines · Simon Glass
When of-platdata is used in SPL we don't use the device tree. So there is no point in attaching it. Adjust the
Makefileto skip attaching the device tree when of-platdata is enabled.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonescripts/Makefile.spl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 38/62 dm: core: Expand platdata for of-platdata devices
In reply to Simon GlassDevices which use of-platdata have their own platdata. However, in many cases the driver will have its own auto-alloced platdata, for use with the device tree. The ofdata_to_platdata() method converts the device tree settings to platdata.
With of-platdata we would not normally allocate the platdata since it is provided by the U_BOOT_DEVICE() declaration. However this is inconvenient since the of-platdata struct is closely tied to the device tree properties. It is unlikely to exactly match the platdata needed by the driver.
In fact a useful approach is to declare platdata in the driver like this:
struct r3288_mmc_platdata {
struct dtd_rockchip_rk3288_dw_mshc of_platdata;
/* the 'normal' fields go here */
};In this case we have dt_platadata available, but the normal fields are not present, since ofdata_to_platdata() is never called. In fact driver model doesn't allocate any space for the 'normal' fields, since it sees that there is already platform data attached to the device.
To make this easier, adjust driver model to allocate the full size of the struct (i.e. platdata_auto_alloc_size from the driver) and copy in the of-platdata. This means that when the driver's bind() method is called, the of-platdata will be present, followed by zero bytes for the empty 'normal field' portion.
A new DM_FLAG_OF_PLATDATA flag is available that indicates that the platdata came from of-platdata. When the allocation/copy happens, the DM_FLAG_ALLOC_PDATA flag will be set as well. The dtoc tool is updated to output the platdata_size field, since U-Boot has no other way of knowing the size of the of-platdata struct.
---
Changes in v3:
- Don't try to expand when there is no of-platdata
Changes in v2: None
drivers/core/device.c | 43 ++++++++++++++++++++++++++++++++----------- include/dm/device.h | 2 ++ include/dm/platdata.h | 5 +++++ tools/dtoc/dtoc.py | 2 ++ 4 files changed, 41 insertions(+), 11 deletions(-)
drivers/core/device.c +32 -11
@@ -29,7 +29,7 @@ DECLARE_GLOBAL_DATA_PTR;static int device_bind_common (struct udevice *parent,const struct driver *drv,const char *name,void *platdata,ulong driver_data,int of_offset, -struct udevice **devp) +uint of_platdata_size,struct udevice **devp) {struct udevice *dev;struct uclass *uc;
@@ -83,12 +83,29 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, } } -if (!dev->platdata && drv->platdata_auto_alloc_size) { - dev->flags |=DM_FLAG_ALLOC_PDATA ; - dev->platdata =calloc (1 , drv->platdata_auto_alloc_size); -if (!dev->platdata) { - ret = -ENOMEM ; - goto fail_alloc1; +if (drv->platdata_auto_alloc_size) { +bool alloc = !platdata; + +if (CONFIG_IS_ENABLED (OF_PLATDATA )) { +if (of_platdata_size) { + dev->flags |=DM_FLAG_OF_PLATDATA ; +if (of_platdata_size < + drv->platdata_auto_alloc_size) + alloc = true; + } + } +if (alloc) { + dev->flags |=DM_FLAG_ALLOC_PDATA ; + dev->platdata =calloc (1 , + drv->platdata_auto_alloc_size); +if (!dev->platdata) { + ret = -ENOMEM ; + goto fail_alloc1; + } +if (CONFIG_IS_ENABLED (OF_PLATDATA ) && platdata) { +memcpy (dev->platdata, platdata, + of_platdata_size); + } } }
@@ -201,14 +218,14 @@ int device_bind_with_driver_data(struct udevice *parent, struct udevice **devp) {return device_bind_common (parent, drv, name,NULL , driver_data, - of_offset, devp); + of_offset,0 , devp); }int device_bind (struct udevice *parent,const struct driver *drv,const char *name,void *platdata,int of_offset,struct udevice **devp) { -return device_bind_common (parent, drv, name, platdata,0 , of_offset, +return device_bind_common (parent, drv, name, platdata,0 , of_offset,0 , devp); }
@@ -216,6 +233,7 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, const struct driver_info *info, struct udevice **devp) { struct driver *drv; +uint platdata_size =0 ; drv =lists_driver_lookup_name (info->name);if (!drv)
@@ -223,8 +241,11 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,if (pre_reloc_only && !(drv->flags &DM_FLAG_PRE_RELOC ))return -EPERM ; -return device_bind (parent, drv, info->name, (void *)info->platdata, --1 , devp); +#if CONFIG_IS_ENABLED (OF_PLATDATA ) + platdata_size = info->platdata_size; +#endif +return device_bind_common (parent, drv, info->name, + (void *)info->platdata,0 ,-1 , platdata_size, devp); }static void *alloc_priv (int size,uint flags)
include/dm/device.h +2 -0
@@ -44,6 +44,8 @@ struct driver_info;/* Device name is allocated and should be freed on unbind() */ #define DM_FLAG_NAME_ALLOCED (1 << 7) +#define DM_FLAG_OF_PLATDATA (1 << 8) +/** * struct udevice - An instance of a driver *
include/dm/platdata.h +5 -0
@@ -22,10 +22,15 @@* * @name: Driver name * @platdata: Driver-specific platform data +* @platdata_size: Size of platform data structure +* @flags: Platform data flags (DM_FLAG_...) */ struct driver_info {const char *name;const void *platdata; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +uint platdata_size; +#endif };/**
tools/dtoc/dtoc.py +2 -0
@@ -346,6 +346,8 @@ class DtbPlatdata: self.Buf('U_BOOT_DEVICE(%s) = {\n' % var_name) self.Buf('\t.name\t\t= "%s",\n' % struct_name) self.Buf('\t.platdata\t= &%s%s,\n' % (VAL_PREFIX, var_name)) + self.Buf('\t.platdata_size\t= sizeof(%s%s),\n' % + (VAL_PREFIX, var_name)) self.Buf('};\n') self.Buf('\n')
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 38/62 dm: core: Expand platdata for of-platdata devices
Quoted 40 lines · Simon Glass
Devices which use of-platdata have their own platdata. However, in many cases the driver will have its own auto-alloced platdata, for use with the device tree. The
ofdata_to_platdata()method converts the device tree settings to platdata.With of-platdata we would not normally allocate the platdata since it is provided by the
U_BOOT_DEVICE()declaration. However this is inconvenient since the of-platdata struct is closely tied to the device tree properties. It is unlikely to exactly match the platdata needed by the driver.In fact a useful approach is to declare platdata in the driver like this:
struct r3288_mmc_platdata { struct dtd_rockchip_rk3288_dw_mshc of_platdata; /* the 'normal' fields go here */ };In this case we have
dt_platadataavailable, but the normal fields are not present, sinceofdata_to_platdata()is never called. In fact driver model doesn't allocate any space for the 'normal' fields, since it sees that there is already platform data attached to the device.To make this easier, adjust driver model to allocate the full size of the struct (i.e.
platdata_auto_alloc_sizefrom the driver) and copy in the of-platdata. This means that when the driver'sbind()method is called, the of-platdata will be present, followed by zero bytes for the empty 'normal field' portion.A new
DM_FLAG_OF_PLATDATAflag is available that indicates that the platdata came from of-platdata. When the allocation/copy happens, theDM_FLAG_ALLOC_PDATAflag will be set as well. The dtoc tool is updated to output theplatdata_sizefield, since U-Boot has no other way of knowing the size of the of-platdata struct.Signed-off-by Simon Glass <[email protected]>---
Changes in v3:
- Don't try to expand when there is no of-platdata
Quoted 7 lines
Changes in v2: None
drivers/core/device.c | 43 ++++++++++++++++++++++++++++++++----------- include/dm/device.h | 2 ++ include/dm/platdata.h | 5 +++++ tools/dtoc/dtoc.py | 2 ++ 4 files changed, 41 insertions(+), 11 deletions(-)
Applied to u-boot-dm
PATCH v3 39/62 sandbox: Don't bring in the eeprom emulator in SPL
In reply to Simon GlassThis driver should not be used in SPL since we do not have I2C support enabled in SPL on sandbox.
---
Changes in v3:
- Add new patch to avoid bringing in the eeprom emulator in SPL
Changes in v2: None
drivers/misc/Makefile | 2 ++ 1 file changed, 2 insertions(+)
drivers/misc/Makefile +2 -0
@@ -29,8 +29,10 @@ obj-$(CONFIG_PDSP188x) += pdsp188x.o obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o obj-$(CONFIG_SANDBOX) += sysreset_sandbox.o ifdef CONFIG_DM_I2C +ifndef CONFIG_SPL_BUILD obj-$(CONFIG_SANDBOX) += i2c_eeprom_emul.o endif +endif obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o obj-$(CONFIG_SMSC_SIO1007) += smsc_sio1007.o obj-$(CONFIG_STATUS_LED) += status_led.o
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 39/62 sandbox: Don't bring in the eeprom emulator in SPL
Quoted 6 lines · Simon Glass
This driver should not be used in SPL since we do not have I2C support enabled in SPL on sandbox.
Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v3:
- Add new patch to avoid bringing in the eeprom emulator in SPLChanges in v2: None
drivers/misc/Makefile | 2 ++ 1 file changed, 2 insertions(+)
Applied to u-boot-dm
PATCH v3 40/62 dm: sandbox: Enable of-platdata for sandbox_spl
In reply to Simon GlassEnable this feature so that we can use it for testing in sandbox_spl.
---
Changes in v3: None
Changes in v2: None
configs/sandbox_spl_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/sandbox_spl_defconfig +1 -0
@@ -64,6 +64,7 @@ CONFIG_CMD_FS_GENERIC=y CONFIG_OF_CONTROL=y CONFIG_SPL_OF_CONTROL=y CONFIG_OF_HOSTFILE=y +CONFIG_SPL_OF_PLATDATA=y CONFIG_NETCONSOLE=y CONFIG_SPL_DM=y CONFIG_REGMAP=y
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 40/62 dm: sandbox: Enable of-platdata for sandbox_spl
Quoted 10 lines · Simon Glass
Enable this feature so that we can use it for testing in
sandbox_spl.Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Noneconfigs/sandbox_spl_defconfig | 1 + 1 file changed, 1 insertion(+)
Applied to u-boot-dm
PATCH v3 41/62 dm: core: Move regmap allocation into a separate function
In reply to Simon GlassWe plan to add a new way of creating a regmap for of-platdata. Move the allocation code into a separate function so that it can be shared.
---
Changes in v3: None
Changes in v2: None
drivers/core/regmap.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/core/regmap.c +22 -12
@@ -15,6 +15,27 @@DECLARE_GLOBAL_DATA_PTR ; +static struct regmap *regmap_alloc_count (int count) +{ +struct regmap *map; + + map =malloc (sizeof (struct regmap )); +if (!map) +return NULL ; +if (count <=1 ) { + map->range = &map->base_range; + }else { + map->range =malloc (count *sizeof (struct regmap_range )); +if (!map->range) { +free (map); +return NULL ; + } + } + map->range_count = count; + +return map; +} +#if CONFIG_IS_ENABLED (OF_PLATDATA )int regmap_init_mem_platdata (struct udevice *dev,fdt32_t *reg,int size,struct regmap **mapp)
@@ -45,22 +66,11 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp)if (!cell || !count)return -EINVAL ; - map =malloc (sizeof (struct regmap )); + map =regmap_alloc_count (count);if (!map)return -ENOMEM ; -if (count <=1 ) { - map->range = &map->base_range; - }else { - map->range =malloc (count *sizeof (struct regmap_range )); -if (!map->range) { -free (map); -return -ENOMEM ; - } - } - map->base =fdtdec_get_number (cell, addr_len); - map->range_count = count;for (range = map->range; count >0 ; count--, cell += both_len, range++) {
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 41/62 dm: core: Move regmap allocation into a separate function
Quoted 11 lines · Simon Glass
We plan to add a new way of creating a regmap for of-platdata. Move the allocation code into a separate function so that it can be shared.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/core/regmap.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
Applied to u-boot-dm
PATCH v3 42/62 dm: core: Add an implementation of regmap_init_mem_platdata()
In reply to Simon GlassAdd an implementation of this function which mirrors the functions of the automatic device-tree implementation. This can be used with of-platdata to create regmaps.
---
Changes in v3: None
Changes in v2: None
drivers/core/regmap.c | 18 ++++++++++++++++-- include/regmap.h | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-)
drivers/core/regmap.c +16 -2
@@ -37,10 +37,24 @@ static struct regmap *regmap_alloc_count(int count) }#if CONFIG_IS_ENABLED (OF_PLATDATA ) -int regmap_init_mem_platdata (struct udevice *dev,fdt32_t *reg,int size, +int regmap_init_mem_platdata (struct udevice *dev,u32 *reg,int count,struct regmap **mapp) { -/* TODO(sjg at chromium.org): Implement this when needed */ +struct regmap_range *range; +struct regmap *map; + + map =regmap_alloc_count (count); +if (!map) +return -ENOMEM ; + + map->base = *reg; +for (range = map->range; count >0 ; reg +=2 , range++, count--) { + range->start = *reg; + range->size = reg[1 ]; + } + + *mapp = map; +return 0 ; }#else
include/regmap.h +14 -1
@@ -56,7 +56,20 @@ int regmap_read(struct regmap *map, uint offset, uint *valp);*/ int regmap_init_mem (struct udevice *dev,struct regmap **mapp); -int regmap_init_mem_platdata (struct udevice *dev,fdt32_t *reg,int size, +/** +* regmap_init_mem_platdata() - Set up a new memory register map for of-platdata +* +* This creates a new regmap with a list of regions passed in, rather than +* using the device tree. It only supports 32-bit machines. +* +* Use regmap_uninit() to free it. +* +* @dev: Device that uses this map +* @reg: List of address, size pairs +* @count: Number of pairs (e.g. 1 if the regmap has a single entry) +* @mapp: Returns allocated map +*/ +int regmap_init_mem_platdata (struct udevice *dev,u32 *reg,int count,struct regmap **mapp);/**
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 42/62 dm: core: Add an implementation of regmap_init_mem_platdata()
Quoted 5 lines · Simon Glass
Add an implementation of this function which mirrors the functions of the automatic device-tree implementation. This can be used with of-platdata to create regmaps.
Signed-off-by Simon Glass <[email protected]>
Quoted 8 lines
---
Changes in v3: None
Changes in v2: Nonedrivers/core/regmap.c | 18 ++++++++++++++++-- include/regmap.h | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-)
Applied to u-boot-dm
PATCH v3 43/62 dm: serial: ns16550: Update to support of-platdata
In reply to Simon GlassWith of-platdata this driver cannot know the format of the of-platdata struct, so we cannot use generic code for accessing the of-platdata. Each SoC that uses this driver will need to set up ns16550's platdata for it. So don't compile in the generic code.
---
Changes in v3: None
Changes in v2: None
drivers/serial/ns16550.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/serial/ns16550.c +3 -1
@@ -347,7 +347,7 @@ int ns16550_serial_probe(struct udevice *dev)return 0 ; } -#if CONFIG_IS_ENABLED (OF_CONTROL ) +#if CONFIG_IS_ENABLED (OF_CONTROL ) && !CONFIG_IS_ENABLED (OF_PLATDATA )int ns16550_serial_ofdata_to_platdata (struct udevice *dev) {struct ns16550_platdata *plat = dev->platdata;
@@ -416,6 +416,7 @@ const struct dm_serial_ops ns16550_serial_ops = { .setbrg = ns16550_serial_setbrg, }; +#if !CONFIG_IS_ENABLED (OF_PLATDATA )#if CONFIG_IS_ENABLED (OF_CONTROL )/* * Please consider existing compatible strings before adding a new
@@ -452,4 +453,5 @@ U_BOOT_DRIVER(ns16550_serial) = { .flags = DM_FLAG_PRE_RELOC, };#endif +#endif /* !OF_PLATDATA */ #endif /* CONFIG_DM_SERIAL */
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 43/62 dm: serial: ns16550: Update to support of-platdata
Quoted 5 lines · Simon Glass
With of-platdata this driver cannot know the format of the of-platdata struct, so we cannot use generic code for accessing the of-platdata. Each SoC that uses this driver will need to set up ns16550's platdata for it. So don't compile in the generic code.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/serial/ns16550.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 44/62 rockchip: serial: Add an of-platdata driver for rockchip
In reply to Simon GlassAdd a driver that works with of-platdata. It sets up the platform data and calls the standard ns16550 driver.
---
Changes in v3: None
Changes in v2: None
drivers/serial/Kconfig | 9 +++++++++ drivers/serial/Makefile | 3 +++ drivers/serial/serial_rockchip.c | 43 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 drivers/serial/serial_rockchip.c
drivers/serial/Kconfig +9 -0
@@ -312,6 +312,15 @@ config SYS_NS16550 be used. It can be a constant or a function to get clock, eg, get_serial_clock(). +config ROCKCHIP_SERIAL + bool "Rockchip on-chip UART support" + depends on DM_SERIAL && SPL_OF_PLATDATA + help + Select this to enable a debug UART for Rockchip devices when using + CONFIG_OF_PLATDATA (i.e. a compiled-in device tree replacemenmt). + This uses the ns16550 driver, converting the platdata from of-platdata + to the ns16550 format. + config SANDBOX_SERIAL bool "Sandbox UART support" depends on SANDBOX
drivers/serial/Makefile +3 -0
@@ -28,6 +28,9 @@ obj-$(CONFIG_S5P) += serial_s5p.o obj-$(CONFIG_MXC_UART) += serial_mxc.o obj-$(CONFIG_PXA_SERIAL) += serial_pxa.o obj-$(CONFIG_MESON_SERIAL) += serial_meson.o +ifdef CONFIG_SPL_BUILD +obj-$(CONFIG_ROCKCHIP_SERIAL) += serial_rockchip.o +endif obj-$(CONFIG_S3C24X0_SERIAL) += serial_s3c24x0.o obj-$(CONFIG_XILINX_UARTLITE) += serial_xuartlite.o obj-$(CONFIG_SANDBOX_SERIAL) += sandbox.o
drivers/serial/serial_rockchip.c new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 44/62 rockchip: serial: Add an of-platdata driver for rockchip
Quoted 6 lines · Simon Glass
Add a driver that works with of-platdata. It sets up the platform data and calls the standard ns16550 driver.
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Changes in v3: None
Changes in v2: Nonedrivers/serial/Kconfig | 9 +++++++++ drivers/serial/Makefile | 3 +++ drivers/serial/serial_rockchip.c | 43 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 drivers/serial/serial_rockchip.c
Applied to u-boot-dm
PATCH v3 45/62 rockchip: Update the sdram-channel property to support of-platdata
In reply to Simon GlassAdd an extra byte so that this data is not byteswapped. Add a comment to the code to explain the purpose.
---
Changes in v3: None
Changes in v2: None
arch/arm/dts/rk3288-firefly.dts | 3 ++- arch/arm/include/asm/arch-rockchip/sdram.h | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-)
arch/arm/dts/rk3288-firefly.dts +2 -1
@@ -30,7 +30,8 @@ 0x5 0x0>; rockchip,phy-timing = <0x48f9aab4 0xea0910 0x1002c200 0xa60 0x40 0x10 0x0>; - rockchip,sdram-channel = /bits/ 8 <0x1 0xa 0x3 0x2 0x1 0x0 0xf 0xf>; + /* Add a dummy value to cause of-platdata think this is bytes */ + rockchip,sdram-channel = /bits/ 8 <0x1 0xa 0x3 0x2 0x1 0x0 0xf 0xf 0xff>; rockchip,sdram-params = <0x30B25564 0x627 3 666000000 3 9 1>; };
arch/arm/include/asm/arch-rockchip/sdram.h +6 -0
@@ -24,6 +24,12 @@ struct rk3288_sdram_channel {u8 row_3_4;u8 cs0_row;u8 cs1_row; +/* +* For of-platdata, which would otherwise convert this into two +* byte-swapped integers. With a size of 9 bytes, this struct will +* appear in of-platdata as a byte array. +*/ +u8 dummy; };struct rk3288_sdram_pctl_timing {
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 45/62 rockchip: Update the sdram-channel property to support of-platdata
Quoted 4 lines · Simon Glass
Add an extra byte so that this data is not byteswapped. Add a comment to the code to explain the purpose.
Signed-off-by Simon Glass <[email protected]>
Quoted 8 lines
---
Changes in v3: None
Changes in v2: Nonearch/arm/dts/rk3288-firefly.dts | 3 ++- arch/arm/include/asm/arch-rockchip/sdram.h | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 46/62 rockchip: mmc: Move all DT decoding to ofdata_to_platdata()
In reply to Simon GlassIt is more correct to avoid touching the device tree in the probe() method. Update the driver to work this way.
---
Changes in v3: None
Changes in v2: None
drivers/mmc/rockchip_dw_mmc.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
drivers/mmc/rockchip_dw_mmc.c +17 -15
@@ -26,6 +26,9 @@ struct rockchip_mmc_plat {struct rockchip_dwmmc_priv {struct clk clk;struct dwmci_host host; +int fifo_depth; +bool fifo_mode; +u32 minmax[2 ]; };static uint rockchip_dwmmc_get_mmc_clk (struct dwmci_host *host,uint freq)
@@ -61,6 +64,16 @@ static int rockchip_dwmmc_ofdata_to_platdata(struct udevice *dev)else host->dev_index =1 ; + priv->fifo_depth =fdtdec_get_int (gd->fdt_blob, dev->of_offset, +"fifo-depth" ,0 ); +if (priv->fifo_depth <0 ) +return -EINVAL ; + priv->fifo_mode =fdtdec_get_bool (gd->fdt_blob, dev->of_offset, +"fifo-mode" ); +if (fdtdec_get_int_array (gd->fdt_blob, dev->of_offset, +"clock-freq-min-max" , priv->minmax,2 )) +return -EINVAL ; +return 0 ; }
@@ -71,28 +84,17 @@ static int rockchip_dwmmc_probe(struct udevice *dev)struct rockchip_dwmmc_priv *priv =dev_get_priv (dev);struct dwmci_host *host = &priv->host;struct udevice *pwr_dev__maybe_unused ; -u32 minmax[2 ];int ret; -int fifo_depth; ret =clk_get_by_index (dev,0 , &priv->clk);if (ret <0 )return ret; -if (fdtdec_get_int_array (gd->fdt_blob, dev->of_offset, -"clock-freq-min-max" , minmax,2 )) -return -EINVAL ; - - fifo_depth =fdtdec_get_int (gd->fdt_blob, dev->of_offset, -"fifo-depth" ,0 ); -if (fifo_depth <0 ) -return -EINVAL ; - host->fifoth_val =MSIZE (0x2 ) | -RX_WMARK (fifo_depth /2 -1 ) |TX_WMARK (fifo_depth /2 ); +RX_WMARK (priv->fifo_depth /2 -1 ) | +TX_WMARK (priv->fifo_depth /2 ); -if (fdtdec_get_bool (gd->fdt_blob, dev->of_offset,"fifo-mode" )) - host->fifo_mode = true; + host->fifo_mode = priv->fifo_mode;#ifdef CONFIG_PWRSEQ /* Enable power if needed */
@@ -105,7 +107,7 @@ static int rockchip_dwmmc_probe(struct udevice *dev) }#endif dwmci_setup_cfg (&plat->cfg, dev->name, host->buswidth, host->caps, - minmax[1 ], minmax[0 ]); + priv->minmax[1 ], priv->minmax[0 ]); host->mmc = &plat->mmc; host->mmc->priv = &priv->host; host->mmc->dev = dev;
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 46/62 rockchip: mmc: Move all DT decoding to ofdata_to_platdata()
Quoted 11 lines · Simon Glass
It is more correct to avoid touching the device tree in the
probe()method. Update the driver to work this way.Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/mmc/rockchip_dw_mmc.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
Applied to u-boot-dm
PATCH v3 47/62 rockchip: mmc: Update the driver to support of-platdata
In reply to Simon GlassAdd support for of-platdata with rk3288. This requires decoding the of-platdata struct and setting up the device from that. Also the driver needs to be renamed to match the string that of-platdata will search for.
---
Changes in v3: None
Changes in v2: None
drivers/mmc/rockchip_dw_mmc.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
drivers/mmc/rockchip_dw_mmc.c +26 -3
@@ -7,8 +7,10 @@#include <common.h> #include <clk.h> #include <dm.h> +#include <dt-structs.h> #include <dwmmc.h> #include <errno.h> +#include <mapmem.h> #include <pwrseq.h> #include <syscon.h> #include <asm/gpio.h>
@@ -19,6 +21,9 @@DECLARE_GLOBAL_DATA_PTR ;struct rockchip_mmc_plat { +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +struct dtd_rockchip_rk3288_dw_mshc dtplat; +#endif struct mmc_config cfg;struct mmc mmc; };
@@ -48,6 +53,7 @@ static uint rockchip_dwmmc_get_mmc_clk(struct dwmci_host *host, uint freq)static int rockchip_dwmmc_ofdata_to_platdata (struct udevice *dev) { +#if !CONFIG_IS_ENABLED (OF_PLATDATA )struct rockchip_dwmmc_priv *priv =dev_get_priv (dev);struct dwmci_host *host = &priv->host;
@@ -73,7 +79,7 @@ static int rockchip_dwmmc_ofdata_to_platdata(struct udevice *dev)if (fdtdec_get_int_array (gd->fdt_blob, dev->of_offset,"clock-freq-min-max" , priv->minmax,2 ))return -EINVAL ; - +#endif return 0 ; }
@@ -86,10 +92,27 @@ static int rockchip_dwmmc_probe(struct udevice *dev)struct udevice *pwr_dev__maybe_unused ;int ret; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +struct dtd_rockchip_rk3288_dw_mshc *dtplat = &plat->dtplat; + + host->name = dev->name; + host->ioaddr =map_sysmem (dtplat->reg[0 ], dtplat->reg[1 ]); + host->buswidth = dtplat->bus_width; + host->get_mmc_clk = rockchip_dwmmc_get_mmc_clk; + host->priv = dev; + host->dev_index =0 ; + priv->fifo_depth = dtplat->fifo_depth; + priv->fifo_mode =0 ; +memcpy (priv->minmax, dtplat->clock_freq_min_max,sizeof (priv->minmax)); + + ret =clk_get_by_index_platdata (dev,0 , dtplat->clocks, &priv->clk); +if (ret <0 ) +return ret; +#else ret =clk_get_by_index (dev,0 , &priv->clk);if (ret <0 )return ret; - +#endif host->fifoth_val =MSIZE (0x2 ) |RX_WMARK (priv->fifo_depth /2 -1 ) |TX_WMARK (priv->fifo_depth /2 );
@@ -134,7 +157,7 @@ static const struct udevice_id rockchip_dwmmc_ids[] = { };U_BOOT_DRIVER (rockchip_dwmmc_drv) = { - .name ="rockchip_dwmmc" , + .name ="rockchip_rk3288_dw_mshc" , .id =UCLASS_MMC , .of_match = rockchip_dwmmc_ids, .ofdata_to_platdata = rockchip_dwmmc_ofdata_to_platdata,
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 47/62 rockchip: mmc: Update the driver to support of-platdata
Quoted 4 lines · Simon Glass
Add support for of-platdata with rk3288. This requires decoding the of-platdata struct and setting up the device from that. Also the driver needs to be renamed to match the string that of-platdata will search for.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/mmc/rockchip_dw_mmc.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
Applied to u-boot-dm
PATCH v3 48/62 rockchip: clk: Move all DT decoding to ofdata_to_platdata()
In reply to Simon GlassIt is more correct to avoid touching the device tree in the probe() method. Update the driver to work this way. Also add an error check on grf since if that fails then we should not use it.
---
Changes in v3:
- Rebase to master
Changes in v2: None
drivers/clk/clk_rk3288.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/clk/clk_rk3288.c +12 -1
@@ -783,12 +783,22 @@ static struct clk_ops rk3288_clk_ops = { .set_rate = rk3288_clk_set_rate, }; -static int rk3288_clk_probe (struct udevice *dev) +static int rk3288_clk_ofdata_to_platdata (struct udevice *dev) {struct rk3288_clk_priv *priv =dev_get_priv (dev); priv->cru = (struct rk3288_cru *)dev_get_addr (dev); + +return 0 ; +} + +static int rk3288_clk_probe (struct udevice *dev) +{ +struct rk3288_clk_priv *priv =dev_get_priv (dev); + priv->grf =syscon_get_first_range (ROCKCHIP_SYSCON_GRF ); +if (IS_ERR (priv->grf)) +return PTR_ERR (priv->grf);#ifdef CONFIG_SPL_BUILD rkclk_init (priv->cru, priv->grf);#endif
@@ -820,5 +830,6 @@ U_BOOT_DRIVER(clk_rk3288) = { .priv_auto_alloc_size = sizeof(struct rk3288_clk_priv), .ops = &rk3288_clk_ops, .bind = rk3288_clk_bind, + .ofdata_to_platdata = rk3288_clk_ofdata_to_platdata, .probe = rk3288_clk_probe, };
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 48/62 rockchip: clk: Move all DT decoding to ofdata_to_platdata()
Quoted 7 lines · Simon Glass
It is more correct to avoid touching the device tree in the
probe()method. Update the driver to work this way. Also add an error check on grf since if that fails then we should not use it.Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v3:
- Rebase to masterChanges in v2: None
drivers/clk/clk_rk3288.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 49/62 rockchip: clk: Update the rk3288 driver to support of-platdata
In reply to Simon GlassAdd support for of-platdata with rk3288. This requires decoding the of-platdata struct and setting up the devices from that. Also the driver needs to be renamed to match the string that of-platdata will search for.
---
Changes in v3:
- Rebase to master
Changes in v2: None
drivers/clk/clk_rk3288.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/clk/clk_rk3288.c +18 -2
@@ -7,7 +7,9 @@#include <common.h> #include <clk-uclass.h> #include <dm.h> +#include <dt-structs.h> #include <errno.h> +#include <mapmem.h> #include <syscon.h> #include <asm/io.h> #include <asm/arch/clock.h>
@@ -21,6 +23,12 @@DECLARE_GLOBAL_DATA_PTR ; +struct rk3288_clk_plat { +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +struct dtd_rockchip_rk3288_cru dtd; +#endif +}; +struct rk3288_clk_priv {struct rk3288_grf *grf;struct rk3288_cru *cru;
@@ -785,9 +793,11 @@ static struct clk_ops rk3288_clk_ops = {static int rk3288_clk_ofdata_to_platdata (struct udevice *dev) { +#if !CONFIG_IS_ENABLED (OF_PLATDATA )struct rk3288_clk_priv *priv =dev_get_priv (dev); priv->cru = (struct rk3288_cru *)dev_get_addr (dev); +#endif return 0 ; }
@@ -800,6 +810,11 @@ static int rk3288_clk_probe(struct udevice *dev)if (IS_ERR (priv->grf))return PTR_ERR (priv->grf);#ifdef CONFIG_SPL_BUILD +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +struct rk3288_clk_plat *plat =dev_get_platdata (dev); + + priv->cru =map_sysmem (plat->dtd.reg[0 ], plat->dtd.reg[1 ]); +#endif rkclk_init (priv->cru, priv->grf);#endif
@@ -823,11 +838,12 @@ static const struct udevice_id rk3288_clk_ids[] = { { } }; -U_BOOT_DRIVER (clk_rk3288) = { - .name ="clk_rk3288" , +U_BOOT_DRIVER (rockchip_rk3288_cru) = { + .name ="rockchip_rk3288_cru" , .id =UCLASS_CLK , .of_match = rk3288_clk_ids, .priv_auto_alloc_size =sizeof (struct rk3288_clk_priv ), + .platdata_auto_alloc_size =sizeof (struct rk3288_clk_plat ), .ops = &rk3288_clk_ops, .bind = rk3288_clk_bind, .ofdata_to_platdata = rk3288_clk_ofdata_to_platdata,
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 49/62 rockchip: clk: Update the rk3288 driver to support of-platdata
Quoted 7 lines · Simon Glass
Add support for of-platdata with rk3288. This requires decoding the of-platdata struct and setting up the devices from that. Also the driver needs to be renamed to match the string that of-platdata will search for.
Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v3:
- Rebase to masterChanges in v2: None
drivers/clk/clk_rk3288.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
Applied to u-boot-dm
PATCH v3 50/62 rockchip: pinctrl: Update the rk3288 driver to support of-platdata
In reply to Simon GlassAdd support for of-platdata with rk3288. This requires disabling access to the device tree and renaming the driver to match the string that of-platdata will search for.
---
Changes in v3: None
Changes in v2: None
drivers/pinctrl/rockchip/pinctrl_rk3288.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl_rk3288.c +7 -1
@@ -476,6 +476,7 @@ static int rk3288_pinctrl_request(struct udevice *dev, int func, int flags)static int rk3288_pinctrl_get_periph_id (struct udevice *dev,struct udevice *periph) { +#if !CONFIG_IS_ENABLED (OF_PLATDATA )u32 cell[3 ];int ret;
@@ -506,6 +507,7 @@ static int rk3288_pinctrl_get_periph_id(struct udevice *dev,case 103 : return PERIPH_ID_HDMI; } +#endif return -ENOENT ; }
@@ -664,8 +666,12 @@ static struct pinctrl_ops rk3288_pinctrl_ops = {static int rk3288_pinctrl_bind (struct udevice *dev) { +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +return 0 ; +#else /* scan child GPIO banks */ return dm_scan_fdt_node (dev, gd->fdt_blob, dev->of_offset, false); +#endif }#ifndef CONFIG_SPL_BUILD
@@ -719,7 +725,7 @@ static const struct udevice_id rk3288_pinctrl_ids[] = { };U_BOOT_DRIVER (pinctrl_rk3288) = { - .name ="pinctrl_rk3288" , + .name ="rockchip_rk3288_pinctrl" , .id =UCLASS_PINCTRL , .of_match = rk3288_pinctrl_ids, .priv_auto_alloc_size =sizeof (struct rk3288_pinctrl_priv ),
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 50/62 rockchip: pinctrl: Update the rk3288 driver to support of-platdata
Quoted 4 lines · Simon Glass
Add support for of-platdata with rk3288. This requires disabling access to the device tree and renaming the driver to match the string that of-platdata will search for.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonedrivers/pinctrl/rockchip/pinctrl_rk3288.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 51/62 rockchip: Move the MMC setup check earlier
In reply to Simon GlassWhen the boot ROM sets up MMC we don't need to do it again. Remove the MMC setup code entirely.
---
Changes in v3: None
Changes in v2: None
arch/arm/mach-rockchip/rk3288-board-spl.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
arch/arm/mach-rockchip/rk3288-board-spl.c +12 -11
@@ -114,7 +114,6 @@ static void configure_l2ctlr(void)#ifdef CONFIG_SPL_MMC_SUPPORT static int configure_emmc (struct udevice *pinctrl) { -#if !defined(CONFIG_TARGET_ROCK2 ) && !defined(CONFIG_TARGET_FIREFLY_RK3288 )struct gpio_desc desc;int ret;
@@ -144,7 +143,6 @@ static int configure_emmc(struct udevice *pinctrl)debug ("gpio value ret=%d\n" , ret);return ret; } -#endif return 0 ; }
@@ -247,15 +245,18 @@ void spl_board_init(void) goto err; }#ifdef CONFIG_SPL_MMC_SUPPORT - ret =pinctrl_request_noflags (pinctrl,PERIPH_ID_SDCARD ); -if (ret) { -debug ("%s: Failed to set up SD card\n" , __func__); - goto err; - } - ret =configure_emmc (pinctrl); -if (ret) { -debug ("%s: Failed to set up eMMC\n" , __func__); - goto err; +if (!IS_ENABLED (CONFIG_TARGET_ROCK2 ) && + !IS_ENABLED (CONFIG_TARGET_FIREFLY_RK3288 )) { + ret =pinctrl_request_noflags (pinctrl,PERIPH_ID_SDCARD ); +if (ret) { +debug ("%s: Failed to set up SD card\n" , __func__); + goto err; + } + ret =configure_emmc (pinctrl); +if (ret) { +debug ("%s: Failed to set up eMMC\n" , __func__); + goto err; + } }#endif
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 51/62 rockchip: Move the MMC setup check earlier
Quoted 11 lines · Simon Glass
When the boot ROM sets up MMC we don't need to do it again. Remove the MMC setup code entirely.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/arm/mach-rockchip/rk3288-board-spl.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
Applied to u-boot-dm
PATCH v3 52/62 rockchip: Don't use spl_boot_device() with of-platdata
In reply to Simon GlassThis function cannot look at the device tree when of-platdata is used. Update the code to handle this.
---
Changes in v3: None
Changes in v2: None
arch/arm/mach-rockchip/rk3288-board-spl.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm/mach-rockchip/rk3288-board-spl.c +2 -0
@@ -29,6 +29,7 @@ DECLARE_GLOBAL_DATA_PTR;u32 spl_boot_device (void ) { +#if !CONFIG_IS_ENABLED (OF_PLATDATA )const void *blob = gd->fdt_blob;struct udevice *dev;const char *bootdev;
@@ -63,6 +64,7 @@ u32 spl_boot_device(void) } fallback: +#endif return BOOT_DEVICE_MMC1 ; }
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 52/62 rockchip: Don't use spl_boot_device() with of-platdata
Quoted 11 lines · Simon Glass
This function cannot look at the device tree when of-platdata is used. Update the code to handle this.
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/arm/mach-rockchip/rk3288-board-spl.c | 2 ++ 1 file changed, 2 insertions(+)
Applied to u-boot-dm
PATCH v3 53/62 rockchip: syscon: Update to work with of-platdata
In reply to Simon GlassThe syscon devices all end up having diffent driver names with of-platdata, since the driver name comes from the first string in the compatible list. Add separate device declarations for each one, and add a bind method to set up driver_data correctly.
---
Changes in v3: None
Changes in v2: None
arch/arm/mach-rockchip/rk3288/syscon_rk3288.c | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
arch/arm/mach-rockchip/rk3288/syscon_rk3288.c +38 -0
@@ -23,3 +23,41 @@ U_BOOT_DRIVER(syscon_rk3288) = { .id = UCLASS_SYSCON, .of_match = rk3288_syscon_ids, }; + +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +static int rk3288_syscon_bind_of_platdata (struct udevice *dev) +{ + dev->driver_data = dev->driver->of_match->data; +debug ("syscon: %s %d\n" , dev->name, (uint )dev->driver_data); + +return 0 ; +} + +U_BOOT_DRIVER (rockchip_rk3288_noc) = { + .name ="rockchip_rk3288_noc" , + .id =UCLASS_SYSCON , + .of_match = rk3288_syscon_ids, + .bind = rk3288_syscon_bind_of_platdata, +}; + +U_BOOT_DRIVER (rockchip_rk3288_grf) = { + .name ="rockchip_rk3288_grf" , + .id =UCLASS_SYSCON , + .of_match = rk3288_syscon_ids +1 , + .bind = rk3288_syscon_bind_of_platdata, +}; + +U_BOOT_DRIVER (rockchip_rk3288_sgrf) = { + .name ="rockchip_rk3288_sgrf" , + .id =UCLASS_SYSCON , + .of_match = rk3288_syscon_ids +2 , + .bind = rk3288_syscon_bind_of_platdata, +}; + +U_BOOT_DRIVER (rockchip_rk3288_pmu) = { + .name ="rockchip_rk3288_pmu" , + .id =UCLASS_SYSCON , + .of_match = rk3288_syscon_ids +3 , + .bind = rk3288_syscon_bind_of_platdata, +}; +#endif
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 53/62 rockchip: syscon: Update to work with of-platdata
Quoted 5 lines · Simon Glass
The syscon devices all end up having diffent driver names with of-platdata, since the driver name comes from the first string in the compatible list. Add separate device declarations for each one, and add a bind method to set up
driver_datacorrectly.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/arm/mach-rockchip/rk3288/syscon_rk3288.c | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
Applied to u-boot-dm
PATCH v3 54/62 rockchip: sdram: Move all DT decoding to ofdata_to_platdata()
In reply to Simon GlassIt is more correct to avoid touching the device tree in the probe() method. Update the driver to work this way. Note that only SPL needs to fiddle with the SDRAM registers, so decoding the platform data fully is not necessary in U-Boot proper.
---
Changes in v3: None
Changes in v2: None
arch/arm/include/asm/arch-rockchip/sdram.h | 8 --- arch/arm/mach-rockchip/rk3288/sdram_rk3288.c | 94 +++++++++++++++++++--------- 2 files changed, 64 insertions(+), 38 deletions(-)
arch/arm/include/asm/arch-rockchip/sdram.h +0 -8
@@ -87,12 +87,4 @@ struct rk3288_base_params { u32 odt; }; -struct rk3288_sdram_params { -struct rk3288_sdram_channel ch[2 ]; -struct rk3288_sdram_pctl_timing pctl_timing; -struct rk3288_sdram_phy_timing phy_timing; -struct rk3288_base_params base; -int num_channels; -}; -#endif
arch/arm/mach-rockchip/rk3288/sdram_rk3288.c +64 -30
156 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 54/62 rockchip: sdram: Move all DT decoding to ofdata_to_platdata()
Quoted 6 lines · Simon Glass
It is more correct to avoid touching the device tree in the
probe()method. Update the driver to work this way. Note that only SPL needs to fiddle with the SDRAM registers, so decoding the platform data fully is not necessary in U-Boot proper.Signed-off-by Simon Glass <[email protected]>
Quoted 8 lines
---
Changes in v3: None
Changes in v2: Nonearch/arm/include/asm/arch-rockchip/sdram.h | 8 --- arch/arm/mach-rockchip/rk3288/sdram_rk3288.c | 94 +++++++++++++++++++--------- 2 files changed, 64 insertions(+), 38 deletions(-)
Applied to u-boot-dm
PATCH v3 55/62 rockchip: sdram: Update the driver to support of-platdata
In reply to Simon GlassAdd support for of-platdata with rk3288 SDRAM initr. This requires decoding the of-platdata struct and setting up the device from that. Also the driver needs to be renamed to match the string that of-platdata will search for.
The platform data is copied from the of-platdata structure to the one used by the driver. This allows the same code to be used with device tree and of-platdata.
---
Changes in v3: None
Changes in v2: None
arch/arm/mach-rockchip/rk3288/sdram_rk3288.c | 40 +++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)
arch/arm/mach-rockchip/rk3288/sdram_rk3288.c +39 -1
@@ -10,6 +10,7 @@#include <common.h> #include <clk.h> #include <dm.h> +#include <dt-structs.h> #include <errno.h> #include <ram.h> #include <regmap.h>
@@ -45,6 +46,9 @@ struct dram_info { };struct rk3288_sdram_params { +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +struct dtd_rockchip_rk3288_dmc of_plat; +#endif struct rk3288_sdram_channel ch[2 ];struct rk3288_sdram_pctl_timing pctl_timing;struct rk3288_sdram_phy_timing phy_timing;
@@ -806,6 +810,7 @@ static int setup_sdram(struct udevice *dev)static int rk3288_dmc_ofdata_to_platdata (struct udevice *dev) { +#if !CONFIG_IS_ENABLED (OF_PLATDATA )struct rk3288_sdram_params *params =dev_get_platdata (dev);const void *blob = gd->fdt_blob;int node = dev->of_offset;
@@ -853,11 +858,39 @@ static int rk3288_dmc_ofdata_to_platdata(struct udevice *dev) ret =regmap_init_mem (dev, ¶ms->map);if (ret)return ret; +#endif return 0 ; }#endif /* CONFIG_SPL_BUILD */ +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +static int conv_of_platdata (struct udevice *dev) +{ +struct rk3288_sdram_params *plat =dev_get_platdata (dev); +struct dtd_rockchip_rk3288_dmc *of_plat = &plat->of_plat; +int i, ret; + +for (i =0 ; i <2 ; i++) { +memcpy (&plat->ch[i], of_plat->rockchip_sdram_channel, +sizeof (plat->ch[i])); + } +memcpy (&plat->pctl_timing, of_plat->rockchip_pctl_timing, +sizeof (plat->pctl_timing)); +memcpy (&plat->phy_timing, of_plat->rockchip_phy_timing, +sizeof (plat->phy_timing)); +memcpy (&plat->base, of_plat->rockchip_sdram_params,sizeof (plat->base)); + plat->num_channels = of_plat->rockchip_num_channels; + ret =regmap_init_mem_platdata (dev, of_plat->reg, +ARRAY_SIZE (of_plat->reg) /2 , + &plat->map); +if (ret) +return ret; + +return 0 ; +} +#endif +static int rk3288_dmc_probe (struct udevice *dev) {#ifdef CONFIG_SPL_BUILD
@@ -868,6 +901,11 @@ static int rk3288_dmc_probe(struct udevice *dev)int ret;struct udevice *dev_clk; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) + ret =conv_of_platdata (dev); +if (ret) +return ret; +#endif map =syscon_get_regmap_by_driver_data (ROCKCHIP_SYSCON_NOC );if (IS_ERR (map))return PTR_ERR (map);
@@ -926,7 +964,7 @@ static const struct udevice_id rk3288_dmc_ids[] = { };U_BOOT_DRIVER (dmc_rk3288) = { - .name ="rk3288_dmc" , + .name ="rockchip_rk3288_dmc" , .id =UCLASS_RAM , .of_match = rk3288_dmc_ids, .ops = &rk3288_dmc_ops,
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 55/62 rockchip: sdram: Update the driver to support of-platdata
Quoted 8 lines · Simon Glass
Add support for of-platdata with rk3288 SDRAM initr. This requires decoding the of-platdata struct and setting up the device from that. Also the driver needs to be renamed to match the string that of-platdata will search for.
The platform data is copied from the of-platdata structure to the one used by the driver. This allows the same code to be used with device tree and of-platdata.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Nonearch/arm/mach-rockchip/rk3288/sdram_rk3288.c | 40 +++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 56/62 rockchip: Use of-platdata for firefly-rk3288
In reply to Simon GlassAs an experiment, move this board over to use of-platdata. This means that its SPL configuration will come from C structures generated at build-time from the device tree, instead of coming from the device tree at run-time.
---
Changes in v3: None
Changes in v2: None
configs/firefly-rk3288_defconfig | 3 +++ 1 file changed, 3 insertions(+)
configs/firefly-rk3288_defconfig +3 -0
@@ -69,3 +69,6 @@ CONFIG_USE_PRIVATE_LIBGCC=y CONFIG_USE_TINY_PRINTF=y CONFIG_CMD_DHRYSTONE=y CONFIG_ERRNO_STR=y +CONFIG_SPL_OF_PLATDATA=y +# CONFIG_SPL_OF_LIBFDT is not set +CONFIG_ROCKCHIP_SERIAL=y
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 56/62 rockchip: Use of-platdata for firefly-rk3288
Quoted 4 lines · Simon Glass
As an experiment, move this board over to use of-platdata. This means that its SPL configuration will come from C structures generated at build-time from the device tree, instead of coming from the device tree at run-time.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: Noneconfigs/firefly-rk3288_defconfig | 3 +++ 1 file changed, 3 insertions(+)
Applied to u-boot-dm
PATCH v3 57/62 test/py: Handle testing with the sandbox_spl board
In reply to Simon GlassThis board can sometimes be used for tests. Handle it the same way as sandbox.
Note: I plan to drop the sandbox_spl board at some point and merge its features into sandbox. So this commit may not be necessary.
---
Changes in v3:
- Add new patch to handle testing with the sandbox_spl board
Changes in v2: None
test/py/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
test/py/conftest.py +1 -1
@@ -193,7 +193,7 @@ def pytest_configure(config): for v in env_vars: os.environ['U_BOOT_' + v.upper()] = getattr(ubconfig, v) - if board_type == 'sandbox': + if board_type.startswith('sandbox'): import u_boot_console_sandbox console = u_boot_console_sandbox.ConsoleSandbox(log, ubconfig) else:
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 57/62 test/py: Handle testing with the sandbox_spl board
Quoted 9 lines · Simon Glass
This board can sometimes be used for tests. Handle it the same way as sandbox.
Note: I plan to drop the
sandbox_splboard at some point and merge its features into sandbox. So this commit may not be necessary.Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v3:
- Add new patch to handle testing with thesandbox_splboardChanges in v2: None
test/py/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 58/62 test/py: Note which console produced unexpected output
In reply to Simon GlassAt present the SPL and U-Boot consoles both present the same error message when the expected console output does not appear. Add "SPL" to the SPL error message to resolve this ambiguity.
---
Changes in v3:
- Add new patch to note which console produced unexpected output
Changes in v2: None
test/py/u_boot_console_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
test/py/u_boot_console_base.py +1 -1
@@ -345,7 +345,7 @@ class ConsoleBase(object): m = self.p.expect([pattern_u_boot_spl_signon] + self.bad_patterns) if m != 0: - raise Exception('Bad pattern found on console: ' + + raise Exception('Bad pattern found on SPL console: ' + self.bad_pattern_ids[m - 1]) m = self.p.expect([pattern_u_boot_main_signon] + self.bad_patterns) if m != 0:
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 59/62 test/py: Provide a way to get early console output
In reply to Simon GlassSome tests want to check the console output from SPL or U-Boot proper. Provide a means to do this.
---
Changes in v3:
- Add new patch to provide a way to get early console output
Changes in v2: None
test/py/u_boot_console_base.py | 10 ++++++++++ test/py/u_boot_spawn.py | 13 +++++++++++++ 2 files changed, 23 insertions(+)
test/py/u_boot_console_base.py +10 -0
@@ -393,6 +393,16 @@ class ConsoleBase(object): pass self.p = None + def get_spawn_output(self): + """Return the start-up output from U-Boot + + Returns: + The output produced by ensure_spawed(), as a string. + """ + if self.p: + return self.p.get_expect_output() + return None + def validate_version_string_in_text(self, text): """Assert that a command's output includes the U-Boot signon message.
test/py/u_boot_spawn.py +13 -0
@@ -18,6 +18,9 @@ class Timeout(Exception): class Spawn(object): """Represents the stdio of a freshly created sub-process. Commands may be sent to the process, and responses waited for. + + Members: + output: accumulated output from expect() """ def __init__(self, args, cwd=None):
@@ -34,6 +37,7 @@ class Spawn(object): self.waited = False self.buf = '' + self.output = '' self.logfile_read = None self.before = '' self.after = ''
@@ -149,6 +153,7 @@ class Spawn(object): posafter = earliest_m.end() self.before = self.buf[:pos] self.after = self.buf[pos:posafter] + self.output += self.buf[:posafter] self.buf = self.buf[posafter:] return earliest_pi tnow_s = time.time()
@@ -189,3 +194,11 @@ class Spawn(object): if not self.isalive(): break time.sleep(0.1) + + def get_expect_output(self): + """Return the output read by expect() + + Returns: + The output processed by expect(), as a string. + """ + return self.output
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 59/62 test/py: Provide a way to get early console output
Quoted 6 lines · Simon Glass
Some tests want to check the console output from SPL or U-Boot proper. Provide a means to do this.
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Changes in v3:
- Add new patch to provide a way to get early console outputChanges in v2: None
test/py/u_boot_console_base.py | 10 ++++++++++ test/py/u_boot_spawn.py | 13 +++++++++++++ 2 files changed, 23 insertions(+)
Applied to u-boot-dm
PATCH v3 60/62 test/py: Start sandbox SPL when enabled
In reply to Simon GlassWhen sandbox SPL is enabled we want to start that rather than U-Boot proper, since some tests may rely on running it first.
---
Changes in v3:
- Add new patch to start sandbox SPL when enabled
Changes in v2: None
test/py/u_boot_console_sandbox.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
test/py/u_boot_console_sandbox.py +5 -1
@@ -39,11 +39,15 @@ class ConsoleSandbox(ConsoleBase): A u_boot_spawn.Spawn object that is attached to U-Boot. """ + bcfg = self.config.buildconfig + config_spl = bcfg.get('config_spl', 'n') == 'y' + fname = '/spl/u-boot-spl' if config_spl else '/u-boot' + print fname cmd = [] if self.config.gdbserver: cmd += ['gdbserver', self.config.gdbserver] cmd += [ - self.config.build_dir + '/u-boot', + self.config.build_dir + fname, '-v', '-d', self.config.dtb
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 60/62 test/py: Start sandbox SPL when enabled
Quoted 6 lines · Simon Glass
When sandbox SPL is enabled we want to start that rather than U-Boot proper, since some tests may rely on running it first.
Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v3:
- Add new patch to start sandbox SPL when enabledChanges in v2: None
test/py/u_boot_console_sandbox.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Applied to u-boot-dm
PATCH v3 61/62 dm: Add a test for of-platdata
In reply to Simon GlassAdd a simple test which checks that the of-platdata system is working correctly. The sequence is as follows:
- SPL starts up and probes all the UCLASS_MISC drivers
- There are 3 of these in sandbox.dts
- Therefore there should be 3 U_BOOT_DEVICE() declarations in dt-platdata.c
- These should produce 3 sandbox_spl_test devices
- Each device prints out its platform data when probed
- This test checks for this output and compares it against expectations
---
Changes in v3:
- Add new patch to test of-platdata
Changes in v2: None
test/py/tests/test_ofplatdata.py | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/py/tests/test_ofplatdata.py
test/py/tests/test_ofplatdata.py new file +42 -0
@@ -0,0 +1,42 @@ +# Copyright (c) 2016 Google, Inc +# +# SPDX-License-Identifier: GPL-2.0+ + +import pytest + +OF_PLATDATA_OUTPUT = ''' +of-platdata probe: +bool 1 +byte 05 +bytearray 06 00 00 +int 1 +intarray 2 3 4 0 +longbytearray 09 0a 0b 0c 0d 0e 0f 10 11 +string message +stringarray "multi-word" "message" "" +of-platdata probe: +bool 0 +byte 08 +bytearray 01 23 34 +int 3 +intarray 5 0 0 0 +longbytearray 09 00 00 00 00 00 00 00 00 +string message2 +stringarray "another" "multi-word" "message" +of-platdata probe: +bool 0 +byte 00 +bytearray 00 00 00 +int 0 +intarray 0 0 0 0 +longbytearray 00 00 00 00 00 00 00 00 00 +string <NULL> +stringarray "one" "" "" +''' + + at pytest.mark.buildconfigspec('spl') +def test_ofplatdata(u_boot_console): + """Test that of-platdata can be generated and used in sandbox""" + cons = u_boot_console + output = cons.get_spawn_output().replace('\r', '') + assert OF_PLATDATA_OUTPUT in output
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 61/62 dm: Add a test for of-platdata
Quoted 13 lines · Simon Glass
Add a simple test which checks that the of-platdata system is working correctly. The sequence is as follows:
- SPL starts up and probes all the
UCLASS_MISCdrivers
- There are 3 of these insandbox.dts
- Therefore there should be 3U_BOOT_DEVICE()declarations indt-platdata.c
- These should produce 3sandbox_spl_testdevices
- Each device prints out its platform data when probed
- This test checks for this output and compares it against expectationsSigned-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Changes in v3:
- Add new patch to test of-platdataChanges in v2: None
test/py/tests/test_ofplatdata.py | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/py/tests/test_ofplatdata.py
Applied to u-boot-dm
PATCH v3 62/62 dm: Update the of-platdata README for the new features
In reply to Simon GlassRevise the content based on the v2 additions. This is kept as a separate patch to avoid confusing those who have already reviewed the v1 series.
---
Changes in v3:
- Add a test for of-platdata
Changes in v2:
- Add support for rockchip
- Various minor enhancements to the v1 implementation
doc/driver-model/of-plat.txt | 110 ++++++++++++++++++++++++++++++------------- 1 file changed, 76 insertions(+), 34 deletions(-)
doc/driver-model/of-plat.txt +76 -34
@@ -19,24 +19,28 @@ SoCs require a 16KB SPL image which must include a full MMC stack. In this case the overhead of device tree access may be too great. It is possible to create platform data manually by defining C structures -for it, and referencing that data in a U_BOOT_DEVICE() declaration. This -bypasses the use of device tree completely, but is an available option for -SPL. +for it, and reference that data in a U_BOOT_DEVICE() declaration. This +bypasses the use of device tree completely, effectively creating a parallel +configuration mechanism. But it is an available option for SPL. -As an alternative, a new 'of-platdata' feature is provided. This converts +As an alternative, a new 'of-platdata' feature is provided. This converts the device tree contents into C code which can be compiled into the SPL binary. This saves the 3KB of code overhead and perhaps a few hundred more bytes due to more efficient storage of the data. +Note: Quite a bit of thought has gone into the design of this feature. +However it still has many rough edges and comments and suggestions are +strongly encouraged! Quite possibly there is a much better approach. + Caveats ------- There are many problems with this features. It should only be used when -stricly necessary. Notable problems include: +strictly necessary. Notable problems include: - - Device tree does not describe data types but the C code must define a - type for each property. Thesee are guessed using heuristics which + - Device tree does not describe data types. But the C code must define a + type for each property. These are guessed using heuristics which are wrong in several fairly common cases. For example an 8-byte value is considered to be a 2-item integer array, and is byte-swapped. A boolean value that is not present means 'false', but cannot be
@@ -45,14 +49,15 @@ stricly necessary. Notable problems include: - Naming of nodes and properties is automatic. This means that they follow the naming in the device tree, which may result in C identifiers that - look a bit strange + look a bit strange. - It is not possible to find a value given a property name. Code must use the associated C member variable directly in the code. This makes the code less robust in the face of device-tree changes. It also makes it very unlikely that your driver code will be useful for more than one SoC. Even if the code is common, each SoC will end up with - a different C struct and format for the platform data. + a different C struct name, and a likely a different format for the + platform data. - The platform data is provided to drivers as a C structure. The driver must use the same structure to access the data. Since a driver
@@ -112,7 +117,6 @@ struct dtd_rockchip_rk3288_dw_mshc { fdt32_t interrupts[3]; fdt32_t num_slots; fdt32_t reg[2]; - bool u_boot_dm_pre_reloc; fdt32_t vmmc_supply; };
@@ -125,7 +129,10 @@ static struct dtd_rockchip_rk3288_dw_mshc dtv_dwmmc_at_ff0c0000 = { .clock_freq_min_max = {0x61a80, 0x8f0d180}, .vmmc_supply = 0xb, .num_slots = 0x1, - .clocks = {{&dtv_clock_controller_at_ff760000, 456}, {&dtv_clock_controller_at_ff760000, 68}, {&dtv_clock_controller_at_ff760000, 114}, {&dtv_clock_controller_at_ff760000, 118}}, + .clocks = {{&dtv_clock_controller_at_ff760000, 456}, + {&dtv_clock_controller_at_ff760000, 68}, + {&dtv_clock_controller_at_ff760000, 114}, + {&dtv_clock_controller_at_ff760000, 118}}, .cap_mmc_highspeed = true, .disable_wp = true, .bus_width = 0x4,
@@ -136,6 +143,7 @@ static struct dtd_rockchip_rk3288_dw_mshc dtv_dwmmc_at_ff0c0000 = { U_BOOT_DEVICE(dwmmc_at_ff0c0000) = { .name = "rockchip_rk3288_dw_mshc", .platdata = &dtv_dwmmc_at_ff0c0000, + .platdata_size = sizeof(dtv_dwmmc_at_ff0c0000), }; The device is then instantiated at run-time and the platform data can be
@@ -149,15 +157,31 @@ platform data in the driver. The ofdata_to_platdata() method should therefore do nothing in such a driver. +Converting of-platdata to a useful form +--------------------------------------- + +Of course it would be possible use the of-platdata directly in your driver +whenever configuration information is required. However this meands that the +driver will not be able to support device tree, since the of-platdata +structure is not available when device tree is used. It would make no sense +to use this structure if device tree were available, since the structure has +all the limitations metioned in caveats above. + +Therefore it is recommended that the of-platdata structure should be used +only in the probe() method of your driver. It cannot be used in the +ofdata_to_platdata() method since this is not called when platform data is +already present. + + How to structure your driver ---------------------------- Drivers should always support device tree as an option. The of-platdata feature is intended as a add-on to existing drivers. -Your driver should directly access the platdata struct in its probe() -method. The existing device tree decoding logic should be kept in the -ofdata_to_platdata() and wrapped with #ifdef. +Your driver should convert the platdata struct in its probe() method. The +existing device tree decoding logic should be kept in the +ofdata_to_platdata() method and wrapped with #if. For example:
@@ -165,13 +189,12 @@ For example: struct mmc_platdata { #if CONFIG_IS_ENABLED(SPL_OF_PLATDATA) - /* Put this first */ + /* Put this first since driver model will copy the data here */ struct dtd_mmc dtplat; #endif /* * Other fields can go here, to be filled in by decoding from - * the device tree. They will point to random memory in the - * of-plat case. + * the device tree (or the C structures when of-platdata is used). */ int fifo_depth; };
@@ -179,6 +202,7 @@ For example: static int mmc_ofdata_to_platdata(struct udevice *dev) { #if !CONFIG_IS_ENABLED(SPL_OF_PLATDATA) + /* Decode the device tree data */ struct mmc_platdata *plat = dev_get_platdata(dev); const void *blob = gd->fdt_blob; int node = dev->of_offset;
@@ -192,15 +216,15 @@ For example: static int mmc_probe(struct udevice *dev) { struct mmc_platdata *plat = dev_get_platdata(dev); + #if CONFIG_IS_ENABLED(SPL_OF_PLATDATA) + /* Decode the of-platdata from the C structures */ struct dtd_mmc *dtplat = &plat->dtplat; - /* Set up the device from the dtplat data */ - writel(dtplat->fifo_depth, ...) - #else + plat->fifo_depth = dtplat->fifo_depth; + #endif /* Set up the device from the plat data */ writel(plat->fifo_depth, ...) - #endif } static const struct udevice_id mmc_ids[] = {
@@ -220,15 +244,26 @@ For example: In the case where SPL_OF_PLATDATA is enabled, platdata_auto_alloc_size is -ignored, and the platform data points to the C structure data. In the case -where device tree is used, the platform data is allocated, and starts -zeroed. In this case the ofdata_to_platdata() method should set up the -platform data. +still used to allocate space for the platform data. This is different from +the normal behaviour and is triggered by the use of of-platdata (strictly +speaking it is a non-zero platdata_size which triggers this). -SPL must use either of-platdata or device tree. Drivers cannot use both. -The device tree becomes in accessible when CONFIG_SPL_OF_PLATDATA is enabled, -since the device-tree access code is not compiled in. +The of-platdata struct contents is copied from the C structure data to the +start of the newly allocated area. In the case where device tree is used, +the platform data is allocated, and starts zeroed. In this case the +ofdata_to_platdata() method should still set up the platform data (and the +of-platdata struct will not be present). + +SPL must use either of-platdata or device tree. Drivers cannot use both at +the same time, but they must support device tree. Supporting of-platdata is +optional. +The device tree becomes in accessible when CONFIG_SPL_OF_PLATDATA is enabled, +since the device-tree access code is not compiled in. A corollary is that +a board can only move to using of-platdata if all the drivers it uses support +it. There would be little point in having some drivers require the device +tree data, since then libfdt would still be needed for those drivers and +there would be no code-size benefit. Internals ---------
@@ -236,7 +271,8 @@ Internals The dt-structs.h file includes the generated file (include/generated//dt-structs.h) if CONFIG_SPL_OF_PLATDATA is enabled. Otherwise (such as in U-Boot proper) these structs are not available. This -prevents them being used inadvertently. +prevents them being used inadvertently. All usage must be bracketed with +#if CONFIG_IS_ENABLED(SPL_OF_PLATDATA). The dt-platdata.c file contains the device declarations and is is built in spl/dt-platdata.c.
@@ -249,20 +285,26 @@ yet implemented, however. The beginnings of a libfdt Python module are provided. So far this only implements a subset of the features. -The 'swig' tool is needed to build the libfdt Python module. +The 'swig' tool is needed to build the libfdt Python module. If this is not +found then the Python model is not used and a fallback is used instead, which +makes use of fdtget. + + +Credits +------- + +This is an implementation of an idea by Tom Rini <[email protected]>. Future work ----------- -- Add unit tests -- Add a sandbox_spl functional test - Consider programmatically reading binding files instead of device tree contents -- Drop the device tree data from the SPL image - Complete the phandle feature -- Get this running on a Rockchip board - Move to using a full Python libfdt module -- Simon Glass <[email protected]> +Google, Inc 6/6/16 +Updated Independence Day 2016
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH v3 62/62 dm: Update the of-platdata README for the new features
Quoted 10 lines · Simon Glass
Revise the content based on the v2 additions. This is kept as a separate patch to avoid confusing those who have already reviewed the v1 series.
Signed-off-by Simon Glass <[email protected]>Suggested-by Tom Rini <[email protected]>---
Changes in v3:
- Add a test for of-platdata
Quoted 6 lines
Changes in v2:
- Add support for rockchip
- Various minor enhancements to the v1 implementationdoc/driver-model/of-plat.txt | 110 ++++++++++++++++++++++++++++++------------- 1 file changed, 76 insertions(+), 34 deletions(-)
Applied to u-boot-dm
v3 cover dm: rockchip: sandbox: Add support for compiled-in platform data
In reply to Simon GlassHi,
Quoted 47 lines · Simon Glass
Note: This v3 series adds a test and fixes a few bugs found in generation of of-platdata.
This series provides a way to compile in the contents of a device tree as C code into U-Boot, implementing an idea that Tom Rini came up with. It is intended to deal with extremely tight environments where there is not enough space for the ~3KB device tree code overhead. Examples include SPL where there is only 16KB of available RAM yet a full MMC stack is required.
To provide a reasonable test environment, SPL support is added to sandbox, through a new '
sandbox_spl' target. A new tool 'dtoc' converts device tree data to C code (and structure definitions).To check its effectiveness for a real application, the v2 series includes support for enabling of-platdata for a rockchip board (firefly-rk3288). The results are as follows:
Code Data u-boot-spl.bin size of-platdata disabled 23159 1624 28864 of-platdata enabled 19093 2616 21761Overall the saving is 7103 bytes, about 7KB. Approximately 4KB of this comes from removing the device tree data from SPL although this is offset by the size of the of-platdata itself (around 1KB). On top of this effective 3KB reduction, another ~3KB reduction comes from dropping libfdt and a further 1KB from dropping unused setup and driver-model code.
Clearly this approach does have value. Looked at with a favourable light it provides the best of both worlds: configuration using standard device tree bindings without the run-time overhead.
Looking under the hood shows a less rosy picture. Effectively we end up with a new set of C structures which must be handled by the driver. This series suggests a suitable approach for dealing with this (see of-plat.txt) which is workable. However there are a number of serious caveats. See that file for details.
Thsi feature should be used sparingly. Rockchip is to some extent an unusual
case: lots of features (leading to a large SPL device tree size of 4KB), no MMC stack available to SPL from the internal ROM* and a very limited maximum SPL code size. Most SoCs will not benefit from this.However, for an SoC with very small SRAM where only a few drivers are needed in SPL (such as serial and MMC) then of-platdata could provide a useful benefit, without a significant increase in complexity.
Quoted 5 lines
With the v3 series this feature is ready for use. It is available at u-boot-dm/dt-working.
The dtoc tool might be better renamed fdttoc (which is clumsy) or fdt2c. Ideas welcome.
I'm planning to apply this series soon. Please let me know if there are any further comments.
Regards,
Simon