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. 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.

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. First of all make sure you have installed a toolchain.

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

./configure # to list all currently supported boards ./configure make hwpack-install SD_CARD=/dev/sdX ROOTFS=your_rootfs.tar.gz (Please refer to Bootable_SD_card to decide what rootfs you will use.)

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
Please refer to U-Boot

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

Then, get into the sunxi-board tree and find the fex file for your board. You also need to find out the MAC Address of Ethernet adapter, 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 .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 --track origin/sunxi-3.4

Now you need to configure your kernel. Depending on the SoC you have, you can select between sun4i_defconfig for A10, sun5i_defconfig for A13 and sun7i_defconfig for A20.

Then run

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

Afterwards build the kernel image and modules (you can add -jX where X is the number of cores of your computer to accelerate compilation).

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

The uImage file will be created in /arch/arm/boot directory. 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 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.

Please execute commands in Bootable_SD_card, Bootable_SD_card, Bootable_SD_card and Bootable_SD_card.

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

If you have cubieboard2 you might need to insert following line into your boot.cmd (see Cubieboard2 wheezy image):

setenv machid 0x00000f35

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

Setting up the rootfs
Please refer to Bootable_SD_card

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 =