Commit 2a29f5dc authored by Andrzej Puzdrowski's avatar Andrzej Puzdrowski Committed by David Brown
Browse files

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: default avatarAndrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
parent 4f9c7304
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -137,4 +137,24 @@ int boot_copy_region_post_hook(int img_index, const struct flash_area *area,
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*/
+33 −20
Original line number Diff line number Diff line
@@ -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,8 +62,19 @@ static int custom_img_status(int image_index, uint32_t slot,char *buffer,
    struct flash_area const *fap;
    struct image_header hdr;
    int rc;
    int img_install_stat = 0;
    int img_install_stat;

    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 = 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);
@@ -70,10 +83,11 @@ static int custom_img_status(int image_index, uint32_t slot,char *buffer,
        }

        rc = flash_area_read(fap, 0, &hdr, sizeof(hdr));
    if (rc) {
        goto func_end;

        flash_area_close(fap);
    }

    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,
@@ -84,9 +98,8 @@ static int custom_img_status(int image_index, uint32_t slot,char *buffer,
        } else {
            rc = 1;
        }
    }

func_end:
    flash_area_close(fap);
    return rc;
}