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

相关文章

Java实现复杂查询优化的7个技巧小结

《Java实现复杂查询优化的7个技巧小结》在Java项目中,复杂查询是开发者面临的“硬骨头”,本文将通过7个实战技巧,结合代码示例和性能对比,手把手教你如何让复杂查询变得优雅,大家可以根据需求进行选择... 目录一、复杂查询的痛点:为何你的代码“又臭又长”1.1冗余变量与中间状态1.2重复查询与性能陷阱1.

MySQL中查询和展示LONGBLOB类型数据的技巧总结

《MySQL中查询和展示LONGBLOB类型数据的技巧总结》在MySQL中LONGBLOB是一种二进制大对象(BLOB)数据类型,用于存储大量的二进制数据,:本文主要介绍MySQL中查询和展示LO... 目录前言1. 查询 LONGBLOB 数据的大小2. 查询并展示 LONGBLOB 数据2.1 转换为十

使用SpringBoot+InfluxDB实现高效数据存储与查询

《使用SpringBoot+InfluxDB实现高效数据存储与查询》InfluxDB是一个开源的时间序列数据库,特别适合处理带有时间戳的监控数据、指标数据等,下面详细介绍如何在SpringBoot项目... 目录1、项目介绍2、 InfluxDB 介绍3、Spring Boot 配置 InfluxDB4、I

Go语言使用Gin处理路由参数和查询参数

《Go语言使用Gin处理路由参数和查询参数》在WebAPI开发中,处理路由参数(PathParameter)和查询参数(QueryParameter)是非常常见的需求,下面我们就来看看Go语言... 目录一、路由参数 vs 查询参数二、Gin 获取路由参数和查询参数三、示例代码四、运行与测试1. 测试编程路

MySQL 数据库表与查询操作实战案例

《MySQL数据库表与查询操作实战案例》本文将通过实际案例,详细介绍MySQL中数据库表的设计、数据插入以及常用的查询操作,帮助初学者快速上手,感兴趣的朋友跟随小编一起看看吧... 目录mysql 数据库表操作与查询实战案例项目一:产品相关数据库设计与创建一、数据库及表结构设计二、数据库与表的创建项目二:员

Linux查询服务器 IP 地址的命令详解

《Linux查询服务器IP地址的命令详解》在服务器管理和网络运维中,快速准确地获取服务器的IP地址是一项基本但至关重要的技能,下面我们来看看Linux中查询服务器IP的相关命令使用吧... 目录一、hostname 命令:简单高效的 IP 查询工具命令详解实际应用技巧注意事项二、ip 命令:新一代网络配置全

Linux查询服务器系统版本号的多种方法

《Linux查询服务器系统版本号的多种方法》在Linux系统管理和维护工作中,了解当前操作系统的版本信息是最基础也是最重要的操作之一,系统版本不仅关系到软件兼容性、安全更新策略,还直接影响到故障排查和... 目录一、引言:系统版本查询的重要性二、基础命令解析:cat /etc/Centos-release详

MySQL慢查询工具的使用小结

《MySQL慢查询工具的使用小结》使用MySQL的慢查询工具可以帮助开发者识别和优化性能不佳的SQL查询,本文就来介绍一下MySQL的慢查询工具,具有一定的参考价值,感兴趣的可以了解一下... 目录一、启用慢查询日志1.1 编辑mysql配置文件1.2 重启MySQL服务二、配置动态参数(可选)三、分析慢查

MyBatis流式查询两种实现方式

《MyBatis流式查询两种实现方式》本文详解MyBatis流式查询,通过ResultHandler和Cursor实现边读边处理,避免内存溢出,ResultHandler逐条回调,Cursor支持迭代... 目录MyBATis 流式查询详解:ResultHandler 与 Cursor1. 什么是流式查询?

Java慢查询排查与性能调优完整实战指南

《Java慢查询排查与性能调优完整实战指南》Java调优是一个广泛的话题,它涵盖了代码优化、内存管理、并发处理等多个方面,:本文主要介绍Java慢查询排查与性能调优的相关资料,文中通过代码介绍的非... 目录1. 事故全景:从告警到定位1.1 事故时间线1.2 关键指标异常1.3 排查工具链2. 深度剖析: