作者

QQ群:852283276
微信:arm80x86
微信公众号:青儿创客基地
B站:主页 https://space.bilibili.com/208826118

参考

mtd-physmap
General MTD documentation

问题

开机启动打印,

jffs2: Write of 109 bytes at 0x0160f61c failed. returned -5, retlen 108
jffs2: Write of 109 bytes at 0x0160f68c failed. returned -5, retlen 108
jffs2: Write of 45 bytes at 0x0160f784 failed. returned -5, retlen 44
jffs2: Write of 45 bytes at 0x0160f7b4 failed. returned -5, retlen 44
jffs2: Write of 77 bytes at 0x0160f828 failed. returned -5, retlen 76
jffs2: Write of 77 bytes at 0x0160f878 failed. returned -5, retlen 76

写flash打印,

root@t2080rdb:~# fw_setenv flag 1
MTD erase error on /dev/mtd6: Input/output error
Error: can't write fw_env to flash

其中Input/output error就是代表returned -5

分析

用户层发起ioctl传到驱动drivers\mtd\mtdchar.c

mtdchar_ioctl

cfi-flash对应驱动代码为drivers\mtd\maps\physmap_of.c

Nor Flash设备树

CFI or JEDEC memory-mapped NOR flash, MTD-RAM (NVRAM…)

Flash chips (Memory Technology Devices) are often used for solid state file systems on embedded devices.

  • compatible : should contain the specific model of mtd chip(s) used, if known, followed by either “cfi-flash”, “jedec-flash”, “mtd-ram” or “mtd-rom”.
  • reg : Address range(s) of the mtd chip(s) It’s possible to (optionally) define multiple “reg” tuples so that non-identical chips can be described in one node.
  • bank-width : Width (in bytes) of the bank. Equal to the device width times the number of interleaved chips.
  • device-width : (optional) Width of a single mtd chip. If omitted, assumed to be equal to ‘bank-width’.
  • #address-cells, #size-cells : Must be present if the device has sub-nodes representing partitions (see below). In this case both #address-cells and #size-cells must be equal to 1.
  • no-unaligned-direct-access: boolean to disable the default direct mapping of the flash. On some platforms (e.g. MPC5200) a direct 1:1 mapping may cause problems with JFFS2 usage, as the local bus (LPB) doesn’t support unaligned accesses as implemented in the JFFS2 code via memcpy(). By defining “no-unaligned-direct-access”, the flash will not be exposed directly to the MTD users (e.g. JFFS2) any more.
  • linux,mtd-name: allow to specify the mtd name for retro capability with physmap-flash drivers as boot loader pass the mtd partition via the old device name physmap-flash.
  • use-advanced-sector-protection: boolean to enable support for the advanced sector protection (Spansion: PPB - Persistent Protection Bits) locking.
  • addr-gpios : (optional) List of GPIO descriptors that will be used to address the MSBs address lines. The order goes from LSB to MSB.

For JEDEC compatible devices, the following additional properties are defined:

  • vendor-id : Contains the flash chip’s vendor id (1 byte).
  • device-id : Contains the flash chip’s device id (1 byte).

For ROM compatible devices (and ROM fallback from cfi-flash), the following additional (optional) property is defined:

  • erase-size : The chip’s physical erase block size in bytes.

