zephyr: boot: serial_recovery: Add no application entrace method

Adds a bootloader serial recovery entrance mode that will allow
recovering a module if there is no application that can be booted.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
diff --git a/boot/zephyr/Kconfig.serial_recovery b/boot/zephyr/Kconfig.serial_recovery
index 5285e98..ddde2c6 100644
--- a/boot/zephyr/Kconfig.serial_recovery
+++ b/boot/zephyr/Kconfig.serial_recovery
@@ -185,6 +185,12 @@
 	  retention system (i.e. an application must set the boot mode to stay
 	  in serial recovery mode and reboot the module).
 
+config BOOT_SERIAL_NO_APPLICATION
+	bool "Stay in bootloader if no application"
+	help
+	  Allows for entering serial recovery mode if there is no bootable
+	  application that the bootloader can jump to.
+
 endmenu
 
 config BOOT_SERIAL_IMG_GRP_HASH
diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c
index 8c2b98e..4a672fd 100644
--- a/boot/zephyr/main.c
+++ b/boot/zephyr/main.c
@@ -128,7 +128,8 @@
 #ifdef CONFIG_MCUBOOT_SERIAL
 #if !defined(CONFIG_BOOT_SERIAL_ENTRANCE_GPIO) && \
     !defined(CONFIG_BOOT_SERIAL_WAIT_FOR_DFU) && \
-    !defined(CONFIG_BOOT_SERIAL_BOOT_MODE)
+    !defined(CONFIG_BOOT_SERIAL_BOOT_MODE) && \
+    !defined(CONFIG_BOOT_SERIAL_NO_APPLICATION)
 #error "Serial recovery selected without an entrance mode set"
 #endif
 #endif
@@ -596,6 +597,19 @@
 
         mcuboot_status_change(MCUBOOT_STATUS_NO_BOOTABLE_IMAGE_FOUND);
 
+#ifdef CONFIG_BOOT_SERIAL_NO_APPLICATION
+        /* No bootable image and configuration set to remain in serial
+         * recovery mode
+         */
+#ifdef CONFIG_MCUBOOT_INDICATION_LED
+        gpio_pin_set_dt(&led0, 1);
+#endif
+
+        mcuboot_status_change(MCUBOOT_STATUS_SERIAL_DFU_ENTERED);
+        rc = boot_console_init();
+        boot_serial_start(&boot_funcs);
+#endif
+
         FIH_PANIC;
     }