Skip to content

Commit 929f9d3

Browse files
committed
Fix base_version mismatch
1 parent 597ca3a commit 929f9d3

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

.github/workflows/test-powerfail-simulator.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ jobs:
198198
- name: Rebuild wolfboot.elf
199199
run: |
200200
make test-sim-internal-flash-with-delta-update
201-
201+
202202
- name: Run update-revert test with power failures (DELTA)
203203
run: |
204204
tools/scripts/sim-update-powerfail-resume.sh

src/update_flash.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
215215
uint32_t *img_size;
216216
uint32_t total_size;
217217
WB_PATCH_CTX ctx;
218+
uint32_t cur_v, upd_v, delta_base_v;
218219
#ifdef EXT_ENCRYPTED
219220
uint8_t key[ENCRYPT_KEY_SIZE];
220221
uint8_t nonce[ENCRYPT_NONCE_SIZE];
@@ -237,20 +238,24 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
237238
if (wolfBoot_get_delta_info(PART_UPDATE, inverse, &img_offset, &img_size) < 0) {
238239
return -1;
239240
}
241+
cur_v = wolfBoot_current_firmware_version();
242+
upd_v = wolfBoot_update_firmware_version();
243+
delta_base_v = wolfBoot_get_diffbase_version(PART_UPDATE);
240244
if (inverse) {
241-
uint32_t cur_v, upd_v, delta_base_v;
242-
cur_v = wolfBoot_current_firmware_version();
243-
upd_v = wolfBoot_update_firmware_version();
244-
delta_base_v = wolfBoot_get_diffbase_version(PART_UPDATE);
245245
if (((cur_v == upd_v) && (delta_base_v < cur_v)) || resume_inverse) {
246246
ret = wb_patch_init(&ctx, boot->hdr, boot->fw_size +
247247
IMAGE_HEADER_SIZE, update->hdr + *img_offset, *img_size);
248248
} else {
249249
ret = -1;
250250
}
251251
} else {
252-
ret = wb_patch_init(&ctx, boot->hdr, boot->fw_size + IMAGE_HEADER_SIZE,
253-
update->hdr + IMAGE_HEADER_SIZE, *img_size);
252+
if (cur_v != delta_base_v) {
253+
/* Wrong base image, cannot apply delta patch */
254+
ret = -1;
255+
} else {
256+
ret = wb_patch_init(&ctx, boot->hdr, boot->fw_size + IMAGE_HEADER_SIZE,
257+
update->hdr + IMAGE_HEADER_SIZE, *img_size);
258+
}
254259
}
255260
if (ret < 0)
256261
goto out;

0 commit comments

Comments
 (0)