Build and Use Android on Phytec phyCORE-OMAP4430


Table of Contents

1. Overview of Android
2. Folder structures
3. Install Software on the host
3.1. Install third party software on the host
3.2. Install Phytec software on the host
4. Use Binary Versions of Android
4.1. Copy Boot Images from DVD to Host
4.2. Prepare barebox
4.2.1. Prepare tftp server
4.2.2. Configure barebox
4.2.3. Default settings
4.3. Boot via TFTP and NFS
4.3.1. Binaries for Boot with TFTP and NFS
4.3.2. Prepare NFS
4.3.3. Barebox
4.4. Boot from MMC in File System Boot Mode
4.4.1. Binaries for File System Boot Mode
4.4.2. Prepare SD-Card
4.4.3. barebox
4.5. Boot from NAND
4.5.1. Binaries for Booting from NAND
4.5.2. Prepare TFTP server
4.5.3. barebox
5. Build Android from Source
5.1. Build Android File System from Source Code
5.1.1. Install Mirror
5.1.2. Install Source
5.1.3. verify tag
5.1.4. Install Phytec Board Support Package
5.1.4.1. Add device pcm049
5.1.4.2. Copy Manifest Files
5.1.4.3. Adjust path to BSP in manifest files
5.1.4.4. Two Different Ways to Apply Patches to the Android Source Code
5.1.4.5. Use Git Bundles to Apply Patches to the Android Source Code
5.1.4.6. Use Patches Files to Apply Patches to the Android Source Code
5.1.5. Apply Patch for Mouse
5.1.6. Build Android File System
5.1.7. Manifest
5.1.7.1. Create Manifest
5.1.7.2. Move the local_manifest.xml file
5.1.7.3. Select Manifest
5.2. Build Android Kernel from Source Code
5.2.1. Download Source Code
5.2.2. Two Different Ways to Apply Patches to the Android Kernel Source Code
5.2.3. Use Git Bundles to Apply Patches to the Android Kernel Source Code
5.2.4. Use Patch Files to Apply Patches to the Android Kernel Source Code
5.2.5. Build Android Kernel
5.2.6. Install kernel modules
5.3. Boot with TFTP and NFS
5.3.1. Create RootFS for NFS
5.3.2. Create RootFS Archive for NFS
5.3.3. Copy Kernel for NFS
5.3.4. Prepare TFTP
5.3.5. Prepare NFS
5.3.6. Barebox
5.4. Boot from NAND
5.4.1. Create RootFS for NAND
5.4.2. Create JFFS2 File System
5.4.3. Prepare Kernel
5.4.4. Prepare TFTP
5.4.5. barebox
5.5. Boot from MMC in File System Boot Mode
5.5.1. Create RootFS for MMC
5.5.2. Create RootFS Archive
5.5.3. Prepare Kernel
5.5.4. Bootloader
5.5.5. Prepare SD-Card
5.5.6. barebox
6. Use Android
6.1. Setup Hardware
6.2. Booting for the first Time
6.3. Disable sleep mode
6.3.1. Use the GUI to disable sleep mode
6.3.2. Use the console to disable sleep mode
6.4. Configure Network
6.5. Fixed Problems
6.6. Known Problems
7. Develop Applications for Android
7.1. Build Application
7.2. Test Application

Author: Jan Kobler, Kobler Systems GmbH, email: eng1@koblersystems.de

1. Overview of Android

For a working Android device you need a bootloader, an Android Kernel and an Android File System.

For the CPU OMAP4430 the bootloader is split into two applications. The internal bootcode of OMAP4430 loads and starts at first the bootloader MLO. Then MLO loads and starts the second bootloader barebox.bin.

Bootloader:

  • MLO

  • barebox.bin

The bootloader barebox.bin loads and starts the Android kernel. The kernel mounts the Android File System and starts the first application init.

The Android Kernel is provided as uImage or as part of boot.img:

  • uImage

  • boot.img

The boot.img consists of the the Android Kernel zImage and a ramdisk.

The Android File System is split into three parts:

  • root

  • system

  • data

root contains only the files which are needed to initialize Android and to provide a debug environment. system contains all the other applications and configuration files. data contains user data. How to build them is described in Build_Android_File_System.

How these parts are deployed on the device, depends on how the device is booted and which storage devices are used.

The root part can be used as ramdisk for the Android kernel. The system and data parts can be put in different partitions on a SD-Card or into Flash.

All three parts can also be copied into one file system, which can be mounted as a root file system by the Android kernel. This is described in Create_RootFS_for_NFS.

2. Folder structures

These folders are used:

Device name of MMC or SD-card on host: ${MY_MMC}

Mount point of Phytec software: ${MY_DVD}

Folder for Android software: ${MY_ANDROID}

Folder for source code of Android File System: ${MY_PLATFORM}

Folder for source code of Android Kernel: ${MY_KERNEL}

Folder for mirrors of git repositories: ${MY_MIRROR}

Folder Structure on the DVD:

${MY_DVD}/images/boot_mmc_file images and file system for booting from MMC in File System mode.

${MY_DVD}/images/boot_tftp_nfs images and file system for booting via TFTP and NFS.

${MY_DVD}/images/barebox config files for barebox.

${MY_DVD}/git-phytec git repositories of Phytec for Android.

${MY_DVD}/patches patch files

Folder Structure on the host:

${MY_PLATFORM}/out/host/linux-x86/bin host applications, created when the Android File System is built.

${MY_ANDROID}/git-phytec git repositories of Phytec for Android.

/tftpboot folder of the TFTP server.

${MY_ANDROID}/modules/v02 folder for the kernel modules

Folder Structure on the host for prebuilt files from DVD:

${MY_ANDROID}/images/v01/boot_tftp_nfs images for booting via TFTP and NFS.

${MY_ANDROID}/images/v01/boot_mmc_file images for booting from MMC in File System mode.

${MY_ANDROID}/rootfs/test01 root file system which is exported by the NFS server.

${MY_ANDROID}/images/v01/barebox config files for barebox.

Folder Structure on the host for images, which will be built from source:

${MY_ANDROID}/images/v02/boot_tftp_nfs images for booting via TFTP and NFS.

