Skip to content

Commit f4e0cc6

Browse files
committed
Delta update fixes
- img_size: use 32-bit variable - remove '+1' from pa_start calculation - fix broken delta.c wb_diff check for distance between matching patterns (root cause for the delta+encrypt bug)
1 parent 90ecd9f commit f4e0cc6

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

include/delta.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int wb_diff_init(WB_DIFF_CTX *ctx, uint8_t *src_a, uint32_t len_a, uint8_t *src_
6767
int wb_diff(WB_DIFF_CTX *ctx, uint8_t *patch, uint32_t len);
6868
int wb_patch_init(WB_PATCH_CTX *bm, uint8_t *src, uint32_t ssz, uint8_t *patch, uint32_t psz);
6969
int wb_patch(WB_PATCH_CTX *ctx, uint8_t *dst, uint32_t len);
70-
int wolfBoot_get_delta_info(uint8_t part, int inverse, uint32_t **img_offset, uint16_t **img_size);
70+
int wolfBoot_get_delta_info(uint8_t part, int inverse, uint32_t **img_offset, uint32_t **img_size);
7171

7272
#endif
7373

src/delta.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ int wb_diff(WB_DIFF_CTX *ctx, uint8_t *patch, uint32_t len)
209209
* base for the sectors that have already been updated.
210210
*/
211211

212-
pa_start = (WOLFBOOT_SECTOR_SIZE + 1) * page_start;
212+
pa_start = WOLFBOOT_SECTOR_SIZE * page_start;
213213
pa = ctx->src_a + pa_start;
214214
while (((uintptr_t)(pa - ctx->src_a) < (uintptr_t)ctx->size_a) && (p_off < len)) {
215215
if ((uintptr_t)(ctx->size_a - (pa - ctx->src_a)) < BLOCK_HDR_SIZE)
@@ -273,7 +273,8 @@ int wb_diff(WB_DIFF_CTX *ctx, uint8_t *patch, uint32_t len)
273273
/* Don't try matching backwards if the distance between the two
274274
* blocks is smaller than one sector.
275275
*/
276-
if (WOLFBOOT_SECTOR_SIZE > (pb - ctx->src_b) - (page_start * WOLFBOOT_SECTOR_SIZE))
276+
if (WOLFBOOT_SECTOR_SIZE > (page_start * WOLFBOOT_SECTOR_SIZE)
277+
- (pb - ctx->src_b))
277278
break;
278279

279280
if ((memcmp(pb, (ctx->src_b + ctx->off_b), BLOCK_HDR_SIZE) == 0)) {

src/update_flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
212212
uint32_t offset = 0;
213213
uint16_t ptr_len;
214214
uint32_t *img_offset;
215-
uint16_t *img_size;
215+
uint32_t *img_size;
216216
uint32_t total_size;
217217
WB_PATCH_CTX ctx;
218218
#ifdef EXT_ENCRYPTED

0 commit comments

Comments
 (0)