网上大部分是利用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) 好像不起作用,大家小心点