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

相关文章

SQL 中多表查询的常见连接方式详解

《SQL中多表查询的常见连接方式详解》本文介绍SQL中多表查询的常见连接方式,包括内连接(INNERJOIN)、左连接(LEFTJOIN)、右连接(RIGHTJOIN)、全外连接(FULLOUTER... 目录一、连接类型图表(ASCII 形式)二、前置代码(创建示例表)三、连接方式代码示例1. 内连接(I

轻松上手MYSQL之JSON函数实现高效数据查询与操作

《轻松上手MYSQL之JSON函数实现高效数据查询与操作》:本文主要介绍轻松上手MYSQL之JSON函数实现高效数据查询与操作的相关资料,MySQL提供了多个JSON函数,用于处理和查询JSON数... 目录一、jsON_EXTRACT 提取指定数据二、JSON_UNQUOTE 取消双引号三、JSON_KE

查询SQL Server数据库服务器IP地址的多种有效方法

《查询SQLServer数据库服务器IP地址的多种有效方法》作为数据库管理员或开发人员,了解如何查询SQLServer数据库服务器的IP地址是一项重要技能,本文将介绍几种简单而有效的方法,帮助你轻松... 目录使用T-SQL查询方法1:使用系统函数方法2:使用系统视图使用SQL Server Configu

MYSQL关联关系查询方式

《MYSQL关联关系查询方式》文章详细介绍了MySQL中如何使用内连接和左外连接进行表的关联查询,并展示了如何选择列和使用别名,文章还提供了一些关于查询优化的建议,并鼓励读者参考和支持脚本之家... 目录mysql关联关系查询关联关系查询这个查询做了以下几件事MySQL自关联查询总结MYSQL关联关系查询

Java实现Elasticsearch查询当前索引全部数据的完整代码

《Java实现Elasticsearch查询当前索引全部数据的完整代码》:本文主要介绍如何在Java中实现查询Elasticsearch索引中指定条件下的全部数据,通过设置滚动查询参数(scrol... 目录需求背景通常情况Java 实现查询 Elasticsearch 全部数据写在最后需求背景通常情况下

查询Oracle数据库表是否被锁的实现方式

《查询Oracle数据库表是否被锁的实现方式》本文介绍了查询Oracle数据库表是否被锁的方法,包括查询锁表的会话、人员信息,根据object_id查询表名,以及根据会话ID查询和停止本地进程,同时,... 目录查询oracle数据库表是否被锁1、查询锁表的会话、人员等信息2、根据 object_id查询被

Oracle查询优化之高效实现仅查询前10条记录的方法与实践

《Oracle查询优化之高效实现仅查询前10条记录的方法与实践》:本文主要介绍Oracle查询优化之高效实现仅查询前10条记录的相关资料,包括使用ROWNUM、ROW_NUMBER()函数、FET... 目录1. 使用 ROWNUM 查询2. 使用 ROW_NUMBER() 函数3. 使用 FETCH FI

数据库oracle用户密码过期查询及解决方案

《数据库oracle用户密码过期查询及解决方案》:本文主要介绍如何处理ORACLE数据库用户密码过期和修改密码期限的问题,包括创建用户、赋予权限、修改密码、解锁用户和设置密码期限,文中通过代码介绍... 目录前言一、创建用户、赋予权限、修改密码、解锁用户和设置期限二、查询用户密码期限和过期后的修改1.查询用

使用SQL语言查询多个Excel表格的操作方法

《使用SQL语言查询多个Excel表格的操作方法》本文介绍了如何使用SQL语言查询多个Excel表格,通过将所有Excel表格放入一个.xlsx文件中,并使用pandas和pandasql库进行读取和... 目录如何用SQL语言查询多个Excel表格如何使用sql查询excel内容1. 简介2. 实现思路3

MySQL不使用子查询的原因及优化案例

《MySQL不使用子查询的原因及优化案例》对于mysql,不推荐使用子查询,效率太差,执行子查询时,MYSQL需要创建临时表,查询完毕后再删除这些临时表,所以,子查询的速度会受到一定的影响,本文给大家... 目录不推荐使用子查询和JOIN的原因解决方案优化案例案例1:查询所有有库存的商品信息案例2:使用EX