All currently available flash filesystems are based on the Memory
Technology Devices
MTD layer, so you must enable (at least) the
following configuration options to get flash filesystem support in
your system:
CONFIG_MTD=y
CONFIG_MTD_PARTITIONS=y
CONFIG_MTD_CHAR=y
CONFIG_MTD_BLOCK=y
CONFIG_MTD_CFI=y
CONFIG_MTD_GEN_PROBE=y
CONFIG_MTD_CFI_AMDSTD=y
CONFIG_MTD_ROM=y
CONFIG_MTD_canyonlands=y

Note: this configuration uses
CFI conformant AMD flash chips;
you may need to adjust these settings on other boards.
The partition layout of the flash devices is contained in the flat
device tree for the system (see
13.1. Flat Device Tree).
Informational messages of the
MTD
subsystem can be found in the
Linux bootlog, i.e. see section
7.5.1. Bootlog of tftp'd Linux kernel with Root Filesystem over NFS.
One can discover this information in a running system
using the
proc
filesystem:
-bash-3.2# cat /proc/mtd
dev: size erasesize name
mtd0: 001e0000 00020000 "kernel"
mtd1: 00020000 00020000 "dtb"
mtd2: 01400000 00020000 "ramdisk"
mtd3: 00400000 00020000 "jffs2"
mtd4: 02560000 00020000 "user"
mtd5: 00040000 00020000 "env"
mtd6: 00060000 00020000 "u-boot"
mtd7: 00100000 00020000 "u-boot"
mtd8: 03f00000 00020000 "user"
-bash-3.2#
Now we can run some basic tests to verify that the flash driver
routines and the partitioning works as expected:
-bash-3.2# xxd /dev/mtd3 | head -4
0000000: ffff ffff ffff ffff ffff ffff ffff ffff ................
0000010: ffff ffff ffff ffff ffff ffff ffff ffff ................
0000020: ffff ffff ffff ffff ffff ffff ffff ffff ................
0000030: ffff ffff ffff ffff ffff ffff ffff ffff ................
-bash-3.2#
In the hex-dumps of the
MTD devices you can identify some strings
that verify that we indeed see an U-Boot environment,
a Linux kernel, a ramdisk image and an empty partition to play wih.
The last output shows the partition to be empty. We can try
write some data into it:
-bash-3.2# date > /tmp/tempfile
-bash-3.2# dd if=/dev/zero of=/tmp/tempfile bs=1 count=4096 seek=50
4096+0 records in
4096+0 records out
4096 bytes (4.1 kB) copied, 0.0107987 s, 379 kB/s
-bash-3.2# dd if=/tmp/tempfile of=/dev/mtd3 bs=4096 count=1
1+0 records in
1+0 records out
4096 bytes (4.1 kB) copied, 0.0179843 s, 228 kB/s
-bash-3.2# head -1 /dev/mtd3
Mon Feb 8 16:36:04 CET 2010
-bash-3.2# dd if=/tmp/tempfile of=/dev/mtd3 bs=4096 count=1
1+0 records in
1+0 records out
4096 bytes (4.1 kB) copied, 0.0179315 s, 228 kB/s
-bash-3.2#
As you can see it worked the first time. When we tried to write
the (new date) again, we got an error.
The reason is that the date has changed (probably at least the
seconds) and flash memory cannot be simply overwritten - it has to be
erased first.
You can use the
eraseall
Linux commands to erase a whole
MTD
partition:
-bash-3.2# flash_eraseall /dev/mtd3
Erasing 128 Kibyte @ 0 -- 0 % complete.Erasing 128 Kibyte @ 20000 -- 3 % complete.Erasing 128 Kibyte @ 40000 -- 6 % complete.Erasing 128 Kibyte @ 60000 -- 9 % complete.Erasing 128 Kibyte @ 80000 -- 12 % complete.Erasing 128 Kibyte @ a0000 -- 15 % complete.Erasing 128 Kibyte @ c0000 -- 18 % complete.Erasing 128 Kibyte @ e0000 -- 21 % complete.Erasing 128 Kibyte @ 100000 -- 25 % complete.Erasing 128 Kibyte @ 120000 -- 28 % complete.Erasing 128 Kibyte @ 140000 -- 31 % complete.Erasing 128 Kibyte @ 160000 -- 34 % complete.Erasing 128 Kibyte @ 180000 -- 37 % complete.Erasing 128 Kibyte @ 1a0000 -- 40 % complete.Erasing 128 Kibyte @ 1c0000 -- 43 % complete.Erasing 128 Kibyte @ 1e0000 -- 46 % complete.Erasing 128 Kibyte @ 200000 -- 50 % complete.Erasing 128 Kibyte @ 220000 -- 53 % complete.Erasing 128 Kibyte @ 240000 -- 56 % complete.Erasing 128 Kibyte @ 260000 -- 59 % complete.Erasing 128 Kibyte @ 280000 -- 62 % complete.Erasing 128 Kibyte @ 2a0000 -- 65 % complete.Erasing 128 Kibyte @ 2c0000 -- 68 % complete.Erasing 128 Kibyte @ 2e0000 -- 71 % complete.Erasing 128 Kibyte @ 300000 -- 75 % complete.Erasing 128 Kibyte @ 320000 -- 78 % complete.Erasing 128 Kibyte @ 340000 -- 81 % complete.Erasing 128 Kibyte @ 360000 -- 84 % complete.Erasing 128 Kibyte @ 380000 -- 87 % complete.Erasing 128 Kibyte @ 3a0000 -- 90 % complete.Erasing 128 Kibyte @ 3c0000 -- 93 % complete.Erasing 128 Kibyte @ 3e0000 -- 96 % complete.
-bash-3.2# date > /tmp/tempfile
-bash-3.2# dd if=/dev/zero of=/tmp/tempfile bs=1 count=4096 seek=50
4096+0 records in
4096+0 records out
4096 bytes (4.1 kB) copied, 0.01086 s, 377 kB/s
-bash-3.2# dd if=/tmp/tempfile of=/dev/mtd3 bs=4096 count=1
1+0 records in
1+0 records out
4096 bytes (4.1 kB) copied, 0.0180026 s, 228 kB/s
-bash-3.2# head -1 /dev/mtd3
Mon Feb 8 16:35:35 CET 2010
-bash-3.2#
We have now sufficient proof that the
MTD layer is working as
expected, so we can try creating a flash filesystem.