changeset 109:4aaf722ab933

fc-simtool: update-bin-imm command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 26 Jan 2021 01:27:58 +0000
parents 6f80cfdc7e05
children a6de34816297
files simtool/dispatch.c simtool/hexread.c simtool/writecmd.c
diffstat 3 files changed, 67 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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");
--- 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);
+}
--- 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;
 {