changeset 58:1f9302b6f342

fc-loadtool: started flash/flash2 command implementation
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 24 Jun 2013 06:30:57 +0000
parents 10996c267de4
children c3158d30ff0c
files loadtools/ltdispatch.c loadtools/ltflash.c
diffstat 2 files changed, 125 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/loadtools/ltdispatch.c	Mon Jun 24 05:24:19 2013 +0000
+++ b/loadtools/ltdispatch.c	Mon Jun 24 06:30:57 2013 +0000
@@ -14,6 +14,7 @@
 extern int cmd_dump2srec();
 extern int cmd_exec();
 extern int cmd_exit();
+extern int cmd_flash();
 extern int loadtool_cmd_passthru();
 
 static struct cmdtab {
@@ -29,6 +30,8 @@
 	{"dump2srec", 3, 3, cmd_dump2srec},
 	{"exec", 1, 1, cmd_exec},
 	{"exit", 0, 1, cmd_exit},
+	{"flash", 1, 4, cmd_flash},
+	{"flash2", 1, 4, cmd_flash},
 	{"quit", 0, 1, cmd_exit},
 	{"r8", 1, 1, loadtool_cmd_passthru},
 	{"r16", 1, 1, loadtool_cmd_passthru},
--- a/loadtools/ltflash.c	Mon Jun 24 05:24:19 2013 +0000
+++ b/loadtools/ltflash.c	Mon Jun 24 06:30:57 2013 +0000
@@ -128,3 +128,125 @@
 		exit(1);
 	}
 }
+
+flashcmd_blankchk(argc, argv, bank)
+	char **argv;
+{
+	printf("To be implemented\n");
+	return(1);
+}
+
+flashcmd_dump2file(argc, argv, bank)
+	char **argv;
+{
+	struct flash_bank_info *bi;
+	u_long offset, dumplen, maxlen;
+	char *strtoul_endp;
+	int format;
+
+	if (argc < 3 || argc > 5) {
+inv:		fprintf(stderr, "usage: %s %s outfile [offset [length]]\n",
+			argv[0], argv[1]);
+		return(-1);
+	}
+	bi = flash_bank_info + bank;
+	if (argc >= 4) {
+		offset = strtoul(argv[3], &strtoul_endp, 16);
+		if (*strtoul_endp)
+			goto inv;
+		if (offset >= bi->total_size) {
+			fprintf(stderr,
+		"error: specified offset exceeds flash bank size (0x%lx)\n",
+				(u_long) bi->total_size);
+			return(-1);
+		}
+	} else
+		offset = 0;
+	maxlen = bi->total_size - offset;
+	if (argc >= 5) {
+		dumplen = strtoul(argv[4], &strtoul_endp, 16);
+		if (*strtoul_endp)
+			goto inv;
+		if (dumplen > maxlen) {
+			fprintf(stderr,
+	"error: specified offset+length exceed flash bank size (0x%lx)\n",
+				(u_long) bi->total_size);
+			return(-1);
+		}
+	} else
+		dumplen = maxlen;
+	switch (argv[1][5]) {
+	case 'b':
+		format = 0;
+		break;
+	case 's':
+		format = 1;
+		break;
+	default:
+		fprintf(stderr,
+			"internal bug: bad format in flashcmd_dump2file()\n");
+		return(-1);
+	}
+	return loadtool_memdump(bi->base_addr + offset, dumplen, argv[2],
+				format);
+}
+
+flashcmd_info(argc, argv, bank)
+	char **argv;
+{
+	struct flash_bank_info *bi;
+
+	if (argc > 2) {
+		fprintf(stderr, "error: too many arguments\n");
+		return(-1);
+	}
+	bi = flash_bank_info + bank;
+	printf("Flash device type: %s\n", selected_flash_device->name);
+	printf("Bank %d base address: %08lX\n", bank, (u_long) bi->base_addr);
+	printf("Bank %d total size: %lx\n", bank, (u_long) bi->total_size);
+	printf("Sectors in bank %d: %u\n", bank, bi->nsectors);
+	if (selected_flash_device->nbanks == 2 && !bank)
+	    printf("\nFlash device has 2 banks; flash2 command available\n");
+	return(0);
+}
+
+static struct cmdtab {
+	char *cmd;
+	int (*func)();
+} cmdtab[] = {
+	{"blankchk", flashcmd_blankchk},
+	{"dump2bin", flashcmd_dump2file},
+	{"dump2srec", flashcmd_dump2file},
+	{"info", flashcmd_info},
+	{0, 0}
+};
+
+cmd_flash(argc, argv)
+	char **argv;
+{
+	int bank;
+	struct cmdtab *tp;
+
+	if (!selected_flash_device) {
+		fprintf(stderr, "No flash configuration defined\n");
+		return(-1);
+	}
+	if (argv[0][5] == '2') {
+		if (selected_flash_device->nbanks < 2) {
+			fprintf(stderr, "Flash device %s has only one bank\n",
+				selected_flash_device->name);
+			return(-1);
+		}
+		bank = 1;
+	} else
+		bank = 0;
+	for (tp = cmdtab; tp->cmd; tp++)
+		if (!strcmp(tp->cmd, argv[1]))
+			break;
+	if (!tp->func) {
+		fprintf(stderr, "%s %s: unknown/unimplemented subcommand\n",
+			argv[0], argv[1]);
+		return(-1);
+	}
+	return tp->func(argc, argv, bank);
+}