How to Partition MTD on the Kernel Command Line


The Memory Technology Device (MTD) interface is a way of abstracting flash devices as if they were normal block devices. With the densities of these flash chips increasing, the need for partitioning is becoming more apparent. Unlike typical block devices, however, these flash devices generally lack a partition table. Instead, they rely on the underlying operating system to enforce these partitions. For some devices, you can specify the partition table in the kernel, typically in the board-specific file. However, not all types of MTD support this (DataFlash is one such example), and you may require more flexibility in your partitioning. This is where command line partitioning comes in.

Command Line MTD Partitioning uses values passed via the kernel command line to specify the partitioning scheme of a give flash device.




  1. Determine the MTD ID of the device that you wish to partition. This can be done by running cat /proc/mtd on your target platform.
  2. Determine the partition table of your device.
  3. Pass the given command line to your kernel at boot-time using your bootloader.

Finding the MTD ID

The simplest way to find the MTD ID is to boot the board and run cat /proc/mtd from you shell. This works great for unpartitioned devices, but will not work if the device has already been partitioned in the kernel. In the latter case, you will probably need to dig through the driver code to find what you are looking for.

For example, the following text is the output of the cat /proc/mtd command on an AT91SAM9261 board. mtd0 and mtd1 are the names of two partitions on the same NAND chip. These names are defined by the mtd_partition struct in the board-specific code in the kernel. The two spi partitions are the two DataFlash chips on the board, and these names can be used directly on the kernel command line.

dev:    size   erasesize  name
mtd0: 04000000 00020000 "Partition 1" 
mtd1: 0c000000 00020000 "Partition 2" 
mtd2: 00420000 00000210 "spi0.0-AT45DB321x" 
mtd3: 00840000 00000420 "spi0.3-AT45DB642x" 

When looking through the driver, you are interested in the value of the name field of the mtd_info struct.

MTD IDs for common devices

Board Device Driver mtd-id
AT91SAM9/CAP9 (Kernels 2.6.27 and Newer) NAND Flash drivers/mtd/atmel_nand.c atmel_nand
AT91SAM9/CAP9 (Kernels 2.6.26 and Older) NAND Flash drivers/mtd/at91_nand.c at91_nand
AT91SAM9261 DataFlash Chip drivers/mtd/devices/mtd_dataflash.c spi0.0-AT45DB321x 1
DataFlash Card - spi0.3-AT45DB642x 1
AT91SAM9263 DataFlash Card drivers/mtd/devices/mtd_dataflash.c spi0.0-AT45DB642x 1

1 The format is determined by the location of the flash on the board. It takes the format: spi%d.%d-%s. The values correspond to the spi->master->bus_number, spi->chip_select, and name is the part number of the dataflash chip, e.g. AT45DB642x for 8MB cards.

Creating the Partition Table

The command line argument takes the following format:

<mtddef> := <mtd-id>:<partdef>[,<partdef>]
<partdef> := <size>[@offset][<name>][ro]
<mtd-id> := unique id used in mapping driver/device
<size> := standard linux memsize OR "-" to denote allremaining space
<name> := (NAME)

mtd-id is the name determined in the previous step, and partdef is an individual partition definition. The command line can take multiple mtddef sections separated by semi-colons (;), and each mtddef can define multiple partdef sections separated by commas (,). Each partition may be given a size, optional offset, optional name, and optional read-only flag. Note that offset is only necessary if you do not have contiguous partitions, i.e. no unallocated space between partition definitions.

Typically, you want to select values for the partition size that are multiples of the erase block size. This information is usually found in the data sheet, or can be found by running cat /proc/mtd on the command line.


Partitioning DataFlash

The following example partitions the DataFlash chip on the AT91SAM9263-EK board into four partitions.

Name Size Offset RO
AT91Bootstrap 0x4200 0x0000 No
U-Boot_Env 0x4200 0x4200 No
U-Boot 0x42000 0x8400 No
Kernel - (Rest of Chip) 0x42000 No

Partitioning NAND Flash

The following example partitions the NandFlash chip on the AT91SAM9263-EK board into six partitions.

Name Size Offset RO
AT91Bootstrap 0x20000 0x000000 No
U-Boot 0x40000 0x020000 No
U-Boot_Env 0x20000 0x060000 No
U-Boot_Env_Red 0x20000 0x080000 No
Kernel 0x260000 0x0a0000 No
RFS - (Rest of Chip) 0x300000 No

Additional Resources


Allow generic configuration of the MTD partition tables via the kernel
command line. Multiple flash resources are supported for hardware where
different kinds of flash memory are available.

You will still need the parsing functions to be called by the driver
for your particular device. It won't happen automatically. The
SA1100 map driver (CONFIG_MTD_SA1100) has an option for this, for

The format for the command line is as follows:

<mtddef> := <mtd-id>:<partdef>[,<partdef>]
<partdef> := <size>[@offset][<name>][ro]
<mtd-id> := unique id used in mapping driver/device
<size> := standard linux memsize OR "-" to denote all
remaining space
<name> := (NAME)

Due to the way Linux handles the command line, no spaces are
allowed in the partition definition, including mtd id's and partition


1 flash resource (mtd-id "sa1100"), with 1 single writable partition:

Same flash, but 2 named partitions, the first one being read-only:

If unsure, say 'N'.