Skip to contentSkip to conversation

SD card on the GuruPlug

U-Boot New Ludovic Courtès 2 participants 8 messages Oct 1, 2010 – Oct 13, 2010 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

Hello,

The GuruPlug has an internal ?SD card reader, which it views as a USB device:

--8<---------------cut here---------------start------------->8--- Marvell>> usb start
(Re)start USB...
USB: Register 10011 NbrPorts 1
USB EHCI 1.00
scanning bus for devices... 3 USB Device(s) found
scanning bus for storage devices... Device NOT ready
Request Sense returned 02 3A 00
1 Storage Device(s) found
Marvell>> usb tree

Device Tree:
1 Hub (480 Mb/s, 0mA)
| u-boot EHCI Host Controller
|

  +-2  Hub (480 Mb/s, 100mA)
    |   USB2.0 Hub 
    |
    +-3  Mass Storage (480 Mb/s, 500mA)
          USB Storage 000000009909

--8<---------------cut here---------------end--------------->8---

However, with a ?SD card in, with a valid MS-DOS partition table, it apparently fails to read from it:

--8<---------------cut here---------------start------------->8--- Marvell>> usb part
## Unknown partition table
--8<---------------cut here---------------end--------------->8---

Conversely, ?usb part? works as expected with a USB key or USB disk plugged in.

Does anyone have experience with it? Any idea how I could further debug the problem?

Thanks,
Ludo?.

#1 lore raw

[U-Boot] Troubles accessing a USB mass storage device

Quoted 5 lines · ludo at gnu.org (Ludovic Court?s)

However, with a ?SD card in, with a valid MS-DOS partition table, it apparently fails to read from it:

Marvell>> usb part
## Unknown partition table

Further investigation with all the debugging output enabled shows that it?s the ?test unit ready? command (0x0) that fails:

--8<---------------cut here---------------start------------->8---
COMMAND phase
dir 0 lun 0 cmdlen 12 cmd 0065c1c4 datalen 0 pdata 0065c478
cmd[0] 0x0 cmd[1] 0x0 cmd[2] 0x0 cmd[3] 0x0 cmd[4] 0x0 cmd[5] 0x0 cmd[6] 0x0 cmd[7] 0x0 cmd[8] 0x0 cmd[9] 0x0 cmd[10] 0x0 cmd[11] 0x0
STATUS phase
ptr[0] 0x55 ptr[1] 0x53 ptr[2] 0x42 ptr[3] 0x53 ptr[4] 0x7e ptr[5] 0x0 ptr[6] 0x0 ptr[7] 0x0 ptr[8] 0x0 ptr[9] 0x0 ptr[10] 0x0 ptr[11] 0x0 ptr[12] 0x1
FAILED
COMMAND phase
dir 1 lun 0 cmdlen 12 cmd 0065c1c4 datalen 18 pdata 0065c1d4
cmd[0] 0x3 cmd[1] 0x0 cmd[2] 0x0 cmd[3] 0x0 cmd[4] 0x12 cmd[5] 0x0 cmd[6] 0x0 cmd[7] 0x0 cmd[8] 0x0 cmd[9] 0x0 cmd[10] 0x0 cmd[11] 0x0
DATA phase
pdata[0] 0x70 pdata[1] 0x0 pdata[2] 0x2 pdata[3] 0x0 pdata[4] 0x0 pdata[5] 0x0 pdata[6] 0x0 pdata[7] 0xa pdata[8] 0x0 pdata[9] 0x0 pdata[10] 0x0 pdata[11] 0x0 pdata[12] 0x3a pdata[13] 0x0 pdata[14] 0x0 pdata[15] 0x0 pdata[16] 0x0 pdata[17] 0x0 STATUS phase
ptr[0] 0x55 ptr[1] 0x53 ptr[2] 0x42 ptr[3] 0x53 ptr[4] 0x7f ptr[5] 0x0 ptr[6] 0x0 ptr[7] 0x0 ptr[8] 0x0 ptr[9] 0x0 ptr[10] 0x0 ptr[11] 0x0 ptr[12] 0x0
Request Sense returned 02 3A 00
--8<---------------cut here---------------end--------------->8---

