boot: zephyr: Add MCUboot status callback support
Adds an optional callback when the MCUboot status changes which can
allow components to react.
Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c
index e885fb0..9cd0d0a 100644
--- a/boot/zephyr/main.c
+++ b/boot/zephyr/main.c
@@ -33,6 +33,7 @@
#include "bootutil/image.h"
#include "bootutil/bootutil.h"
#include "bootutil/fault_injection_hardening.h"
+#include "bootutil/mcuboot_status.h"
#include "flash_map_backend/flash_map_backend.h"
#ifdef CONFIG_MCUBOOT_SERIAL
@@ -452,6 +453,8 @@
(void)rc;
+ mcuboot_status_change(MCUBOOT_STATUS_STARTUP);
+
#if (!defined(CONFIG_XTENSA) && DT_HAS_CHOSEN(zephyr_flash_controller))
if (!flash_device_get_binding(DT_LABEL(DT_CHOSEN(zephyr_flash_controller)))) {
BOOT_LOG_ERR("Flash device %s not found",
@@ -477,6 +480,8 @@
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");
@@ -493,6 +498,9 @@
#ifdef CONFIG_MCUBOOT_INDICATION_LED
gpio_pin_set_dt(&led0, 1);
#endif
+
+ mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_ENTERED);
+
rc = usb_enable(NULL);
if (rc) {
BOOT_LOG_ERR("Cannot enable USB");
@@ -508,8 +516,13 @@
BOOT_LOG_ERR("Cannot enable USB");
} else {
BOOT_LOG_INF("Waiting for USB DFU");
+
+ mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_WAITING);
+
wait_for_usb_dfu(K_MSEC(CONFIG_BOOT_USB_DFU_WAIT_DELAY_MS));
BOOT_LOG_INF("USB DFU wait time elapsed");
+
+ mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_TIMED_OUT);
}
#endif
@@ -537,6 +550,9 @@
if (fih_not_eq(fih_rc, FIH_SUCCESS)) {
BOOT_LOG_ERR("Unable to find bootable image");
+
+ mcuboot_status_change(MCUBOOT_STATUS_NO_BOOTABLE_IMAGE_FOUND);
+
FIH_PANIC;
}
@@ -548,9 +564,14 @@
#else
BOOT_LOG_INF("Jumping to the first image slot");
#endif
+
+ mcuboot_status_change(MCUBOOT_STATUS_BOOTABLE_IMAGE_FOUND);
+
ZEPHYR_BOOT_LOG_STOP();
do_boot(&rsp);
+ mcuboot_status_change(MCUBOOT_STATUS_BOOT_FAILED);
+
BOOT_LOG_ERR("Never should get here");
while (1)
;