OTA update issue with magic byte

adamoos
Posts: 1
Joined: Sat Jun 29, 2019 10:45 am

OTA update issue with magic byte

Postby adamoos » Sat Jun 29, 2019 1:06 pm

Hi all,

While updating my firmware on ESP8266 with OTA I'm getting magic byte error I checked my bin file and 0xE9 is first byte. My code snippet:
  1.     std::unique_ptr<BearSSL::WiFiClientSecure> client(new BearSSL::WiFiClientSecure);
  2.     client->setInsecure();
  3.  
  4.     HTTPClient http;
  5.  
  6.     http.begin(*client, "https://example.com/firmware.bin");
  7.     int httpCode = http.GET();
  8.  
  9.   if (httpCode <= 0) {
  10.     Serial.printf("HTTP failed, error: %s\n",
  11.        http.errorToString(httpCode).c_str());
  12.     return;
  13.   }
  14.  
  15.     // Check that we have enough space for the new binary.
  16.     int contentLen = http.getSize();
  17.     Serial.printf("Content-Length: %d\n", contentLen);
  18.     bool canBegin = Update.begin(contentLen);
  19.     if (!canBegin)
  20.     {
  21.         Serial.println("Not enough space to begin OTA");
  22.         return;
  23.     }
  24.     // Write the HTTP stream to the Update library.
  25.     WiFiClient *client2 = http.getStreamPtr();
  26.     size_t written = Update.writeStream(*client2);
  27.     Serial.printf("OTA: %d/%d bytes written.\n", written, contentLen);
With method call: Update.writeStream(*client2) - I'm getting magic byte error.

If I comment out code in Updater.cpp method _verifyHeader that checks the byte - OTA process works as expected.

Commented code:
  1. bool UpdaterClass::_verifyHeader(uint8_t data) {
  2.     if(_command == U_FLASH) {
  3.         // check for valid first magic byte (is always 0xE9)
  4.         // if(data != 0xE9) {
  5.         //     _currentAddress = (_startAddress + _size);
  6.         //     _setError(UPDATE_ERROR_MAGIC_BYTE);
  7.         //     return false;
  8.         // }
  9.         return true;
  10.     } else if(_command == U_SPIFFS) {
  11.         // no check of SPIFFS possible with first byte.
  12.         return true;
  13.     }
  14.     return false;
  15. }
Any help will be much appreciated.
Kind regards,

ESP_Alvin
Posts: 195
Joined: Thu May 17, 2018 2:26 am

Re: OTA update issue with magic byte

Postby ESP_Alvin » Sun Jun 30, 2019 11:52 pm

Hi adamoos,

Is your issue on ESP8266? If yes, would you please post your topic on the https://bbs.espressif.com? Thanks.

Alvin

Who is online

Users browsing this forum: No registered users and 231 guests