boot/zephyr: Allow single image applications
The change enables usage of single image applications. This can be used
when user does not need multiple boot images and wants to use more flash
are for main application or other purposes.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
index a642088..044ec3d 100644
--- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h
+++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
@@ -58,18 +58,30 @@
#define MCUBOOT_OVERWRITE_ONLY_FAST
#endif
+#ifdef CONFIG_SINGLE_IMAGE_DFU
+#define MCUBOOT_SINGLE_IMAGE_DFU 1
+#else
+
#ifdef CONFIG_BOOT_SWAP_USING_MOVE
#define MCUBOOT_SWAP_USING_MOVE 1
#endif
-#ifdef CONFIG_LOG
-#define MCUBOOT_HAVE_LOGGING 1
+#ifdef CONFIG_UPDATEABLE_IMAGE_NUMBER
+#define MCUBOOT_IMAGE_NUMBER CONFIG_UPDATEABLE_IMAGE_NUMBER
+#else
+#define MCUBOOT_IMAGE_NUMBER 1
#endif
#ifdef CONFIG_BOOT_SWAP_SAVE_ENCTLV
#define MCUBOOT_SWAP_SAVE_ENCTLV 1
#endif
+#endif /* CONFIG_SINGLE_IMAGE_DFU */
+
+#ifdef CONFIG_LOG
+#define MCUBOOT_HAVE_LOGGING 1
+#endif
+
#ifdef CONFIG_BOOT_ENCRYPT_RSA
#define MCUBOOT_ENC_IMAGES
#define MCUBOOT_ENCRYPT_RSA
@@ -93,12 +105,6 @@
#define MCUBOOT_USE_BENCH 1
#endif
-#ifdef CONFIG_UPDATEABLE_IMAGE_NUMBER
-#define MCUBOOT_IMAGE_NUMBER CONFIG_UPDATEABLE_IMAGE_NUMBER
-#else
-#define MCUBOOT_IMAGE_NUMBER 1
-#endif
-
#ifdef CONFIG_MCUBOOT_DOWNGRADE_PREVENTION
#define MCUBOOT_DOWNGRADE_PREVENTION 1
#endif
diff --git a/boot/zephyr/include/sysflash/sysflash.h b/boot/zephyr/include/sysflash/sysflash.h
index 66dce1d..f651779 100644
--- a/boot/zephyr/include/sysflash/sysflash.h
+++ b/boot/zephyr/include/sysflash/sysflash.h
@@ -6,6 +6,8 @@
#include <devicetree.h>
#include <mcuboot_config/mcuboot_config.h>
+#ifndef CONFIG_SINGLE_IMAGE_DFU
+
#if (MCUBOOT_IMAGE_NUMBER == 1)
/*
* NOTE: the definition below returns the same values for true/false on
@@ -41,4 +43,16 @@
#define FLASH_AREA_IMAGE_SCRATCH FLASH_AREA_ID(image_scratch)
#endif
+#else /* CONFIG_SINGLE_IMAGE_DFU */
+
+#define FLASH_AREA_IMAGE_PRIMARY(x) FLASH_AREA_ID(image_0)
+#define FLASH_AREA_IMAGE_SECONDARY(x) FLASH_AREA_ID(image_0)
+/* NOTE: Scratch parition is not used by single image DFU but some of
+ * functions in common files reference it, so the definitions has been
+ * provided to allow compilation of common units.
+ */
+#define FLASH_AREA_IMAGE_SCRATCH 0
+
+#endif /* CONFIG_SINGLE_IMAGE_DFU */
+
#endif /* __SYSFLASH_H__ */
diff --git a/boot/zephyr/include/target.h b/boot/zephyr/include/target.h
index 2e0f5fd..d585b9c 100644
--- a/boot/zephyr/include/target.h
+++ b/boot/zephyr/include/target.h
@@ -37,8 +37,8 @@
(defined(CONFIG_XTENSA) && !defined(JEDEC_SPI_NOR_0_LABEL)) || \
!defined(FLASH_ALIGN) || \
!(FLASH_AREA_LABEL_EXISTS(image_0)) || \
- !(FLASH_AREA_LABEL_EXISTS(image_1)) || \
- (!defined(CONFIG_BOOT_SWAP_USING_MOVE) && !(FLASH_AREA_LABEL_EXISTS(image_scratch)))
+ !(FLASH_AREA_LABEL_EXISTS(image_1) || CONFIG_SINGLE_IMAGE_DFU) || \
+ (!defined(CONFIG_BOOT_SWAP_USING_MOVE) && !FLASH_AREA_LABEL_EXISTS(image_scratch) && !defined(CONFIG_SINGLE_IMAGE_DFU))
#error "Target support is incomplete; cannot build mcuboot."
#endif