Skip to contentSkip to conversation

vpl: Introduce a verifying program loader

PATCH In review Simon Glass 2 participants 15 messages Apr 30, 2022 – May 3, 2022

Subsystems (9)
Block layer Kbuild Library code GPIO +5 more subsystems
lore
Share & tools
lore
#0 lore raw

v8 cover vpl: Introduce a verifying program loader

U-Boot provides a verified-boot feature based around FIT, but there is no standard way of implementing it for a board. At present the various required pieces must be built up separately, to produce a working implementation. In particular, there is no built-in support for selecting A/B boot or recovery mode.

This series introduces VPL, a verified program loader phase for U-Boot. Its purpose is to run the verified-boot process and decide which SPL binary should be run. It is critical that this decision happens before SPL runs, since SPL sets up SDRAM and we need to be able to update the SDRAM-init code in the field.

Adding VPL into the boot flow provides a standard place to implement verified boot. This series includes the phase itself, some useful Kconfig options and a sandbox_vpl build for sandbox. No verfied-boot support is provided in this series.

Most of the patches in this series are fixes and improvements to docs and various Kconfig conditions for SPL.

This series requires the earlier sandbox fix patches[1] to be applied first. A test is included to make sure that VPL runs correctly for sandbox, i.e. that the TPL -> VPL -> SPL -> U-Boot flow works.

Future work will add an implementation of verified boot into VPL.

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=297248

Changes in v8:
- Rename the VPL symbols in spl.c
- Support SYSCON and REGMAP too
- Update defconfig to account for option changes
- Drop reference to old OF_HOSTFILE option
- Add new patch to support running vpl tests

Changes in v7:
- Add a few more options
- Rebase to master
- Update some options based on settings in master

Changes in v6:
- Add docs for sandbox_vpl build
- Drop TPL_HASH_SUPPORT patch since we only have SPL_HASH now

Changes in v5:
- Rebase this patch on mainline (for GPIO and MISC Kconfig renames)

Changes in v4:
- Add new patch to correct bloblist Kconfig dependencies
- Add new patch to avoid building avb in SPL
- Update spl_phase_prefix() for VPL
- Tidy up some of the Makefile rules
- Add options for blk, core, misc and tpl also
- Add VPL_SIZE_LIMIT
- Add a sandbox_vpl build
- Update cover letter

Changes in v3:
- Move VPL Kconfig options to a separate patch
- Add full build support for VPL
- Add a VPL size check (Kconfig option in next patch)

Changes in v2:
- Add some more VPL Kconfig options

Simon Glass (13):
doc: Convert SPL documentation to ReST
doc: Expand SPL docs to explain the phase and config
test: Tidy up test building with SPL
bloblist: Correct Kconfig dependencies
avb: Don't build in SPL
Makefile: Simplify devicetree rules for SPL/TPL
Makefile: Tidy up the TPL build rules
Introduce Verifying Program Loader (VPL)
vpl: Add Kconfig options for VPL
sandbox: Add a build for VPL
vpl: Support running vpl tests
vpl: Test that VPL runs correctly through to U-Boot proper
CI: Run VPL tests

 .azure-pipelines.yml                |   3 +
 .gitlab-ci.yml                      |   6 +
 Kconfig                             |  10 ++
 Makefile                            |  28 +++-
 arch/sandbox/Kconfig                |   8 +
 arch/sandbox/cpu/spl.c              |  12 +-
 arch/sandbox/dts/sandbox.dtsi       |  10 +-
 board/sandbox/MAINTAINERS           |   7 +
 common/Kconfig                      |  71 +++++++-
 common/Makefile                     |   2 +-
 common/spl/Kconfig                  | 234 +++++++++++++++++++++++++-
 common/spl/spl.c                    |  25 ++-
 configs/sandbox_vpl_defconfig       | 251 ++++++++++++++++++++++++++++
 doc/arch/sandbox.rst                |  13 ++
 doc/develop/index.rst               |   1 +
 doc/{README.SPL => develop/spl.rst} |  75 +++++++--
 drivers/Makefile                    |   2 +
 drivers/block/Kconfig               |  12 ++
 drivers/clk/Kconfig                 |  26 +++
 drivers/core/Kconfig                |  54 +++++-
 drivers/core/Makefile               |   2 +-
 drivers/gpio/Kconfig                |  11 ++
 drivers/i2c/Kconfig                 |  11 ++
 drivers/misc/Kconfig                |  28 ++++
 drivers/pinctrl/Kconfig             |  18 +-
 drivers/rtc/Kconfig                 |   9 +
 drivers/serial/Kconfig              |  20 +++
 drivers/sysreset/Kconfig            |  10 ++
 drivers/timer/Kconfig               |  10 ++
 drivers/tpm/Kconfig                 |  30 ++++
 dts/Kconfig                         |  17 ++
 include/bootstage.h                 |   2 +
 include/linux/kconfig.h             |   3 +
 include/spl.h                       |  22 ++-
 lib/Kconfig                         |  62 +++++++
 scripts/Kbuild.include              |   4 +
 scripts/Makefile.autoconf           |  12 ++
 scripts/Makefile.build              |   4 +
 scripts/Makefile.lib                |   5 +
 scripts/Makefile.spl                |  37 ++--
 test/py/conftest.py                 |   7 +-
 test/py/tests/test_help.py          |  12 ++
 test/py/tests/test_vpl.py           |  34 ++++
 test/py/u_boot_console_sandbox.py   |   7 +-
 44 files changed, 1167 insertions(+), 60 deletions(-)
 create mode 100644 configs/sandbox_vpl_defconfig
 rename doc/{README.SPL => develop/spl.rst} (68%)
 create mode 100644 test/py/tests/test_vpl.py
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#1 lore raw

PATCH v8 1/13 doc: Convert SPL documentation to ReST

Move this documentation over to .rst format.

---

(no changes since v1)

 doc/develop/index.rst               |  1 +
 doc/{README.SPL => develop/spl.rst} | 36 +++++++++++++++--------------
 2 files changed, 20 insertions(+), 17 deletions(-)
 rename doc/{README.SPL => develop/spl.rst} (86%)
doc/develop/index.rst +1 -0
index d32ec490221..fe3564a9fbf 100644
@@ -25,6 +25,7 @@ Implementation
    menus
    printf
    smbios
+   spl
    uefi/index
    version
 
doc/develop/spl.rst renamed from doc/README.SPL +19 -17
similarity index 86%
rename from doc/README.SPL
rename to doc/develop/spl.rst
index 011fd42537a..4d6f394bed9 100644
@@ -20,19 +20,19 @@ u-boot-spl.map.
 A config option named CONFIG_SPL_BUILD is enabled by Kconfig for SPL.
 Source files can therefore be compiled for SPL with different settings.
 
-For example:
+For example::
 
-ifeq ($(CONFIG_SPL_BUILD),y)
-obj-y += board_spl.o
-else
-obj-y += board.o
-endif
+   ifeq ($(CONFIG_SPL_BUILD),y)
+   obj-y += board_spl.o
+   else
+   obj-y += board.o
+   endif
 
-obj-$(CONFIG_SPL_BUILD) += foo.o
+   obj-$(CONFIG_SPL_BUILD) += foo.o
 
-#ifdef CONFIG_SPL_BUILD
-	foo();
-#endif
+   #ifdef CONFIG_SPL_BUILD
+           foo();
+   #endif
 
 
 The building of SPL images can be enabled by CONFIG_SPL option in Kconfig.
@@ -71,11 +71,13 @@ Device tree
 The U-Boot device tree is filtered by the fdtgrep tools during the build
 process to generate a much smaller device tree used in SPL (spl/u-boot-spl.dtb)
 with:
+
 - the mandatory nodes (/alias, /chosen, /config)
 - the nodes with one pre-relocation property:
   'u-boot,dm-pre-reloc' or 'u-boot,dm-spl'
 
 fdtgrep is also used to remove:
+
 - the properties defined in CONFIG_OF_SPL_REMOVE_PROPS
 - all the pre-relocation properties
   ('u-boot,dm-pre-reloc', 'u-boot,dm-spl' and 'u-boot,dm-tpl')
@@ -98,14 +100,14 @@ stack usage at various points in run sequence of SPL.  The -fstack-usage option
 to gcc will produce '.su' files (such as arch/arm/cpu/armv7/syslib.su) that
 will give stack usage information and cflow can construct program flow.
 
-Must have gcc 4.6 or later, which supports -fstack-usage
+Must have gcc 4.6 or later, which supports -fstack-usage:
 
