Skip to content

Instantly share code, notes, and snippets.

@SavageCore
Last active June 16, 2023 01:45
Show Gist options
  • Save SavageCore/697c5973e2d84c481201d623ca85b0b9 to your computer and use it in GitHub Desktop.
Save SavageCore/697c5973e2d84c481201d623ca85b0b9 to your computer and use it in GitHub Desktop.
ACTION=="add", KERNEL=="sda", SUBSYSTEM=="block", ATTRS{vendor}=="RPI ", ATTRS{model}=="RP2 ", RUN+="/home/pi/gp2040-flasher/flash.sh"

Automated RP2040 flasher for GP2040-CE project

Very quick and hacky

More fully featured version in Python for PiTFT just released! 🎉 https://github.com/SavageCore/GP2040-Flasher-Pi/

Still planning to rewrite as a multiplatform app. 🏗️

Picotool and Linux are required.

Brief how-to:

  1. Place 99-rp2040-flash.rules in /etc/udev/rules.d and run sudo udevadm control --reload
  2. Create directory for script and firmwares mkdir -p /home/pi/gp2040-flasher/firmware
  3. Place flash.sh in /home/pi/gp2040-flasher/ and make it executable chmod +x /home/pi/gp2040-flasher/flash.sh
  4. Add flash_nuke.uf2 and GP2040-CE_0.7.2_RP2040AdvancedBreakoutBoard.uf2 to /home/pi/gp2040-flasher/firmware
  5. Insert a Pico whilst holding BOOTSEL
  6. Watch the log for output tail -f /home/pi/gp2040-flasher/debug.log
#!/bin/bash
# This script flashes the Raspberry Pi Pico board with a specified UF2 file
# It assumes that 2 UF2 files are in the same directory as this script
# - flash_nuke.uf2
# - *.uf2
#
# The script will flash the flash_nuke.uf2 file first to erase the board
# Then it will flash with the latest UF2 file
script_dir="/home/pi/gp2040-flasher"
firmware_dir="$script_dir/firmware"
log_file="$script_dir/debug.log"
# TODO: Choose this file somehow
firmware_file="GP2040-CE_0.7.2_RP2040AdvancedBreakoutBoard.uf2"
firmware_path="$firmware_dir/$firmware_file"
nuke_file="flash_nuke.uf2"
nuke_path="$firmware_dir/$nuke_file"
echo "Detected Pico" >>$log_file
printf "\n"
picotool_info=$(picotool info 2>&1)
if [[ $picotool_info == *"none"* ]]; then
echo "Pico is not loaded with firmware" >>$log_file
printf "\n"
echo "Flashing $firmware_file" >>$log_file
printf "\n"
picotool load -v -x $firmware_path
echo "Flashing complete 🎮" >>$log_file
printf "\n"
printf "\n"
# DEBUG: Wait for device to remount in a bad way
sleep 5
# Print lsusb to confirm the board is mounted
lsusb >>$log_file
else
echo "Pico is loaded with firmware" >>$log_file
printf "\n"
echo "Flashing $nuke_file" >>$log_file
printf "\n"
picotool load -v -x $nuke_path
echo "Flashing complete 💣 waiting for device to remount..." >>$log_file
printf "\n"
printf "\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment