mirror of https://github.com/wolfSSL/wolfBoot.git
Added comments to the delta diff code
parent
c76166f6ea
commit
21c57be53e
27
src/delta.c
27
src/delta.c
|
@ -223,18 +223,28 @@ int wb_diff(WB_DIFF_CTX *ctx, uint8_t *patch, uint32_t len)
|
|||
break;
|
||||
if ((memcmp(pa, (ctx->src_b + ctx->off_b), BLOCK_HDR_SIZE) == 0)) {
|
||||
uint32_t b_start;
|
||||
/* Identical areas of BLOCK_HDR_SIZE bytes match between the images.
|
||||
* initialize match_len; blk_start is the relative offset within
|
||||
* the src image.
|
||||
*/
|
||||
match_len = BLOCK_HDR_SIZE;
|
||||
blk_start = pa - ctx->src_a;
|
||||
b_start = ctx->off_b;
|
||||
pa+= BLOCK_HDR_SIZE;
|
||||
ctx->off_b += BLOCK_HDR_SIZE;
|
||||
while (*pa == *(ctx->src_b + ctx->off_b)) {
|
||||
/* Extend matching block if possible, as long as the
|
||||
* identical sequence continues.
|
||||
*/
|
||||
if ((uint32_t)(pa + 1 - ctx->src_a) >= ctx->size_a) {
|
||||
/* Stop matching if the source image size limit is hit. */
|
||||
break;
|
||||
}
|
||||
if ((b_start / WOLFBOOT_SECTOR_SIZE) < ((ctx->off_b + 1) / WOLFBOOT_SECTOR_SIZE)) {
|
||||
/* Stop matching when the sector bound is hit. */
|
||||
break;
|
||||
}
|
||||
/* Increase match len, test next byte */
|
||||
pa++;
|
||||
ctx->off_b++;
|
||||
match_len++;
|
||||
|
@ -257,18 +267,35 @@ int wb_diff(WB_DIFF_CTX *ctx, uint8_t *patch, uint32_t len)
|
|||
uint32_t pb_end = page_start * WOLFBOOT_SECTOR_SIZE;
|
||||
pb = ctx->src_b;
|
||||
while (((uint32_t)(pb - ctx->src_b) < pb_end) && (p_off < len)) {
|
||||
/* Check image boundary */
|
||||
if ((ctx->size_b - ctx->off_b) < BLOCK_HDR_SIZE)
|
||||
break;
|
||||
if ((uint32_t)(ctx->size_b - (pb - ctx->src_b)) < BLOCK_HDR_SIZE)
|
||||
break;
|
||||
|
||||
/* Don't try matching backwards if the distance between the two
|
||||
* blocks is smaller than one sector.
|
||||
*/
|
||||
if (WOLFBOOT_SECTOR_SIZE > (pb - ctx->src_b) - (page_start * WOLFBOOT_SECTOR_SIZE))
|
||||
break;
|
||||
|
||||
if ((memcmp(pb, (ctx->src_b + ctx->off_b), BLOCK_HDR_SIZE) == 0)) {
|
||||
/* A match was found between the current pointer and a
|
||||
* previously patched area in the resulting image.
|
||||
* Initialize match_len and set the blk_start to the beginning
|
||||
* of the matching area in the image.
|
||||
*/
|
||||
match_len = BLOCK_HDR_SIZE;
|
||||
blk_start = pb - ctx->src_b;
|
||||
pb+= BLOCK_HDR_SIZE;
|
||||
ctx->off_b += BLOCK_HDR_SIZE;
|
||||
while (*pb == *(ctx->src_b + ctx->off_b)) {
|
||||
/* Extend match as long as the areas have the
|
||||
* same content. Block skipping in this case is
|
||||
* not a problem since the distance between the patched
|
||||
* area and the area to patch is always larger than one
|
||||
* block size.
|
||||
*/
|
||||
pb++;
|
||||
if ((uint32_t)(pb - ctx->src_b) >= pb_end) {
|
||||
pb--;
|
||||
|
|
Loading…
Reference in New Issue