OpenWrt Forum Archive

Topic: Lean mean Raspberry Pi image: Now with JFFS2 + Hard Float support!

The content of this topic has been archived on 4 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi list!

As many RPI users knows, the tiny computer is not very happy with voltage variations, sudden shutdowns etc, leading to SD card filesystem corruption [1].

So, I was hoping for a fairly static (under a disk perspective) OpenWRT image for RPI. SquashFS + some overlay or something like that, in order to keep the SD card as quiet as possible, so it would make the RPI way more resilient.

However, I paid a visit to http://downloads.openwrt.org/barrier_br … 8/generic/ and I've found ext4 and  vfat + ext4 (yuck!) OpenWRT images for RPI.

This fairly static image would be a damn good idea for unstable environments, and also enhancing RPI's resilience.

Anyone dealt with it?

And a question, what is the 4-MB  penwrt-brcm2708-Image file at the repo?

Thanks a lot,

- RF.

[1] - http://bit.ly/1sR0OoL

---
EDIT:
Some other users are also interested on it. See:
https://forum.openwrt.org/viewtopic.php?id=44727
https://forum.openwrt.org/viewtopic.php?id=52034

(Last edited by man on 24 Aug 2014, 14:20)

You can always create a ram drive for stuff like /var/run and mount the / read-only. That works with Raspbian too.
I think I saw few forum posts out there explaining how to use a ram drive for that on the Pi.

Just my 2 cents.

Building a JFFS2 OpenWRT Raspberry Pi image with hard float support.


Issue

    The default Raspberry Pi OpenWRT image uses the ext4 filesystem.
    Raspberry Pi is known to corrupt the ext4 filesystem if rebooted abruplty or voltage conditions are not optimal.


Environment

    Raspberry Pi
    OpenWRT Barrier Breaker (14.07)
    Red Hat Enterprise Linux 6 for cross-compiling the artifacts.


Resolution

    Build a JFFS2 OpenWRT image. While JFFS2 is not suited for block devices, its filesystem design won't corrupt the entire filesystem in case of some data miswrite, but just the corrupted file (bad, bad ext4). It also supports native data compression.
    Step by step instructions:

Kernel build:

  1. Check out the openwrt image: git clone git://git.openwrt.org/openwrt.git --depth 1

  2. cd to the openwrt directory

  3. If you need/want extra packages (such as Luci, etc.), run the following commands: ./scripts/feeds update -a ; ./scripts/feeds install -a

  4. Run: make defconfig ; make prereq ; make menuconfig

  5. In "Target System" select "Broadcom BCM2708/BCM2835"

  6. Scroll down to "Target images". Check the box JFFS2. Do not touch ext4. If you remove it, it will remove the root partition size config option, yielding a failure when generating the JFFS2 image at the end of the build.

  7. Uncheck "GZip images"

  8. Change the "Root filesystem partition size (in MB)" for a suitable value or leave it untouched.

  9. Return to main menu. Scroll down and check "Advanced configuration options (for developers)"

  10. Check the box "Target Options". Enter this submenu.

  11. Change "Target Optimizations" to the following string: -O2 -pipe -march=armv6j -mfpu=vfp -mfloat-abi=hard

  12. Deselect the option "Use software floating point by default"

  13. Go back to the main menu. Enter "Kernel Modules".  Enter the "Block Devices" submenu.

  14. Set "kmod-block2mtd" to "builtin" type. Press spacebar untill an asterisk shows at the box.

  15. Return back to the root menu and select the packages that you want to install

  16. And then, build your kernel: make

Setting up the SD card:

  1. Become root

  2. Insert your SD card

  3. Umount the partitions that might be mounted automatically

  4. cd to build directory and cd to bin/brcm2708

  5. Write the image: dd if=openwrt-brcm2708-sdcard-vfat-jffs2-64k.img of=<device>  <device> is where your SD card is attached. i.e., /dev/mmcblk0, /dev/sdb, etc

  6. After the write, ensure to commit the data to the SD card, by running: sync

  7. Eject and reinsert the SD card

  8. At the vfat partition, edit the file cmdline.txt and replace its content with the following content:
    block2mtd.block2mtd=/dev/mmcblk0p2,65536,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait console=tty0 console=ttyS0,115200n8 noinitrd

And you're done!


Notes
  • Avoid defining a very large partition at the menuconfig step. The block2mtd will scan the whole partition at boot time, so define a size enough for your business.

  • JFFS2 is not a super-fast filesystem.

  • Double-check where is your SD card inserted when writing the image using the dd tool (Step H).

  • The Raspberry Pi will start as a DHCP server, with IP address 192.168.1.1. If you have defined LuCi at the make menuconfig, just point the browser to this address. Notice that LuCi is not installed by default and needs to be explicitly enabled in both steps 3 and 13.

  • If you didn't install LuCi, you can't ssh until you define a root password. Telnet to 192.168.1.1 and define a root password.

  • I strongly recommend the Apple USB ethernet adapter for the 2nd NIC. Rock stable, powered by RPI's own USB port. See eLinux.

  • It is not booting? Double-check steps 13 and 14.

  • If you want to write the 128k image, don't forget to change the erase block size at the step H (it's the 2nd value on block2mtd cmdline).

(Last edited by man on 27 Aug 2014, 01:47)

man wrote:

