Add -S <offset> option

This commit is contained in:
Joseph C. Lehner 2020-09-10 15:11:04 +02:00
parent 5acfbed385
commit ec3f738fb6
3 changed files with 12 additions and 2 deletions

7
main.c
View file

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

View file

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

6
tftp.c
View file

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