如果没有Nor FLASH的同学可以跳过这一章节,直接进行下一张节。如果遇到什么问题,一般都是你没有定义那个宏之类的,这个问题可以很好的额解决。
修改norflash(nor fhash型号:JS28F320)的配置,把include/configs/fl2440.h中关于“Physical Memory Map”和“FLASH and environment organization”的配置都删掉,换成下面的配置:
修改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文件,修改:
删除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