Page 3 of 3

Re: Different transfer type using uhci

Posted: Sat Dec 24, 2022 4:40 pm
by BenLunt
Bonfra wrote:Sorry i didn't specify, the OS only knows how to read from sata ahci drives for the moment.
anyway the USB thing should happen before it tries to load the init process (actually even before the successfully booted message), so something more should appear if a controller with something attached is found
That makes sense. Okay, I will have a look and see what I can find.

Re: Different transfer type using uhci

Posted: Sat Dec 24, 2022 5:36 pm
by Bonfra
Thanks a lot! I really appreciate what you are doing for me :)
Just don't get too busy with this rn, it still is Christmas XP

Re: Different transfer type using uhci

Posted: Sat Dec 24, 2022 7:48 pm
by BenLunt
Bonfra wrote:Thanks a lot! I really appreciate what you are doing for me :)
Just don't get too busy with this rn, it still is Christmas XP
Indeed, and a Merry Christmas to you as well.

I spent a few minutes and was able to run your image through my USB Test Suite after finding a few errors.

1) The read at:
https://github.com/Bonfra04/BonsOS/blob ... uhci.c#L51
is trying to read a WORD when the register is a BYTE. QEMU seems to allow it, Bochs does not. Your UHCI code returned 'UHCI not detected' and did nothing more.

2) When setting the interface, you need to use USB_REQUEST_RECP_INTERFACE as well
https://github.com/Bonfra04/BonsOS/blob ... uest.c#L75
(For now, you can ignore setting the interface. When you find a device that supports more than one interface (BBB and UASP for example), you will then need to set the interface)

3) Unlike IN packets, when sending OUT packets (Bulk or otherwise), you should send the count of bytes being sent, not the max count.
https://github.com/Bonfra04/BonsOS/blob ... sfer.c#L80
All but that last packet should have a count of MAX_PACKET, then the last packet has the remaining. Since your first try is a CBW, it is only one packet with 31 bytes. You currently tell it you are sending 64. It will STALL.

Your code should be something like:

Code: Select all

  packets[pid].maxlen = (size > MAX_PACKET) ? MAX_PACKET : size;
  size -= MAX_PACKET;
of course paying attention to negative numbers in 'size' and setting MAX_PACKET to the size returned in the endpoint descriptor for this device.

After modifying my test suite to allow these errors, I got your code to retrieve 36 bytes of Inquiry data (though I did not verify that it was correct data) and retrieve a 13-byte CSW.

Again, Merry Christmas to you and everyone here.
Ben

Re: Different transfer type using uhci

Posted: Sun Dec 25, 2022 7:32 am
by Bonfra
It works awesomely! The SCSI output is correct and I can successfully read from the drive. Thanks a lot!
Now I'm having some troubles making this work on real hw, but it's a problem for another day, I'm happy with these results. Thanks again and merry Christmas :)