changeset 204:61c7480b3c50

fc-loadtool: flash idcheck standalone command implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 23 Dec 2013 08:49:38 +0000
parents 99c234bf6a9b
children cd12d1049f91
files loadtools/flutil.c loadtools/ltflash.c
diffstat 2 files changed, 69 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/loadtools/flutil.c	Mon Dec 23 07:26:37 2013 +0000
+++ b/loadtools/flutil.c	Mon Dec 23 08:49:38 2013 +0000
@@ -147,3 +147,70 @@
 	}
 	*s = '\0';
 }
+
+flash_id_check(bank, repeat)
+{
+	struct flash_bank_info *bi;
+	struct flash_bank_desc *bd;
+	struct flash_idcheck *id;
+	int stat, fail;
+	uint16_t rdval;
+	unsigned cnt;
+
+	bi = flash_bank_info + bank;
+	if (bi->idcheck_done && !repeat)
+		return(0);
+	printf("Performing flash ID check\n");
+	stat = do_w16(bi->base_addr + 0xAAA, 0xAA);
+	if (stat) {
+bad_w16:	fprintf(stderr,
+	"unexpected response to w16 in read ID cmd sequence - aborting\n");
+		return(-1);
+	}
+	stat = do_w16(bi->base_addr + 0x554, 0x55);
+	if (stat)
+		goto bad_w16;
+	stat = do_w16(bi->base_addr + 0xAAA, 0x90);
+	if (stat)
+		goto bad_w16;
+	bd = bi->bank_desc;
+	id = bd->idcheck_table;
+	fail = 0;
+	for (cnt = 0; cnt < bd->idcheck_num; cnt++) {
+		stat = do_r16(bi->base_addr + id->offset, &rdval);
+		if (stat)
+			return(stat);	/* error msg already printed */
+		printf("offset %02X: %04X -- ", (int)id->offset, (int)rdval);
+		if (rdval == id->expect_val)
+			printf("PASS\n");
+		else {
+			printf("FAIL: expected %04X\n", (int)id->expect_val);
+			fail = 1;
+			break;
+		}
+		id++;
+	}
+	/* reset flash to read mode */
+	stat = do_w16(bi->base_addr + 0xAAA, 0xF0);
+	if (stat) {
+		fprintf(stderr,
+	"unexpected response to w16 when resetting flash to read mode!\n");
+		return(-1);
+	}
+	if (fail)
+		return(-1);
+	bi->idcheck_done = 1;
+	return(0);
+}
+
+flashcmd_idcheck(argc, argv, bank)
+	char **argv;
+{
+	struct flash_bank_info *bi;
+
+	if (argc > 2) {
+		fprintf(stderr, "error: too many arguments\n");
+		return(-1);
+	}
+	return flash_id_check(bank, 1);
+}
--- a/loadtools/ltflash.c	Mon Dec 23 07:26:37 2013 +0000
+++ b/loadtools/ltflash.c	Mon Dec 23 08:49:38 2013 +0000
@@ -313,6 +313,7 @@
 }
 
 extern int flashcmd_erase();
+extern int flashcmd_idcheck();
 extern int flashcmd_progbin();
 extern int flashcmd_program_m0();
 extern int flashcmd_program_srec();
@@ -327,6 +328,7 @@
 	{"dump2srec", flashcmd_dump2file},
 	{"erase", flashcmd_erase},
 	{"help", flashcmd_help},
+	{"idcheck", flashcmd_idcheck},
 	{"info", flashcmd_info},
 	{"program-bin", flashcmd_progbin},
 	{"program-m0", flashcmd_program_m0},