CFI查询(一)

2024-04-06 05:08
文章标签 查询 cfi

本文主要是介绍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;
}

下一篇接着说:


这篇关于CFI查询(一)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/879067

相关文章

MySQL查询JSON数组字段包含特定字符串的方法

《MySQL查询JSON数组字段包含特定字符串的方法》在MySQL数据库中,当某个字段存储的是JSON数组,需要查询数组中包含特定字符串的记录时传统的LIKE语句无法直接使用,下面小编就为大家介绍两种... 目录问题背景解决方案对比1. 精确匹配方案(推荐)2. 模糊匹配方案参数化查询示例使用场景建议性能优

mysql表操作与查询功能详解

《mysql表操作与查询功能详解》本文系统讲解MySQL表操作与查询,涵盖创建、修改、复制表语法,基本查询结构及WHERE、GROUPBY等子句,本文结合实例代码给大家介绍的非常详细,感兴趣的朋友跟随... 目录01.表的操作1.1表操作概览1.2创建表1.3修改表1.4复制表02.基本查询操作2.1 SE

MySQL数据库的内嵌函数和联合查询实例代码

《MySQL数据库的内嵌函数和联合查询实例代码》联合查询是一种将多个查询结果组合在一起的方法,通常使用UNION、UNIONALL、INTERSECT和EXCEPT关键字,下面:本文主要介绍MyS... 目录一.数据库的内嵌函数1.1聚合函数COUNT([DISTINCT] expr)SUM([DISTIN

XML重复查询一条Sql语句的解决方法

《XML重复查询一条Sql语句的解决方法》文章分析了XML重复查询与日志失效问题,指出因DTO缺少@Data注解导致日志无法格式化、空指针风险及参数穿透,进而引发性能灾难,解决方案为在Controll... 目录一、核心问题:从SQL重复执行到日志失效二、根因剖析:DTO断裂引发的级联故障三、解决方案:修复

mysql查询使用_rowid虚拟列的示例

《mysql查询使用_rowid虚拟列的示例》MySQL中,_rowid是InnoDB虚拟列,用于无主键表的行ID查询,若存在主键或唯一列,则指向其,否则使用隐藏ID(不稳定),推荐使用ROW_NUM... 目录1. 基本查询(适用于没有主键的表)2. 检查表是否支持 _rowid3. 注意事项4. 最佳实

MySQL存储过程之循环遍历查询的结果集详解

《MySQL存储过程之循环遍历查询的结果集详解》:本文主要介绍MySQL存储过程之循环遍历查询的结果集,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录前言1. 表结构2. 存储过程3. 关于存储过程的SQL补充总结前言近来碰到这样一个问题:在生产上导入的数据发现

MySQL JSON 查询中的对象与数组技巧及查询示例

《MySQLJSON查询中的对象与数组技巧及查询示例》MySQL中JSON对象和JSON数组查询的详细介绍及带有WHERE条件的查询示例,本文给大家介绍的非常详细,mysqljson查询示例相关知... 目录jsON 对象查询1. JSON_CONTAINS2. JSON_EXTRACT3. JSON_TA

MYSQL查询结果实现发送给客户端

《MYSQL查询结果实现发送给客户端》:本文主要介绍MYSQL查询结果实现发送给客户端方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql取数据和发数据的流程(边读边发)Sending to clientSending DataLRU(Least Rec

MySQL复杂SQL之多表联查/子查询详细介绍(最新整理)

《MySQL复杂SQL之多表联查/子查询详细介绍(最新整理)》掌握多表联查(INNERJOIN,LEFTJOIN,RIGHTJOIN,FULLJOIN)和子查询(标量、列、行、表子查询、相关/非相关、... 目录第一部分:多表联查 (JOIN Operations)1. 连接的类型 (JOIN Types)

python编写朋克风格的天气查询程序

《python编写朋克风格的天气查询程序》这篇文章主要为大家详细介绍了一个基于Python的桌面应用程序,使用了tkinter库来创建图形用户界面并通过requests库调用Open-MeteoAPI... 目录工具介绍工具使用说明python脚本内容如何运行脚本工具介绍这个天气查询工具是一个基于 Pyt