/proc/mtd the meaning of each parameter--the Linux kernel

Source: Internet
Author: User
Tags sprintf raspi

Read the MTD partition table via the/PROC virtual file system: 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"

through this structure ,sizeIt's this MTD .maximum number of bytes space for a partition,erasesizeis this partition'sMinimum Erase bytes space (block size, Linux flash is in blocks for erase units).

Here are the others ' articles:

This is implemented in detail by the Mtd_read_proc function in the mtdcore.c file under LINUX/DRIVERS/MTD:

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);
}

the results are read as follows:
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"

The definitions of size and erasesize are defined in the struct MTD_INFO structure in the Mtd.h file under LINUX/INCLUDE/LINUX/MTD:
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 is 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 the ECC block size, etc. It's illegal to has 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 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 and 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 could need to maintain
* Its own reference counting. The below functions is only for driver.
* The driver may register its callbacks. These callbacks is not
* Supposed to being called by MTD users */
Int (*get_device) (struct mtd_info *mtd);
void (*put_device) (struct mtd_info *mtd);
}

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

/proc/mtd the meaning of each parameter--the Linux kernel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.