Difference between revisions of "Repartitioning NAND Flash with JFFS2 for Linux"
(created) |
(added cmdline partition table description) |
||
Line 1: | Line 1: | ||
Many of EMAC's ARM processor-based systems utilize NAND flash with JFFS2 filesystems. On these systems, the NAND flash is partitioned using the Linux MTD "Command line partition table parsing" feature. This allows the partition table for the flash to be specified on the kernel command line passed from the bootloader. By default, EMAC OE NAND flash images provide one partition for the root filesystem mounted read-only, and a second read/write auxiliary partition mounted on <code>/root</code>. This article describes how to modify the partition table and how to utilize and configure additional partitions. | Many of EMAC's ARM processor-based systems utilize NAND flash with JFFS2 filesystems. On these systems, the NAND flash is partitioned using the Linux MTD "Command line partition table parsing" feature. This allows the partition table for the flash to be specified on the kernel command line passed from the bootloader. By default, EMAC OE NAND flash images provide one partition for the root filesystem mounted read-only, and a second read/write auxiliary partition mounted on <code>/root</code>. This article describes how to modify the partition table and how to utilize and configure additional partitions. | ||
+ | |||
+ | == Command Line Partition Table == | ||
+ | EMAC OE NAND flash-based systems utilize MTD command line partition table parsing to specify the partition table for the flash. This is different from what you may be used to with other disks where the partition table is stored in the MBR. When the system is booted, the kernel looks at the partition table specified and creates device nodes corresponding to each partition at the given size or offset. These can be accessed like any other partition, but no information about the actual partition table is stored on the disk itself. | ||
+ | |||
+ | A brief description of the format and options for the partition table command line taken from the <code>drivers/mtd/Kconfig</code> is listed below: | ||
+ | <pre>The format for the command line is as follows: | ||
+ | |||
+ | mtdparts=<mtddef>[;<mtddef] | ||
+ | <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 | ||
+ | names. | ||
+ | </pre> | ||
+ | |||
+ | Although the kernel command line is specified in the bootloader (the <code>bootargs</code> variable in U-Boot), the command line can be viewed through the <code>/proc/cmdline</code> file on a running Linux system. The example below illustrates the command line on a system. Note that the settings on your system will most likely differ from the configuration here depending on the required size for the root filesystem, processor type, and other variables. | ||
+ | root@emac-oe:~# cat /proc/cmdline | ||
+ | console=ttyS0,115200 root=/dev/mtdblock0 mtdparts=atmel_nand:128M(root),-(aux) ro rootfstype=jffs2 video=AMPIRE | ||
+ | |||
+ | In the example above, the <code>mtdparts</code> parameter specifies the partition table for one device: <code>atmel_nand</code>. This device name will vary depending on the type of processor on the board and the flash driver name. The first partition is 128MB and is named "root". Following that is a partition named "aux" which takes up the remaining space on the flash. | ||
+ | |||
+ | One method for viewing which device nodes correspond to each of these partitions is to view the <code>/proc/mtd</code> file. The partition names specified in the command line are reflected in the <code>/proc/mtd</code> contents as shown below. In this example, you can see that <code>mtd0</code> corresponds to "root", and <code>mtd1</code> corresponds to "aux". The remaining devices on this system are on the SPI DataFlash device, which uses a hard-coded partition table. | ||
+ | root@emac-oe:~# cat /proc/mtd | ||
+ | dev: size erasesize name | ||
+ | mtd0: 08000000 00020000 "root" | ||
+ | mtd1: 08000000 00020000 "aux" | ||
+ | mtd2: 00042000 00000210 "df_boot" | ||
+ | mtd3: 00210000 00000210 "df_kernel" | ||
+ | mtd4: 001ce000 00000210 "df_aux" | ||
+ | |||
+ | {{mbox | type = notice | text = Note that JFFS2 filesystems utilize the MTD block device corresponding to the MTD device. For example, the <code>/dev/mtdblock0</code> node provides a block device interface to <code>/dev/mtd0</code>.}} | ||
+ | |||
+ | The <code>/etc/fstab</code> file specifies how the NAND flash partitions should be mounted. For example, the system used for this example contains the following entries for the NAND flash partitions: | ||
+ | /dev/mtdblock0 / jffs2 ro 0 0 | ||
+ | /dev/mtdblock1 /root jffs2 rw 0 0 | ||
+ | This configures the system to mount the root filesystem read-only, and to mount the "aux" partition read/write on <code>/root</code>. | ||
+ | |||
+ | [[Category:Linux]] | ||
+ | [[Category:Filesystems]] |
Revision as of 07:40, 12 April 2013
Many of EMAC's ARM processor-based systems utilize NAND flash with JFFS2 filesystems. On these systems, the NAND flash is partitioned using the Linux MTD "Command line partition table parsing" feature. This allows the partition table for the flash to be specified on the kernel command line passed from the bootloader. By default, EMAC OE NAND flash images provide one partition for the root filesystem mounted read-only, and a second read/write auxiliary partition mounted on /root
. This article describes how to modify the partition table and how to utilize and configure additional partitions.
Command Line Partition Table
EMAC OE NAND flash-based systems utilize MTD command line partition table parsing to specify the partition table for the flash. This is different from what you may be used to with other disks where the partition table is stored in the MBR. When the system is booted, the kernel looks at the partition table specified and creates device nodes corresponding to each partition at the given size or offset. These can be accessed like any other partition, but no information about the actual partition table is stored on the disk itself.
A brief description of the format and options for the partition table command line taken from the drivers/mtd/Kconfig
is listed below:
The format for the command line is as follows: mtdparts=<mtddef>[;<mtddef] <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 names.
Although the kernel command line is specified in the bootloader (the bootargs
variable in U-Boot), the command line can be viewed through the /proc/cmdline
file on a running Linux system. The example below illustrates the command line on a system. Note that the settings on your system will most likely differ from the configuration here depending on the required size for the root filesystem, processor type, and other variables.
root@emac-oe:~# cat /proc/cmdline console=ttyS0,115200 root=/dev/mtdblock0 mtdparts=atmel_nand:128M(root),-(aux) ro rootfstype=jffs2 video=AMPIRE
In the example above, the mtdparts
parameter specifies the partition table for one device: atmel_nand
. This device name will vary depending on the type of processor on the board and the flash driver name. The first partition is 128MB and is named "root". Following that is a partition named "aux" which takes up the remaining space on the flash.
One method for viewing which device nodes correspond to each of these partitions is to view the /proc/mtd
file. The partition names specified in the command line are reflected in the /proc/mtd
contents as shown below. In this example, you can see that mtd0
corresponds to "root", and mtd1
corresponds to "aux". The remaining devices on this system are on the SPI DataFlash device, which uses a hard-coded partition table.
root@emac-oe:~# cat /proc/mtd dev: size erasesize name mtd0: 08000000 00020000 "root" mtd1: 08000000 00020000 "aux" mtd2: 00042000 00000210 "df_boot" mtd3: 00210000 00000210 "df_kernel" mtd4: 001ce000 00000210 "df_aux"
Note that JFFS2 filesystems utilize the MTD block device corresponding to the MTD device. For example, the /dev/mtdblock0 node provides a block device interface to /dev/mtd0 . |
The /etc/fstab
file specifies how the NAND flash partitions should be mounted. For example, the system used for this example contains the following entries for the NAND flash partitions:
/dev/mtdblock0 / jffs2 ro 0 0 /dev/mtdblock1 /root jffs2 rw 0 0
This configures the system to mount the root filesystem read-only, and to mount the "aux" partition read/write on /root
.