Skip to content

bootutil: Move primary/secondary slot definition to bootutil_public - enum #2431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions boot/boot_serial/src/boot_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions boot/bootutil/include/bootutil/bootutil_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions boot/bootutil/src/bootutil_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions boot/bootutil/src/bootutil_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, \
Expand All @@ -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
Expand Down Expand Up @@ -279,7 +274,7 @@ struct boot_loader_state {
#if defined(MCUBOOT_DIRECT_XIP) || defined(MCUBOOT_RAM_LOAD)
struct slot_usage_t {
/* Index of the slot chosen to be loaded */
uint32_t active_slot;
enum boot_slot active_slot;
bool slot_available[BOOT_NUM_SLOTS];
#if defined(MCUBOOT_RAM_LOAD)
/* Image destination and size for the active slot */
Expand Down
Loading
Loading