Skip to contentSkip to conversation

Add support for boards where the NOR FLASH is not memory-mapped

PATCH Superseded Stefan Roese 2 participants 3 messages Dec 10, 2008 – Dec 11, 2008

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add support for boards where the NOR FLASH is not memory-mapped

This patch adds the CONFIG_FLASH_NOT_MEM_MAPPED define which can be used on boards where the NOR FLASH is not memory-mapped and special accessor functions are needed to access the NOR FLASH. This affects the memory commands (cmd_mem.c) and the environment (env_flash.c).

Boards using CONFIG_FLASH_NOT_MEM_MAPPED need to additionally specify CONFIG_FLASH_BASE and CONFIG_FLASH_END so that the NOR FLASH region can be detected.

This will be used by the upcoming VCTH board support.

---
v2:
- Added configuration option description to the README
- Fix bug in NOR FLASH end detection in env_flash.c (spotted by Wolfgang)
- Further "cleanup" of the env_flash code supporting non memory-mapped NOR FLASH.
- Macros in crc32.h now wrapped in "do { ... } while (0)" as suggested by Wolfgang

 README              |   17 ++++++++++++
 common/cmd_mem.c    |   66 +++++++++++++++++++++++++++++++++++++-----------
 common/env_flash.c  |   70 +++++++++++++++++++++++++++++++++++++++++---------
 lib_generic/crc32.c |   27 ++++++++++++++++---
 4 files changed, 148 insertions(+), 32 deletions(-)
README +17 -0
index 861ea83..0fd07a9 100644
@@ -2180,6 +2180,23 @@ Configuration Settings:
 		digits and dots.  Recommended value: 45 (9..1) for 80
 		column displays, 15 (3..1) for 40 column displays.
 
+- CONFIG_FLASH_NOT_MEM_MAPPED
+		Unfortunately there are boards, where the NOR FLASH can't
+		be accessed memory mapped. So we needed to find a way to
+		access those FLASH's from the CFI driver and the environment.
+		For the non-memory-mapped NOR FLASH, we need to define the
+		NOR FLASH area. This can't be detected via the addr2info()
+		function, since we check for flash access in the very early
+		U-Boot code, before the NOR FLASH is detected. So we need
+		to additionally define the following options to configure
+		the NOR FLASH range:
+
+		- CONFIG_FLASH_BASE
+			Starting address of the NOR FLASH area
+
+		- CONFIG_FLASH_END
+			Highest possible address of the NOR FLASH area
+
 - CONFIG_SYS_RX_ETH_BUFFER:
 		Defines the number of Ethernet receive buffers. On some
 		Ethernet controllers it is recommended to set this value
common/cmd_mem.c +51 -15

110 lines not on this page · raw message

common/env_flash.c +57 -13

127 lines not on this page · raw message

lib_generic/crc32.c +23 -4
index b6a7a91..51242d7 100644
@@ -148,10 +148,29 @@ const uint32_t * ZEXPORT get_crc_table()
 #endif
 
 /* ========================================================================= */
-#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
-#define DO2(buf)  DO1(buf); DO1(buf);
-#define DO4(buf)  DO2(buf); DO2(buf);
-#define DO8(buf)  DO4(buf); DO4(buf);
+#if defined(CONFIG_FLASH_NOT_MEM_MAPPED)
+u8 flash_read8(void *addr);
+#define DO1(buf)							\
+	do {								\
+		if (((u32)buf >= CONFIG_FLASH_BASE) &&			\
+		    ((u32)buf < CONFIG_FLASH_END)) {			\
+			crc = crc_table[ ((int)crc ^			\
+					 (flash_read8((void *)buf++))) & 0xff] ^ \
+				(crc >> 8);				\
+		} else {						\
+			crc = crc_table[((int)crc ^			\
+					 (*buf++)) & 0xff] ^ (crc >> 8); \
+		}							\
+	} while (0)
+#else
+#define DO1(buf)							\
+	do {								\
+		crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); \
+	} while (0)
+#endif
+#define DO2(buf)	do { DO1(buf); DO1(buf); } while (0)
+#define DO4(buf)	do { DO2(buf); DO2(buf); } while (0)
+#define DO8(buf)	do { DO4(buf); DO4(buf); } while (0)
 
 /* ========================================================================= */
 uint32_t ZEXPORT crc32 (uint32_t crc, const Bytef *buf, uInt len)
Signature · 1 line
1.6.0.5
#1 lore raw

PATCH v2 1/1 Add support for boards where the NOR FLASH is not memory-mapped

common/cmd_mem.c line 58

Quoted 4 lines · Stefan Roese
common/cmd_mem.c +4 -0
+void *board_flash_read_memcpy(void *__to, __const__ void *__from, int n);
+
+#if defined(CONFIG_FLASH_NOT_MEM_MAPPED)
+static inline int flash_read(void *__to, __const__ void *__from, int n)

__const__? The other underscores seem gratuitous as well.

common/cmd_mem.c line 69

Quoted 11 lines
common/cmd_mem.c +11 -0
+{
+#if defined(CONFIG_HAS_DATAFLASH)
+	return read_dataflash(__from, n, __to);
+#elif defined(CONFIG_FLASH_NOT_MEM_MAPPED)
+	if ((addr2info((u32)__from) != NULL))
+		board_flash_read_memcpy(__to, __from, n);
+	else
+		memcpy(__to, __from, n);
+	return OK;
+#endif
+}

What if a board has dataflash *and* NOR flash?

common/env_flash.c static ulong end_addr_new = CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1; · line 90

