ESP_OTA: OTA image has invalid magic byte

tharunjoy
Posts: 22
Joined: Wed Dec 12, 2018 5:30 am

ESP_OTA: OTA image has invalid magic byte

Postby tharunjoy » Mon Feb 17, 2020 11:38 am

Hi,

I am using ESP IDF 3.3v. I am trying to implement OTA update.
I ran an openssl server locally and I was able to do OTA update smoothly. Then I tried deploying the same application firmware in onedrive, google drive and even in dropbox where I am getting some error as show below.

Code: Select all

I (641674) esp_https_ota: Starting OTA...
I (641674) esp_https_ota: Writing to partition subtype 16 at offset 0x170000
I (644734) esp_https_ota: esp_ota_begin succeeded
I (644744) esp_https_ota: Please Wait. This may take time
E (644744) esp_ota_ops: OTA image has invalid magic byte (expected 0xE9, saw 0x3c
E (644754) esp_https_ota: Error: esp_ota_write failed! err=0x0
E (644754) OTA_UPDATE :::: Firmware Upgrades Failed
I am using ESP32-WROOM-32 chipset and I am having a custom partation_table is as below

Code: Select all

# Espressif ESP32 Partition Table
# Name, Type, SubType, Offset, Size, Flags
nvs,data,nvs,0x9000,200K,
otadata,data,ota,0x3b000,8K,
phy_init,data,phy,0x3d000,4K,
factory,app,factory,0x40000,1200K,
ota_0,app,ota_0,0x170000,1200K,
ota_1,app,ota_1,0x2a0000,1200K,
*******************************************************************************
Size of the image is

Code: Select all

Total sizes:
 DRAM .data size:   12976 bytes
 DRAM .bss  size:   68976 bytes
Used static DRAM:   81952 bytes (  42628 available, 65.8% used)
Used static IRAM:   77172 bytes (  53900 available, 58.9% used)
      Flash code:  658886 bytes
    Flash rodata:  153652 bytes
Total image size:~ 902686 bytes (.bin may be padded larger)
Why I am getting this issue and how to resolve this?

Thanks in advance

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: ESP_OTA: OTA image has invalid magic byte

Postby ESP_Angus » Tue Feb 18, 2020 4:38 am

tharunjoy wrote:
Mon Feb 17, 2020 11:38 am
I ran an openssl server locally and I was able to do OTA update smoothly. Then I tried deploying the same application firmware in onedrive, google drive and even in dropbox where I am getting some error as show below.
The most likely explanation is that the web server is not sending the .bin file but is sending something else. The first byte of an app image .bin file should be 0xE9. The error suggests that the file has first character 0x3C which is ASCII "<" and implies the server is sending an HTML page not the .bin file.

You can try putting the same URL into a tool like curl or wget on the command line and download it that way, see if the .bin file is downloaded or if it's something else (like an error page, login page, or a redirect page).

In general, personal cloud file services like the ones you mention are not suitable for use as generic HTTPS web servers. You will probably need a more generic web server, web host service or a different type of cloud service like Amazon S3

tharunjoy
Posts: 22
Joined: Wed Dec 12, 2018 5:30 am

Re: ESP_OTA: OTA image has invalid magic byte

Postby tharunjoy » Tue Feb 18, 2020 12:52 pm

I download image using curl and tried flashing through serial and got the same error.

Code: Select all

E (141) esp_image: image at 0x40000 has invalid magic byte
W (147) esp_image: image at 0x40000 has invalid SPI mode 116
W (153) esp_image: image at 0x40000 has invalid SPI size 6
E (159) boot: Factory app partition is not bootable
E (165) esp_image: image at 0x170000 has invalid magic byte
W (171) esp_image: image at 0x170000 has invalid SPI mode 255
W (178) esp_image: image at 0x170000 has invalid SPI size 15
E (184) boot: OTA app partition slot 0 is not bootable
E (190) esp_image: image at 0x2a0000 has invalid magic byte
W (196) esp_image: image at 0x2a0000 has invalid SPI mode 255
W (203) esp_image: image at 0x2a0000 has invalid SPI size 15
E (209) boot: OTA app partition slot 1 is not bootable
E (215) boot: No bootable app partitions in the partition table
But if I download the same image from a browser, I am not getting any error and is able to flash.
Why is it so? Is browser doing some de-encryption mechanism while downloading or something else?

ESP_Sprite
Posts: 9759
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP_OTA: OTA image has invalid magic byte

Postby ESP_Sprite » Tue Feb 18, 2020 3:31 pm

Hard to say... are you sure your webserver doesn't use e.g. Javascript to redirect to the actual download? A webbrowser would follow that, Curl and the ESP32 would not. Grab the file using Curl and open it in a text editor, that should tell you enough. Given that cloud providers aren't really made for embedded stuff, I wouldn't be surprised if this is the case.

chegewara
Posts: 2376
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP_OTA: OTA image has invalid magic byte

Postby chegewara » Tue Feb 18, 2020 11:47 pm

Code: Select all

curl -sSl -D - https://....
This should give you all info you need, with headers and body I think.

tharunjoy
Posts: 22
Joined: Wed Dec 12, 2018 5:30 am

Re: ESP_OTA: OTA image has invalid magic byte

Postby tharunjoy » Wed Feb 19, 2020 9:04 am

Thank you guys..
I found the reason for this issue. Just like you guys told ESP is not able to automatically redirect the URL like a web browser. I just found the redirected URL and used that in the program, to successfully do an OTA update.

kenn.tran
Posts: 9
Joined: Thu May 14, 2020 2:09 pm

Re: ESP_OTA: OTA image has invalid magic byte

Postby kenn.tran » Wed Jun 29, 2022 1:26 pm

Hello tharunjoy,

I have the same problem, can you please give me more detail about what did you do?
I found the reason for this issue. Just like you guys told ESP is not able to automatically redirect the URL like a web browser. I just found the redirected URL and used that in the program, to successfully do an OTA update.
Thanks.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 128 guests