通过/proc虚拟文件系统读取MTD分区表:cat /proc/mtd

mtd .name = raspi, .size = 0x00400000 (4M) .erasesize = 0x00010000 (64K).numeraseregions = 0

Creating 6 MTD partitions on "raspi":

0x00000000-0x00400000 : "ALL"

0x00000000-0x00030000 : "Bootloader"

0x00030000-0x00040000 : "Config"

0x00040000-0x00050000 : "Factory"

0x00050000-0x00360000 : "Kernel"

0x00360000-0x003b0000 : "DATA"

通过这个结构体可知size是本mtd分区的最大字节数空间,erasesize是本分区的最小擦除字节数空间(块大小,linux的flash是以块为擦除单位的)。

下面是别人的文章:

具体由linux/drivers/mtd下的mtdcore.c文件中的mtd_read_proc函数来实现:

static inline int mtd_proc_info (char *buf, int i)

{

struct mtd_info *this = mtd_table[i];

if (!this)

return 0;

return sprintf(buf, "mtd%d: %8.8x %8.8x \"%s\"\n", i, this->size,

this->erasesize, this->name);

}

static int mtd_read_proc (char *page, char **start, off_t off, int count,

int *eof, void *data_unused)

{

int len, l, i;

off_t begin = 0;

mutex_lock(&mtd_table_mutex);

len = sprintf(page, "dev: size erasesize name\n");

for (i=0; i< MAX_MTD_DEVICES; i++) {

l = mtd_proc_info(page + len, i);

len += l;

if (len+begin > off+count)

goto done;

if (len+begin < off) {

begin += len;

len = 0;

}

}

*eof = 1;

done:

mutex_unlock(&mtd_table_mutex);

if (off >= len+begin)

return 0;

*start = page + (off-begin);

return ((count < begin+len-off) ? count : begin+len-off);

}

读出来的结果如下:

dev: size erasesize name

mtd0: 01000000 00020000 "boot"

mtd1: 01000000 00020000 "setting"

mtd2: 02000000 00020000 "rootfs"

mtd3: 0be00000 00020000 "home"

mtd4: 00200000 00020000 "storage"

mtd5: 00040000 00010000 "u-boot"

mtd6: 00040000 00010000 "others"

其中size和erasesize的定义在linux/include/linux/mtd下mtd.h文件中的struct mtd_info结构体定义:

struct mtd_info {

u_char type;

u_int32_t flags;

u_int32_t size; // Total size of the MTD

/* "Major" erase size for the device. users may take this

* to be the only erase size available, or may use the more detailed

* information below if they desire

*/

u_int32_t erasesize;

/* Minimal writable flash unit size. In case of NOR flash it is 1 (even

* though individual bits can be cleared), in case of NAND flash it is

* one NAND page (or half, or one-fourths of it), in case of ECC-ed NOR

* it is of ECC block size, etc. It is illegal to have writesize = 0.

* Any driver registering a struct mtd_info must ensure a writesize of

* 1 or larger.

*/

u_int32_t writesize;

u_int32_t oobsize; // Amount of OOB data per block (e.g. 16)

u_int32_t oobavail; // Available OOB bytes per block

// Kernel-only stuff starts here.

char *name;

int index;

/* ecc layout structure pointer - read only ! */

struct nand_ecclayout *ecclayout;

/* Data for variable erase regions. If numeraseregions is zero,

* it means that the whole device has erasesize as given above.

*/

int numeraseregions;

struct mtd_erase_region_info *eraseregions;

int (*erase) (struct mtd_info *mtd, struct erase_info *instr);

/* This stuff for eXecute-In-Place */

int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf);

/* We probably shouldn't allow XIP if the unpoint isn't a NULL */

void (*unpoint) (struct mtd_info *mtd, u_char * addr, loff_t from, size_t len);

int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);

int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);

int (*read_oob) (struct mtd_info *mtd, loff_t from,

struct mtd_oob_ops *ops);

int (*write_oob) (struct mtd_info *mtd, loff_t to,

struct mtd_oob_ops *ops);

/*

* Methods to access the protection register area, present in some

* flash devices. The user data is one time programmable but the

* factory data is read only.

*/

int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);

int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);

int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);

int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);

int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);

int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len);

/* kvec-based read/write methods.

NB: The 'count' parameter is the number of _vectors_, each of

which contains an (ofs, len) tuple.

*/

int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);

/* Sync */

void (*sync) (struct mtd_info *mtd);

/* Chip-supported device locking */

int (*lock) (struct mtd_info *mtd, loff_t ofs, size_t len);

int (*unlock) (struct mtd_info *mtd, loff_t ofs, size_t len);

/* Power Management functions */

int (*suspend) (struct mtd_info *mtd);

void (*resume) (struct mtd_info *mtd);

/* Bad block management functions */

int (*block_isbad) (struct mtd_info *mtd, loff_t ofs);

int (*block_markbad) (struct mtd_info *mtd, loff_t ofs);

struct notifier_block reboot_notifier; /* default mode before reboot */

/* ECC status information */

struct mtd_ecc_stats ecc_stats;

/* Subpage shift (NAND) */

int subpage_sft;

void *priv;

struct module *owner;

int usecount;

/* If the driver is something smart, like UBI, it may need to maintain * its own reference counting. The below functions are only for driver. * The driver may register its callbacks. These callbacks are not * supposed to be called by MTD users */ int (*get_device) (struct mtd_info *mtd); void (*put_device) (struct mtd_info *mtd); }

linux 内核 mtd读取,/proc/mtd 各个参数含义 -- linux内核相关推荐

  1. /proc/mtd 各个参数含义 -- linux内核

    通过/proc虚拟文件系统读取MTD分区表:cat /proc/mtd mtd .name = raspi, .size = 0x00400000 (4M) .erasesize = 0x000100 ...

  2. linux 设备树 usb控制器,linux 设备树中 dwc3 节点的phys参数含义

    找了好久今天找到了,记录一下: &dwc3_0 { ... phys = ; ... } Required properties (port (child) nodes): lane0: - ...

  3. linux下刻录光盘读取不了_如何在Linux下刻录数据光盘

    caoshun(原作) 本着让Linux精神发扬光大宗旨,我将部门原来的Windows2000服务器上所有的数据与提供的服务全部迁移到新建的Linux服务器上.在我即将要把这台老Windows2000 ...

  4. linux前一个的输出作为后一个参数,将Linux命令的结果作为下一个命令的参数

    查询所有的pid并杀死. jps -l | grep bdcsc2-native-demo | awk '{print $1}' | xargs kill -9 KISS:keep it short ...

  5. linux下刻录光盘读取不了_怎么从Linux命令行刻录镜像文件到DVD光盘中

    当我们在操作Linux系统的时候,需要将镜像文件刻录到DVD中,那么要怎么做呢?下面小编给大家介绍下怎么从Linux命令行刻录镜像文件到DVD中,一起来学习下吧. 最常见的两种镜像文件格式是ISO(. ...

  6. Linux cp命令的使用方法与参数含义

    1.Linux cp命令 拷贝文件 https://blog.csdn.net/sqbzo/article/details/9000027 2.linux复制指定目录下的全部文件到另一个目录中,lin ...

  7. linux字符集设置为英文,NLS_lang参数设置-linux设置字符集(国外英文资料).doc

    NLS_lang参数设置-linux设置字符集(国外英文资料) 奉菱砰台沉朽签屋玫庚撤骂这臼稠兢掠呆电砾呀萝邦天部辨残涅劫勿炕赘族甫最逆谢店勿鞋子胯污助卑叛滓耪汲矢容谐薪噪惧缎羡绎缘寐懈绊件秃拓轮氛牧 ...

  8. linux操作系统字段含义,Linux系统 /etc/fstab各个字段含义解释

    Linux系统 /etc/fstab各个字段含义解释 # fstab文件的作用 文件/etc/fstab存放的是系统中的文件系统信息.当正确的设置了该文件,则可以通过"mount /dire ...

  9. /proc/mtd 各参数的含义 -- linux内核

    经/proc虚拟文件系统读取MTD分区表:cat /proc/mtd mtd .name = raspi, .size = 0x00400000 (4M) .erasesize = 0x0001000 ...

最新文章

  1. 最小圆覆盖(Smallest Enclosing Discs)
  2. Webpack单元测试,e2e测试
  3. ASP.net 1.1 中相对路径转换为绝对路径
  4. Android通过使用系统广播监听网络状态的改变
  5. 【转】国密算法sm4 CBC模式加解密
  6. Spring IOC扫描器与注册器
  7. 服务器asp.net权限设置问题及解决方法时间:
  8. 叮咚!7.24运维节,您有一份礼物待查收!
  9. Mysql锁定表/解锁句法
  10. 我眼中的“SSD” ..update
  11. tomcat自动启动 linux,Linux设置tomcat开机自启动
  12. LNMPS PHP 团队开发 需要用到的相关工具(2017年11月更新)
  13. 误删微软应用商店怎么装回来
  14. 软件开发流程都是什么样的呢?
  15. git 找到冲突_git怎么知道哪个文件冲突
  16. 苹果应用审核指南最新
  17. Android ButterKnife(黄油刀)的使用
  18. 华为 DAYU 整体介绍
  19. 特殊数字符号整理 - 圆圈数字
  20. 入侵检测系统原理和实践

热门文章

  1. 概率统计:数学期望、方差、协方差、相关系数、矩
  2. 认识DPDK的UIO驱动(一)
  3. python股票指标计算库_GitHub - unclevicky/stock: stock,股票系统。使用python进行开发。...
  4. 苏州大学文正学院计算机多少分,苏州大学文正学院录取分数线2021是多少分(附历年录取分数线)...
  5. 大连理工大学远程与继续教育学院生产实习报告报表
  6. 豪华嘉宾阵容曝光!6月底V神来的那个大会,还有优惠票吗?
  7. (CNS复现)CLAM——Chapter_02
  8. ceonts6.8 nginx做前端代理apache做后端服务架构配置
  9. 【树莓派分享——Raspberry Pi 官方系统安装及VNC查看器显示】
  10. 06-B. DS队列之银行排队