Setting up the SD card:

  • Become root

  • Insert your SD card

  • Umount the partitions that might be mounted automatically

  • cd to build directory and cd to bin/brcm2708

  • Write the image: dd if=openwrt-brcm2708-sdcard-vfat-jffs2-128k.img of=/dev/mmcblk0

  • After the write, ensure to commit the data to the SD card, by running: sync

  • Eject and reinsert the SD card

  • At the vfat partition, edit the file cmdline.txt and replace its content with the following content:
    block2mtd.block2mtd=/dev/mmcblk0p2,65536,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait console=tty0 console=ttyS0,115200n8 noinitrd

When an SD card is inserted into an SD slot, perhaps it is best to first check what device it is assigned to. It could be assigned to /dev/sdb1, /dev/mmcblk0, etc. It is assigned to /dev/mmcblk0, then it is OK. Otherwise, the inserted SD card never gets written with the image file.

mazilo wrote:

When an SD card is inserted into an SD slot, perhaps it is best to first check what device it is assigned to. It could be assigned to /dev/sdb1, /dev/mmcblk0, etc. It is assigned to /dev/mmcblk0, then it is OK. Otherwise, the inserted SD card never gets written with the image file.

Thanks for pointing that Mazi. Fixed the howto!

No problem.

Just wanting to share something here. I used some brand name SD cards with my Seagate Dockstar. The way I did this was to format my SD cards with EXT3 and then filled it by untarring a newly built OpenWRT tarred image. My SD cards usually go bad after 30+ x of reflash with a newly built OpenWRT image. Now, I resort to an old 120GB IDE drive. So far, so good.

man wrote:
mazilo wrote:

When an SD card is inserted into an SD slot, perhaps it is best to first check what device it is assigned to. It could be assigned to /dev/sdb1, /dev/mmcblk0, etc. It is assigned to /dev/mmcblk0, then it is OK. Otherwise, the inserted SD card never gets written with the image file.

Thanks for pointing that Mazi. Fixed the howto!

Thanks for writing these instructions. Using these the pi was able to bootup but i did not get any login prompt. Out of the box is this supposed to be a dhcp server or a dhcp client? I want the pi to be a dhcp client.

I also connected a usb keyboard which the pi showed up on its boot log, but it did not respond to the keypresses.

How do i login into pi after bootup?

trumee wrote:

Thanks for writing these instructions. Using these the pi was able to bootup but i did not get any login prompt. Out of the box is this supposed to be a dhcp server or a dhcp client? I want the pi to be a dhcp client.

I also connected a usb keyboard which the pi showed up on its boot log, but it did not respond to the keypresses.

How do i login into pi after bootup?

Hello Trumee,

The RPI will be a *DHCP SERVER*, with IP address 192.168.1.1.

Connect the ethernet cable to any of your systems (the port is MDI-X, so no need to worry with the IP address) and set your computer as a DHCP client. And then:

1. If you have selected LuCi at the make menuconfig, just point your browser to the IP address (192.168.1.1)
2. If you did not install LuCi, telnet to 192.168.1.1, define a root password (passwd) and then you will be able to SSH it.

Honestly, I did not test it using a monitor + keyboard; I can't confirm if is it the expected result or not.

Best regards,

- RF.

(Last edited by man on 25 Aug 2014, 15:22)

I connected a computer to Rpi, but it didnot get any ip. Even with a static ip (192.168.1.2) on the computer i was not able to ping to Rpi. I just wonder if i am missing anything in the configuration.  Did you have to set any preinit network image configuration in menuconfig?

trumee wrote:

I connected a computer to Rpi, but it didnot get any ip. Even with a static ip (192.168.1.2) on the computer i was not able to ping to Rpi. I just wonder if i am missing anything in the configuration.  Did you have to set any preinit network image configuration in menuconfig?

Hello,

What's the rootfs partition size? Where's the boot screen stuck at?

The rootfs partition is the default size of 48 MB. I took a screenshot of the display.

http://i.imgur.com/r5Q4rQb.jpg

trumee wrote:

The rootfs partition is the default size of 48 MB. I took a screenshot of the display.

You are right; I forgot to describe a important step. See Steps 13 & 14. And also, please pay attention to step E and H. In the previous version, I mixed a 128k erase image coupled with a 64k cmdline.  I unified them to 64k.

HTH!

- RF.

@man have you had any issues with SD card corruption since building it with JFFS2? Thanks

mulletman87 wrote:

@man have you had any issues with SD card corruption since building it with JFFS2? Thanks

Hello Mullet;

I let it run for almost a year. There were some corruption spotted by JFFS2, but in the end the data was retrieved.

For what is worth, now I run a Raspbian plus a single interface (VLAN tag) backed up by a UPS. The data is persisted in a external hard drive, a laptop HDD, through a usb-to-sata adapter.

For my other RPIs not protected by a ups, I use the SD card only to boot them from LAN (the main RPI is a NFS server).

Looks great so far.

Hth
-RF

Interesting, seriously considering this for my project. The alternative was tinycorelinux (runs almost exclusively in RAM with a little persistence on the SD card, just trying to figure out the best route.

At the end of the day, I don't have to have 200+ RPi's out in the wild and having SD cards failing on me and disgruntled clients on the phone tongue

Hello,

i tried this - but didn't get a jffs image.
Also tested with squashfs - no image. Only ext4 was built.

does anybody has any idea?

(Last edited by mwulz on 29 Sep 2016, 14:59)

The discussion might have continued from here.