tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.18k stars 889 forks source link

"Over The Air" updates for Pico-w #4341

Open nickaxgit opened 1 month ago

nickaxgit commented 1 month ago

Hi Chaps

With some direction from Patricio, I have implemented the UDP stack in seqs.. I can now pull binary files with a naïve, "reliable" protocol on top. (Yes, I know I could have done that with TCP !). I made it for camera images, but the next challenge is to be able to update the running program - I'm not sure I need anything as complex as a bootloader - if I can get a new .ELF (or UF2) file onto the Pico, and invoke machine.CPUReset() ... ?? I also just discovered machine.BlockDevice

I'm sure this is not as straightforward as I am hoping, but I'd welcome any pointers.

Is self-updating for TinyGo apps already elsewhere on the radar ? My needs are simple, it doesn't need to be totally robust or secure, bricking a Pico would just mean a short drive - but I could perhaps explore a Proof of Concept that might develop into something more universally useful.

nickaxgit commented 1 month ago

Notes to self (just gathering potentially helpful stuff) https://kevinboone.me/pico_run_ram2.html

https://forums.raspberrypi.com/viewtopic.php?t=322858

This is starting to look very non-trivial

Wondering about using a mem-copy, or possibly DMA to (re)place the running image (unpacked from a UF2/elf file).. https://github.com/raspberrypi/pico-examples/blob/master/dma/hello_dma/hello_dma.c

A watchdog timer could be set, prior to the copy to reboot the device when it (inevitably) crashes (but hopefully by the the copy would have completed)

https://www.raspberrypi.com/documentation/pico-sdk/hardware.html#flash_example

https://kevinboone.me/picoflash.html

b0ch3nski commented 1 month ago

ESPhome has a support for both OTA updates and RP2040 - you could take a look how they are doing it:

  1. https://esphome.io/components/ota
  2. https://esphome.io/components/safe_mode
  3. https://esphome.io/components/rp2040

IMO for a reliable solution, this would require some sort of bootloader and A/B partitions switchover :thinking:

nickaxgit commented 1 month ago

Thanks… will check it. There are a few C solutions out there, some look very robust.. I was looking at something much simpler with a smaller footprint, thinking there might be a way to live very dangerously and overwrite the program that is executing in a single memcopy, rebooting with a watchdog timer.

Perhaps it’s better to forget such a terrible idea and put the effort into something more robust and resilient, it would be nice if it was all GO though.

On Wed, 17 Jul 2024 at 14:03, Piotr Bocheński @.***> wrote:

ESPhome has a support for both OTA updates and RP2040 - you could take a look how they are doing it:

  1. https://esphome.io/components/ota
  2. https://esphome.io/components/safe_mode
  3. https://esphome.io/components/rp2040

IMO for a reliable solution, this would require some sort of bootloader and A/B partitions switchover 🤔

— Reply to this email directly, view it on GitHub https://github.com/tinygo-org/tinygo/issues/4341#issuecomment-2233272897, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALR2VA342PTV4RTAWSMBX4DZMZTSTAVCNFSM6AAAAABK677XBKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZTGI3TEOBZG4 . You are receiving this because you authored the thread.Message ID: @.***>