Bare Metal programming A13

Revision as of 05:51, 30 April 2013 by Scott (talk | contribs)

Programming with no OS, development tools and poor documentation isn't easy therefore this page is currently a work in progress. It will be updated as the author works out more about the process

Stand alone program running with uboot

The linux operating systems shown in the wiki runs on an SD card however it is booted using u-boot. U-boot sets up the CPU, memory and a few other things then starts Linux executing.
The following method outlines how to create a program that replaces linux but still relies on u-boot for setup.


- Computer for cross compiling the program and uboot, such as a linux computer
- SD card and SD card reader / writer
- A13 olinuxino board
- Serial adapter for the A13 olinuxino board (Only way to work with uboot as no screen is configured in uboot)

Setup computer for cross compiling and compiling uboot

You should make sure you have the tools for building the Linux Kernel and install them if you don’t have them. To install new software you should be with super user rights so do this type in a terminal.

$ sudo su

you will be asked for your password and then your prompt will change to # which means you are now the super user, all future commands should be run in this mode

First update apt-get links by typing

#apt-get update

Install the toolchain by typing the following.

# apt-get install gcc-4.6-arm-linux-gnueabi ncurses-dev uboot-mkimage build-essential git

with this line you make sure you have all tools necessary for the A13 kernel and uboot build:

  • GCC compiler used to compile the kernal
  • The kernel config menu
  • uboot make image which is required to allow the SD card to book into the linux image
  • Git which allows you to download from the github which holds source code for some of the system
  • Some other tools for building the kernel

after the installation you now have all tools to make your very own A13 kernel image

Building Uboot

The Allwinner community uboot is maintained by Henrik Nordström aka hno on #freenode irc channel.

First let’s make the directory where we will build the A13-OLinuXino Linux:

# mkdir olinuxino # cd olinuxino

Then let’s download the uboot sources from GitHub repository, note there are lot of branches but you have to use sunxi branch, the files are about 70 MB

# git clone -b sunxi

After the download you should have a new directory

# cd uboot-allwinner/

With the following command you can start the uboot build:

# make a13_olinuxino CROSS_COMPILE=arm-linux-gnueabi-

As you can see A13-OLinuXino already have support configuration in Allwinner community uboot

At the end of the process you can check if everything is OK by

# ls u-boot.bin spl/sunxi-spl.bin

If you got these two files everything is complete, well done so far

Format and setup the SD-card

First we have to make the correct card partitions, this is done with fdisk.

Plug SD card into your SD card reader and enter in the terminal

# ls /dev/sd

Then press two times <TAB> you will see a list of your sd devices like sda sdb sdc note that some of these devices may be your hard disk so make sure you know which one is your sd card before you proceed as you can damage your HDD if you choose the wrong sd-device. You can do this by unplugging your sd card reader and identify which "sd" devices remove from the list.

Once you know which device is your sdcard like sda use this text instead of the sdX name in the references below:

# fdisk -u=sectors /dev/sdX

then do these steps:

1. p

will list your partitions

if there are already partitions on your card do:

2. d 1

to delete them all

3. n p 1

create the first partition, starting from 2048

4. beginning 2048

then list the created partitions:

6. p

then write the partitions to the card

7. w

now we have to format the file system on the card:

the first partition should be vfat as this is FS which U-boot understands

# mkfs.vfat /dev/sdX1

Running hello world

The compilation performed in the previous step compiles uboot and it compiles a few stand alone programs as uboot calls them. One stand alone program is the hello world program

The hello world program code will be located in the directory previously created and in the following sub directories /examples/standalone/hello_world.c