Notizbl0g.

h4cking, ham radio, fire fighting and m0re

Update on Fli4l and CF Cards

It seems that the procedure to install fli4l on large CF cards that I described in 2012 does not reliably work any more. This is probably due to changes from grub to grub2 within recent operating systems. Therefore I did some research again and tried various options and boot loaders to start fli4l from compact flash card.

In the end I found a solution that works with a syslinux MBR and syslinux itself installed to the boot partition. This is actually the solution that mkfli4l.sh should produce. But it my case it fiddled with fdisk to mark the boot partition as active. So I let mkfli4l.sh not install the boot loader to the card but instead did this manually. The whole procedure is described here.

By the way: The paths and names correspond to fli4l version 4.0. Differences from 3.10 are outlined where applicable. Host operating system is an Ubuntu Linux 14.04.2 LTS.

As I had done some experiments with various boot loaders on the same CF card before I wiped the MBR and thus also the partition table from the card. The device with the CF card is /dev/sdg in this case. The card is a 2GB SanDisk Ultra. The Alix 2D13 tells the physical structure as:

01F0 Master 848A SanDisk SDCFH-002G
Phys C/H/S 3897/16/63 Log C/H/S 974/64/63

You will need to change this accordingly and make sure you chose the correct device. Otherwise you might damage your running operating system.

$ sudo dd if=/dev/zero of=/dev/sdg bs=4M count=1

Partitioning and creation of filesystems

Before partitioning the card make sure that it is not mounted. If that is the case (Ubuntu auto-mounts my cards when I insert them) just unmount the card. For example:

$ sudo umount /dev/sdg{1,2}

After that I create two new partitions using fdisk. It is important to use the DOS compatibility flag because otherwise the Alix 2D13 board will not be able to boot (must be investigated further).

$ sudo fdisk -c=dos -u=cylinders /dev/sdg
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd4e2944b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (with command 'c').
WARNING: cylinders as display units are deprecated. Use command 'u' to
         change units to sectors.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First cylinder (1-1021, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1021, default 1021): +128M

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))

Command (m for help): a
Partition number (1-4): 1

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2): 2
First cylinder (70-1021, default 70): 
Using default value 70
Last cylinder, +cylinders or +size{K,M,G} (70-1021, default 1021): 
Using default value 1021

Command (m for help): p

Disk /dev/sdg: 2011 MB, 2011226112 bytes
62 heads, 62 sectors/track, 1021 cylinders
Units = cylinders of 3844 * 512 = 1968128 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd4e2944b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdg1   *           1          69      132587    c  W95 FAT32 (LBA)
/dev/sdg2              70        1021     1829744   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

After that the DOS boot partition needs to be formatted and I also added a label in order to recognise the device after auto-mounting.

$ sudo mkfs.vfat /dev/sdg1
mkfs.fat 3.0.26 (2014-03-07)
$ sudo mlabel -i /dev/sdg1 ::BOOT

The same goes for the data partition that is used to save persistent data that needs to survive a system reboot:

$ sudo mkfs.ext2 /dev/sdg2
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
114464 inodes, 457436 blocks
22871 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=469762048
14 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks: 
   32768, 98304, 163840, 229376, 294912

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done 

$ sudo e2label /dev/sdg2 DATA

From here just pull the card and re-plug it. On my Ubuntu system it is than auto-mounted unter /media/user/BOOT and /media/user/DATA. You can than go on with the installation of the fli4l system.

Installation of the Fli4l Base System

Here I executed mkfli4l.sh as follows:

$ ./mkfli4l.sh --hdinstallpath /media/user/BOOT/

fli4l 4.0.0-r42894 - starting build process
==============================================================================

using configuration from directory 'config'...

--- read and check the build-environment from config/mkfli4l.txt...-----------
------------------------------------------------------------------------------

--- check configuration in directory "config" and create archives ------------
trying unix/x86_64-linux-mkfli4l... OK.
------------------------------------------------------------------------------

