I'm using a raspberry Pi Pico and I'm struggling to find if it's possible to update my script remotely (I cannot use neither SWD or USB). Currently my new firmware (can be .uf2, .bin or .hex file) is stocked in my Pico in the form of an array that I remotely sent, I would like to know if there is any way for me to update the Pico just by rebooting it on the new firmware.
I guess I will have to write my own bootloader but I have no idea where to start and there might be a simplier option (maybe partitionning the flash memory ?).
I'm open to any kind of idea since I don't really know how to start.
Thanks !
UPDATE
Thanks to Jon Durrant answer, I managed to use a custom second stage bootloader and to boot on it but I'm still facing an issue.
On my current setup, I have a connected device that acts as a gateway for my pico. My gateway is connected to the internet and connected to Pico thanks to a CAN bus.
Thanks to this setup, I can upload firmware on the gateway and send it in CAN to the pico. It receives it well and reboots on the new firmware. My issue now is that when it reboots, nothing happens. My pico is dead and I have to flash it again in the classic way (SWD or USB) to make it work again.
And here is my corresponding code :
if(END == 3){
printf("endOK\n");
if(len_msg_frame >= 3) memcpy(msg_to_flash+DATALEN*cnt_loop, data_send, len_msg_frame-eof);
printf("Flash received %d!!!!!\n", cnt_loop);
sleep_ms(10);
watchdog_update();
printf("Commiting...");
pfb_firmware_commit();
printf("Downloading...");
watchdog_update();
pfb_initialize_download_slot();
printf("Downloaded...");
watchdog_update();
int size = (DATALEN*(cnt_loop))/256;
for (int i = 0; i < size; i++){
if(pfb_write_to_flash_aligned_256_bytes(msg_to_flash, i*256, 256)) printf("err writing\n");
}
printf("written %d bytes\n", DATALEN*cnt_loop);
watchdog_update();
int test = 0;
if(test = pfb_firmware_sha256_check(DATALEN*(cnt_loop))) printf("sha256 error %d\n", test);
else printf("Flash written\n");
watchdog_update();
pfb_mark_download_slot_as_valid();
printf("Flash valid\n");
sleep_ms(100);
watchdog_update();
pfb_perform_update();
}
I don't know if there is any link but I disabled any kind of encryption in my CMakeLists.tkt :
set(PFB_WITH_IMAGE_ENCRYPTION OFF)
set(PFB_WITH_SHA256_HASHING OFF)
I also work on a raspberry pi pico instead of a pico W.