Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1464111
  • 博文数量: 267
  • 博客积分: 3010
  • 博客等级: 少校
  • 技术积分: 3089
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-05 17:09
个人简介

尊天命,尽人事

文章分类

全部博文(267)

文章存档

2017年(6)

2015年(4)

2014年(27)

2013年(52)

2012年(59)

2011年(120)

分类: 嵌入式

2011-10-20 10:34:14

网上大部分是利用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的适当位置:

  1. /*-----------------------------------------------------------------------

  2. * NAND flash basic functions

  3. * Added by liuyaojin 2009.5.20

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

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


  8. typedef enum {

  9. NFCE_LOW,

  10. NFCE_HIGH

  11. } NFCE_STATE;
  12. static inline void NF_Conf(u16 conf)

  13. {

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

  16. }
  17. static inline void NF_Cmd(u8 cmd)

  18. {

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

  21. }
  22. static inline void NF_CmdW(u8 cmd)

  23. {

  24. NF_Cmd(cmd);

  25. udelay(1);

  26. }
  27. static inline void NF_Addr(u8 addr)

  28. {

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

  31. }
  32. static inline void NF_SetCE(NFCE_STATE s)

  33. {

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

  36. case NFCE_LOW:

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

  38. break;
  39. case NFCE_HIGH:

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

  41. break;

  42. }

  43. }
  44. static inline void NF_WaitRB(void)

  45. {

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

  48. }
  49. static inline void NF_Write(u8 data)

  50. {

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

  53. }
  54. static inline u8 NF_Read(void)

  55. {

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

  58. }
  59. static inline void NF_Init_ECC(void)

  60. {

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

  63. }
  64. static inline u32 NF_Read_ECC(void)

  65. {

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

  68. }
  69. extern ulong nand_probe(ulong physadr);
  70. static inline void NF_Reset(void)

  71. {

  72. int i;
  73. NF_SetCE(NFCE_LOW);

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

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

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

  77. NF_SetCE(NFCE_HIGH);

  78. }
  79. static inline void NF_Init(void)

  80. {

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

  82. #define TACLS 0

  83. #define TWRPH0 3

  84. #define TWRPH1 0

  85. #else

  86. #define TACLS 0

  87. #define TWRPH0 4

  88. #define TWRPH1 2

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

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

  92. /* 1 1 1 1, 1 xxx, r xxx, r xxx */

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

  95. }
  96. void nand_init(void)

  97. {

  98. S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
  99. NF_Init();

  100. #ifdef DEBUG

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

  102. #endif

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

  104. }
  105. #endif /* (CONFIG_SMDK2410) */



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

  107. #include <configs/smdk2410.h>

  108.  

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

  110.  

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

  113. * NAND flash settings

  114. * Added by liuyaojin 2009.5.20

  115. * Copied from include/conifgs/vcma9.h

  116. */
  117. #define CFG_NAND_LEGACY
  118. //#if (CONFIG_COMMANDS & CFG_CMD_NAND)
  119. #define CFG_MAX_NAND_DEVICE 1 /* Max number of NAND devices */
  120. //nit i=0;
  121. #define SECTORSIZE 512
  122. #define ADDR_COLUMN 1

  123. #define ADDR_PAGE 2

  124. #define ADDR_COLUMN_PAGE 3
  125. #define NAND_ChipID_UNKNOWN 0x00

  126. #define NAND_MAX_FLOORS 1

  127. #define NAND_MAX_CHIPS 1
  128. #define NAND_WAIT_READY(nand) NF_WaitRB()
  129. #define NAND_DISABLE_CE(nand) NF_SetCE(NFCE_HIGH)

  130. #define NAND_ENABLE_CE(nand) NF_SetCE(NFCE_LOW)


  131. #define WRITE_NAND_COMMAND(d, adr) NF_Cmd(d)

  132. #define WRITE_NAND_COMMANDW(d, adr) NF_CmdW(d)

  133. #define WRITE_NAND_ADDRESS(d, adr) NF_Addr(d)

  134. #define WRITE_NAND(d, adr) NF_Write(d)

  135. #define READ_NAND(adr) NF_Read()

  136. /* the following functions are NOP's because S3C24X0 handles this in hardware */

  137. #define NAND_CTL_CLRALE(nandptr)

  138. #define NAND_CTL_SETALE(nandptr)

  139. #define NAND_CTL_CLRCLE(nandptr)

  140. #define NAND_CTL_SETCLE(nandptr)
  141. /* #define CONFIG_MTD_NAND_VERIFY_WRITE 1 */
  142. /* This definition above is commented by Lu Xianzi. 2006.05.28

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

  144. there will be a link error.

  145. */

  146. #define CONFIG_MTD_NAND_ECC_JFFS2 1
  147. //#endif /* CONFIG_COMMANDS & CFG_CMD_NAND */
  148. //---------------添加结束-----------------------

4、make即可

需要注意的地方:

1、必须定义 #define CFG_NAND_LEGACY

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

阅读(929) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~