mtd

最後更新: 2022-07-29

介紹

MTD = Memory Technology Device

 * Please, do not be confused by USB stick, MMC, SD.
(IO -> FTL(Flash Translation Layers) -> eraseblock)

In Linux, FTL = mtdblock (emulates block devices over MTD devices)

MTD devices represent flash devices and they consist of eraseblocks of rather large size (typically about 128KiB)

The whole eraseblock has to be erased before it becomes possible to re-write its contents.
(block devices don't distinguish between write and erase operations.)

Eraseblocks become worn out after some number of erase cycles(wear-out property)

mtd 是一個類似 dd 的工具來, 它用於續/刪 MTD

 


Usage

 

Syntax

mtd  [option] <command> <device / label>

command:

  • erase <dev>                                          # erase all data on device 
  • write <imagefile>|-                                # write <imagefile> (use - for stdin) to device 
  • verify <imagefile>|-                                # verify <imagefile> (use - for stdin) to device

option:

-r => reboot after successful command

查看 flash 的分區情況:

cat /proc/mtd

dev:    size   erasesize  name
mtd0: 00020000 00010000 "u-boot" <-- boot loader
mtd1: 000e5e00 00010000 "kernel" <-- firmware
mtd2: 002ea200 00010000 "rootfs" <-- firmware
mtd3: 00170000 00010000 "rootfs_data"
mtd4: 00010000 00010000 "art"
mtd5: 003d0000 00010000 "firmware"

裝置檔:

/dev/mtdX

Backup方式:

dd if=/dev/mtd0 of=/tmp/u-book.bak

erase:

mtd -r erase rootfs_data

還原 firmware:

mtd -r write /tmp/original_firmware.bin firmware

 


ROM Size

 

dmesg

... m25p80 spi0.0: found s25fl064k, expected m25p80
... m25p80 spi0.0: s25fl064k (8192 Kbytes)
... 5 tp-link partitions found on MTD device spi0.0
... Creating 5 MTD partitions on "spi0.0":
... 0x000000000000-0x000000020000 : "u-boot"
... 0x000000020000-0x0000001725f8 : "kernel"
... 0x0000001725f8-0x0000007f0000 : "rootfs"
... mtd: device 2 (rootfs) set to be root filesystem
... 1 squashfs-split partitions found on MTD device rootfs
... 0x0000003c0000-0x0000007f0000 : "rootfs_data"
... 0x0000007f0000-0x000000800000 : "art"
... 0x000000020000-0x0000007f0000 : "firmware"

rootfs

它包含了 rootfs_data, art, firmware

s25fl064k

64-Mbit CMOS 3.0 Volt Flash Memory with 80-MHz SPI (Serial Peripheral Interface)
 

m25p80

Micron M25P80 Serial Flash Embedded Memory (8Mb, 3V)

Sector erase: 512Kb

Voltage: 2.7V to 3.6

Maximum clock frequency: 75 MHz

Hardware write protection