加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

u-boot1.1.6在NorFlash下启动后实现对Nand的操作(开发用的是sbc

发布时间:2020-12-15 07:12:11 所属栏目:百科 来源:网络整理
导读:refer to: http://blog.csdn.net/lanmanck/article/details/4204610 uboot下载:ftp://ftp.denx.de/pub/u-boot/ 这里针对是make sbc2410x_config 拷贝如下代码到nand_legacy.c的适当位置: ? /*----------------------------------------------------------

refer to:

http://blog.csdn.net/lanmanck/article/details/4204610


uboot下载:ftp://ftp.denx.de/pub/u-boot/

这里针对是make sbc2410x_config

拷贝如下代码到nand_legacy.c的适当位置:

?

/*-----------------------------------------------------------------------

* NAND flash basic functions

* Added by liuyaojin 2009.5.20

* Copied from board/mpl/vcma9/vcma9.h & vcma9.c

*/
#if (CONFIG_SMDK2410)
#include <s3c2410.h>

typedef enum {

NFCE_LOW,

NFCE_HIGH

} NFCE_STATE;
static inline void NF_Conf(u16 conf)

{

S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
nand->NFCONF = conf;

}
static inline void NF_Cmd(u8 cmd)

{

S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
nand->NFCMD = cmd;

}
static inline void NF_CmdW(u8 cmd)

{

NF_Cmd(cmd);

udelay(1);

}
static inline void NF_Addr(u8 addr)

{

S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
nand->NFADDR = addr;

}
static inline void NF_SetCE(NFCE_STATE s)

{

S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
switch (s) {

case NFCE_LOW:

nand->NFCONF &= ~(1<<11);

break;
case NFCE_HIGH:

nand->NFCONF |= (1<<11);

break;

}

}
static inline void NF_WaitRB(void)

{

S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
while (!(nand->NFSTAT & (1<<0)));

}
static inline void NF_Write(u8 data)

{

S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
nand->NFDATA = data;

}
static inline u8 NF_Read(void)

{

S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
return(nand->NFDATA);

}
static inline void NF_Init_ECC(void)

{

S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
nand->NFCONF |= (1<<12);

}
static inline u32 NF_Read_ECC(void)

{

S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
return(nand->NFECC);

}
extern ulong nand_probe(ulong physadr);
static inline void NF_Reset(void)

{

int i;
NF_SetCE(NFCE_LOW);

NF_Cmd(0xFF); /* reset command */

for(i = 0; i < 10; i++); /* tWB = 100ns. */

NF_WaitRB(); /* wait 200~500us; */

NF_SetCE(NFCE_HIGH);

}
static inline void NF_Init(void)

{

#if 0 /* a little bit too optimistic */

#define TACLS 0

#define TWRPH0 3

#define TWRPH1 0

#else

#define TACLS 0

#define TWRPH0 4

#define TWRPH1 2

#endif
NF_Conf((1<<15)|(0<<14)|(0<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0));

/*nand->NFCONF = (1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0); */

/* 1 1 1 1,1 xxx,r xxx,r xxx */

/* En 512B 4step ECCR nFCE=H tACLS tWRPH0 tWRPH1 */
NF_Reset();

}
void nand_init(void)//注意有了这个后,要注销掉nand.c里的同样函数

{

S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
NF_Init();

#ifdef DEBUG

printf("NAND flash probing at 0x%.8lX/n",(ulong)nand);

#endif

printf ("%4lu MB/n",nand_probe((ulong)nand) >> 20);

}
#endif /* (CONFIG_SMDK2410) */



2、在nand_legacy.c头上包含文件:

#include <configs/sbc2410x.h>

3、在sbc2410x.h把CFG_CMD_NAND打开,适当位置中插入如下代码:


/**** 注销掉enable ECC这个 #define CONFIG_MTD_NAND_ECC(不记得是不是这么写)***/

#define CFG_NAND_LEGACY 1
/*-----------------------------------------------------------------------
?* NAND flash settings
?*/
#if (CONFIG_COMMANDS & CFG_CMD_NAND)
#define CFG_MAX_NAND_DEVICE???? 1?????? /* Max number of NAND devices?????????? */
#define SECTORSIZE 512

#define ADDR_COLUMN 1
#define ADDR_PAGE 2
#define ADDR_COLUMN_PAGE 3

#define NAND_ChipID_UNKNOWN???? 0x00
#define NAND_MAX_FLOORS 1
#define NAND_MAX_CHIPS 1

#define NAND_WAIT_READY(nand)?? NF_WaitRB()
#define NAND_DISABLE_CE(nand)?? NF_SetCE(NFCE_HIGH)
#define NAND_ENABLE_CE(nand)??? NF_SetCE(NFCE_LOW)
#define WRITE_NAND_COMMAND(d,adr)????? NF_Cmd(d)
#define WRITE_NAND_COMMANDW(d,adr)???? NF_CmdW(d)
#define WRITE_NAND_ADDRESS(d,adr)????? NF_Addr(d)
#define WRITE_NAND(d,adr)????????????? NF_Write(d)
#define READ_NAND(adr)????????????????? NF_Read()
/* the following functions are NOP's because S3C24X0 handles this in hardware */
#define NAND_CTL_CLRALE(nandptr)
#define NAND_CTL_SETALE(nandptr)
#define NAND_CTL_CLRCLE(nandptr)
#define NAND_CTL_SETCLE(nandptr)
/* #undef CONFIG_MTD_NAND_VERIFY_WRITE */
#endif? /* CONFIG_COMMANDS & CFG_CMD_NAND */


#define CONFIG_MTD_NAND_ECC_JFFS2 1
//#endif /* CONFIG_COMMANDS & CFG_CMD_NAND */
//---------------添加结束-----------------------

4、make即可

需要注意的地方:

1、必须定义 #define CFG_NAND_LEGACY

2、#if (CONFIG_COMMANDS & CFG_CMD_NAND) 好像不起作用,大家小心点

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读