View source for Android

From Openmoko

Jump to: navigation, search

You do not have permission to edit this page, for the following reasons:

  • The action you have requested is limited to users in the group: Administrators.
  • You must confirm your email address before editing pages. Please set and validate your email address through your user preferences.

You can view and copy the source of this page:

Return to Android.

Personal tools

Android is one of the many distributions that currently work on the Openmoko phones. You can compare a distribution with an Operating System on normal computers. It gives the phone all the software needed for operating. For more information about the different flavors, see distributions.


  • 20081021 User:Cfriedt Android -> FreeRunner updates on my blog
  • 20081022 User:Cfriedt I was able to 'trivially' compile all of the Android source code without error for the ARMv4T architecture by removing v5TE instructions. Although it will definitely not run anything predictably, at least now that I know the build system will work with a few simple substitutions in build/core/combo/ At this point I am able to go ahead and re-implement v5TE instructions as v4T instruction sequences instead (or re-implement entire sections of assembly with hand-optimized v4T instructions).
  • 20081023 User:Bricode To track the status of which parts of the Android source tree contain ARMv5 specific code, I've created a table of where it is contained, and the status of patches. It can be found at:
  • 20081029 User:Cfriedt Benno has modified Android's build system so that it will output a JFFS2 image instead of YAFFS . Unlike JFFS2, which can be mounted read-only from an image, mounting a YAFFS image is not possible unless it's already been written to flash (it complains about the block device being of type '1' and not 'NAND'). JFFS2 also has the benefit that it's a standard OpenMoko image format (See Flashing the Neo FreeRunner or Flashing the Neo 1973)


This page is dedicated to porting the Android OS to the Neo 1973 and Neo FreeRunner handsets. Since the Android OS was publically released on 20081021, work is currently underway to port Android to the Neo 1973 and FreeRunner handsets.


  1. Systematically introduce patches for ARMv4T in the Android codebase
  2. Provide Neo1973 and Neo FreeRunner hardware-dependent patches in the Android codebase, leveraging the work already done by the Openmoko developers, without forcing Android-specific changes upstream
  3. Provide a useable Android filesystem and kernel on the Distributions page that conform to current Openmoko installation routines

Early Attempts

As Ben Leslie had pointed out on his blog far before the source code was released, Android was originally designed to work with the ARMv5TE instruction set architecture (ISA), which allows for DSP enhanced instructions. Contrary to the ARMv5TE ISA, the Neo1973 and FreeRunner handsets both feature an arm920t core, which comply to the ARMv4T ISA.

Before the source code was released, kernel trap handlers were implemented to 'emulate' the ARMv5TE ISA. Although the results worked in many cases, trapping is costly and performance suffered as a result. Moreover, without explicitly knowing which conditions were set by various instructions, such as Thumb Mode execution, the result became nondeterministic.

Current State

With the release of the Android source code, the Open Source community is no longer limited to dealing with a binary-only product. The Open Handset Alliance (OHA) has let their source code become their product for everyone enrich and benefit from.

Currently, porting efforts are underway in many circles. Patches should be submitted via the official Android channels.

To track the status of which parts of the Android source tree contain ARMv5 specific code, I've created a table of where it is contained, and the status of patches. It can be found at: User:Bricode

Sean McNeil said that he was able to get Androind running (including telephony) in his Freerunner source.

Ben Leslie mentioned on the android-porting list that he was able to get the 'Android' logo to appear on his Neo 1973.

How to Help

Getting Started

You can start by following the instructions to download and build the Android source from scratch. Please see and follow the instructions for your architecture.

Publicize Your Efforts

It's generally a good idea to make your efforts known via wiki systems, public mailing lists, forums, and publically open version control systems.

Always take credit for your work but please don't do it in the form of comments. Some code is already hard enough to read without comments polluting the text. The best thing to do is to create a patch and put a header with your information at the top. Collaboration systems such as git might already do this for you (??).

If you create something new and have the ability to designate the license for it, please consider license compatibility issues.