The device tree may optionally contain endianness property. little-endian or big-endian : It Represents the endianness that should be used by the controller to properly read/write data from/to the flash. If this property is missing, the endianness is chosen by the system (potentially based on extra configuration options).
The device tree may optionally contain sub-nodes describing partitions of the address space. See partition.txt for more detail.
Example:

    flash@ff000000 {compatible = "amd,am29lv128ml", "cfi-flash";reg = <ff000000 01000000>;bank-width = <4>;device-width = <1>;#address-cells = <1>;#size-cells = <1>;fs@0 {label = "fs";reg = <0 f80000>;};firmware@f80000 {label ="firmware";reg = <f80000 80000>;read-only;};};

Here an example with multiple “reg” tuples:

    flash@f0000000,0 {#address-cells = <1>;#size-cells = <1>;compatible = "intel,PC48F4400P0VB", "cfi-flash";reg = <0 0x00000000 0x020000000 0x02000000 0x02000000>;bank-width = <2>;partition@0 {label = "test-part1";reg = <0 0x04000000>;};};

An example using SRAM:

    sram@2,0 {compatible = "samsung,k6f1616u6a", "mtd-ram";reg = <2 0 0x00200000>;bank-width = <2>;};

分区的描述,

Representing flash partitions in devicetree
Partitions can be represented by sub-nodes of an mtd device. This can be used on platforms which have strong conventions about which portions of a flash are used for what purposes, but which don't use an on-flash partition table such as RedBoot. NOTE: if the sub-node has a compatible string, then it is not a partition.
#address-cells & #size-cells must both be present in the mtd device. There are two valid values for both: <1>: for partitions that require a single 32-bit cell to represent their size/address (aka the value is below 4 GiB) <2>: for partitions that require two 32-bit cells to represent their size/address (aka the value is 4 GiB or greater).
Required properties:
- reg : The partition's offset and size within the mtd bank.
Optional properties:
- label : The label / name for this partition.  If omitted, the label is taken from the node name (excluding the unit address).
- read-only : This parameter, if present, is a hint to Linux that this partition should only be mounted read-only. This is usually used for flash partitions containing early-boot firmware images or data which should not be clobbered.
Examples:
flash@0 { #address-cells = <1>;#size-cells = <1>;partition@0 { label = "u-boot";reg = <0x0000000 0x100000>;read-only; };uimage@100000 { reg = <0x0100000 0x200000>; }; };
flash@1 { #address-cells = <1>;#size-cells = <2>;/* a 4 GiB partition */partition@0 { label = "filesystem";reg = <0x00000000 0x1 0x00000000>; }; };
flash@2 { #address-cells = <2>;#size-cells = <2>;/* an 8 GiB partition */partition@0 { label = "filesystem #1";reg = <0x0 0x00000000 0x2 0x00000000>; };/* a 4 GiB partition */partition@200000000 { label = "filesystem #2";reg = <0x2 0x00000000 0x1 0x00000000>; }; };

测试

root@zynq:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 000c0000 00001000 "boot"
mtd1: 00020000 00001000 "bootenv"
mtd2: 00020000 00001000 "bootenvredund"
mtd3: 01300000 00001000 "pl"
mtd4: 00c00000 00001000 "kernel"

linux mtd设备使用相关推荐

  1. Linux MTD设备文件系统

    1. 文件系统简介 文件系统是一种存储和组织计算机数据的方法,它使得对其访问和查找变得容易,文件系统使用文件和树形目录的抽象逻辑概念代替了硬盘和光盘等物理设备使用数据块的概念,用户使用文件系统来保存数 ...

  2. Linux中不同MTD设备分区,Linux MTD设备总结

    1 flash如何分区? 见内核配置与编译 系统启动后,在dev目录下,/dev/mtd0,1,2等代表char型设备,mtd0代表flash的第一分区,依次类推:/dev/mtdblock0,1,2 ...

  3. 嵌入式linux mtd,嵌入式Linux驱动设备之MTD技术详解

    原标题:嵌入式Linux驱动设备之MTD技术详解 MTD(memory technology device内存技术设备)是用于访问memory设备(ROM.flash)的Linux的子系统. MTD的 ...

  4. Linux MTD架构下的nand flash驱动详解

    转载自:http://blog.csdn.net/wang_zheng_kai/article/details/18988521 有了前面的基础(Nandflash详解:https://blog.cs ...

  5. MTD 设备驱动 和 NAND Flash 驱动程序分析。

    硬件环境: 飞凌OK6410,256MB DDR,2GB NAND Flash.   NAND Flash 型号:K9G8G08U9A   .     分析源码:Linux 2.6.36.2 内核源码 ...

  6. 通过mtd读写flash_【转】 Linux下读写FLASH驱动——MTD设备分析

    最近在学习驱动读写flash的代码部分.经历了可笑的过程:开始我知道flash用通过spi口来读写.所以就到了driver/spi 下面看相关代码.发现有个spidev.c里面有read/write/ ...

  7. mtd分区创建linux,浅析linux下mtd设备onenand存储器的分区和节点创建流程及yaffs2文件系统挂载...

    浅析linux下mtd设备onenand存储器的分区和节点创建流程及yaffs2文件系统挂载 在arch/arm/mach-pxa/luther.c这个产品平台文件中,即: MACHINE_START ...

  8. linux mtd 块设备,Linux系统中/dev/mtd与/dev/mtdblock的区别,即MTD字符设备和块设备的区别...

    转:http://www.crifan.com/linux_system_in__dev__mtd_and__dev__mtdblock_distinction_character_devices_a ...

  9. Linux块设备驱动-MTD子系统

    Linux块设备驱动 块设备驱动 块设备驱动的引入 1. 简单字符驱动程序思想 2. 块设备驱动程序思想 块设备驱动框架 1. 层次框架 2. 分析ll_rw_block 块设备驱动程序编写 1.分配 ...

最新文章

  1. python怎么保存数据框转置结果_python – 如何转置pandas数据帧以交叉制表保存所有值的数据帧...
  2. 快手EB级HDFS挑战与实践
  3. 微信扫码支付模式二【无法回调】解决方案
  4. 基于WINCE6.0+S3C6410的背光驱动
  5. Java面试宝典系列之面试复习提纲
  6. 关于移动端meta设置(未完待续)
  7. iOS Core Animation学习总结(2)--实现自定义图层
  8. 一张图11招学会Python网络黑客
  9. 2021-08-15 reponse文件下载路径
  10. android sdk dns,Android SDK 导入
  11. win10解压软件哪个好(win10用哪个解压软件)
  12. 公交车管理系统C语言
  13. FFmpeg —— 屏幕录像机
  14. 【学习求职必备】微软亚洲研究院和它的10大AI黑科技
  15. python的flask前端显示图片_Python flask框架如何显示图像到web页面
  16. PayPal提现银行不给入账要退回?最新解决方法如下!!!
  17. go语言循环基础练习
  18. iOS运行时Runtime浅析
  19. 3_IMX6ULL启动流程
  20. 小白也能看懂的零信任SDP介绍

热门文章

  1. 快递查询APP隐私条款
  2. PEST分析顺丰服务需求_快递行业宏观环境分析
  3. 黑客全票打飞服务器,《鹅鸭杀》停服三天!更有游戏首发被冲下架
  4. 合肥辰工科技有限公司
  5. 李白 宣州谢朓楼饯别校书叔云
  6. SQL案例学习-数据透视表
  7. 【每日新闻】国内首款3D AI/MR芯片即将量产
  8. 也谈谈我对腾讯“抄袭”的认识
  9. 成绩不好的穷孩子,该做出选择了
  10. jar包启动调用外系统文件上传,无法生成文件,报org.springframework.web.client. ResourceAccessException: I/0 error on POST