Sunday, November 11, 2007

Setting up permissions for USB ports to use libusb for FreeBSD

During the testing of pk2cmd port for FreeBSD, I found a great resource on setting up permissions for USB ports to use libusb or other programs under Linux/BSD.

There is no udev under FreeBSD. It is called devfs rule. To set up proper usb device persimmion so that I can run pk2cmd without being root, I need to do the following.

1. Create group "usb" and add the user name to it.
[Added on 22-Dec-2007]
[mcuee@localhost /usr/home/mcuee]$ su -
localhost# pw groupadd usb (this may not be necessary for FreeBSD 7.0 Beta)
localhost# pw groupmod usb -M mcuee (your_user_name here, mine is "mcuee")
localhost# pw groupshow usb

2. Edit /etc/devfs.rules to add the following lines.
add path 'ugen*' mode 0660 group usb
add path 'da*s*' mode 0660 group usb
3. Edit /etc/devfs.conf and add following lines: [Confirmed that this
is necessary]
perm usb0 0660
own usb0 root:usb
perm usb1 0660
own usb1 root:usb
4. Edit /etc/rc.conf and add the following lines:
# Set the default devfs ruleset.
5. Activate the changes by running the following command (no reboot required):
localhost# /etc/rc.d/devfs start

6. Testing:
localhost# exit

===[mcuee] ~/Desktop/build/pk2cmd4bsd # ls -la /dev/ugen0*
crw-rw---- 1 root usb 0, 138 Nov 1 22:31 /dev/ugen0
crw-rw---- 1 root usb 0, 120 Nov 1 22:56 /dev/ugen0

[Added on 22-Dec-2007]
===[mcuee] ~/Desktop/build/pk2cmd4bsd # lsusb
Bus /dev/usb1 Device /dev/ugen0: ID 04d8:0033 Microchip Technology, Inc.

===[mcuee] ~/Desktop/build/pk2cmd4bsd # ./pk2cmd -PPIC12F675 -I

Locating USB Microchip PICkit2 (vendor 0x04d8/product 0x0033)
Found USB PICkit as device '/dev/ugen0' on USB bus /dev/usb1
Communication established. PICkit2 firmware version is 2.10.0

Device ID = 0FC3

Operation Succeeded


ltsampros said...


I *think* that at the last part you are running the commands as root (note that little #) which would work in any case.

I try these days to make the same configuration in order to make Creative Nomad Jukebox (an old mp3 usb player with a proprietary protocol ("no umass") here) work/accessible on FreeBSD. I've found that by giving permissions to my user account (either 777 or using your/libusb's instructions), programs that link to libusb/libnjb cannot access the usb device. However, if I run them as root, they work perfect.

Anyway, If I come up with something I'll let you know.


Xiaofan Chen said...

No I am not running it as root. Take note I am using Bash.