Skip to content

tools/mesptool.py: A minimal ESP32 bootloader protocol implementation. #9677

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
wants to merge 1 commit into from

Conversation

iabdalkader
Copy link
Contributor

@iabdalkader iabdalkader commented Oct 19, 2022

This is a minimal implementation of the ESP32 ROM bootloader protocol, which allows a board running MicroPython to flash a firmware image to an ESP32 chip. This is not a port esptool.py is because a) It's too complex b) It's GPL, and it's not a serial pass-through (from esptool.py <-> mcu <-> ESP32) because it would still require installing esptool first and running the serial pass-through code. Note this is for ESP32 not ESP32_S/C (although it may still work, because it talks to the ROM bootloader not a stub) and while it's mainly for updating the Nina WiFi firmware, I chose to implement it in Python (vs ioctls) because it makes easier to extend and use for other ESP chips if needed. Example usage, updating the Nina WiFi module firmware, copy firmware binary to storage (with mpremote or MSC) and:

import mesptool

# pre-calculated because RP2 doesn't have MD5.
md5sum = b"9a6cf1257769c9f1af08452558e4d60e"
path = "NINA_W102-v1.5.0-Nano-RP2040-Connect.bin"

esp = mesptool()
esp.bootloader()
esp.set_baudrate(921600) # or slower
esp.flash_init()
esp.flash_write(path)
esp.flash_verify(path, md5sum)
esp.reboot()

Fixes #8896

Note: location in tools might not be the best location, probably should be in micropython-lib.

* This tool is mainly for updating Nina WiFi firmware from MicroPython.
@jimmo
Copy link
Member

jimmo commented Oct 19, 2022

Thanks @iabdalkader -- this is of course very useful for the Nina, but in general perhaps this does serve as a good starting point for the occasional request we get for "I want to use MicroPython to install firmware on X". (Another common one is host-mode USB DFU).

Note: location in tools might not be the best location, probably should be in micropython-lib.

Yes, I think so. The tools directory is really for things relating to the micropython build and generally to be run on the host. micropython-lib makes more sense. I think you could plausibly make an argument for putting it in python-ecosys/esptool but perhaps micropython/esp32/esptool ? (Not sure the m prefix is necessary? Maybe we could call it espflash or something that conveys exactly what it does?)

The other reason for putting it in micropython-lib is that we may (?) choose to freeze it into the Nano Connect firmware, but more likely someone will want to install it with mpremote mip install.

@iabdalkader
Copy link
Contributor Author

Transferred to micropython/micropython-lib#555

@iabdalkader iabdalkader deleted the add_mesptool branch October 20, 2022 06:01
tannewt added a commit to tannewt/circuitpython that referenced this pull request Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Arduino RP2 Nano connect: Unexpected OSError (regression)
2 participants