Create a single thread for each patch to be added to the repository. Please try to stay on topic.
Mega Man
Posts: 260 Joined: Sat Jun 18, 2005 3:14 am
Contact:
Post
by Mega Man » Mon Aug 03, 2009 8:02 am
I had problems with one of my USB memory sticks, which was not detected. I saw the comment "see flow chart in the usbmassbulk_10.pdf doc (page 15)" in the code and realized that the code is not implemented as the flow chart implies. I fixed this and my USB stick was working. I can't generate a patch with "svn diff", because the files are marked as binary. Could someone fix the problems in SVN?
Code: Select all
--- usb_mass/iop/mass_stor.c 2009-08-02 13:16:57.000000000 +0200
+++ usb_mass/iop/mass_stor.c 2009-08-02 23:48:18.000000000 +0200
@@ -49,6 +49,8 @@
#define MASS_CONNECT_CALLBACK 0x0012
#define MASS_DISCONNECT_CALLBACK 0x0013
+#define CSW_PHASE_ERROR 0x02
+
// Added by Hermes
int getBI32(unsigned char* buf) {
return (buf[3] + (buf[2] <<8) + (buf[1] << 16) + (buf[0] << 24));
@@ -438,13 +440,13 @@ int usb_bulk_status(mass_dev* dev, csw_p
if(ret != USB_RC_OK) {
XPRINTF("Usb: Error sending csw bulk command\n");
DeleteSema(semh);
- return -1;
+ return ret;
}else {
WaitSema(semh);
}
DeleteSema(semh);
XPRINTF("Usb: bulk csw.status: %i\n", csw->status);
- return csw->status;
+ return ret;
}
/* see flow chart in the usbmassbulk_10.pdf doc (page 15) */
@@ -454,26 +456,21 @@ int usb_bulk_manage_status(mass_dev* dev
XPRINTF("...waiting for status 1 ...\n");
ret = usb_bulk_status(dev, &csw, tag); /* Attempt to read CSW from bulk in endpoint */
- if (ret == USB_RC_STALL || ret < 0) { /* STALL bulk in -OR- Bulk error */
+ if ((ret == USB_RC_STALL) || (ret != USB_RC_OK)) { /* STALL bulk in -OR- Bulk error */
usb_bulk_clear_halt(dev, 0); /* clear the stall condition for bulk in */
XPRINTF("...waiting for status 2 ...\n");
ret = usb_bulk_status(dev, &csw, tag); /* Attempt to read CSW from bulk in endpoint */
-
}
/* CSW not valid or stalled or phase error */
- if (csw.signature != 0x53425355 || csw.tag != tag) {
+ if ((ret == USB_RC_STALL) || (ret != USB_RC_OK) /* STALL bulk in -OR- Bulk error */
+ || (csw.status == CSW_PHASE_ERROR) || (csw.signature != 0x53425355) || (csw.tag != tag)) {
XPRINTF("...call reset recovery ...\n");
usb_bulk_reset(dev, 3); /* Perform reset recovery */
- }
- if (ret != 0) {
- XPRINTF("Mass storage device not ready!\n");
- return 1; //device is not ready, need to retry!
- } else {
- return 0; //device is ready to process next CBW
- }
+ }
+ return 0; //device is ready to process next CBW
}
jbit
Site Admin
Posts: 293 Joined: Sat May 28, 2005 3:11 am
Location: København, Danmark
Contact:
Post
by jbit » Mon Aug 03, 2009 8:15 am
Code: Select all
if ((ret == USB_RC_STALL) || (ret != USB_RC_OK)) { /* STALL bulk in -OR- Bulk error */
Lines like this concern me... clean them up and I'll commit it (along with your other patches)
hint: ret!=USB_RC_OK implies ret can equal USB_RC_STALL. I get that you were probably just editing code and that's how it ended up this way, but it's best to avoid code which makes you think "what is the actual intended behaviour"...
Thanks for the patches :)
edit: Fixed mime-type issue in usb_mass, SVN should think they're text files now
Mega Man
Posts: 260 Joined: Sat Jun 18, 2005 3:14 am
Contact:
Post
by Mega Man » Wed Aug 05, 2009 8:18 am
I used this style, because it was written this way in the flow chart (STALL Bulk-In -OR- Bulk error).
The SVN files are text files now, but the files still have DOS line endings when checking out under Linux.
Code: Select all
--- iop/mass_stor.c (Revision 1596)
+++ iop/mass_stor.c (Arbeitskopie)
@@ -49,6 +49,8 @@
#define MASS_CONNECT_CALLBACK 0x0012
#define MASS_DISCONNECT_CALLBACK 0x0013
+#define CSW_PHASE_ERROR 0x02
+
// Added by Hermes
int getBI32(unsigned char* buf) {
return (buf[3] + (buf[2] <<8) + (buf[1] << 16) + (buf[0] << 24));
@@ -438,13 +440,13 @@
if(ret != USB_RC_OK) {
XPRINTF("Usb: Error sending csw bulk command\n");
DeleteSema(semh);
- return -1;
+ return ret;
}else {
WaitSema(semh);
}
DeleteSema(semh);
XPRINTF("Usb: bulk csw.status: %i\n", csw->status);
- return csw->status;
+ return ret;
}
/* see flow chart in the usbmassbulk_10.pdf doc (page 15) */
@@ -454,26 +456,22 @@
XPRINTF("...waiting for status 1 ...\n");
ret = usb_bulk_status(dev, &csw, tag); /* Attempt to read CSW from bulk in endpoint */
- if (ret == USB_RC_STALL || ret < 0) { /* STALL bulk in -OR- Bulk error */
+ if (ret != USB_RC_OK) { /* STALL bulk in -OR- Bulk error */
usb_bulk_clear_halt(dev, 0); /* clear the stall condition for bulk in */
XPRINTF("...waiting for status 2 ...\n");
ret = usb_bulk_status(dev, &csw, tag); /* Attempt to read CSW from bulk in endpoint */
-
}
- /* CSW not valid or stalled or phase error */
- if (csw.signature != 0x53425355 || csw.tag != tag) {
+ /* stalled or bulk error or phase error or CSW not valid */
+ if ((ret != USB_RC_OK)
+ || (csw.status == CSW_PHASE_ERROR) || (csw.signature != 0x53425355) || (csw.tag != tag)) {
XPRINTF("...call reset recovery ...\n");
usb_bulk_reset(dev, 3); /* Perform reset recovery */
- }
- if (ret != 0) {
- XPRINTF("Mass storage device not ready!\n");
- return 1; //device is not ready, need to retry!
- } else {
- return 0; //device is ready to process next CBW
- }
+ }
+ XPRINTF("... proces next CBW ...\n");
+ return 0; //device is ready to process next CBW
}
jimparis
Posts: 1145 Joined: Fri Jun 10, 2005 4:21 am
Location: Boston
Post
by jimparis » Tue Aug 11, 2009 12:40 pm
I added the patch in rev 1598.
The forum damaged whitespace, so I had to apply it by hand, and may have made mistakes -- please check.