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/bootutil/include/bootutil/mcuboot_status.h b/boot/bootutil/include/bootutil/mcuboot_status.h
new file mode 100644
index 0000000..b734923
--- /dev/null
+++ b/boot/bootutil/include/bootutil/mcuboot_status.h
@@ -0,0 +1,30 @@
+/*
+ *  Copyright (c) 2022, Laird Connectivity
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef H_MCUBOOT_STATUS_
+#define H_MCUBOOT_STATUS_
+
+/* Enumeration representing the states that MCUboot can be in */
+typedef enum
+{
+	MCUBOOT_STATUS_STARTUP = 0,
+	MCUBOOT_STATUS_UPGRADING,
+	MCUBOOT_STATUS_BOOTABLE_IMAGE_FOUND,
+	MCUBOOT_STATUS_NO_BOOTABLE_IMAGE_FOUND,
+	MCUBOOT_STATUS_BOOT_FAILED,
+	MCUBOOT_STATUS_USB_DFU_WAITING,
+	MCUBOOT_STATUS_USB_DFU_ENTERED,
+	MCUBOOT_STATUS_USB_DFU_TIMED_OUT,
+	MCUBOOT_STATUS_SERIAL_DFU_ENTERED,
+} mcuboot_status_type_t;
+
+#if defined(CONFIG_MCUBOOT_ACTION_HOOKS)
+extern void mcuboot_status_change(mcuboot_status_type_t status);
+#else
+#define mcuboot_status_change(_status) do {} while (0)
+#endif
+
+#endif /* H_MCUBOOT_STATUS_ */
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index 6f6343c..27f2e5f 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -46,6 +46,7 @@
 #include "bootutil/fault_injection_hardening.h"
 #include "bootutil/ramload.h"
 #include "bootutil/boot_hooks.h"
+#include "bootutil/mcuboot_status.h"
 
 #ifdef MCUBOOT_ENC_IMAGES
 #include "bootutil/enc_key.h"
@@ -1998,6 +1999,9 @@
     }
 #endif
 
+    /* Trigger status change callback with upgrading status */
+    mcuboot_status_change(MCUBOOT_STATUS_UPGRADING);
+
     /* Iterate over all the images. At this point there are no aborted swaps
      * and the swap types are determined for each image. By the end of the loop
      * all required update operations will have been finished.