changeset 415:b2487cfd68fd

fc-loadtool: flash erase-program-boot implementation complete
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 17 Jun 2014 06:31:27 +0000
parents a2df77833c21
children c2e14cc15c23
files loadtools/flcmplboot.c loadtools/flmain.c
diffstat 2 files changed, 97 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/loadtools/flcmplboot.c	Tue Jun 17 05:46:21 2014 +0000
+++ b/loadtools/flcmplboot.c	Tue Jun 17 06:31:27 2014 +0000
@@ -77,6 +77,42 @@
 	hack_enabled = 1;
 }
 
+static void
+make_s3_record(buf, dest_addr, datalen)
+	u_char *buf;
+	uint32_t dest_addr;
+{
+	int totlen, i;
+	u_char accum;
+
+	buf[0] = totlen = datalen + 5;
+	buf[1] = dest_addr >> 24;
+	buf[2] = dest_addr >> 16;
+	buf[3] = dest_addr >> 8;
+	buf[4] = dest_addr;
+	accum = 0;
+	for (i = 0; i < totlen; i++)
+		accum += buf[i];
+	buf[i] = ~accum;
+}
+
+static void
+make_ml_arg(rec, buf)
+	u_char *rec;
+	char *buf;
+{
+	register int i, len;
+	register char *s;
+
+	len = rec[0] + 1;
+	s = buf;
+	for (i = 0; i < len; i++) {
+		sprintf(s, "%02X", rec[i]);
+		s += 2;
+	}
+	*s = '\0';
+}
+
 flashcmd_erase_program_boot(argc, argv)
 	char **argv;
 {
@@ -84,6 +120,11 @@
 	struct stat filestat;
 	size_t len;
 	char *strtoul_endp;
+	char *targv[5], longarg[513];
+	char shortarg1[9], shortarg2[9], shortarg3[9];
+	u_char databuf[256];
+	int reclen, cc;
+	uint32_t ramaddr, remlen;
 
 	if (!hack_enabled) {
 		fprintf(stderr,
@@ -139,6 +180,59 @@
 		fclose(binf);
 		return(-1);
 	}
-
+	if (len & 1) {
+		fprintf(stderr, "error: length must be even\n");
+		fclose(binf);
+		return(-1);
+	}
 
+	printf("Loading new boot code into target RAM at %lx\n",
+		(u_long) ram_buffer_addr);
+	targv[0] = "ML";
+	targv[1] = longarg;
+	targv[2] = 0;
+	ramaddr = ram_buffer_addr;
+	for (remlen = len; remlen; remlen -= reclen) {
+		if (remlen >= 250)
+			reclen = 250;
+		else
+			reclen = remlen;
+		cc = fread(databuf + 5, 1, reclen, binf);
+		if (cc != reclen) {
+			fclose(binf);
+			fprintf(stderr, "error reading from %s\n", argv[2]);
+			return(-1);
+		}
+		make_s3_record(databuf, ramaddr, reclen);
+		make_ml_arg(databuf, longarg);
+		tpinterf_make_cmd(targv);
+		if (tpinterf_send_cmd() < 0) {
+			fclose(binf);
+			return(-1);
+		}
+		cc = tpinterf_pass_output(1);
+		if (cc) {
+			fclose(binf);
+			return(cc);
+		}
+		ramaddr += reclen;
+		putchar('.');
+		fflush(stdout);
+	}
+	putchar('\n');
+	fclose(binf);
+
+	printf("Commanding flash erase+program operation on the target\n");
+	sprintf(shortarg1, "%lx", (u_long) ram_buffer_addr);
+	sprintf(shortarg2, "%lx", (u_long) flash_bank_info[0].base_addr);
+	sprintf(shortarg3, "%lx", (u_long) len);
+	targv[0] = "intel-rewrite-sector";
+	targv[1] = shortarg1;
+	targv[2] = shortarg2;
+	targv[3] = shortarg3;
+	targv[4] = 0;
+	tpinterf_make_cmd(targv);
+	if (tpinterf_send_cmd() < 0)
+		return(-1);
+	return tpinterf_pass_output(20);	/* 20 s timeout */
 }
--- a/loadtools/flmain.c	Tue Jun 17 05:46:21 2014 +0000
+++ b/loadtools/flmain.c	Tue Jun 17 06:31:27 2014 +0000
@@ -197,6 +197,7 @@
 extern int flashcmd_blankchk();
 extern int flashcmd_dump2file();
 extern int flashcmd_erase();
+extern int flashcmd_erase_program_boot();
 extern int flashcmd_progbin();
 extern int flashcmd_program_m0();
 extern int flashcmd_program_srec();
@@ -214,6 +215,7 @@
 	{"dump2bin", flashcmd_dump2file},
 	{"dump2srec", flashcmd_dump2file},
 	{"erase", flashcmd_erase},
+	{"erase-program-boot", flashcmd_erase_program_boot},
 	{"help", flashcmd_help},
 	{"info", flashcmd_info},
 	{"program-bin", flashcmd_progbin},