zephyr: migrate upgrade-only to Kconfig

Handle CONFIG_BOOT_UPGRADE_ONLY in mcuboot_config.h, and switch the
release test Makefile to using an OVERLAY_CONFIG fragment.

This removes the last user of the Makefile BOOTLOADER_CONFIG variable,
so delete it as well.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
diff --git a/boot/zephyr/CMakeLists.txt b/boot/zephyr/CMakeLists.txt
index 641ced1..075cd83 100644
--- a/boot/zephyr/CMakeLists.txt
+++ b/boot/zephyr/CMakeLists.txt
@@ -12,21 +12,6 @@
 # Configuration choices.
 ########################
 
-# 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.
-#
-# To enable "upgrade only" mode:
-#
-#     cmake -DCONF_UPGRADE_ONLY=YES [...]
-#
-# To disable "upgrade only" mode (this is the default):
-#
-#     cmake -DCONF_UPGRADE_ONLY=NO [...]
-if (NOT DEFINED CONF_UPGRADE_ONLY)
-  set(CONF_UPGRADE_ONLY NO)
-endif()
-
 # If CONF_ZEPHYR_TRY_MASS_ERASE is set (it is set by default), the
 # Zephyr build system configuration attempts to force a mass erase
 # before flashing. This ensures the scratch and other partitions are
@@ -70,11 +55,6 @@
 # of simply deprecated.)
 list(APPEND MCUBOOT_EXTRA_CFLAGS "-DMCUBOOT_USE_FLASH_AREA_GET_SECTORS")
 
-# Check if we're operating in overwrite-only mode.
-if(CONF_UPGRADE_ONLY STREQUAL YES)
-  list (APPEND MCUBOOT_EXTRA_CFLAGS "-DMCUBOOT_OVERWRITE_ONLY" "-DMCUBOOT_OVERWRITE_ONLY_FAST")
-endif()
-
 # Add values in MCUBOOT_EXTRA_CFLAGS_STR to the Zephyr build's
 # EXTRA_CFLAGS variable.
 string(REPLACE ";" " " MCUBOOT_EXTRA_CFLAGS_STR "${MCUBOOT_EXTRA_CFLAGS}")
diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
index a916045..5872dcb 100644
--- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h
+++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
@@ -34,6 +34,11 @@
 #define MCUBOOT_VALIDATE_SLOT0
 #endif
 
+#ifdef CONFIG_BOOT_UPGRADE_ONLY
+#define MCUBOOT_OVERWRITE_ONLY
+#define MCUBOOT_OVERWRITE_ONLY_FAST
+#endif
+
 #endif /* !__BOOTSIM__ */
 
 #endif /* __MCUBOOT_CONFIG_H__ */
diff --git a/samples/zephyr/Makefile b/samples/zephyr/Makefile
index ec14c46..9b246b7 100644
--- a/samples/zephyr/Makefile
+++ b/samples/zephyr/Makefile
@@ -48,10 +48,6 @@
 # then revert back to the first app, since we did not mark this image
 # as good.
 
-# We can add on to the CMake configuration for the bootloader by
-# 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 ?=
@@ -109,8 +105,7 @@
 	@rm -f mcuboot.bin
 	(mkdir -p $(BUILD_DIR_BOOT) && \
 		cd $(BUILD_DIR_BOOT) && \
-		cmake $(BOOTLOADER_CONFIG) \
-			-DOVERLAY_CONFIG=$(BOOTLOADER_OVERLAY_CONFIG) \
+		cmake -DOVERLAY_CONFIG=$(BOOTLOADER_OVERLAY_CONFIG) \
 			-G"Unix Makefiles" \
 			-DBOARD=$(BOARD) \
 			$(SOURCE_DIRECTORY)/../../boot/zephyr && \
@@ -215,7 +210,7 @@
 # reset: hello2 runs
 test-overwrite: clean
 	$(MAKE) \
-		BOOTLOADER_CONFIG="-DCONF_UPGRADE_ONLY=YES" \
+		BOOTLOADER_OVERLAY_CONFIG=$(PWD)/overlay-upgrade-only.conf \
 		all
 
 # Test that when configured for RSA, a wrong signature in the upgrade
diff --git a/samples/zephyr/overlay-upgrade-only.conf b/samples/zephyr/overlay-upgrade-only.conf
new file mode 100644
index 0000000..bdff7ac
--- /dev/null
+++ b/samples/zephyr/overlay-upgrade-only.conf
@@ -0,0 +1,2 @@
+# Kconfig overlay for building in upgrade-only mode.
+CONFIG_BOOT_UPGRADE_ONLY=y