diff --git a/main.c b/main.c index 67780f7..c1fde06 100644 --- a/main.c +++ b/main.c @@ -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 diff --git a/nmrp.c b/nmrp.c index 87798f0..43b3f64 100644 --- a/nmrp.c +++ b/nmrp.c @@ -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; } diff --git a/nmrpd.h b/nmrpd.h index da9b817..924323b 100644 --- a/nmrpd.h +++ b/nmrpd.h @@ -116,7 +116,7 @@ struct nmrpd_args { uint16_t port; const char *region; off_t offset; - + bool maybe_invalid_firmware_file; struct ethsock *sock; };