Manual build howto

= For users = If you simply want to load an alternative (i.e. non-preinstalled) OS on a sunxi-based device, typically the fastest way to do that would be to get one of the ready-to-use OS images, write that image to an empty SD-card, then insert the card into your device, power it on, and it will boot your new OS directly from the SD-card.


 * Bootable OS images

= For developers =

The following documents the process to combine sunxi u-boot, Linux and other bits together to create a useful SD-card from scratch, 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.

There are two options to choose from, later on. One uses the sunxi-bsp, which is the recommended method for those who just want a working system fast. The other is the manual build of u-boot and the linux kernel, and the manual set-up of the SD card, which is recommended for anyone who needs to play with the kernel or u-boot.

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

= The SD-card = Depending on the rootfs size, you might want to use a 2GB or larger SD-card. SD-card partitioning and formatting will be taken care of later.

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

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

export PATH="$PATH":/home/user/folder/gcc-linaro-arm-linux-gnueabihf-*_linux/bin/

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

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

Replace arm-linux-gnueabihf- with arm-linux-gnueabi- if your are not using a hardfloat toolchain.

'''WARNING: Do not use the 4.8 gcc versions of the linaro toolchain, those seem to have issues building the kernel. Use an earlier version instead.'''

= The rootfs =

We can use many pre-existing root filesystems, pick one which suits your needs best.

linaro rootfs
Linaro offers a set of different root filesystems, but all the links are broken there. Linaro folk remove older ubuntu based images, and then cannot even maintain their own wiki. If they themselves cannot even deal with the stupidity of their own policy, why should we secondary users be able to do so? It's almost as if they do not want people to use their rootfs.

In any case, you can get the actual rootfs tarballs here. ALIP is a minimal LXDE based desktop environment which might me useful to most allwinner users.

= The easy option: sunxi-bsp =

git clone --recursive git://github.com/linux-sunxi/sunxi-bsp.git

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

= The flexible option: manual build and installation =

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

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.

Building script.bin
Descend into sunxi-tools and run the command 'make fex2bin'.

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: [dynamic] MAC = "000000000000" to, for example: [dynamic] MAC = "0123456789AB"

Note: If the [dynamic] section does not exist in your .fex file, you can just add it with your MAC address.

Now you can create the script.bin file: ../../../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: cd linux-sunxi 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: Once more change into the u-boot directory cd u-boot-sunxi and run: dd if=./spl/sunxi-spl.bin of=/dev/mmcblkX bs=1024 seek=8 dd if=./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/mmcblkXp1 and mount it somewhere (for instance at '/mnt') and change to the directory from where you checked out the git trees.

Now copy the kernel image over: cp ./linux-sunxi/arch/arm/boot/uImage /mnt 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 ./sunxi-boards/sys_config/a10/script.bin /mnt

Now change to directory '/mnt' and create a file 'boot.cmd' with the following content: setenv bootargs console=ttyS0,115200 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 (our Debian explains how).

As a last step you need to copy the kernel modules into the newly created rootfs. Change into the top level directory of the newly created rootfs and run: mkdir -p lib/modules rm -rf lib/modules/ cp -r /output/*. (Replace  with the directory you have built your kernel in as described above.)

= Other tutorials =