The request sense KCQ can be interpreted as ?Not Ready - Medium Not Present?, according to
<https://secure.wikimedia.org/wikipedia/en/wiki/KCQ>, despite the fact that the SD card is actually in (and Linux can successfully read from it.)

The card reader has USB IDs 05e3:0726 (Genesys Logic).

Any idea how to go further?

Besides, ?usb_request_sense? and ?usb_test_unit_ready? both assume LUN == 0. Could it be a problem?

Thanks,
Ludo?.

#9 lore raw
In reply to a message not in the archive

Hi,

Quoted 2 lines · Prafulla Wadaskar

On guruplug+ if the uSD cards are inserted on both the slots (internal and external) The USB storage does not gets detected.

Yes, I figured out. I?m preparing a patch that adds support for multi-LUN USB mass storage devices.

Thanks,
Ludo?.

#2 lore raw

PATCH 1/1 usb: Add support for multiple-LUN mass storage devices

In reply to Ludovic Courtès

Hi,

Quoted 7 lines · ludo at gnu.org (Ludovic Court?s)

The request sense KCQ can be interpreted as ?Not Ready - Medium Not Present?, according to
<https://secure.wikimedia.org/wikipedia/en/wiki/KCQ>, despite the fact that the SD card is actually in (and Linux can successfully read from it.)

The card reader has USB IDs 05e3:0726 (Genesys Logic).

The problem was that this card reader exposes two SCSI logical units (LUNs), whereas the code in ?usb_storage.c? assumed single-LUN devices (which is typically the case with USB keys and disks.)

The patch below adds support for multiple-LUN devices like this one. Tested on the GuruPlug.

The net effect for the GuruPlug is that it makes it possible to boot a kernel stored on a microSD card, something long overdue [0, 1].

Can you please review and apply?

Thanks,
Ludo?.

[0] http://plugcomputer.org/plugforum/index.php?topic=1642

[1] It really feels like I?m doing GlobalScale?s or Marvell?s job here. It looks like GlobalScale is steadily strengthening its reputation of being incompetent. Keep up the bad work!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-usb-Add-support-for-multiple-LUN-mass-storage-device.patch
Type: text/x-patch
Size: 4166 bytes
Desc: the patch
Url : http://lists.denx.de/pipermail/u-boot/attachments/20101005/96e83f44/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url : http://lists.denx.de/pipermail/u-boot/attachments/20101005/96e83f44/attachment.pgp

#4 lore raw

PATCH 1/1 usb: Add support for multiple-LUN mass storage devices

In reply to a message not in the archive

Hi Prafulla,

Quoted 1 line · Prafulla Wadaskar

This works for guruplug, I can detect filesystems on both the uSD card on guruplug

Great, thanks for testing.

Quoted 2 lines

The patch could not be applied cleanly on latest u-boot, pls redo it and post it to mailing list (Not as attachment)

I posted an updated patch, which applies cleanly on top of commit d6288664743cdd4824cb877ca424619c827c1256 (Tue Oct 5 14:42:32 2010 +0200) of ?master? in the u-boot.git repo.

Quoted 1 line

Please follow patch submission process http://www.denx.de/wiki/U-Boot/Patches

Let me know if there other specific changes that should be made.

Thanks for reviewing,
Ludo?.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url : http://lists.denx.de/pipermail/u-boot/attachments/20101005/aa6e2ef0/attachment.pgp

#5 lore raw

PATCH v2 1/1 usb: Add support for multiple-LUN mass storage devices

In reply to Ludovic Courtès

