zephyr: Wrapped the RAM loading mode in Zephyr configs.

The RAM loading mode wasn't wrapped in Zephyr configs like the other boot modes.
Added a config to enable RAM loading as well as two configs to set
IMAGE_EXECUTABLE_RAM_START and IMAGE_EXECUTABLE_RAM_SIZE, respectively. These
two values default to the values from the chosen node sram in the dts.

Signed-off-by: Johan Öhman <johan.ohman@softube.com>
diff --git a/boot/zephyr/Kconfig b/boot/zephyr/Kconfig
index 5f899fe..0efd0f0 100644
--- a/boot/zephyr/Kconfig
+++ b/boot/zephyr/Kconfig
@@ -234,8 +234,30 @@
 	  images must be linked to be executed from the given image slot. Using this
 	  mode results in a simpler code path and smaller code size.
 
+config BOOT_RAM_LOAD
+	bool "RAM load"
+	help
+	  If y, mcuboot selects the newest valid image based on the image version
+	  numbers, thereafter the selected image is copied to RAM and executed from
+	  there. For this reason, the image has to be linked to be executed from RAM.
+	  The address that the image is copied to is specified using the load-addr
+	  argument to the imgtool.py script which writes it to the image header.
+
 endchoice
 
+# Workaround for not being able to have commas in macro arguments
+DT_CHOSEN_Z_SRAM := zephyr,sram
+
+if BOOT_RAM_LOAD
+config BOOT_IMAGE_EXECUTABLE_RAM_START
+	hex "Boot image executable ram start"
+	default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_SRAM))
+
+config BOOT_IMAGE_EXECUTABLE_RAM_SIZE
+	int "Boot image executable base size"
+	default $(dt_chosen_reg_size_int,$(DT_CHOSEN_Z_SRAM),0)
+endif
+
 config BOOT_DIRECT_XIP_REVERT
 	bool "Enable the revert mechanism in direct-xip mode"
 	depends on BOOT_DIRECT_XIP
diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
index c2d6672..91a6033 100644
--- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h
+++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
@@ -87,6 +87,12 @@
 #define MCUBOOT_DIRECT_XIP_REVERT
 #endif
 
+#ifdef CONFIG_BOOT_RAM_LOAD
+#define MCUBOOT_RAM_LOAD 1
+#define IMAGE_EXECUTABLE_RAM_START CONFIG_BOOT_IMAGE_EXECUTABLE_RAM_START
+#define IMAGE_EXECUTABLE_RAM_SIZE CONFIG_BOOT_IMAGE_EXECUTABLE_RAM_SIZE
+#endif
+
 #ifdef CONFIG_UPDATEABLE_IMAGE_NUMBER
 #define MCUBOOT_IMAGE_NUMBER    CONFIG_UPDATEABLE_IMAGE_NUMBER
 #else
diff --git a/boot/zephyr/ram_load.conf b/boot/zephyr/ram_load.conf
new file mode 100644
index 0000000..4cca450
--- /dev/null
+++ b/boot/zephyr/ram_load.conf
@@ -0,0 +1,6 @@
+# Enables RAM load mode and specifies 16 MB of memory from 0x80000000
+# as a valid location for the firmware to be loaded into.
+
+CONFIG_BOOT_RAM_LOAD=y
+CONFIG_BOOT_IMAGE_EXECUTABLE_RAM_START=0x80000000
+CONFIG_BOOT_IMAGE_EXECUTABLE_RAM_SIZE=16777216
\ No newline at end of file
diff --git a/boot/zephyr/sample.yaml b/boot/zephyr/sample.yaml
index 6a42312..5d51273 100644
--- a/boot/zephyr/sample.yaml
+++ b/boot/zephyr/sample.yaml
@@ -48,3 +48,9 @@
     integration_platforms:
       - nrf52840dk_nrf52840
     tags: bootloader_mcuboot
+  sample.bootloader.mcuboot.ram_load:
+    extra_args: OVERLAY_CONFIG=./ram_load.conf
+    tags: bootloader_mcuboot
+    platform_allow: mimxrt1020_evk
+    integration_platforms:
+      - mimxrt1020_evk