Android Software Package for 4750/4751

Overview

For 4752 please refer to the Android separate documentation package The GPS software delivery for Android based platforms is discussed here for 4750/4751

The IPC between Broadcom's GPS system and the Android framework is implemented as follows.

android_ipc_diagram.png

There are two different builds to make in order to integrate our GPS solution to Android based platform.

  • glgps_<CUST><PROJ>android: This is the GPS engine which is enclosed in a Linux daemon binary. This is the built output of customers/<CUST>/Make.<PROJ> makefile.
    • Note that this is based on the linux driver. This driver isn't really different from the one for Linux as we only rely on libc/libstdc++ to link against, and all the paths are configurable, we don't have to do major changes to the code in order to make it work in Android's native environment.
  • GPS JNI middleware: In Froyo and older Android versions, this file is named libgps.so. In Gingerbread and newer Android versions, this file is named gps.($TARGET_BOARD_PLATFORM).so. Make sure TARGET_BOARD_PLATFORM is set appropriately in your build. This is the interface library between Java and the native world. Two different versions of this library have been developed so far. The first one was based on the example code in the Android tree in order to parse the NMEA and the second one is based on the Broadcom interface to talk to the daemon. We currently use the second version. Also note that some customer may choose to directly build from the code in allPartners/deliverables/middleware_connectors/* instead of using the library created by Broadcom.

Preparing the environment

To be able to build we need to get the Android source code. Follow the instructions at http://source.android.com/source/download.html . Note that Gingerbread and newer requires Java 6 and a 64-bit OS. Froyo and older requires Java 5.

For Java 6 (Gingerbread and newer), do the following steps:

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo add-apt-repository "deb-src http://archive.canonical.com/ubuntu lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk
$ sudo update-java-alternatives -s java-6-sun

For Java 5 (Froyo and older):

$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper main multiverse"
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper-updates main multiverse"
$ sudo apt-get update
$ sudo apt-get install sun-java5-jdk
$ sudo update-java-alternatives -s java-1.5.0-sun 

Additional software to install from http://source.android.com/source/download.html follows:

$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev
$ sudo apt-get install valgrind 

To get the Android source, you must install Repo:

$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl http://android.git.kernel.org/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

To initialize a Repo client and get the Android source:

# Create an empty directory to hold your working files:
$ mkdir directory
$ cd directory
# Run repo init to bring down the latest version of Repo with all its most recent bug fixes. You must specify a URL for the manifest, which specifies where the various repositories included in the Android source will be placed within your working directory.
$ repo init -u git://android.git.kernel.org/platform/manifest.git
To check out a branch other than "master", specify it with -b:
$ repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake
# To get the files
$ repo sync 

To build the Android source:

$ cd ~/directory
$ source build/envsetup.sh
$ lunch
$ make

In order to compile a specific project (a specific Android.mk file) you should do:

make -C android_root_path files ONE_SHOT_MAKEFILE=/absolute/path/to/my/Android.mk

Or this is what you can do from the Android path:

. build/envsetup.sh
mmm /absolute/path/to/my/Android.mk

By default (for standard libraries and execs binaries) it will be copied to system/lib or /system/bin

GPS driver build

The build environment can be launched the same way it is done with the UNIX builds but it will call the makefiles specific for Android. Doing that we don't have to deal with the compiler (specific compiler options, paths...) and it could be integrated into the target platform makefiles that the user has defined for their whole Android build. Our builds become more generic as it could be compiled for any hardware platform defined by Android.

Normally the Android makefiles are named like: Android.mk

Build Options

There is only one config makefile where all the specific settings for the build are defined. We have makefile in customers/<CUST>/Makefile.<CUST><PROJ>android. For example, this is the sample configuration:

OUT_DIR:=$(shell pwd)/$(dir $(lastword $(MAKEFILE_LIST)))/build_out
ANDROIDPATH      ?= /usr/local/cross/android

CONFIG_HAL_SERIAL_TYPE=UART
CONFIG_HAL_SERIAL_DEV=/dev/tty<your_serial_port>
CONFIG_HAL_CMD=yes
CONFIG_HAL_CMD_FILE=/cache/glgpsctrl
CONFIG_HAL_LTO=yes
CONFIG_HAL_LTO_DIR=/data/gps/
CONFIG_HAL_LTO_FILE=lto.dat
CONFIG_HAL_NMEA_PIPE=yes
CONFIG_HAL_NMEA_FILE=/cache/gpspipe
CONFIG_HAL_NV=yes
CONFIG_HAL_NV_DIR=/data/gps/
CONFIG_HAL_NV_FILE=gldata.sto
CONFIG_HAL_RRC=no
CONFIG_HAL_GPIO_SYSFS=yes
CONFIG_HAL_CATCH_SIGNALS=yes
CONFIG_HAL_EE_DIR=./gps/
CONFIG_HAL_EE_FILE=cbee.cbee
CONFIG_HAL_LCS_API=yes
CONFIG_HAL_LOG_ANDROID=yes
CONFIG_HAL_TIME_MONOTONIC=yes
CONFIG_HAL_LBS=yes
CONFIG_HAL_FRQ_CUSTOM=yes
CONFIG_HAL_SUPL=true
ENABLE_TLS=yes

HAL_XTRA_SRCS:=<PROJ>/glhal/<your_file1>.c \
               <PROJ>/glhal/<your_file2.cpp

TARGET_RELEASE_CFLAGS=<your_optimization_flags> 
  • CONFIG_HAL_SERIAL_DEV: path The path to serial ASIC UART device
  • CONFIG_HAL_CMD: yes/no Whether we will use IRM commands or not
  • CONFIG_HAL_CMD_FILE: path file to cmd The pipe that will listen for IRM commands
  • CONFIG_HAL_LCS_API: yes/no Whether we will use LCS API interface or not
  • CONFIG_HAL_CATCH_SIGNALS: yes/no SIGTERM and SIGINT are caught in order to do a clean exit
  • CONFIG_HAL_NMEA_PIPE: yes/no Enable nmea output thru a pipe
  • CONFIG_HAL_NMEA_TTY: yes/no Enable nmea output thru a TTY file
  • CONFIG_HAL_NV: yes/no Enable non-volatile ram
  • CONFIG_HAL_GPIO_SYSFS: yes/no Enables toggling gpio (standby and reset pin) using sysfs or proc files. This is our preferred way to deal with the IOs as it simple for us, we only have to config the path for the IO in the xml and for the kernel driver involved on the IO toggling this is one of the simplest way to expose the IO toggling to user space
  • CONFIG_HAL_NO_GPIO: yes/no gpio dummy functions (void functions) all platforms should have some way to toggle the IOs, this functions are for testing

This file will be only created to set the options (on another linux builds this file has these options + compiler specific ones)

Building Using Broadcom Makefiles

As mentioned before the project could be compiled using the same Makefiles options we've using so far. So in order to build the gll we could:

make -C vendor/broadcom/gps/proprietary/deliverables/gll_dev/project/make CUST=mycustomer PLATF=myplatform all
make -C vendor/broadcom/gps/allPartners/deliverables/glct/project CUST=mycustomer PLATF=myplatform all
make -C vendor/broadcom/gps/allPartners/deliverables/glhal/unix CUST=mycustomer PLATF=myplatform all
make -C vendor/broadcom/gps/allPartners/deliverables/glgpsapp/unix CUST=mycustomer PLATF=myplatform all

Assuming you have the following in your Platform Makefile "config makefile" "vendor\broadcom\gps\customers\broadcom\Makefile.*.mak". See Build Options - config makefile

ifeq "$(TOOLCHAIN)" "2_1"
ANDROIDPATH      ?= /usr/local/cross/android-2.1
else
ifeq "$(TOOLCHAIN)" "2_2"
ANDROIDPATH      ?= /usr/local/cross/android-2.2
else
ifeq "$(TOOLCHAIN)" "2_3"
ANDROIDPATH      ?= /usr/local/cross/android-2.3
else
ifeq "$(TOOLCHAIN)" "4_0"
ANDROIDPATH      ?= /usr/local/cross/android-4.0
else
ANDROIDPATH      ?= /usr/local/cross/android-2.1
endif #4_0
endif #2_3
endif #2_2
endif #2_1

To Target ECLAIR

make -C vendor/broadcom/gps/allPartners/deliverables/glhal/unix CUST=mycustomer PLATF=myplatform TOOLCHAIN=2_1 OUT_DIR=~/eclair_out all

To target FROYO

make -C vendor/broadcom/gps/allPartners/deliverables/glhal/unix CUST=mycustomer PLATF=myplatform TOOLCHAIN=2_2 OUT_DIR=~/froyo_out all

To target GINGERBREAD

make -C vendor/broadcom/gps/allPartners/deliverables/glhal/unix CUST=mycustomer PLATF=myplatform TOOLCHAIN=2_3 OUT_DIR=~/gingerbread_out all

To target ICE CREAM SANDWICH

make -C vendor/broadcom/gps/allPartners/deliverables/glhal/unix CUST=mycustomer PLATF=myplatform TOOLCHAIN=4_0 OUT_DIR=~/ics_out all

For Windows users, in case you are building using 64 bit VMWare Virtual Machine with a Shared Folder for the SDK pointing to your Windows OPERATING system, make sure you specify your OUT_DIR to link inside the VM to avoid the following error to occur the error "collect2: ld terminated signal 7 [Bus error]".

All the binaries will be generated in the *out* Android folder, that's the normal way it is when building for Android. On the system/bin a binary with the glgps will be created (this is our gps binary). and the customer can create their own system.img (the disk image) with the driver already there.

Any other intermediate binary will not be copied to the *system* tree

On top of this intermediate libraries the final binary will be copied to the customer folder as it was using the old Makefiles (so then any proprietary binary that the user needs to compile will be there, as it was before).

When we want to build the final binary, dependency libraries that are not built yet will be copied from the customer folder in case there is the library. (e.g. gll)

Building Using Android Makefiles

Customers may not want to use our makefiles that wrap the real Android makefiles, we may find some customers ask to bypass our makefiles and use only Android ones.

Each library can be compiled directly like: make -C /path/to/android files ONE_SHOT_MAKEFILE=/absolute/path/to/Android.mk

If we do that directly from gll, glct, glgps... then the config values will be set by default.

Let's say that we have a makefile that defines all the options we want to set (normally that's the file under the customers folder). Then we could make an Android makefile that includes these options plus the makefiles for each specific library and executable.

As an example:

LOCAL_PATH=$(call my-dir)
SOURCE_TOPDIR=$(LOCAL_PATH)/../../
DELIVERABLES_DIR=$(SOURCE_TOPDIR)/allPartners/deliverables
PROPRIETARY_DIR=$(SOURCE_TOPDIR)/proprietary/deliverables
GLCT_DIR=$(DELIVERABLES_DIR)/glct
GLGPS_DIR=$(DELIVERABLES_DIR)/glgpsapp
GLHAL_DIR=$(DELIVERABLES_DIR)/glhal
GLL_DIR=$(PROPRIETARY_DIR)/gll_dev
GLNET_DIR=$(PROPRIETARY_DIR)/glnet_dev

include $(LOCAL_PATH)/Makefile.Myandroidconfig
include $(GLL_DIR)/project/make/Android.mk
include $(GLCT_DIR)/project/Android.mk
include $(GLHAL_DIR)/unix/Android.mk
include $(GLGPS_DIR)/unix/Android.mk

Interface Build

The Android specific code is for the interface library. On most Android platforms the gps driver will not really differ from the generic linux driver.

The Android makefile and code are located at:

  • allPartners/deliverables/middleware_connectors/unix/gps_jni

It can be compiled as usual in Android e.g:

$ make -C android_root_path files ONE_SHOT_MAKEFILE=allPartners/deliverables/middleware_connectors/unix/gps_jni/Android.mk

By default standard libraries will be copied to /system/lib. In Gingerbread, the gps.($TARGET_BOARD_PLATFORM).so file will need to be copied to /system/lib/hw. When building for Gingerbread, the following can be added to Android.mk to copy the library to the correct place:

LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw

Setting Android to Use the GPS Driver

The gps driver binary should be launched from init. We should add an entrance in the init.rc

service gps-demon /system/bin/glgps -c /system/etc/glconfig.xml
    user root
    group root

If you have questions regarding init.rc setting, please refer to Initial Kickstart with the Customer if you are a Broadcom (F)AE..

For Froyo and older Android versions, in order to link our JNI interface against the JNI interface we should add this option to the BoardConfig makefile definition:

BOARD_GPS_LIBRARIES := libgps

Once you compile a new system image our interface will be used.

Testing with the Emulator

We can test with the emulator. To do that we need to tell the emulator which serial com port will be mapped to the emulator.

Install avd from http://developer.android.com/guide/developing/tools/avd.html and run:

    $ emulator -avd eclair -qemu -serial COM1=

settings for the COM port to be used in Android emulator:

android_emulator_com1_settings.gif

The previous command will map windows serial com port COM1 to /dev/ttyS2 on the Android virtual machine (ttyS0 and ttyS1 are already used for different things)

Android Integration

Integration Steps in Android for 4750/4751

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines