u-boot1.1.5的移植二

来源:互联网 发布:智能电视与网络电视 编辑:程序博客网 时间:2024/06/05 02:12
二。nand可以读写,但参数不能修改
http://blog.lupaworld.com/blog/htm/do_showone/tid_4343.html
http://bbs2.chinaunix.net/viewthread.php?tid=855860
1.在nand_legacy中加入nand低层的读写函数
//add
#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(int s)   //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();

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

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

2。在fft2410.h中加入。。  并打开  CFG_CMD_NAND 宏
#define CFG_NAND_LEGACY 1
#define CFG_NAND_BASE 0x4E000000

// enum {NFCE_LOW,NFCE_HIGH} NFCE_STATE;
#define NFCE_LOW 0
#define NFCE_HIGH 1
#define NAND_ChipID_UNKNOWN     0x00

//add2
#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)
/* #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 */
//end add2

3.加入自己的 Nand Flash 芯片型号
  在 include/linux/mtd/ nand_ids.h 中的对如下结构体赋值进行修改:
static struct nand_flash_dev nand_flash_ids[] = {
      ......
    {"Samsung K9F1208U0B",    NAND_MFR_SAMSUNG, 0x76, 26, 0, 4, 0x4000, 0},
      .......
}

4.在nand_legacy中修改
/*    for (i=0; i<CFG_MAX_NAND_DEVICE; i++) {
        if (nand_dev_desc[i].ChipID == NAND_ChipID_UNKNOWN)
                    {
            nand = &nand_dev_desc[i];
            break;
        }
    }
*/
用nand = &nand_dev_desc[0]; 代替