本文主要是介绍CFI查询(四),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
读毛德操《嵌入式系统》读书笔记
接着上一篇
1、回到上一篇的cfi_probe_chip函数中
在发出两个命令后,就接连从闪存中读出三次,如果从每个芯片中读出的字节都依次为0x51、0x52和0x59,即“Q”“R”和“Y”,就表示对上号了,这说明在地址base处检测到了闪存芯片,而且确实是4片16位闪存芯片。
这个操作对应的函数是qry_present函数
/* check for QRY.
in: interleave,type,mode
ret: table index, <0 for error
*/
static inline int qry_present(struct map_info *map, __u32 base,
struct cfi_private *cfi)
{
int osf = cfi->interleave * cfi->device_type; // scale factor
if (cfi_read(map,base+osf*0x10)==cfi_build_cmd('Q',map,cfi) &&
cfi_read(map,base+osf*0x11)==cfi_build_cmd('R',map,cfi) &&
cfi_read(map,base+osf*0x12)==cfi_build_cmd('Y',map,cfi))
return 1; // ok !
return 0; // nothing found
}
注:如果对不上号,那就换一种假设,这是在函数genprobe_new_chip中做的工作,这个函数已经在第二篇中讲了,可以退回去查看。
2、现在已经检测到了闪存芯片,并且已经开始查询流程,接着就要把芯片中的CFI信息块读出来。
我们回到cfi_probe_chip函数的代码中:
static int cfi_probe_chip(struct map_info *map, __u32 base,
struct flchip *chips, struct cfi_private *cfi)
{
int i;
if ((base + 0) >= map->size) {
printk(KERN_NOTICE
"Probe at base[0x00](0x%08lx) past the end of the map(0x%08lx)\n",
(unsigned long)base, map->size -1);
return 0;
}
if ((base + 0xff) >= map->size) {
printk(KERN_NOTICE
"Probe at base[0x55](0x%08lx) past the end of the map(0x%08lx)\n",
(unsigned long)base + 0x55, map->size -1);
return 0;
}
cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
cfi_send_gen_cmd(0x98, 0x55, base, map, cfi, cfi->device_type, NULL);
if (!qry_present(map,base,cfi))
return 0;
上一篇和这一篇开始讲的内容,不再重复。
if (!cfi->numchips) {
/* This is the first time we're called. Set up the CFI
stuff accordingly and return */
return cfi_chip_setup(map, cfi);
此函数把芯片中的信息块读出来,函数源码如下:
static int cfi_chip_setup(struct map_info *map,
struct cfi_private *cfi)
{
int ofs_factor = cfi->interleave*cfi->device_type;
__u32 base = 0;
int num_erase_regions = cfi_read_query(map, base + (0x10 + 28)*ofs_factor);
int i;
#ifdef DEBUG_CFI
printk("Number of erase regions: %d\n", num_erase_regions);
#endif
if (!num_erase_regions)
return 0;
cfi->cfiq = kmalloc(sizeof(struct cfi_ident) + num_erase_regions * 4, GFP_KERNEL);
if (!cfi->cfiq) {
printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name);
return 0;
}
memset(cfi->cfiq,0,sizeof(struct cfi_ident));
cfi->cfi_mode = CFI_MODE_CFI;
cfi->fast_prog=1; /* CFI supports fast programming */
/* Read the CFI info structure */
for (i=0; i<(sizeof(struct cfi_ident) + num_erase_regions * 4); i++) {
((unsigned char *)cfi->cfiq)[i] = cfi_read_query(map,base + (0x10 + i)*ofs_factor);
}
/* Do any necessary byteswapping */
cfi->cfiq->P_ID = le16_to_cpu(cfi->cfiq->P_ID);
cfi->cfiq->P_ADR = le16_to_cpu(cfi->cfiq->P_ADR);
cfi->cfiq->A_ID = le16_to_cpu(cfi->cfiq->A_ID);
cfi->cfiq->A_ADR = le16_to_cpu(cfi->cfiq->A_ADR);
cfi->cfiq->InterfaceDesc = le16_to_cpu(cfi->cfiq->InterfaceDesc);
cfi->cfiq->MaxBufWriteSize = le16_to_cpu(cfi->cfiq->MaxBufWriteSize);
#ifdef DEBUG_CFI
/* Dump the information therein */
print_cfi_ident(cfi->cfiq);
#endif
for (i=0; i<cfi->cfiq->NumEraseRegions; i++) {
cfi->cfiq->EraseRegionInfo[i] = le32_to_cpu(cfi->cfiq->EraseRegionInfo[i]);
#ifdef DEBUG_CFI
printk(" Erase Region #%d: BlockSize 0x%4.4X bytes, %d blocks\n",
i, (cfi->cfiq->EraseRegionInfo[i] >> 8) & ~0xff,
(cfi->cfiq->EraseRegionInfo[i] & 0xffff) + 1);
#endif
}
/* Put it back into Read Mode */
cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
return 1;
}
如前所述,CFI规定了对芯片的品种、规格和各种参数进行查询的流程,以及芯片在受到查询时提供的数据结构。CFI规定,芯片在受到查询时,CPU可以从芯片上的单元地址0x10开始读回一个信息块,其开头是一个数据结构,如下所示:
/* NB: We keep these structures in memory in HOST byteorder, except
* where individually noted.
*/
/* Basic Query Structure */
struct cfi_ident {
__u8 qry[3];
__u16 P_ID; 主
__u16 P_ADR;
__u16 A_ID; 次
__u16 A_ADR;
__u8 VccMin;
__u8 VccMax;
__u8 VppMin;
__u8 VppMax;电源有关
__u8 WordWriteTimeoutTyp;
__u8 BufWriteTimeoutTyp;
__u8 BlockEraseTimeoutTyp;
__u8 ChipEraseTimeoutTyp;
__u8 WordWriteTimeoutMax;
__u8 BufWriteTimeoutMax;
__u8 BlockEraseTimeoutMax;
__u8 ChipEraseTimeoutMax;
芯片进行这些操作时都有超时不能完成的可能,因此这些是,芯片相应操作的超时的典型值和最大值
__u8 DevSize;芯片大小,以2为底的指数
__u16 InterfaceDesc;数据宽度
__u16 MaxBufWriteSize;芯片上写缓冲的大小,以2为底的指数
__u8 NumEraseRegions;芯片上擦除区间的数量
__u32 EraseRegionInfo[0]; /* Not host ordered */
} __attribute__((packed));
}
/* Check each previous chip to see if it's an alias */
for (i=0; i<cfi->numchips; i++) {
/* This chip should be in read mode if it's one
we've already touched. */
if (qry_present(map,chips[i].start,cfi)) {
/* Eep. This chip also had the QRY marker.
* Is it an alias for the new one? */
cfi_send_gen_cmd(0xF0, 0, chips[i].start, map, cfi, cfi->device_type, NULL);
/* If the QRY marker goes away, it's an alias */
if (!qry_present(map, chips[i].start, cfi)) {
printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n",
map->name, base, chips[i].start);
return 0;
}
/* Yes, it's actually got QRY for data. Most
* unfortunate. Stick the new chip in read mode
* too and if it's the same, assume it's an alias. */
/* FIXME: Use other modes to do a proper check */
cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
if (qry_present(map, base, cfi)) {
printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n",
map->name, base, chips[i].start);
return 0;
}
}
}
/* OK, if we got to here, then none of the previous chips appear to
be aliases for the current one. */
if (cfi->numchips == MAX_CFI_CHIPS) {
printk(KERN_WARNING"%s: Too many flash chips detected. Increase MAX_CFI_CHIPS from %d.\n", map->name, MAX_CFI_CHIPS);
/* Doesn't matter about resetting it to Read Mode - we're not going to talk to it anyway */
return -1;
}
chips[cfi->numchips].start = base;
chips[cfi->numchips].state = FL_READY;
cfi->numchips++;
/* Put it back into Read Mode */
cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit mode\n",
map->name, cfi->interleave, cfi->device_type*8, base,
map->buswidth*8);
return 1;
}
3、在CFI信息块中,一方面要说明所支持的是哪一种规程,另一方面还要指明这个信息块的位置。CFI允许提供主、次两种操作规程。
下一篇再说,如何查询主、从算法。
这篇关于CFI查询(四)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!