About Sensor

Tuesday, April 19, 2011

Android Tools

http://www.kernel.org/

Kernel Patch work Project List -
http://www.kernel.org/pub/software/scm/git/

Android Glossary -
http://elinux.org/Android_Glossary

Android Kernel Download From eLinux.orgJump to: navigation, search

[edit] Main Google Android Kernels

The main Google repository with Android source code is at: http://android.git.kernel.org/
There are (as of September 2009) 4 main separate kernel repositories at that site:
  • common
  • experimental
  • msm
  • omap
To download one of these and use it directly, you can use git. For example:
git clone git://android.git.kernel.org/kernel/common.git kernel
To preserve your sanity, it's probably worth downloading this into a 'kernel' directory in your overall Android source directory scheme
You can use repo, following the instructions at http://source.android.com/download, to pull down the entire Android source. However, when you download the rest of the Android source code, using the 'repo' command, you do NOT automatically get a kernel tree included. That is, a kernel git tree is not referenced in the default Android manifest file,
To add projects, such as the kernel, to your overall Android repository scheme, you add the appropriate kernel repository to your local manifest.xml file. This file is located in the .repo directory.
To include the kernel/common tree, include a line like this in .repo/manifest.xml:
<project path="kernel/common" name="kernel/common" />
The complete list of projects (including other kernel options besides kernel/common) is listed on http://android.git.kernel.org/.
Note that the default revision for git repositories is specified in the <default> tag in manifest.xml as "revision=master" but the kernel/common repository may not have a head called "master". In that case if you just type "repo sync kernel/common" you may see the message:
error: revision master in kernel/common not found
Typically the heads in the kernel/common repository will be called android-2.6.x (where x is the kernel number); specifying this number in the manifest should allow repo to sync properly, i.e.:
<project path="kernel/common" name="kernel/common" revision="android-2.6.27"/>
You can view the heads by clicking on the project link from http://android.git.kernel.org/.
For more about repo, see http://source.android.com/download/using-repo

[edit] Other Repositories with Android-specific changes

[edit] 'Raw' Android kernel patches

I do not know of any freely available patches for the Linux kernel with the Android fixes, as of November 2009. I have, however, heard of multiple efforts to extract the patches to make it easier to port the Android kernel features onto newer Linux kernels.
Here is a way of extracting raw Android patches at a certain point in time, though this may be dated:
git clone git://android.git.kernel.org/kernel/common.git android-kernel
cd android-kernel
git checkout --track -b android-2.6.32 origin/android-2.6.32
git fetch --tags git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-2.6.32.y.git
git shortlog v2.6.32.9..HEAD
git format-patch v2.6.32.9..HEAD
Sum total 173 patches for the 2.6.32.9 kernel as of writing.
If anyone knows where raw android kernel patches are available, please add a link here. See also the Android Kernel Features page for more information about individual kernel features.

Android Kernel Build

From eLinux.org

Jump to: navigation, search
How to build an Android kernel.
The Android build system may or may not automatically rebuild a kernel for you.
This page documents how to build an Android kernel, independent of the regular Android "distribution" build system.
[FIXTHIS - nothing here yet.]

[edit] Building an Individual application

Steps required to compile individual application package in Android SDK.
  1. Go to build directory under Android sdk directory
  2. Execute source source envsetup.sh
  3. Go to corresponding application directory
  4. Issue mm command to build the application only


Here are some development tools useful for working with Android

Contents

[hide]

[edit] Android SDK

[edit] host-side tools

[edit] adb

