From 2124d4183e2a4aaed429c0d58dd2eb4cb5099ba4 Mon Sep 17 00:00:00 2001
From: Sigvart Hovland <sigvart.hovland@nordicsemi.no>
Date: Wed, 25 Jan 2023 16:30:17 +0100
Subject: [PATCH] mcuboot: multi-image: Multi Image DFU without external flash

Added the possibility to use Multi Image DFU on nRF53 without external
flash.

Ref. NCSDK-12809

Signed-off-by: Sigvart Hovland <sigvart.hovland@nordicsemi.no>
---
 .../releases/release-notes-changelog.rst      |  7 +++++++
 modules/mcuboot/boot/zephyr/Kconfig           |  1 -
 subsys/partition_manager/Kconfig              | 21 ++++++++++++++++---
 west.yml                                      |  2 +-
 4 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
index d20cde1719f4..bf10e1285e2e 100644
--- a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
+++ b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
@@ -35,6 +35,13 @@ IDE and tool support
 
 |no_changes_yet_note|
 
+MCUboot
+=======
+
+* Added:
+
+  * Support for multi-image DFU without using external flash memory on nRF53.
+
 Application development
 =======================
 
diff --git a/modules/mcuboot/boot/zephyr/Kconfig b/modules/mcuboot/boot/zephyr/Kconfig
index 53631f0ab81f..5cdcd99513b2 100644
--- a/modules/mcuboot/boot/zephyr/Kconfig
+++ b/modules/mcuboot/boot/zephyr/Kconfig
@@ -122,7 +122,6 @@ config NRF53_MULTI_IMAGE_UPDATE
 	depends on FLASH_SIMULATOR
 	depends on FLASH_SIMULATOR_DOUBLE_WRITES
 	depends on !FLASH_SIMULATOR_STATS
-	depends on PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY
 	depends on BOOT_UPGRADE_ONLY || USE_NRF53_MULTI_IMAGE_WITHOUT_UPGRADE_ONLY
 	depends on $(dt_compat_enabled,$(DT_COMPAT_SIM_FLASH))
 	select NRF53_MCUBOOT_PRIMARY_1_RAM_FLASH
diff --git a/subsys/partition_manager/Kconfig b/subsys/partition_manager/Kconfig
index 28b6e1cb0a31..531f7cb04b54 100644
--- a/subsys/partition_manager/Kconfig
+++ b/subsys/partition_manager/Kconfig
@@ -182,11 +182,26 @@ config PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY
 	# option is propagated to the MCUboot child image automatically.
 	depends on PM_EXTERNAL_FLASH_ENABLED || MCUBOOT
 	default y if BOOTLOADER_MCUBOOT
+	imply PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY_1
+	help
+	  Place the secondary partition of MCUboot image 0 in the external flash
+	  instead of the internal flash. This option should only be enabled by
+	  the user in the parent image. The value of this option is propagated to
+	  the MCUboot child image automatically.
+
+config PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY_1
+	bool "Place MCUboot secondary 1 in external flash"
+	depends on BOOTLOADER_MCUBOOT || MCUBOOT
+	# Only depend on the chosen for the parent image.
+	depends on $(dt_chosen_enabled,$(DT_CHOSEN_EXT_FLASH)) || MCUBOOT
+	depends on UPDATEABLE_IMAGE_NUMBER > 1 || !MCUBOOT
+	default y if BOOTLOADER_MCUBOOT
 	imply ADD_MCUBOOT_MEDIATE_SIM_FLASH_DTS
 	help
-	  Place the secondary partition of MCUboot in the external flash instead
-	  of the internal flash. This option should only be enabled by the user
-	  in the parent image.
+	  Place the secondary partition of MCUboot image 1 in the external flash
+	  instead of the internal flash. This option should only be enabled by
+	  the user in the parent image. The value of this option is propagated
+	  to the MCUboot child image automatically.
 
 config PM_IMAGE_NOT_BUILT_FROM_SOURCE
 	bool
diff --git a/west.yml b/west.yml
index 6e06c2e43358..73c5b8f66937 100644
--- a/west.yml
+++ b/west.yml
@@ -129,7 +129,7 @@ manifest:
           compare-by-default: true
     - name: mcuboot
       repo-path: sdk-mcuboot
-      revision: a9d5fa76a6840f8934b2aaaf51e290f91eb3f991
+      revision: pull/235/head
       path: bootloader/mcuboot
     - name: qcbor
       url: https://github.com/laurencelundblade/QCBOR.git