zephyr: migrate slot 0 validation to Kconfig
Handle CONFIG_BOOT_VALIDATE_SLOT0 in mcuboot_config.h, and switch to
setting it with an OVERLAY_CONFIG fragment in the test Makefile.
Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
diff --git a/boot/zephyr/CMakeLists.txt b/boot/zephyr/CMakeLists.txt
index 2cc2aea..641ced1 100644
--- a/boot/zephyr/CMakeLists.txt
+++ b/boot/zephyr/CMakeLists.txt
@@ -12,22 +12,6 @@
# Configuration choices.
########################
-# If CONF_VALIDATE_SLOT0 is set, the bootloader attempts to validate
-# the signature of slot0 every boot. This adds the signature check
-# time to every boot, but can mitigate against some changes that are
-# able to modify the flash image itself.
-#
-# To enable validation (this is the default):
-#
-# cmake -DCONF_VALIDATE_SLOT0=YES [...]
-#
-# To disable validation:
-#
-# cmake -DCONF_VALIDATE_SLOT0=NO [...]
-if (NOT DEFINED CONF_VALIDATE_SLOT0)
- set(CONF_VALIDATE_SLOT0 YES)
-endif()
-
# If CONF_UPGRADE_ONLY is set, overwrite slot0 with the upgrade image
# instead of swapping them. This prevents the fallback recovery, but
# uses a much simpler code path.
@@ -79,11 +63,6 @@
endif()
endmacro()
-# Check if we need to validate slot 0.
-if(CONF_VALIDATE_SLOT0 STREQUAL YES)
- list(APPEND MCUBOOT_EXTRA_CFLAGS "-DMCUBOOT_VALIDATE_SLOT0")
-endif()
-
# Enabling this option uses newer flash map APIs. This saves RAM and
# avoids deprecated API usage.
#
diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
index 03d1e37..a916045 100644
--- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h
+++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
@@ -30,6 +30,10 @@
#define MCUBOOT_USE_TINYCRYPT
#endif
+#ifdef CONFIG_BOOT_VALIDATE_SLOT0
+#define MCUBOOT_VALIDATE_SLOT0
+#endif
+
#endif /* !__BOOTSIM__ */
#endif /* __MCUBOOT_CONFIG_H__ */
diff --git a/samples/zephyr/Makefile b/samples/zephyr/Makefile
index 464cf6e..ec14c46 100644
--- a/samples/zephyr/Makefile
+++ b/samples/zephyr/Makefile
@@ -257,7 +257,7 @@
# reset: hello1 runs
test-no-bootcheck: clean
$(MAKE) \
- BOOTLOADER_CONFIG="-DCONF_VALIDATE_SLOT0=NO" \
+ BOOTLOADER_OVERLAY_CONFIG=$(PWD)/overlay-skip-slot0-validate.conf \
SIGNING_KEY=../../root-ec-p256.pem \
all
diff --git a/samples/zephyr/overlay-skip-slot0-validate.conf b/samples/zephyr/overlay-skip-slot0-validate.conf
new file mode 100644
index 0000000..dd3b2c2
--- /dev/null
+++ b/samples/zephyr/overlay-skip-slot0-validate.conf
@@ -0,0 +1,3 @@
+# Kconfig overlay for building without validating slot 0.
+
+# CONFIG_BOOT_VALIDATE_SLOT0 is not set