您的位置:首页 > 其它

fl2440的U-boot-2010.09移植(四) 添加NOR Flash启动支持

2012-06-27 13:45 423 查看
          我们知道S3C2440支持从NAND Flash启动和从NOR Flash启动两种模式,先来介绍u-boot的NOR Flash启动方式吧。

一、修改NOR Flash的读写程序

        FL2440开发板中使用的NOR Flash是Intel的J3系列存储大小是4M字节,这个系列的NOR Flash支持标准的CFI指令(在最新的U-boot版本中只需要添加宏定义就可以支持CFI接口的NOR Flash了,但我们这个版本中还不行),将board/cmi/flash.c复制到board/fl2440/flash.c,这个文件中包含了我们开发板的NOR Flash读写函数,但是其中还有一点问题,需要修改flash.c文件中的函数write_buff,此函数需要将小端字节数进行short类型变换,即将低地址数放在低位,高地址数放在高位另外还要进行地址对其,因为该型号flash只支持16位写,不支持8位写,那么我们写8位时需要从flash中读取出不改写8位,在加上需要改写的8位组成16位后回写到flash中去,具体将原flash.c中的函数write_buff修改如下:

int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
{
ulong cp, wp;
ushort data;
int i, rc;

if (info->flash_id == FLASH_UNKNOWN) {
return 4;
}

wp = (addr & ~1);	/* get lower word aligned address */

/*
* handle unaligned start byte
*/

/* for not to modify the origin data in flash*/

if (addr - wp) {
data = 0;
for(i = 0, cp = wp; i < 1; ++i, ++cp){
data = (data >> 8) | (*(uchar *) cp << 8);
}
for(; i < 2 && cnt > 0; ++i){
data = (data >> 8) | (*src++ <<8);
--cnt;
++cp;
}
for(; cnt == 0 && i < 2; ++i, ++cp){
data = (data >> 8) | (*(uchar *) cp << 8);
}
if ((rc = write_short(info, wp, data)) != 0) {
return (rc);
}
wp += 2;
}

/*
* handle word aligned part
*/

while (cnt >= 2) {
/*data = 0;
for (i=0; i<2; ++i) {
data = (data << 8) | *src++;
}*/
data = *((vu_short *) src) ;

if ((rc = write_short(info, wp, data)) != 0) {
return (rc);
}
src += 2;
wp  += 2;
cnt -= 2;
}

if (cnt == 0) {
return (0);
}

/*
* handle unaligned tail bytes
* read the origin high byte data and write again!
* modified by yanghao
*/

data = 0;
for (i=0, cp=wp; i<2 && cnt>0; ++i, ++cp) {
data = (data >> 8) | (*src++ << 8);
--cnt;
}
for (; i<2; ++i, ++cp) {
data = (data >> 8) | (*(uchar *)cp << 8);
}

return (write_short(info, wp, data));

}

还需要将flash.c文件中的NOR Flash块大小进行修改:

#define FLASH_BLOCK_SIZE  0x00020000       //数据手册p8说了32Mbit有32个128kBytes block组成

二、修改开发板头文件中的宏定义

为了添加对NOR Flash启动的支持,还需要在include/configs/fl2440.h头文件中添加对NOR Flash的信息描述和支持,将fl2440.h文件中159行附近:

#define CONFIG_AMD_LV400	1	/* uncomment this if you have a LV400 flash */
#if 0
#define CONFIG_AMD_LV800	1	/* uncomment this if you have a LV800 flash */
#endif

#define CONFIG_SYS_MAX_FLASH_BANKS	1	/* max number of memory banks */
#ifdef CONFIG_AMD_LV800
#define PHYS_FLASH_SIZE		0x00100000 /* 1MB */
#define CONFIG_SYS_MAX_FLASH_SECT	(19)	/* max number of sectors on one chip */
#define CONFIG_ENV_ADDR		(CONFIG_SYS_FLASH_BASE + 0x0F0000) /* addr of environment */
#endif
#ifdef CONFIG_AMD_LV400
#define PHYS_FLASH_SIZE		0x00080000 /* 512KB */
#define CONFIG_SYS_MAX_FLASH_SECT	(11)	/* max number of sectors on one chip */
#define CONFIG_ENV_ADDR		(CONFIG_SYS_FLASH_BASE + 0x070000) /* addr of environment */
#endif

全部删除,并修改为:

#define CONFIG_SYS_MAX_FLASH_BANKS	1	/* max number of memory banks */
#ifdef CONFIG_FL2440
#define PHYS_FLASH_SIZE		0x00400000 /* 4MB */
#define CONFIG_SYS_MAX_FLASH_SECT	(32)	/* max number of sectors on one chip */
#define CONFIG_ENV_ADDR		(CONFIG_SYS_FLASH_BASE + 0x0F0000) /* addr of environment */
#define CONFIG_SYS_MONITOR_BASE  TEXT_BASE  /*CMI/flash.c need*/
#define FLASH_BASE0_PRELIM      PHYS_FLASH_1      /*CMI/flash.c need*/
#endif

并将文件中

#define CONFIG_ENV_SIZE  0x10000 /* Total Size of Environment

修改为:

#define CONFIG_ENV_SIZE  0x20000 /* Total Size of Environment

再执行make,生成的u-boot.bin就可以烧写入NOR Flash中了(可以使用JLINK软件包中的JFlash来完成烧写过程),设置开发板启动方式为NOR Flash启动,再次上电启动NOR Flash就完成u-boot的启动了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