Porting Strategy

  • Analysis and leverage of the existing build system
    • buid/core/combo/
      • -D__ARCH_ARM_4__ -D__ARCH_ARM_4T__
      • -march=armv4t -mcpu=arm920t
    • fix various static references to 'armv5'
  • Isolating ARMv5TE ISA dependent code
    • e.g. grep -n -R -i "${armv5te_isa_pattern}" ~/android
  • Abstracting
    • ( C/C++ )
      • Use inlined functions / #ifdef statments to implement functions in a portable manner
      • For inlined assembler calls, it's acceptable for now to use generic C code instead, so long as later on we optimize it by hand.
    • ( ASM )
      • Proprocessor statements based on ISA / architecture, e.g. #ifdef __ARCH_ARM_5__ ... #endif #ifdef __ARCH_ARM_4__ ... #endif
      • It's highly suggested that preprocessor statements should not be nested (i.e. make them mutually exclusive)
      • Some people have suggested that we should not do #ifdef's based on ARCH or ISA, but rather based on an AndroidConfig.h which would define macros like PLD(...) #ifdef HAVE_ARM_PLD pld #else ... #endif .

For each ARMv5TE instruction, one could potentially

  • Implement the instruction using general registers instead of DSP calls (i.e. eabi / softfloat)
  • If that is a) nondeterministic, or b) slow, then sections of code need to be analyzed and hand-optimized for the ARMv4T isa

List of Unsupported Instructions

This is a list of opcodes, extracted from the Android source, that are unsupported for ARMv4T compliant processors (specifically the arm920t). The opcodes represent instructions available for ARMv5, ARMv5T, and ARMv5TE architectures, which are not present in the ARMv4T ISA. The list was obtained by exhaustively editing the recompiling the Android source code until it compiled without error.

Please keep in mind, that in some cases, translating these instructions into a sequence of ARMv4T instructions will be impossible and / or result in nondeterministic execution because of

  • the requirement of additional context
  • the tendencies of certain opcodes to change condition registers that may or may not be present in the arm920t core


Opcode Desription [PDF] Page Number C ASM
BLX(1) Branch, Link, and Exchange 166 N/A (Unused in Android) N/A (Unused in Android)
BLX(2) Branch, Link, and Exchange 168

User:Cfriedt 20081028 Remove from inline assembly with something like

#ifdef HAVE_BLX
... (inline asm) ...
... (inline asm with equivalent blx code, as shown to the right) ...

User:Cfriedt 20081028 Substitute with a macro reference such as

#ifdef HAVE_BLX
#define BLX(a) \
blx a
#define BLX(a) \
mov pc,lr \
bx a
CLZ Count Leading Zeros 175

User:Cfriedt 20081028 Remove from inline assembly with something like

#ifdef HAVE_CLZ
... (inline asm) ...
... (inline asm with equivalent clz code, as shown to the right) ...

User:Cfriedt 20081029

#ifdef HAVE_CLZ
#define CLZ(Rd,Rm) \
clz Rd,Rm
#define CLZ(Rd,Rm) \
LDRD Load Registers Doubleword 200

User:Cfriedt 20081028 Substitute different inline assembly code with something like

#ifdef HAVE_LDRD
... (inline asm) ...
... (inline asm with ldrd substituted) ...

User:Cfriedt 20081028 Substitute with a macro reference such as

#ifdef HAVE_LDRD
#define LDRD(a,b) \
ldrd a,b
#define LDRD(a,b) \
PLD Preload Data 240

User:Cfriedt 20081028 Remove from inline assembly with something like

#ifdef HAVE_PLD
... (inline asm) ...
... (inline asm with pld removed) ...

User:Cfriedt 20081028 Remove or substitute with a macro reference such as

#ifdef HAVE_PLD
#define PLD(a,b) \
pld a,b
#define PLD(a,b)
SMLA<x><y> Signed Multiply-Accumulate 291
SMLAL<x><y> Signed Multiply Accumulate Long 298
SMLAW<y> Signed Multiply-Accumulate Word 302
SMUL<x><y> Signed Multiply 316
SMULW<y> Signed Multiply Word 320
QADD Saturating Add 242
QDADD Saturating Double and Add 249
QDSUB Saturating Double and Subtract 251
QSUB Saturating Subtract 253
STRD Store Registers Doubleword 349

User:Cfriedt 20081028 Substitute different inline assembly code with something like

