Re: Q: how to send ATA cmds to USB drive?

Herbert Rosmanith
2006-06-12T09:27:57Z

> > But now I also have to support USB harddisks from the same company.
> > The USB harddisk uses the same set of ATA commands as the IDE harddisk,
> > well, at least that's what I suppose.
>
> USB storage is a sort of 'pigdin' SCSI. You send SCSI commands to the
> USB storage device but you may find anything too clever breaks.

hm, that depends
on where "too much cleverness" is implemented.
I just noticed that scsi-commands I send to
via SG_IO get modified underway.

the userland program looks like this:

memset(cmd,0,16);
cmd[0]=0x24;
cmd[1]=0x24;
cmd[2]=0x01;
cmd[3]=0x01;

memset(&ioh,0,sizeof(ioh));
ioh.interface_id='S';
ioh.dxfer_direction=SG_DXFER_FROM_DEV;
ioh.dxferp = buf;
ioh.dxfer_len = 8;
ioh.cmdp=cmd;
ioh.cmd_len=16;
ioh.sbp=sbuf;
ioh.mx_sb_len=SG_MAX_SENSE;
ioh.timeout = 2000; // 2 sekunden
ioh.flags = SG_FLAG_DIRECT_IO;

if ((i=ioctl(fd,SG_IO,&ioh))==-1)
die("ioctl");

but what's really sent to the device is:

> usb_stor_Bulk_transport
Bulk Command S 0x43425355 T 0x2a L 8 F 0 Trg 0 LUN 0 CL 16
> usb_stor_bulk_transfer_buf (length=31)
55
53
42
43
2a
00
00
00
08
00
00
00
00
00
10
24
04
01
01
00
00
00
00
00
00
00
00
00
00
00
00

the data really sent is "0x24 0x04 0x01 0x01", which means that 0x20 gets
cleared in byte 2 (for whatever reason).

the specs I have (CY7C68310.pdf from http://www.rockbox.org/twiki/pub/Main/DataSheets/)
say that this field has to be 0x24 for ATACB commands. this is on page12. with the
ATACB, I want to implement TaskFileRead and TaskFileWrite (page 13).
the device is a "Low-Power USB 2.0 ATA/ATPAI Bridge IC".

do you have any idea why the data is modified and how I can prevent this?

kind regards,
herbert rosmanith