Commit 4f1ab9e7 authored by Jamie McCrae's avatar Jamie McCrae Committed by Jamie
Browse files

bootutil: Add missing images to get maximum image size details

Adds support for getting the maximum image size of multiple images
and adding this data to the shared data area

Signed-off-by: default avatarJamie McCrae <jamie.mccrae@nordicsemi.no>
parent 4baa6d32
Loading
Loading
Loading
Loading
+2 −2
Changes for boot/bootutil/include/bootutil/boot_record.h: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -72,14 +72,14 @@ int boot_save_boot_status(uint8_t sw_module,
 * @param[in]  hdr           Pointer to the image header stored in RAM.
 * @param[in]  fap           Pointer to the flash area where image is stored.
 * @param[in]  slot          The currently active slot being booted.
 * @param[in]  max_app_size  The maximum size of an image that can be loaded.
 * @param[in]  max_app_sizes The maximum sizes of images that can be loaded.
 *
 * @return                    0 on success; nonzero on failure.
 */
int boot_save_shared_data(const struct image_header *hdr,
                          const struct flash_area *fap,
                          const uint8_t active_slot,
                          const int max_app_size);
                          const struct image_max_size *max_app_sizes);

#ifdef __cplusplus
}
+6 −1
Changes for boot/bootutil/include/bootutil/boot_status.h: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -113,7 +113,12 @@ extern "C" {
#define BLINFO_RECOVERY             0x02
#define BLINFO_RUNNING_SLOT         0x03
#define BLINFO_BOOTLOADER_VERSION   0x04
#define BLINFO_MAX_APPLICATION_SIZE 0x05
#define BLINFO_MAX_APPLICATION_SIZE 0x05 /* Same as BLINFO_MAX_APPLICATION_SIZE_IMAGE_0, legacy name */
#define BLINFO_MAX_APPLICATION_SIZE_IMAGE_0 BLINFO_MAX_APPLICATION_SIZE
#define BLINFO_MAX_APPLICATION_SIZE_IMAGE_1 0x06
#define BLINFO_MAX_APPLICATION_SIZE_IMAGE_2 0x07
#define BLINFO_MAX_APPLICATION_SIZE_IMAGE_3 0x08
#define BLINFO_MAX_APPLICATION_SIZE_IMAGE_4 0x09

enum mcuboot_mode {
    MCUBOOT_MODE_SINGLE_SLOT,
+6 −0
Changes for boot/bootutil/include/bootutil/bootutil.h: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -77,6 +77,11 @@ struct image_trailer {
    uint8_t magic[BOOT_MAGIC_SZ];
};

struct image_max_size {
	bool calculated;
	uint32_t max_size;
};

/* you must have pre-allocated all the entries within this structure */
fih_ret boot_go(struct boot_rsp *rsp);
fih_ret boot_go_for_image_id(struct boot_rsp *rsp, uint32_t image_id);
@@ -84,6 +89,7 @@ fih_ret boot_go_for_image_id(struct boot_rsp *rsp, uint32_t image_id);
struct boot_loader_state;
void boot_state_clear(struct boot_loader_state *state);
fih_ret context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp);
const struct image_max_size *boot_get_max_app_size(void);

#define SPLIT_GO_OK                 (0)
#define SPLIT_GO_NON_MATCHING       (-1)
+11 −5
Changes for boot/bootutil/src/boot_record.c: 11 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -230,9 +230,10 @@ boot_save_boot_status(uint8_t sw_module,

#ifdef MCUBOOT_DATA_SHARING_BOOTINFO
int boot_save_shared_data(const struct image_header *hdr, const struct flash_area *fap,
                          const uint8_t slot, const int max_app_size)
                          const uint8_t slot, const struct image_max_size *max_app_sizes)
{
    int rc;
    uint8_t image = 0;

#if defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
    uint8_t mode = MCUBOOT_MODE_SINGLE_SLOT;
@@ -325,11 +326,16 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are
    }
#endif

    if (!rc) {
    while (image < BOOT_IMAGE_NUMBER && !rc) {
        if (max_app_sizes[image].calculated == true) {
            rc = boot_add_data_to_shared_area(TLV_MAJOR_BLINFO,
                                          BLINFO_MAX_APPLICATION_SIZE,
                                          sizeof(max_app_size),
                                          (void *)&max_app_size);
                                              (BLINFO_MAX_APPLICATION_SIZE + image),
                                              sizeof(max_app_sizes[image].max_size),
                                              (void *)&max_app_sizes[image].max_size);

        }

        ++image;
    }

    return rc;
+29 −6
Changes for boot/bootutil/src/loader.c: 29 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -63,6 +63,10 @@ BOOT_LOG_MODULE_DECLARE(mcuboot);

static struct boot_loader_state boot_data;

#if defined(MCUBOOT_DATA_SHARING)
static struct image_max_size image_max_sizes[BOOT_IMAGE_NUMBER] = {0};
#endif

#if (BOOT_IMAGE_NUMBER > 1)
#define IMAGES_ITER(x) for ((x) = 0; (x) < BOOT_IMAGE_NUMBER; ++(x))
#else
@@ -137,10 +141,6 @@ boot_add_shared_data(struct boot_loader_state *state,
#if defined(MCUBOOT_MEASURED_BOOT) || defined(MCUBOOT_DATA_SHARING)
    int rc;

#ifdef MCUBOOT_DATA_SHARING
    int max_app_size;
#endif

#ifdef MCUBOOT_MEASURED_BOOT
    rc = boot_save_boot_status(BOOT_CURR_IMG(state),
                                boot_img_hdr(state, active_slot),
@@ -152,10 +152,9 @@ boot_add_shared_data(struct boot_loader_state *state,
#endif /* MCUBOOT_MEASURED_BOOT */

#ifdef MCUBOOT_DATA_SHARING
    max_app_size = app_max_size(state);
    rc = boot_save_shared_data(boot_img_hdr(state, active_slot),
                                BOOT_IMG_AREA(state, active_slot),
                                active_slot, max_app_size);
                                active_slot, image_max_sizes);
    if (rc != 0) {
        BOOT_LOG_ERR("Failed to add data to shared memory area.");
        return rc;
@@ -1841,6 +1840,10 @@ boot_prepare_image_for_update(struct boot_loader_state *state,
    int rc;
    FIH_DECLARE(fih_rc, FIH_FAILURE);

#if defined(MCUBOOT_DATA_SHARING)
    int max_size;
#endif

    /* Determine the sector layout of the image slots and scratch area. */
    rc = boot_read_sectors(state);
    if (rc != 0) {
@@ -1867,6 +1870,16 @@ boot_prepare_image_for_update(struct boot_loader_state *state,
        return;
    }

#if defined(MCUBOOT_DATA_SHARING)
    /* Fetch information on maximum sizes for later usage, if needed */
    max_size = app_max_size(state);

    if (max_size > 0) {
        image_max_sizes[BOOT_CURR_IMG(state)].calculated = true;
        image_max_sizes[BOOT_CURR_IMG(state)].max_size = max_size;
    }
#endif

    /* If the current image's slots aren't compatible, no swap is possible.
     * Just boot into primary slot.
     */
@@ -3323,3 +3336,13 @@ void boot_state_clear(struct boot_loader_state *state)
        memset(&boot_data, 0, sizeof(struct boot_loader_state));
    }
}

#if defined(MCUBOOT_DATA_SHARING)
/**
* Fetches the maximum allowed size of the image
*/
const struct image_max_size *boot_get_max_app_size(void)
{
    return image_max_sizes;
}
#endif