-1) Build normally
-2) Perform the following shell command to generate a list of C files used in
-SPL:
-$ find spl -name '*.su' | sed -e 's:^spl/::' -e 's:[.]su$:.c:' > used-spl.list
-3) Execute cflow:
-$ cflow --main=board_init_r `cat used-spl.list` 2>&1 | $PAGER
+#. Build normally
+#. Perform the following shell command to generate a list of C files used in
+   SPL:
+#. `find spl -name '*.su' | sed -e 's:^spl/::' -e 's:[.]su$:.c:' > used-spl.list`
+#. Execute cflow:
+   `$ cflow --main=board_init_r $(cat used-spl.list) 2>&1 | $PAGER`
 
 cflow will spit out a number of warnings as it does not parse
 the config files and picks functions based on #ifdef.  Parsing the '.i'
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#2 lore raw

Re: [PATCH v8 01/13] doc: Convert SPL documentation to ReST

Quoted 3 lines · Simon Glass

Move this documentation over to .rst format.

For the series, applied to u-boot/master, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH v8 2/13 doc: Expand SPL docs to explain the phase and config

In reply to Simon Glass

Add a bit more information about how to use SPL.

---

(no changes since v1)

 doc/develop/spl.rst | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
doc/develop/spl.rst +34 -0
index 4d6f394bed9..1059b2fb9c0 100644
@@ -66,6 +66,40 @@ CONFIG_SPL_SPI_LOAD (drivers/mtd/spi/spi_spl_load.o)
 CONFIG_SPL_RAM_DEVICE (common/spl/spl.c)
 CONFIG_SPL_WATCHDOG (drivers/watchdog/libwatchdog.o)
 
+Adding SPL-specific code
+------------------------
+
+To check whether a feature is enabled, use CONFIG_IS_ENABLED()::
+
+  if (CONFIG_IS_ENABLED(CLK))
+      ...
+
+This checks CONFIG_CLK for the main build, CONFIG_SPL_CLK for the SPL build,
+CONFIG_TPL_CLK for the TPL build, etc.
+
+U-Boot Phases
+-------------
+
+U-Boot boots through the following phases:
+
+TPL
+   Very early init, as tiny as possible. This loads SPL.
+
+SPL
+   Secondary program loader. Sets up SDRAM and loads U-Boot proper. It may also
+   load other firmware components.
+
+U-Boot
+   U-Boot proper, containing the command line and boot logic.
+
+
+Checking the boot phase
+-----------------------
+
+Use `spl_phase()` to find the current U-Boot phase, e.g. `PHASE_SPL`. You can
+also find the previous and next phase and get the phase name.
+
+
 Device tree
 -----------
 The U-Boot device tree is filtered by the fdtgrep tools during the build
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#4 lore raw

PATCH v8 3/13 test: Tidy up test building with SPL

In reply to Simon Glass

We can in principle add tests to any SPL build, e.g. TPL or VPL. Update the build rules to handle this.

---

(no changes since v1)

 Makefile             | 2 +-
 scripts/Makefile.spl | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Makefile +1 -1
index ccc87c3a5cd..3f28333e644 100644
@@ -846,7 +846,7 @@ libs-y += drivers/usb/ulpi/
 ifdef CONFIG_POST
 libs-y += post/
 endif
-libs-$(CONFIG_UNIT_TEST) += test/
+libs-$(CONFIG_$(SPL_TPL_)UNIT_TEST) += test/
 libs-$(CONFIG_UT_ENV) += test/env/
 libs-$(CONFIG_UT_OPTEE) += test/optee/
 libs-$(CONFIG_UT_OVERLAY) += test/overlay/
scripts/Makefile.spl +1 -1
index 6ad82cecfb7..30672a61179 100644
@@ -109,7 +109,7 @@ libs-y += dts/
 libs-y += fs/
 libs-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/
 libs-$(CONFIG_SPL_NET) += net/
-libs-$(CONFIG_SPL_UNIT_TEST) += test/
+libs-$(CONFIG_$(SPL_TPL_)UNIT_TEST) += test/
 
 head-y		:= $(addprefix $(obj)/,$(head-y))
 libs-y		:= $(addprefix $(obj)/,$(libs-y))
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#5 lore raw

PATCH v8 4/13 bloblist: Correct Kconfig dependencies

In reply to Simon Glass

This feature is not available in SPL unless common/ and lib/ are built. Update the Kconfig to avoid build errors.

---

(no changes since v4)

Changes in v4:
- Add new patch to correct bloblist Kconfig dependencies

 common/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
common/Kconfig +2 -2
index 8f8a9064d50..f55b4211bb2 100644
@@ -762,7 +762,7 @@ config BLOBLIST
 
 config SPL_BLOBLIST
 	bool "Support for a bloblist in SPL"
-	depends on BLOBLIST
+	depends on BLOBLIST && SPL_LIBGENERIC_SUPPORT && SPL_LIBCOMMON_SUPPORT
 	default y if SPL
 	help
 	  This enables a bloblist in SPL. If this is the first part of U-Boot
@@ -771,7 +771,7 @@ config SPL_BLOBLIST
 
 config TPL_BLOBLIST
 	bool "Support for a bloblist in TPL"
-	depends on BLOBLIST
+	depends on BLOBLIST && TPL_LIBGENERIC_SUPPORT && TPL_LIBCOMMON_SUPPORT
 	default y if TPL
 	help
 	  This enables a bloblist in TPL. The bloblist is set up in TPL and
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#6 lore raw

PATCH v8 5/13 avb: Don't build in SPL

In reply to Simon Glass

This feature is not used in SPL at present. Update the Makefile to avoid it being built.

---

(no changes since v4)

Changes in v4:
- Add new patch to avoid building avb in SPL

 common/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/Makefile +1 -1
index cc2ba30c631..75c24e32492 100644
@@ -112,7 +112,7 @@ obj-y += s_record.o
 obj-$(CONFIG_CMD_LOADB) += xyzModem.o
 obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o
 
-obj-$(CONFIG_AVB_VERIFY) += avb_verify.o
+obj-$(CONFIG_$(SPL_TPL_)AVB_VERIFY) += avb_verify.o
 obj-$(CONFIG_$(SPL_TPL_)STACKPROTECTOR) += stackprot.o
 obj-$(CONFIG_SCP03) += scp03.o
 
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#7 lore raw

PATCH v8 6/13 Makefile: Simplify devicetree rules for SPL/TPL

In reply to Simon Glass

The current logic checks several options to decide whether SPL/TPL need the U-Boot devicetree to be built. In fact we can check OF_CONTROL, which is enabled in all cases that matter.

---

(no changes since v1)

 Makefile | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
Makefile +2 -5
index 3f28333e644..9f220de3202 100644
@@ -2095,9 +2095,7 @@ spl/u-boot-spl-dtb.bin: spl/u-boot-spl
 spl/u-boot-spl-dtb.hex: spl/u-boot-spl
 	@:
 
-spl/u-boot-spl: tools prepare \
-		$(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SPL_OF_PLATDATA),dts/dt.dtb) \
-		$(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_TPL_OF_PLATDATA),dts/dt.dtb)
+spl/u-boot-spl: tools prepare $(if $(CONFIG_SPL_OF_CONTROL),dts/dt.dtb)
 	$(Q)$(MAKE) obj=spl -f $(srctree)/scripts/Makefile.spl all
 
 spl/sunxi-spl.bin: spl/u-boot-spl
@@ -2112,8 +2110,7 @@ spl/u-boot-spl.sfp: spl/u-boot-spl
 spl/boot.bin: spl/u-boot-spl
 	@:
 
-tpl/u-boot-tpl.bin: tools prepare \
-		$(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SPL_OF_PLATDATA),dts/dt.dtb)
+tpl/u-boot-tpl.bin: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
 	$(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
 	$(TPL_SIZE_CHECK)
 
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#8 lore raw

PATCH v8 7/13 Makefile: Tidy up the TPL build rules

In reply to Simon Glass

These should follow the same pattern as SPL, for consistency. Fix them.

---

(no changes since v1)

 Makefile | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Makefile +5 -2
index 9f220de3202..82c35a94ae6 100644
@@ -2110,10 +2110,13 @@ spl/u-boot-spl.sfp: spl/u-boot-spl
 spl/boot.bin: spl/u-boot-spl
 	@:
 
-tpl/u-boot-tpl.bin: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
-	$(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
+tpl/u-boot-tpl.bin: tpl/u-boot-tpl
+	@:
 	$(TPL_SIZE_CHECK)
 
+tpl/u-boot-tpl: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
+	$(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
+
 TAG_SUBDIRS := $(patsubst %,$(srctree)/%,$(u-boot-dirs) include)
 
 FIND := find
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#9 lore raw

PATCH v8 8/13 Introduce Verifying Program Loader (VPL)

In reply to Simon Glass

Add support for VPL, a new phase of U-Boot. This runs after TPL. It is responsible for selecting which SPL binary to run, based on a verified-boot process.

---

Changes in v8:
- Rename the VPL symbols in spl.c

Changes in v4:
- Update spl_phase_prefix() for VPL
- Tidy up some of the Makefile rules

Changes in v3:
- Move VPL Kconfig options to a separate patch
- Add full build support for VPL
- Add a VPL size check (Kconfig option in next patch)

Changes in v2:
- Add some more VPL Kconfig options

 Makefile                  | 14 ++++++++++++++
 common/spl/Kconfig        | 15 ++++++++++++++-
 common/spl/spl.c          | 25 ++++++++++++++++++++++---
 doc/develop/spl.rst       |  7 ++++++-
 drivers/Makefile          |  2 ++
 include/bootstage.h       |  2 ++
 include/linux/kconfig.h   |  3 +++
 include/spl.h             | 22 +++++++++++++++++++---
 scripts/Kbuild.include    |  4 ++++
 scripts/Makefile.autoconf | 12 ++++++++++++
 scripts/Makefile.build    |  4 ++++
 scripts/Makefile.lib      |  5 +++++
 scripts/Makefile.spl      | 35 ++++++++++++++++++++++++-----------
 13 files changed, 131 insertions(+), 19 deletions(-)
Makefile +14 -0
index 82c35a94ae6..ea80f00716d 100644
@@ -911,6 +911,12 @@ else
 TPL_SIZE_CHECK =
 endif
 
+ifneq ($(CONFIG_VPL_SIZE_LIMIT),0x0)
+VPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_VPL_SIZE_LIMIT))
+else
+VPL_SIZE_CHECK =
+endif
+
 # Statically apply RELA-style relocations (currently arm64 only)
 # This is useful for arm64 where static relocation needs to be performed on
 # the raw binary, but certain simulators only accept an ELF file (but don't
@@ -951,6 +957,7 @@ INPUTS-$(CONFIG_SPL_FRAMEWORK) += u-boot.img
 endif
 endif
 INPUTS-$(CONFIG_TPL) += tpl/u-boot-tpl.bin
+INPUTS-$(CONFIG_VPL) += vpl/u-boot-vpl.bin
 
 # Allow omitting the .dtb output if it is not normally used
 INPUTS-$(CONFIG_OF_SEPARATE) += $(if $(CONFIG_OF_OMIT_DTB),dts/dt.dtb,u-boot.dtb)
@@ -2117,6 +2124,13 @@ tpl/u-boot-tpl.bin: tpl/u-boot-tpl
 tpl/u-boot-tpl: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
 	$(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
 
+vpl/u-boot-vpl.bin: vpl/u-boot-vpl
+	@:
+	$(VPL_SIZE_CHECK)
+
+vpl/u-boot-vpl: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
+	$(Q)$(MAKE) obj=vpl -f $(srctree)/scripts/Makefile.spl all
+
 TAG_SUBDIRS := $(patsubst %,$(srctree)/%,$(u-boot-dirs) include)
 
 FIND := find
common/spl/Kconfig +14 -1
index ac61b25a066..be098668f0e 100644
@@ -1,4 +1,4 @@
-menu "SPL / TPL"
+menu "SPL / TPL / VPL"
 
 config SUPPORT_SPL
 	bool
@@ -6,6 +6,9 @@ config SUPPORT_SPL
 config SUPPORT_TPL
 	bool
 
+config SUPPORT_VPL
+	bool
+
 config SPL_DFU_NO_RESET
 	bool
 
@@ -302,6 +305,16 @@ config SPL_READ_ONLY
 	  writeable memory) of anything it wants to modify, such as
 	  device-private data.
 
+config TPL_SEPARATE_BSS
+	bool "BSS section is in a different memory region from text"
+	default y if SPL_SEPARATE_BSS
+	help
+	  Some platforms need a large BSS region in TPL and can provide this
+	  because RAM is already set up. In this case BSS can be moved to RAM.
+	  This option should then be enabled so that the correct device tree
+	  location is used. Normally we put the device tree at the end of BSS
+	  but with this option enabled, it goes at _image_binary_end.
+
 config SPL_BANNER_PRINT
 	bool "Enable output of the SPL banner 'U-Boot SPL ...'"
 	default y
common/spl/spl.c +22 -3
index c9750ee1637..c8c463f80bd 100644
@@ -61,6 +61,11 @@ binman_sym_declare(ulong, u_boot_spl, image_pos);
 binman_sym_declare(ulong, u_boot_spl, size);
 #endif
 
+#ifdef CONFIG_VPL
+binman_sym_declare(ulong, u_boot_vpl, image_pos);
+binman_sym_declare(ulong, u_boot_vpl, size);
+#endif
+
 /* Define board data structure */
 static struct bd_info bdata __attribute__ ((section(".data")));
 
@@ -146,14 +151,22 @@ void spl_fixup_fdt(void *fdt_blob)
 #if CONFIG_IS_ENABLED(BINMAN_SYMBOLS)
 ulong spl_get_image_pos(void)
 {
-	return spl_phase() == PHASE_TPL ?
+#ifdef CONFIG_VPL
+	if (spl_next_phase() == PHASE_VPL)
+		return binman_sym(ulong, u_boot_vpl, image_pos);
+#endif
+	return spl_next_phase() == PHASE_SPL ?
 		binman_sym(ulong, u_boot_spl, image_pos) :
 		binman_sym(ulong, u_boot_any, image_pos);
 }
 
 ulong spl_get_image_size(void)
 {
-	return spl_phase() == PHASE_TPL ?
+#ifdef CONFIG_VPL
+	if (spl_next_phase() == PHASE_VPL)
+		return binman_sym(ulong, u_boot_vpl, size);
+#endif
+	return spl_next_phase() == PHASE_SPL ?
 		binman_sym(ulong, u_boot_spl, size) :
 		binman_sym(ulong, u_boot_any, size);
 }
@@ -161,7 +174,11 @@ ulong spl_get_image_size(void)
 
 ulong spl_get_image_text_base(void)
 {
-	return spl_phase() == PHASE_TPL ? CONFIG_SPL_TEXT_BASE :
+#ifdef CONFIG_VPL
+	if (spl_next_phase() == PHASE_VPL)
+		return CONFIG_VPL_TEXT_BASE;
+#endif
+	return spl_next_phase() == PHASE_SPL ? CONFIG_SPL_TEXT_BASE :
 		CONFIG_SYS_TEXT_BASE;
 }
 
@@ -466,6 +483,8 @@ static enum bootstage_id get_bootstage_id(bool start)
 
 	if (IS_ENABLED(CONFIG_TPL_BUILD) && phase == PHASE_TPL)
 		return start ? BOOTSTAGE_ID_START_TPL : BOOTSTAGE_ID_END_TPL;
+	else if (IS_ENABLED(CONFIG_VPL_BUILD) && phase == PHASE_VPL)
+		return start ? BOOTSTAGE_ID_START_VPL : BOOTSTAGE_ID_END_VPL;
 	else
 		return start ? BOOTSTAGE_ID_START_SPL : BOOTSTAGE_ID_END_SPL;
 }
doc/develop/spl.rst +6 -1
index 1059b2fb9c0..aec7b562faa 100644
@@ -83,7 +83,12 @@ U-Boot Phases
 U-Boot boots through the following phases:
 
 TPL
-   Very early init, as tiny as possible. This loads SPL.
+   Very early init, as tiny as possible. This loads SPL (or VPL if enabled).
+
+VPL
+   Optional verification step, which can select one of several SPL binaries,
+   if A/B verified boot is enabled. Implementation of the VPL logic is
+   work-in-progress. For now it just boots into SPL.
 
 SPL
    Secondary program loader. Sets up SDRAM and loads U-Boot proper. It may also
drivers/Makefile +2 -0
index 4e7cf284405..67c8af74424 100644
@@ -38,6 +38,7 @@ obj-$(CONFIG_XEN) += xen/
 obj-$(CONFIG_$(SPL_)FPGA) += fpga/
 
 ifndef CONFIG_TPL_BUILD
+ifndef CONFIG_VPL_BUILD
 ifdef CONFIG_SPL_BUILD
 
 obj-$(CONFIG_SPL_CPU) += cpu/
@@ -60,6 +61,7 @@ obj-$(CONFIG_SPL_SATA) += ata/ scsi/
 obj-$(CONFIG_HAVE_BLOCK_DEVICE) += block/
 obj-$(CONFIG_SPL_THERMAL) += thermal/
 
+endif
 endif
 endif
 
