Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Debugging advice in libusb?



I'm working with some people to get an Atmel AVR embedded development tool running on Mac OS X using libusb (it works fine connecting via serial). One of the guys has run the tools (avrdude and avarice) under gdb and gathered some info. I'm hoping someone on this list with more expertise in Mac OS X's usb internals can speculate as to what might be going on. I've copied two email messages below; sorry for the long post. If you look at the end you can see we're getting a timeout (kIOReturnNotResponding).

My guess is that the problems lie in libusb 0.1.11. Thank you in advance for any help!


Begin forwarded message:

From: Ned Konz <email@hidden>
Date: February 27, 2006 5:42:05 PM PST
To: Rick Mann <email@hidden>, Joerg Wunsch <email@hidden>
Cc: email@hidden
Subject: Re: [AVaRICE-user] Problems running latest avarice on Mac OS X 10.4.4



On Feb 27, 2006, at 2:27 PM, Rick Mann wrote:

Joerg, have you had a chance to examine the output below? When I get home I'm going to try again with the latest libusb.

I just built avrdude 5.0 and libusb 0.1.11 (which are the latest available as far as I know in Darwinports), and ran it under gdb.

Here's what I got:

Starting program: /opt/local/var/db/dports/build/ _Users_ned_src_darwinports_dports_cross_avrdude/work/avrdude-5.0/ avrdude -c jtag2fast -P usb -p atmega128
Reading symbols for shared libraries ..........+ done
Reading symbols for shared libraries .. done


Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
usb_bulk_read (dev=0x350a60, ep=130, bytes=0x276b8 "", size=64, timeout=100) at darwin.c:892
892 darwin.c: No such file or directory.
in darwin.c
(gdb) bt
#0 usb_bulk_read (dev=0x350a60, ep=130, bytes=0x276b8 "", size=64, timeout=100) at darwin.c:892#1 0x0001c05c in usbdev_drain ()
#2 0x0000ec6c in jtagmkII_open (pgm=0x180ae00, port=0xbffff42c "usb") at jtagmkII.c:331
#3 0x0001336c in main (argc=7, argv=0x28b80) at main.c:1169
(gdb) list
887 in darwin.c
(gdb) up
#1 0x0001c05c in usbdev_drain ()
(gdb) list
887 in darwin.c
(gdb) up
#2 0x0000ec6c in jtagmkII_open (pgm=0x180ae00, port=0xbffff42c "usb") at jtagmkII.c:331
331 return serial_drain(pgm->fd, display);
(gdb) list
326 }
327
328
329 static int jtagmkII_drain(PROGRAMMER * pgm, int display)
330 {
331 return serial_drain(pgm->fd, display);
332 }
333
334
335 /*
(gdb) up
#3 0x0001336c in main (argc=7, argv=0x28b80) at main.c:1169
1169 rc = pgm->open(pgm, port);
(gdb) list
1164 fprintf(stderr, "%sSetting bit clk period: %.1f\n", progbuf, bitclock);
1165 }
1166 pgm->bitclock = bitclock * 1e-6;
1167 }
1168
1169 rc = pgm->open(pgm, port);
1170 if (rc < 0) {
1171 exitrc = 1;
1172 pgm->ppidata = 0; /* clear all bits at exit */
1173 goto main_exit;
(gdb)



With avarice, this is what I get:

ned$ src/avarice -d --mkII -j usb -v -v localhost:4242
AVaRICE version 2.4, Feb 27 2006 17:30:36

Defaulting JTAG bitrate to 1 MHz. Make sure that the target
frequency is at least 4 MHz or you will likely encounter failures
controlling the target.

Found JTAG ICE, serno: 00A0000033A6
USB bulk read error: usb_bulk_read: An error occured during read (see messages above)
JTAG config starting.
Attempting synchronisation at bitrate 19200


command[0x01, 1]: 01
Broken pipe


in the debugger:

