Notes on a JFFS2

Note

A whole partition should be erased before an jffs2 image is written to it. See https://e2e.ti.com/support/legacy_forums/embedded/linux/f/354/p/587759/2160573

Normally clean markers should be written after erasing. When we erase from a bootloader or a bare-metal flasher which doesn't have an ability to write clean markers we could just leave partition empty. In this case the kernel jffs2 driver will write markers for us. See http://www.linux-mtd.infradead.org/faq/jffs2.html

Note

A minimum erase block size that mkfs.jffs2 supports without patching is 8KiB. The sector erase size of SPI flash that is reported by MTD driver as an erase size is 4KiB.

See https://patchwork.ozlabs.org/patch/131822/ and this thread http://lists.infradead.org/pipermail/linux-mtd/2011-June/036498.html

Workaround for an 8K erase size limit

In the stock firmware the erase size of jffs2 that drives /etc partition is 4K and it seems to work.

On the device side

It can be achieved by first erasing the whole partition with the following call

flash_eraseall -j /dev/mtd6

and then by mounting an empty partition:

mount -t jffs2 /dev/mtdblock6 /etc

It makes a clean jffs2 with an erase block of 4K mounted over an /etc directory.

On the host side

In order to make an image file of jffs2 on the host machine one should patch the mkfs.jffs2 program. Clone the git repository of mtd user-space tools and make it

git clone git://git.infradead.org/mtd-utils.git
cd mtd-utils
./autogen.sh
./configure
make -j5

Then

vim jffsX-utils/mkfs.jffs2.c

and comment out the following lines

/* If it's less than 8KiB, they're not allowed */
if (erase_block_size < 0x2000) {
    fprintf(stderr, "Erase size 0x%x too small. Increasing to 8KiB minimum\n",
    erase_block_size);
    erase_block_size = 0x2000;
}

Creating a JFFS2 Partition Image

So that after patching a mkfs.jffs2 tool the command to make a jffs2 image is

../toolchain/mtd-utils/mkfs.jffs2 --little-endian --pagesize=0x1000 --eraseblock=0x1000 --pad --root=filesystem/etc --output=etc.jffs2