# SDHC card issues. [SOLVED] (Unrelated to Gentoo)

## nms

I recently bought myself a Panasonic HDC-SD9 digital FullHD video camera with a Transcend 8GB class6 SDHC card. Using the USB cable supplied with the camera I connected it to an EHCI (VIA chipset) port on my motherboard. When powered on, the camera then detects the USB connection and asks whether to use "PC CONNECT" mode or PictBridge. I select "PC CONNECT", wait a few seconds and then check 'dmesg' on the host system:

```
usb 1-1: new high speed USB device using ehci_hcd and address 28

usb 1-1: configuration #1 chosen from 1 choice

scsi14 : SCSI emulation for USB Mass Storage devices

usb-storage: device found at 28

usb-storage: waiting for device to settle before scanning

scsi 14:0:0:0: Direct-Access     MATSHITA HDC-SD9/SD       1.1W PQ: 0 ANSI: 4

sd 14:0:0:0: [sda] 15660032 512-byte hardware sectors (8018 MB)

sd 14:0:0:0: [sda] Write Protect is on

sd 14:0:0:0: [sda] Mode Sense: 2c 00 80 08

sd 14:0:0:0: [sda] Assuming drive cache: write through

sd 14:0:0:0: [sda] 15660032 512-byte hardware sectors (8018 MB)

sd 14:0:0:0: [sda] Write Protect is on

sd 14:0:0:0: [sda] Mode Sense: 2c 00 80 08

sd 14:0:0:0: [sda] Assuming drive cache: write through

 sda: sda1

sd 14:0:0:0: [sda] Attached SCSI removable disk

sd 14:0:0:0: Attached scsi generic sg0 type 0

usb-storage: device scan complete
```

Since that looks all right, I mount the filesystem. The camera for some reason sets the card as read-only for the USB host, which is fine by me since the camera doesn't take long to format the card when asked to. I have a nice line in fstab to allow for my user to mount it with the correct permissions set, as I'm no fan of automounters. This is what 'mount' says about the device:

```
/dev/sda1 on /mnt/usb type vfat (ro,noexec,nosuid,nodev,uid=1000,gid=100,user=martin)
```

Using 'ls' I check the video files I have saved on the card:

```
martin@nerzhul /data/video $ ls -l /mnt/usb/private/avchd/bdmv/stream/

totalt 2417344

-rwxr-xr-x 1 martin users  30130176  5 sep 22.42 00000.mts

-rwxr-xr-x 1 martin users  18284544  5 sep 22.42 00001.mts

-rwxr-xr-x 1 martin users   6279168  5 sep 22.43 00002.mts

-rwxr-xr-x 1 martin users  58257408  5 sep 22.45 00003.mts

-rwxr-xr-x 1 martin users 115789824  5 sep 22.55 00004.mts

-rwxr-xr-x 1 martin users 129994752  5 sep 23.10 00005.mts

-rwxr-xr-x 1 martin users  60241920  5 sep 23.23 00006.mts

-rwxr-xr-x 1 martin users 105535488  5 sep 23.26 00007.mts

-rwxr-xr-x 1 martin users  14757888  5 sep 23.26 00008.mts

-rwxr-xr-x 1 martin users  80228352  5 sep 23.32 00009.mts

-rwxr-xr-x 1 martin users 392079360  5 sep 23.40 00010.mts

-rwxr-xr-x 1 martin users 106156032  5 sep 23.42 00011.mts

-rwxr-xr-x 1 martin users 309387264  6 sep 00.06 00012.mts

-rwxr-xr-x 1 martin users 261881856  6 sep 00.10 00013.mts

-rwxr-xr-x 1 martin users 214456320  6 sep 00.20 00014.mts

-rwxr-xr-x 1 martin users 126978048  6 sep 00.31 00015.mts

-rwxr-xr-x 1 martin users  52254720  6 sep 01.42 00016.mts

-rwxr-xr-x 1 martin users 392429568  6 sep 01.50 00017.mts

martin@nerzhul /data/video $
```

Now I want to copy all these files to the hard disk of my workstation, but I'll do just one for clarity. This is what happens:

```
martin@nerzhul /data/video/080906 $ cp -v /mnt/usb/private/avchd/bdmv/stream/00000.mts .

"/mnt/usb/private/avchd/bdmv/stream/00000.mts" -> "./00000.mts"

cp: reading `/mnt/usb/private/avchd/bdmv/stream/00000.mts': Input/output error
```

The result:

```
martin@nerzhul /data/video/080906 $ ls -l

totalt 12884

-rwxr-xr-x 1 martin users 13172736  6 sep 19.21 00000.mts

martin@nerzhul /data/video/080906 $ 
```

I now check 'dmesg' again, and the following has been appended since last time I checked (before mounting the memory card):

```
usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

usb 1-1: reset high speed USB device using ehci_hcd and address 28

sd 14:0:0:0: Device offlined - not ready after error recovery

sd 14:0:0:0: [sda] Result: hostbyte=0x05 driverbyte=0x00

end_request: I/O error, dev sda, sector 50304

sd 14:0:0:0: rejecting I/O to offline device

sd 14:0:0:0: rejecting I/O to offline device

sd 14:0:0:0: rejecting I/O to offline device

sd 14:0:0:0: [sda] Result: hostbyte=0x01 driverbyte=0x00

end_request: I/O error, dev sda, sector 50544

