Solved: Mini6410 boot and run Linux from SD card

HRuessink
I wanted to run Linux from the SD card on the mini6410, specifically I
wanted to boot the kernel from the SD card and have the rootfs as a normal
ext2/ext3 partition on the SD card (as opposed to a file that contains a
rootfs). This post explains how I achieved that.

Booting a linux kernel from the SD card is not a problem: The bootloader
(Superboot or u-boot) will handle that, with the restriction that the
kernel should be located on the first partitiion and this partition should
be a FAT partition.

As the first partition is used for allowing the bootloader to find and load
the kernel, the ext2/ext3 rootfs must be placed on the second partition.

My initial attempts to do this failed. I partitioned an SD card with two
partitions: a FAT32 partition and a ext2 partition. The FAT partition
contains the images directory containing the Linux/zImage kernel and a
FriendlyARM.ini file. In the FriendlyARM.ini file I set the root= option to
'/dev/mmcblk0p2, which points to the ext2 partition on the SD card. This
failed with a message from the kernel that the device /dev/mmcblk0p2 did
not exist.

Digging into this I found out that the kernel comes with a minimal
filesystem in memory: initrd/initramfs. This filesystem contains the device
nodes that are necessary to access any devices before the root filesystem
has been mounted, and these are also used to mount the root filesystem. 
Looking at the contents of this ramdisk filesystem I saw that it only
contains a device for the first partition of the SD card. There was no
device for the second partition, and this means that the kernel has no way
of accessing it, and cannot mount it.

The solution then was to add the device node to the initial ram filesystem.
This involves recompiling the kernel. 

Below is the complete recipe for a Linux x86 based environment. The recipe
assumes that you have downloaded and mounted the latest FriendlyARM DVDs
(see the bottom of the download page at www.friendlyarm.net for
username/password to download them from ftp.friendlyarm.net) and that you
are using a shell prompt. You must also have sudo rights because root is
required to create device nodes.

Step 1. Toolchain and kernel sources

Create a directory to work in and cd into this directory: 
$> mkdir FriendlyARM
$> cd FriendlyARM

Find the path to the Mini6410A DVD image and xtract the gcc cross-compiler
and the kernel sources from the Linux directory :
$> tar -zxf <dvd_path>/Linux/arm-linux-gcc-4.5.1-v6-vfp-20101103.tar.gz 
$> tar -zxf <dvd_path>/Linux/linux-2.6.36-20110112.tar.gz

Also create a directory for the ram filessystem:
$> mkdir initramfs

You now have three directories: opt (toolchain), linux.2.6.36 (kernel
sources) and initramfs

Step 2. Configure the kernel

Go into the kernel source directory and select a configuration that matches
your display hardware:
$> cd linux-2.6.36
$> cp config_mini6410_<type> .config

I used the n43 version to match my 4.3" display.

Start the configuration menu:
$> make menuconfig
[This requires ncurses. I had to install them on my Ubuntu workstation:
'sudo apt-get install libcdk5-dev'.]

Select 'General setup' (at the top). Select the line that says:
(arm-linux-) Cross-compiler tool prefix

In the dialog change the string to the location of the GCC toolschain:

<path_to_your_home>/FriendlyARM/opt/FriendlyARM/toolschain/4.5.1/bin/arm-n
one-linux-gnueabi-

Enter the absolute path to where you extracted the toolchain.

Select OK, then scroll down to 'Initial RAM filesystem and RAM disk'.
Select the line just below this, the one that reads:
(scripts/FriendlyARM.cpio) Initramfs sourcefile(s)

In the next dialog box, change the input to 'scripts/FriendlyARM_SD.cpio'.
Click OK, then Exit and Exit to leave the configuration menu. Then select
Yes to save the new configuration.

Now build the tool that we need to create the contents of the ram
filesystem.
$> cd usr
$> make gen_init_cpio

Now return to the directory above:

$> cd ../..

Step 3. Setup the ramdisk contents

We will use the gen_init_cpio  tool in the kernel sources to create the
additional devices. The mknod command on the Linux host system may not be
able to create the device nodes for the MMC device.

