Skip to content

Commit 8d9e912

Browse files
committed
Addressed another round of copilot comments
1 parent 90670fc commit 8d9e912

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

src/libwolfboot.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,8 +1401,7 @@ int wolfBoot_dualboot_candidate(void)
14011401

14021402
if (fallback_v < candidate_v) {
14031403
wolfBoot_printf("Rollback to lower version not allowed\n");
1404-
wolfBoot_erase_partition(candidate);
1405-
return -1;
1404+
return candidate;
14061405
}
14071406
#endif
14081407
wolfBoot_erase_partition(candidate);

src/update_disk.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ void RAMFUNCTION wolfBoot_start(void)
253253
#endif
254254
struct wolfBoot_image os_image;
255255
int pA_ver = 0, pB_ver = 0;
256+
uint32_t pA_ver_u = 0U, pB_ver_u = 0U;
256257
uint32_t cur_part = 0;
257258
int ret = -1;
258259
int selected;
@@ -346,11 +347,16 @@ void RAMFUNCTION wolfBoot_start(void)
346347
wolfBoot_panic();
347348
}
348349

349-
wolfBoot_printf("Versions, A:%u B:%u\r\n", pA_ver, pB_ver);
350-
max_ver = (pB_ver > pA_ver) ? (uint32_t)pB_ver : (uint32_t)pA_ver;
350+
if (pA_ver > 0)
351+
pA_ver_u = (uint32_t)pA_ver;
352+
if (pB_ver > 0)
353+
pB_ver_u = (uint32_t)pB_ver;
354+
355+
wolfBoot_printf("Versions, A:%u B:%u\r\n", pA_ver_u, pB_ver_u);
356+
max_ver = (pB_ver_u > pA_ver_u) ? pB_ver_u : pA_ver_u;
351357

352358
/* Choose partition with higher version */
353-
selected = (pB_ver > pA_ver) ? 1: 0;
359+
selected = (pB_ver_u > pA_ver_u) ? 1 : 0;
354360

355361
#ifdef WOLFBOOT_FSP
356362
stage2_params = stage2_get_parameters();
@@ -372,7 +378,7 @@ void RAMFUNCTION wolfBoot_start(void)
372378
cur_part = BOOT_PART_A;
373379
#ifndef ALLOW_DOWNGRADE
374380
{
375-
uint32_t cur_ver = selected ? (uint32_t)pB_ver : (uint32_t)pA_ver;
381+
uint32_t cur_ver = selected ? pB_ver_u : pA_ver_u;
376382
if ((max_ver > 0U) && (cur_ver < max_ver)) {
377383
wolfBoot_printf("Rollback to lower version not allowed\r\n");
378384
wolfBoot_panic();

src/update_ram.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void RAMFUNCTION wolfBoot_start(void)
143143
int update_v_raw = (int)wolfBoot_update_firmware_version();
144144
uint32_t boot_v = 0U;
145145
uint32_t update_v = 0U;
146-
uint32_t max_v = (boot_v > update_v) ? boot_v : update_v;
146+
uint32_t max_v = 0U;
147147

148148
if (boot_v_raw >= 0)
149149
boot_v = (uint32_t)boot_v_raw;

tools/unit-tests/unit-update-ram-nofixed.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static __thread unsigned char
2727
#define WOLFBOOT_LOAD_ADDRESS (((uintptr_t)wolfboot_ram) + IMAGE_HEADER_SIZE)
2828
#define TEST_SIZE_SMALL 5300
2929
#define DIGEST_TLV_OFF_IN_HDR 28
30-
#define STAGE_ADDR_SENTINEL ((uintptr_t)0xFFFFFFFFu)
30+
#define STAGE_ADDR_SENTINEL UINTPTR_MAX
3131

3232
#include "user_settings.h"
3333
#include "wolfboot/wolfboot.h"
@@ -53,7 +53,8 @@ int wolfBoot_dualboot_candidate_addr(void** addr)
5353
#include <wolfssl/wolfcrypt/sha256.h>
5454

5555
int wolfBoot_staged_ok = 0;
56-
const uint32_t *wolfBoot_stage_address = (uint32_t *)0xFFFFFFFF;
56+
const uint32_t *wolfBoot_stage_address =
57+
(const uint32_t *)(uintptr_t)STAGE_ADDR_SENTINEL;
5758

5859
void* hal_get_primary_address(void)
5960
{

tools/unit-tests/unit-update-ram.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,9 @@ START_TEST (test_emergency_rollback_to_older_version_denied) {
433433
ext_flash_lock();
434434

435435
wolfBoot_start();
436-
ck_assert(!wolfBoot_staged_ok);
437-
ck_assert_int_eq(wolfBoot_panicked, 1);
436+
ck_assert(wolfBoot_staged_ok);
437+
ck_assert_int_eq(get_version_ramloaded(), 2);
438+
ck_assert_int_eq(wolfBoot_panicked, 0);
438439
cleanup_flash();
439440
}
440441

@@ -453,8 +454,8 @@ START_TEST (test_dualboot_candidate_rejects_testing_rollback_to_lower_version) {
453454
ext_flash_lock();
454455

455456
candidate = wolfBoot_dualboot_candidate();
456-
ck_assert_int_eq(candidate, -1);
457-
ck_assert_uint_eq(wolfBoot_current_firmware_version(), 0U);
457+
ck_assert_int_eq(candidate, PART_BOOT);
458+
ck_assert_uint_eq(wolfBoot_current_firmware_version(), 2U);
458459
cleanup_flash();
459460
}
460461

0 commit comments

Comments
 (0)