UF2 files are an easy way to load firmware on boards with UF2 bootloaders. Normally the UF2 just contains the firmware. However, on RP2040 boards, the picotool command can be used to produce a UF2 that includes both firmware and the CIRCUITPY filesystem.
Note that picotool is supplied in source format. Pre-built versions are not currently supplied by Raspberry Pi. There are some unofficial builds, but be careful. At least one easily found Windows build does not seem to work properly.
To extract everything in flash storage on your RP2040 board into a UF2, reset the RP2040 into bootloader mode (RPI-RP2 visible) and then do this:
picotool save --all all.uf2
To save into a bin file:
picotool save --all all.bin
On boards with large flash chips, the UF2 file with all of flash will be large, and can take several minutes to load onto the board. You can instead save the .bin file, and inspect it with a hex editor or similar to find the offset of the last piece of interesting data in the file. If you have "nuked" (erased) the flash storage in advance before loading CiruitPython and copying over your files, then unused storage in flash will be all 1's (
Once you know the offset, you can use picotool to extract only a range of what is in flash, to create a smaller file. Extract a range of flash, starting at
0x10000000, and ending at
0x10000000 + the offset. For instance, suppose the offset is
0x2cb600. Use this command:
picotool save --range 0x10000000 0x102cb600 range.uf2