[Soekris] Re: jffs2 on CF with linux kernel

Paul Komarek komarek at andrew.cmu.edu
Mon May 13 07:39:46 UTC 2002

> Message: 2
> Subject: Re: [Soekris] IDE errors on the compactflash
> From: John Laur <johnl at blurbco.com>
> To: soekris-tech at lists.soekris.com
> Date: 07 May 2002 18:32:28 -0500
> You did not specify whether you were using flash memory or a Microdrive.
> If you are using compact flash, then ext3 is a BAD IDEA. Ext3 expects to
> be able to update its journal QUICKLY and OFTEN. It could very easily
> starve on irq's when waiting for the flash chips to erase (especially as
> the "drive" fills up). Use ext2 if you want a "standard" filesystem on
> your CF. Reiserfs would be a better choice than ext3 for flash, but as
> you say, jffs2 is really going to be your best bet. It is an awesome FS,
> but keep in mind actually getting your machine to work with a jffs2
> configuration will be very difficult for you if you aren't highly versed
> in embedded linux. It's not as simple as just reformatting your
> partition as jffs2 and changing your fstab entry :)
> If anyone has taken the time to get a working linux/jffs2 distribution
> on the net4501, I'm sure there are more than a few people that would be
> interested. I was going to attempt it, but instead settled for a
> network-booting nfs-root setup which ended up being much much easier to
> manage.
> John

I guess it's clear that everything we're talking about is for a
linux-based os.


I have used jffs2 on a cf card via the blkmtd module (mtd emulation using
a block device) as a root filesystem.  The read and write speeds were fast
enough (for our application).  You incur a bit more cpu overhead than
normal.  The only bad side-effect was boot time -- when blkmtd is inserted
at boot for a 64MB jffs2-emulating cf card, there is a 5-10 minute pause.
I don't know why, and haven't bothered looking into it.  I'm hoping that
by sharing my strategy, someone else will tell me the "right" way to fix
this (or tell me that this is a stupid thing to do!).

If you didn't want the jffs2 partition as the root filesystem, you only
need to load the drivers mentioned below (and make the initial jffs2 image
with mkfs.jffs2).

Details for root fs using jffs2 on a CF card:

We wanted to change as few files from a custom install based on Red
Hat 7.1, which meant messing with initial ramdisks.  In a "normal"
situation, you'd want to compile stuff into the kernel:

kernel stuff needed (xconfig section, name, symbol, module name)

1) MTD
   mtd support
2) MTD
   caching block device access to MTD devices
3) MTD/Self-contained MTD device drivers
   emulation using block device
4) File systems
   Journalling Flash File System v2 (JFFS2) support

Steps we use (you can do other stuff, of course):

On a host computer with a CF card reader:

1) partition CF card as desired.  Note *exact* size of partition which
will hold the jffs2 filesystem.  This should be a multiple of the cylinder
size for the CF card.  Call this SIZE.  If you screw this up, you can get
really weird results with strange jffs2 errors (at least if you make it
too big).

2) make your initial jffs2 filesystem image with mkfs.jffs2 (available
precompiled for some platforms from the jffs2 web page, and source is in
their cvs archive).  Pad the image to SIZE (using --pad).

3) write jffs2 image onto partition using dd.

4) fix initial ramdisk image to included needed device nodes and modules:
   *) run mkinitrd, including these options among others
      "--preload mtdcore --preload mtdblock --preload blkmtd"
      If you are compiling a kernel from scratch, don't build these mtd
      items as modules; build them into the kernel instead, and you won't
      need an initial ramdisk.
   *) make device nodes on ramdisk image:
      i)   mv ramdisk.image ramdisk.image.gz
      ii)  gzip -d ramdisk.image.gz
      iii) mount -o loop ramdisk.image /mnt/floppy
      iv)  create nodes for accessing CF card, such as hda or hdc
      v)   create nodes for mtd stuff:
           for minor in `seq 0 7`; do
             mknod "$initrdmnt/$devname" b 31 "$minor"
             ln -s "$devname" "$initrdmnt/dev/mtdblock${minor}"
      vi)  umount /mnt/floppy
      vii) gzip ramdisk.image
      viii) mv ramdisk.image.gz ramdisk.image

5) Set up your fstab with /dev/mtdblockX as the device holding the Xth
mounted jffs2 partition (X starts at 0, of course).

6) Set up modules.conf to associate the CF card device (e.g. /dev/hda)
with the blkmtd driver.  I add the following, since my root filesystem is
the second partition on the CF card.

  options blkmtd device=/dev/hda2 erasesz=64
  below mtdblock mtdcore
  below blkmtd mtdblock
  below jffs2 blkmtd

7) I should have said this before -- LILO and GRUB don't like jffs2 yet
(as far as I knew when I was doing this a few months ago), so you have to
have a "nice" partition around for the bootloader's second stage files and
kernel (i.e. /boot).  Thus my fstab contains

  /dev/mtdblock0    /               jffs2  defaults,rw,noatime,sync 0 0
  /dev/hda1         /boot           ext2   defaults,rw,sync,noatime 1 1

8) Set up your boot loader in the "usual" way, with mtdblockX as the root
device and your modified initial ramdisk "ramdisk.image" (if you are using
modules).  Re-read point 7) about bootloaders needing "nice" filesystems
like ext2, and place anything the bootloader needs there (including
kernel, config file(s), second stage stuff, whatever).

I think that covers what we did for a root fs formatted as jffs2 on a cf
card.  Booting takes forever, but performance otherwise is satisfactory on
the Soekris 4501.

I would love to get feedback on this approach.  Since I read this
list sporadically, please cc me in any emails (komarek at cmu.edu).

-Paul Komarek

More information about the Soekris-tech mailing list