Skip to contentSkip to conversation

cfi_flash: Cleanup flash_print_info()

PATCH New Stefan Roese 1 participant 2 messages Aug 13, 2010 – Aug 18, 2010 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cfi_flash: Cleanup flash_print_info()

This patch does the following:

- Extract code to detect if sector is erased into function sector_erased().
- Because of this, we don't have variable declarations inside the sector loop in flash_print_info()
- Change "return" to "break" in the "if (ctrlc()) statement:
This fixes a problem with the resulting output. Before this patch the output was:

Sector Start Addresses:
FC000000 FC020000 FC040000 =>

With this patch it is now:

Sector Start Addresses:
FC000000 FC020000 FC040000
=>

Cc Kim Phillips <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 drivers/mtd/cfi_flash.c |   51 ++++++++++++++++++++++++----------------------
 1 files changed, 27 insertions(+), 24 deletions(-)
drivers/mtd/cfi_flash.c +27 -24
index 2157c02..1191ef0 100644
@@ -1096,8 +1096,30 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
 	return rcode;
 }
 
-/*-----------------------------------------------------------------------
- */
+#ifdef CONFIG_SYS_FLASH_EMPTY_INFO
+static int sector_erased(flash_info_t *info, int i)
+{
+	int k;
+	int size;
+	volatile unsigned long *flash;
+
+	/*
+	 * Check if whole sector is erased
+	 */
+	size = flash_sector_size(info, i);
+	flash = (volatile unsigned long *) info->start[i];
+	/* divide by 4 for longword access */
+	size = size >> 2;
+
+	for (k = 0; k < size; k++) {
+		if (*flash++ != 0xffffffff)
+			return 0;	/* not erased */
+	}
+
+	return 1;			/* erased */
+}
+#endif /* CONFIG_SYS_FLASH_EMPTY_INFO */
+
 void flash_print_info (flash_info_t * info)
 {
 	int i;
@@ -1162,33 +1184,14 @@ void flash_print_info (flash_info_t * info)
 	puts ("\n  Sector Start Addresses:");
 	for (i = 0; i < info->sector_count; ++i) {
 		if (ctrlc())
-			return;
+			break;
 		if ((i % 5) == 0)
-			printf ("\n");
+			putc('\n');
 #ifdef CONFIG_SYS_FLASH_EMPTY_INFO
-		int k;
-		int size;
-		int erased;
-		volatile unsigned long *flash;
-
-		/*
-		 * Check if whole sector is erased
-		 */
-		size = flash_sector_size(info, i);
-		erased = 1;
-		flash = (volatile unsigned long *) info->start[i];
-		size = size >> 2;	/* divide by 4 for longword access */
-		for (k = 0; k < size; k++) {
-			if (*flash++ != 0xffffffff) {
-				erased = 0;
-				break;
-			}
-		}
-
 		/* print empty and read-only info */
 		printf ("  %08lX %c %s ",
 			info->start[i],
-			erased ? 'E' : ' ',
+			sector_erased(info, i) ? 'E' : ' ',
 			info->protect[i] ? "RO" : "  ");
 #else	/* ! CONFIG_SYS_FLASH_EMPTY_INFO */
 		printf ("  %08lX   %s ",
Signature · 1 line
1.7.2.1
#1 lore raw

PATCH 1/1 cfi_flash: Cleanup flash_print_info()

Quoted 10 lines · On Friday 13 August 2010 12:43:02 Stefan Roese wrote:

This patch does the following:

- Extract code to detect if sector is erased into function sector_erased().
- Because of this, we don't have variable declarations inside the sector loop in flash_print_info()
- Change "return" to "break" in the "if (ctrlc()) statement:
This fixes a problem with the resulting output. Before this patch the output was:

Quoted 8 lines

Sector Start Addresses:
FC000000 FC020000 FC040000 =>

With this patch it is now:

Sector Start Addresses:
FC000000 FC020000 FC040000
=>

Applied to u-boot-cfi-flash/master. Thanks.

Cheers,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de