include/bootstage.h +2 -0
index 99a334ad54b..bca9438418f 100644
@@ -176,6 +176,8 @@ enum bootstage_id {
 	BOOTSTAGE_ID_END_TPL,
 	BOOTSTAGE_ID_START_SPL,
 	BOOTSTAGE_ID_END_SPL,
+	BOOTSTAGE_ID_START_VPL,
+	BOOTSTAGE_ID_END_VPL,
 	BOOTSTAGE_ID_START_UBOOT_F,
 	BOOTSTAGE_ID_START_UBOOT_R,
 	BOOTSTAGE_ID_USB_START,
include/linux/kconfig.h +3 -0
index d20da615b96..2bc704e1104 100644
@@ -38,6 +38,8 @@
 #define _CONFIG_PREFIX TOOLS_
 #elif defined(CONFIG_TPL_BUILD)
 #define _CONFIG_PREFIX TPL_
+#elif defined(CONFIG_VPL_BUILD)
+#define _CONFIG_PREFIX VPL_
 #elif defined(CONFIG_SPL_BUILD)
 #define _CONFIG_PREFIX SPL_
 #else
@@ -54,6 +56,7 @@
  *  CONFIG_FOO if CONFIG_SPL_BUILD is undefined,
  *  CONFIG_SPL_FOO if CONFIG_SPL_BUILD is defined.
  *  CONFIG_TPL_FOO if CONFIG_TPL_BUILD is defined.
+ *  CONFIG_VPL_FOO if CONFIG_VPL_BUILD is defined.
  */
 #define CONFIG_VAL(option)  config_val(option)
 
include/spl.h +19 -3
index 6134aba8571..83ac583e0b4 100644
@@ -62,6 +62,7 @@ static inline bool u_boot_first_phase(void)
 enum u_boot_phase {
 	PHASE_NONE,	/* Invalid phase, signifying before U-Boot */
 	PHASE_TPL,	/* Running in TPL */
+	PHASE_VPL,	/* Running in VPL */
 	PHASE_SPL,	/* Running in SPL */
 	PHASE_BOARD_F,	/* Running in U-Boot before relocation */
 	PHASE_BOARD_R,	/* Running in U-Boot after relocation */
@@ -114,7 +115,9 @@ static inline enum u_boot_phase spl_phase(void)
 {
 #ifdef CONFIG_TPL_BUILD
 	return PHASE_TPL;
-#elif CONFIG_SPL_BUILD
+#elif defined(CONFIG_VPL_BUILD)
+	return PHASE_VPL;
+#elif defined(CONFIG_SPL_BUILD)
 	return PHASE_SPL;
 #else
 	DECLARE_GLOBAL_DATA_PTR;
@@ -136,10 +139,15 @@ static inline enum u_boot_phase spl_prev_phase(void)
 {
 #ifdef CONFIG_TPL_BUILD
 	return PHASE_NONE;
+#elif defined(CONFIG_VPL_BUILD)
+	return PHASE_TPL;	/* VPL requires TPL */
 #elif defined(CONFIG_SPL_BUILD)
-	return IS_ENABLED(CONFIG_TPL) ? PHASE_TPL : PHASE_NONE;
+	return IS_ENABLED(CONFIG_VPL) ? PHASE_VPL :
+		IS_ENABLED(CONFIG_TPL) ? PHASE_TPL :
+		PHASE_NONE;
 #else
-	return IS_ENABLED(CONFIG_SPL) ? PHASE_SPL : PHASE_NONE;
+	return IS_ENABLED(CONFIG_SPL) ? PHASE_SPL :
+		PHASE_NONE;
 #endif
 }
 
@@ -152,6 +160,8 @@ static inline enum u_boot_phase spl_prev_phase(void)
 static inline enum u_boot_phase spl_next_phase(void)
 {
 #ifdef CONFIG_TPL_BUILD
+	return IS_ENABLED(CONFIG_VPL) ? PHASE_VPL : PHASE_SPL;
+#elif defined(CONFIG_VPL_BUILD)
 	return PHASE_SPL;
 #else
 	return PHASE_BOARD_F;
@@ -168,6 +178,8 @@ static inline const char *spl_phase_name(enum u_boot_phase phase)
 	switch (phase) {
 	case PHASE_TPL:
 		return "TPL";
+	case PHASE_VPL:
+		return "VPL";
 	case PHASE_SPL:
 		return "SPL";
 	case PHASE_BOARD_F:
@@ -189,6 +201,8 @@ static inline const char *spl_phase_prefix(enum u_boot_phase phase)
 	switch (phase) {
 	case PHASE_TPL:
 		return "tpl";
+	case PHASE_VPL:
+		return "vpl";
 	case PHASE_SPL:
 		return "spl";
 	case PHASE_BOARD_F:
@@ -203,6 +217,8 @@ static inline const char *spl_phase_prefix(enum u_boot_phase phase)
 #ifdef CONFIG_SPL_BUILD
 # ifdef CONFIG_TPL_BUILD
 #  define SPL_TPL_NAME	"TPL"
+# elif defined(CONFIG_VPL_BUILD)
+#  define SPL_TPL_NAME	"VPL"
 # else
 #  define SPL_TPL_NAME	"SPL"
 # endif
scripts/Kbuild.include +4 -0
index 09506cb9a7e..9c14310ad40 100644
@@ -322,11 +322,15 @@ endif
 
 ifdef CONFIG_SPL_BUILD
 SPL_ := SPL_
+ifeq ($(CONFIG_VPL_BUILD),y)
+SPL_TPL_ := VPL_
+else
 ifeq ($(CONFIG_TPL_BUILD),y)
 SPL_TPL_ := TPL_
 else
 SPL_TPL_ := SPL_
 endif
+endif
 else
 SPL_ :=
 SPL_TPL_ :=
scripts/Makefile.autoconf +12 -0
index 0b3ffa08bfa..3fa4d50f1ea 100644
@@ -18,6 +18,10 @@ ifeq ($(shell grep -q '^CONFIG_TPL=y' include/config/auto.conf 2>/dev/null && ec
 __all: tpl/include/autoconf.mk
 endif
 
+ifeq ($(shell grep -q '^CONFIG_VPL=y' include/config/auto.conf 2>/dev/null && echo y),y)
+__all: vpl/include/autoconf.mk
+endif
+
 include include/config/auto.conf
 
 include scripts/Kbuild.include
@@ -85,6 +89,10 @@ tpl/u-boot.cfg: include/config.h FORCE
 	$(Q)mkdir -p $(dir $@)
 	$(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD -DCONFIG_TPL_BUILD)
 
+vpl/u-boot.cfg: include/config.h FORCE
+	$(Q)mkdir -p $(dir $@)
+	$(call cmd,u_boot_cfg,-DCONFIG_SPL_BUILD -DCONFIG_VPL_BUILD)
+
 include/autoconf.mk: u-boot.cfg
 	$(call cmd,autoconf)
 
@@ -96,6 +104,10 @@ tpl/include/autoconf.mk: tpl/u-boot.cfg
 	$(Q)mkdir -p $(dir $@)
 	$(call cmd,autoconf)
 
+vpl/include/autoconf.mk: vpl/u-boot.cfg
+	$(Q)mkdir -p $(dir $@)
+	$(call cmd,autoconf)
+
 # include/config.h
 # Prior to Kconfig, it was generated by mkconfig. Now it is created here.
 define filechk_config_h
scripts/Makefile.build +4 -0
index 5df8f61aa58..3b8c9d8c319 100644
@@ -4,6 +4,9 @@
 # ==========================================================================
 
 # Modified for U-Boot
+prefix := vpl
+src := $(patsubst $(prefix)/%,%,$(obj))
+ifeq ($(obj),$(src))
 prefix := tpl
 src := $(patsubst $(prefix)/%,%,$(obj))
 ifeq ($(obj),$(src))
@@ -13,6 +16,7 @@ ifeq ($(obj),$(src))
 prefix := .
 endif
 endif
+endif
 
 PHONY := __build
 __build:
scripts/Makefile.lib +5 -0
index 2ff39d39dc8..3db2550085a 100644
@@ -581,16 +581,21 @@ cmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \
 # 'u-boot,dm-pre-reloc' property and thus are not needed by SPL. The second
 # pass removes various unused properties from the remaining nodes.
 # The output is typically a much smaller device tree file.
+ifeq ($(CONFIG_VPL_BUILD),y)
+fdtgrep_props := -b u-boot,dm-pre-reloc -b u-boot,dm-vpl
+else
 ifeq ($(CONFIG_TPL_BUILD),y)
 fdtgrep_props := -b u-boot,dm-pre-reloc -b u-boot,dm-tpl
 else
 fdtgrep_props := -b u-boot,dm-pre-reloc -b u-boot,dm-spl
 endif
+endif
 quiet_cmd_fdtgrep = FDTGREP $@
       cmd_fdtgrep = $(objtree)/tools/fdtgrep $(fdtgrep_props) -RT $< \
 		-n /chosen -n /config -O dtb | \
 	$(objtree)/tools/fdtgrep -r -O dtb - -o $@ \
 		-P u-boot,dm-pre-reloc -P u-boot,dm-spl -P u-boot,dm-tpl \
+		 -P u-boot,dm-vpl \
 		$(addprefix -P ,$(subst $\",,$(CONFIG_OF_SPL_REMOVE_PROPS)))
 
 # fdt_rm_props
scripts/Makefile.spl +24 -11
index 30672a61179..f047d4e0941 100644
@@ -27,8 +27,16 @@ UBOOTINCLUDE := -I$(obj)/include $(UBOOTINCLUDE)
 KBUILD_CPPFLAGS += -DCONFIG_SPL_BUILD
 ifeq ($(CONFIG_TPL_BUILD),y)
 KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD
+else
+ifeq ($(CONFIG_VPL_BUILD),y)
+KBUILD_CPPFLAGS += -DCONFIG_VPL_BUILD
+endif
 endif
 
+ifeq ($(CONFIG_VPL_BUILD),y)
+SPL_BIN := u-boot-vpl
+SPL_NAME := vpl
+else
 ifeq ($(CONFIG_TPL_BUILD),y)
 SPL_BIN := u-boot-tpl
 SPL_NAME := tpl
@@ -36,16 +44,21 @@ else
 SPL_BIN := u-boot-spl
 SPL_NAME := spl
 endif
+endif
 
 export SPL_NAME
 
 ifdef CONFIG_SPL_BUILD
 SPL_ := SPL_
+ifeq ($(CONFIG_VPL_BUILD),y)
+SPL_TPL_ := VPL_
+else
 ifeq ($(CONFIG_TPL_BUILD),y)
 SPL_TPL_ := TPL_
 else
 SPL_TPL_ := SPL_
 endif
+endif
 else
 SPL_ :=
 SPL_TPL_ :=
@@ -57,6 +70,9 @@ endif
 ifeq ($(obj)$(CONFIG_SUPPORT_TPL),tpl)
 $(error You cannot build TPL without enabling CONFIG_SUPPORT_TPL)
 endif
+ifeq ($(obj)$(CONFIG_SUPPORT_VPL),vpl)
+$(error You cannot build VPL without enabling CONFIG_SUPPORT_VPL)
+endif
 
 include $(srctree)/config.mk
 include $(srctree)/arch/$(ARCH)/Makefile
@@ -90,17 +106,12 @@ libs-$(CONFIG_SPL_FRAMEWORK) += common/spl/
 endif
 libs-y += common/init/
 
-# Special handling for a few options which support SPL/TPL
-ifeq ($(CONFIG_TPL_BUILD),y)
-libs-$(CONFIG_TPL_LIBCOMMON_SUPPORT) += boot/ common/ cmd/ env/
-libs-$(CONFIG_TPL_LIBGENERIC_SUPPORT) += lib/
-else
-libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += boot/ common/ cmd/ env/
-libs-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/
+# Special handling for a few options which support SPL/TPL/VPL
+libs-$(CONFIG_$(SPL_TPL_)LIBCOMMON_SUPPORT) += boot/ common/ cmd/ env/
+libs-$(CONFIG_$(SPL_TPL_)LIBGENERIC_SUPPORT) += lib/
 ifdef CONFIG_SPL_FRAMEWORK
 libs-$(CONFIG_PARTITIONS) += disk/
 endif
-endif
 
 libs-y += drivers/
 libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/dwc3/
@@ -182,7 +193,7 @@ LDPPFLAGS += \
 	  sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
 
 # Turn various CONFIG symbols into IMAGE symbols for easy reuse of
-# the scripts between SPL and TPL.
+# the scripts between SPL, TPL and VPL.
 ifneq ($(CONFIG_$(SPL_TPL_)MAX_SIZE),)
 LDPPFLAGS += -DIMAGE_MAX_SIZE=$(CONFIG_$(SPL_TPL_)MAX_SIZE)
 endif
@@ -264,6 +275,7 @@ ifeq ($(CONFIG_SYS_SOC),"at91")
 INPUTS-y	+= $(obj)/boot.bin
 endif
 
+ifndef CONFIG_VPL_BUILD
 ifdef CONFIG_TPL_BUILD
 INPUTS-$(CONFIG_TPL_X86_16BIT_INIT) += $(obj)/u-boot-x86-start16-tpl.bin \
 	$(obj)/u-boot-x86-reset16-tpl.bin
@@ -271,6 +283,7 @@ else
 INPUTS-$(CONFIG_SPL_X86_16BIT_INIT) += $(obj)/u-boot-x86-start16-spl.bin \
 	$(obj)/u-boot-x86-reset16-spl.bin
 endif
+endif
 
 INPUTS-$(CONFIG_ARCH_ZYNQ)		+= $(obj)/boot.bin
 INPUTS-$(CONFIG_ARCH_ZYNQMP)	+= $(obj)/boot.bin
@@ -307,7 +320,7 @@ endif
 
 ifneq ($(build_dtb),)
 $(obj)/$(SPL_BIN)-dtb.bin: $(obj)/$(SPL_BIN)-nodtb.bin \
-		$(if $(CONFIG_SPL_SEPARATE_BSS),,$(obj)/$(SPL_BIN)-pad.bin) \
+		$(if $(CONFIG_$(SPL_TPL_)SEPARATE_BSS),,$(obj)/$(SPL_BIN)-pad.bin) \
 		$(FINAL_DTB_CONTAINER)  FORCE
 	$(call if_changed,cat)
 
@@ -398,7 +411,7 @@ LDFLAGS_$(SPL_BIN) += $(call ld-option, --no-dynamic-linker)
 
 LDFLAGS_$(SPL_BIN) += --build-id=none
 
-# Pick the best-match (i.e. SPL_TEXT_BASE for SPL, TPL_TEXT_BASE for TPL)
+# Pick the best match (e.g. SPL_TEXT_BASE for SPL, TPL_TEXT_BASE for TPL)
 ifneq ($(CONFIG_$(SPL_TPL_)TEXT_BASE),)
 LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_$(SPL_TPL_)TEXT_BASE)
 endif
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#10 lore raw

PATCH v8 9/13 vpl: Add Kconfig options for VPL

In reply to Simon Glass

Add VPL versions of commonly used Kconfig options.

---

Changes in v8:
- Support SYSCON and REGMAP too

Changes in v7:
- Add a few more options

Changes in v5:
- Rebase this patch on mainline (for GPIO and MISC Kconfig renames)

Changes in v4:
- Add options for blk, core, misc and tpl also
- Add VPL_SIZE_LIMIT

 Kconfig                  |  10 ++
 common/Kconfig           |  67 ++++++++++++
 common/spl/Kconfig       | 219 +++++++++++++++++++++++++++++++++++++++
 drivers/block/Kconfig    |  12 +++
 drivers/clk/Kconfig      |  26 +++++
 drivers/core/Kconfig     |  54 +++++++++-
 drivers/core/Makefile    |   2 +-
 drivers/gpio/Kconfig     |  11 ++
 drivers/i2c/Kconfig      |  11 ++
 drivers/misc/Kconfig     |  28 +++++
 drivers/pinctrl/Kconfig  |  18 +++-
 drivers/rtc/Kconfig      |   9 ++
 drivers/serial/Kconfig   |  20 ++++
 drivers/sysreset/Kconfig |  10 ++
 drivers/timer/Kconfig    |  10 ++
 drivers/tpm/Kconfig      |  30 ++++++
 dts/Kconfig              |  17 +++
 lib/Kconfig              |  62 +++++++++++
 18 files changed, 612 insertions(+), 4 deletions(-)
Kconfig +10 -0
index bdae59e06f4..8bbb988790b 100644
@@ -319,6 +319,16 @@ config VALGRIND
 	  it can be handled accurately by Valgrind. If you aren't planning on
 	  using valgrind to debug U-Boot, say 'n'.
 
+config VPL_SYS_MALLOC_F_LEN
+	hex "Size of malloc() pool in VPL before relocation"
+	depends on SYS_MALLOC_F && VPL
+	default SYS_MALLOC_F_LEN
+	help
+	  Before relocation, memory is very limited on many platforms. Still,
+	  we can provide a small malloc() pool if needed. Driver model in
+	  particular needs this to operate, so that it can allocate the
+	  initial serial device and any others that are needed.
+
 menuconfig EXPERT
 	bool "Configure standard U-Boot features (expert users)"
 	default y
common/Kconfig +67 -0

91 lines not on this page · raw message

common/spl/Kconfig +219 -0

231 lines not on this page · raw message

drivers/block/Kconfig +12 -0
index c54b58110cf..d6d1c6e32cc 100644
@@ -39,6 +39,18 @@ config TPL_BLK
 	  be partitioned into several areas, called 'partitions' in U-Boot.
 	  A filesystem can be placed in each partition.
 
+config VPL_BLK
+	bool "Support block devices in VPL"
+	depends on VPL_DM && BLK
+	default y
+	help
+	  Enable support for block devices, such as SCSI, MMC and USB
+	  flash sticks. These provide a block-level interface which permits
+	  reading, writing and (in some cases) erasing blocks. Block
+	  devices often have a partition table which allows the device to
+	  be partitioned into several areas, called 'partitions' in U-Boot.
+	  A filesystem can be placed in each partition.
+
 config BLOCK_CACHE
 	bool "Use block device cache"
 	depends on BLK
drivers/clk/Kconfig +26 -0
index 6dc271f71b1..a62b81a1232 100644
@@ -30,6 +30,32 @@ config TPL_CLK
 	  setting up clocks within TPL, and allows the same drivers to be
 	  used as U-Boot proper.
 
+config VPL_CLK
+	bool "Enable clock support in VPL"
+	depends on CLK && VPL_DM
+	help
+	  The clock subsystem adds a small amount of overhead to the image.
+	  If this is acceptable and you have a need to use clock drivers in
+	  SPL, enable this option. It might provide a cleaner interface to
+	  setting up clocks within TPL, and allows the same drivers to be
+	  used as U-Boot proper.
+
+config CLK_BCM6345
+	bool "Clock controller driver for BCM6345"
+	depends on CLK && ARCH_BMIPS
+	default y
+	help
+	  This clock driver adds support for enabling and disabling peripheral
+	  clocks on BCM6345 SoCs. HW has no rate changing capabilities.
+
+config CLK_BOSTON
+	def_bool y if TARGET_BOSTON
+	depends on CLK
+	select REGMAP
+	select SYSCON
+	help
+	  Enable this to support the clocks
+
 config SPL_CLK_CCF
 	bool "SPL Common Clock Framework [CCF] support "
 	depends on SPL
drivers/core/Kconfig +53 -1

84 lines not on this page · raw message

drivers/core/Makefile +1 -1
index 7099073a533..bce0a3f65cb 100644
@@ -5,7 +5,7 @@
 obj-y	+= device.o fdtaddr.o lists.o root.o uclass.o util.o tag.o
 obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi.o
 obj-$(CONFIG_$(SPL_TPL_)DEVRES) += devres.o
-obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE)	+= device-remove.o
+obj-$(CONFIG_$(SPL_TPL_)DM_DEVICE_REMOVE)	+= device-remove.o
 obj-$(CONFIG_$(SPL_)SIMPLE_BUS)	+= simple-bus.o
 obj-$(CONFIG_SIMPLE_PM_BUS)	+= simple-pm-bus.o
 obj-$(CONFIG_DM)	+= dump.o
drivers/gpio/Kconfig +11 -0
index 89068c7800d..886cdbcdbaa 100644
@@ -48,6 +48,17 @@ config TPL_DM_GPIO
 	  particular GPIOs that they provide. The uclass interface
 	  is defined in include/asm-generic/gpio.h.
 
+config VPL_DM_GPIO
+	bool "Enable Driver Model for GPIO drivers in VPL"
+	depends on DM_GPIO && VPL_DM && VPL_GPIO
+	default y
+	help
+	  Enable driver model for GPIO access in VPL. The standard GPIO
+	  interface (gpio_get_value(), etc.) is then implemented by
+	  the GPIO uclass. Drivers provide methods to query the
+	  particular GPIOs that they provide. The uclass interface
+	  is defined in include/asm-generic/gpio.h.
+
 config GPIO_HOG
 	bool "Enable GPIO hog support"
 	depends on DM_GPIO
drivers/i2c/Kconfig +11 -0
index 5482a4a470b..d25c5736ef0 100644
@@ -47,6 +47,17 @@ config SPL_DM_I2C
 	  device (bus child) info is kept as parent platdata. The interface
 	  is defined in include/i2c.h.
 
+config VPL_DM_I2C
+	bool "Enable Driver Model for I2C drivers in VPL"
+	depends on VPL_DM && DM_I2C
+	default y
+	help
+	  Enable driver model for I2C. The I2C uclass interface: probe, read,
+	  write and speed, is implemented with the bus drivers operations,
+	  which provide methods for bus setting and data transfer. Each chip
+	  device (bus child) info is kept as parent platdata. The interface
+	  is defined in include/i2c.h.
+
 config SYS_I2C_LEGACY
 	bool "Enable legacy I2C subsystem and drivers"
 	depends on !DM_I2C
drivers/misc/Kconfig +28 -0
index dab7a99c68c..9af806a20ae 100644
@@ -131,6 +131,16 @@ config TPL_CROS_EC
 	  control access to the battery and main PMIC depending on the
 	  device. You can use the 'crosec' command to access it.
 
+config VPL_CROS_EC
+	bool "Enable Chrome OS EC in VPL"
+	depends on VPL
+	help
+	  Enable access to the Chrome OS EC in VPL. This is a separate
+	  microcontroller typically available on a SPI bus on Chromebooks. It
+	  provides access to the keyboard, some internal storage and may
+	  control access to the battery and main PMIC depending on the
+	  device. You can use the 'crosec' command to access it.
+
 config CROS_EC_I2C
 	bool "Enable Chrome OS EC I2C driver"
 	depends on CROS_EC
@@ -167,6 +177,15 @@ config TPL_CROS_EC_LPC
 	  through a legacy port interface, so on x86 machines the main
 	  function of the EC is power and thermal management.
 
+config VPL_CROS_EC_LPC
+	bool "Enable Chrome OS EC LPC driver in VPL"
+	depends on CROS_EC
+	help
+	  Enable I2C access to the Chrome OS EC. This is used on x86
+	  Chromebooks such as link and falco. The keyboard is provided
+	  through a legacy port interface, so on x86 machines the main
+	  function of the EC is power and thermal management.
+
 config CROS_EC_SANDBOX
 	bool "Enable Chrome OS EC sandbox driver"
 	depends on CROS_EC && SANDBOX
@@ -194,6 +213,15 @@ config TPL_CROS_EC_SANDBOX
 	  EC flash read/write/erase support and a few other things. It is
 	  enough to perform a Chrome OS verified boot on sandbox.
 
+config VPL_CROS_EC_SANDBOX
+	bool "Enable Chrome OS EC sandbox driver in VPL"
+	depends on VPL_CROS_EC && SANDBOX
+	help
+	  Enable a sandbox emulation of the Chrome OS EC in VPL. This supports
+	  keyboard (use the -l flag to enable the LCD), verified boot context,
+	  EC flash read/write/erase support and a few other things. It is
+	  enough to perform a Chrome OS verified boot on sandbox.
+
 config CROS_EC_SPI
 	bool "Enable Chrome OS EC SPI driver"
 	depends on CROS_EC
drivers/pinctrl/Kconfig +16 -2
index 13033198f96..563d96d4f5d 100644
@@ -89,20 +89,34 @@ config TPL_PINCTRL
 	  This option is an TPL variant of the PINCTRL option.
 	  See the help of PINCTRL for details.
 
+config VPL_PINCTRL
+	bool "Support pin controllers in VPL"
+	depends on VPL && VPL_DM
+	help
+	  This option is an VPL variant of the PINCTRL option.
+	  See the help of PINCTRL for details.
+
 config SPL_PINCTRL_FULL
 	bool "Support full pin controllers in SPL"
 	depends on SPL_PINCTRL && SPL_OF_CONTROL
 	default n if TARGET_STM32F746_DISCO
 	default y
 	help
-	  This option is an SPL-variant of the PINCTRL_FULL option.
+	  This option is an SPL variant of the PINCTRL_FULL option.
 	  See the help of PINCTRL_FULL for details.
 
 config TPL_PINCTRL_FULL
 	bool "Support full pin controllers in TPL"
 	depends on TPL_PINCTRL && TPL_OF_CONTROL
 	help
-	  This option is an TPL-variant of the PINCTRL_FULL option.
+	  This option is a TPL variant of the PINCTRL_FULL option.
+	  See the help of PINCTRL_FULL for details.
+
+config VPL_PINCTRL_FULL
+	bool "Support full pin controllers in VPL"
+	depends on VPL_PINCTRL && VPL_OF_CONTROL
+	help
+	  This option is a VPL variant of the PINCTRL_FULL option.
 	  See the help of PINCTRL_FULL for details.
 
 config SPL_PINCTRL_GENERIC
drivers/rtc/Kconfig +9 -0
index 7a6c6efb4b0..23963271928 100644
@@ -32,6 +32,15 @@ config TPL_DM_RTC
 	  drivers to perform the actual functions. See rtc.h for a
 	  description of the API.
 
+config VPL_DM_RTC
+	bool "Enable Driver Model for RTC drivers in VPL"
+	depends on VPL_DM
+	help
+	  Enable drver model for real-time-clock drivers. The RTC uclass
+	  then provides the rtc_get()/rtc_set() interface, delegating to
+	  drivers to perform the actual functions. See rtc.h for a
+	  description of the API.
+
 config RTC_ENABLE_32KHZ_OUTPUT
 	bool "Enable RTC 32Khz output"
 	help
drivers/serial/Kconfig +20 -0
index 1e595d06004..5dcf5c019da 100644
@@ -74,6 +74,16 @@ config TPL_SERIAL_PRESENT
 	  This option enables the full UART in TPL, so if is it disabled,
 	  the full UART driver will be omitted, thus saving space.
 
+config VPL_SERIAL_PRESENT
+	bool "Provide a serial driver in VPL"
+	depends on DM_SERIAL && VPL
+	default y
+	help
+	  In very space-constrained devices even the full UART driver is too
+	  large. In this case the debug UART can still be used in some cases.
+	  This option enables the full UART in TPL, so if is it disabled,
+	  the full UART driver will be omitted, thus saving space.
+
 # Logic to allow us to use the imply keyword to set what the default port
 # should be.  The default is otherwise 1.
 config CONS_INDEX_0
@@ -195,6 +205,16 @@ config TPL_DM_SERIAL
 	  implements serial_putc() etc. The uclass interface is
 	  defined in include/serial.h.
 
+config VPL_DM_SERIAL
+	bool "Enable Driver Model for serial drivers in VPL"
+	depends on DM_SERIAL
+	default y if VPL && DM_SERIAL
+	help
+	  Enable driver model for serial in VPL. This replaces
+	  drivers/serial/serial.c with the serial uclass, which
+	  implements serial_putc() etc. The uclass interface is
+	  defined in include/serial.h.
+
 config DEBUG_UART
 	bool "Enable an early debug UART for debugging"
 	help
drivers/sysreset/Kconfig +10 -0
index 25dd02c7049..a0acffa4b07 100644
@@ -31,6 +31,16 @@ config TPL_SYSRESET
 	  to effect a reset. The uclass will try all available drivers when
 	  reset_walk() is called.
 
+config VPL_SYSRESET
+	bool "Enable support for system reset drivers in VPL mode"
+	depends on SYSRESET && VPL_DM
+	default y if TPL_SYSRESET
+	help
+	  Enable system reset drivers which can be used to reset the CPU or
+	  board. Each driver can provide a reset method which will be called
+	  to effect a reset. The uclass will try all available drivers when
+	  reset_walk() is called.
+
 if SYSRESET
 
 config SYSRESET_CMD_RESET
drivers/timer/Kconfig +10 -0
index 92050179c28..2eda3bcca5b 100644
@@ -27,6 +27,16 @@ config TPL_TIMER
 	  function. This enables the drivers in drivers/timer as part of an
 	  TPL build.
 
+config VPL_TIMER
+	bool "Enable driver model for timer drivers in VPL"
+	depends on TIMER && VPL
+	default y if TPL_TIMER
+	help
+	  Enable support for timer drivers in VPL. These can be used to get
+	  a timer value when in VPL, or perhaps for implementing a delay
+	  function. This enables the drivers in drivers/timer as part of an
+	  TPL build.
+
 config TIMER_EARLY
 	bool "Allow timer to be used early in U-Boot"
 	depends on TIMER
drivers/tpm/Kconfig +30 -0
index 406ee8716e1..eceff27d5f8 100644
@@ -137,6 +137,36 @@ config TPM2_CR50_I2C
 	  trust for a device, It operates like a TPM and can be used with
 	  verified boot. Cr50 is used on recent Chromebooks (since 2017).
 
+config SPL_TPM2_CR50_I2C
+	bool "Enable support for Google cr50 TPM"
+	depends on DM_I2C && SPL_TPM
+	help
+	  Cr50 is an implementation of a TPM on Google's H1 security chip.
+	  This uses the same open-source firmware as the Chromium OS EC.
+	  While Cr50 has other features, its primary role is as the root of
+	  trust for a device, It operates like a TPM and can be used with
+	  verified boot. Cr50 is used on recent Chromebooks (since 2017).
+
+config TPL_TPM2_CR50_I2C
+	bool "Enable support for Google cr50 TPM"
+	depends on DM_I2C && TPL_TPM
+	help
+	  Cr50 is an implementation of a TPM on Google's H1 security chip.
+	  This uses the same open-source firmware as the Chromium OS EC.
+	  While Cr50 has other features, its primary role is as the root of
+	  trust for a device, It operates like a TPM and can be used with
+	  verified boot. Cr50 is used on recent Chromebooks (since 2017).
+
+config VPL_TPM2_CR50_I2C
+	bool "Enable support for Google cr50 TPM"
+	depends on DM_I2C && VPL_TPM
+	help
+	  Cr50 is an implementation of a TPM on Google's H1 security chip.
+	  This uses the same open-source firmware as the Chromium OS EC.
+	  While Cr50 has other features, its primary role is as the root of
+	  trust for a device, It operates like a TPM and can be used with
+	  verified boot. Cr50 is used on recent Chromebooks (since 2017).
+
 config TPM2_TIS_SANDBOX
 	bool "Enable sandbox TPMv2.x driver"
 	depends on TPM_V2 && SANDBOX
dts/Kconfig +17 -0
index b19912d10dd..f1d05cc0803 100644
@@ -65,6 +65,15 @@ config TPL_OF_CONTROL
 	  which is not enough to support device tree. Enable this option to
 	  allow such boards to be supported by U-Boot TPL.
 
+config VPL_OF_CONTROL
+	bool "Enable run-time configuration via Device Tree in VPL"
+	depends on VPL && OF_CONTROL
+	default y if SPL_OF_CONTROL
+	help
+	  Some boards use device tree in U-Boot but only have 4KB of SRAM
+	  which is not enough to support device tree. Enable this option to
+	  allow such boards to be supported by U-Boot VPL.
+
 config OF_LIVE
 	bool "Enable use of a live tree"
 	depends on DM && OF_CONTROL
@@ -523,4 +532,12 @@ config TPL_OF_PLATDATA_DRIVER_RT
 
 endif
 
+config VPL_OF_REAL
+	def_bool y
+	help
+	  Indicates that a real devicetree is available which can be accessed
+	  at runtime. This means that dev_read_...() functions can be used to
+	  read data from the devicetree for each device. This is true if
+	  TPL_OF_CONTROL is enabled and not TPL_OF_PLATDATA
+
 endmenu
lib/Kconfig +62 -0

116 lines not on this page · raw message

Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#11 lore raw

PATCH v8 10/13 sandbox: Add a build for VPL

In reply to Simon Glass

Add an initial VPL build for sandbox. This includes the flow:

TPL (with of-platdata) -> VPL -> SPL -> U-Boot

To run it:

./tpl/u-boot-tpl -D

The -D is needed to get the default device tree, which includes the serial console info.

Add a Makefile check for OF_HOSTFILE which is the option that enables devicetree control on sandbox.

---

Changes in v8:
- Update defconfig to account for option changes
- Drop reference to old OF_HOSTFILE option

Changes in v7:
- Rebase to master
- Update some options based on settings in master

Changes in v6:
- Add docs for sandbox_vpl build
- Drop TPL_HASH_SUPPORT patch since we only have SPL_HASH now

Changes in v4:
- Add a sandbox_vpl build
- Update cover letter

 arch/sandbox/Kconfig          |   8 ++
 arch/sandbox/cpu/spl.c        |  12 +-
 arch/sandbox/dts/sandbox.dtsi |  10 +-
 board/sandbox/MAINTAINERS     |   7 +
 configs/sandbox_vpl_defconfig | 251 ++++++++++++++++++++++++++++++++++
 doc/arch/sandbox.rst          |  13 ++
 6 files changed, 294 insertions(+), 7 deletions(-)
 create mode 100644 configs/sandbox_vpl_defconfig
arch/sandbox/Kconfig +8 -0
index 477c51960da..5f55c7f28e1 100644
@@ -29,6 +29,14 @@ config SANDBOX_SPL
 	bool "Enable SPL for sandbox"
 	select SUPPORT_SPL
 
+config SANDBOX_TPL
+	bool "Enable TPL for sandbox"
+	select SUPPORT_TPL
+
+config SANDBOX_VPL
+	bool "Enable VPL for sandbox"
+	select SUPPORT_VPL
+
 config SYS_CONFIG_NAME
 	default "sandbox_spl" if SANDBOX_SPL
 	default "sandbox" if !SANDBOX_SPL
arch/sandbox/cpu/spl.c +9 -3
index 3f107b8acbd..fe5d44d36ed 100644
@@ -32,13 +32,21 @@ int sandbox_find_next_phase(char *fname, int maxlen, bool use_img)
 	return 0;
 }
 
-/* SPL / TPL init function */
+/* SPL / TPL / VPL init function */
 void board_init_f(ulong flag)
 {
 	struct sandbox_state *state = state_get_current();
+	int ret;
 
 	gd->arch.ram_buf = state->ram_buf;
 	gd->ram_size = state->ram_size;
+
+	ret = spl_early_init();
+	if (ret) {
+		debug("spl_early_init() failed: %d\n", ret);
+		hang();
+	}
+	preloader_console_init();
 }
 
 u32 spl_boot_device(void)
@@ -75,8 +83,6 @@ void spl_board_init(void)
 {
 	struct sandbox_state *state = state_get_current();
 
-	preloader_console_init();
-
 	if (state->run_unittests) {
 		struct unit_test *tests = UNIT_TEST_ALL_START();
 		const int count = UNIT_TEST_ALL_COUNT();
arch/sandbox/dts/sandbox.dtsi +6 -4
index 29306ac04da..aa22b8765c8 100644
@@ -254,7 +254,7 @@
 	};
 
 	spl-test {
-		u-boot,dm-pre-reloc;
+		u-boot,dm-spl;
 		compatible = "sandbox,spl-test";
 		boolval;
 		intval = <1>;
@@ -268,7 +268,7 @@
 	};
 
 	spl-test2 {
-		u-boot,dm-pre-reloc;
+		u-boot,dm-spl;
 		compatible = "sandbox,spl-test";
 		intval = <3>;
 		intarray = <5>;
@@ -280,14 +280,14 @@
 	};
 
 	spl-test3 {
-		u-boot,dm-pre-reloc;
+		u-boot,dm-spl;
 		compatible = "sandbox,spl-test";
 		stringarray = "one";
 		maybe-empty-int = <1>;
 	};
 
 	spl-test5 {
-		u-boot,dm-tpl;
+		u-boot,dm-vpl;
 		compatible = "sandbox,spl-test";
 		stringarray = "tpl";
 	};
@@ -334,6 +334,8 @@
 	/* Needs to be available prior to relocation */
 	uart0: serial {
 		u-boot,dm-spl;
+		u-boot,dm-tpl;
+		u-boot,dm-vpl;
 		compatible = "sandbox,serial";
 		sandbox,text-colour = "cyan";
 		pinctrl-names = "default";
board/sandbox/MAINTAINERS +7 -0
index d32561cd1d0..9f5073bf287 100644
@@ -33,3 +33,10 @@ S:	Maintained
 F:	board/sandbox/
 F:	include/configs/sandbox.h
 F:	configs/sandbox_flattree_defconfig
+
+SANDBOX VPL BOARD
+M:	Simon Glass <[email protected]>
+S:	Maintained
+F:	board/sandbox/
+F:	include/configs/sandbox_spl.h
+F:	configs/sandbox_vpl_defconfig
configs/sandbox_vpl_defconfig new file +251 -0

251 lines not on this page · raw message

doc/arch/sandbox.rst +13 -0
index e1119492b45..bc670b98b7e 100644
@@ -420,6 +420,19 @@ state_setprop() which does this automatically and avoids running out of
 space. See existing code for examples.
 
 
+VPL (Verifying Program Loader)
+------------------------------
+
+Sandbox provides an example build of vpl called `sandbox_vpl`. This can be run
+using::
+
+   /path/to/sandbox_vpl/tpl/u-boot-tpl -D
+
+It starts up TPL (first-stage init), then VPL, then runs SPL and finally U-Boot
+proper, following the normal flow for a verified boot. At present, no
+verification is actually implemented.
+
+
 Debugging the init sequence
 ---------------------------
 
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#12 lore raw

PATCH v8 11/13 vpl: Support running vpl tests

In reply to Simon Glass

Add support for these to the pytest system.

---

Changes in v8:
- Add new patch to support running vpl tests

 test/py/conftest.py               |  7 +++++--
 test/py/tests/test_vpl.py         | 34 +++++++++++++++++++++++++++++++
 test/py/u_boot_console_sandbox.py |  7 ++++++-
 3 files changed, 45 insertions(+), 3 deletions(-)
 create mode 100644 test/py/tests/test_vpl.py
test/py/conftest.py +5 -2
index 16e445cd8ee..2ba34479e03 100644
@@ -322,8 +322,11 @@ def pytest_generate_tests(metafunc):
         if fn == 'ut_subtest':
             generate_ut_subtest(metafunc, fn, '/u-boot.sym')
             continue
-        if fn == 'ut_spl_subtest':
-            generate_ut_subtest(metafunc, fn, '/spl/u-boot-spl.sym')
+        m_subtest = re.match('ut_(.)pl_subtest', fn)
+        if m_subtest:
+            spl_name = m_subtest.group(1)
+            generate_ut_subtest(
+                metafunc, fn, f'/{spl_name}pl/u-boot-{spl_name}pl.sym')
             continue
         generate_config(metafunc, fn)
 
test/py/tests/test_vpl.py new file +34 -0
new file mode 100644
index 00000000000..4af578b9173
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright 2022 Google LLC
+# Written by Simon Glass <[email protected]>
+
+import os.path
+import pytest
+
+def test_vpl(u_boot_console, ut_vpl_subtest):
+    """Execute a "ut" subtest.
+
+    The subtests are collected in function generate_ut_subtest() from linker
+    generated lists by applying a regular expression to the lines of file
+    vpl/u-boot-vpl.sym. The list entries are created using the C macro
+    UNIT_TEST().
+
+    Strict naming conventions have to be followed to match the regular
+    expression. Use UNIT_TEST(foo_test_bar, _flags, foo_test) for a test bar in
+    test suite foo that can be executed via command 'ut foo bar' and is
+    implemented in C function foo_test_bar().
+
+    Args:
+        u_boot_console (ConsoleBase): U-Boot console
+        ut_subtest (str): VPL test to be executed (e.g. 'dm platdata_phandle')
+    """
+    try:
+        cons = u_boot_console
+        cons.restart_uboot_with_flags(['-u', '-k', ut_vpl_subtest.split()[1]])
+        output = cons.get_spawn_output().replace('\r', '')
+        assert 'Failures: 0' in output
+    finally:
+        # Restart afterward in case a non-VPL test is run next. This should not
+        # happen since VPL tests are run in their own invocation of test.py, but
+        # the cost of doing this is not too great at present.
+        u_boot_console.restart_uboot()
test/py/u_boot_console_sandbox.py +6 -1
index b79ec817957..27c6db8d719 100644
@@ -44,7 +44,12 @@ class ConsoleSandbox(ConsoleBase):
 
         bcfg = self.config.buildconfig
         config_spl = bcfg.get('config_spl', 'n') == 'y'
-        fname = '/spl/u-boot-spl' if config_spl else '/u-boot'
+        config_vpl = bcfg.get('config_vpl', 'n') == 'y'
+        if config_vpl:
+            # Run TPL first, which runs VPL
+            fname = '/tpl/u-boot-tpl'
+        else:
+            fname = '/spl/u-boot-spl' if config_spl else '/u-boot'
         print(fname)
         cmd = []
         if self.config.gdbserver:
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#13 lore raw

PATCH v8 12/13 vpl: Test that VPL runs correctly through to U-Boot proper

In reply to Simon Glass

Check the TPL -> VPL -> SPL -> U-Boot path by running the 'help' command in U-Boot.

---

(no changes since v1)

 test/py/tests/test_help.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)
test/py/tests/test_help.py +12 -0
index 03b9d91c117..153133cf28f 100644
@@ -20,3 +20,15 @@ def test_help_no_devicetree(u_boot_console):
     finally:
         # Restart afterward to get the normal device tree back
         u_boot_console.restart_uboot()
+
[email protected]('sandbox_vpl')
+def test_vpl_help(u_boot_console):
+    try:
+        cons = u_boot_console
+        cons.restart_uboot()
+        cons.run_command('help')
+        output = cons.get_spawn_output().replace('\r', '')
+        assert 'print command description/usage' in output
+    finally:
+        # Restart afterward to get the normal device tree back
+        u_boot_console.restart_uboot()
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
#14 lore raw

PATCH v8 13/13 CI: Run VPL tests

In reply to Simon Glass

Add tests for VPL into the mix. For now this just runs the help test and a few SPL ones.

---

(no changes since v1)

 .azure-pipelines.yml | 3 +++
 .gitlab-ci.yml       | 6 ++++++
 2 files changed, 9 insertions(+)
.azure-pipelines.yml +3 -0
index 48a587a59ea..4e5c4b785a7 100644
@@ -245,6 +245,9 @@ stages:
         sandbox_spl:
           TEST_PY_BD: "sandbox_spl"
           TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
+        sandbox_vpl:
+          TEST_PY_BD: "sandbox_vpl"
+          TEST_PY_TEST_SPEC: "test_vpl_help or test_spl"
         sandbox_noinst:
           TEST_PY_BD: "sandbox_noinst"
           TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
.gitlab-ci.yml +6 -0
index f193ffd3cbc..c6a608f7e2a 100644
@@ -260,6 +260,12 @@ sandbox_noinst_test.py:
     TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
   <<: *buildman_and_testpy_dfn
 
+sandbox_vpl test.py:
+  variables:
+    TEST_PY_BD: "sandbox_vpl"
+    TEST_PY_TEST_SPEC: "test_vpl_help or test_spl"
+  <<: *buildman_and_testpy_dfn
+
 evb-ast2500 test.py:
   variables:
     TEST_PY_BD: "evb-ast2500"
Signature · 1 line
2.36.0.464.gb9c8b46e94-goog