Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp_https_ota Corrupts downloaded firmware image when partial_http_download is used (IDFGH-11993) #13065

Closed
3 tasks done
therealergo opened this issue Jan 29, 2024 · 1 comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@therealergo
Copy link

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.1.2

Espressif SoC revision.

ESP32

Operating System used.

Windows

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

PowerShell

Development Kit.

Custom Board

Power Supply used.

USB

What is the expected behavior?

The esp_https_ota module should successfully download OTA images regardless of the partial_http_download setting.

What is the actual behavior?

Whenever partial_http_download is set to true and esp_https_ota_get_img_desc(...) is not called between esp_https_ota_begin(...) and esp_https_ota_perform(...), the downloaded OTA image is corrupted.

Steps to reproduce.

  • Call esp_https_ota(...) with partial_http_download set to true.
  • Watch the OTA fail to complete.

Debug Logs.

e.g. `esp_image: invalid segment length 0x1` or other random image validation failures caused by a corrupted OTA image.

More Information.

This is caused by a set of bytes being double-counted at the very start of the OTA update process. If esp_https_ota_get_img_desc(...) is not called, then control flows through the else block at lines 511-514 (using 5.1.2 line numbers) of esp_https_ota.c. The call to read_header(...) in that block updates the value of handle->binary_file_len to account for the bytes that are read in order to read in the header. These bytes are then counted again in the value of handle->binary_file_len when _ota_write(...) is called with that same buffer on line 535. This then offsets the header calculation on line 588, effectively skipping part of the file download. This corrupts the downloaded OTA and typically makes it unusable.

This appears to have been fixed in v5.3-dev by commit 37a098e, but the commit message only refers to an incorrect debug print and it has not been back-ported to v5.1. It does not only affect printing, it can corrupt the OTA image.

Additionally note that esp_https_ota_get_img_desc(...) is incorrectly referred to as esp_https_ota_read_img_desc(...) in several of the comments and error messages in esp_https_ota.c.

@therealergo therealergo added the Type: Bug bugs in IDF label Jan 29, 2024
@espressif-bot espressif-bot added the Status: Opened Issue is new label Jan 29, 2024
@github-actions github-actions bot changed the title esp_https_ota Corrupts downloaded firmware image when partial_http_download is used esp_https_ota Corrupts downloaded firmware image when partial_http_download is used (IDFGH-11993) Jan 29, 2024
@hmalpani
Copy link
Collaborator

Hello @therealergo
The commit you are referring to has been backported to release/v5.1 branch: 7970408
It will be available in next release of v5.1. Until then you can cherry-pick the commit to resolve the issue. Hope it helps

@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened Issue is new labels Feb 1, 2024
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: In Progress Work is in progress labels Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

3 participants