TQ2440移植u-boot2016.11 NOR FLASH驱动移植
TQ2440开发板上板载一片NOR FLASH,型号为EON EN29LV160AB
,挂载到了0x0000_0000~0x001F_FFFF地址,2M字节,16bit位宽。
编辑配置头文件:
gedit include/configs/tq2440.h
定位到NOR Flash的配置宏:
/*-----------------------------------------------------------------------
* FLASH and environment organization
*/
#define CONFIG_SYS_FLASH_CFI
#define CONFIG_FLASH_CFI_DRIVER
#define CONFIG_FLASH_CFI_LEGACY
#define CONFIG_SYS_FLASH_LEGACY_512Kx16
#define CONFIG_FLASH_SHOW_PROGRESS 45
#define CONFIG_SYS_MAX_FLASH_BANKS 1
#define CONFIG_SYS_FLASH_BANKS_LIST { CONFIG_SYS_FLASH_BASE }
#define CONFIG_SYS_MAX_FLASH_SECT (19)
#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000)
#define CONFIG_ENV_IS_IN_FLASH
#define CONFIG_ENV_SIZE 0x10000
/* allow to overwrite serial and ethaddr */
#define CONFIG_ENV_OVERWRITE
替换为:
/*-----------------------------------------------------------------------
* FLASH and environment organization
*/
#define CONFIG_SYS_FLASH_CFI
#define CONFIG_FLASH_CFI_DRIVER
#define CONFIG_FLASH_CFI_LEGACY
#define CONFIG_SYS_FLASH_LEGACY_1024Kx16 /* NOR FLASH 大小为2M字节,16位宽 */
#define CONFIG_FLASH_SHOW_PROGRESS 45
#define CONFIG_SYS_MAX_FLASH_BANKS 1 /* NOR FLASH 数量,TQ2440板子上只有一个 */
#define CONFIG_SYS_FLASH_BANKS_LIST { CONFIG_SYS_FLASH_BASE }
#define CONFIG_SYS_MAX_FLASH_SECT (35) /* NOR FLASH 扇区数目 */
#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x100000) /* 环境变量保存位置 */
#define CONFIG_ENV_IS_IN_FLASH /* 定义该宏后环境变量保存入NOR FLASH */
#define CONFIG_ENV_SIZE 0x10000 /* 环境变量大小为64K */
#define CONFIG_ENV_OVERWRITE /* 允许覆写环境变量 */
其中CONFIG_ENV_ADDR
定义了环境变量保存的位置,使用命令ls -hl u-boot.bin
查看一下u-boot的大小为521K大小,那么环境变量的位置就必须大于这个地址,否则就会把u-boot的内存覆盖掉,这里我设置的为0x100000
,在NOR Flash的1M地址处保存环境变量。
添加TQ2440板子上的NOR Flash的初始化选项:
gedit drivers/mtd/jedec_flash.c
找到jedec_table
这个数组,在该数组末尾加入以下代码:
#ifdef CONFIG_SYS_FLASH_LEGACY_1024Kx16
{
.mfr_id = 0x1C,
.dev_id = 0x2249,
.name = "EON EN29LV160AB",
.uaddr = {
[1] = MTD_UADDR_0x0555_0x02AA /* x16 */
},
.DevSize = SIZE_2MiB,
.CmdSet = P_ID_AMD_STD,
.NumEraseRegions = 4,
.regions = {
ERASEINFO(0x04000, 1),
ERASEINFO(0x02000, 2),
ERASEINFO(0x08000, 1),
ERASEINFO(0x10000, 31),
}
},
#endif
编译后使用tftp下载到开发板0x30008000处可以并go到0x30008000地址处运行程序,可以看到已经正确识别出Nor Flash的大小:
下面测试一下NOR FLASH的读写:
- 去除写保护:
protect off all
- 擦除从0x100000地址开始的64K,从0x100000地址处开始是为了避开自带的u-boot:
erase 0x100000 +0x10000
- 拷贝内存64K的内容到NOR FLASH:
cp.b 0x30008000 0x100000 0x10000
- 读取Nor Flash 64K内容到内存:
cp.b 0x100000 0x30108000 0x10000
- 比较64K数据:
cmp.b 0x30108000 0x30008000 0x10000
读出的与写入的一致,测试通过:
ends…