Saturday, March 20, 2010

Booting AT91SAM9G20-EK Android

With an AT91SAM9G20 board running a standard Linux you can now continue on to getting Android booted.

First of all you need a kernel with android specific patches. You can either build it yourself as explained in another post or you can download a prebuilt uImage here:

Boot your module and transfer the uImage using TFTP and write it to flash as you did with the regular kernel.

Then set the bootargs variable:

setenv bootargs 'mem=64M console=ttyS0,115200 root=/dev/mtdblock1 rw rootfstype=jffs2 init=init video=vfb: vfb_enable=1 vinput.vinput_devices=1'
saveenv

Now boot Linux using the boot command.

With the Android kernel booted edit /etc/fstab and add the following line to mount the second nand flash partition using the yaffs2 file system:

/dev/mtdblock2 /android yaffs2 defaults 0 0

Then run

mkdir /android
mount /android
chmod 777 android

Now upload the root and system tarballs to /android using scp:

root.tar.bz2 root@192.168.1.2:/android
system.tar.bz2 root@192.168.1.2:/android

And untar them on target:

cd /android
tar -xvjf root.tar.bz2
tar -xvjf system.tar.bz2


Create a symbolic link for /system:

ln -s /android/system /system


Now run /android/runandroid to start it all. This will also start a VNC server and you can connect to it at port 5901. Using ubuntu and vncviewer:

vncviewer 192.168.1.2:5901


Android will take over your console which will conflict with the shell you are currently running so if you want to execute commands on the target use SSH instead.

This will start Android from inside Ångström. If you want to start Android directly without you can do this by asking the linux kernel to use the /android partition as root filesystem.

Reboot the module and stop the boot process in u-boot. Then change the bootcmd variable:

setenv bootargs 'mem=64M console=ttyS0,115200 root=/dev/mtdblock2 rw rootfstype=yaffs2 init=init video=vfb: vfb_enable=1 vinput.vinput_devices=1'
saveenv

Then boot linux with the boot command.

If you only want to run from inside Ångström you might want to disable the Android console so you can continue to use the Ångström terminal. Edit /android/root/init.rc and out-comment the console service like this:

## Daemon processes to be run by init.
##
#service console /system/bin/sh
# console


To make networking in Android work correctly you must first edit /android/system/etc/init.at91sam9g20.sh to setup the Ethernet IP address, gateway and netmask. Edit the following lines to match your settings:

ifconfig eth0 192.168.1.2 netmask 255.255.255.0 up
route add default gw 192.168.1.1 dev eth0

You should also edit /android/default.prop to setup your DNS server. Edit the following line to match your settings (leaving it at default will use an OpenDNS server):

net.dns1=208.67.222.222

Building AT91SAM9G20-EK Android

Android for AT91SAM9G20 is using repo just like regular Android and you should start by setting up your system and repo as described in "Get source" (http://source.android.com/download).

This guide assume that you use Linux as a host. The build has been tested on an Ubuntu 9.04.

Instead of using the manifest from android.kernel.org initialise your repo with the following:

repo init -u http://blue-kite.dk/repos/at91sam9g20-manifest.git/
repo sync

This will clone all the source code needed. Most of the source comes directly from android.kernel.org git repository and the AT91SAM9G20 specific stuff must be manually patched before compile.

repo start at91sam9g20 --all
at91sam9g20-android/patches/apply.sh

This will create a branch at91sam9g20 and apply the AT91SAM9G20 specific patches to the checkout. Note that the changes are not commited yet. If you would like to commit the changes use "repo status" see the modified files and go through each changed git repository and do a "git add ." and "git commit".

To build do:

make

this will take a long time.

When the build is finished you now have an Android kernel and a root filesystem.

The Android file system is split in two different parts: root and system. To create tarballs these do:

tar -cvjf root.tar.bz2 -C out/target/product/generic/root .
tar -cvjf system.tar.bz2 -C out/target/product/generic system



To build the linux kernel go to the common directory and execute:

make ARCH=arm at91sam9g20ek_defconfig
make ARCH=arm CROSS_COMPILE=$(pwd)/../prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-
mkimage -A arm -O linux -C none -T kernel -a 20008000 -e 20008000 -n linux-2.6 -d arch/arm/boot/Image uImage


Now you have a workin uImage containing a Linux kernel with the necessary Android specific patches.

If you havent the u-boot mkimage utility install it on Ubuntu with:

sudo apt-get install uboot-mkimage

Booting AT91SAM9G20-EK

Before attempting to boot Android on the AT91SAM9G20 Evaluation Kit you should start with getting a regular Linux to boot.

Start by going to http://www.at91.com/linux4sam/bin/view/Linux4SAM/ which will guide you through the steps of getting Linux to boot.

You should use the "Linux4SAM DataFlash demo - Memory map" described at http://www.at91.com/linux4sam/bin/view/Linux4SAM/GettingStarted. This means that you must use:

dataflash_at91sam9g20ek.bin
u-boot-1.3.4-exp.3-at91sam9g20ek-dataflash_cs1.bin
linux-2.6.30-at91-exp-at91sam9g20ek.bin
Angstrom-console-image-demo-glibc.rootfs.jffs2

When you have booted this configuration you are ready to get started with Android.

The Ångström distribution supports easy download and install of additional software through the ipkg package system - just like a normal PC distribution.

Use username root with no password to login to Ångström and change the password with:

passwd


Using vi, edit the eth0 section in /etc/network/interfaces to setup network proberly. E.g.

auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1

Also edit /etc/resolv.conf

nameserver 208.67.222.222

This will add an opendns nameserver. Then restart network and check that you can ping android.com

/etc/init.d/networking restart

When network is up and running you can use ipkg to download and install additional utilities:

ipkg update
ipkg install nano

Friday, March 19, 2010

Open Source Days 2010

Marts 6th I gave a presentation on Open Source Days 2010 at the IT university in Copenhagen.

The slideshow from the presentation can be downloaded here

My first Android port: Android for AT91SAM9G20

I wanted to learn more about Android internals and what better way than to try and boot it on a new microcontroller.

Since I had an AT91SAM9G20 evaluation kit I started working on that and booting Android was actually quite easy after I had gotten the hang of how Android works.

If you want to boot Android on an AT91SAM9G20 I have assembled a short guide to help you. I have divided it into 3 steps:
1) Booting AT91SAM9G20-EK
How to install software and boot the AT91SAM9G20 evaluation kit using binary images available at at91.com

2) Building AT91SAM9G20-EK Android
How to download the official Android code, patch the AT91SAM9G20 specific parts and finally build both kernel and file system

3) Booting AT91SAM9G20-EK Android
How to use the generated kernal and file systems to boot Android both on top of the generic at91 system and as a fully self-contained Android.

I hope this guide will help you in booting Android on your AT91SAM9G20. If you have any trouble getting it to work please feel free to drop a comment.