From 69f8accae6fe9df16c326216249a7d791646b1fc Mon Sep 17 00:00:00 2001 From: daishengdong Date: Sun, 28 Jun 2020 19:23:05 +0800 Subject: [PATCH] bugfix of ota_patch --- components/ota/common/diff/ota_diff.c | 2 +- components/ota/recovery/ota_patch.c | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/components/ota/common/diff/ota_diff.c b/components/ota/common/diff/ota_diff.c index 0e2450dc..bf5301af 100644 --- a/components/ota/common/diff/ota_diff.c +++ b/components/ota/common/diff/ota_diff.c @@ -1226,7 +1226,7 @@ static int patch_test(uint8_t *old, size_t oldsize, uint8_t *new, size_t newsize ctrl_blk += sizeof(uint16_t); Z = offtin_u32(ctrl_blk); - ctrl_blk += sizeof(uint16_t); + ctrl_blk += sizeof(uint32_t); old_idx = BLK_IDX(Z, blk_len); old_offset = Z - BLK_LOWER_BOUND(old_idx, blk_len); diff --git a/components/ota/recovery/ota_patch.c b/components/ota/recovery/ota_patch.c index ecdb4011..b845485e 100644 --- a/components/ota/recovery/ota_patch.c +++ b/components/ota/recovery/ota_patch.c @@ -20,6 +20,22 @@ #include "ota_partition.h" #include "lzma_uncompress.h" +static int32_t offtin_u32(uint8_t *buf) +{ + int32_t y; + + y = buf[3] & 0x7F; + y = y * 256; y += buf[2]; + y = y * 256; y += buf[1]; + y = y * 256; y += buf[0]; + + if (buf[3] & 0x80) { + y = -y; + } + + return y; +} + static uint16_t offtin_u16(uint8_t *buf) { int32_t y; @@ -132,7 +148,8 @@ int ota_patch(uint32_t patch, size_t patchsize, size_t ota_size) /* the patch4blk stuff */ uint8_t X; - uint16_t I, N, Y, Z, C, D; + uint32_t Z; + uint16_t I, N, Y, C, D; uint8_t *ctrl_blk, *diff_blk, *extra_blk; uint16_t cursor = 0; uint16_t old_idx, old_offset; @@ -285,8 +302,8 @@ int ota_patch(uint32_t patch, size_t patchsize, size_t ota_size) Y = offtin_u16(ctrl_blk); ctrl_blk += sizeof(uint16_t); - Z = offtin_u16(ctrl_blk); - ctrl_blk += sizeof(uint16_t); + Z = offtin_u32(ctrl_blk); + ctrl_blk += sizeof(uint32_t); old_idx = BLK_IDX(Z, blk_len); old_offset = Z - BLK_LOWER_BOUND(old_idx, blk_len);