Deploying Frozen Files in a Micropython UF2 Build in a Production Environment #10464
-
Hello, If anyone has any advice, suggestions, or resources to point me to in regards to this project please let me know 😄 I'm currently working on a companion desktop app to allow for end users of my devices to perform the automated retrieval and flashing of a pre-built UF2 to chipsets that support Micropython such as the RP2040 (for example on a Raspberry Pi Pico) I've experimented with and researched some popular methods of creating custom Micropython builds with frozen files, and it appears that the most robust method of doing so is to:
The commands I've ran in order to do so (currently running in Ubuntu 22.04.1 LTS with all of the appropriate dependencies installed) were: # OR - clone another version
$ git clone https://github.com/micropython/micropython
$ cd micropython/mpy-cross
$ make
$ ..
$ git submodule update --init lib/pico-sdk lib/tinyusb
$ cd ports/rp2
$ make BOARD=PICO submodules
# At which point, from /rp2 I can now run:
$ make
# Which leaves the uf2 of the build (and various other files) in the subfolder ./build-PICO
Does this seem like an appropriate method to generate a UF2 with frozen firmware to flash to boards in a production environment (5000+ devices)? Thank you, |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
If you prefer you can locate your files for freezing elsewhere. For example my build script has
with the contents of
This adds a set of extra modules to those provided by default. The benefits are that the source tree is unmodified and it readily facilitates freezing different sets of modules. |
Beta Was this translation helpful? Give feedback.
-
This is not the case. The way you've described is fragile, relies on internal implementation details (e.g. the modules directory which is for system modules), and modifying the micropython repo. The best way to do this is described here: https://docs.micropython.org/en/latest/reference/manifest.html |
Beta Was this translation helpful? Give feedback.
-
Thank you for the responses and suggestions. I've adjusted the method I use to build a UF2 to instead point to an external folder with a custom manifest file including instructions to freeze the appropriate sub-directories and modules required for the firmware update. Something else that I've been experimenting with is a method of copying other plain-text or similar non-python files to an RP2040 while it is in Device Firmware Update mode. As far as I can tell from the micropython docs it isn't possible, but if anyone knows of a way to either bake-in non-.mpy/.py content into the UF2 or has suggestions for a better way to do so please let me know. Currently, my idea is to append a function to the beginning of the main.py that gets uploaded to the board as frozen firmware and then have it listen for a standard serial connection for a few seconds after the board starts up. If a serial connection is established in this time and the incoming buffer contains a particular 'signature' requesting a file write, then the raw file data is transferred via serial and subsequently written to a file on the board from within this function (which I can then verify with some parity checks). Although, I have a few concerns with this method's reliability, and being able to transfer this content while the board is still in DFU mode would be preferable to minimise the number of steps to transfer all of the updated firmware and config. |
Beta Was this translation helpful? Give feedback.
-
I'm guessing from the second part of your message that you mean your own implementation of a Device Firmware Update functionality -- the term DFU has a fairly specific meaning. Also assuming you don't mean the rp2 .uf2 bootloader. Your approach does sound fairly reasonable. I wonder if it might be easier just to use the mechanism used by pyboard.py (and mpremote) to copy files via scripting the REPL? (In a nutshell, pyboard.py sends Ctrl-C to stop the current program, then scripts the REPL to do file write commands, then triggers a soft reset to resume the program). To your question about putting content into the .uf2 file, there are two main options here:
For both of those two options, my ideal is to extend the manifest system to support both. i.e. adding |
Beta Was this translation helpful? Give feedback.
-
Hello, If someone is reading this, and want to have the first approach done(bundling the application into the uf2 file), please have a look at following project: It basically does exactly that. I have tested it and its working perfect out of the box for a PicoW Board. |
Beta Was this translation helpful? Give feedback.
If you prefer you can locate your files for freezing elsewhere. For example my build script has
with the contents of
rp2_manifest.py
beingThis adds a set of extra modules to those provided by default. The benefits are that the source tree is unmodified and it readily facilitates freezing different sets of modules.