Add support for boards where the NOR FLASH is not memory-mapped
PATCH v4 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 VCT board support.
---
v4:
- Fix a problem with "normal" NOR FLASH in "cp" command
v3:
- Removed some gratuitous underscores in function parameters
- Prototypes moved to header (common.h)
- Removed ";" after macro definition
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 | 62 ++++++++++++++++++++++++++++++++++++----------- common/env_flash.c | 66 +++++++++++++++++++++++++++++++++++++++++---------- include/common.h | 8 ++++++ lib_generic/crc32.c | 26 +++++++++++++++++--- 5 files changed, 147 insertions(+), 32 deletions(-)
README +17 -0
@@ -2198,6 +2198,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 +47 -15
106 lines not on this page · raw message
common/env_flash.c +53 -13
123 lines not on this page · raw message
include/common.h +8 -0
@@ -716,6 +716,14 @@ int cpu_reset(int nr);int cpu_release (int nr,int argc,char *argv[]);#endif +/* +* Functions only needed when CONFIG_FLASH_NOT_MEM_MAPPED is defined +* for boards where the NOR FLASH can't be accessed memory-mapped. +*/ +void *board_flash_read_memcpy (void *to,const void *from,size_t n); +u8 flash_read8 (void *addr); +u32 flash_read32 (void *addr); +#ifdef CONFIG_POST #define CONFIG_HAS_POST #endif
lib_generic/crc32.c +22 -4
@@ -148,10 +148,28 @@ 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 ) +#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