su cd /etc/udev/rules.d vi 80-rp2040.upload.rulesI create that file with the following contents:
SUBSYSTEM=="block", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0003", ACTION=="add", SYMLINK+="rp2040upl%n" SUBSYSTEM=="block", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0003", ACTION=="add", RUN+="/usr/local/bin/rp2040_upload.sh"
Now, decide on a name for a mount folder. I like the idea /pico (why not?) so:
su mkdir /pico
Now I am thinking on my feet. I will (as user tom) do this:
cd mkdir pico
So the directory /home/tom/pico will be the place for the script we are about to introduce to pick up the ".uf2" file and copy it to the pico.
Create the script:
cd /usr/local/bin vi rp2040_upload.sh chmod a+x rp2040_upload.shThat file will have the following contents.
#!/usr/bin/bash MOUNT_PATH=/pico UF2_PATH=/home/tom/pico mount /dev/rp2040upl1 $MOUNT_PATH sleep 2 cp $UF2_PATH/*.uf2 $MOUNT_PATHNote:. This all looks lovely, but as you will read below, the mount command is crippled within udev scripts and this won't work. I wonder how the fellow who posted this nice idea managed to get it to work? He posted in April of 2022. Maybe he is working on a nice linux system without the nasty systemd.
Finally, tell the linux system to reload the udev rules.
su udevadm control --reload
install: rm -f /home/tom/pico/*.uf2 cp xyz.uf2 /home/tom/picoThen what I do is to type "make install", then do the two button game on the pico itself.
(udev-worker)[10145]: sdd: Process '/usr/local/bin/rp2040_upload.sh' failed with exit code 1.Amazingly enough, I see this:
[root@trona tom]# ls -l /dev/rp* lrwxrwxrwx 1 root root 3 Aug 17 15:52 /dev/rp2040upl -> sdd lrwxrwxrwx 1 root root 4 Aug 17 15:52 /dev/rp2040upl1 -> sdd1And when I run this by hand, it works just fine (and when the mount is done, the icon vanishes from my desktop):
su mount /dev/rp2040upl1 /picoBut the script failed to do the mount. I add some logging to the script and find that mount is giving the error:
mount /dev/rp2040upl1 /pico mount: /pico: permission denied. dmesg(1) may have more information after failed mount system call.I find this absolutely baffling. I check and selinux is disabled. I can copy and paste the mount command into a window and the mount works. There is no interesting or useful information in dmesg output.
One possibility is using "systemd-mount" which operates in some weird way in this world of mirrors and confusion. It is supposed to mount things in /run/media. I experimented with it and found it to be erratic -- and when the mount succeeded it would be /run/media/system/RPI-RP2, but restricted to root.
Note that the default situation with fedora is that it knows it should mount the device as /run/media/tom/RPI-RP2, but doesn't do it until you click on the icon. And then it brings up this filemanager I hate and don't want. If I could persuade it to go ahead with the mount and skip the filemanager, this would be a workable situation.
People call this idiotic business a systemd "feature". Ha ha -- the joke is on us. But they say there is a way to bypass all of this
The game is to set up an override file for "systemd-udevd". You can do this:su systemctl edit systemd-udevdHeaven only knows that editor this launches. The file seems to be:
/usr/lib/systemd/system/systemd-udevd.serviceI used vim to edit this and added the following (there already was a "Service" section, so I just added the MountFlags line
[Service] MountFlags=sharedAfter this, do:
systemctl daemon-reload #service systemd-udevd --full-restart service systemd-udevd restart(I tried the --full-restart, but my version of "service" would not take it.)
After this, I still get the permission denied error, so very nice, but no cigar.
What can we do to achieve our end purpose. One idea is to write a script that watches the /dev directory and when it sees /dev/rp2040upl appear, it would mount and copy the file to it. There would be permission issues to solve.
Another idea is to find out what part of the udev rules does the current thing that puts up the icon labeled RPI-RP2 and see if it is possible to make changes. Have it mount the device (if it is the Pico) with writeable permissions (as gets done when you click on the icon) and have it not bring up the file manager (Thunar).
Or forget the whole mess and look into Picotool.
Picotool can write directly to the Pico without mounting it! The following udev rule allows this to be done by an ordinary user:
# /etc/udev/rules.d/99-pico.rules # Make an RP2040 in BOOTSEL mode writable by all users, so you can `picotool` # without `sudo`. SUBSYSTEM=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0003", MODE="0666" # Symlink an RP2040 running MicroPython from /dev/pico. # # Then you can `mpr connect $(realpath /dev/pico)`. SUBSYSTEM=="tty", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0005", SYMLINK+="pico"
Tom's electronics pages / [email protected]