Spritetm / libesphttpd

NOTE: THIS CODE IS UNMAINTAINED. Please take a look at https://github.com/chmorgan/libesphttpd instead.
125 stars 109 forks source link

OTA firmware update throws exception #24

Closed mroavi closed 8 years ago

mroavi commented 8 years ago

I tried to update the firmware using the interface in /flash/index.html. I chose the 'httpd.user2.bin' file, clicked on 'Upgrade' and received the following exception:

URL = /flash/upload
Mallocced buffer for 1024 + 1 bytes of post data.
Is url index 0
Is url index 6
Firmware upload cgi start.

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x40100000, len 1856, room 16 
tail 0
chksum 0x63
load 0x3ffe8000, len 776, room 8 
tail 0
chksum 0x02
load 0x3ffe8310, len 552, room 8 
tail 0
chksum 0x79
csum 0x79

2nd boot version : 1.5
  SPI Speed      : 40MHz
  SPI Mode       : QIO
  SPI Flash Size & Map: 32Mbit(512KB+512KB)
jump to run user1 @ 1000

Fatal exception (0): 
epc1=0x40201a24, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
Spritetm commented 8 years ago

What happens if you upload the httpd.ota file instead?

mroavi commented 8 years ago

I tried uploading the httpd.ota file and it did work. However, when I tried refreshing the webpage I noticed that it opened the webpage of a previous project I was running (esp-link in this case).

This is the log output after uploading the ESP for the first time using esptool.py:

APPGEN build/httpd.user1.bin
-2087800074
2087800073
** user1.bin uses 368708 bytes of available
APPGEN build/httpd.user2.bin
-446219354
446219353
** user1.bin uses 368708 bytes of available
Header: 40 bytes, user1: 368708 bytes, user2: 368708 bytes.
Connecting...
Erasing flash...
Took 0.13s to erase flash block
Wrote 4096 bytes at 0x00000000 in 0.1 seconds (289.2 kbit/s)...
Erasing flash...
Took 2.29s to erase flash block
Wrote 369664 bytes at 0x00001000 in 10.2 seconds (289.3 kbit/s)...

Leaving...

I noticed something strange here: After runningAPPGEN build/httpd.user2.bin it is reported again that user1: 368708 bytes. Shouldn't it be user2? Could this have to do with the problems I'm having?

I double checked and I think that I configured the Makefile correctly:

#You can build this example in three ways:
# 'separate' - Separate espfs and binaries, no OTA upgrade
# 'combined' - Combined firmware blob, no OTA upgrade
# 'ota' - Combined firmware blob with OTA upgrades.
#Please do a 'make clean' after changing this.
#OUTPUT_TYPE=separate
#OUTPUT_TYPE=combined
OUTPUT_TYPE=ota

#SPI flash size, in K
ESP_SPI_FLASH_SIZE_K=4096
#0: QIO, 1: QOUT, 2: DIO, 3: DOUT
ESP_FLASH_MODE=0
#0: 40MHz, 1: 26MHz, 2: 20MHz, 15: 80MHz
ESP_FLASH_FREQ_DIV=0
mroavi commented 8 years ago

Here is the log after doing the OTA firmware update:

Conn req from  192.168.1.101:48203, using pool slot 0
URL = /flash/upload
Mallocced buffer for 1024 + 1 bytes of post data.
Is url index 0
Is url index 6
Firmware upload cgi start.
Flashing user2.bin from ota image
Upload done. Sending response.
Pool slot 0 is done. Cleaning up for next req
URL = /flash/reboot                                                    
Is url index 0                                                         
Is url index 7                                                         
Pool slot 0 is done. Cleaning up for next req                          
reboot to use2
state: 5 -> 0 (0)
rm 0
del if0
bcn 0
del if1
usl

 ets Jan  8 2013,rst cause:2, boot mode:(1,7)

 ets Jan  8 2013,rst cause:4, boot mode:(1,7)

wdt reset

Afterwards the browser just hangs trying to load a webpage that it can't find:

image

mroavi commented 8 years ago

I actually noticed that I missed an important part in the log fragment that I posted previously, which is:

2nd boot version : 1.5                                                    
  SPI Speed      : 40MHz                                                  
  SPI Mode       : QIO                                                    
  SPI Flash Size & Map: 32Mbit(512KB+512KB)                               
jump to run user2 @ 81000      

error magic!                                                              
first boot failed, reboot to try backup bin 

Could you explain to me what 'magic' means in this context?

mroavi commented 8 years ago

I managed to find what the problem was and also realized that I should have not raised this issue here but rather in https://github.com/Spritetm/esphttpd.

The problem is an incorrect assignment of the start address of user2.bin.

.fw2Pos=((OTA_FLASH_SIZE_K*1024)/2)+0x1000,

When OTA_FLASH_SIZE_K is equal to 4096, the address that is assigned is 0x201000 while it should actually be 0x81000. After hardcoding 0x81000 to .fw2Pos OTA firmware updating started working.