Saturday, 14 March 2015

And now for something completely different....

So it's been a busy few months (work, real life), and I've become distracted in the blender internals when working out some details on projecting multiple images onto 3d reconstructed surfaces.

However in the meantime I have been playing with the MIPS CI20 boards from Imagination Technologies.

So, here's a quick starter on how I'm running this board

The Hardware

Essentially I'm wiring up the serial port and running the board in a headless mode. The header is detailed on the CI20 Hardware page, and I take the four pins from the primary header to drive my output board:

To power the external board
  • Pin 1 is +3v3
  • Pin 6 is Ground
 And the data signals are
  • Pin 8 Uart0 Txd
  • Pin 10 Uart 0 Rxd

Connecting through minicom (115200, 8N1) then shortly after boot UBoot reports:

 U-Boot 2013.10-rc3-gb253ee9 (Feb 14 2015 - 15:30:32)

Board: ci20 (Ingenic XBurst JZ4780 SoC)
DRAM:  1 GiB
NAND:  8192 MiB
MMC:   jz_mmc msc1: 0
*** Warning - bad CRC, using default environment

In:    eserial4
Out:   eserial4
Err:   eserial4
Net:   dm9000
Hit any key to stop autoboot:  0

(and of course on this run I stopped the autoboot with a keypress)

The Sources

Initially I grab the Buildroot and Kernel sources, and build a simple kernel image I can tftp across to the board, so I check out the sources on my development host with:

mkdir ci20
cd ci20

export ROOTDIR=`pwd`
git clone kernel
cd kernel
git checkout ci20-v3.0.8
cd ..
git clone git:// buildroot

And I take a snapshot of the raw checkout in case of problems with:

tar -cf buildroot-checkout.tar buildroot/
bzip2 buildroot-checkout.tar
tar -cf kernel-checkout.tar kernel/
bzip2 kernel-checkout.tar

The Rootfs

First I build up the rootfs using Buildroot, using the suggested Malta default config as a base:

cd buildroot
make qemu_mipsel_malta_defconfig
make menuconfig

At this point I set the options:
  • Under Toolchain, switch to "Toolchain type (External toolchain)", and this sets the correct defaults (Toolchain (Sourcery CodeBench MIPS 2014.11) and Toolchain origin (Toolchain to be downloaded and installed) in my case)
  • Under Filesystem images then enable the "cpio the root filesystem" option
  • Under "Kernel" then disable "Linux Kernel" option. This disables this entire sub-menu.
Next exit, save and run the build with


This will leave two files under "output/images/", and we care about the rootfs.cpio:

-rw-r--r-- 1 tony tony 4.8M Mar 14 15:27 rootfs.cpio

The Kernel

Next up the kernel; just go into the kernel directory; initially set up the path to point to the toolchain Buildroot downloaded and set up; i.e.
export PATH=$ROOTDIR/buildroot/output/host/usr/bin/:$PATH

and start by using the ci20_defconfig for the base config
cd ../kernel/
make ci20_defconfig
make ARCH=mips CROSS_COMPILE=mips-linux-gnu- menuconfig

At this point set the options:
  • Under  "General setup" "Initial RAM filesystem and RAM disk (initramfs/initrd) support
    • For "Initramfs source files(s)": set this to point at the cpio from buildroot (i.e. $ROOTDIR/buildroot/output/images/rootfs.cpio)
    • For " Built-in initramfs compression mode" select "Gzip"
Exit and build with
make ARCH=mips CROSS_COMPILE=mips-linux-gnu- uImage

And copy the output uImage file to the tftp directory; i.e.

cp arch/mips/boot/uImage /var/lib/tftpboot/uimage-ci20

Loading it

Now we can go back to the ci20 serial console and load the kernel, using tftp to transfer the image to the target over Ethernet. I have installed the tftp daemon on the host.

So to load the image on the board then return to the serial port and the bootloader commands I use are:

tftpboot 0x88000000 <host ip>:uimage-ci20
bootm 0x88000000

(The dhcp/tftpboot separation might not be necessary for anyone else, but I'm on a network with a PXE boot server, which adds some complications)

Following this the system boots to a console prompt (no password to log in as root), and I can just log in and check the build time is right fpr the kernel image I made and the architecture is what I expect (always a good sanity check):

Welcome to Buildroot
buildroot login: root
# uname -a
Linux buildroot 3.0.8-12456-g2e5af7d #1 SMP PREEMPT Sat Mar 14 14:53:40 GMT 2015 mips GNU/Linux
#  cat /proc/cpuinfo
system type             : CI20
processor               : 0
cpu model               : Ingenic Xburst V4.15  FPU V0.0
BogoMIPS                : 1196.85

etc, etc...

Extending it

This isn't particularly functional, being the bare minimum rootfs. Also changes won't persist since the rootfs is mounted over a tmpfs (which for my use case is a feature).

However both the kernel and Buildroot have a ton of options which can be enabled to improve functionality, using the menuconfig menus.

To enable more basic system features go back to the Buildroot directory and reconfigure. So, on the host:

cd $ROOTDIR/buildroot
make menuconfig

Then set the options
  • Under  System configuration
    • Set the  Root password to the password you want to use
    • Set the Network interface to configure through DHCP as "eth0"
  • Under Target packages
    • Under Networking applications
      • Select ethtool, dropbear, openssh, etc

and rebuild with:
make && cd ../kernel/ && \
 make ARCH=mips CROSS_COMPILE=mips-linux-gnu- uImage && \
 cp arch/mips/boot/uImage /var/lib/tftpboot/uimage-ci20

And then reboot and load the new image - having set the root password, enabled the eth0 dhcp and included an ssh daemon you should be able to ssh into the box.