zephyr/boot_serial_extension: added hooks to custom image list MGMT
Introduced boot_img_install_stat_hook() hook fuinction for fetch
the image's slot installation status.
The image's slot installation status is custom property.
It's detailed definition depends on user implementation. It is only
defined that the status will be set to 0 if this hook not provides
another value.
Inserted available hook for read image header as well.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
diff --git a/boot/bootutil/include/bootutil/boot_hooks.h b/boot/bootutil/include/bootutil/boot_hooks.h
index bb5406b..61de3c4 100644
--- a/boot/bootutil/include/bootutil/boot_hooks.h
+++ b/boot/bootutil/include/bootutil/boot_hooks.h
@@ -137,4 +137,24 @@
int boot_serial_uploaded_hook(int img_index, const struct flash_area *area,
size_t size);
+/** Hook for implement the image's slot installation status fetch operation for
+ * the MGMT custom command.
+ *
+ * The image's slot installation status is custom property. It's detailed
+ * definition depends on user implementation. It is only defined that the status
+ * will be set to 0 if this hook not provides another value.
+ *
+ * @param img_index the index of the image pair
+ * @param slot slot number
+ * @param img_install_stat the image installation status to be populated
+ *
+ * @retval 0: the installaton status was fetched successfully,
+ * BOOT_HOOK_REGULAR: follow the normal execution path, status will be
+ * set to 0
+ * otherwise an error-code value. Error-code is ignored, but it is up to
+ * the implementation to reflect this error in img_install_stat.
+ */
+int boot_img_install_stat_hook(int image_index, int slot,
+ int *img_install_stat);
+
#endif /*H_BOOTUTIL_HOOKS*/
diff --git a/boot/zephyr/boot_serial_extensions.c b/boot/zephyr/boot_serial_extensions.c
index d3dafee..49bb4ea 100644
--- a/boot/zephyr/boot_serial_extensions.c
+++ b/boot/zephyr/boot_serial_extensions.c
@@ -16,6 +16,8 @@
#include "../boot_serial/src/cbor_encode.h"
#include "bootutil/image.h"
+#include "bootutil/bootutil_public.h"
+#include "bootutil/boot_hooks.h"
MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
@@ -60,33 +62,44 @@
struct flash_area const *fap;
struct image_header hdr;
int rc;
- int img_install_stat = 0;
+ int img_install_stat;
- area_id = flash_area_id_from_multi_image_slot(image_index, slot);
-
- rc = flash_area_open(area_id, &fap);
- if (rc) {
- return rc;
+ rc = BOOT_HOOK_CALL(boot_img_install_stat_hook, BOOT_HOOK_REGULAR,
+ image_index, slot, &img_install_stat);
+ if (rc == BOOT_HOOK_REGULAR)
+ {
+ img_install_stat = 0;
}
- rc = flash_area_read(fap, 0, &hdr, sizeof(hdr));
- if (rc) {
- goto func_end;
+ rc = BOOT_HOOK_CALL(boot_read_image_header_hook, BOOT_HOOK_REGULAR,
+ image_index, slot, &hdr);
+ if (rc == BOOT_HOOK_REGULAR)
+ {
+ area_id = flash_area_id_from_multi_image_slot(image_index, slot);
+
+ rc = flash_area_open(area_id, &fap);
+ if (rc) {
+ return rc;
+ }
+
+ rc = flash_area_read(fap, 0, &hdr, sizeof(hdr));
+
+ flash_area_close(fap);
}
- if (hdr.ih_magic == IMAGE_MAGIC) {
- snprintf(buffer, len, "ver=%d.%d.%d.%d,install_stat=%d",
- hdr.ih_ver.iv_major,
- hdr.ih_ver.iv_minor,
- hdr.ih_ver.iv_revision,
- hdr.ih_ver.iv_build_num,
- img_install_stat);
- } else {
- rc = 1;
+ if (rc == 0) {
+ if (hdr.ih_magic == IMAGE_MAGIC) {
+ snprintf(buffer, len, "ver=%d.%d.%d.%d,install_stat=%d",
+ hdr.ih_ver.iv_major,
+ hdr.ih_ver.iv_minor,
+ hdr.ih_ver.iv_revision,
+ hdr.ih_ver.iv_build_num,
+ img_install_stat);
+ } else {
+ rc = 1;
+ }
}
-func_end:
- flash_area_close(fap);
return rc;
}