Skip to content

Commit 0776cbf

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 0776cbf

File tree

5 files changed

+37
-34
lines changed

5 files changed

+37
-34
lines changed

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_priv.h

Lines changed: 1 addition & 6 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
@@ -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 */

boot/bootutil/src/loader.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ boot_add_shared_data(struct boot_loader_state *state,
194194
static void
195195
fill_rsp(struct boot_loader_state *state, struct boot_rsp *rsp)
196196
{
197-
uint32_t active_slot;
197+
enum boot_slot active_slot;
198198

199199
#if (BOOT_IMAGE_NUMBER > 1)
200200
/* Always boot from the first enabled image. */
@@ -451,7 +451,7 @@ static int
451451
boot_verify_dependencies(struct boot_loader_state *state)
452452
{
453453
int rc = -1;
454-
uint32_t active_slot;
454+
enum boot_slot active_slot;
455455

456456
IMAGES_ITER(BOOT_CURR_IMG(state)) {
457457
if (state->img_mask[BOOT_CURR_IMG(state)]) {
@@ -467,7 +467,7 @@ boot_verify_dependencies(struct boot_loader_state *state)
467467
#endif /* MCUBOOT_RAM_LOAD */
468468

469469
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
470-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
470+
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
471471

472472
return rc;
473473
}
@@ -849,7 +849,7 @@ boot_check_header_erased(struct boot_loader_state *state, int slot)
849849
static bool
850850
boot_rom_address_check(struct boot_loader_state *state)
851851
{
852-
uint32_t active_slot;
852+
enum boot_slot active_slot;
853853
const struct image_header *hdr;
854854
uint32_t f_off;
855855

@@ -2584,7 +2584,7 @@ boot_get_slot_usage(struct boot_loader_state *state)
25842584
}
25852585
}
25862586

2587-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
2587+
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
25882588
}
25892589

25902590
return 0;
@@ -2596,19 +2596,19 @@ boot_get_slot_usage(struct boot_loader_state *state)
25962596
*
25972597
* @param state Boot loader status information.
25982598
*
2599-
* @return NO_ACTIVE_SLOT if no available slot found, number of
2599+
* @return BOOT_SLOT_NONE if no available slot found, number of
26002600
* the found slot otherwise.
26012601
*/
26022602
static uint32_t
26032603
find_slot_with_highest_version(struct boot_loader_state *state)
26042604
{
26052605
uint32_t slot;
2606-
uint32_t candidate_slot = NO_ACTIVE_SLOT;
2606+
uint32_t candidate_slot = BOOT_SLOT_NONE;
26072607
int rc;
26082608

26092609
for (slot = 0; slot < BOOT_NUM_SLOTS; slot++) {
26102610
if (state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot]) {
2611-
if (candidate_slot == NO_ACTIVE_SLOT) {
2611+
if (candidate_slot == BOOT_SLOT_NONE) {
26122612
candidate_slot = slot;
26132613
} else {
26142614
rc = boot_version_cmp(
@@ -2636,7 +2636,7 @@ find_slot_with_highest_version(struct boot_loader_state *state)
26362636
static void
26372637
print_loaded_images(struct boot_loader_state *state)
26382638
{
2639-
uint32_t active_slot;
2639+
enum boot_slot active_slot;
26402640

26412641
(void)state;
26422642

@@ -2672,7 +2672,7 @@ boot_select_or_erase(struct boot_loader_state *state)
26722672
{
26732673
const struct flash_area *fap = NULL;
26742674
int rc;
2675-
uint32_t active_slot;
2675+
enum boot_slot active_slot;
26762676
struct boot_swap_state* active_swap_state;
26772677

26782678
active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
@@ -2736,7 +2736,7 @@ boot_select_or_erase(struct boot_loader_state *state)
27362736
fih_ret
27372737
boot_load_and_validate_images(struct boot_loader_state *state)
27382738
{
2739-
uint32_t active_slot;
2739+
enum boot_slot active_slot;
27402740
int rc;
27412741
fih_ret fih_rc;
27422742
uint32_t slot;
@@ -2758,7 +2758,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
27582758
if (rc != 0) {
27592759
/* The image is placed in an unsuitable slot. */
27602760
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
2761-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
2761+
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
27622762
continue;
27632763
}
27642764

@@ -2767,7 +2767,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
27672767
if (rc != 0) {
27682768
/* The selected image slot has been erased. */
27692769
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
2770-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
2770+
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
27712771
continue;
27722772
}
27732773
#endif /* MCUBOOT_DIRECT_XIP_REVERT */
@@ -2784,7 +2784,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
27842784
/* Image cannot be ramloaded. */
27852785
boot_remove_image_from_flash(state, slot);
27862786
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
2787-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
2787+
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
27882788
continue;
27892789
}
27902790
#endif /* MCUBOOT_RAM_LOAD */
@@ -2796,12 +2796,12 @@ boot_load_and_validate_images(struct boot_loader_state *state)
27962796
boot_remove_image_from_sram(state);
27972797
#endif /* MCUBOOT_RAM_LOAD */
27982798
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
2799-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
2799+
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
28002800
continue;
28012801
}
28022802

28032803
/* Valid image loaded from a slot, go to the next slot. */
2804-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
2804+
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
28052805
}
28062806
}
28072807

@@ -2813,7 +2813,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
28132813
while (true) {
28142814
/* Go over all the slots and try to load one */
28152815
active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
2816-
if (active_slot != NO_ACTIVE_SLOT){
2816+
if (active_slot != BOOT_SLOT_NONE){
28172817
/* A slot is already active, go to next image. */
28182818
break;
28192819
}
@@ -2824,7 +2824,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
28242824
active_slot = find_slot_with_highest_version(state);
28252825
}
28262826

2827-
if (active_slot == NO_ACTIVE_SLOT) {
2827+
if (active_slot == BOOT_SLOT_NONE) {
28282828
BOOT_LOG_INF("No slot to load for image %d",
28292829
BOOT_CURR_IMG(state));
28302830
FIH_RET(FIH_FAILURE);
@@ -2853,7 +2853,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
28532853
fih_ret
28542854
boot_load_and_validate_images(struct boot_loader_state *state)
28552855
{
2856-
uint32_t active_slot;
2856+
enum boot_slot active_slot;
28572857
int rc;
28582858
fih_ret fih_rc;
28592859

@@ -2865,7 +2865,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
28652865
while (true) {
28662866
/* Go over all the slots and try to load one */
28672867
active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
2868-
if (active_slot != NO_ACTIVE_SLOT){
2868+
if (active_slot != BOOT_SLOT_NONE){
28692869
/* A slot is already active, go to next image. */
28702870
break;
28712871
}
@@ -2876,7 +2876,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
28762876
active_slot = find_slot_with_highest_version(state);
28772877
}
28782878

2879-
if (active_slot == NO_ACTIVE_SLOT) {
2879+
if (active_slot == BOOT_SLOT_NONE) {
28802880
BOOT_LOG_INF("No slot to load for image %d",
28812881
BOOT_CURR_IMG(state));
28822882
FIH_RET(FIH_FAILURE);
@@ -2896,7 +2896,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
28962896
if (rc != 0) {
28972897
/* The image is placed in an unsuitable slot. */
28982898
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
2899-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
2899+
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
29002900
continue;
29012901
}
29022902
#endif /* MCUBOOT_DIRECT_XIP */
@@ -2906,7 +2906,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
29062906
if (rc != 0) {
29072907
/* The selected image slot has been erased. */
29082908
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
2909-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
2909+
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
29102910
continue;
29112911
}
29122912
#endif /* MCUBOOT_DIRECT_XIP_REVERT || MCUBOOT_RAM_LOAD_REVERT */
@@ -2922,7 +2922,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
29222922
/* Image cannot be ramloaded. */
29232923
boot_remove_image_from_flash(state, active_slot);
29242924
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
2925-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
2925+
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
29262926
continue;
29272927
}
29282928
#endif /* MCUBOOT_RAM_LOAD */
@@ -2934,7 +2934,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
29342934
boot_remove_image_from_sram(state);
29352935
#endif /* MCUBOOT_RAM_LOAD */
29362936
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
2937-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
2937+
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
29382938
continue;
29392939
}
29402940

boot/bootutil/src/ram_load.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ boot_check_ram_load_overlapping(struct boot_loader_state *state)
274274
end_a = start_a + state->slot_usage[image_id_to_check].img_sz;
275275

276276
for (i = 0; i < BOOT_IMAGE_NUMBER; i++) {
277-
if (state->slot_usage[i].active_slot == NO_ACTIVE_SLOT
277+
if (state->slot_usage[i].active_slot == BOOT_SLOT_NONE
278278
|| i == image_id_to_check) {
279279
continue;
280280
}
@@ -304,7 +304,7 @@ boot_check_ram_load_overlapping(struct boot_loader_state *state)
304304
int
305305
boot_load_image_to_sram(struct boot_loader_state *state)
306306
{
307-
uint32_t active_slot;
307+
enum boot_slot active_slot;
308308
struct image_header *hdr = NULL;
309309
uint32_t img_dst;
310310
uint32_t img_sz;

boot/zephyr/hooks_sample.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int boot_img_install_stat_hook(int image_index, int slot, int *img_install_stat)
9494
return BOOT_HOOK_REGULAR;
9595
}
9696

97-
int boot_find_next_slot_hook(struct boot_loader_state *state, uint8_t image, uint32_t *active_slot)
97+
int boot_find_next_slot_hook(struct boot_loader_state *state, uint8_t image, enum boot_slot *active_slot)
9898
{
9999
return BOOT_HOOK_REGULAR;
100100
}

0 commit comments

Comments
 (0)