${MY_ANDROID}/images/v02/boot_mmc_file images for booting from MMC in File System mode.

${MY_ANDROID}/rootfs/test02 root file system which is exported by the NFS server.

${MY_ANDROID}/images/v02/barebox config files for barebox.

Define environment variables:

export MY_MMC=/dev/sdc
export MY_DVD=/mnt/cdrom
export MY_ANDROID=/my_android
export MY_PLATFORM=/my_android/platform
export MY_KERNEL=/my_android/kernel/common
export MY_MIRROR=/my_mirror

3. Install Software on the host

This section describes how to install Phytec and third party software on the host.

3.1. Install third party software on the host

For a Gentoo host you need the following software:

emerge -av =dev-lang/python-2*
emerge -av sun-jdk
emerge -av git
emerge -av u-boot-tools

3.2. Install Phytec software on the host

Phytec software for Android for phyCORE-OMAP4430 is shipped on a DVD or as archive. Make it available in the folder ${MY_DVD}.

Note: The software is currently shipped only as an archive.

If you have received the archive, please extract it into a folder.

export MY_DVD="/my_dvd"
mkdir -p ${MY_DVD}
tar xjf android-pcm049-120215-1.tar.bz2 -C ${MY_DVD}

If you have received the DVD, please mount it.

export MY_DVD="/mnt/cdrom"
mount ${MY_DVD}

Now the Phytec software is available in the folder ${MY_DVD}.

4. Use Binary Versions of Android

This chapter shows how to download the binary images of the bootloader, Android kernel and the Android file system and boot the device in different ways.

4.1. Copy Boot Images from DVD to Host

