Skip to content

Commit 90670fc

Browse files
committed
Addressed the 3 remaining open Copilot comments.
1 parent 0a4f828 commit 90670fc

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/update_flash_hwswap.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@ void RAMFUNCTION wolfBoot_start(void)
4747
struct wolfBoot_image fw_image;
4848
uint8_t p_state;
4949
#ifndef ALLOW_DOWNGRADE
50-
uint32_t boot_v = wolfBoot_current_firmware_version();
51-
uint32_t update_v = wolfBoot_update_firmware_version();
50+
int boot_v_raw = (int)wolfBoot_current_firmware_version();
51+
int update_v_raw = (int)wolfBoot_update_firmware_version();
52+
uint32_t boot_v = 0U;
53+
uint32_t update_v = 0U;
5254
uint32_t max_v = (boot_v > update_v) ? boot_v : update_v;
55+
56+
if (boot_v_raw >= 0)
57+
boot_v = (uint32_t)boot_v_raw;
58+
if (update_v_raw >= 0)
59+
update_v = (uint32_t)update_v_raw;
60+
max_v = (boot_v > update_v) ? boot_v : update_v;
5361
#endif
5462
active = wolfBoot_dualboot_candidate();
5563

src/update_ram.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,17 @@ void RAMFUNCTION wolfBoot_start(void)
139139
uint32_t dts_size = 0;
140140
#endif
141141
#ifndef ALLOW_DOWNGRADE
142-
uint32_t boot_v = wolfBoot_current_firmware_version();
143-
uint32_t update_v = wolfBoot_update_firmware_version();
142+
int boot_v_raw = (int)wolfBoot_current_firmware_version();
143+
int update_v_raw = (int)wolfBoot_update_firmware_version();
144+
uint32_t boot_v = 0U;
145+
uint32_t update_v = 0U;
144146
uint32_t max_v = (boot_v > update_v) ? boot_v : update_v;
147+
148+
if (boot_v_raw >= 0)
149+
boot_v = (uint32_t)boot_v_raw;
150+
if (update_v_raw >= 0)
151+
update_v = (uint32_t)update_v_raw;
152+
max_v = (boot_v > update_v) ? boot_v : update_v;
145153
#endif
146154

147155
memset(&os_image, 0, sizeof(struct wolfBoot_image));

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +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)
3031

3132
#include "user_settings.h"
3233
#include "wolfboot/wolfboot.h"
@@ -210,7 +211,7 @@ START_TEST(test_invalid_update_rollback_to_older_boot_is_denied)
210211

211212
ck_assert_int_eq(wolfBoot_staged_ok, 0);
212213
ck_assert_int_eq(wolfBoot_panicked, 1);
213-
ck_assert_ptr_eq((void *)wolfBoot_stage_address, (void *)0xFFFFFFFF);
214+
ck_assert_uint_eq((uintptr_t)wolfBoot_stage_address, STAGE_ADDR_SENTINEL);
214215
cleanup_flash();
215216
}
216217
END_TEST

0 commit comments

Comments
 (0)