From b26fc487ee522a754a4b93b62bc7a533ca0bfe69 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Fri, 9 Dec 2022 17:10:20 +0000 Subject: [PATCH] boot/boot_serial: Add boot_reset_request_hook to bs_reset When hooks are enabled then boot_reset_request_hook will be called to check whether it is allowed to reset a device. Signed-off-by: Dominik Ermel --- boot/boot_serial/src/boot_serial.c | 28 ++++++++++++++++++------- boot/boot_serial/src/boot_serial_priv.h | 1 + 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/boot/boot_serial/src/boot_serial.c b/boot/boot_serial/src/boot_serial.c index 14de8c11..1e453d8d 100644 --- a/boot/boot_serial/src/boot_serial.c +++ b/boot/boot_serial/src/boot_serial.c @@ -657,22 +657,34 @@ out: static void bs_reset(char *buf, int len) { - bs_rc_rsp(0); + int rc = BOOT_HOOK_CALL(boot_reset_request_hook, 0, false); + if (rc == BOOT_RESET_REQUEST_HOOK_BUSY) { + rc = MGMT_ERR_EBUSY; + } else { + /* Currently whatever else is returned it is just converted + * to 0/no error. Boot serial starts accepting "force" parameter + * in command this needs to change. + */ + rc = 0; + } + bs_rc_rsp(rc); + if (rc == 0) { #ifdef __ZEPHYR__ #ifdef CONFIG_MULTITHREADING - k_sleep(K_MSEC(250)); + k_sleep(K_MSEC(250)); #else - k_busy_wait(250000); + k_busy_wait(250000); #endif - sys_reboot(SYS_REBOOT_COLD); + sys_reboot(SYS_REBOOT_COLD); #elif __ESPRESSIF__ - esp_rom_delay_us(250000); - bootloader_reset(); + esp_rom_delay_us(250000); + bootloader_reset(); #else - os_cputime_delay_usecs(250000); - hal_system_reset(); + os_cputime_delay_usecs(250000); + hal_system_reset(); #endif + } } /* diff --git a/boot/boot_serial/src/boot_serial_priv.h b/boot/boot_serial/src/boot_serial_priv.h index 287fd0f4..6dcbd691 100644 --- a/boot/boot_serial/src/boot_serial_priv.h +++ b/boot/boot_serial/src/boot_serial_priv.h @@ -41,6 +41,7 @@ extern "C" { #define MGMT_ERR_ENOMEM 2 #define MGMT_ERR_EINVAL 3 #define MGMT_ERR_ENOTSUP 8 +#define MGMT_ERR_EBUSY 10 #define NMGR_OP_READ 0 #define NMGR_OP_WRITE 2