Program received signal SIGPIPE, Broken pipe.
0x90014508 in write ()
(gdb) l
85 jtagCheck(count);
86 else // this shouldn't happen
87 check(count == commandSize + 10, JTAG_CAUSE);
88 }
89
90 /*
91 * Receive one frame, return it in &msg. Received sequence number is
92 * returned in &seqno. Any valid frame will be returned, regardless
93 * whether it matches the expected sequence number, including event
94 * notification frames (seqno == 0xffff).
(gdb) bt
#0 0x90014508 in write ()
#1 0x00006698 in jtag::safewrite (this=0x2600cb0, b=0x2603560, count=11) at jtaggeneric.cc:180
#2 0x00003074 in jtag2::sendFrame (this=0x2600cb0, command=0xbfffeeb8 "\001àCì", commandSize=1) at jtag2io.cc:80
#3 0x00003580 in jtag2::sendJtagCommand (this=0x2600cb0, command=0xbfffeeb8 "\001àCì", commandSize=1, tries=@0x1, msg=@0xbfffeec0, msgsize=@0xbfffeec4, verify=false) at jtag2io.cc:297
#4 0x00003b70 in jtag2::synchroniseAt (this=0x2600cb0, bitrate=19200) at jtag2io.cc:412
#5 0x00003d90 in jtag2::startJtagLink (this=0x2600cb0) at jtag2io.cc:466
#6 0x0000405c in jtag2::initJtagBox (this=0x2600cb0) at jtag2io.cc: 570
#7 0x00009604 in main (argc=1, argv=0x2600ca0) at main.cc:411



I'm wondering if it's time to move avarice/avrdude to the new libusb API, since I suspect most development on it will continue in that branch. On the libusb list, they've been soliciting feedback for the new API, and I suspect it will be congealing soon.

TIA,

Rick



On Feb 4, 2006, at 11:53 AM, Joerg Wunsch wrote:


This must somehow be related to libusb on MacOS X.  Does OS X have a
syscall tracer (like ktrace under BSD)?  Maybe you can find at least
where it hangs, and locate that spot in libusb's source code.


It does, in fact, have ktrace. What a neat program!

Here's the last bit of the trace for avarice:


$ ktrace avarice --mkII -j usb -v
$ kdump -m 24 > trace.txt




1378 avarice CALL write(0x1,0x2505000,0x16)
1378 avarice GIO fd 1 wrote 22 bytes
"JTAG config starting.
"
1378 avarice RET write 22/0x16
1378 avarice CALL fcntl(0x3,0x3,0xb)
1378 avarice RET fcntl 2
1378 avarice CALL fcntl(0x3,0x4,0)
1378 avarice RET fcntl 0
1378 avarice CALL write(0x3,0x2602920,0xb)
1378 avarice GIO fd 3 wrote 11 bytes
"\^[\0\0\^A\0\0\0\^N\^A\M-s\M^W"
1378 avarice RET write 11/0xb
1378 avarice CALL fcntl(0x3,0x4,0x2)
1378 avarice RET fcntl 0
1378 avarice CALL select(0x4,0xbffff2f0,0,0,0xbffff2e8)
1378 avarice RET select -1 errno 4 Interrupted system call
1378 avarice PSIG SIGCHLD caught handler=0x5f04 mask=0x0 code=0x0
1378 avarice CALL wait4(0xffffffff,0xbfffec68,0,0)
1378 avarice RET wait4 1380/0x564
1378 avarice CALL write(0x2,0x47180,0x10)
1378 avarice GIO fd 2 wrote 16 bytes
"USB daemon died
"
1378 avarice RET write 16/0x10
1378 avarice CALL exit(0x1)




And the last bit for avrdude. Interesting to note: avrdude manages to also output "Found JTAGICE mkII, serno: 00A0000033FA" before it hangs, but I don't see that in the trace output. I waited 10 seconds, then typed control-C.


1462 avrdude CALL mmap(0x205000,0x9000,0x5,0x12,0x3,0)
1462 avrdude RET mmap 2117632/0x205000
1462 avrdude CALL mmap(0x20e000,0x1000,0x3,0x12,0x3,0x9000)
1462 avrdude RET mmap 2154496/0x20e000
1462 avrdude CALL mmap(0x20f000,0x8878,0x1,0x12,0x3,0xa000)
1462 avrdude RET mmap 2158592/0x20f000
1462 avrdude CALL close(0x3)
1462 avrdude RET close 0
1462 avrdude CALL open(0x205594,0,0)
1462 avrdude NAMI "/usr/lib/libstdc++.6.dylib"
1462 avrdude RET open 3
1462 avrdude CALL fstat(0x3,0xbfffc070)
1462 avrdude RET fstat 0
1462 avrdude CALL pread(0x3,0xbfffc4d0,0x1000,0)
1462 avrdude GIO fd 3 read 4096 bytes
"\M-J\M-~\M-:\M->\0\0\0\^B\^A\0\0\^R\0\0\0\0\0\0\^P\0\0\^Qr \M-x"
1462 avrdude RET pread 4096/0x1000
1462 avrdude CALL pread(0x3,0xbfffc4d0,0x1000,0x11c000)
1462 avrdude GIO fd 3 read 4096 bytes
"\M-~\M-m\M-z\M-N\0\0\0\^R\0\0\0\0\0\0\0\^F\0\0\0\v\0\0\bX"
1462 avrdude RET pread 4096/0x1000
1462 avrdude CALL shared_region_map_file_np (0x3,0x4,0xbfffb540,0)
1462 avrdude RET shared_region_map_file_np 0
1462 avrdude CALL close(0x3)
1462 avrdude RET close 0
1462 avrdude CALL write(0x2,0xbfffe520,0x40)
1462 avrdude GIO fd 2 wrote 64 bytes
"avrdude: usbdev_open(): "
1462 avrdude RET write 64/0x40
1462 avrdude PSIG SIGINT SIG_DFL




More on debugging avarice/libusb: I found a usb debug flag and turned it way up... this is what I got:

usb_os_open: 03eb:2103
usb_control_msg: 128 6 768 0 0xbfffeb58 255 1000
usb_control_msg: 128 6 771 1033 0xbfffeb58 255 1000
usb_set_configuration: called for config 1
usb_claim_interface: called for interface 0
Interface 0 of device is 0x00001057
claim_interface: Interface 0 of device from QueryInterface is 0x2603d40
libusb/darwin.c get_endpoints: building table of endpoints.
get_endpoints: Pipe 1: DIR: 1 number: 2
get_endpoints: Pipe 2: DIR: 0 number: 2
libusb/darwin.c get_endpoints: complete.
JTAG config starting.
libusb/darwin.c ep_to_pipeRef: Converting ep address to pipeRef.
libusb/darwin.c usb_bulk_transfer: Transfering 11 bytes of data on endpoint 0x02
USB error: usb_bulk_transfer (w/ Timeout): no connection to an IOService
USB error: usb_bulk_write: An error occured during write (see messages above)
USB bulk write error: usb_bulk_write: An error occured during write (see messages above)
USB daemon died



And looking at it a bit further by debugging the test programs that come with libusb (which are also failing), I see that we're getting a kIOReturnNotResponding (0xe00002ed) error on the DeviceRequestTO, apparently a timeout:


usb_os_open: 05ac:8005
usb_os_open(USBDeviceOpenSeize): another process has device opened for exclusive access
usb_control_msg: 128 6 768 0 0xbfffeeb8 256 1000
USB error: usb_control_msg(DeviceRequestTO): unknown error <0xe00002ed><-536870163>
usb_control_msg: 128 6 768 0 0xbfffeeb8 256 1000
USB error: usb_control_msg(DeviceRequestTO): unknown error <0xe00002ed><-536870163>
Bus error



-- Rick


_______________________________________________ Do not post admin requests to the list. They will be ignored. Usb mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/usb/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.