Hi all,

The attached patch makes a (n admittedly not very pretty, but minimal)
change to powerpc/shared/flash/flash.c so that it won't try to erase a
flash segment just because the existing contents aren't all-1s. Now, so
long as no bits would have to be changed from a 0 to a 1 an erase is not
necessarily required.

With this change I've been able to use the spansionFlash driver to bring
up a JFFS2 file-system, reading and writing files, which failed without.
-- 
Nick Withers

Embedded Systems Programmer
Department of Nuclear Physics, Research School of Physics and Engineering
The Australian National University (CRICOS: 00120C)
>From f9672901b5e3a9a0d4982b3327a83415a0bdcaf5 Mon Sep 17 00:00:00 2001
From: Nick Withers <nick.with...@anu.edu.au>
Date: Fri, 17 Jan 2014 12:41:25 +1100
Subject: [PATCH] A flash erase cycle is not required unless a change of a bit
 from a 0 to a 1 is requested

---
 c/src/lib/libbsp/powerpc/shared/flash/flash.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/c/src/lib/libbsp/powerpc/shared/flash/flash.c b/c/src/lib/libbsp/powerpc/shared/flash/flash.c
index ebd38cf..4efd3a1 100644
--- a/c/src/lib/libbsp/powerpc/shared/flash/flash.c
+++ b/c/src/lib/libbsp/powerpc/shared/flash/flash.c
@@ -519,7 +519,7 @@ regionCheckAndErase(int bank, uint32_t offset, char *src, uint32_t n_bytes, int
 struct bankdesc *b;
 uint32_t         i;
 char            *p;
-uint32_t		a,e;
+uint32_t         a,e;
 
 	if ( ! (b = argcheck(bank, offset, src, n_bytes)) )
 		return -1;
@@ -534,7 +534,8 @@ uint32_t		a,e;
 		a += b->fblksz;
 		i  = ( a > offset + n_bytes ) ? offset + n_bytes : a;
 		for ( p = (char*)(b->start + offset); p < (char*)(b->start + i); p++ ) {
-			if ( (char)0xff != *p ) {
+			/* Check that there are no bits in *p that would need to be set, requiring an erase */
+			if ( ~(*p) & *(src + (p - ((char *) (b->start + offset)))) ) {
 				if ( ! quiet ) {
 					fprintf(stderr,"Starting offset not block-aligned and destination area not empty.\n");
 					fprintf(stderr,"I'll need to erase data below destination start\n");
@@ -548,7 +549,8 @@ uint32_t		a,e;
 		e -= b->fblksz;
 		i  = ( e < offset ) ? offset : e;
 		for ( p = (char*)(b->start + i); p < (char*)(b->start + offset + n_bytes); p++ ) {
-			if ( (char)0xff != *p ) {
+			/* Check that there are no bits in *p that would need to be set, requiring an erase */
+			if ( ~(*p) & *(src + (p - ((char *) (b->start + i)))) ) {
 				if ( ! quiet ) {
 					fprintf(stderr,"Ending offset not block-aligned and destination area not empty.\n");
 					fprintf(stderr,"I'll need to erase data beyond destination end\n");
-- 
1.8.5.2

_______________________________________________
rtems-devel mailing list
rtems-devel@rtems.org
http://www.rtems.org/mailman/listinfo/rtems-devel

Reply via email to