Create a file that specifies the required device nodes for the SD card, for
instance the following lines define device nodes for a second, third and
fourth partition:
$> > new_devices
$> echo "nod dev/mmcblk0p2 0644 0 0 b 179 2" >> new_devices
$> echo "nod dev/mmcblk0p3 0644 0 0 b 179 3" >> new_devices
$> echo "nod dev/mmcblk0p4 0644 0 0 b 179 4" >> new_devices

Extract the FriendlyARM ramdisk archive into the initramfs directory. Use
sudo because extracting the archive will create device nodes:
$> cd initramfs
$> sudo cpio -id -F ../linux-2.6.36/scripts/FriendlyARM.cpio

Use the definition file to add the new device nodes:
$> ../linux-2.6.36/usr/gen_init_cpio ../new_devices | sudo cpio -id

Check that this succeeded:
$> ls -l dev
total 0
crw-r--r-- 1 root root   5, 1 2011-02-14 14:56 console
brw-r--r-- 1 root root   7, 0 2011-02-14 14:56 loop0
brw-r--r-- 1 root root   7, 1 2011-02-14 14:56 loop1
brw-r--r-- 1 root root 179, 1 2011-02-14 14:56 mmcblk0p1
brw-r--r-- 1 root root 179, 2 2011-02-14 15:36 mmcblk0p2
brw-r--r-- 1 root root 179, 3 2011-02-14 15:36 mmcblk0p3
brw-r--r-- 1 root root 179, 4 2011-02-14 15:36 mmcblk0p4
brw-r--r-- 1 root root  31, 0 2011-02-14 14:56 mtdblock0
brw-r--r-- 1 root root  31, 1 2011-02-14 14:56 mtdblock1
brw-r--r-- 1 root root  31, 2 2011-02-14 14:56 mtdblock2
crw-rw-rw- 1 root root   1, 3 2011-02-14 14:56 null

If all is well, buld a new ramfs archive:
$> find * | sudo cpio -H newc -o >
../linux-2.6.36/scripts/FriendlyARM_SD.cpio

Go back to the directory above:
$> cd ..

Step 5. Compile the kernel and partition the SD card

$> cd linux-2.6.36
$> make

This will take awhile. In the meantime, partition an SD card and initialize
the filesystems. The first partition should be a FAT partition of at least
5 MB. I used 20 MB just to be on the safe side. This partition will only
hold the kernel and the FriendlyARM.ini file, so you don't need much space.
The second partition should be a ext2 or ext3 file system (I understand
that ext2 is easier on the SD card as the ext3 journalling writes every
transaction in the same small buffer, wearing out the SD card more
quickly).

Use the SDflasher tool (in Windows) to flash the Superboot bootloader to
the SD card.

Step 6. Fill the SD card

Make sure that you are still in the linux-2.6.36 directory.

Attach the SD card to your linux workstation. This should mount two
filesystems: the FAT filesystem (the boot partition) and the ext2 or ext3
filesystem (the root filesystem). Check where they are mounted using the
'mount'. On Ubuntu they are mounted under /media. Adapt the commands to
where your partitions are mounted:

$> mount
[...]
/dev/sdb2 on /media/Root type ext2 (rw,nosuid,nodev,uhelper=udisks)
/dev/sdb1 on /media/BOOT type vfat
(rw,nosuid,nodev,uhelper=udisks,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf
8=1,showexec,flush)

Create the images directory on the BOOT partition, add the Linux
subdirectory and copy the kernel to this directory:
$> mkdir /media/BOOT/images
$> mkdir /media/BOOT/images/Linux
$> cp arch/arm/boot/zImage /media/BOOT/images/Linux/zImage_SD

Add the file FriendlyARM.ini to /media/BOOT/images with the following
minimalist content:

#This line cannot be removed. by FriendlyARM(www.arm9.net)
CheckOneButton=No
Action=run
OS= Linux
VerifyNandWrite=No
StatusType = Beeper| LED
#################### Linux #####################
Linux-Kernel = Linux/zImage_SD
Linux-CommandLine = root=/dev/mmcblk0p2 rootwait init=/sbin/init
console=ttySAC0,115200


The boot options specifiy the rootfs device (/dev/mmcblk0p2), to wait until
the root device becomes available (possibly not needed, as the card must be
available because the kernel is loaded from the card), to start /sbin/init
(depends on the kind of linux distribution that is put on the SD card) and
the settings for the console.
Go back to the directory FriendlyARM:

