# Using Blackberry in USB Storage Mode (random disconnections)

## eno2001

I have my kernel compiled with USB removable storage support and initially all seemed to be going well with USB storage.  I could copy files back and forth, access media files in media players and image viewers, etc...  Obviously the microSD card is in VFAT format since that's what the Blackberry requires.  Within the first few days, however, any time I'd try to access a file, the BlackBerry would "crash" and require that I remove the battery and restart the system before it was usable again.  It would just go into a non-responsive mode.  I'm not one to give up though...

I upgraded to the latest Verizon firmware just about two weeks ago but that didn't appear to fix the problem.  So, I wondered if the microSD card had a problem and went out to by an extra one (possible spare if I needed it).  I did that about a week ago.  I used rsync to copy the data to the new microSD card and then plugged it into the system.  Identical problems.  So I gave it some thought and realized that the problems appear to be when trying to do anything that reads or writes data from or to the microSD card when it's accessed from the BlackBerry.  To further rule out microSD issues, I used the adapter that came with the microSD card and plugged it straight into my laptop.  No problems accessing the data at all.

I also wondered if it might have something to do with length limits on the total length of cable + hub in monitor + cable to the PC.  So I plugged it directly into my PC and still experiences the same problems.  I also tried different cables to no avail.  The issue strictly seems to be accessing the microSD through the BlackBerry in removable storage mode.

So I have now ruled out the microSD card, the USB cables, USB distance limitations and the BlackBerry's firmware as possible causes.  I decided to run a few more tests.  Using the Nautilus file manager to peruse the microSD card can consistently crash the BlackBerry.  I also tried using 'rsync', 'cp' and 'dd' to copy the data from BlackBerry to a test location.  'rsync' fails after a half a minute or less saying that the source device no longer exists.  'cp' does the same.  'dd' works, but the disk image is corrupt and cannot be mounted (using the offset= option for mount to mount the virtual partition).  This morning I tried playing an MP3 directly off of the BlackBerry via the command line player 'mplayer'.  This is the set of errors I got while it was playing and failing miserably:

```
eno2001@perses /media/disk/BlackBerry/music $ mplayer Sensitized.ogg.mp3 

MPlayer dev-SVN-rUNKNOWN-4.1.2 (C) 2000-2007 MPlayer Team

CPU: Intel(R) Pentium(R) 4 CPU 3.40GHz (Family: 15, Model: 4, Stepping: 3)

CPUflags:  MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1

Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2

Playing Sensitized.ogg.mp3.

Audio file file format detected.

Clip info:

 Title: Sensitized.ogg

 Artist: Kylie Minogue

 Album: X

 Year: 

 Comment: 

 Genre: Blues

==========================================================================

Opening audio decoder: [mp3lib] MPEG layer-2, layer-3

AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)

Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)

==========================================================================

[AO OSS] audio_setup: Can't open audio device /dev/dsp: Device or resource busy

AO: [alsa] 44100Hz 2ch s16le (2 bytes per sample)

Video: no video

Starting playback...

Blocktype == 0 and window-switching == 1 not allowed.

Blocktype == 0 and window-switching == 1 not allowed.

big_values too large!

big_values too large!

big_values too large!6.0 (03:56.0)  0.7% 

big_values too large!

mpg123: Can't rewind stream by 1891 bits!

big_values too large!

mpg123: Can't rewind stream by 901 bits!

mpg123: Can't rewind stream by 4 bits!

Note: Illegal Audio-MPEG-Header 0xc3c4c5ff at offset 0x25104.

Note: Trying to resync...

[common.c:489] error: giving up resync - your stream is not nice... perhaps an improved routine could catch up

```

'xine' gave was able to continue, but the playback skipped and was really glitchy.  'mpg123' also did the same thing.  I am beginning to suspect that something about the way that the BlackBerry is used by removable storage may be the problem.  Here's what is in my /var/log/messages after I plug in the BlackBerry and then try to access it from Nautilus:

