sunxi: support signed images in SPL without SPL_DM
Subsystems (2)
cover sunxi: support signed images in SPL without SPL_DM
This series adds support for signed SPL/U-Boot FIT images on Sunxi platforms and removes the unnecessary SPL_DM dependency for RSA verification.
Patch 1 allows FIT signature verification in SPL to work on boards that do not enable SPL_DM by falling back to the software RSA implementation when no hardware modular exponentiation driver is available.
Patch 2 extends sunxi-u-boot.dtsi to add conditional nodes for hashes and signatures, following the same approach used in the Rockchip u-boot.dtsi. This enables secure boot flows where SPL can verify U-Boot and associated binaries before handing over control.
Tested on a Sunxi board with CONFIG_SPL_FIT_SIGNATURE enabled and SPL_DM disabled, verifying a signed U-Boot image successfully.
Lukas Schmid (2):
rsa: allow operation without SPL_DM by falling back to software
sunxi: u-boot.dtsi: add support for signed SPL and U-Boot images
arch/arm/dts/sunxi-u-boot.dtsi | 68 ++++++++++++++++++++++++++++++++-- boot/Kconfig | 2 +- lib/rsa/rsa-verify.c | 4 +- 3 files changed, 67 insertions(+), 7 deletions(-)
Signature · 1 line
2.39.5
PATCH 1/2 rsa: allow operation without SPL_DM by falling back to software
Boards using secure boot but lacking SPL_DM support currently cannot use FIT signature verification in SPL, as SPL_FIT_SIGNATURE depends on SPL_DM. This dependency is only needed for hardware RSA modular exponentiation drivers; software RSA verification works without DM.
Remove the SPL_DM dependency in Kconfig and guard the hardware RSA path in rsa-verify.c with CONFIG_IS_ENABLED(DM). This allows SPL to verify signed FIT images using the software RSA implementation on non-DM systems.
--- boot/Kconfig | 2 +- lib/rsa/rsa-verify.c | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-)
boot/Kconfig +1 -1
@@ -203,7 +203,7 @@ config SPL_FIT_FULL_CHECK config SPL_FIT_SIGNATURE bool "Enable signature verification of FIT firmware within SPL" - depends on SPL_DM +# depends on SPL_DM depends on SPL_LOAD_FIT || SPL_LOAD_FIT_FULL select FIT_SIGNATURE select SPL_FIT
lib/rsa/rsa-verify.c +16 -11
@@ -327,8 +327,9 @@ static int rsa_verify_key(struct image_sign_info *info, const uint32_t key_len) {int ret; -#if !defined(USE_HOSTCC ) -struct udevice *mod_exp_dev; +#ifndef USE_HOSTCC +if (IS_ENABLED (CONFIG_DM )) + struct udevice *mod_exp_dev;#endif struct checksum_algo *checksum = info->checksum;struct padding_algo *padding = info->padding;
@@ -354,17 +355,21 @@ static int rsa_verify_key(struct image_sign_info *info,uint8_t buf[sig_len]; hash_len = checksum->checksum_len; -#if !defined(USE_HOSTCC ) - ret =uclass_get_device (UCLASS_MOD_EXP ,0 , &mod_exp_dev); -if (ret) { -printf ("RSA: Can't find Modular Exp implementation\n" ); -return -EINVAL ; - } +#ifndef USE_HOSTCC +if (IS_ENABLED (CONFIG_DM )) { + ret =uclass_get_device (UCLASS_MOD_EXP ,0 , &mod_exp_dev); +if (ret) { +printf ("RSA: Can't find Modular Exp implementation\n" ); +return -EINVAL ; + } - ret =rsa_mod_exp (mod_exp_dev, sig, sig_len, prop, buf); -#else - ret =rsa_mod_exp_sw (sig, sig_len, prop, buf); + ret =rsa_mod_exp (mod_exp_dev, sig, sig_len, prop, buf); + } else#endif + { + ret =rsa_mod_exp_sw (sig, sig_len, prop, buf); + } +if (ret) {debug ("Error in Modular exponentation\n" );return ret;
Signature · 1 line
2.39.5
PATCH 2/2 sunxi: u-boot.dtsi: add support for signed SPL and U-Boot images
In reply to Lukas SchmidAdd conditional nodes to sunxi-u-boot.dtsi to support building signed SPL and U-Boot images, using the same #ifdef scheme as in the Rockchip u-boot.dtsi. When CONFIG_SPL_FIT_SIGNATURE is enabled, the FIT image includes hash and signature nodes for firmware, loadables, and device trees, enabling SPL to verify U-Boot and associated binaries before boot.
This prepares Sunxi boards for secure boot flows similar to other SoCs.
--- arch/arm/dts/sunxi-u-boot.dtsi | 68 ++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-)
arch/arm/dts/sunxi-u-boot.dtsi +64 -4
@@ -27,6 +27,38 @@ #endif &binman { +#ifdef CONFIG_SPL_FIT_SIGNATURE + spl { +#ifdef CONFIG_SPL_IMAGE_TYPE_SUNXI_TOC0 + filename = "spl/u-boot-spl.bin"; +#else + filename = "spl/sunxi-spl.bin"; +#endif + + u-boot-spl-nodtb { + }; + + u-boot-spl-pubkey-dtb { + algo = "sha256,rsa2048"; + required = "conf"; + key-name-hint = "dev"; + }; + }; + +#ifdef CONFIG_SPL_IMAGE_TYPE_SUNXI_TOC0 + image { + filename = "spl/sunxi-spl.bin"; + + mkimage { + args = "-a 0x20060 -T sunxi_toc0"; + data-to-imagename; + + u-boot-spl { + }; + }; + }; +#endif +#endif u-boot-sunxi-with-spl { filename = "u-boot-sunxi-with-spl.bin"; pad-byte = <0xff>;
@@ -45,6 +77,9 @@ description = "Configuration to load U-Boot and firmware"; #address-cells = <1>; fit,fdt-list = "of-list"; +#ifdef CONFIG_SPL_FIT_SIGNATURE + fit,sign; +#endif images { uboot {
@@ -60,6 +95,11 @@ u-boot-nodtb { }; +#ifdef CONFIG_SPL_FIT_SIGNATURE + hash { + algo = "sha256"; + }; +#endif }; #if CONFIG_SUNXI_BL31_BASE
@@ -76,6 +116,11 @@ filename = "bl31.bin"; missing-msg = "atf-bl31-sunxi"; }; +#ifdef CONFIG_SPL_FIT_SIGNATURE + hash { + algo = "sha256"; + }; +#endif }; #endif
@@ -92,6 +137,11 @@ missing-msg = "scp-sunxi"; optional; }; +#ifdef CONFIG_SPL_FIT_SIGNATURE + hash { + algo = "sha256"; + }; +#endif }; #endif
@@ -99,6 +149,11 @@ description = "NAME"; type = "flat_dt"; compression = "none"; +#ifdef CONFIG_SPL_FIT_SIGNATURE + hash { + algo = "sha256"; + }; +#endif }; };
@@ -108,16 +163,21 @@ @config-SEQ { description = "NAME"; #if CONFIG_SUNXI_BL31_BASE - firmware = "atf"; + firmware = "atf", "uboot"; #else firmware = "uboot"; #endif #if CONFIG_SUNXI_SCP_BASE - loadables = "scp", "uboot"; -#else - loadables = "uboot"; + loadables = "scp"; #endif fdt = "fdt-SEQ"; +#ifdef CONFIG_SPL_FIT_SIGNATURE + signature { + algo = "sha256,rsa2048"; + key-name-hint = "dev"; + sign-images = "firmware", "loadables", "fdt"; + }; +#endif }; }; };
Signature · 1 line
2.39.5