Skip to content

Commit f8f12f9

Browse files
author
Jamie C. Driver
committed
ota consistency: small tweaks to make full and delta code more consistent
Rename function argument and check validity before updating progress.
1 parent 5853368 commit f8f12f9

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

main/process/ota.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ typedef struct {
2727
} ota_deflate_ctx_t;
2828

2929
/* this is called by the deflate library when it has uncompressed data to write */
30-
static int uncompressed_stream_writer(void* ctx, uint8_t* uncompressed, size_t towrite)
30+
static int uncompressed_stream_writer(void* ctx, uint8_t* uncompressed, size_t length)
3131
{
3232
JADE_ASSERT(ctx);
3333
JADE_ASSERT(uncompressed);
34-
JADE_ASSERT(towrite);
34+
JADE_ASSERT(length);
3535

3636
ota_deflate_ctx_t* octx = (ota_deflate_ctx_t*)ctx;
3737
JADE_ASSERT(octx->joctx);
3838

39-
if (!*octx->prevalidated && towrite >= CUSTOM_HEADER_MIN_WRITE) {
39+
if (!*octx->prevalidated && length >= CUSTOM_HEADER_MIN_WRITE) {
4040
const enum ota_status res = ota_user_validation(octx->joctx, uncompressed);
4141
if (res != SUCCESS) {
4242
JADE_LOGE("ota_user_validation() error, %u", res);
@@ -46,7 +46,7 @@ static int uncompressed_stream_writer(void* ctx, uint8_t* uncompressed, size_t t
4646
*octx->prevalidated = true;
4747
}
4848

49-
const esp_err_t res = esp_ota_write(*octx->joctx->ota_handle, (const void*)uncompressed, towrite);
49+
const esp_err_t res = esp_ota_write(*octx->joctx->ota_handle, (const void*)uncompressed, length);
5050
if (res != ESP_OK) {
5151
JADE_LOGE("ota_write() error: %u", res);
5252
*octx->joctx->ota_return_status = ERROR_WRITE;
@@ -55,22 +55,22 @@ static int uncompressed_stream_writer(void* ctx, uint8_t* uncompressed, size_t t
5555

5656
if (octx->joctx->hash_type == HASHTYPE_FULLFWDATA) {
5757
// Add written to hash calculation
58-
JADE_ZERO_VERIFY(mbedtls_sha256_update(octx->joctx->sha_ctx, uncompressed, towrite));
58+
JADE_ZERO_VERIFY(mbedtls_sha256_update(octx->joctx->sha_ctx, uncompressed, length));
5959
}
6060

61-
*octx->joctx->remaining_uncompressed -= towrite;
61+
*octx->joctx->remaining_uncompressed -= length;
6262
const size_t written = octx->joctx->uncompressedsize - *octx->joctx->remaining_uncompressed;
6363

64+
if (written > CUSTOM_HEADER_MIN_WRITE && !*octx->prevalidated) {
65+
return DEFLATE_ERROR;
66+
}
67+
6468
/* Update the progress bar once the user has confirmed and upload is in progress */
6569
if (*octx->prevalidated) {
6670
JADE_ASSERT(octx->joctx->progress_bar.progress_bar);
6771
update_progress_bar(&octx->joctx->progress_bar, octx->joctx->uncompressedsize, written);
6872
}
6973

70-
if (written > CUSTOM_HEADER_MIN_WRITE && !*octx->prevalidated) {
71-
return DEFLATE_ERROR;
72-
}
73-
7474
return DEFLATE_OK;
7575
}
7676

0 commit comments

Comments
 (0)