# HG changeset patch # User Mychaela Falconia # Date 1611624478 0 # Node ID 4aaf722ab93323fd42618248fc20dedc54680c49 # Parent 6f80cfdc7e055a3efc3804601bed071a0e0e6511 fc-simtool: update-bin-imm command implemented diff -r 6f80cfdc7e05 -r 4aaf722ab933 simtool/dispatch.c --- a/simtool/dispatch.c Tue Jan 26 00:51:59 2021 +0000 +++ b/simtool/dispatch.c Tue Jan 26 01:27:58 2021 +0000 @@ -28,6 +28,7 @@ extern int cmd_telecom_sum(); extern int cmd_unblock_chv(); extern int cmd_update_bin(); +extern int cmd_update_bin_imm(); extern int cmd_update_rec(); extern int cmd_verify_chv(); @@ -73,6 +74,7 @@ {"unblock-pin1", 2, 2, cmd_unblock_chv}, {"unblock-pin2", 2, 2, cmd_unblock_chv}, {"update-bin", 2, 2, cmd_update_bin}, + {"update-bin-imm", 2, 2, cmd_update_bin_imm}, {"update-rec", 2, 2, cmd_update_rec}, {"verify-chv1", 1, 1, cmd_verify_chv}, {"verify-chv2", 1, 1, cmd_verify_chv}, @@ -113,11 +115,23 @@ fprintf(stderr, "error: too many arguments\n"); return(-1); } - *ap++ = cp; - while (*cp && !isspace(*cp)) - cp++; - if (*cp) + if (*cp == '"') { + *ap++ = ++cp; + while (*cp && *cp != '"') + cp++; + if (*cp != '"') { + fprintf(stderr, + "error: unterminated quoted string\n"); + return(-1); + } *cp++ = '\0'; + } else { + *ap++ = cp; + while (*cp && !isspace(*cp)) + cp++; + if (*cp) + *cp++ = '\0'; + } } if (ap - argv - 1 < tp->minargs) { fprintf(stderr, "error: too few arguments\n"); diff -r 6f80cfdc7e05 -r 4aaf722ab933 simtool/hexread.c --- a/simtool/hexread.c Tue Jan 26 00:51:59 2021 +0000 +++ b/simtool/hexread.c Tue Jan 26 01:27:58 2021 +0000 @@ -65,3 +65,33 @@ } return(count); } + +decode_hex_data_from_string(arg, databuf) + char *arg; + u_char *databuf; +{ + unsigned count; + + for (count = 0; ; count++) { + while (isspace(*arg)) + arg++; + if (!*arg) + break; + if (!isxdigit(arg[0]) || !isxdigit(arg[1])) { + fprintf(stderr, "error: invalid hex string input\n"); + return(-1); + } + if (count >= 255) { + fprintf(stderr, "error: hex input data is too long\n"); + return(-1); + } + databuf[count] = (decode_hex_digit(arg[0]) << 4) | + decode_hex_digit(arg[1]); + arg += 2; + } + if (!count) { + fprintf(stderr, "error: empty hex string argument\n"); + return(-1); + } + return(count); +} diff -r 6f80cfdc7e05 -r 4aaf722ab933 simtool/writecmd.c --- a/simtool/writecmd.c Tue Jan 26 00:51:59 2021 +0000 +++ b/simtool/writecmd.c Tue Jan 26 01:27:58 2021 +0000 @@ -24,6 +24,25 @@ return update_bin_op(offset, data, len); } +cmd_update_bin_imm(argc, argv) + char **argv; +{ + unsigned offset, len; + u_char data[255]; + int rc; + + offset = strtoul(argv[1], 0, 0); + if (offset > 0xFFFF) { + fprintf(stderr, "error: offset argument is out of range\n"); + return(-1); + } + rc = decode_hex_data_from_string(argv[2], data); + if (rc < 0) + return(rc); + len = rc; + return update_bin_op(offset, data, len); +} + cmd_update_rec(argc, argv) char **argv; {