• Home
  • Help
  • Search
  • Login
  • Register
Pages: [1]
Author Topic: Access SATA SSD through SG_IO?  (Read 3347 times)
joejhliao
Newbie
*

Karma: 0
Posts: 2


View Profile
« on: June 08, 2009, 12:04:27 AM »

Hello All,
     I'm developing a disk utility for SSD which connected to sata port.
     It detects and mounts my SSD well on kernel 2.6.22.18.
     Also IDE reset at UBoot get correct identify information.

     But once I want to access sata port by my program through /dev/sdb with SG_IO interface.
     I get SG_IO error: SCSI sense =0x5/20/00, ATA =0x00/00
     But it works well on my x86 fedora 7.
     Didn't SG_IO is supported just enable SCSI GENERIC in Kernel?
     Any suggestion will be appreciated.
     Here is sample identify C code.

 
        unsigned char cdb[ATA_16_LEN]
      = { ATA_16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
   unsigned char sense[32];
   unsigned int nsects = 1;
   struct sg_io_hdr hdr;

   cdb[ 1] = ATA_PROTO_PIO_IN;
   cdb[ 6] = nsects;
   cdb[14] = 0xEC;

   memset(&hdr, 0, sizeof(struct sg_io_hdr));
   hdr.interface_id   = 'S';
   hdr.cmd_len      = ATA_16_LEN;
   hdr.mx_sb_len      = sizeof(sense);
   hdr.dxfer_direction   = SG_DXFER_FROM_DEV;
   hdr.dxfer_len      = nsects * ATA_SECT_SIZE;
   hdr.dxferp      = buf;
   hdr.cmdp      = cdb;
   hdr.sbp         = sense;
   hdr.timeout      = 5000; /* milliseconds */

   memset(sense, 0, sizeof(sense));
   if (ioctl(fd, SG_IO, &hdr) < 0) {
      perror("ioctl(SG_IO)");
      return (-1);
   }
   if (hdr.status == 0 && hdr.host_status == 0 && hdr.driver_status == 0)
      return 0; /* success */

   if (hdr.status > 0) {
      unsigned char *d = sense + 8;
      /* SCSI status is non-zero */
      fprintf(stderr, "SG_IO error: SCSI sense=0x%x/%02x/%02x, ATA=0x%02x/%02x\n",
         sense[1] & 0xf, sense[2], sense[3], d[13], d[3]);
      return -1;
   }
     
     

     



Logged

puppetboy
Newbie
*

Karma: 0
Posts: 4


View Profile
« Reply #1 on: June 08, 2009, 09:05:26 AM »

How did you physically connect to your SATA port ?
Thanks for any info or URLs or pointers.
Gus
Logged

superpat
Full Member
***

Karma: 15
Posts: 141


View Profile
« Reply #2 on: June 09, 2009, 07:23:44 AM »

Hi,

Are you using an OpenRd-* device HuhHuh

Or have you found a way to get at the SATA pins on a Sheevaplug?

Inquiring minds would like to know please!

regards

Patrick
Logged

joejhliao
Newbie
*

Karma: 0
Posts: 2


View Profile
« Reply #3 on: June 28, 2009, 07:11:38 PM »

Hi Patrick,
   Thanks for your reply.
   I was using an OpenRD device.

   Anyway, Instead of tuning the kernel, I make my application become one of the UBoot command.
   But if there any one still looking for the answer (SG_IO in kernel), I would like to discuss too.

Joe
Logged

Pages: [1]
Print
Jump to: