现在的位置: 首页 > 综合 > 正文

u-boot-2011.06在mini2440上的移植之Nor flash支持

2018年04月12日 ⁄ 综合 ⁄ 共 7265字 ⁄ 字号 评论关闭

转载请注明出处http://blog.csdn.net/cneozhang/article/details/6693764,如有任何疑问,欢迎交流学习。

源码可以到我的git仓库下载:

  1. git clone git://github.com/cneozhang/u-boot-2011.06-cneo.git  

 

一、清理编译环境

在上一篇,我们已经建立好了mini2440的开发环境,并且编译成功,为了有个干净的环境,我们先清理以下现场(不是必须的):

在u-boot-2011.06根目录下:

 

  1. <pre class="plain" name="code">neo@neo-machine:~/u-boot-2-11.06$ make distclean  





二、关于SST39LV1601 flash的一些特性:

重要需要了解的是,这款Nor flash兼容JEDEC接口方式,对于U-BOOT来说,如果直接定义成CFI接口方式的话,操作命令过程中,flash不能unlock。

FEATURES:

size:   1M x 16bit

sector:2KWord / sector

block: 32Kword / sector

 

Product identification

 

Software command sequence

三、更改代码:

1、更改include/configs/mini2440.h中关于nor flash的配置:
 

  1. /*----------------------------------------------------------------------- 
  2.  * FLASH and environment organization 
  3.  */  
  4.   
  5. #define CONFIG_SYS_FLASH_CFI  
  6. #define CONFIG_FLASH_CFI_DRIVER
      
  7. #define CONFIG_FLASH_CFI_LEGACY  
  8. #define CONFIG_SYS_FLASH_LEGACY_1024Kx16  
  9. #define CONFIG_FLASH_SHOW_PROGRESS  45  
  10. #define CONFIG_FLASH_CFI_MTD   
  11.   
  12. #define CONFIG_SYS_MAX_FLASH_BANKS  1  
  13. #define CONFIG_SYS_FLASH_BANKS_LIST     { CONFIG_SYS_FLASH_BASE }  
  14. #define CONFIG_SYS_MAX_FLASH_SECT   (512)  
  15.   
  16. #define CONFIG_ENV_ADDR         (CONFIG_SYS_FLASH_BASE + 0x1f0000) /* at the end block */  
  17. #define CONFIG_ENV_IS_IN_FLASH  
  18. #define CONFIG_ENV_SIZE         0x10000  

1. 在drivers/mtd/cfi_flash.c文件中,unsigned long flash_init (void)函数说明:

flash设备通过flash_info[]数组管理每一个flash芯片(如一颗SST39LV1601芯片)信息,因为mini2440只用到一颗nor flash芯片(#define CONFIG_SYS_MAX_FLASH_BANKS    1),所以其实这个数组只有一个成员,flash info结构介绍如下:

  1. *-----------------------------------------------------------------------  
  2.  * FLASH Info: contains chip specific data, per FLASH bank  
  3.  */  
  4.   
  5. typedef struct {  
  6.     ulong   size;           /* total bank size in bytes     */  
  7.     ushort  sector_count;       /* number of erase units        */  
  8.     ulong   flash_id;       /* combined device & manufacturer code  */  
  9.     ulong   start[CONFIG_SYS_MAX_FLASH_SECT];   /* virtual sector start address */  
  10.     uchar   protect[CONFIG_SYS_MAX_FLASH_SECT]; /* sector protection status */  
  11. #ifdef CONFIG_SYS_FLASH_CFI  
  12.     uchar   portwidth;      /* the width of the port        */  
  13.     uchar   chipwidth;      /* the width of the chip        */  
  14.     ushort  buffer_size;        /* # of bytes in write buffer       */  
  15.     ulong   erase_blk_tout;     /* maximum block erase timeout      */  
  16.     ulong   write_tout;     /* maximum write timeout        */  
  17.     ulong   buffer_write_tout;  /* maximum buffer write timeout     */  
  18.     ushort  vendor;         /* the primary vendor id        */  
  19.     ushort  cmd_reset;      /* vendor specific reset command    */  
  20.     ushort  interface;      /* used for x8/x16 adjustments      */  
  21.     ushort  legacy_unlock;      /* support Intel legacy (un)locking */  
  22.     ushort  manufacturer_id;    /* manufacturer id          */  
  23.     ushort  device_id;      /* device id                */  
  24.     ushort  device_id2;     /* extended device id           */  
  25.     ushort  ext_addr;       /* extended query table address     */  
  26.     ushort  cfi_version;        /* cfi version              */  
  27.     ushort  cfi_offset;     /* offset for cfi query         */  
  28.     ulong   addr_unlock1;       /* unlock address 1 for AMD flash roms  */  
  29.     ulong   addr_unlock2;       /* unlock address 2 for AMD flash roms  */  
  30.     const char *name;       /* human-readable name                  */  
  31. #endif   
  32. } flash_info_t;  

调用关系:

flash_init() -->flash_detect_legacy(cfi_flash_bank_addr(i), i) 去探测目标板中是否存在nor flash芯片

static int flash_detect_legacy(phys_addr_t base, int banknum) -->flash_read_jedec_ids(info)获取JEDEC接口标准flash芯片的信息,并填充info->manufacturer_id和info->device_id

static int flash_detect_legacy(phys_addr_t base, int banknum) -->jedec_flash_match(info, info->start[0])去匹配获取到的id号是否与jedec_table中定义的成员匹配,如果匹配,继续填充flash_info的其他信息,并返回1表示detect成功。

2、我们观察jedec_teble[]定义时发现,里边并未定义SST39LV1601芯片,所以要将其增加进去。

3、将SST39LV1601增加进jedec_table[]成员:

  1. #ifdef CONFIG_SYS_FLASH_LEGACY_1024Kx16  
  2.     {  
  3.         .mfr_id     = (u16)SST_MANUFACT,  
  4.         .dev_id     = SST39VF1601,  
  5.         .name       = "SST 39LV1601",  
  6.         .uaddr      = {  
  7.             [1] = MTD_UADDR_0x5555_0x2AAA /* x16 */  
  8.         },  
  9.         .DevSize    = SIZE_2MiB,  
  10.         .CmdSet     = P_ID_AMD_STD,  
  11.         .NumEraseRegions= 4,  
  12.         .regions    = {  
  13.             ERASEINFO(0x10000,6),  /* 6  blocks */  
  14.             ERASEINFO(0x10000,10), /* 10 blocks */  
  15.             ERASEINFO(0x10000,15), /* 15 blocks */  
  16.             ERASEINFO(0x10000,1),  /* 1  blocks */  
  17.         }  
  18.     },  
  19. #endif  

至此,nor flash的支持代码已经增加完成

四、编译,烧录:

  1. neo@neo-machine:~/u-boot-2-11.06$ make mini2440_config  
  2. neo@neo-machine:~/u-boot-2-11.06$ make  

将u-boot.bin文件烧录进nor flash,启动,此时,串口打印信息已经可以正确识别到nor flash了:

 

试验:

  1. mini2440 # flinfo  

在执行flinfo命令时,可能会提示raise: Signal # 8 错误,请参考我转载的《u-boot-2011.06 raise: Signal # 8 错误修正》。

抱歉!评论已关闭.