$> cd ..

To create the contents of the root filesystem I used the
rootfs_qtopia_qt4.ext3 file from the Mini6410B DVD. First create a
directory that will act as a mountpoint and mount the rootfs file as a
loopback filesystem:

$> mkdir rootfs
$> sudo mount -o loop -t ext3
<dvd_path>/images/Linux/rootfs_qtopia_qt4.ext3 ./rootfs

Now copy the contents to the second partition on the SD card:
$> cd rootfs
$> sudo find * | sudo cpio -ov | (cd /media/Root ; sudo cpio -idv)
$> sync; sync

This may take awhile. The sync command ensure that all write actions are
completed.

When this is done, safely eject the SD card and insert it in Mini6410.
Connect a serial line to Mini6410 to monitor the boot process. Set the S2
switch (left side) to NOR (to the back) and turn on the Mini6410.

The Mini6410 will now boot into Qtopia from the SD card with the screen
calibration application (at least, on my touchscreen Mini6410).

Tuxerito
Thanks for this info.

I have a Mini6410 too and 2 month ago I had installed Debian SID on my
board, but I forgot somethings that I did to run the SO from the SD.

With this info I will install Debian again but using somethings that you
say that I didn't used last time.

cagatay
did you write about the error seems like as shown below ? 

usb 1-2: new full speed USB device using s3c2410-ohci and address 2
VFS: Cannot open root device "mmcblk0p2" or unknown-block(179,2)
Please append a correct "root=" boot option; here are the available
partitions:
1f00             256 mtdblock0 (driver?)
1f01             128 mtdblock1 (driver?)
1f02            5120 mtdblock2 (driver?)
1f03           60032 mtdblock3 (driver?)
1f04           65536 mtdblock4 (driver?)
b300          262144 mmcblk0 driver: mmcblk
  b301           32098 mmcblk0p1
  b302          200812 mmcblk0p2
  b303           24097 mmcblk0p3
Kernel panic - not syncing: VFS: Unable to mount root fs on
unknown-block(179,2)
Backtrace:

Tuxerito
I have the same error Kernel panic - not syncing: VFS: Unable to mount root
fs on
unknown-block(179,2)

redeagle
I get "mount: mounting /dev/mmcblk0p2 on /r failed: No such device or
address"
but /dev/mmcblk0p2 should be available - I checked my .cpio-file. It's also
addressed in the .config-file…

Wenqi
Same problem found with mini210s and kernel-2.6.35.7
The described method is not useful.

redeagle
I solved the problem by switching the filesystem of the root-fs from ext2
to ext3 AND by using a slower SD-Card.

in other words:
ext2, fast SD: error
ext3, fast SD: error
ext2, slow SD: error
ext3, slow SD: success \o/ :D

gprengan
thanks a lot..
I did this Procedure for Android for mini6410 boot and run.. It quiet
working good but the touchscreen is not working.. other than touch screen
it works cool. please give solution to touch screen.

gprengan
i got the touchscreen working with some changes in FriendlyARM.ini
thanks

Jeffin
do not select the config as:

kernel make menuconfig
 General setup->Initial RAM filesystem and RAM disk (initramfs/initrd)
support

disable it.

kanth
Thanks a lot. I followed the procedure and could able to boot linux on
Mini6410. My LCD A70 is showing GUI. But I could not able to see log
messages on my PC.

I connected serial port cable from Mini6410 to PC
Configured minicom with /dev/ttySAC0, 115200
Ubuntu version - 13.04

Can anybody help in this issue please?

Nikhil Shah
Please can any one send me the images folder written ion SD card given by
FriendlyARM, as it has been format unknowingly. I am trying to boot u-boot
image from the CD2 given but i am unable to solve the problem.

Himasagar
hi all
am new to arm9 P35 board.
when am trying to load os(root fs file) in to board through sd card. my
board is not detecting the sd card it is giving that no sd card. how to
overcome this.

Thanks in Advance

Sunny Leone
your sd card should to be formatted with "FAT32" file system and it must
contain "images" directory with "FriendlyArm.ini" file.