```

May  5 09:17:16 perses usb 5-1: new full speed USB device using uhci_hcd and address 4

May  5 09:17:16 perses usb 5-1: configuration #1 chosen from 1 choice

May  5 09:17:16 perses scsi20 : SCSI emulation for USB Mass Storage devices

May  5 09:17:16 perses usb-storage: device found at 4

May  5 09:17:16 perses usb-storage: waiting for device to settle before scanning

May  5 09:17:22 perses scsi 20:0:0:0: Direct-Access     RIM      BlackBerry SD    0001 PQ: 0 ANSI: 4 CCS

May  5 09:17:22 perses sd 20:0:0:0: [sdd] 7959552 512-byte hardware sectors (4075 MB)

May  5 09:17:22 perses sd 20:0:0:0: [sdd] Write Protect is off

May  5 09:17:22 perses sd 20:0:0:0: [sdd] Mode Sense: 43 00 00 53

May  5 09:17:22 perses sd 20:0:0:0: [sdd] Assuming drive cache: write through

May  5 09:17:22 perses sd 20:0:0:0: [sdd] 7959552 512-byte hardware sectors (4075 MB)

May  5 09:17:22 perses sd 20:0:0:0: [sdd] Write Protect is off

May  5 09:17:22 perses sd 20:0:0:0: [sdd] Mode Sense: 43 00 00 53

May  5 09:17:22 perses sd 20:0:0:0: [sdd] Assuming drive cache: write through

May  5 09:17:22 perses sdd: sdd1

May  5 09:17:22 perses sd 20:0:0:0: [sdd] Attached SCSI removable disk

May  5 09:17:22 perses sd 20:0:0:0: Attached scsi generic sg3 type 0

May  5 09:17:22 perses usb-storage: device scan complete

May  5 09:17:22 perses hald: mounted /dev/sdd1 on behalf of uid 501

May  5 09:17:42 perses sd 20:0:0:0: [sdd] Sense Key : 0x0 [current] 

May  5 09:17:42 perses sd 20:0:0:0: [sdd] ASC=0x0 ASCQ=0x0

May  5 09:17:53 perses usb 5-1: USB disconnect, address 4

May  5 09:17:53 perses sd 20:0:0:0: [sdd] Result: hostbyte=0x01 driverbyte=0x00

May  5 09:17:53 perses end_request: I/O error, dev sdd, sector 2391600

May  5 09:17:53 perses Buffer I/O error on device sdd1, logical block 1

May  5 09:17:53 perses lost page write due to I/O error on sdd1

May  5 09:17:53 perses Buffer I/O error on device sdd1, logical block 8512

May  5 09:17:53 perses lost page write due to I/O error on sdd1

May  5 09:17:53 perses Buffer I/O error on device sdd1, logical block 8513

May  5 09:17:53 perses lost page write due to I/O error on sdd1

May  5 09:17:53 perses Buffer I/O error on device sdd1, logical block 8514

May  5 09:17:53 perses lost page write due to I/O error on sdd1

May  5 09:17:53 perses hald[6467]: forcibly attempting to lazy unmount /dev/sdd1 as enclosing drive was disconnected

May  5 09:17:53 perses hald: unmounted /dev/sdd1 from '/media/disk' on behalf of uid 0

May  5 09:17:54 perses usb 5-1: new full speed USB device using uhci_hcd and address 5

May  5 09:17:54 perses usb 5-1: configuration #1 chosen from 1 choice

May  5 09:17:54 perses scsi 20:0:0:0: rejecting I/O to dead device

May  5 09:17:54 perses FAT: unable to read inode block for updating (i_pos 136210)

May  5 09:17:54 perses scsi 20:0:0:0: rejecting I/O to dead device

```

Unfortunately, it doesn't look like there's much information in there that's helpful.  The section of note seems to be:

```
May  5 09:17:22 perses hald: mounted /dev/sdd1 on behalf of uid 501

May  5 09:17:42 perses sd 20:0:0:0: [sdd] Sense Key : 0x0 [current] 

May  5 09:17:42 perses sd 20:0:0:0: [sdd] ASC=0x0 ASCQ=0x0

May  5 09:17:53 perses usb 5-1: USB disconnect, address 4
```

The device is mounted on behalf of my Gnome login by gnome-vfs for Nautilus.  I was then able to drill down a few levels into /media/disk/BlackBerry/videos and play back part of one file with no problem.  I tried playing another file and the BlackBerry crashed.  That's when we see the Sense Key message followed by the ASC and disconnect messages.  Ideally, if there was more info here, I'd have an idea what's happening.  I've also proven to myself that it's not the BlackBerry itself because it does not exhibit this problem when plugged into a Windows XP or Vista box and files are copied, played back or viewed.

Because of the error messages from mplayer, as well as the fact that thumbnails in Nautilus for images hosted on the BlackBerry are always broken or incomplete, I think this might be a USB speed issue.  Before I continue along those lines, I also want to post the pertinent parts of my kernel config:

```

# USB support

#

CONFIG_USB_ARCH_HAS_HCD=y

CONFIG_USB_ARCH_HAS_OHCI=y

CONFIG_USB_ARCH_HAS_EHCI=y

CONFIG_USB=y

# Miscellaneous USB options

#

CONFIG_USB_DEVICEFS=y

CONFIG_USB_DEVICE_CLASS=y

# USB Host Controller Drivers

#

CONFIG_USB_EHCI_HCD=y

CONFIG_USB_UHCI_HCD=y

#

# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'

#

#

# may also be needed; see USB_STORAGE Help for more information

#

CONFIG_USB_STORAGE=m

# CONFIG_USB_STORAGE_DEBUG is not set

CONFIG_USB_STORAGE_DATAFAB=y

CONFIG_USB_STORAGE_FREECOM=y

CONFIG_USB_STORAGE_ISD200=y

CONFIG_USB_STORAGE_DPCM=y

CONFIG_USB_STORAGE_USBAT=y

CONFIG_USB_STORAGE_SDDR09=y

CONFIG_USB_STORAGE_SDDR55=y

CONFIG_USB_STORAGE_JUMPSHOT=y

CONFIG_USB_STORAGE_KARMA=y

```

Possibly the first thing I should do is enable USB_STORAGE_DEBUG to get more info in /var/log/messages.  But I was also wondering whether it was possible to force the device to mount at a lower speed?  Personally, I think that might be the problem.  The "full speed" mode might not be playing nicely with the BlackBerry.  Anyone else experiencing any of this?

----------

## marrowhk

Just a quick idea. I'd use the bios settings to disable fast USB rather than the OS. Reboot and go to your bios setup and disable from there, this will tell you if your hunch is right or not.

----------

## eno2001

Great suggestion.  Thanks.   :Very Happy:   Unfortunately my BIOS doesn't have a setting for that.  (HP workstation)  I think, I'll probably have to get to compiling a new kernel with the USB debug option as I'd hinted at earlier if I want to see more detail about what's happening.

 *marrowhk wrote:*   

> Just a quick idea. I'd use the bios settings to disable fast USB rather than the OS. Reboot and go to your bios setup and disable from there, this will tell you if your hunch is right or not.

 

----------

## marrowhk

Wow, no bios control of USB - HP sucks! me thinks.   :Laughing: 

----------

## eno2001

I agree with you on that.  Sadly it's a work provided system, so I have no say (nor a real reason to complain since it's "free").   :Smile: 

 *marrowhk wrote:*   

> Wow, no bios control of USB - HP sucks! me thinks.  

 

----------

