Skip to content

Commit 873fd18

Browse files
committed
fix: add check to ensure OTA buffer size for 16-byte aligned
This commit added guide to, round off OTA written size to allowed aignmnet when flash ecnryption enabled.
1 parent 46def99 commit 873fd18

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

components/app_update/include/esp_ota_ops.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp
8989
* Unlike esp_ota_begin(), this function does not erase the partition which receives the OTA update, but rather expects that part of the image
9090
* has already been written correctly, and it resumes writing from the given offset.
9191
*
92+
* @note When flash encryption is enabled, data writes must be 16-byte aligned.
93+
* Any leftover (non-aligned) data is temporarily cached and may be lost after reboot.
94+
* Therefore, during resumption, ensure that image offset is always 16-byte aligned.
95+
*
9296
* @param partition Pointer to info for the partition which is receiving the OTA update. Required.
9397
* @param erase_size Specifies how much flash memory to erase before resuming OTA, depending on whether a sequential write or a bulk erase is being used.
9498
* @param image_offset Offset from where to resume the OTA process. Should be set to the number of bytes already written.

components/esp_https_ota/src/esp_https_ota.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <sys/param.h>
1515
#include <inttypes.h>
1616
#include "esp_check.h"
17+
#include "esp_flash_encrypt.h"
1718
#include "hal/efuse_hal.h"
1819

1920
ESP_EVENT_DEFINE_BASE(ESP_HTTPS_OTA_EVENT);
@@ -528,6 +529,14 @@ esp_err_t esp_https_ota_begin(const esp_https_ota_config_t *ota_config, esp_http
528529
}
529530

530531
const int alloc_size = MAX(ota_config->http_config->buffer_size, DEFAULT_OTA_BUF_SIZE);
532+
if (ota_config->ota_resumption) {
533+
if (esp_flash_encryption_enabled() && (alloc_size & 0xFU) != 0) {
534+
// For FE case the flash is written in multiples of 16 bytes
535+
ESP_LOGE(TAG, "Buffer size must be multiple of 16 bytes for FE and ota resumption case");
536+
goto http_cleanup;
537+
}
538+
}
539+
531540
if (ota_config->buffer_caps != 0) {
532541
https_ota_handle->ota_upgrade_buf = (char *)heap_caps_malloc(alloc_size, ota_config->buffer_caps);
533542
} else {

0 commit comments

Comments
 (0)