<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">On my devices I’m seeing a problem with doing OTA updates when running 3.1.007. I’m seeing:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">OVMS# ota flash http</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">Current running partition is: factory</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">Target partition is: ota_0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">Download firmware from <a href="http://api.openvehicles.com/firmware/ota/v3.1/edge/ovms3.bin" class="">api.openvehicles.com/firmware/ota/v3.1/edge/ovms3.bin</a> to ota_0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">Expected file size is 2850336</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">Preparing flash partition...</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">abort() was called at PC 0x401b8e84 on core 0</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">0x401b8e84: pm_on_beacon_rx at ??:?</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class=""><br class=""></span></font></div><div class=""><span style="font-size: 18px; font-family: "Andale Mono";" class="">Backtrace: 0x40091e6b:0x3ffcc4a0 0x40091fc3:0x3ffcc4c0 0x401b8e84:0x3ffcc4e0 0x401b94ef:0x3ffcc520 0x401b9bd1:0x3ffcc550 0x40089e62:0x3ffcc5a0</span></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">0x40091e6b: invoke_abort at /Users/mark/esp/esp-idf/components/esp32/panic.c:669</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">0x40091fc3: abort at /Users/mark/esp/esp-idf/components/esp32/panic.c:669</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">0x401b8e84: pm_on_beacon_rx at ??:?</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">0x401b94ef: ppRxProtoProc at ??:?</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">0x401b9bd1: ppRxPkt at ??:?</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">0x40089e62: ppTask at ??:?</span></font></div></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 18px;" class="">(this is a firmware rebuild so addresses may vary from stock 3.1.007, but the functions are the same)</span></font></div></blockquote><div class=""><br class=""></div><div class="">The pm_on_beacon_rx function is in libpp (as are ppRxProtoProc, ppRxPkt, and ppTask.</div><div class=""><br class=""></div><div class="">If I comment out the esp_ota_* functions, it does the download and works fine. But if esp_ota_begin is called, then the crash occurs within http.BodyRead. (although I think it is within the ppTask, not in our code).</div><div class=""><br class=""></div><div class="">It I reduce the size parameter given to esp_ota_begin, I can get it to work just fine. Around 1.5MB is fine, but above that is starts to get flaky. Espressif say that during flash writes the cache must be disabled, so all access to SPIRAM halted. Sometimes, I get to see a message 'I (20642) wifi: bcn_timout,ap_probe_send_start’ which seems to confirm the wifi task is being starved for cpu time during the esp_ota_begin(). I guess that is triggering a bug within the wifi stack where it doesn’t handle it gracefully.</div><div class=""><br class=""></div><div class="">I then tried hacking around the esp_ota_begin() function. The Espressif implementation simply calls esp_partition_erase_range() to erase the partition in one call. For us, that now means blanking 2.8MB of flash and takes about 15 seconds or so. I changed that to call esp_partition_erase_range() multiple times, in 256KB chunks, with a 10ms vTaskDelay between each chunk. Problem solved. OTA works again doing it that way.</div><div class=""><br class=""></div><div class="">I’m not sure how to get this fix applied. The issue is in Espressif’s code, related to big partition sizes. I guess they haven’t seen it because with 1MB OTA partitions the delay is only 3 seconds or so and probably not long enough to trigger the issue. I’ll raise a bug report with them, but suspect it will be a while for them to address it. As a temporary workaround for us, I think I’ll bring esp_ota_begin() into our ovms_ota code and customise it there specifically for us. We can always switch back to the normal esp_ota_begin when/if Espressif come up with a permanent solution. I don’t really want to change that core Espressif code, without direction from Espressif as to how to change it (been there, done that, and wasted a lot of time doing it).</div><div class=""> </div><div class="">For safety, I’ve rolled back edge to 3.1.006-15-g14b8eb6. That will stop new deployments of this, while we solve the problem. For existing deployments in the field, I can only think of two solutions: (a) switch ota to factory, reboot, and flash to fixed code, or (b) ota from sdcard, with wifi unused/off.</div><div class=""><br class=""></div><div class="">I should have the fix later today.</div><div class=""><br class=""></div><div class="">Regards, Mark.</div><div class=""><br class=""></div></body></html>