Add -c switch to execute command before (or instead of) TFTP upload
This commit is contained in:
parent
936219b598
commit
32914803f3
2 changed files with 21 additions and 8 deletions
10
main.c
10
main.c
|
@ -30,8 +30,9 @@ void usage(FILE *fp)
|
||||||
fprintf(fp,
|
fprintf(fp,
|
||||||
"Usage: nmrpflash [OPTIONS...]\n"
|
"Usage: nmrpflash [OPTIONS...]\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Options (-a, -i and -f are mandatory):\n"
|
"Options (-a, -i and -f and/or -c are mandatory):\n"
|
||||||
" -a <ipaddr> IP address to assign to target device\n"
|
" -a <ipaddr> IP address to assign to target device\n"
|
||||||
|
" -c <command> Command to run before (or instead of) TFTP upload\n"
|
||||||
" -f <firmware> Firmware file\n"
|
" -f <firmware> Firmware file\n"
|
||||||
" -i <interface> Network interface directly connected to device\n"
|
" -i <interface> Network interface directly connected to device\n"
|
||||||
" -m <mac> MAC address of target device (xx:xx:xx:xx:xx:xx)\n"
|
" -m <mac> MAC address of target device (xx:xx:xx:xx:xx:xx)\n"
|
||||||
|
@ -91,12 +92,15 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "a:f:i:m:M:p:t:T:hLVvU")) != -1) {
|
while ((c = getopt(argc, argv, "a:c:f:i:m:M:p:t:T:hLVvU")) != -1) {
|
||||||
max = 0x7fffffff;
|
max = 0x7fffffff;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'a':
|
case 'a':
|
||||||
args.ipaddr = optarg;
|
args.ipaddr = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
args.tftpcmd = optarg;
|
||||||
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
args.filename = optarg;
|
args.filename = optarg;
|
||||||
break;
|
break;
|
||||||
|
@ -157,7 +161,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!args.filename || !args.intf || !args.ipaddr) {
|
if ((!args.filename && !args.tftpcmd) || !args.intf || !args.ipaddr) {
|
||||||
usage(stderr);
|
usage(stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
19
nmrp.c
19
nmrp.c
|
@ -417,14 +417,23 @@ int nmrp_do(struct nmrpd_args *args)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!args->tftpcmd) {
|
err = 0;
|
||||||
|
|
||||||
|
if (args->tftpcmd) {
|
||||||
|
printf("Executing '%s' ... ", args->tftpcmd);
|
||||||
|
fflush(stdout);
|
||||||
|
err = system(args->tftpcmd);
|
||||||
|
if (!err) {
|
||||||
|
printf("OK\n");
|
||||||
|
} else {
|
||||||
|
printf("ERR\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!err && args->filename) {
|
||||||
printf("Uploading %s ... ", args->filename);
|
printf("Uploading %s ... ", args->filename);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
err = tftp_put(args);
|
err = tftp_put(args);
|
||||||
} else {
|
|
||||||
printf("Running %s ... ", args->tftpcmd);
|
|
||||||
fflush(stdout);
|
|
||||||
err = system(args->tftpcmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue