Is it possible to check for correct architecture on OTA update (ESP32 or ESP8266)? Having a skech running on ESP8266 as well as ESP32 with the ability to update via OTA, uploading the wrong binary (upload to ESP8266 compiled for ESP32, and vice versa) leads to crashing the MCU and not being able to do OTA Updates any more.
The Update is done in the simple usual way: Upload binary file and call the methods from the Update Class (begin(), write(), and end()).
Is there any way to check if the uploaded file matches the architecture of the MCU before starting the update?
Edit:
Both the ESP8266 and the ESP32 Updater class check for an &quot;IMAGE_MAGIC&quot; value in the upload header; but that is defined as &quot;ESP_IMAGE_MAGIC = 0xe9&quot; in both cores. So none of them will refuse to update the wrong one.
Edit 2:
Found a simple workaround that satisfies our needs at the moment: As the arduino IDE saves the binaries with a name like &lt;sketch_name&gt;.&lt;board_name&gt;.bin, we just compare the board name as part of the uploaded filename: if (upload.filename.indexOf(MATCH) &gt; 0) ..., where MATCH is the respective board name. As they are pin compatible, we use &quot;d1_mini.bin&quot; and &quot;d1_mini32.bin&quot;.
Edit 3:
When the webserver tries to abort the upload with 403 Forbidden (because of wrong file), the browser continues to send data until the upload is done. After that, it displays the error message. Thus, even when the filename does not match, it is a waste of time and bandwidth. The only possibility to avoid this is to do a server.client().stop(), but then the browser will not display the message sent, just something like &quot;connection broken&quot;. This does not confirm with the respective RFCs.
This is not really a final solution, so I'ld appreciate any better idea.
Richard
I assume you are the one creating the OTA update.  If so, then why don't you just include a &quot;signature&quot; in the code that is the architecture, i.e. ESP8266 vs. ESP32 and then check for that in your updater code so that it will not install an update for the wrong CPU.