boot: zephyr: Add check of RESETREAS for nRF SoC

Only execute serial recovery if valid pin condition is detected
during power up reset or pin reset on nRF devices with RESETREAS
register. This is to prevent going into serial recovery when
waking up from power off mode with the same pin conditions that
is configured to trigger serial recovery.

Signed-off-by: Jon Helge Nistad <jon.helge.nistad@nordicsemi.no>
diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c
index f561d4f..a264392 100644
--- a/boot/zephyr/main.c
+++ b/boot/zephyr/main.c
@@ -44,6 +44,26 @@
 #include <usb/class/usb_dfu.h>
 #endif
 
+#ifdef CONFIG_SOC_FAMILY_NRF
+#include <hal/nrf_power.h>
+
+static inline bool boot_skip_serial_recovery()
+{
+#if NRF_POWER_HAS_RESETREAS	
+    u32_t rr = nrf_power_resetreas_get(NRF_POWER);
+
+    return !(rr == 0 || (rr & NRF_POWER_RESETREAS_RESETPIN_MASK));
+#else
+    return false;
+#endif
+}
+#else
+static inline bool boot_skip_serial_recovery()
+{
+    return false;
+}
+#endif
+
 MCUBOOT_LOG_MODULE_REGISTER(mcuboot);
 
 void os_heap_init(void);
@@ -193,8 +213,8 @@
     rc = gpio_pin_read(detect_port, CONFIG_BOOT_SERIAL_DETECT_PIN,
                        &detect_value);
     __ASSERT(rc == 0, "Error of the reading the detect pin.\n");
-
-    if (detect_value == CONFIG_BOOT_SERIAL_DETECT_PIN_VAL) {
+    if (detect_value == CONFIG_BOOT_SERIAL_DETECT_PIN_VAL &&
+        !boot_skip_serial_recovery()) {
         BOOT_LOG_INF("Enter the serial recovery mode");
         rc = boot_console_init();
         __ASSERT(rc == 0, "Error initializing boot console.\n");