Skip to content

Support for OTA updates #3777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
microdev1 opened this issue Dec 1, 2020 · 8 comments
Closed
2 tasks done

Support for OTA updates #3777

microdev1 opened this issue Dec 1, 2020 · 8 comments
Labels
enhancement espressif applies to multiple Espressif chips supervisor
Milestone

Comments

@microdev1
Copy link
Collaborator

microdev1 commented Dec 1, 2020

The esp32s2 brings WiFi support and with that the possibility to have a mechanism for OTA updates.

There are two domains for OTA update implementation:

  • User Code Update
  • CircuitPython Update

User Code Update

For this my plan is to expose the circuitpy drive as a network drive.

CircuitPython Update

The plan here is to have the user code handle firmware grabbing and for the flashing part I agree with what @tannewt suggests.

add an esp32s2 specific library that can write to the “other” OTA area and then switch to the alternate.

@tannewt tannewt added enhancement espressif applies to multiple Espressif chips supervisor labels Dec 1, 2020
@tannewt tannewt added this to the Long term milestone Dec 1, 2020
@tannewt
Copy link
Member

tannewt commented Dec 1, 2020

#3696 and #3454 could be helpful for user code updates. That way you don't need to overwrite the current, known good file.

@microdev1
Copy link
Collaborator Author

I got the CircuitPython update working. The changes are in my ota-s2 branch.

With the current implementation the user provides buffer to be placed in ota_0/1.

Question:

  • Do we want the ability to update other flash partitions like uf2?
    Note: This could be risky as there is no rollback available for these partitions.

Todo enhancements:

  • Python library to handle firmware grabbing.
  • Ability to flash firmware in continuous/discontinuous chunks.

Test Code:

  • Build artifacts are here.
import ota
import ssl
import time
import wifi
import socketpool
import microcontroller
import adafruit_requests

# Firmware
url = "https://adafruit-circuit-python.s3.amazonaws.com/bin/microdev_micro_s2/en_US/adafruit-circuitpython-microdev_micro_s2-en_US-6.1.0-beta.2.bin"

# Start Address 0x10000 (refer: partitions.csv/makefile)
header = {}
header["Range"] = "bytes=65536-"

# Configure Wifi
for network in wifi.radio.start_scanning_networks():
    print(network, network.ssid, network.rssi, network.channel)

print()

wifi.radio.stop_scanning_networks()
wifi.radio.connect("ssid", "password")

# Setup Requests
pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())

# Log Time
start_time = time.monotonic()

# Get Firmware
response = requests.get(url, headers=header)
print(response.status_code)
print(response._headers)

print()

# Update Firmware
print("Preparing Update")
ota.flash(response.content)
print("Update took:", time.monotonic() - start_time, "sec")

print()

print("done")

# Reset Microcontroller
microcontroller.reset()

@tannewt
Copy link
Member

tannewt commented Dec 7, 2020

* Do we want the ability to update other flash partitions like `uf2`?
  _Note: This could be risky as there is no rollback available for these partitions._

Not now, let's start simple. :-)

@microdev1 microdev1 mentioned this issue Dec 9, 2020
3 tasks
@microdev1
Copy link
Collaborator Author

CircuitPython update is implemented and User Code update can be done by a FTP server implementation in python layer as a library instead of implementing it in the core.

@JamesJian-tech
Copy link

User Code update can be done by a FTP server implementation @microdev1 Any example available ?

@microdev1
Copy link
Collaborator Author

Hi @jamesjian007 There isn't a CircuitPython library to implement FTP server yet... I found a few MicroPython implementations which could be ported to CPY. Try searching for micropython ftp on github. :-)

@ThreepE0
Copy link

Very interested in something like this; Managing the several devices scattered about would be magnitudes easier once this is implemented.

@daniel-alsen
Copy link

Agree, a critical feature for real consumer applications. Please let me know if there is any progress on this. It would be great to be able to download both Circuitpython and user code over HTTPS and flash in smaller chunks, using Dualbank.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement espressif applies to multiple Espressif chips supervisor
Projects
None yet
Development

No branches or pull requests

5 participants