通过/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);
}

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

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

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

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

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

  3. linux查询内核参数命令,Linux内核启动参数详解

    1.环境: Ubuntu 16.04 Linux linuxidc 4.4.0-89-generic #112-Ubuntu SMP Mon Jul 31 19:38:41 UTC 2017 x86_ ...

  4. linux系统内核参数命令,Linux内核启动参数解析及添加

    1.环境: Linux linuxidc 4.4.0-89-generic #112-Ubuntu SMP Mon Jul 31 19:38:41 UTC 2017 x86_64 x86_64 x86 ...

  5. python中forward的参数_ip_forward参数对Linux内核转发影响分析

    在进行Linux内核转发时,需要在proc文件系统的proc/sys目录设置转发的参数,可以使用下面的方法查看该参数的值 cat /proc/sys/net/ipv4/ip_forward,该参数的默 ...

  6. ip_forward参数对Linux内核转发影响分析

    在进行Linux内核转发时,需要在proc文件系统的proc/sys目录设置转发的参数,可以使用下面的方法查看该参数的值 cat /proc/sys/net/ipv4/ip_forward,该参数的默 ...

  7. linux内核参数分析,linux内核启动第一阶段分析

    linux内核启动第一阶段分析 http://blog.csdn.net/aaronychen/article/details/2838341 本文的很多内容是参考了网上某位大侠的文章写的<&l ...

  8. 开机时设置linux 内核参数 mem,Linux内核开机保留大块内存的方法总结

    在网上搜了很久,才慢慢了解在开机保留内存的方法,现在总结一下这阶段的学习过程!(我是在ARM板子上进行的实验,内核版本是2.6.38) 在开机保留内存的方式一共有三种方法: 1. reserve_bo ...

  9. linux ipv4参数查看,Linux内核参数之IPV4变量引用

    变量路径在/proc/sys/net/ipv4/目录下面,关于ipv4的内核参数如下: ip_autoconfig 参数:0或1 1表示通过RARP,BOOTP,DHCP或者其它协议获取主机的IP地址 ...

最新文章

  1. 服务治理治什么,10张图告诉你答案
  2. 360导航源码php,114啦网址导航源码仿360网址导航最新版
  3. css3-11 如何实现2D动画
  4. 读锁调度导致高延迟的 case 一例
  5. 如何将拷贝过来的数据 *.ibd 文件生效
  6. 电路板上的插头怎么拔下来_空调插头一直不拔费电吗?实测一周竟然发现了真相!...
  7. vim关闭下一行也是注释_在Vim中注释/取消注释行的快速方法是什么?
  8. 作者:靳小龙,中国科学院计算技术研究所副研究员,博士生导师。
  9. 电子表格控件Aspose.Cells V17.4.0发布 | 新增重要功能
  10. 寻找二叉树最小叶子节点值
  11. 大多数微型计算机都是基于,基于PCI总线数据采集系统的设计
  12. 虚拟机启动失败/检查打开虚拟化-解决方案小结
  13. ubuntu 16.04 64位 搭建GenieACS
  14. SL会员商城系统后台管理模板
  15. 遇到from playsound import playsoundModuleNotFoundError: No module named ‘playsound‘解决办法
  16. 什么是项目沟通管理?
  17. 微信开放平台开发第三方授权登陆(一):开发前期准备
  18. 微信小程序 一键下载所有图片和视频
  19. 物流设施布局方法——CRAFT
  20. 基于机器视觉的机器人智能制造实践应用研究

热门文章

  1. 计算机专业大专学校排名河南的,2020河南大专学校排名榜单
  2. Android 列表视图制作古诗词
  3. 当微信小程序遇上filter~
  4. 信息孤岛的由来,以及如何改善
  5. 京东数科一面实习面经
  6. 2021年中国氨纶行业发展现状及进出口状况分析:氨纶价格创十年新高 [图]
  7. Worthington核酸酶、微球菌相关研究及测定方案
  8. 软 RAID 和硬 RAID的比较概览
  9. 浅谈sPLS和sgPLS
  10. 关于texlive2021安装,一直卡在安装界面怎么回事?