Commit 557f84be authored by Artur Hadasz's avatar Artur Hadasz Committed by Jamie
Browse files

bootutil: Move primary/secondary slot definition to bootutil_public



The slots definitions (BOOT_PRIMARY_SLOT, BOOT_SECONDARY_SLOT)
were defined in bootutil_priv.h, which made them unusable for
bootloader requests. This commit moves them to bootutil_public.h

Signed-off-by: default avatarArtur Hadasz <artur.hadasz@nordicsemi.no>
parent 82bd4a76
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -331,7 +331,7 @@ bs_list(struct boot_loader_state *state, char *buf, int len)
            }

#ifdef MCUBOOT_SWAP_USING_OFFSET
            if (slot == BOOT_SECONDARY_SLOT && swap_status != BOOT_SWAP_TYPE_REVERT) {
            if (slot == BOOT_SLOT_SECONDARY && swap_status != BOOT_SWAP_TYPE_REVERT) {
                start_off = boot_img_sector_size(state, slot, 0);
                state->secondary_offset[image_index] = start_off;
            }
@@ -401,25 +401,25 @@ bs_list(struct boot_loader_state *state, char *buf, int len)

#ifdef MCUBOOT_SERIAL_IMG_GRP_IMAGE_STATE
            if (swap_status == BOOT_SWAP_TYPE_NONE) {
                if (slot == BOOT_PRIMARY_SLOT) {
                if (slot == BOOT_SLOT_PRIMARY) {
                    confirmed = true;
                    active = true;
                }
            } else if (swap_status == BOOT_SWAP_TYPE_TEST) {
                if (slot == BOOT_PRIMARY_SLOT) {
                if (slot == BOOT_SLOT_PRIMARY) {
                    confirmed = true;
                } else {
                    pending = true;
                }
            } else if (swap_status == BOOT_SWAP_TYPE_PERM) {
                if (slot == BOOT_PRIMARY_SLOT) {
                if (slot == BOOT_SLOT_PRIMARY) {
                    confirmed = true;
                } else {
                    pending = true;
                    permanent = true;
                }
            } else if (swap_status == BOOT_SWAP_TYPE_REVERT) {
                if (slot == BOOT_PRIMARY_SLOT) {
                if (slot == BOOT_SLOT_PRIMARY) {
                    active = true;
                } else {
                    confirmed = true;
@@ -551,7 +551,7 @@ bs_set(struct boot_loader_state *state, char *buf, int len)
                }

#ifdef MCUBOOT_SWAP_USING_OFFSET
                if (slot == BOOT_SECONDARY_SLOT && swap_status != BOOT_SWAP_TYPE_REVERT) {
                if (slot == BOOT_SLOT_SECONDARY && swap_status != BOOT_SWAP_TYPE_REVERT) {
                    start_off = boot_img_sector_size(state, slot, 0);
                    state->secondary_offset[image_index] = start_off;
                }
+8 −0
Original line number Diff line number Diff line
@@ -129,6 +129,14 @@ _Static_assert(MCUBOOT_BOOT_MAX_ALIGN >= 8 && MCUBOOT_BOOT_MAX_ALIGN <= 32,
                                                    (swap_info) = (image) << 4 \
                                                                | (type);      \
                                                    }

enum boot_slot {
    BOOT_SLOT_PRIMARY = 0,      /* Primary slot */
    BOOT_SLOT_SECONDARY = 1,    /* Secondary slot */
    BOOT_SLOT_COUNT = 2,        /* Number of slots */
    BOOT_SLOT_NONE = UINT32_MAX /* special value representing no active slot */
};

#ifdef MCUBOOT_HAVE_ASSERT_H
#include "mcuboot_config/mcuboot_assert.h"
#else
+12 −12
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ int boot_header_scramble_off_sz(const struct flash_area *fa, int slot, size_t *o
    /* In case of swap offset, header of secondary slot image is positioned
     * in second sector of slot.
     */
    if (slot == BOOT_SECONDARY_SLOT) {
    if (slot == BOOT_SLOT_SECONDARY) {
        ret = flash_area_get_sector(fa, 0, &sector);
        if (ret < 0) {
            return ret;
@@ -316,7 +316,7 @@ boot_find_status(const struct boot_loader_state *state, int image_index)
#if MCUBOOT_SWAP_USING_SCRATCH
        state->scratch.area,
#endif
        state->imgs[image_index][BOOT_PRIMARY_SLOT].area,
        state->imgs[image_index][BOOT_SLOT_PRIMARY].area,
    };
    unsigned int i;

@@ -470,7 +470,7 @@ boot_read_image_size(struct boot_loader_state *state, int slot, uint32_t *size)
    uint32_t protect_tlv_size;
    int rc;

    assert(slot == BOOT_PRIMARY_SLOT || slot == BOOT_SECONDARY_SLOT);
    assert(slot == BOOT_SLOT_PRIMARY || slot == BOOT_SLOT_SECONDARY);

    fap = BOOT_IMG_AREA(state, slot);
    assert(fap != NULL);
@@ -636,12 +636,12 @@ boot_initialize_area(struct boot_loader_state *state, int flash_area)
    num_sectors = BOOT_MAX_IMG_SECTORS;

    if (flash_area == FLASH_AREA_IMAGE_PRIMARY(BOOT_CURR_IMG(state))) {
        out_sectors = BOOT_IMG(state, BOOT_PRIMARY_SLOT).sectors;
        out_num_sectors = &BOOT_IMG(state, BOOT_PRIMARY_SLOT).num_sectors;
        out_sectors = BOOT_IMG(state, BOOT_SLOT_PRIMARY).sectors;
        out_num_sectors = &BOOT_IMG(state, BOOT_SLOT_PRIMARY).num_sectors;
#if BOOT_NUM_SLOTS > 1
    } else if (flash_area == FLASH_AREA_IMAGE_SECONDARY(BOOT_CURR_IMG(state))) {
        out_sectors = BOOT_IMG(state, BOOT_SECONDARY_SLOT).sectors;
        out_num_sectors = &BOOT_IMG(state, BOOT_SECONDARY_SLOT).num_sectors;
        out_sectors = BOOT_IMG(state, BOOT_SLOT_SECONDARY).sectors;
        out_num_sectors = &BOOT_IMG(state, BOOT_SLOT_SECONDARY).num_sectors;
#if MCUBOOT_SWAP_USING_SCRATCH
    } else if (flash_area == FLASH_AREA_IMAGE_SCRATCH) {
        out_sectors = state->scratch.sectors;
@@ -677,7 +677,7 @@ boot_write_sz(struct boot_loader_state *state)
     * on what the minimum write size is for scratch area, active image slot.
     * We need to use the bigger of those 2 values.
     */
    elem_sz = flash_area_align(BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT));
    elem_sz = flash_area_align(BOOT_IMG_AREA(state, BOOT_SLOT_PRIMARY));
#if MCUBOOT_SWAP_USING_SCRATCH
    align = flash_area_align(BOOT_SCRATCH_AREA(state));
    if (align > elem_sz) {
@@ -700,10 +700,10 @@ boot_read_sectors(struct boot_loader_state *state, struct boot_sector_buffer *se

    image_index = BOOT_CURR_IMG(state);

    BOOT_IMG(state, BOOT_PRIMARY_SLOT).sectors =
    BOOT_IMG(state, BOOT_SLOT_PRIMARY).sectors =
        sectors->primary[image_index];
#if BOOT_NUM_SLOTS > 1
    BOOT_IMG(state, BOOT_SECONDARY_SLOT).sectors =
    BOOT_IMG(state, BOOT_SLOT_SECONDARY).sectors =
        sectors->secondary[image_index];
#if MCUBOOT_SWAP_USING_SCRATCH
    state->scratch.sectors = sectors->scratch;
@@ -780,10 +780,10 @@ void boot_fetch_slot_state_sizes(void)

        image_index = BOOT_CURR_IMG(boot_get_loader_state());

        BOOT_IMG(boot_get_loader_state(), BOOT_PRIMARY_SLOT).sectors =
        BOOT_IMG(boot_get_loader_state(), BOOT_SLOT_PRIMARY).sectors =
            sector_buffers.primary[image_index];
#if BOOT_NUM_SLOTS > 1
        BOOT_IMG(boot_get_loader_state(), BOOT_SECONDARY_SLOT).sectors =
        BOOT_IMG(boot_get_loader_state(), BOOT_SLOT_SECONDARY).sectors =
            sector_buffers.secondary[image_index];
#if MCUBOOT_SWAP_USING_SCRATCH
        boot_get_loader_state()->scratch.sectors = sector_buffers.scratch;
+1 −6
Original line number Diff line number Diff line
@@ -51,8 +51,6 @@ struct flash_area;

#define BOOT_TMPBUF_SZ  256

#define NO_ACTIVE_SLOT UINT32_MAX

/** Number of image slots in flash; currently limited to two. */
#if defined(MCUBOOT_SINGLE_APPLICATION_SLOT) || defined(MCUBOOT_SINGLE_APPLICATION_SLOT_RAM_LOAD)
#define BOOT_NUM_SLOTS                  1
@@ -202,7 +200,7 @@ _Static_assert(sizeof(boot_img_magic) == BOOT_MAGIC_SZ, "Invalid size for image

#define BOOT_LOG_IMAGE_INFO(slot, hdr)                                    \
    BOOT_LOG_INF("%-9s slot: version=%u.%u.%u+%u",                        \
                 ((slot) == BOOT_PRIMARY_SLOT) ? "Primary" : "Secondary", \
                 ((slot) == BOOT_SLOT_PRIMARY) ? "Primary" : "Secondary", \
                 (hdr)->ih_ver.iv_major,                                  \
                 (hdr)->ih_ver.iv_minor,                                  \
                 (hdr)->ih_ver.iv_revision,                               \
@@ -222,9 +220,6 @@ _Static_assert(sizeof(boot_img_magic) == BOOT_MAGIC_SZ, "Invalid size for image
/** Maximum number of image sectors supported by the bootloader. */
#define BOOT_STATUS_MAX_ENTRIES         BOOT_MAX_IMG_SECTORS

#define BOOT_PRIMARY_SLOT               0
#define BOOT_SECONDARY_SLOT             1

#define BOOT_STATUS_SOURCE_NONE         0
#define BOOT_STATUS_SOURCE_SCRATCH      1
#define BOOT_STATUS_SOURCE_PRIMARY_SLOT 2
+98 −98

File changed.

Preview size limit exceeded, changes collapsed.

Loading