This patch changes `usb_stor_scan' to scan all the LUNs of each mass storage device. It also fixes the various commands to correctly set the LUN field.

Notably, it allows each LUN of GuruPlug's microSD card reader to be accessed.

---
Changes for v2:
- commit log changed to more closely follow the patch submission rules

 common/usb_storage.c |   39 +++++++++++++++++++++++++++++++++++----
 1 files changed, 35 insertions(+), 4 deletions(-)
common/usb_storage.c +35 -4
index 76949b8..613c4f0 100644
@@ -204,6 +204,22 @@ int usb_stor_info(void)
 	return 1;
 }
 
+static unsigned int usb_get_max_lun(struct us_data *us)
+{
+	int len;
+	unsigned char result;
+	len = usb_control_msg(us->pusb_dev,
+			      usb_rcvctrlpipe(us->pusb_dev, 0),
+			      US_BBB_GET_MAX_LUN,
+			      USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
+			      0, us->ifnum,
+			      &result, sizeof(result),
+			      USB_CNTL_TIMEOUT * 5);
+	USB_STOR_PRINTF("Get Max LUN -> len = %i, result = %i\n",
+			len, (int) result);
+	return (len > 0) ? result : 0;
+}
+
 /*******************************************************************************
  * scan the usb and reports device info
  * to the user if mode = 1
@@ -241,13 +257,22 @@ int usb_stor_scan(int mode)
 			break; /* no more devices avaiable */
 
 		if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) {
-			/* ok, it is a storage devices
-			 * get info and fill it in
+			/* OK, it's a storage device.  Iterate over its LUNs
+			 * and populate `usb_dev_desc'.
 			 */
