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查询的相关知识,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录mysql 的 jsON 路径格式基本结构路径组件详解特殊语法元素实际示例简单路径复杂路径简写操作符注意MySQL 的 J

Go语言开发实现查询IP信息的MCP服务器

《Go语言开发实现查询IP信息的MCP服务器》随着MCP的快速普及和广泛应用,MCP服务器也层出不穷,本文将详细介绍如何在Go语言中使用go-mcp库来开发一个查询IP信息的MCP... 目录前言mcp-ip-geo 服务器目录结构说明查询 IP 信息功能实现工具实现工具管理查询单个 IP 信息工具的实现服

MySQL索引的优化之LIKE模糊查询功能实现

《MySQL索引的优化之LIKE模糊查询功能实现》:本文主要介绍MySQL索引的优化之LIKE模糊查询功能实现,本文通过示例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录一、前缀匹配优化二、后缀匹配优化三、中间匹配优化四、覆盖索引优化五、减少查询范围六、避免通配符开头七、使用外部搜索引擎八、分

SQL表间关联查询实例详解

《SQL表间关联查询实例详解》本文主要讲解SQL语句中常用的表间关联查询方式,包括:左连接(leftjoin)、右连接(rightjoin)、全连接(fulljoin)、内连接(innerjoin)、... 目录简介样例准备左外连接右外连接全外连接内连接交叉连接自然连接简介本文主要讲解SQL语句中常用的表

MySQL高级查询之JOIN、子查询、窗口函数实际案例

《MySQL高级查询之JOIN、子查询、窗口函数实际案例》:本文主要介绍MySQL高级查询之JOIN、子查询、窗口函数实际案例的相关资料,JOIN用于多表关联查询,子查询用于数据筛选和过滤,窗口函... 目录前言1. JOIN(连接查询)1.1 内连接(INNER JOIN)1.2 左连接(LEFT JOI

MySQL 中查询 VARCHAR 类型 JSON 数据的问题记录

《MySQL中查询VARCHAR类型JSON数据的问题记录》在数据库设计中,有时我们会将JSON数据存储在VARCHAR或TEXT类型字段中,本文将详细介绍如何在MySQL中有效查询存储为V... 目录一、问题背景二、mysql jsON 函数2.1 常用 JSON 函数三、查询示例3.1 基本查询3.2

MySQL中的交叉连接、自然连接和内连接查询详解

《MySQL中的交叉连接、自然连接和内连接查询详解》:本文主要介绍MySQL中的交叉连接、自然连接和内连接查询,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、引入二、交php叉连接(cross join)三、自然连接(naturalandroid join)四

mysql的基础语句和外键查询及其语句详解(推荐)

《mysql的基础语句和外键查询及其语句详解(推荐)》:本文主要介绍mysql的基础语句和外键查询及其语句详解(推荐),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋... 目录一、mysql 基础语句1. 数据库操作 创建数据库2. 表操作 创建表3. CRUD 操作二、外键

Mybatis 传参与排序模糊查询功能实现

《Mybatis传参与排序模糊查询功能实现》:本文主要介绍Mybatis传参与排序模糊查询功能实现,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、#{ }和${ }传参的区别二、排序三、like查询四、数据库连接池五、mysql 开发企业规范一、#{ }和${ }传参的

浅谈mysql的sql_mode可能会限制你的查询

《浅谈mysql的sql_mode可能会限制你的查询》本文主要介绍了浅谈mysql的sql_mode可能会限制你的查询,这个问题主要说明的是,我们写的sql查询语句违背了聚合函数groupby的规则... 目录场景:问题描述原因分析:解决方案:第一种:修改后,只有当前生效,若是mysql服务重启,就会失效;