Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Tweeted twitter.com/StackArduino/status/1351544975134224384
added 509 characters in body
Source Link
ridgy
  • 181
  • 7

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 "IMAGE_MAGIC" value in the upload header; but that is defined as "ESP_IMAGE_MAGIC = 0xe9" 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 <sketch_name>.<board_name>.bin, we just compare the board name as part of the uploaded filename: if (upload.filename.indexOf(MATCH) > 0) ..., where MATCH is the respective board name. As they are pin compatible, we use "d1_mini.bin" and "d1_mini32.bin".

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 "connection broken". This does not confirm with the respective RFCs.

This is not really a final solution, so I'ld appreciate any better idea.

Richard

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 "IMAGE_MAGIC" value in the upload header; but that is defined as "ESP_IMAGE_MAGIC = 0xe9" 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 <sketch_name>.<board_name>.bin, we just compare the board name as part of the uploaded filename: if (upload.filename.indexOf(MATCH) > 0) ..., where MATCH is the respective board name. As they are pin compatible, we use "d1_mini.bin" and "d1_mini32.bin".

This is not really a final solution, so I'ld appreciate any better idea.

Richard

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 "IMAGE_MAGIC" value in the upload header; but that is defined as "ESP_IMAGE_MAGIC = 0xe9" 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 <sketch_name>.<board_name>.bin, we just compare the board name as part of the uploaded filename: if (upload.filename.indexOf(MATCH) > 0) ..., where MATCH is the respective board name. As they are pin compatible, we use "d1_mini.bin" and "d1_mini32.bin".

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 "connection broken". This does not confirm with the respective RFCs.

This is not really a final solution, so I'ld appreciate any better idea.

Richard

added 2 characters in body
Source Link
ridgy
  • 181
  • 7

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 "IMAGE_MAGIC" value in the upload header; but that is defined as "ESP_IMAGE_MAGIC = 0xe9" 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 <sketch_name>.<board_name>.bin, we just compare the board name as part of the uploaded filename: if (upload.filename.indexOf(MATCH) > 0) ..., where MATCH is the respective board name. As they are pin compatible, we use "d1mini"d1_mini.bin" and "d1mini32"d1_mini32.bin".

This is not really a final solution, so I'ld appreciate any better idea.

Richard

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 "IMAGE_MAGIC" value in the upload header; but that is defined as "ESP_IMAGE_MAGIC = 0xe9" 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 <sketch_name>.<board_name>.bin, we just compare the board name as part of the uploaded filename: if (upload.filename.indexOf(MATCH) > 0) ..., where MATCH is the respective board name. As they are pin compatible, we use "d1mini.bin" and "d1mini32.bin".

This is not really a final solution, so I'ld appreciate any better idea.

Richard

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 "IMAGE_MAGIC" value in the upload header; but that is defined as "ESP_IMAGE_MAGIC = 0xe9" 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 <sketch_name>.<board_name>.bin, we just compare the board name as part of the uploaded filename: if (upload.filename.indexOf(MATCH) > 0) ..., where MATCH is the respective board name. As they are pin compatible, we use "d1_mini.bin" and "d1_mini32.bin".

This is not really a final solution, so I'ld appreciate any better idea.

Richard

added 417 characters in body
Source Link
ridgy
  • 181
  • 7

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 aan "IMAGE_MAGIC" value in the upload header; but that is defined as "ESP_IMAGE_MAGIC = 0xe9" in both cores. So none of them will refuse to Updateupdate the wrong one.

Thank you forEdit 2:

Found a simple workaround that satisfies our needs at the moment: As the arduino IDE saves the binaries with a name like <sketch_name>.<board_name>.bin, we just compare the board name as part of the uploaded filename: if (upload.filename.indexOf(MATCH) > 0) ..., where MATCH is the respective board name. As they are pin compatible, we use "d1mini.bin" and "d1mini32.bin".

This is not really a final solution, so I'ld appreciate any advicebetter idea.

Richard

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 a "IMAGE_MAGIC" value in the upload header; but that is defined as "ESP_IMAGE_MAGIC = 0xe9" in both cores. So none of them will refuse to Update the wrong one.

Thank you for any advice.

Richard

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 "IMAGE_MAGIC" value in the upload header; but that is defined as "ESP_IMAGE_MAGIC = 0xe9" 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 <sketch_name>.<board_name>.bin, we just compare the board name as part of the uploaded filename: if (upload.filename.indexOf(MATCH) > 0) ..., where MATCH is the respective board name. As they are pin compatible, we use "d1mini.bin" and "d1mini32.bin".

This is not really a final solution, so I'ld appreciate any better idea.

Richard

added 228 characters in body
Source Link
ridgy
  • 181
  • 7
Loading
Source Link
ridgy
  • 181
  • 7
Loading