diff loadtools/flutil.c @ 400:f027c6fbe37e

fc-loadtool flash: first round of refactoring for CFI
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 15 Jun 2014 20:05:54 +0000
parents cd12d1049f91
children 7602443edf0d
line wrap: on
line diff
--- a/loadtools/flutil.c	Sun Jun 15 00:47:06 2014 +0000
+++ b/loadtools/flutil.c	Sun Jun 15 20:05:54 2014 +0000
@@ -10,42 +10,35 @@
 
 extern struct flash_bank_info flash_bank_info[2];
 
-compute_flash_totsize_nsecs(bank)
+flash_get_cfi(bank)
 {
 	struct flash_bank_info *bi;
-	struct flash_region_desc *reg;
 
 	bi = flash_bank_info + bank;
-	for (reg = bi->bank_desc->regions; reg->nsectors; reg++) {
-		bi->nsectors += reg->nsectors;
-		bi->total_size += reg->sector_size * reg->nsectors;
-	}
-}
-
-/* the following function is used to verify that total_size is a power of 2 */
-count_ones(word)
-	uint32_t word;
-{
-	int count;
-
-	for (count = 0; word; word >>= 1)
-		count += word & 1;
-	return count;
+	if (bi->cfi)
+		return(0);
+	printf("Error: CFI info retrieval not implemented yet\n");
+	return(-1);
 }
 
 get_flash_sector_table(bank)
 {
 	struct flash_bank_info *bi;
+	struct cfi_info *cfi;
 	struct flash_region_desc *reg;
 	struct sector_info *sp;
 	uint32_t offset;
-	int i;
+	int nr, i;
 
 	bi = flash_bank_info + bank;
 	if (bi->sectors)
 		return(0);
+	i = flash_get_cfi(bank);
+	if (i < 0)
+		return(i);
+	cfi = bi->cfi;
 	sp = (struct sector_info *) malloc(sizeof(struct sector_info)
-						* (bi->nsectors + 1));
+						* (cfi->total_sectors + 1));
 	if (!sp) {
 		fprintf(stderr,
 		"unable to malloc buffer for flash bank %d sector table\n",
@@ -55,7 +48,8 @@
 	bi->sectors = sp;
 	/* now fill it */
 	offset = 0;
-	for (reg = bi->bank_desc->regions; reg->nsectors; reg++) {
+	for (nr = 0; nr < cfi->nregions; nr++) {
+		reg = cfi->regions + nr;
 		for (i = 0; i < reg->nsectors; i++) {
 			sp->start = offset;
 			sp->size = reg->sector_size;
@@ -64,12 +58,12 @@
 		}
 	}
 	/* sanity checks */
-	if (sp - bi->sectors != bi->nsectors) {
+	if (sp - bi->sectors != cfi->total_sectors) {
 		fprintf(stderr,
 	"BUG in get_flash_sector_table(): wrong # of sectors at the end\n");
 		abort();
 	}
-	if (offset != bi->total_size) {
+	if (offset != cfi->total_size) {
 		fprintf(stderr,
 		"BUG in get_flash_sector_table(): wrong offset at the end\n");
 		abort();
@@ -93,7 +87,7 @@
 	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("%u sectors in flash bank %d:\n", bi->cfi->total_sectors, bank);
 	printf("Offset    Size\n");
 	for (sp = bi->sectors; sp->size; sp++)
 		printf("%08lX  %lx\n", (u_long) sp->start, (u_long) sp->size);
@@ -160,6 +154,9 @@
 	bi = flash_bank_info + bank;
 	if (bi->idcheck_done && !repeat)
 		return(0);
+	bd = bi->bank_desc;
+	if (!bd->idcheck_table || !bd->idcheck_num)
+		return(0);
 	printf("Performing flash ID check\n");
 	stat = do_w16(bi->base_addr + 0xAAA, 0xAA);
 	if (stat) {
@@ -173,7 +170,6 @@
 	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++) {