1.mtdåmtdblockçåºå«
2.Linux SPI-NAND 驱动开发指南
3.iMX6ull SDå¡ç³»ç»åNandflashç³»ç»
mtdåmtdblockçåºå«
mtd-utilså·¥å ·å¯¹mtdåmtdblockååºè®¾å¤çåºå«å¤ç
1 / $ flash_eraseall /dev/mtdblock/2
2 flash_eraseall: /dev/mtdblock/2: unable to get MTD device info
3 / $ flash_eraseall /dev/mtdblock/2
4 flash_eraseall: /dev/mtdblock/2: unable to get MTD device info
5 / $ flash_eraseall /dev/mtd/2
6 Erasing Kibyte @ 8e -- % complete.
7 / $ ls
1 / $ flashcp rootfs_version /dev/mtdblock2
2 This 源码doesn't seem to be a valid MTD flash device!
3 / $ flashcp rootfs_version /dev/mtdblock/2
4 This doesn't seem to be a valid MTD flash device!
5 / $ flashcp rootfs_version /dev/mtd2
6 / $ ls
mtdåmtdblockååºè®¾å¤mountæ¶çåºå«
1 / $ mount -t jffs2 /dev/mtd/2 qqzm/
2 mount: Mounting /dev/mtd/2 on qqzm/ failed: Invalid argument
3 / $ mount -t jffs2 /dev/mtd2 qqzm/
4 mount: Mounting /dev/mtd2 on qqzm/ failed: Invalid argument
5 / $ mount -t jffs2 /dev/mtdblock/2 qqzm/
6 / $ ls
mtdblockæè½½æåï¼åæ¦é¤åå¸è½½å¤±è´¥
/ $ flash_eraseall /dev/mtd/2 <span></span> Erasing Kibyte @ 8e -- % complete.
/qqzm $ mount
/dev/root on / type jffs2 (rw,noatime)
proc on /proc type proc (rw,nodiratime)
sysfs on /sys type sysfs (rw)
devfs on /dev type devfs (rw)
devpts on /dev/pts type devpts (rw)
/dev/mmcblk0p1 on /mnt/sd type vfat (rw,nodiratime,fmask=,dmask=,codepage=cp,iocharset=iso-1)
/dev/mtdblock/2 on /qqzm type jffs2 (rw,noatime)
none on /qqzm/www/cgi-bin/tmp type ramfs (rw)
/qqzm $ cd ..
/ $ umount /qqzm
umount: Couldn't umount /qqzm: Inappropriate ioctl for device
/ $ umount /dev/mtdblock/2
umount: Couldn't umount /dev/mtdblock/2: Inappropriate ioctl for device
/ $
MTDææ¯çåºæ¬åç
MTD(memory technology deviceå åææ¯è®¾å¤)æ¯ç¨äºè®¿é®memory设å¤ï¼ROMãflashï¼çLinuxçåç³»ç»ãMTDç主è¦ç®çæ¯ä¸ºäºä½¿æ°çmemory设å¤ç驱å¨æ´å ç®åï¼ä¸ºæ¤å®å¨ç¡¬ä»¶åä¸å±ä¹é´æä¾äºä¸ä¸ªæ½è±¡çæ¥å£ï¼å¹¶è¿è¡äºä¸ä¸ªå±æ¬¡ååï¼å±æ¬¡ä»ä¸å°ä¸å¤§è´ä¸ºï¼è®¾å¤æ件ãMTD设å¤å±ãMTDåå§è®¾å¤å±ã硬件驱å¨å±ãMTDçæææºä»£ç å¨/drivers/mtdåç®å½ä¸ã
ç³»ç»ä¸çMTD设å¤æ件
~ $ ls /dev/mtd* -l
crw-rw---- 1 root root , 0 Jan 1 : /dev/mtd0
crw-rw---- 1 root root , 1 Jan 1 : /dev/mtd0ro
crw-rw---- 1 root root , 2 Jan 1 : /dev/mtd1
crw-rw---- 1 root root , 3 Jan 1 : /dev/mtd1ro
crw-rw---- 1 root root , 4 Jan 1 : /dev/mtd2
crw-rw---- 1 root root , 5 Jan 1 : /dev/mtd2ro
crw-rw---- 1 root root , 6 Jan 1 : /dev/mtd3
crw-rw---- 1 root root , 7 Jan 1 : /dev/mtd3ro
brw-rw---- 1 root root , 0 Jan 1 : /dev/mtdblock0
brw-rw---- 1 root root , 1 Jan 1 : /dev/mtdblock1
brw-rw---- 1 root root , 2 Jan 1 : /dev/mtdblock2
brw-rw---- 1 root root , 3 Jan 1 : /dev/mtdblock3
/dev/mtd:
crw-rw-rw- 1 root root , 0 Jan 1 : 0
cr--r--r-- 1 root root , 1 Jan 1 : 0ro
crw-rw-rw- 1 root root , 2 Jan 1 : 1
cr--r--r-- 1 root root , 3 Jan 1 : 1ro
crw-rw-rw- 1 root root , 4 Jan 1 : 2
cr--r--r-- 1 root root , 5 Jan 1 : 2ro
crw-rw-rw- 1 root root , 6 Jan 1 : 3
cr--r--r-- 1 root root , 7 Jan 1 : 3ro
/dev/mtdblock:
brw------- 1 root root , 0 Jan 1 : 0
brw------- 1 root root , 1 Jan 1 : 1
brw------- 1 root root , 2 Jan 1 : 2
brw------- 1 root root , 3 Jan 1 : 3
~ $
å¯ä»¥çå°æmtdNå对åºç/dev/mtd/NãmtdblockNå对åºç/dev/mtdblock/N两类MTD设å¤ï¼åå«æ¯å符设å¤ï¼ä¸»è®¾å¤å·åå设å¤ï¼ä¸»è®¾å¤å·ãå ¶ä¸/dev/mtd0å/dev/mtd/0æ¯å®å ¨çä»·çï¼/dev/mtdblock0å/dev/mtdblock/0æ¯å®å ¨çä»·çï¼è/dev/mtd0å/dev/mtdblock0åæ¯åä¸ä¸ªMTDååºç两ç§ä¸ååºç¨æè¿°ï¼æä½ä¸æ¯æåºå«çã
/dev/mtdN设å¤
/dev/mtdN æ¯MTDæ¶æä¸å®ç°çmtdååºæ对åºçå符设å¤(å°mtd设å¤åæå¤ä¸ªåºï¼æ¯ä¸ªåºå°±ä¸ºä¸ä¸ªå符设å¤)ï¼å ¶éé¢æ·»å äºä¸äºioctlï¼æ¯æå¾å¤å½ä»¤ï¼å¦MEMGETINFOï¼MEMERASEçã
mtd-utilsä¸çflash_eraseallçå·¥å ·ï¼å°±æ¯ä»¥è¿äºioctl为åºç¡èå®ç°çå·¥å ·ï¼å®ç°ä¸äºå ³äºFlashçæä½ãæ¯å¦ï¼mtd å·¥å ·ä¸ flash_eraseallä¸ï¼
1 if (ioctl(fd, MEMGETINFO, &meminfo) != 0)
2 {
3 fprintf(stderr, "%s: %s: unable to get MTD device info\n",exe_name, mtd_device);
4 return 1;
5 }
MEMGETINFOæ¯Linux MTDä¸çdrivers/mtd/mtdchar.cä¸çioctlå½ä»¤ï¼ä½¿ç¨mtdå符设å¤éè¦å è½½mtdcharå æ ¸æ¨¡åã该代ç 解éäºä¸é¢ç第ä¸ä¸ªç°è±¡ã
/dev/mtdblockN设å¤
/dev/mtdblockNï¼æ¯Flash驱å¨ä¸ç¨add_mtd_partitions()æ·»å MTD设å¤ååºï¼èçæç对åºçå设å¤ãMTDå设å¤é©±å¨ç¨åºå¯ä»¥è®©flashå¨ä»¶ä¼ªè£ æå设å¤ï¼å®é ä¸å®éè¿ææ´åçerase blockæ¾å°raméé¢è¿è¡è®¿é®ï¼ç¶ååæ´æ°å°flashï¼ç¨æ·å¯ä»¥å¨è¿ä¸ªå设å¤ä¸å建é常çæ件系ç»ã
è对äºMTDå设å¤ï¼MTD设å¤å±æ¯ä¸æä¾ioctlçå®ç°æ¹æ³çï¼ä¹å°±ä¸ä¼æ对åºçMEMGETINFOå½ä»¤ä¹ç±»ï¼å æ¤ä¸è½ä½¿ç¨nandwrite,flash_eraseall,flash_eraseçå·¥å ·å»å¯¹/dev/mtdblockNå»è¿è¡æä½ï¼å¦åå°±ä¼åºç°ä¸é¢çç°è±¡ä¸ï¼åæ¶ä¹è§£éäºç°è±¡3ââç¨mtd2æ¦é¤ååºåï¼å¨ç¨mtdblock2è¿è¡umountå°±ä¼é ææ··ä¹±ã
mtdå设å¤ç大å°å¯ä»¥éè¿procæ件系ç»è¿è¡æ¥çï¼
~ $ cat /proc/partitions
major minor #blocks name
0 mtdblock0
1 mtdblock1
2 mtdblock2
3 mtdblock3
0 mmcblk0
1 mmcblk0p1
~ $
åé¢ç两个æ¯SDå设å¤çååºå¤§å°ãæ¯ä¸ªblockç大å°æ¯1KBã
MTD设å¤ååºåæ»ç»
éè¿procæ件系ç»æ¥çmtd设å¤çååºæ åµï¼
1 ~ $ cat /proc/mtd
2 dev: size erasesize name
3 mtd0: "boot"
4 mtd1: "kernel"
5 mtd2: "roofs"
6 mtd3: "app"
7 ~ $
å¯ä»¥åç°ï¼å®é ä¸mtdNåmtdblockNæè¿°çæ¯åä¸ä¸ªMTDååºï¼å¯¹åºåä¸ä¸ªç¡¬ä»¶ååºï¼ä¸¤è ç大å°æ¯ä¸æ ·çï¼åªä¸è¿æ¯MTD设å¤å±æä¾ç»ä¸å±çè§å¾ä¸ä¸æ ·ï¼ç»ä¸å±æä¾äºå符åå设å¤ä¸¤ç§æä½è§å¾ââ为äºä¸å±ä½¿ç¨ç便å©åéè¦ï¼æ¯å¦mountå½ä»¤çéæ±ï¼ä½ åªè½æè½½å设å¤(ææ件系ç»)ï¼èä¸è½å¯¹å符设å¤è¿è¡æè½½ï¼å¦åä¼åºç°ä¸é¢çç°è±¡2:æ æåæ°ã
è¿é对äºmtdåmtdblock设å¤ç使ç¨åºæ¯è¿è¡ç®åæ»ç»ï¼
mtd-utilså·¥å ·åªè½åºç¨ä¸/dev/mtdNçMTDå符设å¤
mountãumountå½ä»¤åªå¯¹/dev/mtdblockNçMTDå设å¤ææ
/dev/mtdNå/dev/mtdblockNæ¯åä¸ä¸ªMTD设å¤çåä¸ä¸ªååºï¼Nä¸æ ·ï¼
Linux SPI-NAND 驱动开发指南
Linux SPI-NAND 驱动开发指南概述 1.1 目的 本指南旨在详细介绍Sunxi SPINand mtd/ubi驱动,为驱动和应用开发者提供便利。源码 1.2 适用范围 适用于所有sunxi平台的源码NAND MTD/UBI驱动开发。 1.3 参与人员 包括NAND模块开发者和应用开发者在内的源码相关人员。关键概念
MTD:Linux子系统中的源码开奖网源码出售内存技术设备,负责Flash驱动部分。源码觅元素网站源码 UBI:基于MTD的源码子系统,管理NAND特性,源码屏蔽底层细节。源码 坏块:由制造工艺和设备性质导致的源码不可用存储单元。开发流程
3.1 结构设计 NAND MTD/UBI驱动由5个核心组件构成,源码如图所示: 3.2 源码位置 驱动代码位于Linux 5.4内核的源码mtd/awnand/spinand目录下。关键数据定义
flash设备信息:包含型号、源码安卓 源码下载ID、源码芯片内部结构等详细参数。源码
chip操作接口:如读写、擦除、银行jsp项目源码ecc处理和缓存管理等。
操作请求结构:定义了操作的目标页面和数据结构。
UBI ECC header:存储擦除计数器等信息。
UBI VID header:逻辑和物理块映射的2017爱之谷源码详细描述。
接口说明
3.4.1 MTD层接口:包括 erase、read、read_oob、write、write_oob、检查坏块和标记坏块等。 3.4.2 物理层接口:针对芯片级别的读写、擦除和坏块操作。模块配置
4.1 U-Boot配置:涉及特定菜单项,如图所示。 4.2 内核配置:涉及UBI、NAND和SPI相关配置,如SPI设备、DMA和SID设置。 4.3 env.cfg:在构建过程中,通过添加特定变量来定制驱动环境。iMX6ull SDå¡ç³»ç»åNandflashç³»ç»
ç³»ç»æºç åç¼è¯æ¹æ³ï¼[åè§è¿æ¥] ( munity.nxp.com/docs/DOC- )å ¶ä¸dtbæ件é对LCDæHDMIä¿®æ¹çå 容对iSpeakeræ å½±åï¼ä¸ç¨å»ä¿®æ¹ãæ们ä¼ä½¿ç¨å¦å¤çdtbæ件ã
ç§åSDæ¹å¼ä¹ä¸éç¨è¿ä¸ªææ¡£ä¸çæ¹æ³ï¼ç´æ¥å¨linuxå½ä»¤è¡ä¸å¦ä¸æä½ï¼
Nandflash使ç¨zImageï¼dtbæ件åSDå¡ä¸ä½¿ç¨çå®å ¨ä¸è´ãUbootæ件SDä¸ä½¿ç¨çä¸è½ç¨äºNandflashï¼æºç å¦è§ã
ç§åNandflashéè¦ç¨SDå¡ç³»ç»çå¯å¨ï¼SDå¡ç³»ç»ä¸éè¦å·²å®è£ mtd-utilså·¥å ·ãç³»ç»å¯å¨åè½æ£å¸¸çå°mtd0~mtd4ååºãæç §ä¸é¢æ¥éª¤æä½ï¼
$ flash_erase /dev/mtd0 0 0
$ flash_erase /dev/mtd1 0 0
$ flash_erase /dev/mtd2 0 0
$ kobs-ng init -x u-boot.imx --search_exponent=1 -v
$ flash_erase /dev/mtd3 0 0
$ nandwrite -p /dev/mtd3 zImage
$ nandwrite -p /dev/mtd3 -s 0x7e imx.dtb
$ ubiformat /dev/mtd4 -f ubi.img
å ¶ä¸ä½¿ç¨ubi.imgæ件ï¼å¨linux主æºä¸å¶ä½æ¹æ³å¦ä¸ï¼
使ç¨çæ ¹æ件系ç»åSDå¡ä¸çæ ¹æ件系ç»ä¸æ ·ï¼å设SDå¡å·²æå ¥linux主æºusbæ¥å£ï¼å¹¶å°ç¬¬äºä¸ªååºæè½½ä¸/mntä¸ï¼é¦å å¨linux主æºå·¥ä½ç®å½ä¸å»ºç«ææ¬æ件ubifs.cfgï¼å 容å¦ä¸ï¼
[ubifs]
mode=ubi
image=ubifs.img
vol_id=0
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize
ç¶åæ§è¡å¦ä¸å½ä»¤ï¼
$ mkfs.ubifs -x zlib -m -e KiB -c -r /mnt ubifs.img
$ ubinize -o ubi.img -m -p KiB -s -O ubifs.cfg
2024-12-27 16:09
2024-12-27 16:07
2024-12-27 16:02
2024-12-27 15:45
2024-12-27 14:49
2024-12-27 14:36
2024-12-27 14:30
2024-12-27 14:21