-			if (usb_stor_get_info(dev, &usb_stor[usb_max_devs],
-						&usb_dev_desc[usb_max_devs]) == 1)
+			int lun, max_lun, start = usb_max_devs;
+
+			max_lun = usb_get_max_lun(&usb_stor[usb_max_devs]);
+			for (lun = 0;
+			     lun <= max_lun && usb_max_devs < USB_MAX_STOR_DEV;
+			     lun++) {
+				usb_dev_desc[usb_max_devs].lun = lun;
+				if (usb_stor_get_info(dev, &usb_stor[start],
+						      &usb_dev_desc[usb_max_devs]) == 1) {
 				usb_max_devs++;
 		}
+			}
+		}
 		/* if storage device */
 		if (usb_max_devs == USB_MAX_STOR_DEV) {
 			printf("max USB Storage Device reached: %d stopping\n",
@@ -882,6 +907,7 @@ static int usb_inquiry(ccb *srb, struct us_data *ss)
 	do {
 		memset(&srb->cmd[0], 0, 12);
 		srb->cmd[0] = SCSI_INQUIRY;
+		srb->cmd[1] = srb->lun << 5;
 		srb->cmd[4] = 36;
 		srb->datalen = 36;
 		srb->cmdlen = 12;
@@ -905,6 +931,7 @@ static int usb_request_sense(ccb *srb, struct us_data *ss)
 	ptr = (char *)srb->pdata;
 	memset(&srb->cmd[0], 0, 12);
 	srb->cmd[0] = SCSI_REQ_SENSE;
+	srb->cmd[1] = srb->lun << 5;
 	srb->cmd[4] = 18;
 	srb->datalen = 18;
 	srb->pdata = &srb->sense_buf[0];
@@ -924,6 +951,7 @@ static int usb_test_unit_ready(ccb *srb, struct us_data *ss)
 	do {
 		memset(&srb->cmd[0], 0, 12);
 		srb->cmd[0] = SCSI_TST_U_RDY;
+		srb->cmd[1] = srb->lun << 5;
 		srb->datalen = 0;
 		srb->cmdlen = 12;
 		if (ss->transport(srb, ss) == USB_STOR_TRANSPORT_GOOD)
@@ -943,6 +971,7 @@ static int usb_read_capacity(ccb *srb, struct us_data *ss)
 	do {
 		memset(&srb->cmd[0], 0, 12);
 		srb->cmd[0] = SCSI_RD_CAPAC;
+		srb->cmd[1] = srb->lun << 5;
 		srb->datalen = 8;
 		srb->cmdlen = 12;
 		if (ss->transport(srb, ss) == USB_STOR_TRANSPORT_GOOD)
@@ -957,6 +986,7 @@ static int usb_read_10(ccb *srb, struct us_data *ss, unsigned long start,
 {
 	memset(&srb->cmd[0], 0, 12);
 	srb->cmd[0] = SCSI_READ10;
+	srb->cmd[1] = srb->lun << 5;
 	srb->cmd[2] = ((unsigned char) (start >> 24)) & 0xff;
 	srb->cmd[3] = ((unsigned char) (start >> 16)) & 0xff;
 	srb->cmd[4] = ((unsigned char) (start >> 8)) & 0xff;
@@ -973,6 +1003,7 @@ static int usb_write_10(ccb *srb, struct us_data *ss, unsigned long start,
 {
 	memset(&srb->cmd[0], 0, 12);
 	srb->cmd[0] = SCSI_WRITE10;
+	srb->cmd[1] = srb->lun << 5;
 	srb->cmd[2] = ((unsigned char) (start >> 24)) & 0xff;
 	srb->cmd[3] = ((unsigned char) (start >> 16)) & 0xff;
 	srb->cmd[4] = ((unsigned char) (start >> 8)) & 0xff;
Signature · 1 line
1.7.0
#6 lore raw

PATCH v2 1/1 usb: Add support for multiple-LUN mass storage devices

This patch changes `usb_stor_scan' to scan all the LUNs of each mass storage device. It also fixes the various commands to correctly set the LUN field.

Notably, it allows each LUN of GuruPlug's microSD card reader to be accessed.

---
Changes for v2:
- commit log changed to more closely follow the patch submission rules

 common/usb_storage.c |   39 +++++++++++++++++++++++++++++++++++----
 1 files changed, 35 insertions(+), 4 deletions(-)
common/usb_storage.c +35 -4
index 76949b8..613c4f0 100644
@@ -204,6 +204,22 @@ int usb_stor_info(void)
 	return 1;
 }
 
+static unsigned int usb_get_max_lun(struct us_data *us)
+{
+	int len;
+	unsigned char result;
+	len = usb_control_msg(us->pusb_dev,
+			      usb_rcvctrlpipe(us->pusb_dev, 0),
+			      US_BBB_GET_MAX_LUN,
+			      USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
+			      0, us->ifnum,
+			      &result, sizeof(result),
+			      USB_CNTL_TIMEOUT * 5);
+	USB_STOR_PRINTF("Get Max LUN -> len = %i, result = %i\n",
+			len, (int) result);
+	return (len > 0) ? result : 0;
+}
+
 /*******************************************************************************
  * scan the usb and reports device info
  * to the user if mode = 1
@@ -241,13 +257,22 @@ int usb_stor_scan(int mode)
 			break; /* no more devices avaiable */
 
 		if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) {
-			/* ok, it is a storage devices
-			 * get info and fill it in
+			/* OK, it's a storage device.  Iterate over its LUNs
+			 * and populate `usb_dev_desc'.
 			 */
-			if (usb_stor_get_info(dev, &usb_stor[usb_max_devs],
-						&usb_dev_desc[usb_max_devs]) == 1)
+			int lun, max_lun, start = usb_max_devs;
+
+			max_lun = usb_get_max_lun(&usb_stor[usb_max_devs]);
+			for (lun = 0;
+			     lun <= max_lun && usb_max_devs < USB_MAX_STOR_DEV;
+			     lun++) {
+				usb_dev_desc[usb_max_devs].lun = lun;
+				if (usb_stor_get_info(dev, &usb_stor[start],
+						      &usb_dev_desc[usb_max_devs]) == 1) {
 				usb_max_devs++;
 		}
+			}
+		}
 		/* if storage device */
 		if (usb_max_devs == USB_MAX_STOR_DEV) {
 			printf("max USB Storage Device reached: %d stopping\n",
@@ -882,6 +907,7 @@ static int usb_inquiry(ccb *srb, struct us_data *ss)
 	do {
 		memset(&srb->cmd[0], 0, 12);
 		srb->cmd[0] = SCSI_INQUIRY;
+		srb->cmd[1] = srb->lun << 5;
 		srb->cmd[4] = 36;
 		srb->datalen = 36;
 		srb->cmdlen = 12;
@@ -905,6 +931,7 @@ static int usb_request_sense(ccb *srb, struct us_data *ss)
 	ptr = (char *)srb->pdata;
 	memset(&srb->cmd[0], 0, 12);
 	srb->cmd[0] = SCSI_REQ_SENSE;
+	srb->cmd[1] = srb->lun << 5;
 	srb->cmd[4] = 18;
 	srb->datalen = 18;
 	srb->pdata = &srb->sense_buf[0];
@@ -924,6 +951,7 @@ static int usb_test_unit_ready(ccb *srb, struct us_data *ss)
 	do {
 		memset(&srb->cmd[0], 0, 12);
 		srb->cmd[0] = SCSI_TST_U_RDY;
+		srb->cmd[1] = srb->lun << 5;
 		srb->datalen = 0;
 		srb->cmdlen = 12;
 		if (ss->transport(srb, ss) == USB_STOR_TRANSPORT_GOOD)
@@ -943,6 +971,7 @@ static int usb_read_capacity(ccb *srb, struct us_data *ss)
 	do {
 		memset(&srb->cmd[0], 0, 12);
 		srb->cmd[0] = SCSI_RD_CAPAC;
+		srb->cmd[1] = srb->lun << 5;
 		srb->datalen = 8;
 		srb->cmdlen = 12;
 		if (ss->transport(srb, ss) == USB_STOR_TRANSPORT_GOOD)
@@ -957,6 +986,7 @@ static int usb_read_10(ccb *srb, struct us_data *ss, unsigned long start,
 {
 	memset(&srb->cmd[0], 0, 12);
 	srb->cmd[0] = SCSI_READ10;
+	srb->cmd[1] = srb->lun << 5;
 	srb->cmd[2] = ((unsigned char) (start >> 24)) & 0xff;
 	srb->cmd[3] = ((unsigned char) (start >> 16)) & 0xff;
 	srb->cmd[4] = ((unsigned char) (start >> 8)) & 0xff;
@@ -973,6 +1003,7 @@ static int usb_write_10(ccb *srb, struct us_data *ss, unsigned long start,
 {
 	memset(&srb->cmd[0], 0, 12);
 	srb->cmd[0] = SCSI_WRITE10;
+	srb->cmd[1] = srb->lun << 5;
 	srb->cmd[2] = ((unsigned char) (start >> 24)) & 0xff;
 	srb->cmd[3] = ((unsigned char) (start >> 16)) & 0xff;
 	srb->cmd[4] = ((unsigned char) (start >> 8)) & 0xff;
Signature · 1 line
1.7.0
#7 lore raw

PATCH v2 1/1 usb: Add support for multiple-LUN mass storage devices

Hi,

2010/10/13 Ludovic Court?s <[email protected]>:

Quoted 9 lines

This patch changes `usb_stor_scan' to scan all the LUNs of each mass storage device. ?It also fixes the various commands to correctly set the LUN field.

Notably, it allows each LUN of GuruPlug's microSD card reader to be accessed.

Quoted 9 lines

---
Changes for v2:
?- commit log changed to more closely follow the patch submission ? ?rules

?common/usb_storage.c | ? 39 +++++++++++++++++++++++++++++++++++---- ?1 files changed, 35 insertions(+), 4 deletions(-)

This patch was already applied to u-boot-usb a few days ago. Thanks.

Kind regards,

Remy