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("Usage:\n");
printf("\t-a, --address <n>: starting address (default: 0)\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-r <filename>: Read data into file.\n");
printf("\t-w <filename>: Write data from file.\n"); printf("\t-w <filename>: Write data from file.\n");
} }
@ -137,8 +137,27 @@ int main(int argc, char** argv)
return EXIT_FAILURE; 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) { if (length == 0) {
fprintf(stderr, "Requested transfer of zero bytes.\n"); fprintf(stderr, "Requested transfer of zero bytes.\n");
if(fd != NULL)
fclose(fd);
usage(); usage();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -146,20 +165,14 @@ int main(int argc, char** argv)
if ((length > MAX_LENGTH) || (address > MAX_LENGTH) if ((length > MAX_LENGTH) || (address > MAX_LENGTH)
|| ((address + length) > MAX_LENGTH)) { || ((address + length) > MAX_LENGTH)) {
fprintf(stderr, "Request exceeds size of flash memory.\n"); fprintf(stderr, "Request exceeds size of flash memory.\n");
usage(); if(fd != NULL)
return EXIT_FAILURE; fclose(fd);
}
if (path == NULL) {
fprintf(stderr, "Specify a path to a file.\n");
usage(); usage();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (read) { if (read) {
fd = fopen(path, "wb"); fd = fopen(path, "wb");
} else {
fd = fopen(path, "rb");
} }
if (fd == NULL) { if (fd == NULL) {