changeset 61:a10491da8c3a

fc-loadtool flash support: sector table generation implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 24 Jun 2013 17:46:15 +0000
parents 048329d0888e
children 6fb41cfa773d
files loadtools/flutil.c loadtools/ltflash.c
diffstat 2 files changed, 70 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/loadtools/flutil.c	Mon Jun 24 07:29:53 2013 +0000
+++ b/loadtools/flutil.c	Mon Jun 24 17:46:15 2013 +0000
@@ -32,3 +32,70 @@
 		count += word & 1;
 	return count;
 }
+
+get_flash_sector_table(bank)
+{
+	struct flash_bank_info *bi;
+	struct flash_region_desc *reg;
+	struct sector_info *sp;
+	uint32_t offset;
+	int i;
+
+	bi = flash_bank_info + bank;
+	if (bi->sectors)
+		return(0);
+	sp = (struct sector_info *) malloc(sizeof(struct sector_info)
+						* (bi->nsectors + 1));
+	if (!sp) {
+		fprintf(stderr,
+		"unable to malloc buffer for flash bank %d sector table\n",
+			bank);
+		return(-1);
+	}
+	bi->sectors = sp;
+	/* now fill it */
+	offset = 0;
+	for (reg = bi->bank_desc->regions; reg->nsectors; reg++) {
+		for (i = 0; i < reg->nsectors; i++) {
+			sp->start = offset;
+			sp->size = reg->sector_size;
+			sp++;
+			offset += reg->sector_size;
+		}
+	}
+	/* sanity checks */
+	if (sp - bi->sectors != bi->nsectors) {
+		fprintf(stderr,
+	"BUG in get_flash_sector_table(): wrong # of sectors at the end\n");
+		abort();
+	}
+	if (offset != bi->total_size) {
+		fprintf(stderr,
+		"BUG in get_flash_sector_table(): wrong offset at the end\n");
+		abort();
+	}
+	/* finish */
+	sp->start = 0;
+	sp->size = 0;
+	return(0);
+}
+
+flashcmd_sectors(argc, argv, bank)
+	char **argv;
+{
+	struct flash_bank_info *bi;
+	struct sector_info *sp;
+
+	if (argc > 2) {
+		fprintf(stderr, "error: too many arguments\n");
+		return(-1);
+	}
+	if (get_flash_sector_table(bank) < 0)
+		return(-1);
+	bi = flash_bank_info + bank;
+	printf("%u sectors in flash bank %d:\n", bi->nsectors, bank);
+	printf("Offset    Size\n");
+	for (sp = bi->sectors; sp->size; sp++)
+		printf("%08lX  %lx\n", (u_long) sp->start, (u_long) sp->size);
+	return(0);
+}
--- a/loadtools/ltflash.c	Mon Jun 24 07:29:53 2013 +0000
+++ b/loadtools/ltflash.c	Mon Jun 24 17:46:15 2013 +0000
@@ -247,6 +247,8 @@
 	return(0);
 }
 
+extern int flashcmd_sectors();
+
 static struct cmdtab {
 	char *cmd;
 	int (*func)();
@@ -255,6 +257,7 @@
 	{"dump2bin", flashcmd_dump2file},
 	{"dump2srec", flashcmd_dump2file},
 	{"info", flashcmd_info},
+	{"sectors", flashcmd_sectors},
 	{0, 0}
 };