adb is the android debugger - it also doubles as file transfer agent. The setup consists of an adbd on the target in the /sbin directory. On the host two programs are run: the adb application (in the SDK's tools directory) and an adb server, started by the adb application.
For emulators, adb will usually run automagically.
For real boards - with debugging over USB, you might need to do work, as is documented here: http://developer.android.com/guide/developing/device.html#setting-up .
For real boards that do not have a USB connection but have Ethernet instead, you might need to do a few tricks.
  • make sure that adbd runs on the board. If it doesn't run, you might want to check the init.rc file.
  • make sure that the network connection between host and the board is working - test pinging both ways.
  • on the host, type the following (and yes, you need to specify the board's IP address on the host):
ADBHOST=<target-ip> tools/adb kill-server
  ADBHOST=<target-ip> tools/adb shell
  • you should now get a prompt on the board, you can exit the prompt if you want.
  • tools/adb devices should now list the device.

[edit] aapt

The Android Asset Packaging Tool is used to create, inspect and manage Android packages.
You can use this to see details about a package, it's resources, and xml information.
The Android developer page on aapt is somewhat meager.
See Android aapt for substantially more information.

[edit] ddms

The Dalvik Debug Monitor Server is a host-based tool which interacts with and Android target system and can show numerous bits of information, including the log, cpu and memory utilization, and lots of details about individual processes.
See the DDMS developer guide


[edit] Fastboot

Android Fastboot is a tool to boot and manipulate the partitions on an Android development phone.

[edit] Toolchains

Android provides pre-built toolchains (C/C++ compilers and linkers), but requires the installation of a java compiler (JDK) from an external source.
As of NDK version r5 (December 2010), the toolchains can now be used in standalone cross-compiler mode. See docs/STANDALONE-TOOLCHAIN.html in the NDK for information about this. Previously, the toolchains could be used within the build system, but it was difficult and error prone to compile native programs outside the Android build system with them.

[edit] Emulator

The emulator is a version of QEMU, which mimics the instruction set of an ARM processor, and the hardware that one might find on a mobile phone. The emulator runs on an x86 system, but executes an ARM linux kernel and programs. The flow of control is:
    • application ->
    • dalvik VM ->
    • C/C++ libraries ->
    • ARM linux kernel ->
    • emulated instructions and hardware (QEMU)->
    • C libraries->
    • x86 kernel ->
    • real hardware

[edit] traceview

[edit] target-side tools

[edit] am

Activity Manager - can be used to start applications at the command line, or send intents to running applications.

[edit] dumpstate

[edit] logcat

This is the user tool for accessing the Android system log. This is implemented at a special option in adb (I'm not sure what the difference is between "adb logcat" and "adb shell logcat")
You can find lots of information about logcat on the Android logger page, and at http://developer.android.com/guide/developing/tools/adb.html#logcat

[edit] monkey

[edit] procrank

procrank shows a listing of processes on the system, sorted by one of the memory utilization metrics. See Android Memory Usage#procrank

[edit] service

Can be used to send an individual service message.
Usage: service [-h|-?]
       service list
       service check SERVICE
       service call SERVICE CODE [i32 INT | s16 STR] ...
Options:
   i32: Write the integer INT into the send parcel.
   s16: Write the UTF-16 string STR into the send parcel.
On one forum, I saw that you could switch between portrait and landscape with:
$ service call window 18 i32 1 # to set to landscape on the emulator
$ service call window 18 i32 0 # to set to portrait on the emulator
service list will show a list of different services that can be communicated with.

[edit] toolbox

stop, start - commands to stop and start services on an Android system

[edit] other tools

[edit] agcc

[edit] bootchart

[edit] busybox

Android ships with a utility suite (called 'toolbox') that is not busybox.
You can get a binary busybox for Android here The site includes instructions for easy installation on your device.

[edit] smem

  • smem - smem is a tools for analyzing the memory usage on a system

[edit] strace

[edit] Eclipse

The officially supported integrated development environment (IDE) is Eclipse (currently 3.4 or 3.5) using the Android Development Tools (ADT) Plugin, though developers may use any text editor to edit Java and XML files then use command line tools (Java Development Kit and Apache Ant are required) to create, build and debug Android applications as well as control attached Android devices (e.g., triggering a reboot, installing software package(s) remotely).

[edit] Hardware

[edit] Serial Cable for G1

You can build a serial cable to use with the G1, which is helpful to see kernel boot messages on the serial console.
See http://www.instructables.com/id/Android_G1_Serial_Cable
Back to Android Portal

Dalvik Porting Guide


Dalvik Porting Guide

The Dalvik virtual machine is intended to run on a variety of platforms. The baseline system is expected to be a variant of UNIX (Linux, BSD, Mac OS X) running the GNU C compiler. Little-endian CPUs have been exercised the most heavily, but big-endian systems are explicitly supported.
There are two general categories of work: porting to a Linux system with a previously unseen CPU architecture, and porting to a different operating system. This document covers the former.
Basic familiarity with the Android platform, source code structure, and build system is assumed.

Core Libraries

The native code in the core libraries (chiefly libcore, but also dalvik/vm/native) is written in C/C++ and is expected to work without modification in a Linux environment. Much of the code comes directly from the Apache Harmony project.
The core libraries pull in code from many other projects, including OpenSSL, zlib, and ICU. These will also need to be ported before the VM can be used.

JNI Call Bridge

Most of the Dalvik VM runtime is written in portable C. The one non-portable component of the runtime is the JNI call bridge. Simply put, this converts an array of integers into function arguments of various types, and calls a function. This must be done according to the C calling conventions for the platform. The task could be as simple as pushing all of the arguments onto the stack, or involve complex rules for register assignment and stack alignment.
To ease porting to new platforms, the open-source FFI library (Foreign Function Interface) is used when a custom bridge is unavailable. FFI is not as fast as a native implementation, and the optional performance improvements it does offer are not used, so writing a replacement is a good first step.
The code lives in dalvik/vm/arch/*, with the FFI-based version in the "generic" directory. There are two source files for each architecture. One defines the call bridge itself:
void dvmPlatformInvoke(void* pEnv, ClassObject* clazz, int argInfo, int argc, const u4* argv, const char* signature, void* func, JValue* pReturn)
This will invoke a C/C++ function declared:
return_type func(JNIEnv* pEnv, Object* this [, args])
or (for a "static" method):
return_type func(JNIEnv* pEnv, ClassObject* clazz [, args])
The role of dvmPlatformInvoke is to convert the values in argv into C-style calling conventions, call the method, and then place the return type into pReturn (a union that holds all of the basic JNI types). The code may use the method signature (a DEX "shorty" signature, with one character for the return type and one per argument) to determine how to handle the values.
The other source file involved here defines a 32-bit "hint". The hint is computed when the method's class is loaded, and passed in as the "argInfo" argument. The hint can be used to avoid scanning the ASCII method signature for things like the return value, total argument size, or inter-argument 64-bit alignment restrictions.

Interpreter

The Dalvik runtime includes two interpreters, labeled "portable" and "fast". The portable interpreter is largely contained within a single C function, and should compile on any system that supports gcc. (If you don't have gcc, you may need to disable the "threaded" execution model, which relies on gcc's "goto table" implementation; look for the THREADED_INTERP define.)
The fast interpreter uses hand-coded assembly fragments. If none are available for the current architecture, the build system will create an interpreter out of C "stubs". The resulting "all stubs" interpreter is quite a bit slower than the portable interpreter, making "fast" something of a misnomer.
The fast interpreter is enabled by default. On platforms without native support, you may want to switch to the portable interpreter. This can be controlled with the dalvik.vm.execution-mode system property. For example, if you:
adb shell "echo dalvik.vm.execution-mode = int:portable >> /data/local.prop"
and reboot, the Android app framework will start the VM with the portable interpreter enabled.

Mterp Interpreter Structure

There may be significant performance advantages to rewriting the interpreter core in assembly language, using architecture-specific optimizations. In Dalvik this can be done one instruction at a time.
The simplest way to implement an interpreter is to have a large "switch" statement. After each instruction is handled, the interpreter returns to the top of the loop, fetches the next instruction, and jumps to the appropriate label.
An improvement on this is called "threaded" execution. The instruction fetch and dispatch are included at the end of every instruction handler. This makes the interpreter a little larger overall, but you get to avoid the (potentially expensive) branch back to the top of the switch statement.
Dalvik mterp goes one step further, using a computed goto instead of a goto table. Instead of looking up the address in a table, which requires an extra memory fetch on every instruction, mterp multiplies the opcode number by a fixed value. By default, each handler is allowed 64 bytes of space.
Not all handlers fit in 64 bytes. Those that don't can have subroutines or simply continue on to additional code outside the basic space. Some of this is handled automatically by Dalvik, but there's no portable way to detect overflow of a 64-byte handler until the VM starts executing.
The choice of 64 bytes is somewhat arbitrary, but has worked out well for ARM and x86.
In the course of development it's useful to have C and assembly implementations of each handler, and be able to flip back and forth between them when hunting problems down. In mterp this is relatively straightforward. You can always see the files being fed to the compiler and assembler for your platform by looking in the dalvik/vm/mterp/out directory.
The interpreter sources live in dalvik/vm/mterp. If you haven't yet, you should read dalvik/vm/mterp/README.txt now.

Getting Started With Mterp

Getting started:
  1. Decide on the name of your architecture. For the sake of discussion, let's call it myarch.
  2. Make a copy of dalvik/vm/mterp/config-allstubs to dalvik/vm/mterp/config-myarch.
  3. Create a dalvik/vm/mterp/myarch directory to hold your source files.
  4. Add myarch to the list in dalvik/vm/mterp/rebuild.sh.
  5. Make sure dalvik/vm/Android.mk will find the files for your architecture. If $(TARGET_ARCH) is configured this will happen automatically.
You now have the basic framework in place. Whenever you make a change, you need to perform two steps: regenerate the mterp output, and build the core VM library. (It's two steps because we didn't want the build system to require Python 2.5. Which, incidentally, you need to have.)
  1. In the dalvik/vm/mterp directory, regenerate the contents of the files in dalvik/vm/mterp/out by executing ./rebuild.sh. Note there are two files, one in C and one in assembly.
  2. In the dalvik directory, regenerate the libdvm.so library with mm. You can also use make libdvm from the top of the tree.
This will leave you with an updated libdvm.so, which can be pushed out to a device with adb sync or adb push. If you're using the emulator, you need to add make snod (System image, NO Dependency check) to rebuild the system image file. You should not need to do a top-level "make" and rebuild the dependent binaries.
At this point you have an "all stubs" interpreter. You can see how it works by examining dalvik/vm/mterp/cstubs/entry.c. The code runs in a loop, pulling out the next opcode, and invoking the handler through a function pointer. Each handler takes a "glue" argument that contains all of the useful state.
Your goal is to replace the entry method, exit method, and each individual instruction with custom implementations. The first thing you need to do is create an entry function that calls the handler for the first instruction. After that, the instructions chain together, so you don't need a loop. (Look at the ARM or x86 implementation to see how they work.)
Once you have that, you need something to jump to. You can't branch directly to the C stub because it's expecting to be called with a "glue" argument and then return. We need a C stub "wrapper" that does the setup and jumps directly to the next handler. We write this in assembly and then add it to the config file definition.
To see how this works, create a file called dalvik/vm/mterp/myarch/stub.S that contains one line:
/* stub for ${opcode} */
Then, in dalvik/vm/mterp/config-myarch, add this below the handler-size directive:
# source for the instruction table stub
asm-stub myarch/stub.S
Regenerate the sources with ./rebuild.sh, and take a look inside dalvik/vm/mterp/out/InterpAsm-myarch.S. You should see 256 copies of the stub function in a single large block after the dvmAsmInstructionStart label. The stub.S code will be used anywhere you don't provide an assembly implementation.
Note that each block begins with a .balign 64 directive. This is what pads each handler out to 64 bytes. Note also that the ${opcode} text changed into an opcode name, which should be used to call the C implementation (dvmMterp_${opcode}).
The actual contents of stub.S are up to you to define. See entry.S and stub.S in the armv5te or x86 directories for working examples.
If you're working on a variation of an existing architecture, you may be able to use most of the existing code and just provide replacements for a few instructions. Look at the armv4t implementation as an example.

Replacing Stubs

There are roughly 230 Dalvik opcodes, including some that are inserted by dexopt and aren't described in the Dalvik bytecode documentation. Each one must perform the appropriate actions, fetch the next opcode, and branch to the next handler. The actions performed by the assembly version must exactly match those performed by the C version (in dalvik/vm/mterp/c/OP_*).
It is possible to customize the set of "optimized" instructions for your platform. This is possible because optimized DEX files are not expected to work on multiple devices. Adding, removing, or redefining instructions is beyond the scope of this document, and for simplicity it's best to stick with the basic set defined by the portable interpreter.
Once you have written a handler that looks like it should work, add it to the config file. For example, suppose we have a working version of OP_NOP. For demonstration purposes, fake it for now by putting this into dalvik/vm/mterp/myarch/OP_NOP.S:
/* This is my NOP handler */
Then, in the op-start section of config-myarch, add:
op OP_NOP myarch
This tells the generation script to use the assembly version from the myarch directory instead of the C version from the c directory.
Execute ./rebuild.sh. Look at InterpAsm-myarch.S and InterpC-myarch.c in the out directory. You will see that the OP_NOP stub wrapper has been replaced with our new code in the assembly file, and the C stub implementation is no longer included.
As you implement instructions, the C version and corresponding stub wrapper will disappear from the output files. Eventually you will have a 100% assembly interpreter. You may find it saves a little time to examine the output of your compiler for some of the operations. The porting-proto.c sample code can be helpful here.

Interpreter Switching

The Dalvik VM actually includes a third interpreter implementation: the debug interpreter. This is a variation of the portable interpreter that includes support for debugging and profiling.
When a debugger attaches, or a profiling feature is enabled, the VM will switch interpreters at a convenient point. This is done at the same time as the GC safe point check: on a backward branch, a method return, or an exception throw. Similarly, when the debugger detaches or profiling is discontinued, execution transfers back to the "fast" or "portable" interpreter.
Your entry function needs to test the "entryPoint" value in the "glue" pointer to determine where execution should begin. Your exit function will need to return a boolean that indicates whether the interpreter is exiting (because we reached the "bottom" of a thread stack) or wants to switch to the other implementation.
See the entry.S file in x86 or armv5te for examples.

Testing

A number of VM tests can be found in dalvik/tests. The most useful during interpreter development is 003-omnibus-opcodes, which tests many different instructions.
The basic invocation is:
$ cd dalvik/tests
$ ./run-test 003
This will run test 003 on an attached device or emulator. You can run the test against your desktop VM by specifying --reference if you suspect the test may be faulty. You can also use --portable and --fast to explictly specify one Dalvik interpreter or the other.
Some instructions are replaced by dexopt, notably when "quickening" field accesses and method invocations. To ensure that you are testing the basic form of the instruction, add the --no-optimize option.
There is no in-built instruction tracing mechanism. If you want to know for sure that your implementation of an opcode handler is being used, the easiest approach is to insert a "printf" call. For an example, look at common_squeak in dalvik/vm/mterp/armv5te/footer.S.
At some point you need to ensure that debuggers and profiling work with your interpreter. The easiest way to do this is to simply connect a debugger or toggle profiling. (A future test suite may include some tests for this.)

Copyright © 2009 The Android Open Source Project

Android's git Repository

***
a public git repository put together with the 
various android-specific kernel patches (binder, logger, alarm drivers,
goldflish platform support, etc) soon. 
 
 
Which HW support
[Anil S <anils@mistralsolutions.com>]
> Hello Brian,
> 
>  It would be really great if you could share thoughts on the
> questions given here on Android:
> 
> I was able to add support for the keypad, touch and network in Android,
> however the interfaces like GPS, Accelerometer, vibrator, hardware 3D
> acceleration, battery etc. are not integrated with Android right now. I
> would appreciate if you could throw some light on these open issues. How
> exactly can these interfaces be integrated with Android? 

We're trying to use the standard kernel/driver interfaces when possible,
but for things that may have a good deal of variation in implementation,
we're looking to provide a very thin "hardware interface library" layer
to adapt between the bottom of the userspace stack and the drivers or
whatnot for specific hardware platforms.  

We'll continue to adopt standardized kernel solutions as they become
available -- We're now using the power supply framework in 2.6.24 for
monitoring battery/charge state (post M5 SDK -- it'll be in the next 
release), for example.
 
List:       linux-omap
Subject:    Re: Android on OMAP
From:       Dirk Behme <dirk.behme () googlemail ! com>
Date:       2008-02-26 8:46:05
Message-ID: 47C3D1CD.9060204 () googlemail ! com
[Download message RAW]

skyflame wrote:
>>> Hi
>>>
>>> I move to m5-r14 with both kernel driver and filesystem grabed from 
>>> the sdk.
>>> Now, I can enter the homescreen , and the keyboard is also working 8 )
>>>
>>> I don't do anything extra than what I am doing on the m3-r14 release.
>>
>>
>> Great! Congratulations! :)
>>
>> Do you think you can make the kernel patch (against 2.6.23-omap1?) and 
>> the filesystem available somewhere? Then we can link wiki page to it.
>>
>> Dirk
>>
>>
> 
> Hi Dirk
> 
> I was working on a 2.6.21 kernel. For I don't got a working 2.6.23 
> kernel on hand.
> The git tree kernel don't work fine with my omap2430SDP V5.0
> The PMIC seems not working in the right way, thus the LCD don't run up.
> So I can not make the diff over 2.6.23 omap1  : (

Okay. I sent my 2.6.23 omap1 Android patch yesterday (seems that it 
didn't reach the list cause of > 100k). If you didn't get it I can 
send it again in private mail. Would be quite nice if you could check 
if there are the same files in it you used.

Anything like

cat my_patch | grep +++ > file1
cat your_patch | grep +++ > file2
kdiff3 file1 file2

> The whole Filesystem is about 28MBytes in bz2 format.
> I don't know where can I upload it. I can not find some place where can 
> hold such big file for a long time.
> I am glad to upload it , if someone has the network storage resources.

As already mentioned yesterday: Same to me ;)

Anybody with ~30-40 MB permanent public storage?
   
> I'm hoping to get a public git repository put together with the 
> various android-specific kernel patches (binder, logger, alarm drivers,
> goldflish platform support, etc) soon.  This should at least make
> it easier for folks to merge various drivers 'n things into their
> working trees, rather than having to extract them from the kernel
> source tarball provided with emulator/sdk releases.

The core android kernel patches are now available from git.android.com.
Please be aware that these are *newer* than the M5 SDK, and I think
the binder driver in particular may not be compatible with M5.  When
the next SDK release happens, we should be able to point at a sha1
hash of the git change the kernel came from.

http://git.android.com/?p=kernel.git;a=shortlog;h=android
git://git.android.com/kernel.git

Please note that for legacy reasons the default branch is the
msm-2.6.24 branch -- you'll want to check out the "android"
branch if you're looking for the generic patches useful for
all platforms.

Android Porting On Real Target [Realtime Project]


1 Introduction


Google explains that Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This document explains the Android architecture by Google and porting procedure on the real hardware. The explanation is based on the m3 sdk version of the Android emulator.


If you have enough knowledge about patching the kernel, resolving rejections from a patch, making an ramdisk image, and the Linux kernel itself, reading this article will be easier.

2 Copyright and Acknowledgements


This document is copyright (c) Kwangwoo Lee (kwangwoo.lee at gmail dot com). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License.

AndroidPortingOnRealTarget/ko - Korean translation by dasomoli (dasomoli at gmail dot com).

3 The brief analysis of the Android architecture


3.1 Android Kernel


The most different things are the Android kernel uses ARM EABI(Embedded Application Binary Interface) and OpenBinder IPC(Inter Process Communication). If you want to compile the kernel supporting ARM EABI, you should rebuild toolchains to support ARM EABI.

The Android sdk emulates goldfish architecture using qemu. The alsa may be used for audio on Android. See the audio.c file in the goldfish architecture directory and the driver uses /dev/eac for audio on the Android system. RTC(Real Time Clock) device is also used through /dev/rtc0.

The following parts explain the main differences:

3.1.1 ARM EABI


EABI is the new "Embedded" ABI by ARM Ltd. The changes are listed on Debian wiki. (http://wiki.debian.org/ArmEabiPort)

Example with long ftruncate64(unsigned int fd, loff_t length):

legacy ABI:
- put fd into r0
- put length into r1-r2
- use "swi #(0x900000 + 194)" to call the kernel

new ARM EABI:
- put fd into r0
- put length into r2-r3 (skipping over r1)
- put 194 into r7
- use "swi 0" to call the kernel

The Android uses EABI kernel feature. Enable kernel options of the CONFIG_AEABI and CONFIG_OABI_COMPAT. You can see the differences of the executable binary as follows :

  • Legacy ABI
$ arm-softfloat-linux-gnu-objdump -x t7-demo | grep private
private flags = 202: [APCS-32] [FPA float format] [software FP] [has entry point]

$ file t7-demo
t7-demo: ELF 32-bit LSB executable, ARM, version 1 (ARM), 
for GNU/Linux 2.4.3, dynamically linked (uses shared libs), 
for GNU/Linux 2.4.3, stripped

  • ARM EABI
$ arm-softfloat-linux-gnueabi-objdump -x t7-demo  | grep private
private flags = 4000002: [Version4 EABI] [has entry point]

$ file t7-demo
t7-demo: ELF 32-bit LSB executable, ARM, version 1 (SYSV), 
for GNU/Linux 2.6.14, dynamically linked (uses shared libs), 
for GNU/Linux 2.6.14, stripped


What is the ABI for the ARM Architecture? Is it the same as the ARM EABI?

The ABI for the ARM Architecture is a standard developed by ARM and its partners (including CodeSourcery) that explains how compilers, assemblers, linkers, and other similar tools should generate object files and executable files. Tools that correctly implement the ABI for the ARM Architecture can interoperate; i.e., objects files built with one toolchain can be combined with object files built with another toolchain if both compilers use the ABI for the ARM Architecture. The "ARM EABI" is an informal name for the ABI for the ARM Architecture.

3.1.2 OpenBinder


The OpenBinder provides a object-oriented operating system environment. It is designed to be hosted by traditional kernels. This project is started at Be. Inc. as the part of the next generation BeOS, and finished implementing at PalmSource as a core part at the Cobalt system.

It is a system oriented component architecture rather than application oriented, and It provides IPC between processes, threadpool, memory management and clean up feature at the end of reference of an binder object.

The vanilla kernel do not have OpenBinder IPC mechanism you should patch the kernel. The OpenBinder offers thread management for the system through /dev/binder. It is the reason that Android system do not offer thread libraries.

After patching the kernel, you can see the files for binder at drivers/binder/.

3.1.3 Frame Buffer


The basic frame buffer driver should be implemented already. After that you need to implement the differences between your architecture driver and the goldfish driver.

The frame buffer driver of the goldfish architecture supports the fb_pan_display function of the struct fb_ops. It means you should allocate memory twice rather than the actual frame size.

  • Initialize frame buffer information
struct fb_info *fbinfo;
...
fbinfo->fix.ypanstep = 1;
fbinfo->var.yres_virtual    = gm->lcd.yres * 2;
fbinfo->fix.smem_len        = (gm->lcd.xres *
                                gm->lcd.yres *
                                gm->lcd.bpp / 8) * 2;

  • Allocate frame buffer memory
struct mvfb_info *fbi;
...
fbi->map_size = PAGE_ALIGN(fbi->fb->fix.smem_len + PAGE_SIZE);
fbi->map_cpu  = dma_alloc_writecombine(fbi->dev, fbi->map_size,
                                       &fbi->map_dma, GFP_KERNEL);

  • Implement fb_pan_display fuction hook
static int mvfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fb)
{
...
}

static struct fb_ops mvfb_ops = {
        .owner  = THIS_MODULE,

        .fb_check_var = mvfb_check_var,
        .fb_set_par = mvfb_set_par, 
        .fb_setcolreg = mvfb_setcolreg,
        .fb_blank = mvfb_blank,
        .fb_pan_display = mvfb_pan_display,

        .fb_fillrect = cfb_fillrect,
        .fb_copyarea = cfb_copyarea,
        .fb_imageblit = cfb_imageblit,

        .fb_mmap = mvfb_mmap, 
};

The device file is located at /dev/graphics/fb0.

3.1.4 Input Devices


Android uses event device for user input. There are three devices such as keypad, qwerty2 keyboard and mouse. The qwerty2 keyboard and mouse are normal devices. So I just explain the keypad and touchscreen which mouse device is replaced with.

On the Android shell, Cat the /proc/bus/input/{devices,handlers} and then you will see the devices used for the Android.
$ adb shell

# cat /proc/bus/input/devices
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="goldfish-events-keyboard"
P: Phys=
S: Sysfs=/class/inut/input0
U: Uniq=
H: Handlers=kbd mouse0 event0
...
#
# cat /proc/bus/input/handlers
N: Number=0 Name=kbd
N: Number=1 Name=mousedev Minor=32
N: Number=2 Name=evdev Minor=64
#

  • Keypad

Qemu emulates goldfish-events-keyboard. It is a keypad using event device(/dev/input/event0). So you should know which key event and values come from the event device to activate Android applications. To do that, read event0 device with cat and redirect the output to a file. If you push and release the key button on emulator, the output values will be saved.

The output format is struct input_event. So the output on each event is 16 bytes like 8 bytes for time, 2 bytes for type, 2 bytes for code, 4 bytes for value. Read input.txt and input-programming.txt about input event devices in the Documentation/input directory of the Linux kernel source code.

struct input_event {
        struct timeval time;
        unsigned short type;
        unsigned short code;
        unsigned int value;
};

The Tiger7 evaluation board has it's own scancode table. The following shows the key layout on evaluation board, scancode table, and Android keycodes:
/*
 *  Key Layout       Scancode Table
 *
 *   1  2  3        0x1  0x10  0x100
 *   4  5  6        0x2  0x20  0x200
 *   7  8  9        0x4  0x40  0x400
 *   *  0  #        0x8  0x80  0x800
 */

static unsigned short android_keycode[] = {
        /*
         *  0x66 0x67 0x9e Home  Up   Back
         *  0x69 0xe8 0x6a Left  Ok   Right
         *  0xe7 0x6c 0x6b Send  Down Hangup
         *  0xe5  Menu       just_distinction_for_private
         */
        KEY_HOME,         KEY_UP,       KEY_BACK,
        KEY_LEFT,         KEY_REPLY,    KEY_RIGHT,
        KEY_SEND,         KEY_DOWN,     KEY_END,
        KEY_KBDILLUMDOWN, KEY_RESERVED, KEY_PLAY
};

There is a power button on emulator, but I skipped it to get output value.

If an interrupt of the keypad is caught, translate the scancode with the keycode of the Android on the above table and send event to user space application.
...
keycode = translate_keycode(scancode);
...
input_event(keydev->input, EV_KEY, keycode, KEY_PRESSED);
or
input_event(keydev->input, EV_KEY, keycode, KEY_RELEASED);
...

The high resolution timer - hrtimer is used for reduce keypad debounce.

  • Touchscreen

If you have a touchscreen driver supporting the event interface for a pointing device, it'll work well. If you do not have it, you may implement it or use other pointing devices. Fortunately the evaluation board has already implemented touchscreen driver - drivers/input/touchscreen/tsc2007.c - which is made just before beginning to porting Android. Refer the drivers on drivers/input/touchscreen/ to implement your own driver and the text files on Documentation/input/.

Here is the output of the /proc/bus/input/{devices,handlers} on evaluation board.
# cat /proc/bus/input/devices
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="MVT7 KEYPAD"
P: Phys=
S: Sysfs=/class/input/input0
U: Uniq=
H: Handlers=kbd event0 evbug
B: EV=f
...

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="TSC2007 Touchscreen"
P: Phys=0-0090/input0
S: Sysfs=/class/input/input1
U: Uniq=
H: Handlers=event1 evbug
B: EV=b
B: KEY=400 0 0 0 0 0 0 0 0 0 0
B: ABS=1000003

# cat /proc/bus/input/handlers
N: Number=0 Name=kbd
N: Number=1 Name=evdev Minor=64
N: Number=2 Name=evbug

As a result, the keypad uses /dev/input/event0 and the touchscreen interface uses /dev/input/event1 on application layer.

3.1.5 Low Memory Killer


The Linux Kernel has an OOM(Out of Memory) killer for the situation that no memory is left to allocate for a request of a process. It examines all processes and keeps score with some restrictions. The process with highest score will be killed except init.

The Low Memory Killer of the Android behaves a bit different against OOM killer. It classifies processes according to the importance with groups and kills the process in the lowest group. It will make the system to be stable at the view of the end users. For example, the UI Process - foreground process - is the most important process for the end users. So to keep the process live looks more stable than keeping other background processes live.

Enable CONFIG_LOW_MEMORY_KILLER after patching the kernel.

3.1.6 Android Logger


If you enable this feature, you can see some useful information about Android through /dev/log/main. There are three device files on /dev/log such as main, events, radio. The /dev/log/radio file seems to be related with a modem device and ril daemon - rild - on Android system.

When this logger is enabled, the system performance is a bit slower on the system. To use this feature, enable CONFIG_ANDROID_LOGGER.

3.1.7 Android Power


The Android power is for the battery management on devices and some subsystem related with power management like inotify feature on file system. It is not necessary to start up Android through the init(ShellScript) of the Android system. But the runtime binary looks up some files regarding Android power - /sys/android_power/acruire_partial_wake_lock - on starting up Android manually and failed to start up. Enable CONFIG_ANDROID_POWER to use.
- 예전 버전의 문서에서 init은 바이너리로 되어있었는데 쉘스크립트로 바뀌어 있네요. 이전 문서에서 말한 init은 안드로이드 램디스크의 루트 디렉토리 밑에 있는 init 바이너리를 말씀하신 것 같은데, 그 것이 아니고 다른 init인건가요? 아니면 그 init이 쉘 스크립트인 것인가요? -- dasomoli

- 문서를 작성한 m3 버전에서는 binary 였습니다. 다른 분이 shell script로 바꾼 것 같네요. 번역해 주셔서 감사합니다. -- 이광우

- m5 버전에서도 바이너리인 것 같아서요. 그리고 별 말씀을요.^^; -- dasomoli

3.1.8 Panic Timeout


It is not necessary to start up Android on evaluation board. Set CONFIG_PANIC_TIMEOUT with a desired value.

3.2 Android Root File system


Android emulator has 3 basic images on tools/lib/images directory.

  • ramdisk.img
  • system.img
  • userdata.img

ramdisk.img is gziped cpio archive. ramdisk image is very small and contains configuration files, and some executable files such as init and recovery. The init file is not a regular system V init. It is made just for the Android and do special things to start up the Android system.

system.img and userdata.img are VMS Alpha executable. system.img and userdata.img have the contents of /system and /data directory on root file system. They are mapped on NAND devices with yaffs2 file system. /dev/block/mtdblock0 for /system and /dev/block/mtdblock1 for /data.

/system directory has libraries and default system packages (*.apk). /data directory has timezone, cache, and ApiDemos.apk package.

The main services are zygote(/system/bin/app_process), runtime(/system/bin/runtime), and dbus(/system/bin/dbus-daemon). You can see the /etc/init.rc file on the Android ramdisk image.

...
zygote {
    exec /system/bin/app_process
    args {
        0 -Xzygote
        1 /system/bin
        2 --zygote
    }
    autostart 1
}
runtime {
    exec /system/bin/runtime
    autostart 1
}
...
dbus {
    exec /system/bin/dbus-daemon
    args.0 --system
    args.1 --nofork
    autostart 1
}
...

3.3 Licenses of the Android Packages


tools/lib/images/NOTICE contains package lists and licenses for each libraries. The table of the licenses is cited from the presentation by Lim,GeunSik at 2008 Korea Android Summit.

Open Source License
Linux Kernel GPL
NetBSD C Library BSD
DBUS GPL2
OpenBinder (core) GPL2
YAFFS2 GPL
SQLite GPL2
Webkit BSD (including LGPL)
WebCore LGPL
SDL LGPL
SGL Google(Skia)
OpenGL SGI OpenGL (BSD/MPL)


4 Toolchain supporting ARM EABI


The toolchain represents the tools to be used for the system development. It contains C/C++ compiler, linker, libraries, binutils, and etc. The Android kernel and system requires EABI support. So legacy toolchain is not compatible to make the Android system.

4.1 Building toolchain


To make life easier, I used the crosstool-0.43 script (http://www.kegel.com/crosstool/) by Dan Kegel. Unfortunately it is not support to build eabi toolchain, so I applied a glibc 2.5+ nptl build for arm softfloat eabi patch (http://sources.redhat.com/ml/crossgcc/2006-12/msg00076.html) by Khem Raj.

$./arm-softfloat-eabi.sh

If the network is connected, the script will download and build toolchain using gcc 4.1.1 and glibc 2.5.

4.2 Other toolchain


I did not use the codesourcery toolchain, but they said it will work for the building Android system.


5 Kernel


To port the Android on a real hardware is started by Benno (http://benno.id.au), you can see some useful information on his blog. On his blog some pre-compiled static binaries are linked. It is very helpful for debugging Android system. You can also build static build busybox and strace binaries, but it's better to get them and use.

You can get patch file including the differences between the Android kernel and the vanilla kernel with 2.6.23 version. It has all differences between them. So you need to extract parts of them, and make your own patch for your system architecture.

For example, the Android kernel has it's own yaffs file system patch. If you have your own yaffs or some other file systems like jffs2 on your architecture, then you need to remove the yaffs parts of the patch. The goldfish architecture which the Android kernel emulate an ARM architecture on qemu is not necessary part for your architecture. It can be removed.

The Android kernel emulates ARMv5 instructions. So ARM926EJ-S (ARMv5TEJ) will be good to work.

5.1 Patch kernel


Benno played with a NEO1973 device by openmoko. So he made patch files for it. Get the original patch file from http://benno.id.au/blog/2007/11/21/android-neo1973, I used android.diff. It has whole things about goldfish, qemu, yaffs, and Android specific parts.

You can edit and remove the patch file directly. After making patch including binder, android power, android logger, low memory killer except goldfish and qemu specific parts, get vanilla 2.6.23 version Linux kernel and patch it.

If you use a 2.6.24.1 version Linux kernel, some part regarding android power should be fixed accordingly or disabled to work.

5.2 .config


  • Necessary
...
CONFIG_PANIC_TIMEOUT=0
CONFIG_AEABI=y
CONFIG_OABI_COMPAT=y
CONFIG_BINDER=y
CONFIG_LOW_MEMORY_KILLER=y
...

  • Optional
...
# CONFIG_ANDROID_GADGET is not set
# CONFIG_ANDROID_RAM_CONSOLE is not set
# CONFIG_ANDROID_POWER is not set
# CONFIG_ANDROID_LOGGER is not set
...

6 Root file system


The root file system is composed of three parts such as a primary ramdisk image on ram, a system image on nand dev0 (/dev/block/mtdblock0), and a data image on nand dev1 (/dev/block/mtdblock1). The mtd devices has a yaffs2 file system and each of them has 64 MiB capacity on the Android emulator.

The extracted system and data directories are copied to the real existing NAND device and they are mounted with --bind option to work on a real hardware.

6.1 Get ramdisk image from emulator


1. unpack ramdisk image from tools/lib/images/ramdisk.img
$ gzip -cd ramdisk.img > ramdisk
$ cpio -iv -F ramdisk

cpio will extract files and directories on current working directory.

2. the contents list of the ramdisk
data
dev
etc
etc/default.prop
etc/firmware
etc/firmware/brf6150.bin
etc/firmware/brf6300.bin
etc/hcid.conf
etc/hosts
etc/init.gprs-pppd
etc/init.rc
etc/init.ril
etc/init.testmenu
etc/ppp
etc/ppp/chap-secrets
etc/ppp/ip-down
etc/ppp/ip-up
etc/qemu-init.sh
etc/system.conf
etc/system.d
etc/system.d/bluez-hcid.conf
etc/usbd.conf
init
proc
sbin
sbin/recovery
sys
system
tmp
var
var/run

6.2 Get data and system directory from emulator


To get data and system directory you need a static compiled busybox binary. The compiled binary can be obtained from http://benno.id.au/blog/2007/11/14/android-busybox , or make your own binary.

1. launch the Android emulator

2. push static compiled busybox into emulator
# adb push busybox .

3. launch the Android shell
# adb shell

4. make tarball with busybox
# chmod +x /busybox
# busybox tar -c /data.tar /data
# busybox tar -c /system.tar /system
# exit

5. extract tarball from the emulator
# adb pull /data.tar .
# adb pull /system.tar .

Extract command often failed. So you may repeat it again until it has done successfully.

6.3 Integrate the Android system with a existing ramdisk image.


The ramdisk for your architecture can make your work a bit easier. Copy the contents of the Android ramdisk to your own ramdisk except system and data directory. And make just mount point for system and data directory. The mount points will be used later with a bind option. The init binary of the Android ramdisk image is the key binary to start the system and It read a configuration file on /etc/init.rc.

Edit /etc/init.rc and comment out qemu part.

...
startup {
        ...
#       qemu-init {
#           exec /etc/qemu-init.sh
#       }
}
...

Make run.sh script. /dev/block/mtdblock5 is a mtd partition on a real NAND device, and it is mounted on /mnt. data and system directories are already copied on mtdblock5. So the script below just shows bind mounting each directory on /. Fix your script according to your board configuration.

#!/bin/sh
mount -t yaffs /dev/block/mtdblock5 /mnt
mount --bind /mnt/data   /data
mount --bind /mnt/system /system

# data folder is owned by system user on emulator. Fix 777 to other.
chmod 777 /data
#chmod 777 /system

export PATH=/system/sbin:/system/bin:/sbin/usr/local/bin
export LD_LIBRARY_PATH=/system/lib

export ANDROID_BOOTLOGO=1
export ANDROID_ROOT=/system
export ANDROID_ASSETS=/system/app
export EXTERNAL_STORAGE=/sdcard
export ANDROID_DATA=/data
export DRM_CONTENT=/data/drm/content

/init &

An optional configuration for touchscreen - TSLib.

...
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_PLUGINDIR=/lib/ts

export LD_PRELOAD=/lib/libts.so:/lib/ts/pthres.so
...

6.4 System and Data directories


The contents of the system and data directories are copied to mtdblock5 already. You should copy your own method. To use it, I chose bind mounting on root directory. Bind mounting is a technique to mount an existing directory with a new mount point.

6.5 Run and Debug


Now the kernel, ramdisk, and data directories - data and system - are ready. It's time to see the red cylon eye. After boot up your integrated system, run the run.sh on root directory.

# cd /
# . /android/run.sh
yaffs: dev is 32505861 name is "mtdblock5"
yaffs: passed flags ""
yaffs: Attempting MTD mount on 31.5, "mtdblock5"
yaffs: auto selecting yaffs2
# init: HOW ARE YOU GENTLEMEN
init: reading config file
init: device init
init: mtd partition -1,
init: mtd partition 0, "l1boot"
init: mtd partition 1, "u-boot"
init: mtd partition 2, "params"
init: mtd partition 3, "kernel"
init: mtd partition 4, "ramdisk"
init: mtd partition 5, "rootfs"
sh: can't access tty; job control turned off
# binder_open(c394bcc8 c3c731a0) (pid 1577) got c3e48000
binder_open(c394bcc8 c3cd8dc0) (pid 1616) got c319f000
binder_open(c394bcc8 c3cd8ac0) (pid 1673) got c3d10000
binder_open(c394bcc8 c3cd8940) (pid 1680) got c0e19000
binder_open(c394bcc8 c3cd88c0) (pid 1691) got c2fa0000
binder_open(c394bcc8 c3d174a0) (pid 1592) got c25b8000
binder_release(c394bcc8 c3cd88c0) (pid 1691) pd c2fa0000
#

  • Do not make eac device file on /dev. It is for the audio on qemu. If it exists, the start up sequence will wait forever to finish writing some data to the sound device.
  • Use the Android init binary instead of manual startup. The manual start up will require the android power patch. In that case the start up sequence will access /sys/android_power/acquire_partial_wake_lock and wait.

To debug the Android system, use static compiled strace binary from http://benno.id.au/blog/2007/11/18/android-runtime-strace and run the Android manually.

#!/bin/sh
# set environment variables above example
...
/system/bin/app_process -Xzygote /system/bin --zygote &
/system/bin/dbus-daemon --system &
/system/bin/runtime

The above example shows manual startup sequence, use strace on run /system/bin/runtime binary.

./strace -ff -F -tt -s 200 -o /tmp/strace runtime

6.6 Screenshots


  • Skipped

7 Application Development


The Android applications use Java syntax and xml layouts, but it is not a Java. Because they use their own virtual machine - dalvik - and compiler for dex file format. And use package named apk such as Home.apk, Phone.apk, ApiDemos.apk and etc.

The apk file is a Zip archive and it has four parts.

  • AndroidManifest.xml
  • classes.dex
  • resources.arsc
  • res directory

The Dex file format is explained on http://www.retrodev.com/android/dexformat.html. And the contents of the files and directories are explained some day by Google. It is not explained currently. We can just guess about it.

The Android SDK will create an *.apk file.

7.1 Install Eclipse IDE



1. Eclipse IDE for Java developer (JDT and WST plugins are included) from http://www.eclipse.org/downloads/


3. ADT (Android Development Tools) with a eclipse plugin including Apache Ant

7.2 Build and Run Sample Applications


1. Open sample projects and build

2. Run sample applications on emulator

7.3 Screenshots


  • Android Platform on Nokia's N810 Product(arm1136jf-s)
    n810.kandroid200805.PNG

  • Android Platform on arm1136jf-S for another CE Product.
    fi.initial_display.jpg
  • invain님이 shot을 올려주셨군요. -- 이광우

8 Epilogue


The Android system seems to be a new kind of a Linux based distribution for a mobile environment like Debian, RedHat, SuSE, and etc. They just use the Linux kernel and a lot of different libraries in the open source world. They offer a software based OpenGL-ES library on a 3D acceleration currently, but they are developing on a hardware accelerated baseband processor for it. The hardware acceleration is necessary for fast UI rendering effects later.

The Android system on the sdk is not a completed one to port on a real hardware, because some device - for example, camera - related libraries and classes are not implemented yet and not opened for users. It seems to be under the development stage. So we would better to wait the Google announces the whole porting kit.

Until then, we should look for the business model with the Android system. It requires a bit high cpu performance, so the carrier vendors will require a cheap baseband processor (RF part) and a multimedia co-processor, because the baseband processor including multimedia features will be very expensive.

9 Links and References