CFI查询(一)

毛德操《嵌入式系统》读书笔记

1、介绍一些涉及的数据结构:


的mtd_info。

这样,只要抓住一个mtd_part数据结构,就可以找到所属的mtd_info结构,再找到相应的map_info结构,进而cfi_private结构,最后到达cfi_ident结构、cfi_pri_intelext结构,还有flchip结构数组chips[]。

2、

下面我们从sa1100_mtd_init函数开始看闪存模块的初始化:

int __init sa1100_mtd_init(void)
{
struct mtd_partition *parts;
int nb_parts = 0, ret;
int parsed_nr_parts = 0;
const char *part_type;
unsigned long base = -1UL;

。。。

#ifdef CONFIG_SA1100_GRAPHICSCLIENT
if (machine_is_graphicsclient()) {
parts = graphicsclient_partitions;指向一个具体的mtd_partition结构数组,对于此处是

static struct mtd_partition graphicsmaster_partitions[] = {
{
name: "zImage",
size: 0x100000,
offset: 0,
mask_flags: MTD_WRITEABLE,  /* force read-only */
},
{
name: "ramdisk.gz",
size: 0x300000,
offset: MTDPART_OFS_APPEND,
mask_flags: MTD_WRITEABLE,  /* force read-only */
},
{
name: "User FS",
size: MTDPART_SIZ_FULL,
offset: MTDPART_OFS_APPEND,
}
};

nb_parts = ARRAY_SIZE(graphicsclient_partitions);
sa1100_map.size = GRAPHICSCLIENT_FLASH_SIZE;
sa1100_map.buswidth = (MSC1 & MSC_RBW) ? 2:4;总线宽度,2个字节或4个字节
}
#endif

。。。

/*
* Now let's probe for the actual flash.  Do it here since前面只是逻辑上的描述,其真正的物理组成,内核需要进行一番调查。
* specific machine settings might have been set above.
*/
printk(KERN_NOTICE "SA1100 flash: probing %d-bit flash bus\n", sa1100_map.buswidth*8);
mymtd = do_map_probe("cfi_probe",
&sa1100_map);有此函数完成调查

static struct map_info sa1100_map = {
name: "SA1100 flash",
read8: sa1100_read8,
read16: sa1100_read16,
read32: sa1100_read32,
copy_from: sa1100_copy_from,
write8: sa1100_write8,
write16: sa1100_write16,
write32: sa1100_write32,
copy_to: sa1100_copy_to,


map_priv_1: WINDOW_ADDR,
map_priv_2: -1,
};

ret = -ENXIO;
if (!mymtd)
goto out_err;
mymtd->module = THIS_MODULE;

3、接下来顺着函数走一篇:

注:函数是层层调用的。

(1)、上一个函数通过下面的结构体最终调用cfi_probe函数。

static struct mtd_chip_driver cfi_chipdrv = {
probe: cfi_probe,
name: "cfi_probe",
module: THIS_MODULE
};

(2)、

struct mtd_info *cfi_probe(struct map_info *map)
{
/*
* Just use the generic probe stuff to call our CFI-specific
* chip_probe routine in all the possible permutations, etc.
*/
return mtd_do_chip_probe(map, &cfi_chip_probe);
}

(3)、

struct mtd_info *mtd_do_chip_probe(struct map_info *map, struct chip_probe *cp)
{
struct mtd_info *mtd = NULL;
struct cfi_private *cfi;


/* First probe the map to see if we have CFI stuff there. */
cfi = genprobe_ident_chips(map, cp);检查系统是否有闪存芯片存在,调查结果通过一个struct cfi_private数据结构返回。如果调查的结果表明系统中有闪存芯片存在,便将指向这个数据结构的指针记录在map_info数据结构中。

if (!cfi)
return NULL;


map->fldrv_priv = cfi;
/* OK we liked it. Now find a driver for the command set it talks */


mtd = check_cmd_set(map, 1); /* First the primary cmdset */
if (!mtd)
mtd = check_cmd_set(map, 0); /* Then the secondary */

if (mtd)
return mtd;


printk(KERN_WARNING"gen_probe: No supported Vendor Command Set found\n");

kfree(cfi->cfiq);
kfree(cfi);
map->fldrv_priv = NULL;
return NULL;
}

(4)、



struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chip_probe *cp)
{
unsigned long base=0;
struct cfi_private cfi;
struct cfi_private *retcfi;
struct flchip chip[MAX_CFI_CHIPS];
int i;


memset(&cfi, 0, sizeof(cfi));


/* Call the probetype-specific code with all permutations of 
  interleave and device type, etc. */
if (!genprobe_new_chip(map, cp, &cfi)) {
/* The probe didn't like it */
printk(KERN_WARNING "%s: Found no %s device at location zero\n",
      cp->name, map->name);
return NULL;
}


。。。
chip[0].start = 0;
chip[0].state = FL_READY;
cfi.chipshift = cfi.cfiq->DevSize;


switch(cfi.interleave) {
#ifdef CFIDEV_INTERLEAVE_1
case 1:
break;
#endif
#ifdef CFIDEV_INTERLEAVE_2
case 2:
cfi.chipshift++;
break;
#endif
#ifdef CFIDEV_INTERLEAVE_4
case 4:
cfi.chipshift+=2;
break;
#endif
default:
BUG();
}

cfi.numchips = 1;


/*
* Now probe for other chips, checking sensibly for aliases while
* we're at it. The new_chip probe above should have let the first
* chip in read mode.
*
* NOTE: Here, we're checking if there is room for another chip
*       the same size within the mapping. Therefore, 
*       base + chipsize <= map->size is the correct thing to do, 
*       because, base + chipsize would be the  _first_ byte of the
*       next chip, not the one we're currently pondering.
*/


for (base = (1<<cfi.chipshift); base + (1<<cfi.chipshift) <= map->size;
    base += (1<<cfi.chipshift))
cp->probe_chip(map, base, &chip[0], &cfi);


/*
* Now allocate the space for the structures we need to return to 
* our caller, and copy the appropriate data into them.
*/


retcfi = kmalloc(sizeof(struct cfi_private) + cfi.numchips * sizeof(struct flchip), GFP_KERNEL);


if (!retcfi) {
printk(KERN_WARNING "%s: kmalloc failed for CFI private structure\n", map->name);
kfree(cfi.cfiq);
return NULL;
}


memcpy(retcfi, &cfi, sizeof(cfi));
memcpy(&retcfi->chips[0], chip, sizeof(struct flchip) * cfi.numchips);


/* Fix up the stuff that breaks when you move it */
for (i=0; i< retcfi->numchips; i++) {
init_waitqueue_head(&retcfi->chips[i].wq);
spin_lock_init(&retcfi->chips[i]._spinlock);
retcfi->chips[i].mutex = &retcfi->chips[i]._spinlock;
}


return retcfi;
}

下一篇接着说:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值