Quoted 11 lines
common/env_flash.c +3 -0
index 75ee8dd..ee7c4d7 100644
@@ -85,9 +85,50 @@ static ulong end_addr_new = CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1;
 extern uchar default_environment[];
 extern int default_environment_size;
 
+void *board_flash_read_memcpy(void *__to, __const__ void *__from, int n);
+u8 flash_read8(void *addr);
+u32 flash_read32(void *addr);

Should go in a header file.

common/env_flash.c static ulong end_addr_new = CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1; · line 96

Quoted 5 lines
common/env_flash.c +5 -0
+#if defined(CONFIG_FLASH_NOT_MEM_MAPPED)
+#define FLASH_READ_MEMCPY(d, s, n)	board_flash_read_memcpy(d, s, n)
+#else
+#define FLASH_READ_MEMCPY(d, s, n)	memcpy(d, s, n);
+#endif /* CONFIG_FLASH_NOT_MEM_MAPPED */

No semicolon after memcpy, or FLASH_READ_MEMCPY won't behave like a function call in certain contexts (if/else, for loops, etc).

common/env_flash.c static ulong end_addr_new = CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1; · line 107

Quoted 12 lines
common/env_flash.c +12 -0
+#define DO1(buf)							\
+	do {								\
+		if (((u32)buf >= CONFIG_FLASH_BASE) &&			\
+		    ((u32)buf < CONFIG_FLASH_END)) {			\
+			crc = crc_table[ ((int)crc ^			\
+					 (flash_read8((void *)buf++))) & 0xff] ^ \
+				(crc >> 8);				\
+		} else {						\
+			crc = crc_table[((int)crc ^			\
+					 (*buf++)) & 0xff] ^ (crc >> 8); \
+		}							\
+	} while (0)

Maybe make this an inline function?

-Scott

#2 lore raw

PATCH v2 1/1 Add support for boards where the NOR FLASH is not memory-mapped

Quoted 7 lines · Scott Wood

common/cmd_mem.c line 58

Quoted 4 lines · Stefan Roese

+void *board_flash_read_memcpy(void *__to, __const__ void *__from, int n); +

common/cmd_mem.c +2 -0
+#if defined(CONFIG_FLASH_NOT_MEM_MAPPED)
+static inline int flash_read(void *__to, __const__ void *__from, int n)

__const__? The other underscores seem gratuitous as well.

Not sure where I copied this from. I'll remove the underscores in the next version.

Quoted 5 lines
Quoted 5 lines
common/cmd_mem.c +5 -0
+{
+#if defined(CONFIG_HAS_DATAFLASH)
+	return read_dataflash(__from, n, __to);
+#elif defined(CONFIG_FLASH_NOT_MEM_MAPPED)
+	if ((addr2info((u32)__from) != NULL))
Quoted 8 lines

common/cmd_mem.c line 69

Quoted 6 lines
common/cmd_mem.c +6 -0
+		board_flash_read_memcpy(__to, __from, n);
+	else
+		memcpy(__to, __from, n);
+	return OK;
+#endif
+}

What if a board has dataflash *and* NOR flash?

You probably mean a board with dataflash *and* NOR FLASH that can't be accessed memory-mapped. We currently don't have such a board. The upcoming VCT board port is the first with such an (cumbersome) local bus interface. And I hope it will be the last.

Quoted 8 lines
Quoted 8 lines
common/env_flash.c +0 -0
index 75ee8dd..ee7c4d7 100644
@@ -85,9 +85,50 @@ static ulong end_addr_new = CONFIG_ENV_ADDR_REDUND +
 CONFIG_ENV_SECT_SIZE - 1; extern uchar default_environment[];
 extern int default_environment_size;
 
Quoted 5 lines

common/env_flash.c static ulong end_addr_new = CONFIG_ENV_ADDR_REDUND + · line 90

Quoted 3 lines
common/env_flash.c +2 -0
+void *board_flash_read_memcpy(void *__to, __const__ void *__from, int
 n); +u8 flash_read8(void *addr);
+u32 flash_read32(void *addr);

Should go in a header file.

OK.

Quoted 8 lines

common/env_flash.c static ulong end_addr_new = CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1; · line 96

Quoted 5 lines
common/env_flash.c +5 -0
+#if defined(CONFIG_FLASH_NOT_MEM_MAPPED)
+#define FLASH_READ_MEMCPY(d, s, n)	board_flash_read_memcpy(d, s, n)
+#else
+#define FLASH_READ_MEMCPY(d, s, n)	memcpy(d, s, n);
+#endif /* CONFIG_FLASH_NOT_MEM_MAPPED */

No semicolon after memcpy, or FLASH_READ_MEMCPY won't behave like a function call in certain contexts (if/else, for loops, etc).

Right. Thanks for spotting.

Quoted 6 lines
Quoted 6 lines
common/env_flash.c +6 -0
+#define DO1(buf)							\
+	do {								\
+		if (((u32)buf >= CONFIG_FLASH_BASE) &&			\
+		    ((u32)buf < CONFIG_FLASH_END)) {			\
+			crc = crc_table[ ((int)crc ^			\
+					 (flash_read8((void *)buf++))) & 0xff] ^ \
Quoted 8 lines

common/env_flash.c static ulong end_addr_new = CONFIG_ENV_ADDR_REDUND + · line 107

Quoted 6 lines
common/env_flash.c +6 -0
+				(crc >> 8);				\
+		} else {						\
+			crc = crc_table[((int)crc ^			\
+					 (*buf++)) & 0xff] ^ (crc >> 8); \
+		}							\
+	} while (0)

Maybe make this an inline function?

That would be a bigger change since this macro changes "buf" and "crc" without having those parameters passed to it. I didn't want to make this bigger change if not really necessary.

Best regards,
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
=====================================================================