#include #include #include #include #include #include #include #include #include "flash.h" #define FLASHSIZE 1024*1024 main(argc,argv) int argc; char **argv; { int fd = 0; int uTemp = 0; int uTemp1 = 0; char* p; char* filebuf; char* basename; FILE* dumpfile; // printf("\nargc=%d, argv:[0]=%s, [1]=%s, [2]=%s, [3]=%s.\n\n", // argc,argv[0],argv[1],argv[2],argv[3]); basename = (p = strrchr(argv[0], '/')) ? p+1 : argv[0]; if(argc != 2) { fprintf(stderr,"\nNetwinder Flash Dump utility, Woody 1999.\nUsage: %s filename.\n\n", basename); return EXIT_FAILURE; } fd = open("/dev/nwflash", O_RDWR); if (fd <0) { printf("Error %d opening /dev/nwflash\n",fd); return EXIT_FAILURE; } else { // printf("Flash Open OK, rc = 0x%X.\n",fd); } filebuf = (char *)malloc (FLASHSIZE); uTemp = lseek(fd, 0, 0); //start from the beginning // printf("Seek rc = 0x%X.\n",uTemp); uTemp = read(fd, filebuf, FLASHSIZE); printf("Read 0x%X bytes.\n",uTemp); ioctl(fd, CMD_WRITE_DISABLE); if (close(fd) != 0) printf("Error closing /dev/nwflash\n"); dumpfile = fopen(argv[1], "wb"); if (dumpfile <= 0) { fprintf(stderr,"%s: unable to open file \"%s\", error 0x%X.\n", basename, argv[1], errno); return EXIT_FAILURE; } uTemp1 = fwrite(filebuf,uTemp,1,dumpfile); fclose(dumpfile); free(filebuf); if (uTemp1 >= 0) { return EXIT_SUCCESS; } else { fprintf(stderr,"%s: error writing to the file \"%s\", error 0x%X.\n", basename, argv[1], errno); return EXIT_FAILURE; } }