ESP8266 Building and flashing OTA firmware

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
rosenrot
Posts: 30
Joined: Mon Dec 12, 2016 9:39 pm

ESP8266 Building and flashing OTA firmware

Post by rosenrot » Wed May 17, 2017 8:54 am

How do I use the yaota8266 script to flash my own ota firmwares?

I can create the firmware via

Code: Select all

make ota
Do I have to flash the initial ota image provided http://micropython.org/download#esp8266 first?
Or just flashing my image via

Code: Select all

make deploy
and afterwards I can use the yaota8266?

Thanks
Last edited by rosenrot on Thu May 18, 2017 6:46 am, edited 1 time in total.

rosenrot
Posts: 30
Joined: Mon Dec 12, 2016 9:39 pm

Re: Building and flashing OTA firmware

Post by rosenrot » Thu May 18, 2017 6:42 am

I tried to

Code: Select all

make deploy
the custom build firmware-ota.bin without a preceding flash_erase. The esp8266 was stuck in a bootloop. I guess I have to erase first?

Why there is no answer yet about how to deploy custom ota firmware? Is it because it is not yet implemented?

fdufnews
Posts: 76
Joined: Mon Jul 25, 2016 11:31 am

Re: Building and flashing OTA firmware

Post by fdufnews » Thu May 18, 2017 6:44 am

Up to now, I have not used it but on the download page it is stated:
"The first time you use this build you need to flash one of the "initial image" images using esptool.py as described above. After that, you can update the firmware over the air using the "OTA update" file in conjunction with the ota-client script from yaota8266. The "OTA update" files are digitally signed and will only work with the provided "initial image" files, and vice versa. (Note: this feature is work-in-progress.)"
so I suppose you shall install the initial image first.

rosenrot
Posts: 30
Joined: Mon Dec 12, 2016 9:39 pm

Re: Building and flashing OTA firmware

Post by rosenrot » Thu May 18, 2017 6:53 am

fdufnews wrote:Up to now, I have not used it but on the download page it is stated:
"The first time you use this build you need to flash one of the "initial image" images using esptool.py as described above. After that, you can update the firmware over the air using the "OTA update" file in conjunction with the ota-client script from yaota8266. The "OTA update" files are digitally signed and will only work with the provided "initial image" files, and vice versa. (Note: this feature is work-in-progress.)"
so I suppose you shall install the initial image first.
Just tried it but I get the following error if I put my own ota file:

Code: Select all

ota_client.py: error: Invalid OTA file signature
There is a 'sign' command for the yaota8266 script but I do not know where to get the
priv.key
from.

fdufnews
Posts: 76
Joined: Mon Jul 25, 2016 11:31 am

Re: ESP8266 Building and flashing OTA firmware

Post by fdufnews » Fri May 19, 2017 7:06 am

On pfalcon github repo it is said "Each datagram is signed with RSA private key. Only someone with a valid private key may produce valid datagrams, information from which ota-server will flash as a user application. (The public key is configured when building ota-server.)".
Look at the comments in the config.h.example file
Maybe you can ask pfalcon the question if you still have problems.

rosenrot
Posts: 30
Joined: Mon Dec 12, 2016 9:39 pm

Re: ESP8266 Building and flashing OTA firmware

Post by rosenrot » Sat May 20, 2017 6:25 am

fdufnews wrote:On pfalcon github repo it is said "Each datagram is signed with RSA private key. Only someone with a valid private key may produce valid datagrams, information from which ota-server will flash as a user application. (The public key is configured when building ota-server.)".
Look at the comments in the config.h.example file
Maybe you can ask pfalcon the question if you still have problems.
I see. But how is the procedure?
1. Flashing my custom build fw.
2. Build ota_server, flash it.
3. Build boot8266, flash it.

Or how to include those from yaota8266 to the custom firmware?

tomm2
Posts: 6
Joined: Thu Mar 23, 2017 4:32 pm

Re: ESP8266 Building and flashing OTA firmware

Post by tomm2 » Sat Jun 10, 2017 11:25 am

Here the procedure for manually building and flashing the OTA version of micropython:
  • build boot8266: cd <projects-dir>/yaota8266/boot8266; make
  • build ota version: cd <projects-dir>/micropython/esp8266; make ota > make-ota.log
  • flash:
    • esptool.py --port your-port erase_flash
    • esptool.py --port your-port --baud 230400 write_flash -fm dio --flash_size=detect 0x0 <projects-dir>/yaota8266/boot8266/boot8266-0x00000.bin
    • esptool.py --port your-port --baud 230400 write_flash -fm dio --flash_size=detect 0x3c000 <projects-dir>/micropython/esp8266/build/firmware-ota.bin
