Tuesday, September 25, 2012

Tracking down USB errors on MacOS 10.6.8

I have been buried in logs.:/
How do you supposed that one figures out what this actually means?
[5] AppleUSBOHCI[0x554c000]::ControlPacketHandler(FN: 0, EP:0): Error: 0xe00002ed, 
    stage: 0x15, todo: 0x40
[3] AppleUSBOHCI[0x554c000]:ControlPacketHandler error 0xe00002ed
    occured on endpoint (0). todo = 0x0 (Clearing stall)
[5] +AppleUSBOHCI[0x554c000]: clearing endpoint 0:0 stall
Well, I found the error codes in IOReturn.h.
#define kIOReturnNotResponding  iokit_common_err(0x2ed) // device not responding
Oh no...

Saturday, September 22, 2012

MacOS USBProber script to clean logs.

MacOS' USBProber is a great tool to debug USB transactions; however, it's just full of information. The logs that it generates just have too much! I created a bash script that I use to remove timestamps and other key words.
Consider the following three entries:
 4733.082 [7] AppleUSBOHCI[0x425d800]::ControlPacketHandler(0:0): still more to come: todo=0x40
 4733.098 [7] IOUSBControllerV3(AppleUSBOHCI)[0x425d800]::RootHubTimerFired - PolicyMaker[0x45be400] powerState[4] _powerStateChangingTo[-1]
 4736.585 [7] IOUSBHIDDriver[0x474a800]::powerChangeDone from state (4) to state (4) _device name(Apple Internal Keyboard / Trackpad)

I wanted to remove anything that had "PolicyMaker" or "Trackpad", along with the timestamp. This resulted in the following script:
#!/bin/sh

#sui's script to clean out MacOS USB prober information
#densui.blogspot.com

#change this list to include more filters
removelist="PolicyMaker Trackpad"

#function that looks for things in the last
function listcontains() {
  line=$2
  a_list=( $1 )
  #echo ${#a_list[@]}
  a_length=${#a_list[@]};
 for (( i = 0; i < $a_length; ++i ))
 do
     a_word=${a_list[$i]}
     if [[ $2 == *"$a_word"* ]]
  then
   return 0
  fi
 done
  return 1
}

#remove the old file if it exists
rm -f $2
# the main loop
cat $1 | while read line; do 
    if listcontains "$removelist" "$line"; 
    then 
     #echo Y;
     HOLDER=1
    else 
     echo ${line#*.*' '} >> $2
     #echo N;
     #echo ""
    fi    
done
Running the script on a file with the lines from the top of the page, I will get a filtered output of:
[7] AppleUSBOHCI[0x425d800]::ControlPacketHandler(0:0): still more to come: todo=0x40
So, no timestamp, no trackpad and no hub information! :)

Saturday, September 15, 2012

NeXTStep

NeXTStep was an amazingly good GUI implementation on top of unix. I still prefer it to MacOS so I use the look/feel when I use BSD. It has even made its way to anime.

Saturday, September 1, 2012

j-link with Mac OS

I was excited to get SAM-ICE up and running on Mac OS so I could use GDB without windows. Before you start though, you should download the latest version of the JLINK software for Windows from SEGGER so that you can update the flash on your JTAG debugger. This was a huge holdup for me because my firmware was older.

I installed the tools into /Applications/JLink.

The SAM-ICE tools require "libusb", so you will need to get this. I used macports, and SEGGER used macports, so I suggest this in case things change in the future. Once you install macports, type:
sudo port install libusb
I ran JLinkGDBServer from the command line, but go this:
suinomakuea:~ suigin$ /Applications/JLink/JLinkGDBServer ; exit;
dyld: Library not loaded: Output/Release/x86_64/JLinkARMDLL/libjlinkarm.4.50.9.dylib
  Referenced from: /Applications/JLink/JLinkGDBServer
  Reason: image not found
Trace/BPT trap
JLinkGDBServer.command is the command that should be run. It would have been better to have named it JLinkGDBServer.sh or something that would be better for people who know the command line. You will still get a library error because you need to copy the libraries to the location specified in the file JLinkGDBServer.command.
sudo cp /Applications/JLink/libjlinkarm.4.* /opt/local/lib/.
And now, when I run ./JLinkGDBServer.command I get a debugger connection!