如果没有Nor FLASH的同学可以跳过这一章节,直接进行下一张节。如果遇到什么问题,一般都是你没有定义那个宏之类的,这个问题可以很好的额解决。
修改norflash(nor fhash型号:JS28F320)的配置,把include/configs/fl2440.h中关于“Physical Memory Map”和“FLASH and environment organization”的配置都删掉,换成下面的配置:
~~~
- /*-----------------------------------------------------------------------
* Physical Memory Map
*/
#define CONFIG_NR_DRAM_BANKS1 /* we have 1 bank of DRAM */
#define PHYS_SDRAM_10x30000000 /* SDRAM Bank #1 */
#define PHYS_SDRAM_1_SIZE0x04000000 /* 64 MB */
#define PHYS_FLASH_10x00000000 /* Flash Bank #1 */
#define CONFIG_SYS_FLASH_BASEPHYS_FLASH_1
#define CONFIG_SYS_MONITOR_BASE TEXT_BASE
#define FLASH_BASE0_PRELIM PHYS_FLASH_1
/*-----------------------------------------------------------------------
* FLASH and environment organization
*/
#if 0
#define CONFIG_AMD_LV4001/* uncomment this if you have a LV400 flash */
#define CONFIG_AMD_LV8001/* uncomment this if you have a LV800 flash */
#endif
#define CONFIG_SYS_MAX_FLASH_BANKS1/* max number of memory banks */
#define CONFIG_JS2_8F320 1
#define CONFIG_SYS_FLASH_PROTECTION 1
#define CONFIG_SYS_FLASH_SIZE 0x00400000 /*4 MB*/
#define CONFIG_SYS_MAX_FLASH_SECT 32 /*max number of sectors on one chip*/
/* timeout values are in ticks */
#define CONFIG_SYS_FLASH_ERASE_TOUT(2*CONFIG_SYS_HZ) /* Timeout for Flash Erase */
#define CONFIG_SYS_FLASH_WRITE_TOUT(2*CONFIG_SYS_HZ) /* Timeout for Flash Write */
#defineCONFIG_ENV_IS_IN_FLASH1
#define CONFIG_ENV_SIZE0x40000/* Total Size of Environment Sector,这是256K的环境变量储存空间 */
#define CONFIG_ENV_OFFSET 0x100000 //在以后的内核分区中环境变量分区的OFFSET值要与此一致
#endif/* __CONFIG_H */
~~~
修改board/samsung/fl2440/lowlevel_init.S文件中SDARM刷新参数
~~~
#define REFCNT 1258
~~~
修改flash型号相关文件,用board/cmi/flash.c文件替换board/samsung/ofl2440/flash.c文件,使uboot支持Intel的JS28F320型号nor fhash.
打开board/samsung/fl2440/flash.c文件,修改:
1.把:
~~~
#define FLASH_BLOCK_SIZE 0x00010000
~~~
改为:
~~~
#define FLASH_BLOCK_SIZE 0x00020000
~~~
2.把声明:
~~~
static int write_short (flash_info_t *info, ulong dest, ushort data);//并删除这个函数体
改为:
static int write_word (flash_info_t *info, ulong dest, ushort data);
1.
删除write_buff和write_short两个函数,用下面两个函数代替:
int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
{
ulong cp, wp;
ushort data;
int l;
int i, rc;
wp = (addr & ~1); /* get lower word aligned address */
/*
* handle unaligned start bytes
*/
if ((l = addr - wp) != 0)
{
data = 0;
for (i=0, cp=wp; i<l; ++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_word(info, wp, data)) != 0) {
return (rc);
}
wp += 2;
}
/*
* handle word aligned part
*/
while (cnt >= 2) {
data = *((vu_short*)src);
if ((rc = write_word(info, wp, data)) != 0) {
return (rc);
}
src += 2;
wp += 2;
cnt -= 2;
}
if (cnt == 0) {
return ERR_OK;
}
/*
* handle unaligned tail bytes
*/
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_word(info, wp, data);
}
/*
* Write 16 bit (short) to flash
*/
static int write_word (flash_info_t *info, ulong dest, ushort data)
{
vu_short *addr = (vu_short *)dest, val;
int rc = ERR_OK;
int flag;
/* Check if Flash is (sufficiently) erased , fix by kavin*/
if ((*addr & data) != data)
return ERR_NOT_ERASED;
/*
* Disable interrupts which might cause a timeout
* here. Remember that our exception vectors are
* at address 0 in the flash, and we don't want a
* (ticker) exception to happen while the flash
* chip is in programming mode.
*/
flag = disable_interrupts();
/* clear status register command */
*addr = 0x50;
/* program set-up command */
*addr = 0x40;
/* latch address/data */
*addr = data;
/* arm simple, non interrupt dependent timer */
reset_timer_masked();
/* wait while polling the status register */
while(((val = *addr) & 0x80) != 0x80)
{
if (get_timer_masked() > CONFIG_SYS_FLASH_WRITE_TOUT) {
rc = ERR_TIMOUT;
/* suspend program command */
*addr = 0xB0;
goto outahere;
}
}
if(val & 0x1A) { /* check for error */
printf("\nFlash write error %02x at address %08lx\n",
(int)val, (unsigned long)dest);
if(val & (1<<3)) {
printf("Voltage range error.\n");
rc = ERR_PROG_ERROR;
goto outahere;
}
if(val & (1<<1)) {
printf("Device protect error.\n");
rc = ERR_PROTECTED;
goto outahere;
}
if(val & (1<<4)) {
printf("Programming error.\n");
rc = ERR_PROG_ERROR;
goto outahere;
}
rc = ERR_PROG_ERROR;
goto outahere;
}
outahere:
/* read array command */
*addr = 0xFF;
if (flag)
enable_interrupts();
return rc;
}
~~~
到目前为止我们还不能用tftp来下载文件,因为我们还没有移植DM9000网卡。
至此,uboot就能完会支持从nor flash启动,编译生成新的u-boot.bin并通过DNW的USB线下载到SDRAM中运行,便可看到u-boot检测到了我们的flash。用flinfo命令可以看 到具体的块信息,还可以用flash的各种命令对flash进行操作,从而实现这块nor flash驱动的完全支持。烧写当然也是没问题的了,把需要烧写的文件下载到SDRAM中后,用cp.b命令就可以了。
下面大该分析一下这个驱动文件的函数调用,此flash.c文件中有如下几个函数:
~~~
static ulong flash_get_size (vu_short *addr, flash_info_t *info);
static void flash_get_offsets (ulong base, flash_info_t *info);
static int write_word (flash_info_t *info, ulong dest, ushort data)
unsigned long flash_init (void)
void flash_print_info (flash_info_t *info)
int flash_erase (flash_info_t *info, int s_first, int s_last)
int flash_real_protect(flash_info_t *info, long sector, int prot)
int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
~~~
1.u-boot启动只会用到flash.c文件中的flash_init函数,正如上面所述;
2.以static修饰的3个函数只在flash.c文件中被调用;
3.最后面的4个函数会被/common/cmd_flash.c文件中的函数调用,以实现u-boot下的各种命令操作。
附:若用JLINK下载u-boot.bin到nor flash 中,需要把/include/configs/fl2440.h 中定义的以下这个宏注释掉:
~~~
/* #define CONFIG_SKIP_RELOCATE_UBOOT 1 */ 注释掉u-boo才能初始化CPU
~~~
- 前言
- FL2440的u-boot-2010.09移植(一)
- FL2440的u-boot-2010.09移植(二)
- FL2440的U-boot-2009.08移植(三)支持Nor FLASH
- FL2440的U-boot-2009.08移植(四) 支持DM900网卡
- FL2440的U-boot-2009.08移植(五)uboot架构中NAND Flash驱动修改
- FL2440如何利用JLINK烧写U-boot到NAND Flash中
- uboot中的快捷菜单的制作说明
- env_relocate 函数深入分析
- U-boot mkimage指定Linux内核地址时的两种方式
- 实现u-boot对yaffs/yaffs2文件系统下载的支持