With this procedure, here is what comes out the RS232 port when the ESP boots:
<SDK boot status/info at 74800 baud>
boot8266
HW RTC Reset reason: 1
System reset reason: 1222647575
Initial GPIO state: c0030001, OE: 0
Running app
#0 ets_task(40245c10, 31, 3ffe9020, 4)
<more SDK boot status/info at 74800 baud>
OSError: [Errno 2] ENOENT

MicroPython v1.9-32-g4d2778c9 on 2017-06-10; ESP module with ESP8266
Type "help()" for more information.
>>>
Note that I did not make and flash the yaota ota-server. I believe that would be flashed at 0x8000.
The boot8266 runs the 'app' since the length and MD5 verify OK. If you don't flash the ota image, boot8266 prints the following instead of 'Running app':
Invalid main app size: XXXXXXXX
Running OTA
'make ota' creates the .bin file using 8266_ota.ld instead of the esp8266.ld; the irom0_0_seg is changed in the OTA version.

rosenrot
Posts: 30
Joined: Mon Dec 12, 2016 9:39 pm

Re: ESP8266 Building and flashing OTA firmware

Post by rosenrot » Sat Jun 10, 2017 12:53 pm

tomm2 wrote:Here the procedure for manually building and flashing the OTA version of micropython:
  • build boot8266: cd <projects-dir>/yaota8266/boot8266; make
  • build ota version: cd <projects-dir>/micropython/esp8266; make ota > make-ota.log
  • flash:
    • esptool.py --port your-port erase_flash
    • esptool.py --port your-port --baud 230400 write_flash -fm dio --flash_size=detect 0x0 <projects-dir>/yaota8266/boot8266/boot8266-0x00000.bin
    • esptool.py --port your-port --baud 230400 write_flash -fm dio --flash_size=detect 0x3c000 <projects-dir>/micropython/esp8266/build/firmware-ota.bin
With this procedure, here is what comes out the RS232 port when the ESP boots:
<SDK boot status/info at 74800 baud>
boot8266
HW RTC Reset reason: 1
System reset reason: 1222647575
Initial GPIO state: c0030001, OE: 0
Running app
#0 ets_task(40245c10, 31, 3ffe9020, 4)
<more SDK boot status/info at 74800 baud>
OSError: [Errno 2] ENOENT

MicroPython v1.9-32-g4d2778c9 on 2017-06-10; ESP module with ESP8266
Type "help()" for more information.
>>>
Note that I did not make and flash the yaota ota-server. I believe that would be flashed at 0x8000.
The boot8266 runs the 'app' since the length and MD5 verify OK. If you don't flash the ota image, boot8266 prints the following instead of 'Running app':
Invalid main app size: XXXXXXXX
Running OTA
'make ota' creates the .bin file using 8266_ota.ld instead of the esp8266.ld; the irom0_0_seg is changed in the OTA version.
Thanks a lot! Only one question, if you do not flash the yaota server, what is the gain of flashing the ota image? Can you do the ota somehow without the yaota?

tomm2
Posts: 6
Joined: Thu Mar 23, 2017 4:32 pm

Re: ESP8266 Building and flashing OTA firmware

Post by tomm2 » Sat Jun 10, 2017 5:37 pm

I was going to write a python program that would download firmware versions in chunks from AWS S3; it would flash it to a different address (haven't figure out where yet). I would then modify boot8266 to check for a working version/app in either 0x3c000 or the other location. A mechanism to determine which is the latest version would have to be added to boot8266. Getting OTA versions to work manually was the first step. I'm currently using AWS IOT for ESP state control: https://github.com/manningt/aws-iot-GET-POST-loop, so using AWS S3 for firmware re-uses the authentication process and saves administrating a server.

rosenrot
Posts: 30
Joined: Mon Dec 12, 2016 9:39 pm

Re: ESP8266 Building and flashing OTA firmware

Post by rosenrot » Sat Jun 10, 2017 8:29 pm

Thanks for the description. I'm wondering a little bit that, at least for me, it seems the support in this forum is a little bit slow. I asked the question about the ota a month ago. In the beginning i thought there is a big community behind micropython but it seems rather small.

Post Reply