织梦CMS - 轻松建站从此开始!

罗索

uClinux下的MTD技术(1):Flash驱动实现

jackyhwei 发布于 2011-07-21 17:09 点击:次 
说明了Am29LV320MT和K9W8G08U1M两种Flash在uClinux 2.6下的驱动实现。
TAG:

本文开发环境为:uClinux-2.6,BF561,编译器为VDSP4.5
 
1   norflash: Am29LV320MT
AM29LV320MT是一个4M,16位的NorFlash,支持CFI接口,其地址空间为0x2000 0000 ~ 0x2040 0000。
1、配置异步存储器,以下是几个相关的宏:
  1. #define CONFIG_C_AMBEN_ALL                     1 
  2. #define CONFIG_C_B0PEN                         1 
  3. #define CONFIG_C_B1PEN                         1 
  4. #define CONFIG_C_B2PEN                         1 
  5. #define CONFIG_C_B3PEN                         1 
  6. #define CONFIG_BANK_0                          0x7BB0 
  7. #define CONFIG_BANK_1                          0xFFC2 
  8. #define CONFIG_BANK_2                          0xFFC2 
  9. #define CONFIG_BANK_3                          0xFFC2 
2、定义命令集:
  1. #define CONFIG_MTD_CFI_AMDSTD                  1 
3、定义Flash的基本参数:
  1. #define CONFIG_EBIU_FLASH_BASE                 0x20000000 
  2. #define CONFIG_BFIN_FLASH_SIZE                 4 
4、加入drivers/mtd/maps/ezkit561.c。
5、修改
  1. #define EZKIT561_FLASH_BASE 0x20000000 
  2. #define EZKIT561_FLASH_SIZE 0x00400000 
为板载Flash的地址和大小。
6、修改ezkit561_parts分区定义为希望的值。
搞定。
2   Nand:K9W8G08U1M
K9W8G08U1M是一个1G的Nand flash,由两片512M的芯片堆叠而成。其RB1与RB2接到PF4和PF5,CE1与CE2接到PF0和PF1,ALE接到PF2,CLE接到PF3。
uClinux下的驱动与u-boot下的驱动相似但略有不同。
1、加入drivers/mtd/nand/bfin_nand.c。
2、修改地址定义:
  1. #define BFIN_NAND_BASE  0x29000000/*CONFIG_BFIN_NAND_BASE*/ 
3、修改bfin_nand_init函数中设置PF口的代码:
  1. /* Configure GPIO-BFIN_NAND_READY */ 
  2. *pFIO0_DIR |= 0x000F; // set PF0~PF3 as output , others as inputs 
  3. asm("ssync;"); 
  4. *pFIO0_INEN |= 0x0030; //enable input buffer for PF4,PF5 
  5. asm("ssync;"); 
4、修改以下3个控制函数:
  1. static void bfin_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) 
  2.     register struct nand_chip *this = mtd->priv; 
  3.      if (cmd == NAND_CMD_NONE) 
  4.         return
  5.         
  6.     if(ctrl & NAND_CLE) {  
  7.     *pFIO0_FLAG_S = 0x04; 
  8.     *pFIO0_FLAG_C = 0x08; 
  9.     } 
  10.     
  11.     if(ctrl & NAND_ALE) {  
  12.     *pFIO0_FLAG_C = 0x04; 
  13.     *pFIO0_FLAG_S = 0x08; 
  14.     } 
  15.   
  16.     this->IO_ADDR_R = this->IO_ADDR_W; 
  17.   
  18.     /* Drain the writebuffer */ 
  19.     asm("ssync;"); 
  20.     //__builtin_bfin_ssync(); 
  21.     
  22.     writeb(cmd, p_nand); 
  23.   
  24.     asm("ssync;"); 
  25.     *pFIO0_FLAG_C = 0x04 | 0x08; 
  26.         
  27. /* 
  28.      if (cmd == NAND_CMD_NONE) 
  29.                 return; 
  30.   
  31.         if (ctrl & NAND_CLE) 
  32.                 writeb(cmd, p_nand + BFIN_NAND_CLE); 
  33.         else 
  34.                 writeb(cmd, p_nand + BFIN_NAND_ALE); 
  35.   
  36.      SSYNC(); 
  37.      */ 
  38.   
  39. int bfin_device_ready(struct mtd_info *mtd) 
  40. {
  41.     return ((*pFIO0_FLAG_D & 0x30) == 0x30) ? 1 : 0; 
  42.      //return gpio_get_value(CONFIG_BFIN_NAND_READY); 
  43. }
  44.  
  45. /** 
  46.  * nand_select_chip - [DEFAULT] control CE line 
  47.  * @mtd: MTD device structure 
  48.  * @chip: chipnumber to select, -1 for deselect 
  49.  * 
  50.  * Default select function for 1 chip devices. 
  51.  */ 
  52. static int current_chip = -1; 
  53. static void bfin_select_chip(struct mtd_info *mtd, int chip) 
  54.      struct nand_chip *this = mtd->priv; 
  55.      current_chip = chip; 
  56.      switch(chip) { 
  57.      case -1: 
  58.         *pFIO0_FLAG_S = 0x03; 
  59.          break
  60.      case 0: 
  61.         *pFIO0_FLAG_C = 0x01; 
  62.          asm("ssync;"); 
  63.         *pFIO0_FLAG_S = 0x02; 
  64.          break
  65.      case 1: 
  66.         *pFIO0_FLAG_C = 0x02; 
  67.          asm("ssync;"); 
  68.         *pFIO0_FLAG_S = 0x01; 
  69.          break
  70.   
  71.      default
  72.          BUG(); 
  73.      } 
  74.     asm("ssync;"); 
5、修改partition_info中的分区定义。
搞定。
需要注意的是,NandFlash和NorFlash检测完成后都后添加相应的分区, 此时用于系统启动的mtdblock号可能会发生变化。默认情况下,NorFlash加入3个分区,NandFlash加入2个分区,所以启动时的 root也相应地由/dev/mtdblock0改变为/dev/mtdblock5。

 

(lights_joy)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201107/14738.html]
本文出处:blog.csdn.net/lights_joy 作者:lights_joy
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容