Browse Source

Add -S <offset> option

Joseph C. Lehner 3 years ago
parent
commit
ec3f738fb6
3 changed files with 12 additions and 2 deletions
  1. 6 1
      main.c
  2. 1 0
      nmrpd.h
  3. 5 1
      tftp.c

+ 6 - 1
main.c

@@ -44,6 +44,7 @@ void usage(FILE *fp)
 #ifdef NMRPFLASH_SET_REGION
 			" -R <region>     Set device region (NA, WW, GR, PR, RU, BZ, IN, KO, JP)\n"
 #endif
+			" -S <n>          Skip <n> bytes of the firmware file\n"
 #ifdef NMRPFLASH_TFTP_TEST
 			" -U              Test TFTP upload\n"
 #endif
@@ -145,6 +146,7 @@ int main(int argc, char **argv)
 		.port = 69,
 		.region = NULL,
 		.blind = false,
+		.offset = 0,
 	};
 #ifdef NMRPFLASH_WINDOWS
 	char *newpath = NULL;
@@ -181,7 +183,7 @@ int main(int argc, char **argv)
 
 	opterr = 0;
 
-	while ((c = getopt(argc, argv, "a:A:Bc:f:F:i:m:M:p:R:t:T:hLVvU")) != -1) {
+	while ((c = getopt(argc, argv, "a:A:Bc:f:F:i:m:M:p:R:S:t:T:hLVvU")) != -1) {
 		max = 0x7fffffff;
 		switch (c) {
 			case 'a':
@@ -218,6 +220,7 @@ int main(int argc, char **argv)
 				break;
 #endif
 			case 'p':
+			case 'S':
 			case 'T':
 			case 't':
 				if (c == 'p') {
@@ -236,6 +239,8 @@ int main(int argc, char **argv)
 					args.rx_timeout = val;
 				} else if (c == 'T') {
 					args.ul_timeout = val * 1000;
+				} else if (c == 'S') {
+					args.offset = val;
 				}
 
 				break;

+ 1 - 0
nmrpd.h

@@ -100,6 +100,7 @@ struct nmrpd_args {
 	bool blind;
 	uint16_t port;
 	const char *region;
+	off_t offset;
 };
 
 const char *leafname(const char *path);

+ 5 - 1
tftp.c

@@ -349,11 +349,15 @@ int tftp_put(struct nmrpd_args *args)
 		fd = open(args->file_local, O_RDONLY | O_BINARY);
 		if (fd < 0) {
 			xperror("open");
-			ret = fd;
 			goto cleanup;
 		} else if (!file_remote) {
 			file_remote = args->file_local;
 		}
+
+		if (lseek(fd, args->offset, SEEK_SET) == (off_t)-1) {
+			xperror("lseek");
+			goto cleanup;
+		}
 	}
 
 #ifndef NMRPFLASH_FUZZ_TFTP