zephyr: migrate signature type to Kconfig
Handle the CONFIG_BOOT_SIGNATURE_TYPE_xxx values in Zephyr's
mcuboot_config.h by converting them into the platform-agnostic MCUboot
definitions.
This requires some changes to the way the release test Makefile is
structured, since Kconfig symbols cannot be set from the command line.
Instead, use the OVERLAY_CONFIG feature of the Zephyr build system,
which allows specifying extra fragments to merge into the final
.config. (This is an orthogonal mechanism to setting CONF_FILE; it is
used by Zephyr's CI script sanitycheck to add additional fragments, so
it's appropriate for use by MCUboot's testing scripts as well.)
We additionally need to move to a single prj.conf file due to a
dependency issue. We can no longer determine CONF_FILE from the
signature type, since that is now determined from the final .config or
autoconf.h, which is a build output that depends on CONF_FILE.
To move to a single prj.conf:
- delete prj-p256.conf and adjust prj.conf to serve both signature types
- add a top-level mbedTLS configuration file which dispatches to
the right sub-header depending on the key type
- as a side effect, have the simulator pick the right config file
depending on the case
This fixes and cleans up quite a bit of the signature type handling,
which had become something of a mess over time. For example, it fixes
a bug in ECDSA mode's configuration that wasn't actually selecting
config-asn1.h, and forces the simulator to use the same mbedTLS
configuration file as builds for real hardware.
Finally, we also have to move the mbedTLS vs. TinyCrypt choice into
mcuboot_config.h at the same time as well, since CMakeLists.txt was
making that decision based on the signature type.
Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
diff --git a/samples/zephyr/Makefile b/samples/zephyr/Makefile
index 8d55e30..464cf6e 100644
--- a/samples/zephyr/Makefile
+++ b/samples/zephyr/Makefile
@@ -52,6 +52,10 @@
# setting this.
BOOTLOADER_CONFIG ?=
+# Extra .conf fragments to merge into the MCUboot .config, as a
+# semicolon-separated list (i.e., a CMake list).
+BOOTLOADER_OVERLAY_CONFIG ?=
+
BOARD ?= frdm_k64f
.PHONY: check boot hello1 clean_boot clean_hello1 \
@@ -106,6 +110,7 @@
(mkdir -p $(BUILD_DIR_BOOT) && \
cd $(BUILD_DIR_BOOT) && \
cmake $(BOOTLOADER_CONFIG) \
+ -DOVERLAY_CONFIG=$(BOOTLOADER_OVERLAY_CONFIG) \
-G"Unix Makefiles" \
-DBOARD=$(BOARD) \
$(SOURCE_DIRECTORY)/../../boot/zephyr && \
@@ -188,7 +193,7 @@
# reset: hello1 runs
test-good-rsa: clean
$(MAKE) \
- BOOTLOADER_CONFIG="-DCONF_SIGNATURE_TYPE=RSA" \
+ BOOTLOADER_OVERLAY_CONFIG=$(PWD)/overlay-rsa.conf \
all
# Test a good image, with a good upgrade, using ECDSA signatures.
@@ -198,7 +203,7 @@
# reset: hello1 runs
test-good-ecdsa: clean
$(MAKE) \
- BOOTLOADER_CONFIG="-DCONF_SIGNATURE_TYPE=ECDSA_P256" \
+ BOOTLOADER_OVERLAY_CONFIG=$(PWD)/overlay-ecdsa-p256.conf \
SIGNING_KEY=../../root-ec-p256.pem \
all
@@ -221,10 +226,10 @@
# reset: hello1 runs
test-bad-rsa-upgrade: clean
$(MAKE) \
- BOOTLOADER_CONFIG="-DCONF_SIGNATURE_TYPE=RSA" \
+ BOOTLOADER_OVERLAY_CONFIG=$(PWD)/overlay-rsa.conf \
boot hello1
$(MAKE) \
- BOOTLOADER_CONFIG="-DCONF_SIGNATURE_TYPE=RSA" \
+ BOOTLOADER_OVERLAY_CONFIG=$(PWD)/overlay-rsa.conf \
SIGNING_KEY=../../root-ec-p256.pem \
hello2
@@ -236,11 +241,11 @@
# reset: hello1 runs
test-bad-ecdsa-upgrade: clean
$(MAKE) \
- BOOTLOADER_CONFIG="-DCONF_SIGNATURE_TYPE=ECDSA_P256" \
+ BOOTLOADER_OVERLAY_CONFIG=$(PWD)/overlay-ecdsa-p256.conf \
SIGNING_KEY=../../root-ec-p256.pem \
boot hello1
$(MAKE) \
- BOOTLOADER_CONFIG="-DCONF_SIGNATURE_TYPE=ECDSA_P256" \
+ BOOTLOADER_OVERLAY_CONFIG=$(PWD)/overlay-ecdsa-p256.conf \
SIGNING_KEY=../../root-rsa-2048.pem \
hello2
@@ -263,10 +268,10 @@
# reset: hello1 runs
test-wrong-rsa: clean
$(MAKE) \
- BOOTLOADER_CONFIG="-DCONF_SIGNATURE_TYPE=RSA" \
+ BOOTLOADER_OVERLAY_CONFIG=$(PWD)/overlay-rsa.conf \
boot hello1
$(MAKE) \
- BOOTLOADER_CONFIG="-DCONF_SIGNATURE_TYPE=RSA" \
+ BOOTLOADER_OVERLAY_CONFIG=$(PWD)/overlay-rsa.conf \
SIGNING_KEY=bad-keys/bad-rsa-2048.pem \
hello2
@@ -277,11 +282,11 @@
# reset: hello1 runs
test-wrong-ecdsa: clean
$(MAKE) \
- BOOTLOADER_CONFIG="-DCONF_SIGNATURE_TYPE=ECDSA_P256" \
+ BOOTLOADER_OVERLAY_CONFIG=$(PWD)/overlay-ecdsa-p256.conf \
SIGNING_KEY=../../root-ec-p256.pem \
boot hello1
$(MAKE) \
- BOOTLOADER_CONFIG="-DCONF_SIGNATURE_TYPE=ECDSA_P256" \
+ BOOTLOADER_OVERLAY_CONFIG=$(PWD)/overlay-ecdsa-p256.conf \
SIGNING_KEY=bad-keys/bad-ec-p256.pem \
hello2
diff --git a/samples/zephyr/overlay-ecdsa-p256.conf b/samples/zephyr/overlay-ecdsa-p256.conf
new file mode 100644
index 0000000..722fcf5
--- /dev/null
+++ b/samples/zephyr/overlay-ecdsa-p256.conf
@@ -0,0 +1,2 @@
+# Kconfig overlay for building with ECDSA-P256 signatures
+CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y
diff --git a/samples/zephyr/overlay-rsa.conf b/samples/zephyr/overlay-rsa.conf
new file mode 100644
index 0000000..539e779
--- /dev/null
+++ b/samples/zephyr/overlay-rsa.conf
@@ -0,0 +1,2 @@
+# Kconfig overlay for building with RSA signatures
+CONFIG_BOOT_SIGNATURE_TYPE_RSA=y