转载请注明出处http://blog.csdn.net/cneozhang/article/details/6693764,如有任何疑问,欢迎交流学习。
源码可以到我的git仓库下载:
[plain] view plain copy print ?
- git clone git://github.com/cneozhang/u-boot-2011.06-cneo.git
git clone git://github.com/cneozhang/u-boot-2011.06-cneo.git
一、清理编译环境
在上一篇,我们已经建立好了mini2440的开发环境,并且编译成功,为了有个干净的环境,我们先清理以下现场(不是必须的):
在u-boot-2011.06根目录下:
[plain] view plain copy print ?
- <pre class="plain" name="code">neo@neo-machine:~/u-boot-2-11.06$ make distclean
<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的配置:
[cpp] view plain copy print ?
-
-
-
-
- #define CONFIG_SYS_FLASH_CFI
- #define CONFIG_FLASH_CFI_DRIVER
- #define CONFIG_FLASH_CFI_LEGACY
- #define CONFIG_SYS_FLASH_LEGACY_1024Kx16
- #define CONFIG_FLASH_SHOW_PROGRESS 45
- #define CONFIG_FLASH_CFI_MTD
-
- #define CONFIG_SYS_MAX_FLASH_BANKS 1
- #define CONFIG_SYS_FLASH_BANKS_LIST { CONFIG_SYS_FLASH_BASE }
- #define CONFIG_SYS_MAX_FLASH_SECT (512)
-
- #define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x1f0000) /* at the end block */
- #define CONFIG_ENV_IS_IN_FLASH
- #define CONFIG_ENV_SIZE 0x10000
/*----------------------------------------------------------------------- * FLASH and environment organization */ #define CONFIG_SYS_FLASH_CFI #define CONFIG_FLASH_CFI_DRIVER #define CONFIG_FLASH_CFI_LEGACY #define CONFIG_SYS_FLASH_LEGACY_1024Kx16 #define CONFIG_FLASH_SHOW_PROGRESS 45 #define CONFIG_FLASH_CFI_MTD #define CONFIG_SYS_MAX_FLASH_BANKS 1 #define CONFIG_SYS_FLASH_BANKS_LIST { CONFIG_SYS_FLASH_BASE } #define CONFIG_SYS_MAX_FLASH_SECT (512) #define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x1f0000) /* at the end block */ #define CONFIG_ENV_IS_IN_FLASH #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结构介绍如下:
[cpp] view plain copy print ?
- *-----------------------------------------------------------------------
- * FLASH Info: contains chip specific data, per FLASH bank
- */
-
- typedef struct {
- ulong size;
- ushort sector_count;
- ulong flash_id;
- ulong start[CONFIG_SYS_MAX_FLASH_SECT];
- uchar protect[CONFIG_SYS_MAX_FLASH_SECT];
- #ifdef CONFIG_SYS_FLASH_CFI
- uchar portwidth;
- uchar chipwidth;
- ushort buffer_size;
- ulong erase_blk_tout;
- ulong write_tout;
- ulong buffer_write_tout;
- ushort vendor;
- ushort cmd_reset;
- ushort interface;
- ushort legacy_unlock;
- ushort manufacturer_id;
- ushort device_id;
- ushort device_id2;
- ushort ext_addr;
- ushort cfi_version;
- ushort cfi_offset;
- ulong addr_unlock1;
- ulong addr_unlock2;
- const char *name;
- #endif
- } flash_info_t;
*----------------------------------------------------------------------- * FLASH Info: contains chip specific data, per FLASH bank */ typedef struct { ulong size; /* total bank size in bytes */ ushort sector_count; /* number of erase units */ ulong flash_id; /* combined device & manufacturer code */ ulong start[CONFIG_SYS_MAX_FLASH_SECT]; /* virtual sector start address */ uchar protect[CONFIG_SYS_MAX_FLASH_SECT]; /* sector protection status */ #ifdef CONFIG_SYS_FLASH_CFI uchar portwidth; /* the width of the port */ uchar chipwidth; /* the width of the chip */ ushort buffer_size; /* # of bytes in write buffer */ ulong erase_blk_tout; /* maximum block erase timeout */ ulong write_tout; /* maximum write timeout */ ulong buffer_write_tout; /* maximum buffer write timeout */ ushort vendor; /* the primary vendor id */ ushort cmd_reset; /* vendor specific reset command */ ushort interface; /* used for x8/x16 adjustments */ ushort legacy_unlock; /* support Intel legacy (un)locking */ ushort manufacturer_id; /* manufacturer id */ ushort device_id; /* device id */ ushort device_id2; /* extended device id */ ushort ext_addr; /* extended query table address */ ushort cfi_version; /* cfi version */ ushort cfi_offset; /* offset for cfi query */ ulong addr_unlock1; /* unlock address 1 for AMD flash roms */ ulong addr_unlock2; /* unlock address 2 for AMD flash roms */ const char *name; /* human-readable name */ #endif } 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[]成员:
[cpp] view plain copy print ?
- #ifdef CONFIG_SYS_FLASH_LEGACY_1024Kx16
- {
- .mfr_id = (u16)SST_MANUFACT,
- .dev_id = SST39VF1601,
- .name = "SST 39LV1601",
- .uaddr = {
- [1] = MTD_UADDR_0x5555_0x2AAA
- },
- .DevSize = SIZE_2MiB,
- .CmdSet = P_ID_AMD_STD,
- .NumEraseRegions= 4,
- .regions = {
- ERASEINFO(0x10000,6),
- ERASEINFO(0x10000,10),
- ERASEINFO(0x10000,15),
- ERASEINFO(0x10000,1),
- }
- },
- #endif
#ifdef CONFIG_SYS_FLASH_LEGACY_1024Kx16 { .mfr_id = (u16)SST_MANUFACT, .dev_id = SST39VF1601, .name = "SST 39LV1601", .uaddr = { [1] = MTD_UADDR_0x5555_0x2AAA /* x16 */ }, .DevSize = SIZE_2MiB, .CmdSet = P_ID_AMD_STD, .NumEraseRegions= 4, .regions = { ERASEINFO(0x10000,6), /* 6 blocks */ ERASEINFO(0x10000,10), /* 10 blocks */ ERASEINFO(0x10000,15), /* 15 blocks */ ERASEINFO(0x10000,1), /* 1 blocks */ } }, #endif
至此,nor flash的支持代码已经增加完成
四、编译,烧录:
[plain] view plain copy print ?
- neo@neo-machine:~/u-boot-2-11.06$ make mini2440_config
- neo@neo-machine:~/u-boot-2-11.06$ make
neo@neo-machine:~/u-boot-2-11.06$ make mini2440_config neo@neo-machine:~/u-boot-2-11.06$ make
将u-boot.bin文件烧录进nor flash,启动,此时,串口打印信息已经可以正确识别到nor flash了:
试验:
[plain] view plain copy print ?
- mini2440 # flinfo
mini2440 # flinfo
在执行flinfo命令时,可能会提示raise: Signal # 8 错误,请参考我转载的《u-boot-2011.06 raise: Signal # 8 错误修正》。