Using pinguino IDE on linux as non root.

Started by fffdddooo, January 24, 2014, 09:49:36 PM

Previous topic - Next topic

fffdddooo

When I plug in my pic32 pinguino micro and switch to bootloader mode, it is recognized, but when I try to upload a program I receive this error:


/home/fernando/ProgramasLocales/Pinguino-x.4/linux/p32/bin/ubw32 Error: UBW32 not found (is device attached and in Bootloader mode?)


As root I can use it with no error, so It is a permissions problem.


I have changed UDEV rules in order to let a normal user to use the bootloader. 


andromeda:/etc/udev/rules.d # cat 20-hidbootloader.rules
SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="04d8", ATTR{idProduct}=="003c", SYMLINK+="hidbl-%k", OWNER:="root", GROUP:="users", MODE:="0660"



But it does not work.
I'm using OpenSuse 13.1 x86_64

Any help?

regards

JohnS

I think it must be either the udev rule that's not right or non-root is not in the right group(s).

I'm on LInux Mint (Debian) and have a different rule:
ATTR{idVendor}=="04d8", ATTR{idProduct}=="003c", MODE="0660",GROUP="plugdev"

And I'm in group plugdev

You need to login again for a change of groups to take effect.

John

fffdddooo

I've changed the configuration of udev rules:


andromeda:/etc/udev/rules.d # cat 80-microchip.rules
# Pinguino32 (PIC32MX)
ATTR{idVendor}=="04d8", ATTR{idProduct}=="003c", MODE="0660",GROUP="users", SYMLINK+="hidbl-%k"

andromeda:/etc/udev/rules.d # ls -l /dev/hidb*
lrwxrwxrwx 1 root root 15 ene 25 10:05 /dev/hidbl-1-1.4.2 -> bus/usb/001/011
andromeda:/etc/udev/rules.d # ls /dev/bus/usb/001/011 -l
crw-rw-rw- 1 root users 189, 10 ene 25 10:05 /dev/bus/usb/001/011
andromeda:/etc/udev/rules.d #



I'm on the groups users (my system dos not have a plugdev group. Still not working.  I've made a symlink /dev/hdblxx  and it has the right permission, but  I'm not sure which device is using pinguino-IDE.  Maybe it is looking for another device?


JohnS

#3
I don't think it looks for a device as such but rather will find it by enumeration (haven't checked the code for a while - have a look yourself if interested).

Maybe try mode 0666 and at least that may help figure it out?

They used to use a separate executable (a variant of mphidflash) to do the actual programming.  If you try it that way you might get an error message pointing towards the problem (a .so not in the users path or whatever).  mphidflash needs libusb and libhid I think.

John

fffdddooo

I've tried mode 666 and It didn't work either.

I have been searching where does pinguino IDE search for the device, but I cant see it clear

There are some pieces of the python code that looks like it is near there:

pinguino.py
class MyApp(wx.App):
    def __init__(self):
        if "--dev" in sys.argv and sys.argv[sys.argv.index("--dev") + 1].lower() == "true":
            wx.App.__init__(self)
        else:
            wx.App.__init__(self, redirect=True, filename="pinguinoPanic")


What is self?


wxgui/pinguino.py
    def setOSvariables(self):
        """Get OS name and define some OS dependant variable"""
        pa = platform.architecture()
        if pa[0]=='64bit': OSarch="64"
        else: OSarch="32"

        if sys.platform == 'darwin':
            self.osdir = 'macosx'
            self.debug_port = '/dev/tty.usbmodem1912'
            self.c8 = 'sdcc'
            self.u32 = 'mphidflash'
            self.make = 'make'

        elif sys.platform == 'win32':
            self.osdir = 'win32'
            self.debug_port = 15
            self.c8 = 'sdcc.exe'
            self.p8 = 'picpgm.exe'
            self.u32 = 'mphidflash.exe'
            self.make = os.path.join(HOME_DIR, self.osdir, 'p32', 'bin', 'make.exe')

        else:
            self.osdir = 'linux'
            self.debug_port = '/dev/ttyACM0'
            self.c8 = 'sdcc'
            self.p8 = 'picpgm'
            self.u32 = 'ubw32'
            self.make = 'make'



