Skip to content

Commit 8534953

Browse files
tomchynordicjm
authored andcommitted
[nrf noup] mcuboot: Use dedicated type for slot numbers
nrf-squash! [nrf noup] bootloader: Add bootloader requests Change bootloader request module, so it uses the new, dedicated type to point to the specific slot. Ref: NCSDK-35199 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 388a9da commit 8534953

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

boot/bootutil/include/bootutil/boot_request.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extern "C" {
1313

1414
#include <stdint.h>
1515
#include <stdbool.h>
16+
#include <bootutil/bootutil_public.h>
1617

1718
/** Special value, indicating that there is no preferred slot. */
1819
#define BOOT_REQUEST_NO_PREFERRED_SLOT UINT32_MAX
@@ -25,7 +26,7 @@ extern "C" {
2526
*
2627
* @return 0 if requested, negative error code otherwise.
2728
*/
28-
int boot_request_confirm_slot(uint8_t image, uint32_t slot);
29+
int boot_request_confirm_slot(uint8_t image, enum boot_slot slot);
2930

3031
/**
3132
* @brief Request a bootloader to boot the specified slot of an image.
@@ -35,7 +36,7 @@ int boot_request_confirm_slot(uint8_t image, uint32_t slot);
3536
*
3637
* @return 0 if requested, negative error code otherwise.
3738
*/
38-
int boot_request_set_preferred_slot(uint8_t image, uint32_t slot);
39+
int boot_request_set_preferred_slot(uint8_t image, enum boot_slot slot);
3940

4041
/**
4142
* @brief Request a bootloader to boot recovery image.
@@ -59,16 +60,16 @@ int boot_request_enter_firmware_loader(void);
5960
*
6061
* @return true if requested, false otherwise.
6162
*/
62-
bool boot_request_check_confirmed_slot(uint8_t image, uint32_t slot);
63+
bool boot_request_check_confirmed_slot(uint8_t image, enum boot_slot slot);
6364

6465
/**
6566
* @brief Find if there is a request to boot certain slot of the specified image.
6667
*
6768
* @param[in] image Image number.
6869
*
69-
* @return slot number if requested, BOOT_REQUEST_NO_PREFERRED_SLOT otherwise.
70+
* @return slot number if requested, BOOT_SLOT_NONE otherwise.
7071
*/
71-
uint32_t boot_request_get_preferred_slot(uint8_t image);
72+
enum boot_slot boot_request_get_preferred_slot(uint8_t image);
7273

7374
/**
7475
* @brief Check if there is a request to boot recovery image.

boot/bootutil/src/bootutil_public.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ boot_write_copy_done(const struct flash_area *fap)
511511
#ifdef SEND_BOOT_REQUEST
512512
static int
513513
send_boot_request(uint8_t magic, uint8_t image_ok, bool confirm, int image_id,
514-
uint32_t slot_id)
514+
enum boot_slot slot_id)
515515
{
516516
int rc = BOOT_EBADIMAGE;
517517

boot/bootutil/zephyr/src/boot_request_retention.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ int boot_request_clear(void)
155155
return retention_clear(bootloader_request_dev);
156156
}
157157

158-
int boot_request_confirm_slot(uint8_t image, uint32_t slot)
158+
int boot_request_confirm_slot(uint8_t image, enum boot_slot slot)
159159
{
160160
uint8_t value = BOOT_REQUEST_SLOT_INVALID;
161161
size_t req_entry;
@@ -167,10 +167,10 @@ int boot_request_confirm_slot(uint8_t image, uint32_t slot)
167167
}
168168

169169
switch (slot) {
170-
case 0:
170+
case BOOT_SLOT_PRIMARY:
171171
value = BOOT_REQUEST_SLOT_PRIMARY;
172172
break;
173-
case 1:
173+
case BOOT_SLOT_SECONDARY:
174174
value = BOOT_REQUEST_SLOT_SECONDARY;
175175
break;
176176
default:
@@ -181,7 +181,7 @@ int boot_request_confirm_slot(uint8_t image, uint32_t slot)
181181
sizeof(value));
182182
}
183183

184-
bool boot_request_check_confirmed_slot(uint8_t image, uint32_t slot)
184+
bool boot_request_check_confirmed_slot(uint8_t image, enum boot_slot slot)
185185
{
186186
uint8_t value = BOOT_REQUEST_SLOT_INVALID;
187187
size_t req_entry;
@@ -200,17 +200,17 @@ bool boot_request_check_confirmed_slot(uint8_t image, uint32_t slot)
200200

201201
switch (value) {
202202
case BOOT_REQUEST_SLOT_PRIMARY:
203-
return (slot == 0);
203+
return (slot == BOOT_SLOT_PRIMARY);
204204
case BOOT_REQUEST_SLOT_SECONDARY:
205-
return (slot == 1);
205+
return (slot == BOOT_SLOT_SECONDARY);
206206
default:
207207
break;
208208
}
209209

210210
return false;
211211
}
212212

213-
int boot_request_set_preferred_slot(uint8_t image, uint32_t slot)
213+
int boot_request_set_preferred_slot(uint8_t image, enum boot_slot slot)
214214
{
215215
uint8_t value = BOOT_REQUEST_SLOT_INVALID;
216216
size_t req_entry;
@@ -222,10 +222,10 @@ int boot_request_set_preferred_slot(uint8_t image, uint32_t slot)
222222
}
223223

224224
switch (slot) {
225-
case 0:
225+
case BOOT_SLOT_PRIMARY:
226226
value = BOOT_REQUEST_SLOT_PRIMARY;
227227
break;
228-
case 1:
228+
case BOOT_SLOT_SECONDARY:
229229
value = BOOT_REQUEST_SLOT_SECONDARY;
230230
break;
231231
default:
@@ -237,33 +237,33 @@ int boot_request_set_preferred_slot(uint8_t image, uint32_t slot)
237237
}
238238

239239
#ifdef CONFIG_FIND_NEXT_SLOT_HOOKS
240-
uint32_t boot_request_get_preferred_slot(uint8_t image)
240+
enum boot_slot boot_request_get_preferred_slot(uint8_t image)
241241
{
242242
uint8_t value = BOOT_REQUEST_SLOT_INVALID;
243243
size_t req_entry;
244244
int ret;
245245

246246
ret = boot_request_entry_find(BOOT_REQUEST_IMG_PREFERENCE, image, &req_entry);
247247
if (ret != 0) {
248-
return BOOT_REQUEST_NO_PREFERRED_SLOT;
248+
return BOOT_SLOT_NONE;
249249
}
250250

251251
ret = retention_read(bootloader_request_dev, req_entry * sizeof(value), (void *)&value,
252252
sizeof(value));
253253
if (ret != 0) {
254-
return BOOT_REQUEST_NO_PREFERRED_SLOT;
254+
return BOOT_SLOT_NONE;
255255
}
256256

257257
switch (value) {
258258
case BOOT_REQUEST_SLOT_PRIMARY:
259-
return 0;
259+
return BOOT_SLOT_PRIMARY;
260260
case BOOT_REQUEST_SLOT_SECONDARY:
261-
return 1;
261+
return BOOT_SLOT_SECONDARY;
262262
default:
263263
break;
264264
}
265265

266-
return BOOT_REQUEST_NO_PREFERRED_SLOT;
266+
return BOOT_SLOT_NONE;
267267
}
268268
#endif /* CONFIG_FIND_NEXT_SLOT_HOOKS */
269269

boot/zephyr/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ static int boot_prevalidate(void)
616616
{
617617
#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
618618
uint8_t image_index;
619-
uint32_t slot;
619+
enum boot_slot slot;
620620
uint32_t area_id;
621621
const struct flash_area *fap;
622622
int rc = boot_request_init();
@@ -626,7 +626,7 @@ static int boot_prevalidate(void)
626626
}
627627

628628
for (image_index = 0; image_index < BOOT_IMAGE_NUMBER; ++image_index) {
629-
for (slot = 0; slot < BOOT_REQUEST_NUM_SLOTS; slot++) {
629+
for (slot = BOOT_SLOT_PRIMARY; slot < BOOT_SLOT_COUNT; slot++) {
630630
if (boot_request_check_confirmed_slot(image_index, slot)) {
631631
BOOT_LOG_DBG("Confirm image: %d slot: %d due to bootloader request.",
632632
image_index, slot);

0 commit comments

Comments
 (0)