I had some trouble with the usb mass storage driver. I added patches to solve it. Can someone check it into the svn repository. Some files in the svn are marked as binary, so CRLF line terminators are not converted to LF on linux. Can someone fix this also.
I can test it only with one USB stick.
The first patch fixes the mode of ohci. The ohci was not set to operational mode. I don't why this was working with ps2. With normal x86 hardware this is not working.
Code: Select all
diff -ur ps2sdk/iop/usb/usbd/src/hcd.c ps2sdk2/iop/usb/usbd/src/hcd.c
--- ps2sdk/iop/usb/usbd/src/hcd.c 2006-07-21 17:00:55.000000000 +0200
+++ ps2sdk2/iop/usb/usbd/src/hcd.c 2006-07-21 17:34:01.000000000 +0200
@@ -462,7 +462,7 @@
memPool.ohciRegs->HcFmInterval = 0x27782EDF;
memPool.ohciRegs->HcPeriodicStart = 0x2A2F;
memPool.ohciRegs->HcInterruptEnable = OHCI_INT_MIE | OHCI_INT_RHSC | OHCI_INT_UE | OHCI_INT_WDH | OHCI_INT_SO;
- memPool.ohciRegs->HcControl |= OHCI_CTR_USB_OPERATIONAL | OHCI_CTR_PLE | OHCI_CTR_IE | OHCI_CTR_CLE | OHCI_CTR_BLE | 3;
+ memPool.ohciRegs->HcControl = OHCI_CTR_USB_OPERATIONAL | OHCI_CTR_PLE | OHCI_CTR_IE | OHCI_CTR_CLE | OHCI_CTR_BLE | 3;
return 0;
}
- There were some compiling problems.
- Get emulation working with linux (Makefile, missing return values and variables, segmentation fault).
- My USB stick was not initialized correctly and was only working when reseting iop without reseting my USB stick. This has been fixed.
Code: Select all
diff -ur usb_mass/iop/fat_driver.c usb_mass2/iop/fat_driver.c
--- usb_mass/iop/fat_driver.c 2006-07-21 17:00:28.000000000 +0200
+++ usb_mass2/iop/fat_driver.c 2006-07-21 17:07:26.000000000 +0200
@@ -354,7 +354,8 @@
part -> record[ i ].sid == 4 ||
part -> record[ i ].sid == 1 || // fat 16, fat 12
part -> record[ i ].sid == 0x0B ||
- part -> record[ i ].sid == 0x0C // fat 32
+ part -> record[ i ].sid == 0x0C || // fat 32
+ part -> record[ i ].sid == 0x0E // fat 16 LBA
) workPartition = i;
} /* end for */
@@ -1017,8 +1018,9 @@
if (ret < 0) {
return ret;
}
- if ( ((dirName[0] == '/' || dirName[0]=='\\') && dirName[1] == 0) || // the root directory
- dirName[0] == 0 || dirName == NULL) {
+ if ( dirName == NULL ||
+ ((dirName[0] == '/' || dirName[0]=='\\') && dirName[1] == 0) || // the root directory
+ dirName[0] == 0 ) {
direntryCluster = 0;
} else {
ret = fat_getFileStartCluster(&partBpb, dirName, &startCluster, fatDir);
@@ -1037,7 +1039,7 @@
int fat_initDriver() {
- int ret;
+ int ret = 0;
lastChainCluster = 0xFFFFFFFF;
lastChainResult = -1;
@@ -1058,7 +1060,7 @@
#endif
fs_init(NULL);
mounted = 1;
-
+ return ret;
}
diff -ur usb_mass/iop/imports.lst usb_mass2/iop/imports.lst
--- usb_mass/iop/imports.lst 2006-07-21 17:00:28.000000000 +0200
+++ usb_mass2/iop/imports.lst 2006-07-21 17:25:21.000000000 +0200
@@ -70,7 +70,6 @@
usbd_IMPORTS_start
I_UsbGetDeviceStaticDescriptor
I_UsbOpenEndpoint
-I_UsbOpenBulkEndpoint
I_UsbCloseEndpoint
I_UsbSetDevicePrivateData
I_UsbTransfer
diff -ur usb_mass/iop/mass_stor.c usb_mass2/iop/mass_stor.c
--- usb_mass/iop/mass_stor.c 2006-07-21 17:00:28.000000000 +0200
+++ usb_mass2/iop/mass_stor.c 2006-07-21 17:43:54.000000000 +0200
@@ -454,7 +454,7 @@
XPRINTF("...waiting for status 1 ...\n");
ret = usb_bulk_status(dev, &csw, tag); /* Attempt to read CSW from bulk in endpoint */
- if (ret == 4 || ret < 0) { /* STALL bulk in -OR- Bulk error */
+ if (ret == USB_RC_STALL || ret < 0) { /* 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");
@@ -463,12 +463,17 @@
}
/* CSW not valid or stalled or phase error */
- if (csw.signature != 0x53425355 || csw.tag != tag || ret != 0) {
+ if (csw.signature != 0x53425355 || csw.tag != tag) {
XPRINTF("...call reset recovery ...\n");
usb_bulk_reset(dev, 3); /* Perform reset recovery */
}
- return 0; //device is ready to process next CBW
+ 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
+ }
}
@@ -549,7 +554,7 @@
/* helper functions */
-#ifdef COMPILE_DUMPS
+#ifdef DEBUG
void dumpDevice(UsbDeviceDescriptor* data) {
printf("\n");
printf("DEVICE info\n");
@@ -572,7 +577,6 @@
printf("config value=0x%02X\n", data->bConfigurationValue);
printf("index configuration=0x%02X\n", data->iConfiguration);
printf("attributes=0x%02X\n", data->bmAttributes);
- printf("max power=0x%02X\n", data->MaxPower);
}
@@ -731,14 +735,14 @@
/* out transfer */
if ((endpoint->bEndpointAddress & 0x80) == 0 && dev->bulkEpO < 0) {
dev->bulkEpOAddr = endpoint->bEndpointAddress;
- dev->bulkEpO = UsbOpenBulkEndpoint(dev->devId, endpoint);
+ dev->bulkEpO = UsbOpenEndpoint(dev->devId, endpoint);
dev->packetSzO = endpoint->wMaxPacketSizeHB * 256 + endpoint->wMaxPacketSizeLB;
XPRINTF("register Output endpoint id =%i addr=%02X packetSize=%i\n", dev->bulkEpO,dev->bulkEpOAddr, dev->packetSzO);
}else
/* in transfer */
if ((endpoint->bEndpointAddress & 0x80) != 0 && dev->bulkEpI < 0) {
dev->bulkEpIAddr = endpoint->bEndpointAddress;
- dev->bulkEpI = UsbOpenBulkEndpoint(dev->devId, endpoint);
+ dev->bulkEpI = UsbOpenEndpoint(dev->devId, endpoint);
dev->packetSzI = endpoint->wMaxPacketSizeHB * 256 + endpoint->wMaxPacketSizeLB;
XPRINTF("register Intput endpoint id =%i addr=%02X packetSize=%i\n", dev->bulkEpI, dev->bulkEpIAddr, dev->packetSzI);
}
@@ -960,7 +964,6 @@
printf("!Error: device not ready!\n");
return -1;
}
-/*
//send start stop command
cbw_scsi_start_stop_unit(&cbw);
XPRINTF("-START COMMAND\n");
@@ -970,14 +973,14 @@
usb_bulk_manage_status(dev, -TAG_START_STOP_UNIT);
- //send test unit ready command
- cbw_scsi_test_unit_ready(&cbw);
- XPRINTF("-TUR COMMAND\n");
- usb_bulk_command(dev, &cbw);
+ do {
+ //send test unit ready command
+ cbw_scsi_test_unit_ready(&cbw);
+ XPRINTF("-TUR COMMAND\n");
+ usb_bulk_command(dev, &cbw);
- XPRINTF("-TUR STATUS\n");
- usb_bulk_manage_status(dev, -TAG_TEST_UNIT_READY);
-*/
+ XPRINTF("-TUR STATUS\n");
+ } while(usb_bulk_manage_status(dev, -TAG_TEST_UNIT_READY) != 0);
//send "request sense" command
//required for correct operation of some devices
@@ -1010,7 +1013,8 @@
//according to usb doc we should allways
//attempt to read the CSW packet. But in some cases
//reading of CSW packet just freeze ps2....:-(
- if (returnCode == 4) {
+ if (returnCode == USB_RC_STALL) {
+ XPRINTF("call reset recovery ...\n");
usb_bulk_reset(dev, 1);
} else {
diff -ur usb_mass/iop/usb_mass.c usb_mass2/iop/usb_mass.c
--- usb_mass/iop/usb_mass.c 2006-07-21 17:00:28.000000000 +0200
+++ usb_mass2/iop/usb_mass.c 2006-07-21 17:16:29.000000000 +0200
@@ -88,7 +88,7 @@
param.attr = TH_C;
param.thread = rpcMainThread;
param.priority = 40;
- param.stacksize = 0x800;
+ param.stacksize = 0x8000;
param.option = 0;
@@ -257,4 +257,4 @@
}
buf[0] = ret; //store return code
return buffer;
-}
\ Kein Zeilenumbruch am Dateiende.
+}
diff -ur usb_mass/pc/fat_test.c usb_mass2/pc/fat_test.c
--- usb_mass/pc/fat_test.c 2006-07-21 17:00:27.000000000 +0200
+++ usb_mass2/pc/fat_test.c 2006-07-21 17:23:03.000000000 +0200
@@ -105,7 +105,7 @@
bufSize = 4096;
fd = fs_open(&file, fname, O_RDONLY);
- fo = open(oname, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, S_IWUSR | S_IRUSR);
+ fo = open(oname, O_RDWR | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR);
if (fd >=0 && fo >=0) {
size = fs_lseek(&file, 0, SEEK_END);
printf("file: %s size: %i \n", fname, size);
@@ -300,7 +300,7 @@
bufSize = 4096;
fd = fs_open(&file, fname, O_RDWR | O_CREAT | O_TRUNC );
- fi = open(iname, O_RDONLY | O_BINARY , S_IWUSR | S_IRUSR);
+ fi = open(iname, O_RDONLY, S_IWUSR | S_IRUSR);
if (fd >=0 && fi >=0) {
size = lseek(fi, 0, SEEK_END);
printf("file: %s size: %i \n", iname, size);
diff -ur usb_mass/pc/makefile usb_mass2/pc/makefile
--- usb_mass/pc/makefile 2006-07-21 17:00:27.000000000 +0200
+++ usb_mass2/pc/makefile 2006-07-21 17:22:13.000000000 +0200
@@ -1,29 +1,35 @@
-CC=d:/gcc/bin/g++
-CFLAGS= -s
+CC=gcc
+CFLAGS= -g3 -I../iop
#uncomment to enable write support
WRITE_SUPPORT=1
-OBJECTS1=fat_test.o fat_driver.o scache.o vdisk.o
-OBJECTS2=obj/fat_test.o obj/fat_driver.o obj/scache.o obj/vdisk.o
+OBJECTS=fat_test.o fat_driver.o scache.o vdisk.o
ifdef WRITE_SUPPORT
CFLAGS += -DWRITE_SUPPORT
-OBJECTS1 += fat_write.o
-OBJECTS2 += obj/fat_write.o
+OBJECTS += fat_write.o
endif
-
-ALL: fat_test.exe
+all: fat_test
clean:
- rm obj/*.o
+ rm -f *.o
+
+fat_test: $(OBJECTS)
+ $(CC) $(CFLAGS) -o $@ $^
+
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $^ -o $@
-fat_test.exe: $(OBJECTS1)
- $(CC) $(CFLAGS) -ofat_test.exe $(OBJECTS2)
+fat_driver.c: ../iop/fat_driver.c
+ ln -s $^ $@
+scache.c: ../iop/scache.c
+ ln -s $^ $@
-.c.o:
- $(CC) $(CFLAGS) -c $(<) -o obj/$*.o
+fat_write.c: ../iop/fat_write.c
+ ln -s $^ $@
diff -ur usb_mass/pc/vdisk.c usb_mass2/pc/vdisk.c
--- usb_mass/pc/vdisk.c 2006-07-21 17:00:27.000000000 +0200
+++ usb_mass2/pc/vdisk.c 2006-07-21 17:22:42.000000000 +0200
@@ -20,6 +20,7 @@
int fileSize; //virtual disk size (given in bytes)
unsigned Size_Sector=512; //
+unsigned g_MaxLBA; /* Size of disk */
/*
@@ -29,7 +30,7 @@
int vdisk_init(char * param, int sectorSize) {
Size_Sector = sectorSize;
printf ("Accessing file : %s \n", param);
- fi = open(param, O_RDWR | O_BINARY , S_IWUSR);
+ fi = open(param, O_RDWR, S_IWUSR);
if (fi >=0) {
fileSize = lseek(fi, 0, SEEK_END);
@@ -37,6 +38,7 @@
} else {
fileSize = 0;
}
+ g_MaxLBA = fileSize / Size_Sector;
return fi;
}