Should be ubw32, but what is ubw32?



I'm trying to use mphidflash, but it didn't work either


fernando@andromeda:~/documentos/instituto/me/micros/software/pinguino/mphidflash-1.3-bin-linux> ./mphidflash
./mphidflash: error while loading shared libraries: libhid.so.0: cannot open shared object file: No such file or directory



I've installed libhidapi1-0.7.0-7.1.x86_64.rpm and libhidapi-devel-0.7.0-7.1.x86_64.rpm   but it keeps reporting the same error.




JohnS

#5
If it's using ubw32 (use "find" to find it under the pinguino directory) and you have 64-bit Linux that may be the problem.

A much newer IDE may have stopped using it and not care 32/64-bit.  I'm not sure.  Install in another place to try it :)

ubw32 is another name for mphidflash (and it has other names) - it's a Linux USB program to talk to the USB PIC32 bootloader.

Try running it as
./ubw32 -h

python is OO (object oriented) so self is the current object.

John

fffdddooo

I've found ubw32, but


andromeda:/home/fernando/ProgramasLocales/Pinguino-x.4/linux/p32/bin # ls
Blink.hex    libhid.so.0.0.0  libmpfr.so.1        mips-elf-ar   mips-elf-cc       mips-elf-elfedit  mips-elf-gcc-4.5.2  mips-elf-ld      mips-elf-objcopy  mips-elf-readelf  mips-elf-strip
libgmp.so.3  libmpc.so.2      libmpfr.so.4        mips-elf-as   mips-elf-c++filt  mips-elf-g++      mips-elf-gccbug     mips-elf-ld.bfd  mips-elf-objdump  mips-elf-size     mphidflash
libhid.so.0  libmpc.so.2.0.0  mips-elf-addr2line  mips-elf-c++  mips-elf-cpp      mips-elf-gcc      mips-elf-gcov       mips-elf-nm      mips-elf-ranlib   mips-elf-strings  ubw32
andromeda:/home/fernando/ProgramasLocales/Pinguino-x.4/linux/p32/bin # ./ubw32 -h
./ubw32: error while loading shared libraries: libhid.so.0: cannot open shared object file: No such file or directory
andromeda:/home/fernando/ProgramasLocales/Pinguino-x.4/linux/p32/bin #

libhid.so.0  is in the same directory.


I've found the code where pinguino IDE is trying to open the device, is located in uploader32.py:


[code]device = getDevice(VENDOR_ID, PRODUCT_ID)
if device == ERR_DEVICE_NOT_FOUND:
print "Pinguino not found"
print "Is your device connected and/or in bootloader mode ?"
sys.exit(0)
else:
print "Pinguino found"

[/code]

where the constants are:

VENDOR_ID = 0x04D8
PRODUCT_ID = 0x003C
.....
ERR_DEVICE_NOT_FOUND = 3




def getDevice(vendor, product):
""" get list of USB devices and search for pinguino """
busses = usb.busses()
for bus in busses:
for device in bus.devices:
if device.idVendor == vendor and device.idProduct == product:
return device
return ERR_DEVICE_NOT_FOUND


and busses() is located in the module usb



class Device(object):
    r"""Device descriptor object"""
    def __init__(self, dev):
        self.deviceClass = dev.bDeviceClass
        self.deviceSubClass = dev.bDeviceSubClass
        self.deviceProtocol = dev.bDeviceProtocol
        self.deviceVersion = dev.bcdDevice
        self.devnum = None
        self.filename = ''
        self.iManufacturer = dev.iManufacturer
        self.iProduct = dev.iProduct
        self.iSerialNumber = dev.iSerialNumber
        self.idProduct = dev.idProduct
        self.idVendor = dev.idVendor
        self.maxPacketSize = dev.bMaxPacketSize0
        self.usbVersion = dev.bcdUSB
        self.configurations = [Configuration(c) for c in dev]
        self.dev = dev

    def open(self):
        r"""Open the device for use.

        Return a DeviceHandle object
        """
        return DeviceHandle(self.dev)

class Bus(object):
    r"""Bus object."""
    def __init__(self):
        self.dirname = ''
        self.localtion = 0
        self.devices = [Device(d) for d in core.find(find_all=True)]

def busses():
    r"""Return a tuple with the usb busses."""
    return (Bus(),)


And I don't understant all the code but I can't explain the reason why it works as root but not as noon root.

Unless the problem is not there........

The program is started from this script
let's see


fernando@andromeda:~/ProgramasLocales/Pinguino-x.4> ./pinguino_start.sh

Pinguino IDE starts, I try to upload a program an it fails


In the log everything seems to be OK

fernando@andromeda:~/ProgramasLocales/Pinguino-x.4> cat pinguino.log
Pinguino started at Sun Jan 26 00:16:00 2014

release:        3.11.6-4-desktop
dist:           SuSE 13.1 x86_64
system:         Linux
win32_ver:                 
processor:      x86_64


check OS and compilers
        System host is GNU/Linux
        8-bit compiler OK.
        32-bit compiler OK.

check Pinguino modules
        wxgui/pinguino.py found
        wxgui/uploader/__init__.py found
        wxgui/uploader/uploader.py found
        wxgui/uploader/uploader8.py found
        wxgui/uploader/uploaderMCC.py found
        wxgui/uploader/uploaderVSC.py found
        wxgui/uploader/autodetect.py found
        wxgui/uploader/uploaderDLN.py found
        wxgui/__init__.py found
        wxgui/_trad.py found
        wxgui/editor/events.py found
        wxgui/editor/preferences.py found
        wxgui/editor/__init__.py found
        wxgui/editor/constants.py found
        wxgui/editor/experimental.py found
        wxgui/editor/editeur.py found
        wxgui/editor/stdout.py found
        wxgui/editor/autocompleter.py found
        wxgui/editor/board_selector.py found
        wxgui/editor/get_config.py found
        wxgui/editor/funtions_help.py found
        wxgui/editor/load_features.py found
        wxgui/editor/dic.py found
        wxgui/editor/frames/__init__.py found
        wxgui/editor/frames/framesX4.py found
        wxgui/editor/frames/gettext.py found
        wxgui/editor/lateral_tool_area/__init__.py found
        wxgui/editor/lateral_tool_area/dock_searchReplace.py found
        wxgui/editor/lateral_tool_area/dock_documents.py found
        wxgui/editor/lateral_tool_area/dock_files.py found
        wxgui/editor/general.py found
        wxgui/boards.py found
        wxgui/argparse.py found
        wxgui/check.py found
        python_lib/usb found
        python_lib/importlib found

check Python version
        Python version is OK (>=2.5)

check Python modules
        wxPython successfully loaded
        PyShutil successfully loaded
        subprocess successfully loaded
        gettext successfully loaded
        locale successfully loaded
        webbrowser successfully loaded
        threading successfully loaded

Everything is OK.
fernando@andromeda:~/ProgramasLocales/Pinguino-x.4>




The script which launches the IDE

fernando@andromeda:~/ProgramasLocales/Pinguino-x.4> cat pinguino_start.sh
#!/bin/sh

# Pinguino start-script for Linux
## ...based on pinguino_lin64.sh (Marcus Fazzi) and arduino's start-script

LOCALPATH="$(dirname -- $(readlink -f -- "${0}") )"
cd $LOCALPATH

# Set LD_LIBRARY_PATH to have our libs take precedence over what may be installed
ARCH=$(arch)
case $ARCH in
    *64 )
    # catch "ia64" (Itanium) and  "x86_64"
         LD_LIBRARY_PATH=/usr/lib32:${LOCALPATH}/linux/p32/bin:/usr/lib:/usr/lib64     
         ;;
    * )
    # i386 and the rest land here.
        LD_LIBRARY_PATH=/usr/lib32:${LOCALPATH}/linux/p32/bin:/usr/lib
        ;;
esac

export LD_LIBRARY_PATH
python ./pinguino.py $@




I'm lost  :-(



fffdddooo

I've found a solution although I don't like it very much:


andromeda:/home/fernando/ProgramasLocales/Pinguino-x.4 # ls -l /dev/bus
total 0
drwxr-xr-x 11 root root 220 ene 25 09:25 usb
andromeda:/home/fernando/ProgramasLocales/Pinguino-x.4 # chgrp -R users /dev/bus/usb
andromeda:/home/fernando/ProgramasLocales/Pinguino-x.4 # chmod -R g+w  /dev/bus/usb
andromeda:/home/fernando/ProgramasLocales/Pinguino-x.4 # ls -l /dev/bus
total 0
drwxrwxr-x 11 root users 220 ene 25 09:25 usb
andromeda:/home/fernando/ProgramasLocales/Pinguino-x.4 #




Now It works as a user in users group.

JohnS

I'm puzzled but am on 32-bit Linux with older IDE that doesn't use that code.

You might try:

LD_LIBRARY_PATH=. ./ubw32 -h

from that directory.

If it runs then I think a change (to ldconfig) may fix it.

John

fffdddooo

Quote from: JohnS on January 26, 2014, 06:46:15 PM
I'm puzzled but am on 32-bit Linux with older IDE that doesn't use that code.

Mee too and today more than yesterday

Quote
You might try:

LD_LIBRARY_PATH=. ./ubw32 -h

from that directory.

If it runs then I think a change (to ldconfig) may fix it.

John

It works. that makes ubw find the libraries but. the permission problem persist and is inexplicable for me.


Before switching the card to bootloader mode

andromeda:/dev/bus/usb/001 # ls -l
total 0
cr--r--r-- 1 root root 189, 0 ene 26 10:46 001
cr--r--r-- 1 root root 189, 1 ene 26 10:46 002
cr--r--r-- 1 root root 189, 3 ene 26 10:46 004
cr--r--r-- 1 root root 189, 5 ene 26 10:46 006
cr--r--r-- 1 root root 189, 6 ene 26 10:46 007



The I switch it to bootloader mode and

andromeda:/dev/bus/usb/001 # ls -l
total 0
cr--r--r-- 1 root root  189,  0 ene 26 10:46 001
cr--r--r-- 1 root root  189,  1 ene 26 10:46 002
cr--r--r-- 1 root root  189,  3 ene 26 10:46 004
cr--r--r-- 1 root root  189,  5 ene 26 10:46 006
cr--r--r-- 1 root root  189,  6 ene 26 10:46 007
crw-rw-rw- 1 root users 189, 14 ene 26 20:35 015


andromeda:/dev/bus/usb/001 # ls -l /dev/hid*
lrwxrwxrwx 1 root root     15 ene 26 20:35 /dev/hidbl-1-1.4.4 -> bus/usb/001/015
crw------- 1 root root 251, 0 ene 26 10:46 /dev/hidraw0
.......



OK that's fine it is just what udev rule should do
andromeda:/etc/udev/rules.d # cat 80-microchip.rules
# Pinguino32 (PIC32MX)
ATTR{idVendor}=="04d8", ATTR{idProduct}=="003c", MODE="0660",GROUP="users", SYMLINK+="hidbl-%k"



So, if I have permissions to write to /dev/bus/usb/001/015  I might write the file to the bootloader, right?

fernando@andromeda:~/ProgramasLocales/Pinguino-x.4/linux/p32/bin> LD_LIBRARY_PATH=. ./ubw32 -w Blink.hex
./ubw32 Error: UBW32 not found (is device attached and in Bootloader mode?)


It does not seems so    :o


Then I try:
andromeda:/dev/bus/usb/001 # chmod a+w 001  an try again.......  same error

until i try
andromeda:/dev/bus/usb/001 # chmod a+w 007

and then
fernando@andromeda:~/ProgramasLocales/Pinguino-x.4/linux/p32/bin> LD_LIBRARY_PATH=. ./ubw32 -w Blink.hex
UBW32 found: 241664 bytes free
Erasing...
Writing hex file 'Blink.hex':...
Verifying:...



Why?   I don't know.  Moreover. I've tried it three times and the device I have to change is not always the same: twice 001, once 007.





JohnS

I'm mystified  sorry.

I suppose you might (as a horrible work-around) try making ubw32 set-uid root.  Marginally better than having to be root.

You might also need some sort of wrapper that sets the LD_LIBRARY_PATH for testing this.

You can run the IDE as
LD_LIBRARY_PATH=(whatever) ./pinguino.py
for testing, too, but I think it's ldconfig or some such to sort this part of the puzzle out.

I wonder if it could be something inside libusb.so / libhid.so that's the problem (er, no idea what and yes I'm guessing).

John

fffdddooo

I have found the solution.....or the problem or whatever....

I've been plugging the device to a usb hub. when I plug it The device appears under /dev/bus/usb/001/xxx ...  Today is /dev/bus/usb/001/037

There are 5 other devices in this directory

before I plug it

fernando@andromeda:~> ls -l /dev/bus/usb/001
total 0
crw-rw-r-- 1 root root 189,  0 ene 28 08:58 001
crw-rw-r-- 1 root root 189, 27 ene 28 21:04 028
crw-rw-r-- 1 root root 189, 28 ene 28 21:04 029
crw-rw-r-- 1 root root 189, 30 ene 28 21:04 031
crw-rw-r-- 1 root root 189, 35 ene 29 00:21 036


After I plug it in and put it in bootoloader mode. I've now deleted my udev rule  but It does work same way because the device is recogniced by udev rule z010_mchp_tools.rules wich should be installed when I intalled MplabX IDE. The difference is that my rule set the device to group users and the microchip rule set the device to group root, but giving write permissions to everybody


fernando@andromeda:~> ls -l /dev/bus/usb/001
total 0
crw-rw-r-- 1 root root 189,  0 ene 28 08:58 001
crw-rw-r-- 1 root root 189, 27 ene 28 21:04 028
crw-rw-r-- 1 root root 189, 28 ene 28 21:04 029
crw-rw-r-- 1 root root 189, 30 ene 28 21:04 031
crw-rw-r-- 1 root root 189, 35 ene 29 00:21 036
crw-rw-rw- 1 root root 189, 36 ene 29 17:36 037

Anyway, I can't write to de device using pinguino IDE or ubw32, but I've discovered that in order to be able to use it as non root I have to have write access to ALL devices under /dev/bus/usb/001.

If I unplug the usb HUB all these devices disappear.

And if I plug it in an other usb (I've done to a usb3 pic-e card) 

andromeda:/home/fernando # ls /dev/bus/usb/003/007 -l
crw-rw-rw- 1 root root 189, 262 ene 29 17:47 /dev/bus/usb/003/007


Then only one device appears in this directory and then I can use the card as non-root.

So it seems as if when I plug it to the hub I need write access to all the ports in the hub  :o


regards


JohnS

Oh.  I don't know what to say but I'm not happy at that.  Something weird is lurking somewhere and I feel it'll bite me or others sooner or later.  Thanks for at least highlighting it.

I'll try my Pinguino on a hub some time but it's got no bootloader at all right now (long story).

John

JohnS

I've tried my Pinguino PIC32 MX220 on a hub and it just worked.

Now even more mystified!

John

fffdddooo

May be some kind of strange behavior of my hub. I will try with other devices although I don't remember having any problem before.