Using the internal flash to run Linux (or anything else)

From Joggler
Jump to: navigation, search

CAUTION: Update 19/5/10Ignore the previous comments about differences between the O2 and OpenPeak EFI's. The corruption appears to be caused by having something plugged into the USB port when the device is booted. I am trying to narrow it down, and I have cleaned up my EFI partition on my USB stick and the internal flash. Near as I can figure out 2 of my bluetooth dongles and my USB keyboard (which has a hub built in) have corrupted it, I cannot get it to corrupt with my (bootable) usb stick attached either booting off the stick or booting off the internal flash. I did have the original boot.efi hanging around so it is possible that this is triggering something.

This little guide is aimed at people who wish to run a custom OS off the units internal 1GB flash.

For clarification the Joggler has 2 flashable internal chips, the EFI chip which should not be messed with and the 1 GB mmc flash which this guide deals with.

My experimentation has proved (if nothing else) that it is not possible to brick the Joggler by messing with the internal 1GB flash, however it is quite easy to leave the Joggler unbootable.

Recovering an unbootable Joggler

Before you do any of this, it is essential that you have a working usbstick with an efi partition and a working OS with all drivers.

If something you do leaves the Joggler in a non-booting state (i.e. stuck on O2/OpenPeak screen) take the following steps:

  1. Don't Panic
  2. Attach keyboard and known good usb stick, and apply power to the Joggler
  3. Press escape frantically (oh yes just like the good ol' days)
  4. Once the num-lock key has lit, press escape a few more times. The process has worked if the numlock/caps lock key switches on and off when you press the appropriate key.
  5. type the following: fs1:boot and press enter. You are typing blind thanks to the jogglers boot screen.
  6. If it doesn't boot the USB stick repeat the whole process.
  7. It it doesn't work repeat the whole process but type fs0:boot and press enter.


The reason for step 7 is that if you (or the joggler) has wiped the partition table of the mmc, then it is not seen as a file system, and the usb stick becomes fs0.

Flash Layout

Out of the factory the flash inside the Joggler looks like so: (output of fdisk -l /dev/mmcblk0)

Disk /dev/mmcblk0: 1028 MB, 1028128768 bytes
4 heads, 16 sectors/track, 31376 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Disk identifier: 0x00000000

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *           1        1954       62520   ef  EFI (FAT-12/16/32)
/dev/mmcblk0p2            1955        9768      250048   83  Linux
/dev/mmcblk0p3            9769       17582      250048   83  Linux
/dev/mmcblk0p4           17583       31376      441408   83  Linux

My first handy hint is DO NOT CHANGE the size of the first partition. Every time I changed the size, on the next reboot the Joggler wiped the partition table. YMMV.

As I didn't want to struggle to fit the various file systems in the 3 partitions I changed the partition structure so it looked like this:

Disk /dev/mmcblk0: 1028 MB, 1028128768 bytes
4 heads, 16 sectors/track, 31376 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Disk identifier: 0x5213f7df

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *           1        1954       62520   ef  EFI (FAT-12/16/32)
/dev/mmcblk0p2            1955       31376      941504   83  Linux

EFI Partition

To build my EFI partition I mounted the existing one (mount /dev/mmcblk0p1 /mnt/mount), and copied the files from my working usb stick EFI partition over, leave the existing 'startup.nsh' in place. The layout of your files may vary, but you need to edit grub.cfg (which if are using a recent usb stick image will be in /mnt/mount/grub.cfg if you used the mount command detailed).

It would probably look something like:

set timeout=0

menuentry "USB" {
	set root=(hd0,1)
	linux /vmlinuz-2.6.32 root=/dev/sda2 ro acpi=force idle=halt
	initrd /initrd-2.6.32
}

Assuming that the other entries are correct you need to change 'root=/dev/sda2' so it becomes 'root=/dev/mmcblk0p2' (/dev/mmcblk0p2 is the second partition on the internal flash).

You might also need to double check the boot.nsh script and modify this to be "fs0: grub", rather than "fs1: grub".

Linux Partition

To fill this generous space I built an emdebian grip squeeze image, which is basically the next release of debian (squeeze) with a light grip applied. This removes a lot of the docs, man pages etc, and drastically reduces the size of the installation. With an lxde X11 setup with mplayer, samba, and all the other tools I need for my Joggler, df -k looks like this:

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mmcblk0p2          926680    477064    402544  55% /
tmpfs                   255436         4    255432   1% /lib/init/rw
udev                     10240        88     10152   1% /dev
tmpfs                   255436         0    255436   0% /dev/shm

So plenty of room for further expansion, my photos being displayed from my server, no unsightly usb stick and an empty usb slot.

Assuming you copy your image from a usb stick to the internal flash, to get your image to work when you boot off internal, you will need to edit /etc/fstab

There will be a line like:

/dev/sda2       /               ext3    errors=remount-ro,relatime 0       1

(if you use UUID, then you are on your own as I have no clue about them) Again, you need to change the sda2 to mmcblk0p2.

Issues

I am getting lots of 'mmc2: Too large timeout requested!' errors in syslog/dmesg. Google has provided some clues but I haven't managed to track it down yet, although it doesn't seem to cause problems.

Credit: Thanks to STSkeeps blog for the escape boot method, and the grub loader.


Disclaimer: You attempt the above modifications at your own risk. They haven't appeared to damage either of my Jogglers that doesn't mean yours won't be hosed.

@OP Could you maybe post up a quick guide of how you setup emdebian? I (and others) are struggling with getting it setup for the joggler.