From a0eedf112f1c046f53334397f87f05b3f565ad5c Mon Sep 17 00:00:00 2001 From: Supreet Deshpande Date: Mon, 10 Dec 2018 17:16:38 +0530 Subject: [PATCH 1/2] bugfix/ota_magic_byte_issue: Fixes OTA magic byte error On enabling flash encryption, OTA fails with magic byte error in the second chunk if the http data is split into two or more chunks and first chunk is less than 16. --- components/app_update/esp_ota_ops.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/app_update/esp_ota_ops.c b/components/app_update/esp_ota_ops.c index c33deef353..af6019a815 100644 --- a/components/app_update/esp_ota_ops.c +++ b/components/app_update/esp_ota_ops.c @@ -145,8 +145,7 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size) if (it->handle == handle) { // must erase the partition before writing to it assert(it->erased_size > 0 && "must erase the partition before writing to it"); - - if(it->wrote_size == 0 && size > 0 && data_bytes[0] != 0xE9) { + if(it->wrote_size == 0 && it->partial_bytes == 0 && size > 0 && data_bytes[0] != 0xE9) { ESP_LOGE(TAG, "OTA image has invalid magic byte (expected 0xE9, saw 0x%02x", data_bytes[0]); return ESP_ERR_OTA_VALIDATE_FAILED; } From 3c87f47ba2353d75bcec255ee2d4558ad9b73f26 Mon Sep 17 00:00:00 2001 From: Supreet Deshpande Date: Mon, 17 Dec 2018 09:56:18 +0530 Subject: [PATCH 2/2] bugfix/ota_magic_byte_issue: Fix indent and replace constant by macro Replace 0xE9 by ESP_IMAGE_HEADER_MAGIC. --- components/app_update/esp_ota_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/app_update/esp_ota_ops.c b/components/app_update/esp_ota_ops.c index af6019a815..8a2da845d6 100644 --- a/components/app_update/esp_ota_ops.c +++ b/components/app_update/esp_ota_ops.c @@ -145,7 +145,7 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size) if (it->handle == handle) { // must erase the partition before writing to it assert(it->erased_size > 0 && "must erase the partition before writing to it"); - if(it->wrote_size == 0 && it->partial_bytes == 0 && size > 0 && data_bytes[0] != 0xE9) { + if (it->wrote_size == 0 && it->partial_bytes == 0 && size > 0 && data_bytes[0] != ESP_IMAGE_HEADER_MAGIC) { ESP_LOGE(TAG, "OTA image has invalid magic byte (expected 0xE9, saw 0x%02x", data_bytes[0]); return ESP_ERR_OTA_VALIDATE_FAILED; }