mkdir -p ${MY_ANDROID}/images/v01
cp -dRv ${MY_DVD}/images/* ${MY_ANDROID}/images/v01

4.2. Prepare barebox

There are new config and boot files, which allow to select kernel_loc=mmc and rootfs_loc=mmc. Then the kernel or the rootfs is loaded from an SD-Card. Also when os=android is set, Android specific bootargs and nfsroot are used.

4.2.1. Prepare tftp server

Copy the new config and boot file into the folder of the tftp server.

cp ${MY_ANDROID}/images/v01/barebox/barebox-env-config /tftpboot
cp ${MY_ANDROID}/images/v01/barebox/barebox-env-bin-boot /tftpboot

4.2.2. Configure barebox

Save a copy of the current files

cp /env/bin/boot /env/bin/boot_old
cp /env/config /env/bin/config_old

Download new configuration and boot file from the tftp server

tftpboot barebox-env-bin-boot /env/bin/boot
tftpboot barebox-env-config /env/config

These files have been tested with barebox 2011.07.0 (Jul 22 2011 - 12:40:26). If you have a different version you should compare the old and new files.

Edit the new config file and set the networking parameters eth0.* or ip

edit /env/config

Save the file with CTRL-D or close the file without saving by pressing CTRL-C.

Save changes

saveenv

4.2.3. Default settings

When you want to return to the default settings, erase all your changes.

unprotect /dev/nand0.bareboxenv.bb
gpmc_nand0.eccmode=${bareboxenv_eccmode}
erase /dev/nand0.bareboxenv.bb

4.3. Boot via TFTP and NFS

4.3.1. Binaries for Boot with TFTP and NFS

Extract Android file system

mkdir -p ${MY_ANDROID}/rootfs/test01
cd ${MY_ANDROID}/rootfs/test01
sudo tar xjf ${MY_ANDROID}/images/v01/boot_tftp_nfs/root-pcm049-android.tar.bz2

Copy Android Linux kernel into the tftp server folder

mkdir -p /tftpboot
cp ${MY_ANDROID}/images/v01/boot_tftp_nfs/uImage-pcm049 /tftpboot

4.3.2. Prepare NFS

sudo nano /etc/exports

New or changed content of file exports:

/my_android/rootfs/test01 192.168.1.255/24(rw,no_root_squash,async,subtree_check)
sudo exportfs -r

4.3.3. Barebox

Test booting from TFTP and NFS

boot tftp

Configure barebox to boot TFTP and NFS by default

edit /env/config

New or changed content of file /env/config:

kernel_loc=tftp
rootfs_loc=net

	if [ x$os = xandroid ]; then
		nfsroot="${nfsroot}/my_android/rootfs/test01"

Save settings and boot

saveenv
boot

4.4. Boot from MMC in File System Boot Mode

4.4.1. Binaries for File System Boot Mode

In the folder ${MY_ANDROID}/images/v01/boot_mmc_file there are the bootloaders, the kernel image and the Android File System.

ls -1 ${MY_ANDROID}/images/v01/boot_mmc_file

Output:

barebox.bin
MLO
root-pcm049-android.tar.bz2
uImage-pcm049

4.4.2. Prepare SD-Card

Install the bootloader and the kernel in the FAT partition. Install the Android file system in ext3 partition.

Useful links:

http://omappedia.org/wiki/Android_Build_SD_Configuration

http://omappedia.org/wiki/SD_Configuration

Insert a MMC or SD-Card in your card reader, which appears as device e.g. /dev/sdc on your host. Define an environment variable for this device.

export MY_MMC=/dev/sdc

Delete the boot sector on this device. The reason is described in the man pages of fsck(8).

Warning: Don't delete the boot sector on your root device!!!

dd if=/dev/zero of=${MY_MMC} bs=1024 count=1024

Display information about the device:

fdisk -l ${MY_MMC} 

As an example an 4GByte SD-Card is used. Output:

Platte /dev/sdc: 4014 MByte, 4014997504 Byte
124 Köpfe, 62 Sektoren/Spur, 1020 Zylinder
Einheiten = Zylinder von 7688 x 512 = 3936256 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Festplatte /dev/sdc enthält keine gültige Partitionstabelle

Size of 1 cylinder is: 124 Head/Cylinder * 62 Sector/Head * 512 Byte/Sector = 7688 Sector/Cylinder * 512 Byte/Sector = 3936256 Byte/Cylinder

Create these partitions:

60MB boot File System: vfat Typ: 0xc

2G rootfs File System: ext3 Typ: 0x83

2G media File System: vfat Typ: 0xc

Compute the number of cylinders for the first partition:

60*1024*1024 Byte / (3936256 Byte/Cylinder) = 15.98 Cylinder

For 60 MByte 16 Cylinders are needed.

fdisk ${MY_MMC} 

Press m to show the help text of fdisk. You will need the following commands:

Output:

Command action
   a   toggle a bootable flag
   l   list known partition types
   m   print this menu
   n   add a new partition
   p   print the partition table
   q   quit without saving changes
   t   change a partition's system id
   u   change display/entry units
   w   write table to disk and exit

Press p to print the partition table.

Press u to change units to cylinders.

Press n and create the first partition. Set the size to about 60MByte.

Press n and create the second partition. Set the size to about 2GByte.

Press t and set the system id of the first partition to 0xc.

Press t and set the system id of the second partition to 0x83.

Press a and set the boot flag of the first partition.

Press p to print the partition table.

Press w to write the new partion table to the device. Output:

Platte /dev/sdc: 4014 MByte, 4014997504 Byte
124 Köpfe, 62 Sektoren/Spur, 1020 Zylinder
Einheiten = Zylinder von 7688 x 512 = 3936256 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x965295c0

   Gerät  boot.     Anfang        Ende     Blöcke   Id  System
/dev/sdc1   *         1          17       65317    c  W95 FAT32 (LBA)
/dev/sdc2            18         528     1964284   83  Linux
/dev/sdc3             529        1020     1891248    c  W95 FAT32 (LBA)

Important: If the boot flag of the first partition is not set, the board will not boot from the SD-Card!

Format the first partition with a FAT file system.

mkfs.vfat -n "boot" ${MY_MMC}1

Format the second partition with an ext3 file system.

mke2fs -j -L "rootfs" ${MY_MMC}2

Format the third partition with a FAT file system.

mkfs.vfat -n "sdcard" ${MY_MMC}3

Create the mount points, if they don't exist already.

mkdir -p /mnt/mmc1
mkdir -p /mnt/mmc2

Mount the partitions

mount ${MY_MMC}1 /mnt/mmc1
mount ${MY_MMC}2 /mnt/mmc2

Install the bootloader and the kernel image

cp ${MY_ANDROID}/images/v01/boot_mmc_file/MLO /mnt/mmc1
cp ${MY_ANDROID}/images/v01/boot_mmc_file/barebox.bin /mnt/mmc1
cp ${MY_ANDROID}/images/v01/boot_mmc_file/uImage-pcm049 /mnt/mmc1

Extract Android file system

cd /mnt/mmc2
sudo tar xjf ${MY_ANDROID}/images/v01/boot_mmc_file/root-pcm049-android.tar.bz2

Unmount the SD-Card

umount ${MY_MMC}1
umount ${MY_MMC}2

4.4.3. barebox

Insert the SD-Card into slot X11. Change the boot configuration: Switch S1 all off, S2-2,3,5 on, others off.

Test booting from SD-Card

boot mmc

Configure barebox to boot from SD-card by default

edit /env/config

New or changed content of file /env/config:

kernel_loc=mmc
rootfs_loc=mmc

Save settings and boot

saveenv
boot

4.5. Boot from NAND

4.5.1. Binaries for Booting from NAND

In the folder ${MY_ANDROID}/images/v01/boot_nand there is the kernel image and the Android File System.

ls -1 ${MY_ANDROID}/images/v01/boot_nand

Output:

root-pcm049-android.jffs2
uImage-pcm049

An already working bootloader in NAND is required.

4.5.2. Prepare TFTP server

Copy Android Linux kernel and the Android File System into the tftp server folder

mkdir -p  /tftpboot
cp -${MY_DVD}/images/boot_nand/uImage-pcm049 /tftpboot
cp -${MY_DVD}/images/boot_nand/root-pcm049-android.jffs2 /tftpboot

4.5.3. barebox

Write the Android kernel into NAND

update -t kernel -d nand -m tftp

Write the Android file system into NAND

update -t rootfs -d nand -m tftp -f root-pcm049-android.jffs2

Change the boot configuration: Switch S1 all off, S2 all off

Test booting from NAND

boot nand

Configure barebox to boot from NAND by default

edit /env/config

New or changed content of file /env/config:

kernel_loc=nand
rootfs_loc=nand

Save settings and boot

saveenv
boot

5. Build Android from Source

5.1. Build Android File System from Source Code

Install the Android tools and repositories on your computer. Download the patches for the phyCORE-OMAP4430

5.1.1. Install Mirror

If you only want to install the Android source code once, then you don't need a mirror and you can skip this section. If you want to install the Android source code serveral times, then you should install a mirror as described in this section.

The current size of all git repositories together, which are downloaded and installed by the repo tool, is about 3.8GB. By installing at first a mirror of these git repositories on a local server, you avoid downloading these data from a remote sever again, when you use repo in an empty folder.

This manual is based on http://source.android.com/source/download.html and the output of repo help init.

Install repo, the version control of Android, which is further explained in http://source.android.com/source/version-control.html.

mkdir -p ${MY_MIRROR}/bin
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ${MY_MIRROR}/bin/repo
chmod a+x ${MY_MIRROR}/bin/repo

Define the environment for repo. repo is in ${MY_MIRROR}/bin.

nano ${MY_MIRROR}/setup-env

New or changed content of file setup-env:

export PATH=/my_mirror/bin:$PATH
export PS1="(mirror) $PS1"

Setup the environment now

source ${MY_MIRROR}/setup-env

Init repo

mkdir -p ${MY_MIRROR}/platform
cd ${MY_MIRROR}/platform
repo init -u https://android.googlesource.com/platform/manifest.git --mirror -b gingerbread

Note: I don't know, if the argument -b gingerbread is needed for creating a mirror, but I have used it during my tests.

The repository https://android.googlesource.com/platform/manifest.git is cloned in ${MY_MIRROR}/platform/.repo/manifests.git. The files are checked out into ${MY_MIRROR}/platform/.repo/manifests.

Download the git repositories

repo sync

Now the mirror for the Android source code can be used.

5.1.2. Install Source

This manual is based on http://source.android.com/source/download.html

Install repo, the version control of Android, which is further explained in http://source.android.com/source/version-control.html.

mkdir -p ${MY_ANDROID}/bin
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ${MY_ANDROID}/bin/repo
chmod a+x ${MY_ANDROID}/bin/repo

Define the environment for building Android. repo is in ${MY_ANDROID}/bin. The prebuilt cross-compiler is in ${MY_PLATFORM}/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3.

nano ${MY_ANDROID}/setup-env

New or changed content of file setup-env:

export PATH=/my_android/platform/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH
export PATH=/my_android/bin:$PATH
export PS1="(repo) $PS1"

Setup the environment now

source ${MY_ANDROID}/setup-env

Codenames, Tags and Build Numbers: http://source.android.com/source/build-numbers.html

Init repo. If you don't use a local mirror, leave the argument --reference ${MY_MIRROR}/platform away.

mkdir -p ${MY_PLATFORM}
cd ${MY_PLATFORM}
repo init -u https://android.googlesource.com/platform/manifest.git -b gingerbread --reference ${MY_MIRROR}/platform

Enter your name and email address.

The repository https://android.googlesource.com/platform/manifest.git is cloned in ${MY_PLATFORM}/.repo/manifests.git. The files are checked out into ${MY_PLATFORM}/.repo/manifests.

Check which branches i.e manifests for which android version are available:

git --git-dir=${MY_PLATFORM}/.repo/manifests.git branch -av

Show all the commands recognized by repo

repo help --all

Sync all projects. All source files are checked out. Don't overwrite changed files.

repo sync

Later when you have done some changes you can return to the initial state. Detach projects back to manifest revision. Changed files will be overwritten or removed.

repo sync -d

5.1.3. verify tag

gpg --import

Copy and paste the key(s) below, then enter EOF (Ctrl-D) to end the input and process the keys.Output:

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

mQGiBEnnWD4RBACt9/h4v9xnnGDou13y3dvOx6/t43LPPIxeJ8eX9WB+8LLuROSV
lFhpHawsVAcFlmi7f7jdSRF+OvtZL9ShPKdLfwBJMNkU66/TZmPewS4m782ndtw7
8tR1cXb197Ob8kOfQB3A9yk2XZ4ei4ZC3i6wVdqHLRxABdncwu5hOF9KXwCgkxMD
u4PVgChaAJzTYJ1EG+UYBIUEAJmfearb0qRAN7dEoff0FeXsEaUA6U90sEoVks0Z
wNj96SA8BL+a1OoEUUfpMhiHyLuQSftxisJxTh+2QclzDviDyaTrkANjdYY7p2cq
/HMdOY7LJlHaqtXmZxXjjtw5Uc2QG8UY8aziU3IE9nTjSwCXeJnuyvoizl9/I1S5
jU5SA/9WwIps4SC84ielIXiGWEqq6i6/sk4I9q1YemZF2XVVKnmI1F4iCMtNKsR4
MGSa1gA8s4iQbsKNWPgp7M3a51JCVCu6l/8zTpA+uUGapw4tWCp4o0dpIvDPBEa9
b/aF/ygcR8mh5hgUfpF9IpXdknOsbKCvM9lSSfRciETykZc4wrRCVGhlIEFuZHJv
aWQgT3BlbiBTb3VyY2UgUHJvamVjdCA8aW5pdGlhbC1jb250cmlidXRpb25AYW5k
cm9pZC5jb20+iGAEExECACAFAknnWD4CGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIX
gAAKCRDorT+BmrEOeNr+AJ42Xy6tEW7r3KzrJxnRX8mij9z8tgCdFfQYiHpYngkI
2t09Ed+9Bm4gmEO5Ag0ESedYRBAIAKVW1JcMBWvV/0Bo9WiByJ9WJ5swMN36/vAl
QN4mWRhfzDOk/Rosdb0csAO/l8Kz0gKQPOfObtyYjvI8JMC3rmi+LIvSUT9806Up
hisyEmmHv6U8gUb/xHLIanXGxwhYzjgeuAXVCsv+EvoPIHbY4L/KvP5x+oCJIDbk
C2b1TvVk9PryzmE4BPIQL/NtgR1oLWm/uWR9zRUFtBnE411aMAN3qnAHBBMZzKMX
LWBGWE0znfRrnczI5p49i2YZJAjyX1P2WzmScK49CV82dzLo71MnrF6fj+Udtb5+
OgTg7Cow+8PRaTkJEW5Y2JIZpnRUq0CYxAmHYX79EMKHDSThf/8AAwUIAJPWsB/M
pK+KMs/s3r6nJrnYLTfdZhtmQXimpoDMJg1zxmL8UfNUKiQZ6esoAWtDgpqt7Y7s
KZ8laHRARonte394hidZzM5nb6hQvpPjt2OlPRsyqVxw4c/KsjADtAuKW9/d8phb
N8bTyOJo856qg4oOEzKG9eeF7oaZTYBy33BTL0408sEBxiMior6b8LrZrAhkqDjA
vUXRwm/fFKgpsOysxC6xi553CxBUCH2omNV6Ka1LNMwzSp9ILz8jEGqmUtkBszwo
G1S8fXgE0Lq3cdDM/GJ4QXP/p6LiwNF99faDMTV3+2SAOGvytOX6KjKVzKOSsfJQ
hN0DlsIw8hqJc0WISQQYEQIACQUCSedYRAIbDAAKCRDorT+BmrEOeCUOAJ9qmR0l
EXzeoxcdoafxqf6gZlJZlACgkWF7wi2YLW3Oa+jv2QSTlrx4KLM=
=Wi5D
-----END PGP PUBLIC KEY BLOCK-----

After importing the keys, you can verify any tag with

git tag -v tagname

5.1.4. Install Phytec Board Support Package

At first the device pcm049 is added to the Android source code. Then some patches are applied to the existing Android source code.

5.1.4.1. Add device pcm049

Clone a git bundle from the DVD into your Android folder. This repository contains the BSP for pcm049 for the Android File System.

mkdir -p ${MY_ANDROID}/git-phytec/platform/device/phytec
git clone --bare ${MY_DVD}/git-phytec/platform/device/phytec/pcm049.bundle ${MY_ANDROID}/git-phytec/platform/device/phytec/pcm049.git 

Make the repository known to repo, by adding a local_manifest.xml file.

nano ${MY_PLATFORM}/.repo/local_manifest.xml

New or changed content of file local_manifest.xml:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
    <remote  name="phytec"           
             fetch="file:///my_android/git-phytec/" />

    
<project path="device/phytec/pcm049" name="platform/device/phytec/pcm049" revision="gingerbread" remote="phytec" />
</manifest>

The usage of manifests is further described in Manifest.

Sync with repo to the branch gingerbread

repo init -b gingerbread
repo sync -d

Now the files for the device pcm049, should be installed in the folder ${MY_PLATFORM}/device/phytec.

5.1.4.2. Copy Manifest Files

Copy manifest files, which are needed for applying patches.

mkdir -p ${MY_ANDROID}/manifests
cp ${MY_DVD}/manifests/gingerbread_default_120215-1.xml ${MY_ANDROID}/manifests
cp ${MY_DVD}/manifests/gingerbread_pcm049_120215-1.xml ${MY_ANDROID}/manifests
5.1.4.3. Adjust path to BSP in manifest files

The definition New or changed content of file manifest.xml:

    <remote  name="phytec"           
             fetch="file:///my_android/git-phytec/" />

is also used in two other manifest files. Please open these files and adjust the path if necessary.

nano ${MY_ANDROID}/manifests/gingerbread_pcm049_120215-1.xml
nano ${MY_ANDROID}/manifests/gingerbread_default_120215-1.xml
5.1.4.4. Two Different Ways to Apply Patches to the Android Source Code

There are two different ways to apply the patches. You can pull the commits directly from a git repository, which is shipped as a git bundle, or you can use patch files to apply the patches to the source code.

The first way is usefull, when you want to create a clone of the repository, which has been used to develop the BSP.

The second way is usefull, when you want to apply the patches to some other source code.

In order to ensure that the same source code is installed, which has been tested, it is recommended to use the first way, i.e. git bundle. But both ways result in the same source code.

5.1.4.5. Use Git Bundles to Apply Patches to the Android Source Code

If you want to use patch files instead of git bundles, you can skip this section.

Add patches to project frameworks/base

cd ${MY_ANDROID}/platform/frameworks/base
git remote add phytec ${MY_DVD}/git-phytec/platform/frameworks/base.bundle
git checkout -b pcm049_touchscreen_BGRA_8888 15db39303cb46ef65a483627284d02dde0aba2b9
git pull phytec pcm049_touchscreen_BGRA_8888

Add patches to project hardware/libhardware

cd ${MY_ANDROID}/platform/hardware/libhardware
git remote add phytec ${MY_DVD}/git-phytec/platform/hardware/libhardware.bundle
git checkout -b pixel_format_BGR 33fddf0ca9801080472116654264be63a21b6e80
git pull phytec pixel_format_BGR

Add patches to project system/core

cd ${MY_ANDROID}/platform/system/core
git remote add phytec ${MY_DVD}/git-phytec/platform/system/core.bundle
git checkout -b pcm049-patch a51b3ccfeb7c675005e3eeacb2dff38c0e100883
git pull phytec pcm049-patch

Important: Before you select a manifest, you have to check if local_manifest.xml needs some adjustments as described in Move_the_local_manifest_xml_file.

Select the manifest

repo init --manifest-name=${MY_ANDROID}/manifests/gingerbread_pcm049_120215-1.xml

The above command creates the link manifest.xml. Check it. If it is invalid, create it manually:

ls -l ${MY_ANDROID}/platform/.repo/manifest.xml
ln -fs ${MY_ANDROID}/manifests/gingerbread_pcm049_120215-1.xml ${MY_ANDROID}/platform/.repo/manifest.xml

Perform a local sync.

cd ${MY_PLATFORM}
repo sync -l -d

Now the source code is the same, as it has been used for testing.

5.1.4.6. Use Patches Files to Apply Patches to the Android Source Code

If you have already used the git bundles, to change the source code, you can skip this section.

Important: Before you select a manifest, you have to check if local_manifest.xml needs some adjustments as described in Move_the_local_manifest_xml_file.

Select the manifest

repo init --manifest-name=${MY_ANDROID}/manifests/gingerbread_default_120215-1.xml

The above command creates the link manifest.xml. Check it. If it is invalid, create it manually:

ls -l ${MY_ANDROID}/platform/.repo/manifest.xml
ln -fs ${MY_ANDROID}/manifests/gingerbread_default_120215-1.xml ${MY_ANDROID}/platform/.repo/manifest.xml

Perform a local sync.

cd ${MY_PLATFORM}
repo sync -l -d

Now the source code is the same, as it has been before applying the patches.

Add patches to project frameworks/base

cd ${MY_ANDROID}/platform/frameworks/base
git checkout -b pcm049_touchscreen_BGRA_8888
git am ${MY_DVD}/patches/platform/frameworks/base/*

Add patches to project hardware/libhardware

cd ${MY_ANDROID}/platform/hardware/libhardware
git checkout -b pixel_format_BGR
git am ${MY_DVD}/patches/platform/hardware/libhardware/*

Add patches to project system/core

cd ${MY_ANDROID}/platform/system/core
git checkout -b pcm049-patch
git am ${MY_DVD}/patches/platform/system/core/*

Now the source code is the same, as it has been used for testing.

5.1.5. Apply Patch for Mouse

There is a patch, which allows you to use an USB mouse to control the GUI. This patch is optional. Without this patch you can still control the GUI with an USB keyboard and a touchscreen.

If you want to connect an USB mouse, you need to apply some patches from the project http://gitorious.org/rowboat/frameworks-base. This is based on the description in http://www.omappedia.com/wiki/PandaBoard_GB_Notes#Download_Android_source.

cd ${MY_PLATFORM}/frameworks/base
git branch
git checkout -b pcm049_01_keyboard
git remote add rowboat git://gitorious.org/rowboat/frameworks-base.git
git fetch rowboat
git cherry-pick 17128d44ab04c5b7cb2911e8b1c9f837aa9b36a5
git cherry-pick 174cb50436065dc092114d69fb40d5a7712e3ca0

5.1.6. Build Android File System

Before calling make you have to setup the environment each time.

cd ${MY_PLATFORM}/
source build/envsetup.sh

The shell function lunch is defined. Use it to select the target pcm049.

lunch

Select full_pcm049-eng

Output:

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.3.7
TARGET_PRODUCT=full_pcm049
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=GINGERBREAD
============================================

For a complete rebuild you can remove the build directory ${MY_PLATFORM}/out, if it already exists.

make clean

Build the tools and the Android File System.

make -j4

All files are built and created in ${MY_PLATFORM}/out. The three parts of the Android File System are created in ${MY_PLATFORM}/out/target/product/pcm049.

  • root: ${MY_PLATFORM}/out/target/product/pcm049/root

  • system: ${MY_PLATFORM}/out/target/product/pcm049/system

  • data: ${MY_PLATFORM}/out/target/product/pcm049/data

The created images are

  • root: ${MY_PLATFORM}/out/target/product/pcm049/ramdisk.img

  • system: ${MY_PLATFORM}/out/target/product/pcm049/system.img

  • data: ${MY_PLATFORM}/out/target/product/pcm049/userdata.img

5.1.7. Manifest

The concept of manifests is explained and important commands are shown. More information about manifest files and local_manifest.xml are provided by

repo help manifest
repo help init
5.1.7.1. Create Manifest

You can create a manifest, which describes the current state:

repo manifest -o ${MY_ANDROID}/manifests/pcm049_01.xml -r
5.1.7.2. Move the local_manifest.xml file

When a manifest file is created by repo manifest it contains also the definitions of the current local_manifest.xml file. Before the new manifest file can be used, the no longer needed definitions from the local_manifest.xml file have to be removed. Otherwise you will get an error message. Here the whole local_manifest.xml file is moved to a folder, which contains user specific manifests.

mv ${MY_ANDROID}/platform/.repo/local_manifest.xml ${MY_ANDROID}/manifests
5.1.7.3. Select Manifest

You can return to a saved state by selecting a manifest in the folder .repo/manifests or your own manifest file

repo init --manifest-name=${MY_ANDROID}/manifests/pcm049_01.xml

The above command creates the link manifest.xml. Check it. If it is invalid, create it manually:

ls -l ${MY_ANDROID}/platform/.repo/manifest.xml
ln -fs ${MY_ANDROID}/manifests/pcm049_01.xml ${MY_ANDROID}/platform/.repo/manifest.xml

Detach projects back to the selected manifest revision. Changed files will be overwritten or removed.

repo sync -d

5.2. Build Android Kernel from Source Code

5.2.1. Download Source Code

Clone the git repository for the Android kernel.

Create the git repository in kernel/common

git clone https://android.googlesource.com/kernel/common.git ${MY_ANDROID}/kernel/common

5.2.2. Two Different Ways to Apply Patches to the Android Kernel Source Code

There are two different ways to apply the patches. You can pull the commits directly from a git repository, which is shipped as a git bundle, or you can use patch files to apply the patches to the source code.

The first way is usefull, when you want to create a clone of the repository, which has been used to develop the BSP.

The second way is usefull, when you want to apply the patches to some other source code.

In order to ensure that the same source code is installed, which has been tested, it is recommended to use the first way, i.e. git bundle. But both ways result in the same source code.

5.2.3. Use Git Bundles to Apply Patches to the Android Kernel Source Code

If you want to use patch files instead of git bundles, you can skip this section.

Add patches to git repository in kernel/common

cd ${MY_ANDROID}/kernel/common
git remote add phytec ${MY_DVD}/git-phytec/kernel/common.bundle
git checkout -b pcm049-android-3.0 4e111751cfcb75f26d2725eab934b6eb91a3d115
git pull phytec pcm049-android-3.0

Now the source code is the same, as it has been used for testing.

5.2.4. Use Patch Files to Apply Patches to the Android Kernel Source Code

If you have already used the git bundles, to change the source code, you can skip this section.

Add patches to git repository in kernel/common

cd ${MY_ANDROID}/kernel/common
git checkout -b pcm049-android-3.0 4e111751cfcb75f26d2725eab934b6eb91a3d115
git am ${MY_DVD}/patches/kernel/common/*

Now the source code is the same, as it has been used for testing.

5.2.5. Build Android Kernel

Build the kernel

cd ${MY_KERNEL}
make ARCH=arm CROSS_COMPILE=arm-eabi- clean
make ARCH=arm CROSS_COMPILE=arm-eabi- pcm049_android_defconfig
make ARCH=arm CROSS_COMPILE=arm-eabi- menuconfig
make ARCH=arm CROSS_COMPILE=arm-eabi- all

Create the kernel as uImage, which can be loaded by the bootloader barebox.

make ARCH=arm CROSS_COMPILE=arm-eabi- uImage
ls -l arch/arm/boot/uImage

5.2.6. Install kernel modules

Install kernel modules into ${MY_ANDROID}/modules/v02

cd ${MY_KERNEL}
make ARCH=arm CROSS_COMPILE=arm-eabi- INSTALL_MOD_PATH="${MY_ANDROID}/modules/v02" modules_install

Copy modules into the Android File System.

mkdir -p ${MY_ANDROID}/rootfs/test02
cd ${MY_ANDROID}/modules/v02
cp -va --parents lib/firmware ${MY_ANDROID}/rootfs/test02
cp -va --parents lib/modules/3.0.0-k21-g4f7e4c6 ${MY_ANDROID}/rootfs/test02

5.3. Boot with TFTP and NFS

For test purposes load the kernel via TFTP and mount the file system via NFS. This allows you to quickly test a new kernel or file system. The bootloader in NAND or on an MMC card is configured to load the kernel via TFTP.

5.3.1. Create RootFS for NFS

Create root file system, which can be mounted via NFS.

mkdir -p ${MY_ANDROID}/rootfs/test02
cd ${MY_PLATFORM}/out/target/product/pcm049
cp -a root/* ${MY_ANDROID}/rootfs/test02
cp -a data ${MY_ANDROID}/rootfs/test02
cp -a system ${MY_ANDROID}/rootfs/test02
sudo chown -R 1000:1000 ${MY_ANDROID}/rootfs/test02

Disable remounting the file system. The patch init_nfs.patch is part of the BSP of pcm049.

cd  ${MY_ANDROID}/rootfs/test02
patch <init_nfs.patch

5.3.2. Create RootFS Archive for NFS

Create an archive

mkdir -p ${MY_ANDROID}/images/v02/boot_tftp_nfs
sudo tar -cjf ${MY_ANDROID}/images/v02/boot_tftp_nfs/root-pcm049-android.tar.bz2 -C ${MY_ANDROID}/rootfs/test02 .

5.3.3. Copy Kernel for NFS

Copy the kernel image into ${MY_ANDROID}/images/v02/boot_tftp_nfs/

mkdir -p ${MY_ANDROID}/images/v02/boot_tftp_nfs
cp ${MY_KERNEL}/arch/arm/boot/uImage ${MY_ANDROID}/images/v02/boot_tftp_nfs/uImage-pcm049

5.3.4. Prepare TFTP

Copy Android Linux kernel into the tftp server folder

mkdir -p /tftpboot
cp ${MY_ANDROID}/images/v02/boot_tftp_nfs/uImage-pcm049 /tftpboot

5.3.5. Prepare NFS

sudo nano /etc/exports

New or changed content of file exports:

/my_android/rootfs/test02 192.168.1.255/24(rw,no_root_squash,async,subtree_check)
sudo exportfs -r

5.3.6. Barebox

Test booting from TFTP and NFS

boot tftp

Configure barebox to boot TFTP and NFS by default

edit /env/config

New or changed content of file /env/config:

kernel_loc=tftp
rootfs_loc=net

	if [ x$os = xandroid ]; then
		nfsroot="${nfsroot}/my_android/rootfs/test02"

Save settings and boot

saveenv
boot

5.4. Boot from NAND

Write the bootloader, the kernel and the Android file system in the flash

5.4.1. Create RootFS for NAND

Create root file system, which can be written into NAND.

The same root file system as for NFS is used. Create the root fs as described in Create_RootFS_for_NFS, if it has not yet been created.

5.4.2. Create JFFS2 File System

mkdir -p ${MY_ANDROID}/images/v02/boot_nand
sudo mkfs.jffs2 --root=${MY_ANDROID}/rootfs/test02 -v --output=${MY_ANDROID}/images/v02/boot_nand/root-pcm049-android.jffs2 --eraseblock=0x20000 -n

5.4.3. Prepare Kernel

Prepare the kernel in ${MY_ANDROID}/images/v02/boot_nand.

The same kernel image as for NFS is used. Copy kernel image as described in Copy_Kernel_for_NFS, if it has not yet been done.

Then create a link to it:

ln -s ../boot_tftp_nfs/uImage-pcm049 ${MY_ANDROID}/images/v02/boot_nand/uImage-pcm049

5.4.4. Prepare TFTP

Copy Android Linux kernel into the tftp server folder

mkdir -p /tftpboot
cp ${MY_ANDROID}/images/v02/boot_nand/uImage-pcm049 /tftpboot

5.4.5. barebox

Write the Android kernel into NAND

update -t kernel -d nand -m tftp

Write the Android file system into NAND

update -t rootfs -d nand -m tftp -f root-pcm049-android.jffs2

Change the boot configuration: Switch S1 all off, S2 all off

Test booting from NAND

boot nand

Configure barebox to boot from NAND by default

edit /env/config

New or changed content of file /env/config:

kernel_loc=nand
rootfs_loc=nand

Save settings and boot

saveenv
boot

5.5. Boot from MMC in File System Boot Mode

5.5.1. Create RootFS for MMC

Create root file system, which can be copied on a SD-card.

The same root file system as for NFS is used. Create the root fs as described in Create_RootFS_for_NFS, if it has not yet been created.

5.5.2. Create RootFS Archive

Create the archive of the root fs as described in Create_RootFS_Archive_for_NFS, if it has not yet been created.

Then create a link to it:

mkdir -p ${MY_ANDROID}/images/v02/boot_mmc_file
ln -s ../boot_tftp_nfs/root-pcm049-android.tar.bz2 ${MY_ANDROID}/images/v02/boot_mmc_file/root-pcm049-android.tar.bz2

5.5.3. Prepare Kernel

Prepare the kernel in ${MY_ANDROID}/images/v02/boot_mmc_file.

The same kernel image as for NFS is used. Copy kernel image as described in Copy_Kernel_for_NFS, if it has not yet been done.

Then create a link to it:

ln -s ../boot_tftp_nfs/uImage-pcm049 ${MY_ANDROID}/images/v02/boot_mmc_file/uImage-pcm049

5.5.4. Bootloader

Prepare the bootloader in ${MY_ANDROID}/images/v02/boot_mmc_file

mkdir -p ${MY_ANDROID}/images/v02/boot_mmc_file
cp ${MY_DVD}/images/boot_mmc_file/MLO ${MY_ANDROID}/images/v02/boot_mmc_file
cp ${MY_DVD}/images/boot_mmc_file/barebox.bin ${MY_ANDROID}/images/v02/boot_mmc_file

5.5.5. Prepare SD-Card

Install the bootloader and the kernel in the FAT partition. Install the Android file system in ext3 partition.

Useful links:

http://omappedia.org/wiki/Android_Build_SD_Configuration

http://omappedia.org/wiki/SD_Configuration

Insert a MMC or SD-Card in your card reader, which appears as device e.g. /dev/sdc on your host. Define an environment variable for this device.

export MY_MMC=/dev/sdc

Delete the boot sector on this device. The reason is described in the man pages of fsck(8).

Warning: Don't delete the boot sector on your root device!!!

dd if=/dev/zero of=${MY_MMC} bs=1024 count=1024

Display information about the device:

fdisk -l ${MY_MMC} 

As an example an 4GByte SD-Card is used. Output:

Platte /dev/sdc: 4014 MByte, 4014997504 Byte
124 Köpfe, 62 Sektoren/Spur, 1020 Zylinder
Einheiten = Zylinder von 7688 x 512 = 3936256 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Festplatte /dev/sdc enthält keine gültige Partitionstabelle

Size of 1 cylinder is: 124 Head/Cylinder * 62 Sector/Head * 512 Byte/Sector = 7688 Sector/Cylinder * 512 Byte/Sector = 3936256 Byte/Cylinder

Create these partitions:

60MB boot File System: vfat Typ: 0xc

2G rootfs File System: ext3 Typ: 0x83

2G media File System: vfat Typ: 0xc

Compute the number of cylinders for the first partition:

60*1024*1024 Byte / (3936256 Byte/Cylinder) = 15.98 Cylinder

For 60 MByte 16 Cylinders are needed.

fdisk ${MY_MMC} 

Press m to show the help text of fdisk. You will need the following commands:

Output:

Command action
   a   toggle a bootable flag
   l   list known partition types
   m   print this menu
   n   add a new partition
   p   print the partition table
   q   quit without saving changes
   t   change a partition's system id
   u   change display/entry units
   w   write table to disk and exit

Press p to print the partition table.

Press u to change units to cylinders.

Press n and create the first partition. Set the size to about 60MByte.

Press n and create the second partition. Set the size to about 2GByte.

Press t and set the system id of the first partition to 0xc.

Press t and set the system id of the second partition to 0x83.

Press a and set the boot flag of the first partition.

Press p to print the partition table.

Press w to write the new partion table to the device. Output:

Platte /dev/sdc: 4014 MByte, 4014997504 Byte
124 Köpfe, 62 Sektoren/Spur, 1020 Zylinder
Einheiten = Zylinder von 7688 x 512 = 3936256 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x965295c0

   Gerät  boot.     Anfang        Ende     Blöcke   Id  System
/dev/sdc1   *         1          17       65317    c  W95 FAT32 (LBA)
/dev/sdc2            18         528     1964284   83  Linux
/dev/sdc3             529        1020     1891248    c  W95 FAT32 (LBA)

Important: If the boot flag of the first partition is not set, the board will not boot from the SD-Card!

Format the first partition with a FAT file system.

mkfs.vfat -n "boot" ${MY_MMC}1

Format the second partition with an ext3 file system.

mke2fs -j -L "rootfs" ${MY_MMC}2

Format the third partition with a FAT file system.

mkfs.vfat -n "sdcard" ${MY_MMC}3

Create the mount points, if they don't exist already.

mkdir -p /mnt/mmc1
mkdir -p /mnt/mmc2

Mount the partitions

mount ${MY_MMC}1 /mnt/mmc1
mount ${MY_MMC}2 /mnt/mmc2

Install the bootloader and the kernel image

cp ${MY_ANDROID}/images/v02/boot_mmc_file/MLO /mnt/mmc1
cp ${MY_ANDROID}/images/v02/boot_mmc_file/barebox.bin /mnt/mmc1
cp ${MY_ANDROID}/images/v02/boot_mmc_file/uImage-pcm049 /mnt/mmc1

Extract Android file system

cd /mnt/mmc2
sudo tar xjf ${MY_ANDROID}/images/v02/boot_mmc_file/root-pcm049-android.tar.bz2

Unmount the SD-Card

umount ${MY_MMC}1
umount ${MY_MMC}2

5.5.6. barebox

Insert the SD-Card into slot X11. Change the boot configuration: Switch S1 all off, S2-2,3,5 on, others off.

Test booting from SD-Card

boot mmc

Configure barebox to boot from SD-card by default

edit /env/config

New or changed content of file /env/config:

kernel_loc=mmc
rootfs_loc=mmc

Save settings and boot

saveenv
boot

6. Use Android

6.1. Setup Hardware

Connect a serial cable to the upper serial port P1 on the board and a serial port of the host. Start a terminal application like cu or minicom on the host with the settings 115200 8N1.

Connect an Ethernet cable to the Ethernet port X9. Connect a USB Keyboard to the USB port X8. Connect a LCD Monitor to the DVI port X23 or connect a Phytec LCD Display PL1337.1 to the DISPLAY port.

Connect the power supply to the board.

Stop the bootloader barebox and change the configuration to your needs.

6.2. Booting for the first Time

When you boot for the first time, it will take a long time until the Android GUI appears. Next time it should be faster.

6.3. Disable sleep mode

Currently Android crashes, when it tries to switch to sleep mode. You have to disable the sleep mode by using the GUI or the console.

6.3.1. Use the GUI to disable sleep mode

Settings -> Applications -> Development -> Stay awake

By selecting "Stay awake" the value of wake_lock is set to PowerManagerService

cat /sys/power/wake_lock

Output:

PowerManagerService

You need to set this only once.

6.3.2. Use the console to disable sleep mode

cat /sys/power/wake_lock
echo foo > /sys/power/wake_lock
cat /sys/power/wake_lock

Output:

foo

You need to set this each time you boot the board.

6.4. Configure Network

Set the address of your nameserver on the command line:

setprop net.dns1 192.168.1.1

When this is working you can also define it in default.prop in the root folder of Android. New or changed content of file default.prop:

# nameserver
net.dns1=192.168.1.1

6.5. Fixed Problems

The Android GUI is displayed on a Phytec LCD Display PL1337.1 connected to the DIPLAY port or on a LCD Monitor connected to the DVI port.

The colors are correct.

Page flipping is disabled, because the LCD Display has flickered.

The touchscreen is working.

6.6. Known Problems

Android cannot automatically mount a SD card at the MMC port X11. There is an error in /system/etc/vold.fstab. When this error is corrected, an SD card could be used, but the Gallery application crashes.

The graphics driver SGX is not used.

You have to use an USB keyboard because you need the keys: ESC, F1

ESC: go back

F1 F1: Unlock screen

F1: Menue

F3: phone dialog

F4: Lock screen

End: Lock screen

Pos1: Home

Windows Menue key: Browser

No additional applications have been installed. This is just the Android which is available as open source.

7. Develop Applications for Android

Develop Java Applications for Android.

7.1. Build Application

Building a Java application with Eclipse and the Android SDK is described in the Dev Guide.

7.2. Test Application

Download and debug the application. Use gdb, eclipse or adb. A useful link is http://www.omappedia.com/wiki/Android_Debugging .