sd 14:0:0:0: rejecting I/O to offline device
```

The USB card reader I have does not support SDHC as far as I know (I got it before SDHC was a standard), so the negative results I got from testing the card with that are not really helping. I did however insert the card into the SD slot of my Asus Eee PC 701, which (according to specifications on teh intarwebs) is SDHC compatible.

Original probe of the card reader at boot:

```
scsi 2:0:0:0: Direct-Access     USB2.0   CardReader SD0   0100 PQ: 0 ANSI: 0

sd 2:0:0:0: [sdb] Attached SCSI removable disk

sd 2:0:0:0: Attached scsi generic sg1 type 0

usb-storage: device scan complete
```

With a freshly booted system I insert the SDHC card into the card slot and check the logs. Nothing. No reaction what so ever from the kernel to the introduction of a card to the reader. Oh well, I run 'partx /dev/sdb' which lists the four partition entries as follows:

```
# 1:      8192- 15660031 ( 15651840 sectors,   8013 MB)

# 2:         0-       -1 (        0 sectors,      0 MB)

# 3:         0-       -1 (        0 sectors,      0 MB)

# 4:         0-       -1 (        0 sectors,      0 MB)
```

That looks completely normal, so I run 'partx -a /dev/sdb' to tell the kernel about it:

```
BLKPG: Device or resource busy

error adding partition 1
```

Trying to remove the partitions from the kernel using 'partx -d /dev/sdb' doesn't help either:

```
error deleting partitions 2-15: BLKPG: No such device or address

error deleting partition 16: BLKPG: Invalid argument
```

I try 'partx -l /dev/sdb' anyway and this is the result in the kernel log:

```
sd 2:0:0:0: [sdb] 15660032 512-byte hardware sectors (8018 MB)

sd 2:0:0:0: [sdb] Write Protect is on

sd 2:0:0:0: [sdb] Mode Sense: 03 00 80 00

sd 2:0:0:0: [sdb] Assuming drive cache: write through

sd 2:0:0:0: [sdb] 15660032 512-byte hardware sectors (8018 MB)

sd 2:0:0:0: [sdb] Write Protect is on

sd 2:0:0:0: [sdb] Mode Sense: 03 00 80 00

sd 2:0:0:0: [sdb] Assuming drive cache: write through

 sdb: sdb1

sd 2:0:0:0: [sdb] Result: hostbyte=0x00 driverbyte=0x08

sd 2:0:0:0: [sdb] Sense Key : 0x4 [current] 

sd 2:0:0:0: [sdb] ASC=0x11 ASCQ=0x0

end_request: I/O error, dev sdb, sector 15660024
```

... and 'partx' just hangs there, not even responding to ^C or ^Z. Killing with normal SIGTERM does the trick, but the card reader is locked up until I power off the Eee PC. Subsequent executions of 'partx' can not be killed with SIGTERM or even SIGKILL.

Is there an issue with my SDHC card (which seems to work absolutely fine with the camera, both for recording and for viewing), or is this a problem with my kernel configuration? I will post specific parts of my /proc/config.gz and/or output of specific system tools upon request to avoid causing unneccessary scrolling by posting the whole thing.

If I can't come up with any better ideas I guess I'll install Windows XP on a separate disk just to see if it will do the trick. If it does, Linux should definitely be able to as well.Last edited by nms on Sat Sep 06, 2008 9:43 pm; edited 1 time in total

----------

## nms

Small update.

I found an old installation of Windows XP on a spare disk in my workstation, so I booted that, connected the USB cable to the camera, waited for Windows to detect it and load the appropriate drivers, asked it to show me the files on the device when it wanted to autorun, selected a couple of the files and dragged them to a folder on my desktop. Standard Windows file copy dialog showed up, progress bar churned through and a minute later it was done copying a few hundred MB without a single hickup.

I will try disconnecting and reconnecting and copy a few of the other files to see if there is any change in results, but I suspect that Linux for some reason has a problem with my shiny new camera or its memory card.

----------

## nms

Proceeding to copy another bunch of files the card or the reader in the camera locked up again, just like in Gentoo. The difference being that I got about half of the files copied before it happened, while I have done multiple attempts in Gentoo and only managed to copy about 30MB total.

Guess I'll start by going back to the store and ask for another card and see if that helps.

----------

## nms

I did a couple of other tests and concluded that the problem lies not in Gentoo, the card or the camera - the cause of all this is the USB functionality on my motherboard.

I took the 2GB microSD (non-HC) card from my Samsung phone and put it in my pocket memory card reader, which I connected to my USB 2.0 hub, which in turn is connected to one of the EHCI ports on my motherboard. I proceeded to back up all the images, videos and music from the card while still in Windows XP, and after a couple of minutes the device disappeared, forcing me to disconnect and reconnect the card reader before copying the rest. I then put the microSD card in an SD adapter and inserted it into the camera card slot, formatted the card and started recording stuff. With a few minutes worth of video I hooked the camera back up to the computer and tried to copy the video file, running into the same problem once again.

Final test: I disconnected the USB cable from the workstation and hooked it up to the Eee PC instead. Checking the logs showed that the kernel detected it immediately, assigning the card to /dev/sdc and detecting one partition. I mounted /dev/sdc1 to /mnt/floppy and copied the file four times without as much as a glitch. I disconnected the USB cable from the camera and recorded another couple of clips, now totalling about 450MB. Hooked it back up and copied to Eee PC. No problem.

I guess I need a new workstation.

----------

