Skip to content

Commit 0d6ba96

Browse files
committed
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: Artur Hadasz <artur.hadasz@nordicsemi.no>
1 parent fe8f9fc commit 0d6ba96

File tree

17 files changed

+255
-252
lines changed

17 files changed

+255
-252
lines changed

boot/boot_serial/src/boot_serial.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ bs_list(struct boot_loader_state *state, char *buf, int len)
331331
}
332332

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

402402
#ifdef MCUBOOT_SERIAL_IMG_GRP_IMAGE_STATE
403403
if (swap_status == BOOT_SWAP_TYPE_NONE) {
404-
if (slot == BOOT_PRIMARY_SLOT) {
404+
if (slot == BOOT_SLOT_PRIMARY) {
405405
confirmed = true;
406406
active = true;
407407
}
408408
} else if (swap_status == BOOT_SWAP_TYPE_TEST) {
409-
if (slot == BOOT_PRIMARY_SLOT) {
409+
if (slot == BOOT_SLOT_PRIMARY) {
410410
confirmed = true;
411411
} else {
412412
pending = true;
413413
}
414414
} else if (swap_status == BOOT_SWAP_TYPE_PERM) {
415-
if (slot == BOOT_PRIMARY_SLOT) {
415+
if (slot == BOOT_SLOT_PRIMARY) {
416416
confirmed = true;
417417
} else {
418418
pending = true;
419419
permanent = true;
420420
}
421421
} else if (swap_status == BOOT_SWAP_TYPE_REVERT) {
422-
if (slot == BOOT_PRIMARY_SLOT) {
422+
if (slot == BOOT_SLOT_PRIMARY) {
423423
active = true;
424424
} else {
425425
confirmed = true;
@@ -551,7 +551,7 @@ bs_set(struct boot_loader_state *state, char *buf, int len)
551551
}
552552

553553
#ifdef MCUBOOT_SWAP_USING_OFFSET
554-
if (slot == BOOT_SECONDARY_SLOT && swap_status != BOOT_SWAP_TYPE_REVERT) {
554+
if (slot == BOOT_SLOT_SECONDARY && swap_status != BOOT_SWAP_TYPE_REVERT) {
555555
start_off = boot_img_sector_size(state, slot, 0);
556556
state->secondary_offset[image_index] = start_off;
557557
}

boot/bootutil/include/bootutil/bootutil_public.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ _Static_assert(MCUBOOT_BOOT_MAX_ALIGN >= 8 && MCUBOOT_BOOT_MAX_ALIGN <= 32,
129129
(swap_info) = (image) << 4 \
130130
| (type); \
131131
}
132+
133+
enum boot_slot {
134+
BOOT_SLOT_PRIMARY = 0, /* Primary slot */
135+
BOOT_SLOT_SECONDARY = 1, /* Secondary slot */
136+
BOOT_SLOT_COUNT = 2, /* Number of slots */
137+
BOOT_SLOT_NONE = UINT32_MAX /* special value representing no active slot */
138+
};
139+
132140
#ifdef MCUBOOT_HAVE_ASSERT_H
133141
#include "mcuboot_config/mcuboot_assert.h"
134142
#else

boot/bootutil/src/bootutil_misc.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ int boot_header_scramble_off_sz(const struct flash_area *fa, int slot, size_t *o
209209
/* In case of swap offset, header of secondary slot image is positioned
210210
* in second sector of slot.
211211
*/
212-
if (slot == BOOT_SECONDARY_SLOT) {
212+
if (slot == BOOT_SLOT_SECONDARY) {
213213
ret = flash_area_get_sector(fa, 0, &sector);
214214
if (ret < 0) {
215215
return ret;
@@ -316,7 +316,7 @@ boot_find_status(const struct boot_loader_state *state, int image_index)
316316
#if MCUBOOT_SWAP_USING_SCRATCH
317317
state->scratch.area,
318318
#endif
319-
state->imgs[image_index][BOOT_PRIMARY_SLOT].area,
319+
state->imgs[image_index][BOOT_SLOT_PRIMARY].area,
320320
};
321321
unsigned int i;
322322

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

473-
assert(slot == BOOT_PRIMARY_SLOT || slot == BOOT_SECONDARY_SLOT);
473+
assert(slot == BOOT_SLOT_PRIMARY || slot == BOOT_SLOT_SECONDARY);
474474

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

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

701701
image_index = BOOT_CURR_IMG(state);
702702

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

781781
image_index = BOOT_CURR_IMG(boot_get_loader_state());
782782

783-
BOOT_IMG(boot_get_loader_state(), BOOT_PRIMARY_SLOT).sectors =
783+
BOOT_IMG(boot_get_loader_state(), BOOT_SLOT_PRIMARY).sectors =
784784
sector_buffers.primary[image_index];
785785
#if BOOT_NUM_SLOTS > 1
786-
BOOT_IMG(boot_get_loader_state(), BOOT_SECONDARY_SLOT).sectors =
786+
BOOT_IMG(boot_get_loader_state(), BOOT_SLOT_SECONDARY).sectors =
787787
sector_buffers.secondary[image_index];
788788
#if MCUBOOT_SWAP_USING_SCRATCH
789789
boot_get_loader_state()->scratch.sectors = sector_buffers.scratch;

boot/bootutil/src/bootutil_priv.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ struct flash_area;
5151

5252
#define BOOT_TMPBUF_SZ 256
5353

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

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

225-
#define BOOT_PRIMARY_SLOT 0
226-
#define BOOT_SECONDARY_SLOT 1
227-
228223
#define BOOT_STATUS_SOURCE_NONE 0
229224
#define BOOT_STATUS_SOURCE_SCRATCH 1
230225
#define BOOT_STATUS_SOURCE_PRIMARY_SLOT 2
@@ -279,7 +274,7 @@ struct boot_loader_state {
279274
#if defined(MCUBOOT_DIRECT_XIP) || defined(MCUBOOT_RAM_LOAD)
280275
struct slot_usage_t {
281276
/* Index of the slot chosen to be loaded */
282-
uint32_t active_slot;
277+
enum boot_slot active_slot;
283278
bool slot_available[BOOT_NUM_SLOTS];
284279
#if defined(MCUBOOT_RAM_LOAD)
285280
/* Image destination and size for the active slot */

0 commit comments

Comments
 (0)