CFI查询(三)

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

本文主要是介绍CFI查询(三),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1、上一篇通过结构体

static struct chip_probe cfi_chip_probe = {
name: "CFI",
probe_chip: cfi_probe_chip
};

了解到,主要的查询工作要靠probe_chip: cfi_probe_chip函数完成。

其源码如下:

static int cfi_probe_chip(struct map_info *map, __u32 base,
 struct flchip *chips, struct cfi_private *cfi)

这是在上一篇中,调用次函数的情景:

cp->probe_chip(map, 0, NULL, 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);

向闪存芯片发送两条命令,如下表所示


第一条命令是0xf0是芯片进入随机读取状态。

第二条命令是0x98是芯片开始一个CFI查询流程。

函数cfi_send_gen_cmd函数源码如下:

/*
 * Sends a CFI command to a bank of flash for the given geometry.
 *
 * Returns the offset in flash where the command was written.
 * If prev_val is non-null, it will be set to the value at the command address,
 * before the command was written.
 */
static inline __u32 cfi_send_gen_cmd(u_char cmd, __u32 cmd_addr, __u32 base,
struct map_info *map, struct cfi_private *cfi,
int type, cfi_word *prev_val)
{
cfi_word val;
__u32 addr = base +
cfi_build_cmd_addr(cmd_addr, CFIDEV_INTERLEAVE, type);地址换算

val =
cfi_build_cmd(cmd, map, cfi);命令调整

        这两个函数根据具体的芯片格局对地址和命令作出换算和调整。

这是cfi_build_cmd_addr函数源码:

/*
 * Returns the command address according to the given geometry.
 */
static inline __u32 cfi_build_cmd_addr(__u32 cmd_ofs, int interleave, int type)
{
return (cmd_ofs * type) * interleave;
}


这是cfi_build_cmd函数源码:

在有多个芯片并列时,对芯片的命令要写入到并列的每一个芯片中,所以需要根据具体的情况将命令重复几次。CFI规定16位和32位数据均采用“小端”格式,而有些CPU采用“大端”格式,所以要通过函数cpu_to_cfi32转化。如果CPU本就是“小端”,则本函数为空。
/*
 * Transforms the CFI command for the given geometry (bus width & interleave.
 */
static inline cfi_word cfi_build_cmd(u_char cmd, struct map_info *map, struct cfi_private *cfi)
{
cfi_word val = 0;


if (cfi_buswidth_is_1()) {
/* 1 x8 device */
val = cmd;
} else if (cfi_buswidth_is_2()) {
if (cfi_interleave_is_1()) {
/* 1 x16 device in x16 mode */
val = cpu_to_cfi16(cmd);
} else if (cfi_interleave_is_2()) {
/* 2 (x8, x16 or x32) devices in x8 mode */
val = cpu_to_cfi16((cmd << 8) | cmd);
}
} else if (cfi_buswidth_is_4()) {
if (cfi_interleave_is_1()) {
/* 1 x32 device in x32 mode */
val = cpu_to_cfi32(cmd);
} else if (cfi_interleave_is_2()) {
/* 2 x16 device in x16 mode */
val = cpu_to_cfi32((cmd << 16) | cmd);
} else if (cfi_interleave_is_4()) {
/* 4 (x8, x16 or x32) devices in x8 mode */
val = (cmd << 16) | cmd;
val = cpu_to_cfi32((val << 8) | val);
}
#ifdef CFI_WORD_64
} else if (cfi_buswidth_is_8()) {
if (cfi_interleave_is_1()) {
/* 1 x64 device in x64 mode */
val = cpu_to_cfi64(cmd);
} else if (cfi_interleave_is_2()) {
/* 2 x32 device in x32 mode */
val = cmd;
val = cpu_to_cfi64((val << 32) | val);
} else if (cfi_interleave_is_4()) {
/* 4 (x16, x32 or x64) devices in x16 mode */
val = (cmd << 16) | cmd;
val = cpu_to_cfi64((val << 32) | val);
} else if (cfi_interleave_is_8()) {
/* 8 (x8, x16 or x32) devices in x8 mode */
val = (cmd << 8) | cmd;
val = (val << 16) | val;
val = (val << 32) | val;
val = cpu_to_cfi64(val);
}
#endif /* CFI_WORD_64 */
}
return val;
}

if (prev_val)
*prev_val = cfi_read(map, addr);

cfi_write(map, val, addr);

return addr - base;
}

注:CFI查询中所用的地址都是以芯片本身的存储单元为单位的,而CPU使用的32位地址则是字节地址,所以要根据芯片的宽度加以换算。当采用多个芯片并列时实际上相当于改变了芯片宽度,因此需要进一步加以换算。


/*
 * Read a value according to the bus width.
 */


static inline cfi_word cfi_read(struct map_info *map, __u32 addr)
{
if (cfi_buswidth_is_1()) {
return map->read8(map, addr);
} else if (cfi_buswidth_is_2()) {
return map->read16(map, addr);
} else if (cfi_buswidth_is_4()) {
return map->read32(map, addr);
} else if (cfi_buswidth_is_8()) {
return map->read64(map, addr);
} else {
return 0;
}
}

此函数从目标地址中读出数据,具体的调用那个函数取决于数据宽度和map_info结构中的函数指针。

cfi_write也类似。
/*
 * Write a value according to the bus width.
 */

static inline void cfi_write(struct map_info *map, cfi_word val, __u32 addr)
{
if (cfi_buswidth_is_1()) {
map->write8(map, val, addr);
} else if (cfi_buswidth_is_2()) {
map->write16(map, val, addr);
} else if (cfi_buswidth_is_4()) {
map->write32(map, val, addr);
} else if (cfi_buswidth_is_8()) {
map->write64(map, val, addr);
}
}





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);
}


/* 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;
}

下一篇接着说:

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



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

相关文章

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