diff target-utils/loadagent/cmd_memload.c @ 658:0da2cf5a999c

target-utils: libload eliminated
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 03 Mar 2020 06:06:17 +0000
parents target-utils/libload/cmd_memload.c@9214118ae941
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/loadagent/cmd_memload.c	Tue Mar 03 06:06:17 2020 +0000
@@ -0,0 +1,52 @@
+/*
+ * This module implements the ML (memory load) command, which will be
+ * used by fc-chainload.
+ *
+ * The sole argument to the ML command is the body of an S3 record
+ * with the initial "S3" characters stripped, i.e., starting with the
+ * "count" byte, followed by the address, data and checksum bytes
+ * exactly as in the original S3 record.
+ */
+
+#include "types.h"
+
+void
+cmd_memload(argbulk)
+	char *argbulk;
+{
+	char *argv[2], *s;
+	u8 srecbin[256], cksum;
+	int len, i, c;
+	u32 addr;
+
+	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
+		return;
+	s = argv[0];
+	if (decode_hex_digits(s, 2, &len) < 0) {
+inv:		printf("ERROR: ML argument is invalid\n");
+		return;
+	}
+	s += 2;
+	if (len < 6)
+		goto inv;
+	srecbin[0] = len;
+	for (i = 1; i <= len; i++) {
+		if (decode_hex_digits(s, 2, &c) < 0)
+			goto inv;
+		s += 2;
+		srecbin[i] = c;
+	}
+	cksum = 0;
+	for (i = 0; i <= len; i++)
+		cksum += srecbin[i];
+	if (cksum != 0xFF) {
+		printf("ERROR: bad ML S-record checksum\n");
+		return;
+	}
+	len -= 5;
+	addr =  ((u32)srecbin[1] << 24) |
+		((u32)srecbin[2] << 16) |
+		((u32)srecbin[3] << 8) |
+		 (u32)srecbin[4];
+	memcpy(addr, srecbin + 5, len);
+}