#ifdef HAVE_STRD
... (inline asm) ...
... (inline asm without strd) ...

User:Cfriedt 20081028 Substitute with a macro reference such as

#ifdef HAVE_STRD
#define STRD(a,b) \
strd a,b
#define STRD(a,b) \

Scanning for Files That Use the ARMv5TE ISA

Using the above list of opcodes, one can scan the Android source code for ARMv4T-incompatible instruction sequences.


opcodes="blx clz ldrd pld smlabb smlabt smlatt smlal smlawb smlawt smulbb smulbt smull smultt smulwb smulwt qadd qdadd qsub qdsub strd"

opcodePat="$(echo ${opcodes} | sed -e 's/ /\\\|/g')"

fileList="$(grep -R -i "\(${opcodePat}\) " * 2>/dev/null | grep -v "^Binary file" | sed -e 's/:.*//' | grep -v "CREDITS\|README\|^\(kernel/\)\|\(\.txt\)$" | sort -u)"

for i in ${fileList}; do
echo "* ${i}"

Source Files in Android that Use the ARMv5TE ISA

The list of files below may or may not be complete. There might also be some assembly code that is generated with a python script (verification?).

  • bionic/libc/arch-arm/bionic/memcmp.S
  • bionic/libc/arch-arm/bionic/memcmp16.S
  • bionic/libc/arch-arm/bionic/memcpy.S
  • bionic/libc/arch-arm/bionic/strlen.c
  • bionic/libc/kernel/arch-arm/asm/arch/irqs.h
  • bionic/libc/tools/
  • bootloader/legacy/nandwrite/init.S
  • bootloader/legacy/usbloader/init.S
  • dalvik/vm/arch/arm/CallEABI.S
  • dalvik/vm/arch/arm/CallOldABI.S
  • dalvik/vm/mterp/armv5/OP_AGET_WIDE.S
  • dalvik/vm/mterp/armv5/OP_APUT_WIDE.S
  • dalvik/vm/mterp/armv5/OP_IGET_WIDE.S
  • dalvik/vm/mterp/armv5/OP_IGET_WIDE_QUICK.S
  • dalvik/vm/mterp/armv5/OP_IPUT_WIDE.S
  • dalvik/vm/mterp/armv5/OP_IPUT_WIDE_QUICK.S
  • dalvik/vm/mterp/armv5/OP_SGET_WIDE.S
  • dalvik/vm/mterp/armv5/OP_SPUT_WIDE.S
  • dalvik/vm/mterp/out/InterpAsm-armv5.S
  • dalvik/vm/oo/Object.h
  • development/emulator/qtools/armdis.cpp
  • development/emulator/qtools/thumbdis.cpp
  • external/elfutils/src/Makefile
  • external/elfutils/src/
  • external/elfutils/src/
  • external/freetype/include/freetype/config/ftconfig.h
  • external/jpeg/jidctfst.S
  • external/neven/Embedded/common/src/b_BasicEm/Math.c
  • external/opencore/codecs_v2/audio/aac/dec/src/calc_sbr_synfilterbank.cpp
  • external/opencore/codecs_v2/audio/aac/dec/src/fxp_mul32_arm_gcc.h
  • external/opencore/codecs_v2/audio/aac/dec/src/fxp_mul32_arm_v4.h
  • external/opencore/codecs_v2/audio/aac/dec/src/fxp_mul32_arm_v4_gcc.h
  • external/opencore/codecs_v2/audio/aac/dec/src/fxp_mul32_arm_v5.h
  • external/opencore/codecs_v2/audio/aac/dec/src/pv_normalize.h
  • external/opencore/codecs_v2/audio/aac/dec/src/trans4m_freq_2_time_fxp.cpp
  • external/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basic_op_arm_gcc_v5.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/basic_op_arm_v5.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_add.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_mac.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_msu.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_mult.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/l_sub.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mpy_32.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mpy_32_16.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/mult.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_nb/common/include/norm_l.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_wb/dec/src/normalize_amr_wb.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_wb/dec/src/pvamrwbdecoder_basic_op_armv5.h
  • external/opencore/codecs_v2/audio/gsm_amr/amr_wb/dec/src/pvamrwbdecoder_basic_op_gcc_armv5.h
  • external/opencore/codecs_v2/audio/mp3/dec/src/asm/pvmp3_dct_16_gcc.s
  • external/opencore/codecs_v2/audio/mp3/dec/src/asm/pvmp3_dct_9.s
  • external/opencore/codecs_v2/audio/mp3/dec/src/asm/pvmp3_dct_9_gcc.s
  • external/opencore/codecs_v2/audio/mp3/dec/src/asm/pvmp3_mdct_18.asm
  • external/opencore/codecs_v2/audio/mp3/dec/src/asm/pvmp3_mdct_18.s
  • external/opencore/codecs_v2/audio/mp3/dec/src/asm/pvmp3_mdct_18_gcc.s
  • external/opencore/codecs_v2/audio/mp3/dec/src/asm/pvmp3_polyphase_filter_window.asm
  • external/opencore/codecs_v2/audio/mp3/dec/src/asm/pvmp3_polyphase_filter_window.s
  • external/opencore/codecs_v2/audio/mp3/dec/src/asm/pvmp3_polyphase_filter_window_gcc.s
  • external/opencore/codecs_v2/audio/mp3/dec/src/pv_mp3dec_fxd_op_arm.h
  • external/opencore/codecs_v2/audio/mp3/dec/src/pv_mp3dec_fxd_op_arm_gcc.h
  • external/opencore/codecs_v2/audio/mp3/dec/src/pvmp3_normalize.h
  • external/opencore/codecs_v2/audio/sbc/enc/src/sbcenc_filter.h
  • external/opencore/codecs_v2/video/avc_h264/dec/src/vlc.cpp
  • external/opencore/codecs_v2/video/m4v_h263/enc/src/dct_inline.h
  • external/opencore/codecs_v2/video/m4v_h263/enc/src/fastquant_inline.h
  • external/opencore/codecs_v2/video/m4v_h263/enc/src/vlc_encode_inline.h
  • external/opencore/fileformats/avi/parser/include/pv_avifile_streamlist.h
  • external/opencore/fileformats/avi/parser/src/pv_avifile_streamlist.cpp
  • external/openssl/crypto/bn/bn_prime.c
  • external/qemu/target-arm/translate.c
  • external/qemu/trace.c
  • external/skia/include/corecg/SkFixed.h
  • external/skia/include/corecg/SkMath.h
  • external/skia/libcorecg/Sk64.cpp
  • external/skia/libcorecg/SkMatrix.cpp
  • external/skia/libsgl/effects/SkColorMatrixFilter.cpp
  • external/skia/libsgl/sgl/SkBitmap.cpp
  • external/skia/libsgl/sgl/SkBitmapShader.cpp
  • external/skia/libsgl/sgl/SkGraphics.cpp
  • external/srec/config/
  • frameworks/base/libs/audioflinger/AudioMixer.cpp
  • frameworks/base/libs/audioflinger/AudioResamplerSinc.cpp
  • frameworks/base/opengl/libagl/iterators.S
  • frameworks/base/opengl/libagl/matrix.h
  • system/core/include/private/pixelflinger/ggl_fixed.h
  • system/core/libpixelflinger/codeflinger/ARMAssembler.cpp
  • system/core/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp
  • system/core/libpixelflinger/codeflinger/disassem.c
  • system/core/libpixelflinger/codeflinger/texturing.cpp
  • system/core/libpixelflinger/rotate90CW_4x4_16v6.S
  • system/core/libpixelflinger/t32cb16blend.S



  • (ASM) In order to return from a subroutine, use methods that are known to work from ARMv4T onwards
    mov pc,lr ==> bx lr


  • User:Cfriedt 20081024 I'm not sure how feasible this is, given that the SMedia 3362 is heavily NDA'd. However, since the arm920t lacks a floating-point unit / DSP core, is it possible to use the SMedia chip for general-purpose math? This would help in the Android platform, at least, for things like audio and video codecs. Aside from an OpenGL ES driver, OpenMoko documentation for the SMedia would be highly appreciated.

Important Links

(Please Update Me)


Instruction Set References

Hardware Reference


See also

External Links