44 lines
929 B
C
Executable File
44 lines
929 B
C
Executable File
#include <stdio.h>
|
|
#include <linux/types.h>
|
|
#include <stdlib.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/ioctl.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
|
|
unsigned char write_buff[8] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
|
|
unsigned char read_buff[8] = {0};
|
|
|
|
int main(void)
|
|
{
|
|
|
|
int fd,num,i;
|
|
fd = open("/dev/mmcblk0",O_RDWR);
|
|
if(fd < 0)
|
|
printf("open mmcblk0 error\n");
|
|
|
|
num = write(fd, write_buff, 8);
|
|
if (8 != num)
|
|
printf("write device failed!\n");
|
|
|
|
lseek(fd,0,SEEK_SET);
|
|
num = read(fd, read_buff, 8);
|
|
if (8 != num)
|
|
printf("read device failed!\n");
|
|
|
|
if (memcmp(write_buff, read_buff, 8) == 0)
|
|
printf("Block test OK!\n");
|
|
else
|
|
printf("Block test Fail!\n");
|
|
|
|
for(i = 0;i < 8;i++)
|
|
printf("0x%x ",read_buff[i]);
|
|
|
|
printf("\n");
|
|
|
|
close(fd);
|
|
return 0;
|
|
}
|