Cubox-i

Goal
The goal of these instructions is to have a running installation of Gentoo on a Cubox-i, with a kernel up-to-date enough to run a current btrfs root filesystem.

Prerequisite

 * Cubox-i
 * if you want to configure over a serial console you need a CuBox-i2ultra or a CuBox-i4pro
 * otherwise you need an hdmi display and an usb keyboard
 * another (Linux) computer with a cross compiler for arm installed
 * git
 * tftp server
 * u-boot-tools
 * mini-image
 * sd-card (with enough space, boot partition, rootfs with a git kernel and gentoo, 4GB+)
 * network cable for an internet connection (the wifi driver needs a firmware that can be installed later)

Installation
The install consists of partitioning and formatting, the sd-card. Copying over a stage3 tarball, configuring it so that it can boot and it can be accessed. Creating a kernel. Booting the kernel on the machine. Installing the kernel for an automatic boot. Continue a default Gentoo installation.

Setup Custom u-Boot
 u-Boot can be compiled from source as well. Nevertheless we start with a precompiled one, so this step can be skipped.

Setup serial console
If the model is a CuBox-i2ultra or a CuBox-i4pro it can be connected direclty with your other computer. If not you need to attach it to an hdmi display and connect a usb keyboard.

Preparing SD Card
To start we flash the mini-image on the sd-card. This way there is already u-boot properly installed and we can test if the serial connection (or connected keyboard and display) is working.

If the first test worked okay you can partition and format the card. As in the goal described in a two partition scheme will be used.
 * /dev/mmcblk0p0 will be ext2 with 100MB (boot)
 * /dev/mmcblk0p1 will be btrfs with the rest of the capacity (root)

/dev/mmcblk0 can be different in your computer probably /dev/sdX

The minimal configuration of the root has to be done already on the other computer
 * 1) extract stage3
 * 2) edit /etc/fstab
 * 3) set root password
 * 4) enable serial console

extract stage 3
Get from Gentoo Mirrors the latest /releases/arm/autobuilds/current-stage3-armv7a_hardfp/ and extract it to the root partition

cd /mnt/sdcard-root tar xvjpf /path/to/download/stage3-*.tar.bz2

edit /etc/fstab
edit on the root partition on the sdcard /etc/fstab

/dev/mmcblk0p1         /boot           ext2            noauto,noatime  1 2 /dev/mmcblk0p2         /               btrfs           noatime         0 1


 * 1) /dev/SWAP             none            swap            sw              0 0
 * 2) /dev/cdrom            /mnt/cdrom      auto            noauto,ro       0 0
 * 3) /dev/fd0              /mnt/floppy     auto            noauto          0 0

edit root password
to be able to login later we need to set a root password, we create passwor hash and edit it to the /etc/shadow


 * 1) openssl passwd -1


 * 1) nano -w /mnt/sdcard-root/etc/shadow
 * 2) #replace the start or current hash of the root user with the output from the command above

enable serial console
to also have a serial console after we booted the current system we need to modify


 * 1) nano /mnt/sdcard-root/etc/inittab

s0:12345:respawn:/sbin/agetty -L 115200 ttymxc0 vt100
 * 1) # and change the s0 line to the following

This should be enough that a kernel can boot the system and that we can work with it afterwards

Kernel
At the moment the are multiple sources for kernels available all with their specific advantages and drawbacks.


 * https://github.com/SolidRun/linux-imx6 the kernels here are all 3.0.x, they are the offical ones from solidrun with all the patches included but unfortunately to old for a current btrfs system
 * a vanilla kernel 3.12+ might run on the cubox-i but it does not contain all the patches to use the complete hardware
 * https://github.com/SolidRun/linux-linaro-stable-mx6 is new merge of 3.10.x and all the patches, in the following we are going with this one
 * (2014-03-01) I had some problems with make dtbs, and had to make some modifications, you can find the here, but be warned I have no idea what I am doing.
 * There are also some patches for 3.14-rc around. I could not test them. 3.14 or 3.15 should include more support for the Cubox-i in the vanilla kernel.


 * 1) export ARCH=arm
 * 2) export CROSS_COMPILE=armv7a-hardfloat-linux-gnueabi-


 * 1) git clone https://github.com/linux4kix/linux-linaro-stable-mx6


 * 1) cd linux-linaro-stable-mx6


 * 1) make imx_v7_cubox-i_hummingboard_defconfig
 * 2) make menuconfig
 * 3) # add btrfs to the kernel (built-in)
 * 4) # add ARM_APPENDED_DTB to the kernel


 * 1) make


 * 1) cd arch/arm/boot
 * 2) cat zImage dts/imx6q-cubox-i.dtb > zImage-dtb
 * 3) mkimage -A arm -O linux -C none -T kernel -a 0x10008000 -e 0x10008000 -n "linux-cubox-i-3.10.30" -d zImage-dtb uImage

Wifi
The drivers for wifi need a firmware. In case you are have set them to built-in you have to include the blobs already in the kernel

The following settings are necessay for the driver: CONFIG_BRCMUTIL=y CONFIG_BRCMFMAC=y CONFIG_BRCMFMAC_SDIO=y

I have the blobs from the geexbox package firmware-wifi-brcm80211_20140206-d7f8a7c81a3-1_armv7.opk
 * brcmfmac4329-sdio.bin
 * brcmfmac4329-sdio.txt

The files have to be dropped in "/lib/firmware/brcm/" if the driver is compiled as module or directly into the kernel source folder under "firmware/brcm" if they will be compiled built-in.

Interactive
Connect to your Cubox-i with a serial console (or with a keyboard and a display) and interrupt the u-boot bootloader with Enter and type the following commands.

setenv ipaddr 192.168.0. setenv serverip 192.168.0. setenv bootargs root=/dev/mmcblk0p2 rootfstype=btrfs ro rootwait console=ttymxc0,115200 tftpboot 0x10800000 uimage bootm 0x10800000

This should boot you in your Cubox-i installation and you should be able to login as root with your password. From here you can continue with a default Gentoo installation. To make this boot configuration permanent follow the next step "Default".

Default
In the following we will make the settings permanent. The uImage file is copied to the boot partition. The first line contains the settings for loading the kernel into memory. The second holds the arguments for the kernel. The third one is the code to execute the kernel.

The bootcmd is called by default and executes theses three steps in order. The last line makes these variables permanent in the u-boot settings. setenv mybootload ext2load mmc 0:1 0x10800000 /uimage setenv mybootset setenv bootargs root=/dev/mmcblk0p2 rootfstype=btrfs ro rootwait console=ttymxc0,115200 setenv mybootstart bootm 0x10800000 setenv bootcmd run mybootset mybootload mybootstart saveenv

Continue Gentoo install
Steps that should be done right after the installation
 * 1) setup network
 * 2) set date
 * 3) emerge-webrsync
 * 4) emerge ntpd
 * 5) /etc/init.d/sshd

Gentoo arm install Handbook

Premade Image


Open Questions

 * HDMI