OpenJBOD / software

MIT License
24 stars 1 forks source link

Better software update mechanism #9

Open TheGuyDanish opened 3 weeks ago

TheGuyDanish commented 3 weeks ago

At the moment, deploying the software relies on copying over files via USB which isn't really ideal. In an ideal world, we'd have an option to replace the files on the board without using USB, either by uploading a package to it or by having it fetch the newer version from the internet.

Unfortunately, doing this is quite difficult as the Pico has no means of unarchiving, such as tar or zip, but does have the ability to decompress gzip or zlib-compressed files.

TheGuyDanish commented 4 days ago

This has now been partially implemented. The new CI builds the OpenJBOD Software into a MicroPython image that can be flashed (as a uf2 file) onto the RP2040-based board. This removes the step of uploading files to the board manually.

The software is extracted at runtime thanks to a change in the _boot.py file that imports the frozen_openjbod package after mounting the filesystem. The aforementioned package is a freezefs archive of the files required to run the software, it unpacks and overwrites existing flash content (excluding config.json) on every boot. This does slightly complicate development as changes made would be overwritten on reset. This can be worked around though.

While this change simplifies deploying the software package in the first place, it can also be used to introduce remote OTA updates. The frozen_openjbod package is subject to the same hierarchy of precedence as other Python packages. Which is to say, if a frozen_openjbod.py file is placed in the flash root, when the import frozen_openjbod command runs, the file in the flash root is the one to be executed, not the one frozen into the firmware.

This means OTA software updates could be introduced by:

  1. Allowing the user to upload a software package
  2. Resetting the microcontroller
  3. Letting the uploaded package self extract
  4. Mission accomplished!

If a malformed software package is uploaded, at best, it would fail to execute, and at worst, it would require the board to be plugged into USB to reflash a valid package. That said, the freezefs extraction process only overwrites existing files.