diff loadtools/flerase.c @ 669:ba9523ca6ed8

fc-loadtool code: preparations for e-program-* addition
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 08 Mar 2020 01:32:08 +0000
parents cd48bc4c5460
children 185c9bf208d3
line wrap: on
line diff
--- a/loadtools/flerase.c	Sun Mar 08 00:29:11 2020 +0000
+++ b/loadtools/flerase.c	Sun Mar 08 01:32:08 2020 +0000
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <time.h>
 #include "flash.h"
+#include "discontig.h"
 
 extern struct flash_bank_info flash_bank_info[2];
 
@@ -55,7 +56,7 @@
 		return(0);
 	}
 	/* now enforce sector alignment for both offset and length */
-	if (get_flash_sector_table(bank) < 0)
+	if (get_flash_sector_table(bi) < 0)
 		return(-1);
 	if (get_flash_sector_range(bi, offset, len, &startsec, &endsec) < 0)
 		return(-1);
@@ -76,3 +77,56 @@
 	printf("Operation completed in %um%us\n", mm, ss);
 	return(0);
 }
+
+erase_sectors_for_prog(bi, regions, nregions)
+	struct flash_bank_info *bi;
+	struct discontig_prog *regions;
+	unsigned nregions;
+{
+	struct sector_info *seclist[256], **seclp, **secendp, *sp;
+	struct discontig_prog *regp, *regendp;
+	uint32_t endaddr, secendaddr;
+	int flag, stat;
+	time_t start_time, finish_time;
+	unsigned duration, mm, ss;
+
+	if (get_flash_sector_table(bi) < 0)
+		return(-1);
+	seclp = seclist;
+	endaddr = regions[nregions-1].end;
+	regendp = regions + nregions;
+	for (sp = bi->sectors; sp->size; sp++) {
+		if (sp->start >= endaddr)
+			break;
+		secendaddr = sp->start + sp->size;
+		flag = 0;
+		for (regp = regions; regp < regendp; regp++) {
+			if (regp->start >= secendaddr)
+				break;
+			if (sp->start >= regp->end)
+				continue;
+			flag = 1;
+			break;
+		}
+		if (flag)
+			*seclp++ = sp;
+	}
+	secendp = seclp;
+	printf("Erasing %d sector(s)\n", secendp - seclist);
+	time(&start_time);
+	for (seclp = seclist; seclp < secendp; seclp++) {
+		sp = *seclp;
+		stat = bi->ops->erase_sector(bi, sp);
+		if (stat)
+			return(stat);
+		putchar('.');
+		fflush(stdout);
+	}
+	time(&finish_time);
+	putchar('\n');
+	duration = finish_time - start_time;
+	mm = duration / 60;
+	ss = duration - mm * 60;
+	printf("Operation completed in %um%us\n", mm, ss);
+	return(0);
+}