Commit e58f9bd0 authored by Jon Helge Nistad's avatar Jon Helge Nistad Committed by Andrzej Puzdrowski
Browse files

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: default avatarJon Helge Nistad <jon.helge.nistad@nordicsemi.no>
parent 3c44607e
Loading
Loading
Loading
Loading
+22 −2
Changes for boot/zephyr/main.c: 22 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -44,6 +44,26 @@ const struct boot_uart_funcs boot_funcs = {
#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 @@ void main(void)
    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");