Page 1 of 1

OTA Firmware: Invalid app size

Posted: Sun Apr 12, 2020 9:26 pm
by oserror
I have tried compiling the code both with my own modules in micropython/ports/esp8266/modules and with none of my modules present there. I am able to flash the ESP8266 with the signed firmware-ota.bin.ota file (the second flashing). This is what shows in the terminal when the reset button is pressed:

Code: Select all

boot8266
HW RTC Reset reason: 2
System reset reason: 1
Initial GPIO state: c0030031, OE: 0
RTC user memory: 746f617a 61746f61
Comparator: 746f6179 61746f61
Magic word in RTC memory not detected, continuing normally.
Invalid main app size: 1487058088
Running OTA
The ESP8266 4MB reboots until I unplug it. I thought at first it had to do with a missing main.py in the firmware and I added one to the inisetup.py script, but this does not seem to be the problem.

Any help will be greatly appreciated.

Thanks!

EDIT: Here is the code in boot8266.c in the yaota8266 project that triggers the OTA server over and over:

Code: Select all

bool check_main_app(void)
{
    //_printf("check_main_app\n");
    MD5_CTX ctx;
    MD5Init(&ctx);

    uint32_t off = MAIN_APP_OFFSET;
    uint32_t sz = 0;
    SPIRead(MAIN_APP_OFFSET + 0x8ffc, &sz, sizeof(sz));
    if (sz > 800000) {
        _printf("Invalid main app size: %u\n", sz);
        return false;
    }

Re: OTA Firmware: Invalid app size

Posted: Tue Apr 14, 2020 5:37 am
by jimmo
Having a bit of a hard time following your question sorry... are you saying that everything works fine (including OTA) when you don't add any frozen modules? Or is the issue with OTA more generally?

Re: OTA Firmware: Invalid app size

Posted: Wed Apr 15, 2020 1:49 pm
by oserror
I tried this again with the micropython-1.12.tar.xz file available on the micropython.org website (not the git source code I used before with the v1.12 tag). I tried compiling the firmware with 'make ota', erasing the flash with esptool, loading the initial yaota8266.bin firmware at position 0x0 and the firmware-ota.bin at position 0x3c000, signing the firmware-ota.bin file with the ota_client to firmware-ota.bin.ota, and uploading the firmware-ota.bin.ota file with the ota_client. I did make my own RSA key before signing.

I used the yaota8266 code at https://github.com/jedie/yaota8266. Perhaps this is the problem, but I could not get pfalcon's code to work on its own. @jedie and @schinckel both were active in making his code viable.

Below is the output with just the vanilla micropython-1.12 code base (none of my modules were added and I did not touch a thing, just compiled and tested):

I had to change the networking part of @jedie's code as his broadcast to 255.255.255.255 was not working on my network. I just put in a command-line option to specify the IP of my ESP8266. I left the rest alone, leaving the default values in config.h except for the updated modulus from my RSA key. I'm pretty sure that everything is all right.

Code: Select all

boot8266
HW RTC Reset reason: 2
System reset reason: 1
Initial GPIO state: e0030031, OE: 0
RTC user memory: 746f617a 61746f61
Comparator: 746f6179 61746f61
Magic word in RTC memory not detected, continuing normally.
Invalid main app size: 1487058088
Running OTA
#0 ets_task(0x4020b518, 31, 0x3ffe89d0, 4)
ll��|��{rnc�
            �l����b�
                    #
                     r�ܜ�cB$
After this, the board goes into OTA mode, times out, and repeats, going back into OTA mode.

Re: OTA Firmware: Invalid app size

Posted: Wed Jun 17, 2020 7:11 am
by PiR
Hello I have exctly same problem (on wemos d1 mini):
when I flash with esptool the bootloader and the firmware all works well (boot until python prompt):

Code: Select all

esptool.py --port /dev/ttyUSB1 --baud 115200 erase_flash
esptool.py --port /dev/ttyUSB1 --baud 115200 write_flash --flash_size=detect --verify 0 yaota8266.bin
esptool.py --port /dev/ttyUSB1 --baud 115200 write_flash --flash_size=detect --verify 0x3c000 firmware-ota.bin
But when I sign (the same firmware) and upload it (with cli.py ota) The upload seems ok :

Code: Select all

python3 cli.py sign firmware-ota.bin
python3 cli.py ota firmware-ota.bin.ota
Validate firmware-ota.bin.ota
File is valid, ok.
wait for response...received from: ('192.168.0.42', 8266)
0.1% Sending #2 (126.7 KBytes/s)
1.6% Sending #53 (13.2 KBytes/s)
3.1% Sending #100 (12.5 KBytes/s)
.....
97.9% Sending #3167 (12.3 KBytes/s)
99.6% Sending #3222 (12.4 KBytes/s)
Send OTA end...Done, rexmits: 2
Send 828208 Bytes in 65.8sec (12.3 KBytes/s)
but after the wemos don't boot :

Code: Select all

boot8266
HW RTC Reset reason: 2
System reset reason: 1
Initial GPIO state: e0030001, OE: 0
RTC user memory: 4ad7cd00 3362f3fa
Comparator: 746f6179 61746f61
Magic word in RTC memory not detected, continuing normally.
Invalid main app size: 1712033877
Running OTA

Re: OTA Firmware: Invalid app size

Posted: Wed Jun 17, 2020 10:56 am
by oserror
I was signing the ota firmware before sending it with the yaota8266 client. This was my problem. It seems that the client was signing it for me when it was sending the file to the ESP8266 over the air, so it was being signed twice. Compiling the firmware-ota.bin and just sending that over the air worked. Or at least that's how I remember it working a month ago.

I had to modify the client to get it to work. You can try it yourself if you like at https://github.com/truckershitch/yaota8266

The check for the .ota extension was removed on this version. I also commented out the broadcasting feature because it wasn't working with my setup. It's probably something to do with my router settings but I didn't feel like looking into it. Anyway, you have to enter the IP address of your ESP8266 from the command line now.

I haven't played with this much after I got it to work for me last month as I got busy. Also, the code I was working on got more stable and I haven't had the need to update it as often.

Good luck and let me know if you have any other problems. I'll test it again on a spare ESP8266.

Re: OTA Firmware: Invalid app size

Posted: Wed Jun 17, 2020 1:00 pm
by PiR
Many thanks @oserror : just comment "validate_ota(args.file)" and sent the .bin in place of the .ota works well for me too. :D