Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

/sys/class/mtd

FieldValue
SubsystemMTD core, drivers/mtd/mtdcore.c (class mtd_class, devices mtd%d)
Config gateCONFIG_MTD, “Memory Technology Device (MTD) support” (drivers/mtd/Kconfig)
ABI documentationDocumentation/ABI/testing/sysfs-class-mtd (22 What: entries)
SinceClass and base attrs 2.6.29 (April 2009); ecc_strength and bitflip_threshold 3.4; ecc_step_size 3.10; ecc_failures, corrected_bits, bad_blocks, bbt_blocks 3.17; offset 4.1; oobavail 4.16 (all from the ABI file)
Live (5.10.134 host)none observed (no flash device in the container)
Ledger IDSYSC-mtd

What it represents

One directory per MTD device or partition, corresponding to each /dev/mtdX character device, plus a read-only twin directory mtdXro for the read-only device node (minor odd; the read-write node has an even minor). Entries may be physical or simulated flash, partitions, or concatenated devices.

Relationship to the device model

The class device is registered by mtdcore.c with dev_set_name “mtd%d”. The name attribute matches the entry in /proc/mtd, the historical procfs twin, so the two views can be reconciled. IOCTLS on the char device (MEMGETREGIONCOUNT, MEMGETREGIONINFO) complement the sysfs geometry attributes.

Attributes (representative; source: ABI testing/sysfs-class-mtd)

AttributeR/WMeaning
typeROabsent, ram, rom, nor, nand, mlc-nand, dataflash, ubi, unknown
flagsROHex flags: 0x0400 MTD_WRITEABLE, 0x0800 MTD_BIT_WRITEABLE, 0x1000 MTD_NO_ERASE, 0x2000 MTD_POWERUP_LOCK
sizeROTotal size of device or partition in bytes
erasesizeROMajor erase size; when numeraseregions is 0 this is the whole-device eraseblock size
writesizeROMinimal writable unit: 1 for NOR, a page (or fraction) for NAND
oobsize, oobavailROOOB bytes per page; bytes a client may use
numeraseregionsRONumber of variable erase regions, 0 if uniform
nameROASCII name matching /proc/mtd
devRO<major>:<minor> of the char device
ecc_strength, ecc_step_sizeROCorrectable bit errors per ECC step; step size in bytes (0 without ECC)
bitflip_threshold0644Threshold for returning -EUCLEAN from reads; default ecc_strength; users are discouraged from changing it
ecc_failures, corrected_bitsROECC failure and correction counters
bad_blocks, bbt_blocksROMarked-bad and reserved (BBT) block counts in this partition
offsetROPartition offset from parent start; absent on full devices, so it distinguishes partitions

Safety and writes

The only write path is bitflip_threshold, which changes how reads report degradation; the ABI text warns against adjusting it without intimate device knowledge. Erasing and writing happen through the char device, not sysfs. None observed on the container host.

References