int erase_block(const char *device_name,long start,int count) { int regcount; int Fd; int unlock = 0; int res = 0; printf("erase_block : device:%s start 0x%0x, count:%d \n",device_name,(int)start,count); // Open and size the device if ((Fd = open(device_name,O_RDWR)) < 0) { fprintf(stderr,"File open error\n"); return 8; } printf("Erase Total %d Units\n", count); if (ioctl(Fd,MEMGETREGIONCOUNT,®count) == 0) { printf(" regcount is %d \n", regcount); if(regcount == 0) { res = non_region_erase(Fd, start, count, unlock); } else { res = region_erase(Fd, start, count, unlock, regcount); } } close(Fd); return res; }
int main(int argc,char *argv[]) { int regcount; int Fd; int start; int count; int unlock; int res = 0; if (1 >= argc) { fprintf(stderr,"You must specify a device\n"); return 16; } if (argc > 2) start = strtol(argv[2], NULL, 0); else start = 0; if (argc > 3) count = strtol(argv[3], NULL, 0); else count = 1; if(argc > 4) unlock = strtol(argv[4], NULL, 0); else unlock = 0; // Open and size the device if ((Fd = open(argv[1],O_RDWR)) < 0) { fprintf(stderr,"File open error\n"); return 8; } printf("Erase Total %d Units\n", count); if (ioctl(Fd,MEMGETREGIONCOUNT,®count) == 0) { if(regcount == 0) { res = non_region_erase(Fd, start, count, unlock); } else { res = region_erase(Fd, start, count, unlock, regcount); } } return res; }