Show message if firmware file has been (potentially) rejected by remote

This commit is contained in:
Joseph C. Lehner 2024-11-22 17:09:08 +01:00
parent 9f6ed3348a
commit a7310bf2dd
3 changed files with 22 additions and 2 deletions

14
main.c
View file

@ -310,7 +310,19 @@ int main(int argc, char **argv)
require_admin();
}
#endif
val = !list ? nmrp_do(&args) : ethsock_list_all();
if (list) {
val = ethsock_list_all();
} else {
val = nmrp_do(&args);
if (val != 0 && args.maybe_invalid_firmware_file) {
fprintf(stderr,
"\n"
"Firmware file rejected by remote device. Possible causes:\n"
"- Wrong firmware file (model number correct?)\n"
"- Wrong file format (e.g. .chk vs .trx file)\n"
"- Downgrading to a lower version number\n");
}
}
out:
#ifdef NMRPFLASH_WINDOWS

8
nmrp.c
View file

@ -410,6 +410,8 @@ int nmrp_do(struct nmrpd_args *args)
struct in_addr ipaddr;
struct in_addr ipmask;
args->maybe_invalid_firmware_file = false;
if (args->op != NMRP_UPLOAD_FW) {
fprintf(stderr, "Operation not implemented.\n");
return 1;
@ -634,6 +636,10 @@ int nmrp_do(struct nmrpd_args *args)
if (expect != NMRP_C_NONE && rx.msg.code != expect) {
fprintf(stderr, "Received %s while waiting for %s!\n",
msg_code_str(rx.msg.code), msg_code_str(expect));
if (ulreqs && expect == NMRP_C_TFTP_UL_REQ && rx.msg.code == NMRP_C_CONF_REQ) {
args->maybe_invalid_firmware_file = true;
}
}
msg_init(&tx.msg, NMRP_C_NONE);
@ -668,6 +674,7 @@ int nmrp_do(struct nmrpd_args *args)
break;
}
} else {
args->maybe_invalid_firmware_file = true;
if (verbosity) {
printf("Ignoring extra upload request.\n");
}
@ -744,6 +751,7 @@ int nmrp_do(struct nmrpd_args *args)
// file has been rejected. this feature is only implemented
// by some bootloaders.
expect = NMRP_C_TFTP_UL_REQ;
args->maybe_invalid_firmware_file = true;
} else {
goto out;
}

View file

@ -116,7 +116,7 @@ struct nmrpd_args {
uint16_t port;
const char *region;
off_t offset;
bool maybe_invalid_firmware_file;
struct ethsock *sock;
};