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

esp32/ota: Implement ESP-IDF OTA functionality. #7048

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ekondayan
Copy link

@ekondayan ekondayan commented Mar 17, 2021

UPDATE: The test completed successfully on NodeMCU ESP32 by ai-thinker with ESP-IDF v4.0, v4.1, v4.2, v4.3

Implemented new functions in esp32.Partition:

  • mark_app_invalid_rollback_and_reboot()

  • check_rollback_is_possible()

  • app_description()

  • app_state()

  • ota_begin()

  • ota_write()

  • ota_write_with_offset() for ESP-IDF version >= 4.2

  • ota_end()

  • ota_abort() for ESP-IDF version >= 4.3

  • create tests

  • update documentation

For many commercial products, Over The Air updates are a very important and critical part. It must be reliable and should not brick the device. Writing a good OTA from scratch is a daunting task. For that reason the use of well tested and proven reliable libraries is much more preferable than the ones developed in the house.

USECASE

I'm developing an industrial device where the OTA is an essential part of it. Since only a few functions from esp-idf are
implemented (enough for hobby project but not enough for commercial project), I ended up duplicating the esp-idf ota functionality in python.
The result was a module with a questionable quality. I tried to predict all the possible places where it could crash, but my gut was
telling me that I could be missing something. So I decided to implement more of the the OTA functions from esp-idf and to use them in my OTA module.
I've rewritten my OTA module and replaced the redundant code with the implemented functions from esp-idf. This allowed me to reduced the size of the module significantly, increase the robustness of the code and on top of that now the code got much simpler and easier to maintain.
The total increase in size of the compiled app image is 2432 bytes.

IMPLEMENTATION

Extend the esp32.Partition class where all the OTA related functions are
prefixed with "ota_" and app related functions are prefixed with "app_".

Example:
from esp32 import Partition
app_part = Partition(Partition.RUNNING)
app_part.app_description()
app_part.app_state()
handle = app_part.ota_begin()
app_part.ota_end(handle)

New functions:
Partition.mark_app_invalid_rollback_and_reboot(cls)
Partition.check_rollback_is_possible(cls)
Partition.app_description(self)
Partition.app_state(self)
Partition.ota_begin(self, image_size = 0)
Partition.ota_write(self, handle_in, data_in)
Partition.ota_write_with_offset(self, handle_in, data_in, offset)
Partition.ota_end(self, handle_in)
Partition.ota_abort(self, handle_in) only for ESP-IDF version >= 4.3

BENEFITS

  • no code duplication
  • reduced code size
  • cleaner and easier to maintain code
  • esp-idf handles encrypted flash
  • use a reliable and well tested library written by the creators of ESP32
  • more robust OTA procedure
  • better performance

CONS

  • None :) (maybe the 2432 bytes overhead in the final compiled app image)

@ekondayan
Copy link
Author

ekondayan commented Apr 30, 2021

Anybody?
Is there any chance of this getting mainstream?

@ekondayan ekondayan force-pushed the feature/ota branch 2 times, most recently from de47d80 to 3a98bae Compare November 3, 2023 10:13
@ekondayan ekondayan force-pushed the feature/ota branch 2 times, most recently from dbb6555 to db6bf8a Compare November 20, 2023 08:30
@ekondayan ekondayan force-pushed the feature/ota branch 3 times, most recently from e30d4e1 to 9e5ade7 Compare December 6, 2023 08:31
@ekondayan ekondayan force-pushed the feature/ota branch 2 times, most recently from 6848b7d to c668288 Compare December 18, 2023 07:48
@ekondayan ekondayan force-pushed the feature/ota branch 2 times, most recently from 122c3fd to 40487c6 Compare December 28, 2023 09:33
@ekondayan ekondayan force-pushed the feature/ota branch 2 times, most recently from b4e6add to ccc07f5 Compare January 8, 2024 08:15
@ekondayan ekondayan force-pushed the feature/ota branch 2 times, most recently from 7528feb to 904d16c Compare February 20, 2024 08:45
@ekondayan ekondayan force-pushed the feature/ota branch 2 times, most recently from d66a246 to eaccaf7 Compare February 29, 2024 13:54
@projectgus
Copy link
Contributor

This is an automated heads-up that we've just merged a Pull Request
that removes the STATIC macro from MicroPython's C API.

See #13763

A search suggests this PR might apply the STATIC macro to some C code. If it
does, then next time you rebase the PR (or merge from master) then you should
please replace all the STATIC keywords with static.

Although this is an automated message, feel free to @-reply to me directly if
you have any questions about this.

Implemented new functions:
* mark_app_invalid_rollback_and_reboot()
* check_rollback_is_possible()
* app_description()
* app_state()
* ota_begin()
* ota_write()
* ota_write_with_offset() for ESP-IDF version >= 4.2
* ota_end()
* ota_abort() for ESP-IDF version >= 4.3

* create tests
* update documentation

esp32/ota: Implement ESP-IDF OTA functionality.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants