hackrf_spiflash modified -l argument is not used anymore with -w argument, file len is automatically read.

This commit is contained in:
TitanMKD
2013-04-07 18:57:30 +02:00
parent 8777f93721
commit ead843ec2a

View File

@ -70,7 +70,7 @@ static void usage()
{
printf("Usage:\n");
printf("\t-a, --address <n>: starting address (default: 0)\n");
printf("\t-l, --length <n>: number of bytes to read or write (default: 0)\n");
printf("\t-l, --length <n>: number of bytes to read (default: 0)\n");
printf("\t-r <filename>: Read data into file.\n");
printf("\t-w <filename>: Write data from file.\n");
}
@ -136,9 +136,28 @@ int main(int argc, char** argv)
usage();
return EXIT_FAILURE;
}
if (path == NULL) {
fprintf(stderr, "Specify a path to a file.\n");
usage();
return EXIT_FAILURE;
}
if( write )
{
fd = fopen(path, "rb");
/* Get size of the file */
fseek(fd, 0, SEEK_END); /* Not really portable but work on major OS Linux/Win32 */
length = ftell(fd);
/* Move to start */
rewind(fd);
printf("File size %d bytes.\n", length);
}
if (length == 0) {
fprintf(stderr, "Requested transfer of zero bytes.\n");
if(fd != NULL)
fclose(fd);
usage();
return EXIT_FAILURE;
}
@ -146,20 +165,14 @@ int main(int argc, char** argv)
if ((length > MAX_LENGTH) || (address > MAX_LENGTH)
|| ((address + length) > MAX_LENGTH)) {
fprintf(stderr, "Request exceeds size of flash memory.\n");
usage();
return EXIT_FAILURE;
}
if (path == NULL) {
fprintf(stderr, "Specify a path to a file.\n");
if(fd != NULL)
fclose(fd);
usage();
return EXIT_FAILURE;
}
if (read) {
fd = fopen(path, "wb");
} else {
fd = fopen(path, "rb");
}
if (fd == NULL) {