Need for root privilege when flashing

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Need for root privilege when flashing

Post by pythoncoder » Tue Nov 29, 2016 10:38 am

Has anyone found a way to avoid this? I tried the following udev rule without success

Code: Select all

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE:="0666", GROUP="adminpete"
Also various tweaks using visudo, but nothing seems to work.
Peter Hinch
Index to my micropython libraries.

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: Need for root privilege when flashing

Post by platforma » Tue Nov 29, 2016 12:38 pm

All the boards I have work without root using udev rules.
I am assuming you are in the adminpete group. The easiest option is to set the GROUP="users". Otherwise everything seems correct.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Need for root privilege when flashing

Post by Roberthh » Tue Nov 29, 2016 5:35 pm

I had to use sudo all the time. Reading now this post gave me the impetus for another try. Adding this line:

Code: Select all

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE:="0666"
made it now work, for whatever reason. My /etc/udev/rules.d/49-pyboard.rules file now looks like:

Code: Select all

# f055:9800, 9801, 9802 MicroPython pyboard
ATTRS{idVendor}=="f055", ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idVendor}=="f055", ENV{MTP_NO_PROBE}="1"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="f055", MODE:="0666"
KERNEL=="ttyACM*", ATTRS{idVendor}=="f055", MODE:="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE:="0666"

# Add lines like the following to create custom named device nodes based on the
# serial number.
# KERNEL=="ttyACM*", ATTRS{idVendor}=="f055", ATTRS{serial}=="385435603432", SYMLINK+="pyboard", MODE:="0666"

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Need for root privilege when flashing

Post by dhylands » Tue Nov 29, 2016 5:36 pm

I have this in my rules:

Code: Select all

# 0483:df11 - STM32F4 Discovery in DFU mode (CN5)
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE:="0666"
The way that I check the permissions is that I do lsusb when the device is in DFU mode:

Code: Select all

940 >lsusb
...
Bus 005 Device 072: ID 0483:df11 STMicroelectronics STM Device in DFU Mode
...
and then do a find command using the 3 digit device number:

Code: Select all

941 >find /dev -name 072 -ls
      696      0 crw-rw-rw-   1 root     root     189, 583 Nov 29 09:44 /dev/bus/usb/005/072
and that's the permissions of the usb node used by libusb.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Need for root privilege when flashing

Post by pythoncoder » Tue Nov 29, 2016 5:56 pm

Thanks! The key was getting rid of the GROUP clause altogether.
Peter Hinch
Index to my micropython libraries.

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: Need for root privilege when flashing

Post by platforma » Wed Nov 30, 2016 10:04 am

pythoncoder wrote:Thanks! The key was getting rid of the GROUP clause altogether.
I'd keep the GROUP="plugdev" or GROUP="users" if I were you. But if you're not OCD like I am, not having one is also fine :)
Glad you got it working!

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: Need for root privilege when flashing

Post by torwag » Wed Nov 30, 2016 1:45 pm

Well, I usually go the other way around....

1. check with
ls -la /dev/tty*
The user and group of the desired usb device.
2. Add yourself to the group by
usermod -a -G <group> <user>
3. reboot (that's one of the very few cases a linux machine needs a reboot, you can do it without (logout and in) but usually on a desktop machine a reboot is the most painless and successful way)
4. check with

Code: Select all

id
that you belong now to the group with access permission to the usb-device.

From here you should be able to access the usb device without root permission.

This method has the benefit that one do not have to maintain a self-written udev-rule in the system, which at a later time might fire back whenever the distro changes stuff, which conflicts with the home-made udev rule. Usually this happens exactly after you forgot about the udev rule and keeps you busy for a few hours debugging your problem which nobody else seems to be able to reproduce. ;)

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Need for root privilege when flashing

Post by dhylands » Wed Nov 30, 2016 5:13 pm

That works when the device creates a /dev/ttyXXX node, but when the device is in DFU mode it doesn't. So tools like dfu-util use libusb to directly open the USB device.

Post Reply