Manual build howto

Getting u-boot, a kernel, and a rootfs on an SD card.

This is a document which brings the sunxi u-boot, linux and other bits together to form a useful SD card, the basis for further hacking. It is a boiled down and updated version of "Building Debian From Source Code for Mele". We of course do not build a whole distribution, we only build u-boot, the kernel and a handful of tools, and then use an existing rootfs to get a useful system.

While we currently focus on the mele A1000, most of it seems reasonably universal.

The SD-Card
Depending on the size of the rootfs, you might want to use a 2GB or larger SDCard. Partitioning and formatting this SDCard will be taken care of during the relevant sections.

The toolchain
Before anything else, you need to have a working toolchain. This is a set of binaries, system libraries and tools which will allow you to build (in our case, cross-compile) u-boot and the kernel for the target platform. This will, to some limited extent, need to match the target rootfs. A big and vastly incompatible change has taken place recently, namely the introduction of the Hard Float ABI, and now two different debian and ubuntu ports exist which are binary incompatible with eachother.

One option is to get a linaro released toolchain. Ignore most of the files there, but take the gcc-linaro-arm-linux-gnueabihf-*_linux.tar.bz2 file and untar it. You will find a bin directory in there, and it pays to temporarily add it to the environment you are building from:

export PATH="$PATH":/home/blah/bleh/gcc-linaro-arm-linux-gnueabihf-..._linux/bin/

The more recent linaro toolchains are Hard Float (hf), which only runs us into one issue with u-boot, and this will be used throughout the document. Wherever you see something like

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

you need to exchange arm-linux-gnueabihf- with arm-linux-gnueabi- if your are not using a hardfloat toolchain.

The rootfs
Linaro also offers a set of different root filesystems, you can get the actual rootfs tarballs here.

The code
We will need to get four sunxi specific git repositories. All are gathered in one place. git clone git://github.com/linux-sunxi/u-boot-sunxi.git git clone git://github.com/linux-sunxi/linux-sunxi.git git clone git://github.com/linux-sunxi/sunxi-tools.git git clone git://github.com/linux-sunxi/sunxi-boards.git

You can also use sunxi-bsp which has repositories above as submodules. git clone git://github.com/linux-sunxi/sunxi-bsp.git

sunxi-bsp
If you use sunxi-bsp you can skip further steps and run ./configure # to list all currently supported boards ./configure make hwpack-install SD_CARD=/dev/sdX ROOTFS=your_rootfs.tar.gz

Users of Ubuntu Linux or related distros like Mint, may need to install the following packages: sudo apt-get install libusb-1.0-0-dev uboot-mkimage pkg-config

Building u-boot
With the toolchain in your PATH, you can now change directory to u-boot-sunxi and build it: cd u-boot-sunxi make mele_a1000 CROSS_COMPILE=arm-linux-gnueabihf-

Other targets can be found in board/allwinner.

New target can be created if you know correct RAM parameters. RAM parameters can be read by using a10-meminfo tool found from https://github.com/maxnet/a10-meminfo.

Building script.bin
Descend into sunxi-tools and run make. You do need to have the libusb devel package installed though.

Then, get into the sunxi-board tree. You will find the .fex file for the mele in sys_config/a10/. Open up your mele and find out the MAC Address, as you will need to fix the MAC in the [dynamic] section of the fex file, to match the one for your device: MAC = "000000000000" to, for example: [dynamic] MAC = "0123456789AB"

Note
The section [dynamic] might not exist in the example .fex files. It is safe to add it if you need.

Now you can create the script.bin file: /home/blah/bleh/sunxi-tools/fex2bin mele_a1000.fex script.bin You will need this later on when finishing u-boot installation.

Building the kernel
Descend into your linux tree, and check out the correct branch:

git checkout origin/sunxi-3.0

Then run

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun4i_defconfig

and

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j5 uImage modules

Once this stops building you can run

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install

but you can come back to that later, and first occupy yourself with setting up the sdcard.

Setting up the SDCard
The first megabyte of the SDCard will contain the partition table, and a few other binaries needed for booting.

dd if=/dev/zero of=/dev/mmcblkx bs=512 count=2047

Now you can set up a partition table on your SDCard with for instance fdisk. Here is an example partition table for a 4GB SDCard: Disk /dev/mmcblkx: 3965 MB, 3965190144 bytes 122 heads, 62 sectors/track, 1023 cylinders, total 7744512 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xb4e92fdc

Device Boot     Start         End      Blocks   Id  System /dev/mmcblkxp1           2048       34815       16384   83  Linux /dev/mmcblkxp2          34816     7744511     3854848   83  Linux

Note that the boot partition should start at cluster 2048 (1024kB). Also note that this partition can have the linux partition type, we will format it to vfat later. You might want to make your boot partition bigger though.

Install the SPL loader and the u-boot binary to the first MB, before the first partition. The SPL to 8kB and the u-boot binary to 32kB: dd if=/home/blah/bleh/u-boot-sunxi/spl/sunxi-spl.bin of=/dev/mmcblkx bs=1024 seek=8 dd if=/home/blah/bleh/u-boot-sunxi/u-boot.bin of=/dev/mmcblkx bs=1024 seek=32

Setting up the boot partition
Hopefully by now, the building of the kernel and the modules has finished, and you have already installed the kernel modules. If not, go back to and do the last step there.

Format the boot partition mkfs.vfat /dev/mmcblk0p1 and mount it somewhere, and descend into it.

Now copy the kernel image over: cp /home/blah/bleh/linux-sunxi/arch/arm/boot/uImage. We will copy the modules and such to the rootfs later on.

Now copy over the script.bin we created from the .fex file: cp /home/blah/bleh/sunxi-boards/sys_config/a10/script.bin.

Create a boot.cmd with the following content: setenv bootargs console=ttyS0 root=/dev/mmcblk0p2 rootwait panic=10 ${extra} fatload mmc 0 0x43000000 script.bin fatload mmc 0 0x48000000 uImage bootm 0x48000000

Now you can generate boot.scr: mkimage -C none -A arm -T script -d boot.cmd boot.scr

Setting up the rootfs
Format the root partition: mkfs.ext3 /dev/mmcblkxp2 and mount it somewhere convenient.

Untar or copy your rootfs there, or debootstrap it if you are under a debian-like operating system.

See Debian how to debootstrap a debian-rootfs.