s3c2410移植nand支持到uboot, 使用nand_legacy.c 【1】

网上大部分是利用drivers/nand/nand.c或者common/env_nand.c的,但是还有个drivers/nand_legacy/nand_legacy.c,我还不清楚为什么会有2个目录,据说新的uboot是靠nand_legacy.c实现的,于是我想移植到nand_legacy.c下。

 

1、先make smdk2410_config,make成功后再拷贝如下代码到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)

{

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/smdk2410.h>

 

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

 

//然后把下面这些宏定义放在smdk2410.h中
/*-----------------------------------------------------------------------

* NAND flash settings

* Added by liuyaojin 2009.5.20

* Copied from include/conifgs/vcma9.h

*/
#define CFG_NAND_LEGACY
//#if (CONFIG_COMMANDS & CFG_CMD_NAND)
#define CFG_MAX_NAND_DEVICE 1 /* Max number of NAND devices */
//nit i=0;
#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)
/* #define CONFIG_MTD_NAND_VERIFY_WRITE 1 */
/* This definition above is commented by Lu Xianzi. 2006.05.28

Because there's no definition of a macro called __mem_pci,

there will be a link error.

*/

#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) 好像不起作用,大家小心点

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值