Skip to content

Commit

Permalink
zephyr: Create common boot serial enter function
Browse files Browse the repository at this point in the history
Creates a common function for enterial serial recovery mode.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
  • Loading branch information
nordicjm authored and de-nordic committed Apr 13, 2023
1 parent 35941fe commit 6902abb
Showing 1 changed file with 23 additions and 36 deletions.
59 changes: 23 additions & 36 deletions boot/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,25 @@ static bool detect_pin(void)
}
#endif

#ifdef CONFIG_MCUBOOT_SERIAL
static void boot_serial_enter()
{
int rc;

#ifdef CONFIG_MCUBOOT_INDICATION_LED
gpio_pin_set_dt(&led0, 1);
#endif

mcuboot_status_change(MCUBOOT_STATUS_SERIAL_DFU_ENTERED);

BOOT_LOG_INF("Enter the serial recovery mode");
rc = boot_console_init();
__ASSERT(rc == 0, "Error initializing boot console.\n");
boot_serial_start(&boot_funcs);
__ASSERT(0, "Bootloader serial process was terminated unexpectedly.\n");
}
#endif

void main(void)
{
struct boot_rsp rsp;
Expand Down Expand Up @@ -514,36 +533,16 @@ void main(void)
#ifdef CONFIG_BOOT_SERIAL_ENTRANCE_GPIO
if (detect_pin() &&
!boot_skip_serial_recovery()) {
#ifdef CONFIG_MCUBOOT_INDICATION_LED
gpio_pin_set_dt(&led0, 1);
#endif

mcuboot_status_change(MCUBOOT_STATUS_SERIAL_DFU_ENTERED);

BOOT_LOG_INF("Enter the serial recovery mode");
rc = boot_console_init();
__ASSERT(rc == 0, "Error initializing boot console.\n");
boot_serial_start(&boot_funcs);
__ASSERT(0, "Bootloader serial process was terminated unexpectedly.\n");
boot_serial_enter();
}
#endif

#ifdef CONFIG_BOOT_SERIAL_PIN_RESET
rc = hwinfo_get_reset_cause(&reset_cause);

if (rc == 0 && reset_cause == RESET_PIN) {
#ifdef CONFIG_MCUBOOT_INDICATION_LED
gpio_pin_set_dt(&led0, 1);
#endif

mcuboot_status_change(MCUBOOT_STATUS_SERIAL_DFU_ENTERED);
(void)hwinfo_clear_reset_cause();

BOOT_LOG_INF("Enter the serial recovery mode");
rc = boot_console_init();
__ASSERT(rc == 0, "Error initializing boot console.\n");
boot_serial_start(&boot_funcs);
__ASSERT(0, "Bootloader serial process was terminated unexpectedly.\n");
boot_serial_enter();
}
#endif

Expand Down Expand Up @@ -600,14 +599,8 @@ void main(void)
/* Boot mode to stay in bootloader, clear status and enter 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();
bootmode_clear();
boot_serial_start(&boot_funcs);
boot_serial_enter();
}
#endif

Expand All @@ -629,13 +622,7 @@ void main(void)
/* 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);
boot_serial_enter();
#endif

FIH_PANIC;
Expand Down

0 comments on commit 6902abb

Please sign in to comment.