--- extracting some information from config/build/image/rc.cfg ---------------
  ARCH='x86'
  KERNEL_VERSION='4.1.13-nonfree'
  COMP_TYPE_ROOTFS='xz'
  COMP_TYPE_OPT='xz'
  OPT_RECOVER='yes'
------------------------------------------------------------------------------

--- generating md5 sums-------------------------------------------------------
FLI4L_MD5_RC_CFG='c63cdbba086d62ccec7997d4fa5d75ee'
FLI4L_MD5_KERNEL='7e278a76e65845e7a04d2a7b4cecdb50'
FLI4L_MD5_ROOTFS_IMG='bdec1a015d9dce7886ee6d9322babb9e'
FLI4L_MD5_OPT_IMG='8a1d23d52dfb669d07b67b7fe6472a03'
FLI4L_MD5_SYSLINUX_CFG='934b13c25454f488cd9aecebb039d504'
------------------------------------------------------------------------------

creation of all build-files finished...

--- trying to copy files to install medium------------------------------------
   rc.cfg [OK]
   kernel [OK]
   rootfs.img [OK]
   boot.msg [OK]
   boot_s.msg [OK]
   boot_z.msg [OK]
   opt.img [OK]
   syslinux.cfg [OK]
------------------------------------------------------------------------------

--- installing boot loader on /dev/sdg----------------------------------------
If you really know what you're doing type: YES!!!
NO

In order to get the DATA partition mounted at boot time we need to add an entry to the hd.cfg file on the boot partition (/media/user/BOOT/hd.cfg in this case). Mine reads:

hd_boot='sda1'
hd_data='sda2'

Installing syslinux loader

So the next step is the installation of syslinux into the boot section of the first partition.

$ sudo syslinux --install /dev/sdg1

And than write the syslinux MBR with (executed from the directory where all the fli4l archives are extracted):

$ sudo dd if=opt/files/usr/share/syslinux/mbr.bin of=/dev/sdg
0+1 records in
0+1 records out
440 bytes (440 B) copied, 0.000281295 s, 1.6 MB/s

For fli4l v3.10 the image of the MBR is to be found in opt/files/usr/share/. Now you can unmount the two drives again and put the CF card back into the Alix 2D13 board. It should now boot fli4l without any problems.

The serial console shows here:

PC Engines ALIX.2 v0.99m
640 KB Base Memory
261120 KB Extended Memory

01F0 Master 848A SanDisk SDCFH-002G                      
Phys C/H/S 3897/16/63 Log C/H/S 974/64/63

SYSLINUX 4.05 20140113 Copyright (C) 1994-2011 H. Peter Anvin et al

    __ _ _ _  _   _        ____              _                              
   / _| (_) || | | |      |  _ \            | |                             
  | |_| |_| || |_| |______| |_) | ___   ___ | |_ _ __ ___   ___ _ __  _   _ 
  |  _| | |__   _| |______|  _ < / _ \ / _ \| __| '_ ` _ \ / _ \ '_ \| | | |
  | | | | |  | | | |      | |_) | (_) | (_) | |_| | | | | |  __/ | | | |_| |
  |_| |_|_|  |_| |_|      |____/ \___/ \___/ \__|_| |_| |_|\___|_| |_|\__,_|


n <=> boot fli4l standard installation
      Version: 4.0.0-r42894


Choose character from first column to select version and press ENTER

The standard installation will be automatically booted 

Unknown keyword in configuration file: DEVICETREEDIR
Unknown keyword in configuration file: DEVICETREEDIR
Unknown keyword in configuration file: DEVICETREEDIR
boot: 
Loading /kernel....
Loading /rootfs.img.....ready.
Linux version 4.1.13-nonfree (fli4l@eisler) (gcc version 4.9.3 (Buildroot 2015.08.1) ) #1 SMP Wed Nov 18 13:47:27 CET 2015