diff loadtools/ltdump.c @ 35:05af070c4b60

loadtool: preparations for dump2bin and dump2srec
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 05 May 2013 02:24:56 +0000
parents
children 65111e6eee9e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadtools/ltdump.c	Sun May 05 02:24:56 2013 +0000
@@ -0,0 +1,71 @@
+/*
+ * This module implements the dump2bin and dump2srec functionality
+ * of fc-loadtool.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+
+extern char target_response_line[];
+
+crc32_on_target(area_base, area_len, retptr)
+	u_long area_base, area_len, *retptr;
+{
+	char arg1[10], arg2[10], *argv[4];
+	int stat;
+	char *strtoul_endp;
+
+	sprintf(arg1, "%lx", area_base);
+	sprintf(arg2, "%lx", area_len);
+	argv[0] = "crc32";
+	argv[1] = arg1;
+	argv[2] = arg2;
+	argv[3] = 0;
+	tpinterf_make_cmd(argv);
+	if (tpinterf_send_cmd() < 0)
+		return(-1);
+	stat = tpinterf_capture_output_oneline(10);	/* 10 s timeout */
+	if (stat != 1) {
+errout:		fprintf(stderr, "error: malformed response to crc32 command\n");
+		return(-1);
+	}
+	if (strlen(target_response_line) != 8)
+		goto errout;
+	*retptr = strtoul(target_response_line, &strtoul_endp, 16);
+	if (strtoul_endp != target_response_line + 8)
+		goto errout;
+	return(0);
+}
+
+cmd_crc32(argc, argv)
+	char **argv;
+{
+	u_long area_base, area_len;
+	char *strtoul_endp;
+	u_long crc_result;
+	int stat;
+
+	area_base = strtoul(argv[1], &strtoul_endp, 16);
+	if (*strtoul_endp) {
+inv:		fprintf(stderr, "usage: crc32 hex-start hex-len\n");
+		return(-1);
+	}
+	area_len = strtoul(argv[2], &strtoul_endp, 16);
+	if (*strtoul_endp)
+		goto inv;
+	stat = crc32_on_target(area_base, area_len, &crc_result);
+	if (stat == 0)
+		printf("%08lX\n", crc_result);
+	return(stat);
+}
+
+cmd_dump2bin(argc, argv)
+	char **argv;
+{
+
+
+}