libretiny-eu / libretiny

PlatformIO development platform for IoT modules
http://docs.libretiny.eu/
MIT License
382 stars 55 forks source link

[libs] Fix MD5 calculation during OTA update #240

Closed hn closed 5 months ago

hn commented 5 months ago

When the MCU is started with OTA1 image and you try to update the firmware, the OTA process fails:

[D][ota:320]: OTA in progress: 48.8%
[D][ota:320]: OTA in progress: 65.1%
[D][ota:320]: OTA in progress: 81.5%
E [  57890.676] OTA: Error: MD5 Check Failed
E [  57890.680] OTA: - written: 1380864 of 1380864
E [  57890.688] OTA: - buf: size=2199023255552, left=1153652920625948496
E [  57890.691] OTA: - ctx: seq=4294967295, part=(null)
E [  57890.699] OTA: - buf: seq=2696/2697, addr=689920, len=252
[W][ota:336]: Error ending OTA!, error_code: 132

Turns out that lt_ota_write() modifies the data ("binpatch" to update memory addresses for OTA2) and therefore MD5Update has to be called before writing the data.