pk2cmd bugfix

118 views
Skip to first unread message

Xiaofan Chen

unread,
Feb 18, 2010, 9:31:00 PM2/18/10
to pickit-devel
I need the following small fix to pk2usb.cpp.

if (d){ //added by Xiaofan on 19-Feb-2010

if (device->descriptor.iSerialNumber > 0)

{

usb_get_string_simple(d, device->descriptor.iSerialNumber,
unitIDSerial, 64);


if (unitIDSerial[0] && (unitIDSerial[0] != 9))

{

strcpy(unitID, unitIDSerial);

unitID[14] = 0; // ensure termination after 14 characters

}

}

} //added by Xiaofan on 19-Feb-2010

If not, pk2cmd will segfaults under Linux when the USB permission is not set
and running pk2cmd as a normal user.

[mcuee@myhost pk2cmdv1.20]$ ./pk2cmd -?V

Executable Version: 1.20.00
Device File Version: 1.55.00
libusb couldn't open USB device /dev/bus/usb/002/009: Permission denied.
libusb requires write access to USB device nodes.
Segmentation fault

[mcuee@myhost pk2cmdv1.20]$ gdb --args ./pk2cmd -D PK2V023200.hex
GNU gdb (GDB) 7.0.1
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/mcuee/Desktop/build/pk2cmd/pk2cmdv1.20/pk2cmd...done.
(gdb) run
Starting program: /home/mcuee/Desktop/build/pk2cmd/pk2cmdv1.20/pk2cmd
-D PK2V023200.hex
[Thread debugging using libthread_db enabled]
libusb couldn't open USB device /dev/bus/usb/002/009: Permission denied.
libusb requires write access to USB device nodes.

Program received signal SIGSEGV, Segmentation fault.
0xb7fbb6f0 in usb_get_string_simple (dev=0x0,
desc_index=<value optimized out>, buf=0xbffff334 "", buflen=64)
at core.c:866
866 r = libusb_get_string_descriptor_ascii(dev->handle, desc_index & 0xff,
Current language: auto
The current source language is "auto; currently c".
(gdb) bt
#0 0xb7fbb6f0 in usb_get_string_simple (dev=0x0,
desc_index=<value optimized out>, buf=0xbffff334 "", buflen=64)
at core.c:866
#1 0x08067fab in usbPickitOpen (unitIndex=0, unitID=0x82edd03 "-")
at pk2usb.cpp:282
#2 0x08067915 in CUsbhidioc::FindTheHID (this=0x82edd03, unitIndex=0)
at pk2usbcommon.cpp:598
#3 0x0805a0f8 in CPICkitFunctions::DetectPICkit2Device (this=0x80794e0,
unitNumber=0, readFWVer=1 '\001') at PICkitFunctions.cpp:2434
#4 0x0804e602 in Ccmd_app::findPICkit2 (this=0x80794e0, unitIndex=0)
at cmd_app.cpp:2179
#5 0x080498aa in Ccmd_app::PK2_CMD_Entry (this=0x80794e0, argc=2,
argv=0x82ede68) at cmd_app.cpp:135
#6 0x080667f3 in main (argc=3, argv=0xbffff6c4) at pk2cmd.cpp:100
(gdb) quit
A debugging session is active.

Inferior 1 [process 9929] will be killed.

Quit anyway? (y or n) y

With the above fix, it is okay. No more segfaults.
[mcuee@myhost pk2cmdv1.20]$ ./pk2cmd -?V

Executable Version: 1.20.00
Device File Version: 1.55.00
libusb couldn't open USB device /dev/bus/usb/002/009: Permission denied.
libusb requires write access to USB device nodes.
OS Firmware Version: PICkit 2 not found


Operation Succeeded
[mcuee@myhost pk2cmdv1.20]$ ./pk2cmd -D PK2V023200.hex
libusb couldn't open USB device /dev/bus/usb/002/009: Permission denied.
libusb requires write access to USB device nodes.
No PICkit 2 found.

[mcuee@myhost pk2cmdv1.20]$ sudo ./pk2cmd -?V
Password:

Executable Version: 1.20.00
Device File Version: 1.55.00
OS Firmware Version: 2.32.00


Operation Succeeded


--
Xiaofan http://mcuee.blogspot.com

Reply all
Reply to author
Forward
0 new messages