[PATCH v5 0/3] Support UEFI SPI I/O protocol

Paul Barker
2022-11-23T17:50:37Z

These patches add support for the UEFI SPI I/O protocol defined in the
UEFI Platform Initialization (PI) Specification, Version 1.7 Errata A
(April 2020). This allows a UEFI application to interact with devices
on the SPI bus.

This support is initially intended to be used to communicate with SPI
devices from "pre-boot" UEFI applications which perform setup before
the main OS is loaded. Other use cases may also be supported, however
this is not intended to be a replacement for UEFI capsule updates.

The "pre-boot" UEFI application which we are currently developing will
interact with a Micron Authenta[1] flash device, sending vendor-specific
commands over the SPI bus to make use of Authenta security features, to
verify flash integrity and to generate ephemeral keys based on the flash
contents.

The code here is self-contained and easy to enable/disable at compile
time. Compilation testing with am335x_evm_defconfig shows that the size
of u-boot.img increases by less than 2kB when CONFIG_EFI_SPI_PROTOCOL
is enabled.

[1]: https://www.micron.com/-/media/client/global/documents/products/product-flyer/authenta_technology_solutions_brief.pdf

Changes since v4:

* Dropped patches which have already been merged.

* Re-based on top of my other patch series [2] to avoid conflicts in
am335x-sancloud-bbe-lite-u-boot.dtsi.

* Dropped `am335x_evm_defconfig: Enable Micron SPI flash support` as
this was moved to my other patch series [3].

* Reformat code to fit in 80 chars per line where possible.

* Use efi_install_multiple_protocol_interfaces() instead of
efi_create_handle() & efi_add_protocol().

* Rename dtb properties to start with 'u-boot,'.

* Move SanCloud BBE Lite dtb changes to
am335x-sancloud-bbe-lite-u-boot.dtsi.

* Convert remaining printf() calls to debug() calls.

[2]: https://lore.kernel.org/u-boot/20221114124243.3719037-1-paul.barker@sancloud.com/
[3]: https://lore.kernel.org/u-boot/20221114124243.3719037-7-paul.barker@sancloud.com/

Changes since v3:

* Add implementation of spi_set_speed() so we can use this in
efi_spi_io_transaction().

* Rename convert_efi_string() to efi_convert_string() and move to
efi_string.c as a common helper function.

* Call spi_set_speed() instead of manually de-referencing the function
pointer in struct dm_spi_ops.

* Don't call efi_delete_handle() in destroy_efi_spi_peripheral().

* Use '%pUl' to print guid string.

* Split efi_selftest changes into a separate patch.

Changes since v2:

* Added description to efi_spi_protocol.h.

* Moved definition of EFI_SPI_CONFIGURATION_GUID to efi_api.h and
added it to the list in lib/uuid.c.

* Fixed UEFI GUID byte order in test.dts and in debug output.

* Use log_debug() instead of printf() for debug output.

* Add test cases to confirm that efi_legacy_spi_controller_protocol
functions return EFI_UNSUPPORTED (as they are not currently
implemented)

Changes since v1:

* Skip emulated SPI peripherals. These appear as duplicates within the
list of devices on the bus when using the sandbox SPI drivers.

* Make most printf statements debug only.

* Add efi_seltest unit test.

* Do not enable config EFI_SPI_PROTOCOL by default.

* Mark functions with EFIAPI where necessary.

* Handle debug_transaction argument to efi_spi_io_transaction().

* Handle a value of zero for target->max_read_size &
target->max_write_size.

* Probe inactive SPI devices when initializing the EFI SPI protocol to
ensure that dev_get_parent_priv() returns valid data and the exported
devices are ready to use.

Paul Barker (3):
efi_loader: Add SPI I/O protocol support
efi_selftest: Add tests for SPI protocol support
arm: dts: am335x-sancloud-bbe-lite: UEFI SPI export

MAINTAINERS | 7 +
.../dts/am335x-sancloud-bbe-lite-u-boot.dtsi | 13 +-
arch/arm/dts/am335x-sancloud-bbe-lite.dts | 2 +-
arch/sandbox/dts/test.dts | 13 +
configs/am335x_evm_defconfig | 1 +
include/efi_api.h | 4 +
include/efi_loader.h | 4 +
include/efi_spi_protocol.h | 166 +++++
lib/efi_loader/Kconfig | 8 +
lib/efi_loader/Makefile | 1 +
lib/efi_loader/efi_setup.c | 6 +
lib/efi_loader/efi_spi_protocol.c | 576 ++++++++++++++++++
lib/efi_selftest/Makefile | 1 +
lib/efi_selftest/efi_selftest_spi_protocol.c | 284 +++++++++
lib/uuid.c | 4 +
15 files changed, 1086 insertions(+), 4 deletions(-)
create mode 100644 include/efi_spi_protocol.h
create mode 100644 lib/efi_loader/efi_spi_protocol.c
create mode 100644 lib/efi_selftest/efi_selftest_spi_protocol.c

--
2.25.1