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.
 * will be ext2 with 100MB (boot)
 * will be btrfs with the rest of the capacity (root)

can be different in your computer probably

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

Extract stage 3
Get from Gentoo Mirrors the latest and extract it to the root partition.

Edit /etc/fstab
Edit on the root partition on the sdcard :

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.

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.

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.

Add btrfs to the kernel (built-in). Add  to the kernel.

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:

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 if the driver is compiled as module or directly into the kernel source folder under  if they will be compiled built-in.

Headers
To compile certain applications like xbmc that have modified/additional codecs zou need to expose the patched kernel headers. Fortunately there is a script for that:

If you install them into /usr/local/include then you don't overwrite the ones provided by the gentoo package.

Interactive
Connect to your Cubox-i with a serial console (or with a keyboard and a display) and interrupt the u-boot bootloader with 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 (Hardcoded)
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

uEnv
u-Boot can also read configuration values from a file. This way the boot process can be modified without going into the u-Boot console and the settings are permanent as well. The following script is modified from the original mini-image used for the installation. In the uEnv.txt file you can no add now for example rootflags to boot from a specific btrfs snapshot.

setenv gsetmmc 'root="root=/dev/mmcblk${rootunit}p$rootpart rootfstype=$rootfs ro rootwait"' setenv gconsole console=ttymxc0,115200 setenv gbootextra init=/init setenv grootflags "" setenv gvideo mxcfb0:dev=hdmi,1920x1080M@60,if=RGB24 setenv gbootpreset 'bootdev=mmc; bootunit=0; bootpart=1; bootfs=ext2; envfile=uEnv.txt; bootroot=; bootfile=uImage' setenv grootpreset 'rootunit=0; rootpart=2; rootfs=btrfs' setenv gsetenvscript setenv gbootenv "\'run gset\${bootdev}; setenv bootargs \$root \$gvideo \$gconsole \$gbootextra \$grootflags $end\'" setenv gloaduenv 'if ${bootfs}load $bootdev $bootunit:$bootpart $loadaddr $envfile; then env import -t $loadaddr $filesize; fi' setenv grootpresetup 'bootrun=bootm; loadfile=$bootfile; rootdev=$bootdev; rootunit=$bootunit; rootpart=$rootpart; rootfs=$rootfs' setenv gbootload '${bootfs}load $bootdev $bootunit:$bootpart $loadaddr $bootroot/$loadfile' setenv gbootstart '$bootrun' setenv bootcmd run gbootpreset grootpreset gsetenvscript gloaduenv grootpresetup gbootenv gbootload gbootstart

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

Graphics driver (closed source)
You can find a portage repository with packages for the closed source drivers on github: https://github.com/stefan-langenmaier/gentoo-cubox-i-repository

Open Questions

 * open-source hardware-accelerated video driver
 * reverse engineereddrivers
 * kms driver is disabled in patched kernel