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.
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.
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.