经/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. [效果不错] nginx 高并发参数配置及linux内核参数优化,完整的内核优化设置。PHP-FPM高负载解决办法。

    背景:对vps小资源的实践中对,https://justwinit.cn/post/7536/ 的再优化,再实践,再优化,特别是Nginx,PHP,内核: 零)Nginx: error_log /da ...

  2. linux 内核参数优化

    Sysctl命令及linux内核参数调整   一.Sysctl命令用来配置与显示在/proc/sys目录中的内核参数.如果想使参数长期保存,可以通过编辑/etc/sysctl.conf文件来实现.   ...

  3. Sysctl命令及linux内核参数调整

        一.Sysctl命令用来配置与显示在/proc/sys目录中的内核参数.如果想使参数长期保存,可以通过编辑/etc/sysctl.conf文件来实现.    命令格式:  sysctl [-n ...

  4. Linux 内核参数 优化

    Linux 内核参数 优化 目录 Linux 内核参数 优化 1.编辑内核配置文件 2.参数及简单说明 3.客户端的典型状态转移参数 4.TCP重传参数 5.实现Nginx高并发的内核参数优化 生效配 ...

  5. 安装ORACLE时在Linux上设置内核参数的含义

    前两天看到一篇Redhat官方的Oracle安装文档,对于Linux内核参数的修改描述的非常清晰. 安装Oracle之前,除了检查操作系统的硬件和软件是否满足安装需要之外,一个重点就是修改内核参数,其 ...

  6. 优化Linux内核参数/etc/sysctl.conf sysctl 《高性能Linux服务器构建实战:运维监控、性能调优与集群应用》

    优化Linux内核参数/etc/sysctl.conf  sysctl  <高性能Linux服务器构建实战:运维监控.性能调优与集群应用> http://book.51cto.com/ar ...

  7. Linux 内核参数 arp_ignore & arp_announce 详解

    arp_ignore定义了对目标地址为本机IP的ARP询问的不同应答模式. arp_announce对网络接口(网卡)上发出的ARP请求包中的源IP地址作出相应的限制:主机会根据这个参数值的不同选择使 ...

  8. 用于阻止缓冲区溢出攻击的 Linux 内核参数与 gcc 编译选项

    先来看看基于 Red Hat 与 Fedora 衍生版(例如 CentOS)系统用于阻止栈溢出攻击的内核参数,主要包含两项: kernel.exec-shield 可执行栈保护,字面含义比较“绕”, ...

  9. 修改Linux内核参数,减少TCP连接中的TIME-WAIT

    一台服务器CPU和内存资源额定有限的情况下,如何提高服务器的性能是作为系统运维的重要工作.要提高Linux系统下的负载能力,当网站发展起来之后,web连接数过多的问题就会日益明显.在节省成本的情况下, ...

随机推荐

  1. Android项目包装apk和apk反编译,xml反编译

    一.项目和一般原则其不足之处包 (1)开发一个简单的项目.当发布了APK档.假设我们不使用签名的方式,直接地bin文件夹中找到*.apk档.非常方便,但是,当我们在使用的用户,可能有其他方案覆盖安装. ...

  2. 部署Win Server 2012十项注意

    博文来自 http://server.zol.com.cn/351/3511746.html Windows Server 2012是微软公司在2012年推出的面向中小企业应用一款全新的服务器操作系统 ...

  3. linux 脚本測试网络速度

    example: ./netspeed eth0 1 #!/bin/bash 2   3 INTERVAL="1"  # update interval in seconds   ...

  4. 用PowerDesigner生成自定义建表语句

    原文:用PowerDesigner生成自定义建表语句 我们经常用PowerDesigner来进行数据库表结构的设计,并且设计出来的表比较直观的看出之间的相互关系,方便理解:但其自动生成的脚本并不一定符 ...

  5. MongoDB最新版本3.2.9下载地址

    https://downloads.mongodb.com/win32/mongodb-win32-x86_64-enterprise-windows-64-3.2.9.zip?_ga=1.22538 ...

  6. hdu1004----用java链表实现

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  7. 文件搜索神器everything 你不知道的技巧总结

    everything这个软件用了很久,总结了一些大家可能没注意到的技巧,分享给大家 1.指定文件目录搜索示例: TDDOWNLOAD\ abc        在所有TDDOWNLOAD文件夹下搜索包含 ...

  8. C#启动进程之Process

    在程序设计中,我们经常会遇到要从当前的程序跳到另一个程序的设计需求.也就是当前进程创建另一个进程.C#提供了Process使得我们很方便的实现. 1.Process基本属性和方法 Id //进程的Id ...

  9. 简介Customer Care Accelerator (CCA)

    几个月前,我们发表了CRM4.0的附属插件:Customer Care Accelerator (CCA). 年以来CCA已经存在,我们这些新手在CRM的世界里, Customer Care Fram ...

  10. 简单vector达到

    得知c++于,看完这本书后,,最近苦于不知道下一步该怎么做了,在寻找STL在各种容器的源代码分析,我想一次又一次地实现它. 之前,很多问题看的时候不知道是怎么回事,意与理解的.这个vector类写得特 ...