Repartitioning NAND Flash with JFFS2 for Linux
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
.
The usage statistics for each filesystem can be viewed through the df
command as listed below. This information can be helpful in determining the size requirements for the root partition.
root@emac-oe:~# df -h Filesystem Size Used Available Use% Mounted on /dev/root 128.0M 90.8M 37.2M 71% / udev 61.5M 76.0K 61.4M 0% /dev media 2.0M 0 2.0M 0% /media /dev/mmcblk0p1 1.8G 2.3M 1.8G 0% /media/mmcblk0p1 /dev/mtdblock1 128.0M 3.0M 125.0M 2% /root tmpfs 61.5M 88.0K 61.4M 0% /var/volatile tmpfs 61.5M 0 61.5M 0% /dev/shm
Note that the root filesystem node is reported as /dev/root rather than /dev/mtdblock0 . This is a symbolic name that is used to enable generic scripting across many different systems where the different physical device nodes may differ. |
Changing the Mount Point of the Auxiliary Partition
If existing partition scheme is acceptable for your application but you want to use the auxiliary partition for data logging rather than general storage and development, the easiest solution is to simply change the mount point of the second partition.