Results 1 to 4 of 4

Thread: IOCTL call for SD cards

  1. #1
    Join Date
    May 2009
    Posts
    2

    IOCTL call for SD cards

    Hi All,

    Do any of you tried accessing SD (Secure Digital ) cards using IOCTL functions to change the address of the card.

    I tried using below said IOCTL call , but I couldnt change the Lba address mode.

    Code:
    int val;
    
    ioctl(fd,HDIO_SET_ADDRESS,val);
    Is there any other way to access the SD cards for changing address.
    Can any one help me in this,

    Thanks in Advance,
    Ranjin

  2. #2
    Join Date
    Dec 2007
    Posts
    1,547

    Re: IOCTL call for SD cards

    The IOCTLs in this section allow user-mode applications to operate devices in the Secure Digial (SD) card stack. To use the IOCTLs, the caller must first use CreateFile to get a handle to a device in the SD stack, as shown here, where szDevice points to a NULL-terminated string that references the device.

    Code:
    hVol = CreateFile (szDevice,
      GENERIC_READ | GENERIC_WRITE,
      FILE_SHARE_WRITE | FILE_SHARE_DELETE,
      NULL,
      OPEN_EXISTING,
      FILE_ATTRIBUTE_NORMAL,
      NULL
      );
      if (hVol == INVALID_HANDLE_VALUE) {
        return GetLastError();
      }
    For more information go to this link.

  3. #3
    Join Date
    Dec 2008
    Posts
    161

    Re: IOCTL call for SD cards

    A BootP server is used to configure the following:

    *Note- In IMG 1004 need to insert the SD cards.
    • IMG 1004 CTRL IP address
    • you need to know your subnet mask
    • need to have gateway address
    • need to know FTP server address
    • FTP file name of the IMG 1004 system software

    To make the configuration you need to have two server BootP and FTP server, If a BootP server is not available to configure in your system but a remote FTP Server is available, configuring the SD card can be used to configure the boot parameters so that IMG 1004 may help you to retrieve the system software from the remote FTP Server.

  4. #4
    Join Date
    May 2009
    Posts
    2

    Re: IOCTL call for SD cards

    HI All,

    Thanks for the reply,

    As you said I will open the SD card device using ioctl call. then im able to do block write and read to the particular address. If i need to change the address of the block to be read/write. What type of ioctl call i should use.

    Is there any other way to cahnge the block address of the SD card
    using ioctl.

    the code snippet as follows.

    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <unistd.h>
    #include <ctype.h>
    #include <fcntl.h>
    #include <sys/ioctl.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <scsi/sg.h>
    #include <linux/hdreg.h>

    #include <linux/fs.h>
    #include <linux/types.h>
    #include <errno.h>

    //This code contains only IOCTL GET and SET addr + write and read blocks



    int main()
    {
    int fd;
    int val;
    long val1;
    int *next_byte;
    FILE *fp = NULL;
    unsigned int i = 0;
    int err;




    /*******************Read the data from file**********************************/

    next_byte = malloc(4096);
    fp = fopen("./data/data_file","r");

    if(fp == NULL)
    printf("\n------------- CANNOT OPEN FILE -----------\n");

    while(fscanf(fp,"%d \n",&next_byte[i]) != EOF)
    {
    //printf("\n----------- data = %d \n",next_byte[i]);
    i++;
    }

    fclose(fp);
    /***************************************************************/
    /*----------------------open the drive ie open the card mounted and perform READ/WRITE------------------------------*/
    //fd = open("/dev/mmcblk0", O_RDWR);
    fd = open("/dev/mmcblk0", O_WRONLY);
    if(fd == -1)
    printf(" \n fail\n");
    printf("\n Pass \n");

    val = 1;
    err = ioctl(fd, HDIO_SET_ADDRESS,val);
    printf("\n Saddr %x %d %04X \n",val,err, HDIO_SET_ADDRESS);

    err = ioctl(fd, HDIO_GET_ADDRESS,&val1);
    printf("\n Gaddr %x %d \n",val1,err);


    // read(fd,next_byte,4096);
    next_byte[0] = 0xAA;
    write(fd,next_byte,4096);
    ioctl(fd, HDIO_GET_ADDRESS,&val);
    printf("\n Gaddr %x \n",val);
    read(fd,next_byte,4096);
    close(fd);
    free(next_byte);
    next_byte = NULL;


    /**********************************************/
    fd = open("/dev/mmcblk0", O_RDONLY);
    if(fd == -1)
    printf(" \n fail\n");
    printf("\n Pass \n");

    next_byte = malloc(4096);
    read(fd,next_byte,4096);
    close(fd);
    free(next_byte);
    next_byte = NULL;
    /**********************************************/
    return 0;
    }

    As per the above code , I can write/read to one particular address say 0x00.
    is I need to write in the address say 0x5000, what should i Do.

    Regards,
    Ranjini.
    Ra[SIZE="4"][/SIZE]njini

Similar Threads

  1. Replies: 14
    Last Post: 09-04-2012, 02:49 PM
  2. How do I compare laptop video cards to desktop video cards?
    By johnbrad in forum Monitor & Video Cards
    Replies: 1
    Last Post: 17-06-2011, 07:47 PM
  3. The cards in Zynga poker are random cards?
    By Cajetan in forum Video Games
    Replies: 5
    Last Post: 09-03-2011, 07:29 AM
  4. Graphics cards, single card vs 2 sli cards?
    By abela in forum Monitor & Video Cards
    Replies: 7
    Last Post: 28-09-2010, 11:52 PM
  5. Where are all the death cards on Call of Duty 5
    By Bandish in forum Video Games
    Replies: 3
    Last Post: 12-08-2009, 10:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,866,201.22908 seconds with 16 queries