Android How-tos

From OMAPpedia

Jump to: navigation, search


[edit] Android Configuration Options

[edit] Audio


this define allows a dummy audio device to be built for initial testing. to use this option comment out other audio defines such as alsa:


[edit] Camera


this define allows a dummy camera device to be built for initial testing.

[edit] OMAP


this define enables a wide range of android enhancements targeted towards the usage of OMAP3 and OMAP4 platforms.

[edit] Root File System

[edit] Vendor Files

new with gingerbread, a vendor directory is now supported. the vendor directory is expected to be in the root directory. if your vendor directory is in another part of the file system, include a link to the correct directory:

ln -s /vendor /system/vendor

[edit] JAR Files

make sure that the /data and /cache directories are mounted read/write or you will get errors reporting that some of the jar files needed for the JNI are not found.

[edit] GFX Suppport

[edit] Verify Lib GFX Version

cd /system/vendor/lib/egl
ls -al

lrwxrwxrwx 1 danders danders      40 2011-05-10 10:45 ->
-rw-r--r-- 1 danders danders   20192 2011-05-10 10:45
lrwxrwxrwx 1 danders danders      46 2011-05-10 10:45 ->
-rw-r--r-- 1 danders danders 3331116 2011-05-10 10:45
lrwxrwxrwx 1 danders danders      43 2011-05-10 10:45 ->
-rw-r--r-- 1 danders danders 2955632 2011-05-10 10:45

each GFX library file with have an extension with the library version number. in this example the version is 4403

Another way to tell the DDK version of the user mode binaries is to run "strings" on the binary

strings /system/vendor/lib/ | fgrep build
1.4 build

This DDK is version, or sometimes shorthanded to as 468. Note that all version numbers are significant, and as such is not the same as

[edit] Verify Kernel GFX Version

cat drivers/gpu/pvr/pvrversion.h | grep -e PVRVERSION
#ifndef _PVRVERSION_H_
#define _PVRVERSION_H_
#define PVRVERSION_FILE "eurasiacon.pj"

to check the version of GFX inside the kernel source, look at the drivers/gpu/pvr/pvrversion.h file.

cat /proc/pvr/version
Version (release) omap_sgx_android
System Version String: SGX revision = 1.2.0

to check the version of GFX from a running linux kernel, cat the /proc/pvr/version file.

this version information needs to match that of the GFX libraries on the android root file system.

[edit] Memory Allocation

Android defaults to using two framebuffers for page flipping. in order to support this memory for the video subsystem needs to be allocate properly as part of the boot arguments:

vram=32M omapfb.vram=0:16M

these boot args allocate 32M for the video subsystem and then sets the display 0 to use 16M (half) for the primary portion of the display.

For large screens (i.e. 1920x1200), it is necessary to double the amount of video memory:

vram=64M omapfb.vram=0:32M

If you have failed to allocate the memory properly you may receive one or more of the following errors:

I/SurfaceFlinger( 1198): SurfaceFlinger is starting
I/SurfaceFlinger( 1198): SurfaceFlinger's main thread ready to run. Initializing graphics H/W...
E/SurfaceFlinger( 1198): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
E/FramebufferNativeWindow( 1198): couldn't open framebuffer HAL (Bad address)


I/SurfaceFlinger( 1198): SurfaceFlinger is starting
I/SurfaceFlinger( 1198): SurfaceFlinger's main thread ready to run. Initializing graphics H/W...
E/SurfaceFlinger( 1198): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
E/FramebufferNativeWindow( 1198): couldn't open framebuffer HAL (No such device)

Note: The above error messages could also be due to a mismatch in kernel/library versions of GFX drivers. Make sure they have the same version number. Refer to:

[edit] Run Android Application from Command Line

Sometimes, we want to launch an UI app from command line. This can be accomplished using the ‘am’ command. The ‘am’ command syntax is as follows:

am start [-a <action>] [-d ] [-t <mime_type>] [-c <category> [-c <category>] ...] [-e <extra_key> <extra_value> [-e <extra_key> <extra_value> ...] 
[-n <component>] [-D] [<uri>]


To play video:

am start -n -d /sdcard/AV_000574_nieve_H263_CIF_384kbps_30fps_AAC_128kbps_48khz.mp4

To play music:

am start -n -d  {file_uri}

For more info, refer to

[edit] Work Flow: Code Changes

  1. Setup your environment from the root of your Android folder:
  2. $ source build/ 
    $ setpaths 
  3. Make changes to your source code
  4. Build your module
    1. From folder with your source code changes (builds only your specific component):
    2. $ mm 
    3. OR if there is some weird dependencies (i.e OMX):
    4. $ mmm <specify directory of specific> 
    5. OR from any folder you can build from the root:
    6. $ m 
  5. Sync environment to target
    1. If you are using binaries built from your environment: From your Blaze terminal (TeraTerm/Minicom/Cutecom) prompt (if eMMC filesystem)
    2. $ adb remount

      From your Linux box prompt

      $ adb kill-server 
      $ adb sync 

    3. If you are using pre-built binaries and only building specific component (might be other methods, but this is the way I do it): From your Blaze terminal (TeraTerm/Minicom/Cutecom) prompt (if eMMC filesystem)
    4. $ adb remount

      From your Linux box prompt

      $ adb kill-server 
      $ find $ANDROID_PRODUCT_OUT/system/lib -maxdepth 1 -name *.so -mmin -10 -exec adb push {} /system/lib \; 

      You will want to change the find parameters appropriately for your changes

  6. Test and Repeat

[edit] Android Scripting Environment

You can write python scripts on computer and run them on the target. This is possible using adb's port forwarding. First, start an ASE interactive terminal in Python. Take note of the AP_PORT variable at the top of the terminal. Next, set up adb port forwarding and set the AP_PORT environment variable locally.

example: $ python2.6 
Python 2.6 
Type "help", "copyright", "credits" or "license" for more information. 
 >>> import android        NB: The ASE module should be on your sys.path. 
 >>> droid = android.Android() 
 >>> droid.makeToast("Hello from my computer!") 

More info and examples using image gallery and web browsing:

[edit] Debugging Segmentation Faults

Normally we get the backtrace for the seg fault prints in the device console. For analyzing it using the PC value and tracing them to code, kindly refer to my new post in Omappedia:

In some cases we might get Server died message or binder failure as below:

W/AudioSystem( 1000): AudioFlinger server died!
W/MediaPlayer( 1000): MediaPlayer server died!
W/AudioSystem( 1000): AudioPolicyService server died!
I/ServiceManager(  937): service 'media.audio_flinger' died
I/ServiceManager(  937): service 'media.player' died
I/ServiceManager(  937): service '' died
I/ServiceManager(  937): service 'media.audio_policy' died
W/MediaMetadataRetriever( 1140): MediaMetadataRetriever server died! 

It is possible that such scenarios are also caused by seg faults but they are not printed and we would be left clueless.

Inorder to confirm that are no seg faults we can enable additional user space fault prints for debugging purpose.

In the kernel: arch/arm/mm/fault.c file, Within function __do_user_fault () we can enable the CONFIG_DEBUG_USER or just comment the macro and user debug condition so that back trace is printed in case of any fault.

The steps mentioned in the Wiki link above can be used to analyze the seg fault trace

[edit] Open Source Means Participation

No opensource project can be successful without people participating in it. Since many people on the Android team are a little new to opensource and to Linux, I thought I would start my first tip with some advice: participate.

To that end, you must be a learner and a do-er. The best tip I can give regarding this is to start using Internet Relay Chat (IRC). You can listen in and learn from people, you can ask your own questions and learn directly, and when ready you can answer others questions and influence the community in a positive way.

For starters:

  1. Join server. You can get a nice GUI app for any OS these days - on Ubuntu Linux, I like XChat.
  2. Create (AND REGISTER) a nick-name with the freenode NickServ.
  3. Join the #linux-omap channel at minimum.
  4. Browse the channel list and pick topics that are relevant to you. As an audio aficionado , I constantly listen/learn and participate on #alsa and #alsa-soc channels. You can certainly find channels for your domain as well. I know there are channels speficif to V4L, DSS, BlueZ, etc. You can also learn alot on the #ubuntu-arm channel. I have noticed a recent increase in TI presence here since our L23 GL efforts have started making Ubuntu releases for OMAP...
  5. Explore, don't be shy. Ask a question if you have one; challenge some one else's answer if you don't agree 100%. After all, in opensource, the goal is always to be better.

[edit] GIT: Temporarily setting aside work in progress

While you are in the middle of working on something complicated, you find an unrelated but obvious and trivial bug. You would like to fix it before continuing. You can use 'git stash' to save the current state of your work, and after fixing the bug (or, optionally after doing so on a different branch and then coming back), unstash the work-in-progress changes.

$ git stash save "work in progress for foo feature" This command will save your changes away to the stash.

And reset your working tree and the index to match the tip of your current branch. Then you can make your fix as usual. ... edit and test ...

$ git commit -a -s After that,

You can go back to what you were working on with git stash pop:

$ git stash pop

You can also stash several things at the same time just by giving a different name for the stashed item. Like, git stash save "item1" some more modifications... git stash save "item2" Both item1 and item2 will be present in the stash and can be fetched at a later point.

You can view all items in the stash by typing git stash list Suppose you want to fetch item1 back again, you can do that by typing

$ git stash apply stash@{1}

For more details try

$ git stash –help

If you don't want to think of a fancy name for the work you are saving you can just run,

$ git stash

This doesn't require you to use "git add" to select which files to save, as it saves all files with changes made to them. Also this will autogenerate a name including the branch you are on and the latest commit id. E.g:

stash@{1}: WIP on p-android-omap-2.6.35-dpllcascade-jonathan: ef4d2b9 OMAP4: OPP25 for ABE

Also know that when get stash is run it will wipe out all changes in your working dir that are not in the staging area (i.e, git add ...). So if you have three files with changes named f1, f2 & f3 and you run the following,

git add f1 f2
git stash save "saving f1 and f2 for later work"

Then the changes made to f3 will not be saved, and will be wiped out. This is dangerous because you might think that the changes to f3 will remain in your working directory, but unsaved. Instead they'll be gone forever :-(

[edit] Color coding logcat output for easier debugging

You can pipe your adb logcat output through the attached Python script to get started, or you can run the script directly to invoke adb:

$ adb logcat | ~/$ ~/ 

The ouput will be colored to point out various sections in the log Reference:

[edit] Making Ctrl+C work in Android console

If you have ever faced an issue, that the console hangs, and "Ctrl+C" doesnt work, you can add the following to variable to your bootcmd (make sure that you set the right ttyS port for your platform) androidboot.console=ttyS3

[edit] Getting su work from serial console

In some cases running su to get superuser privileges will not work from the serial console. You may get a permission denied error.

shell@android:/ $ su
su: permission denied

To fix this, get to superuser mode from adb shell. (You may have to run adb root first.) Then change the permissions on the su binary:

chmod 6755 /system/xbin/su

[edit] Disabling screen lock forever

Screen lock can be disabled for development, prolonged tests by

#sqlite3 /data/data/ 
#sqlite> update system set value="-1" where name="screen_off_timeout"; 
#sqlite> .quit 

..or via UI,

Settings->Applications->Developers -> Stay Awake 

This will avoid android to lock the screen, but still system wide suspend might happen

Hence System wide suspend can be prevented by helding wakelock.

echo test > /sys/power/wake_lock

[edit] Booting with Unlocked Screen

To always boot with unlocked screen make the following change to frameworks/base/policy/src/com/android/internal/policy/impl/

diff --git a/phone/com/android/internal/policy/impl/ b/phone/com/android/internal/policy/impl/ 
index c255041..c602c1b 100644 
--- a/phone/com/android/internal/policy/impl/ 
+++ b/phone/com/android/internal/policy/impl/ 
@@ -553,7 +553,7 @@ public class KeyguardViewMediator implements KeyguardViewCallback, 
             if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen"); 
-            showLocked(); 
+            //showLocked(); 

[edit] Auto-add reviewers to your patches

If you submit a large number of patches, or even if you just feel burdened by the extra steps required to add reviewers to yourpatches in Gerrit, this tip is for you...

No longer will you need to open your browser and manually type names for each patch.

You can set up your git config to automatically add certain reviewers to each patch (i.e. maintainer, team-lead).

For example, I auto-add a team member to each patch I send to kernel by adding these to my .git/config.

[remote "for-k32"] 
    url = oz:kernel/omap 
    receivepack = git receive-pack 
    push = HEAD:refs/for/p-android-omap-2.6.32

Note: oz is an alias for omapzoom review site in my ~/.ssh/config

Then you can simply use

# git push for-k32

to upload changes. As the linked site mentions, you can specify multiple reviewers this way. You can also specify multiple aliases for your remote/upstream and specify different reviewers for each.

You could also choose to put this in your global .gitconfig, though I prefer to use this in each specific git tree .git/config.

More info here:

[edit] To Clean Build a Subdirectory (mm -B)

Top up tips on cleaning build.

mm -B


$MYDROID/hardware/ti/omap3/liboverlay> mm -B 

Real handy when you update just a .mk file, but not a header/source file, in which case a incremental build wont build the changes as intended. Works well with single liibarary, and so should multiple libraries (yet to confirm sanity of multiple libraries)

make clean-


$make clean-libOMX_CoreOsal   (cleans 
$make clean-libOMX_Core clean-libOMX_CoreOsal  (cleans,

[edit] Use "repo" to Push Patches

repo can manage the branches where the patches will be submitted. This is dependent of the manifest and as long as it is aiming to the correct project branch then your patch will be submitted always to the correct branch.

So replace the following command

$ git checkout -b mybranch 


$ cd ${Some Project} 
$ repo start mybranch . 

don't forget the dot at the end.

Then work as usual, commit your change and then push your patch to gerrit.


$ git push ssh://$ mybranch:refs/for/somebranch 
$ cd ${Some Project} 
$ repo upload . 

Don't forget the dot at the end

If there are multiple branches on your project repo will instruct you to choose the correct one

[edit] Create and Insert a Unique Change-Id Line During git commit

Gerrit Code Review provides a standard commit-msg hook which can be installed in the local Git repository to automatically create and insert a unique Change-Id line during "git commit". To install the hook, copy it from Gerrit's SSH daemon:

# cd <git project>/ 
# scp -p -P 29418 <username> .git/hooks/ 

With the Change-Id in place any patch can be identified across all drafts of it. With this information a new version of the patch/Change can be associated to its original review, even across cherry-picks and rebases

[edit] Git Usage Tips

TIP#1: Generating and applying .patch files with GIT If you ever wanted to send someone a .patch file from git, use the below command that generates patch files for every commit starting from commit id1 to commit id2

git format-patch <commit-id1>... <commit-id2> 

...and to apply a patch created using the above command to your git log

git am <.patch file name> 

TIP#2: Finding out if you are on the right tag You want to absolutely make sure your current commit is pointing to the official release tag, then you can use the following git command. This prints out the tag corresponding the latest commit on your branch

git describe --exact-match HEAD

[edit] Recovering Lost Commits

So, you just did a git reset --hard HEAD^ and threw out your last commit. Well, it turns out you really did need those changes. You’ll never be able to implement that algorithm that perfectly twice, so you need it back. Don’t fear, git reflog should help you recover your lost commit. Type the following commands

git reflog 

This will spit out the history of the commands executed so far:

2e5a0e8 HEAD@{0}: 2e5a0e89f2eff1146eedfb93a19ab76aff154c65: updating HEAD 
8431bc0 HEAD@{1}: commit: OMAP4 CameraHAL: VSTAB updates 
2e5a0e8 HEAD@{2}: commit: OMAP4 Camera HAL: Support for sensor selection inside CameraAdapter 
6f20714 HEAD@{3}: HEAD^: updating HEAD 
0ce00d9 HEAD@{4}: commit: OMAP4 Camera HAL: Support for sensor selection inside CameraAdapter 
6f20714 HEAD@{5}: commit: OMAP4 CameraHAL: Adding prints to dump the 3A parameters in OMXCameraAdapter. 
0819baf HEAD@{6}: checkout: moving from 0819bafb16173174de22a0a002f6fb9a00f88854 to patch 
0819baf HEAD@{7}: checkout: moving from ac629516642b934c6fdb82bff7777109f06df13b to 0819bafb16173174de22a0a002f6fb9a00f88854

The commit in bold is the one you thought you lost, you can then recover that commit by executing

git merge 8431bc0

[edit] Measure Yourself Against Your Team

Measure yourself against your team Have you ever wondered how many patches you have contributed to a project?. Well, git has a nice way to do it

git shortlog -s -n 

This prints the number of commits against the author's name. Try it for yourself and see.

[edit] Speed Up Repo Sync

Whenever you do repo sync for the first time on a project, you should back-up the .repo/projects folder.

Assuming that the projects folder is backed up in ~/mydroid_latest, you can use the following commands

The steps I follow are:

repo init -u git:// -b gingerbread 
cp -r ~/mydroid_latest/projects .repo/ 

Doing this will avoid the ~6 Gb download that repo sync does.

Once the copying is finished, you can do

repo sync 

and it will only download the new code that was added to the repo using the manifest file, that was used to init the repo

[edit] Android Debug Commands

Some handy debug tools...

LOGCAT No tips required though. A hint is: we can filter logcat messages using LOG_TAG field and flags V/D/I/W/E/F/S (corresponds from LOGV verbose to LOGE error, silent)

logcat TIOverlay:V  OMXCodec:D *:S  prints TIOverlay’s all logs, OMXCodec’s only LOGE/LOGD/LOGI logs, but suppresses rest. 

DUMPSYS Dumps state of whole system

    dumpsys meminfo   Displays breakup of memory usage by a process 
    dumpsys meminfo            Displays breakup of memory usage of all process 
    dumpsys                          Displays whole system status

DUMPSTATE Same as dumpsys, prints extra system debug information starting from bootargs, /proc/meminfo, etc...

BUGREPORT Supposed to save logcat, dumpsys, dumpstate data to file. But just prints as trace today in éclair/froyo

Source of these utilities can be found at native app section ./frameworks/base/cmds/

More Info:

[edit] Kernel Traces - On the Go

To get a snapshot of kernel trace buffer


To enable complete kernel traces

echo 8 > /proc/sys/kernel/printk 

To disable complete kernel traces

echo 0 > /proc/sys/kernel/printk

[edit] Repo Commands and Their Equivalent git Commands

Occasionally the repo commands fail. Whenever such a problem occurs try using git equivalent commands:

1. repo start  local_branch_name . 
->  GIT: git checkout -b local_branch_name 
2. repo upload local_branch_name 
-> GIT: git push ssh:// :refs/for/remote_branch_name (froyo, p-froyo etc) 
3. repo upload --replace (to replace a patch) 
-> GIT: git push ssh:// :refs/changes/patch_id

[edit] Finding Your Kernel Version

Here is a quick way to find the kernel version you are using. At the command prompt type:

cat /proc/version

The output from this will look something like the below:

Linux version (x0066741@autumn) (gcc version 4.4.1 (Sourcery G++ Lite 2010q1-202) ) #1 SMP PREEMPT Mon Apr 18 03:
09:42 CDT 2011

In this example 16bf9a3 is the commit ID this Kernel is based on.

[edit] Find What Changed in a subdir of a git Tree

Have you ever needed to find what was recently changed on a specific module or functional block of code? In many git trees like the kernel tree, there are many times where knowing the patches that were made on a specific subdir can help you know what a test suddenly fails, or why something is not working as expected. Try this:

git log -my-sub-tree- 

For example, to see recent changes in the omap specific audio driver you could use

git log sound/soc/omap 

This can be especially nice if you know the last working version and there are not many changes to look at... in this case, you can specify a time in history to begin your log:

git log some-SHA my-sub-tree 

Or, back to the audio example to see what changed since commit=c0ff3e you can use

git log c0ff3e.. sound/soc/omap 

Happy git-logging!! More info found at man git-log

[edit] Compiling latest Android SDK version

When using Android SDK + Eclipse to develop or debug an application downloaded a Android image can be a pre-release version, to compile the current version follow next procedure;

These instruction can be found in


or for Icecream Sandwich


Following the procedure Download code at or using a release notes for specific target, then compile it with next steps. -Depending on the version of Android you are compiling select one option, check for what device you are compiling, the folder's location can change, this instruction comes in Accessing_Source_Code in Android compilation instructions.

check you are located in $MYDROID directory

in Froyo, GingerBread, HoneyComb

cp device/ti/blaze/ ./

in Icecream Sandwich

lunch blaze_tablet-userdebug  # (for Blaze Tablet)


lunch full_blaze-userdebug  # (for Blaze)

or run command "lunch" alone for a list of options.

then run next commands from $MYDROID

source build/
make sdk 

This will create out/host/darwin-x86/sdk/ output file, or one named according to the selected version. Follow installation steps from in order to install just compiled package in your environment;

The instructions to build "ADT plug-in" can be found in this document too. This are build instructions in mentions about using Eclipse specific RCP/Plug-in use the one indicated in the file;

Depending on Android version that you use, the script location ADT plugin can change:

$MYDROID/development/tools/eclipse/scripts/ ~/mysdk $USER

or for Icecream Sandwich


Read howto_build_SDK.txt file and follow compilation instructions.

Notes: Try to do a backup copy of Android SDK that just compiled before compiling "ADT plug-in", previously generated files are erased.

[edit] Faster Git Clones

Any git tree clone can be made much faster using the "--reference" option in clone command.

Eg: Fast Kernel clone when you already had an old kernel clone in kernel-old/ folder.

git clone git:// --reference kernel-old/

[edit] Run-time Debug (and module) Parameter Access

Did you know that you can access kernel module parameters at run-time via sysfs under /sys/module//parameters/?

Many parameters are read-write, allowing you to change it during runtime. Here are a few parameters to try:

/sys/module/omap_vout_mod/parameters/debug (0=off, 1=on) – OMAP V4L2 debugging /sys/module/omapfb/parameters/debug (0=off, 1=on) – FB debugging /sys/module/videobuf_core/parameters/debug (0=off, 1=on, 2=more) – V4L2 buffer handling debugging /sys/module/binder/parameters/debug_mask – Binder debug levels:

       BINDER_DEBUG_USER_ERROR             = 1U << 0, 
       BINDER_DEBUG_DEAD_TRANSACTION       = 1U << 2, 
       BINDER_DEBUG_OPEN_CLOSE             = 1U << 3, 
       BINDER_DEBUG_DEAD_BINDER            = 1U << 4, 
       BINDER_DEBUG_READ_WRITE             = 1U << 6, 
       BINDER_DEBUG_USER_REFS              = 1U << 7, 
       BINDER_DEBUG_THREADS                = 1U << 8, 
       BINDER_DEBUG_TRANSACTION            = 1U << 9, 
       BINDER_DEBUG_FREE_BUFFER            = 1U << 11, 
       BINDER_DEBUG_INTERNAL_REFS          = 1U << 12, 
       BINDER_DEBUG_BUFFER_ALLOC           = 1U << 13, 
       BINDER_DEBUG_PRIORITY_CAP           = 1U << 14, 

You can set the parameter by writing into the file, e.g. “echo value > file”. Read with “cat file”.

[edit] gedit-plugins to make gedit easier to use.

For Ubuntu\GNOME distribution gedit provides a set of useful plugins

You can use either synaptic or apt-get to install the package gedit-plugins;

Set of plugins for gedit gedit-plugins contain a set of plugins for gedit, GNOME's text editor.

The following plugins are included:

Then just go to menu\edit\preferences\plugin to select which one to use.

[edit] repo forall: One Shell Command for All the Projects

"Repo forall" is a very useful tool to run a command in each project of your repository or in a particularly list of projects.

For example if I want to create a branch in all the projects:

[MYDROID]$ repo forall -c "repo start my-branch ." 

Or if you prefer to create a branch is some specific projects (i.e. build and bionic):

[MYDROID]$ repo forall build bionic -c "repo start my-branch ." 

What about a "git reset" in all projects:

[MYDROID]$ repo forall -c "git reset --hard HEAD" 

USAGE: repo forall [project-list ] -c command [arg. ..]

[edit] The Power of Rebasing a Commit

Rebasing a commit is very powerful. It allows you to perform actions on a commit

  1. Change the wording on a commit
  2. Squash changes from one commit to another
  3. Remove commits
  4. Update your branch to the latest version for submission.

First what does squash mean? Squash means that you merge the changes from one commit to another commit.

The command to rebase is

git rebase -i HEAD~X  

Where X is the number of commits that need to be rebased. In most cases it is all of the commits that you have committed on a single branch. Failure to include all of the branches may result in the missing commits to be removed from your branch.

Once you are in the interactive rebase screen you have multiple options

  1. reword
  2. squash
  3. edit
  4. pick
  5. fixup

For this tip we will talk about pick and squash. To use this properly you need to place the commit with the recent changes directly under the commit that you want your new changes to be merged into.

Below is an example: I committed two changes to the same branch. Once both changes were committed I typed

git rebase -i HEAD~2 

Then git presented me with this screen:

pick 626d57f This is my original commit 
pick daef8c4 This is a change on the first commit 
# Rebase a430036..daef8c4 onto a430036 
# Commands: 
#  p, pick = use commit 
#  r, reword = use commit, but edit the commit message 
#  e, edit = use commit, but stop for amending 
#  s, squash = use commit, but meld into previous commit 
#  f, fixup = like "squash", but discard this commit's log message 
# If you remove a line here THAT COMMIT WILL BE LOST. 
# However, if you remove everything, the rebase will be aborted. 

In order to squash the second commit into the first I change the second line so that the entry looks like this

pick 626d57f This is my original commit 
squash daef8c4 This is a change on the first commit

Then I saved the file. If the merge does not go through successfully you will need to resolve any conflicts. Otherwise git will present you with this screen:

# This is a combination of 2 commits. 
# The first commit's message is:

This is my original commit

Change-Id: Icf1644927afd03c208d6295430d7192893182017 
Signed-off-by: Dan Murphy 
# This is the 2nd commit message: 
This is a change on the first commit 
Change-Id: I7f23258a35d7ec1dc6bfa7bb9ea102d9388e836a 
Signed-off-by: Dan Murphy

Now here is where you have a choice as anything you leave in here will show up in the git log. So I usually comment out the second commits message like so.

# This is a combination of 2 commits. 
# The first commit's message is: 
This is my original commit 
Change-Id: Icf1644927afd03c208d6295430d7192893182017 
Signed-off-by: Dan Murphy 
# This is the 2nd commit message: 
#This is a change on the first commit 
#Change-Id: I7f23258a35d7ec1dc6bfa7bb9ea102d9388e836a 
#Signed-off-by: Dan Murphy

Once you have made these changes (if you choose to do so) then you just have to save the file.

So you have successfully squashed two commits. Now you can re-push these changes to Gerrit and the change should show up as another patchset. There is no limit to the number of rebases you can do on a single commit. You can rebase every change you made in one single rebase activity.

Now if you have commits between your last change and the change you want to squash then you merely need to move the changes directly under the commit that it should be merged into. See below for an example.

pick 626d57f This is my original commit 
pick 12345df This is an unrelated change that will not squash 
pick daef8c4 This is a change on the first commit

Move the commit and then change pick to squash: (NOTE: DO NOT DELETE ANY COMMITS HERE OR THEY WILL BE LOST!!!!)

pick 626d57f This is my original commit 
squash daef8c4 This is a change on the first commit 
pick 12345df This is an unrelated change that will not squash

Then continue as you did before. With the commit message and a repush.

For more information you can type:

git rebase --help 

At the command line

[edit] git gc /prune: Reduce Disk Space and Increase Performance

A git project contains an object database which gives a lot of power to git in self. This database contains 3 basic elements: trees, commits and blobs With the time this database increases and many of the objects become unnecessary due to many regular operation like rebase, amend, delete, etc "git gc" will run some housekeeping tasks within the current repository, such as compressing file revisions and removing unreachable object By adding the "--prune" option, "git gc" will packs objects and also deletes loose object The result is a more efficient disk space usage which also increases the performance of your repository.


[MYDROID]$ repo forall "git gc --prune" 

or if you are interested only in deleting all unreachable objects from the object database then you can use:

[MYDROID]$ repo forall "repo prune ." 


[MYDROID]$ repo prune <project name>

[edit] ADB Usage

The Android Debug Bridge, aka ADB, is used to interface with Android devices over USB or TCP connection.

ADB can be used to:

  1. Access the command line of a device
  2. Reboot the device to the operating system or to the bootloader
  3. Access the logcat logs in the device.
  4. Push or pull libraries to/from the device
  5. Install or unintstall apks (Android applications).
  6. Obtain Android bugreports.

Below is the list of commands for each scenario above.

  1. adb shell - Will log you into the device and allow you to access the devices command line
  2. adb reboot - Will reboot the device to the OS. abd reboot bootloader - Will reboot the device into the boot loader
  3. adb logcat - Will log into the device and print the logcat output to the terminal window used. The output can be redirected to a file on the host if the host supports redirection.
  4. adb push - This command will push the a library from the source directory (generally the out directory of the build) to the destination (generally the location in the device that the library will be loaded)
    adb pull - This command will pull the library from the device and copy it to the host location specified.
  5. adb install - This will install an application into the device. This command will fail if the application already exists or if the Android SDK is not supported by the application.
    adb uninstall - This will uninstall the application only not the support or data stored for the application.
  6. adb bugreport - This command will print to terminal window that the command was typed. The output can be redirected to a file on the host if the host supports redirection.

For more information use: adb help- At the command line

[edit] ADB over ethernet

  1. Enable the network port. netcfg eth0 up;netcfg eth0 dhcp if needed. DHCP is enabled by default on target so no need to reserve static IP (ifconfig eth0 will display the IP address acquired).
  2. start adbd on target: setprop service.adb.tcp.port 5555; stop adbd; start adbd
  3. Connect to the adb daemon running on target.
  sudo adb root
  sudo adb connect <IP ADDRESS got from step 1>
  sudo adb devices (this should display the connected device)
  sudo adb remount
  sudo adb <any commands like push etc>
  sudo adb reboot (this hangs forever we have to explicitly do CTRL C)

[edit] Verbose Logs

All verbose LOGV logs will appear only if macro LOG_NDEBUG is enabled with value 0 during compilation (“#define LOG_NDEBUG 0”)

For debugging purpse, we can enable LOGV like,

#define LOG_NDEBUG 0 

[edit] Prelinking in Android

Ever wondered how stagefright library (say) is loaded at same address irrespective of different processes?

cat /proc/1410/maps  (system server) 
cat /proc/1357/maps  (mediaserver) 
. . . 
a2f00000-a2faf000 r-xp 00000000 b3:12 22907      /system/lib/  (code-section) 
a2faf000-a2fb3000 rwxp 000af000 b3:12 22907      /system/lib/  (data-section) 
. . . provides predefined load addresses of registered libraries, so loading of libraries can be faster aiding faster boot, and making applications start faster, in a system like android with large number of libraries. 
# stagefright libraries     0xA3700000 # [~1M]       0xA3600000 # [~1M] 0xA3500000 # [

[edit] Clearing Airplane Mode

On our platforms (zoom/blaze) we have issue with Airplane mode. If you have accidentally enabled it, it's not possible to disable it.

Follow the procedure below to clear the setting...

//Launch sqlite3

sqlite3 /data/data/*/*/settings.db 

//After launching it, execute following command

> delete from system where name='airplane_mode_on'; 

Now restart the board

[edit] Switching Java Versions

After moving to Java 6 for Gingerbreads, you will have switch between Java versions for building Froyo and Gingerbread on the same machine.

Here are the instructions for doing that:

Step 1: Install Java 5

This method adds the Jaunty repositories and installs Java5 as the default java setting in the system. Open the sources file (/etc/apt/sources.list) for editing, as root

sudo gedit /etc/apt/sources.list 

and add:

deb jaunty multiverse 
deb jaunty-updates multiverse 

save the file and close gedit. Next sync your sources by running

sudo apt-get update 

and install

sudo apt-get install sun-java5-jdk 

Step 2: Update your ~/.bashrc file with following aliases

alias j5='sudo update-alternatives --config java && sudo update-alternatives --config javac' 
alias j6='sudo update-java-alternatives -s java-6-sun' 

Step 3: Close and re-open your terminal for these aliases to be effective

Step 4: Before starting FROYO build type j5 on your terminal and Before starting GINGERBREAD build type j6

[edit] Android Screen Capture

There is a nice way to capture screen shots of Android device using android SDK tool (ddms.bat)

The video below explains how to use it...

(Works on blaze)

[edit] Building Gingerbread from 32-bit Ubuntu

ifneq (64,$(findstring 64,$(build_arch)))
ifneq (i686,$(findstring i686,$(build_arch)))



sudo apt-get install lib64z1-dev libc6-dev-amd64 g++-multilib lib64stdc++6
sudo apt-get install sun-java6-jdk

If you receive the next error: E: Package 'sun-java6-jdk' has no installation candidate, try the following

sudo add-apt-repository "deb maverick partner"

NOTE: replace maverick with your current distro name

sudo apt-get update
sudo apt-get install sun-java6-jdk

NOTE: If you still want to have the ability to make Froyo builds you will need to switch to Java 1.5. Use the following to switch Java versions:

To switch to Java 1.5 (needed for Froyo builds):

sudo update-java-alternatives -s java-1.5.0-sun

To switch to Java 1.6 (needed for Gingerbread builds):

sudo update-java-alternatives -s java-6-sun

If building from a 64-bit machine these additional libraries are needed:

sudo apt-get install lib32z1-dev lib32ncurses5-dev
sudo apt-get install g++-multilib
sudo apt-get install flex
sudo apt-get install gperf

[edit] eMMC boot: Quickly Flash Incremental Kernel

While repeatedly testing small changes on top of a kernel, below might be handy.

Have a folder ready with ramdisc, (and preferably all emmc binaries).,

<clean build kernel>

Have an alias to automate all the steps involved in building a kernel.

alias kinc='cd /data/build/kernel_l27x/omap;make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- -j4 uImage;cp arch/arm/boot/zImage /data/data/emmc/zImage;cd /data/data/emmc;  ./; ls -l;sudo ./fastboot flash boot boot.img'

<make kernel changes>
<run alias from any where, which builds,copies zimage, generates boot.img, flashes it in 1 command>


[edit] eMMC boot: Steps to Update init.rc Changes

<update init.rc, or init.omap4430.rc in device/ti/blaze as required.. then steps to create ramdisk.img, further boot.img and flash..>

out/host/linux-x86/bin/acp -fpt system/core/rootdir/init.rc out/target/product/blaze/root/init.rc 
out/host/linux-x86/bin/acp -fpt system/core/rootdir/init.omap4430.rc out/target/product/blaze/root/init.omap4430.rc 
out/host/linux-x86/bin/mkbootfs out/target/product/blaze/root | out/host/linux-x86/bin/minigzip > out/target/product/blaze/ramdisk.img 
cp out/target/product/blaze/ramdisk.img /data/data/emmc/ramdisk.img 
cd /data/data/emmc/ 
ls -l 
sudo ./fastboot flash boot boot.img

[edit] Parallelize Repo Sync

You can parallelize a repo sync by using the -j option. For example,

repo sync -j 4

will fetch up to 4 projects at a time. This way, you will still be able to fetch other projects while waiting for a single big project to sync up

[edit] Side-by-Side Comparison of Patch Sets in Gerrit

By default when you do a Side-by-Side diff in Gerrit the diff you see is the base on the left and Patch Set X changes on the right. However sometimes it is useful to be able to see what changed between two different Patch Sets. Gerrit supports this as well. To do this:

1. From a change record in Gerrit, click on the "Side-by-Side" link for the file you'd like to compare as usual. You will see a diff with base on the left, Patch X on the right. 2. In the upper left set of the page, click on the triangle next to the "Patch History" heading. You'll see something like this:


3. From here you can select which Patch Set to show on the left and the right, and click update to see the comparison.

[edit] An APK is Just a Zip File

An APK (Android Package) file is really just a zip file, so if you want to view the contents just rename it from Xxxxx.apk to and WinZip can open it.

[edit] Filtering Logcat Output

To reduce the log output to a manageable level, you can restrict log output using filter expressions

Every Android log message has a tag and a priority associated with it.

- The tag of a log message is a short string indicating the system component from which the message originates. - The priority is one of the following character values, ordered from lowest to highest priority:

   V — Verbose (lowest priority) 
   D — Debug 
   I — Info 
   W — Warning 
   E — Error 
   F — Fatal 
   S — Silent (highest priority, on which nothing is ever printed) 


If I am only interested in wpa_supplicant and WifiService logs I casn use the filter like this

logcat wpa_supplicant:V WifiService:V *:S

Source: Section "Filtering Log Output" in the below link

[edit] Further Detail on Logcat Logs

Usage: logcat [options] [filterspecs] 

You can control the logcat logs by specifying various options. For eg:

$ logcat –b events 
$ logcat –v time 
$ logcat <tag>:V *:S 

This will make the logs corresponding to <tag> verbose and rest all the logs to silent.

options include:

 -s                          Set default filter to silent. 
                              Like specifying filterspec '*:s' 
 -f <filename>         Log to file. Default to stdout 
 -r [<kbytes>]         Rotate log every kbytes. (16 if unspecified). Requires -f 
 -n <count>            Sets max number of rotated logs to <count>, default 4 
 -v <format>          Sets the log print format, where <format> is one of: 
                 brief process tag thread raw time threadtime long 
 -c              clear (flush) the entire log and exit 
 -d              dump the log and then exit (don't block) 
 -t <count>      print only the most recent <count> lines (implies -d) 
 -g              get the size of the log's ring buffer and exit 
 -b <buffer>     request alternate ring buffer 
                 ('main' (default), 'radio', 'events') 
 -B              output the log in binary 

filterspecs are a series of


where <tag> is a log component tag (or * for all) and priority is:

 V    Verbose 
 D    Debug 
 I    Info 
 W    Warn 
 E    Error 
 F    Fatal 
 S    Silent (supress all output) 

'*' means '*:d' and <tag> by itself means <tag>:v

If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS. If no filterspec is found, filter defaults to '*:I'

If not specified with -v, format is set from ANDROID_PRINTF_LOG or defaults to "brief"

[edit] Capture Baseline Snapshot using repo manifest

When you're ready to do a "repo sync" to sync to the latest baseline, it's a good practice to first capture a snapshot of your current baseline. This is helpful in cases such as when everything was working fine before a repo sync but not working after a repo sync. Comparing a snapshot of the working baseline to the non-working baseline can give valuable data points for debugging. Here's how to do this:

repo manifest -r -o oldbaseline.xml
repo sync
repo manifest -r -o newbaseline.xml

...then do a diff between oldbaseline.xml and newbaseline.xml to quickly see what changes could have caused the break.

[edit] Floating Pane Feature in Gerrit

When a patch involves many files for review, it can be tedious to use the left and right arrows to page through the files sequentially, or to select "Up to change" if you want to skip around. If you press the letter "f" you'll see a list of the files affected by the patch in a floating pane, allowing you to skip between them more easily.

Gerrit files.JPG

[edit] Coding Standards for User Space and Kernel Space

As you probably know, both the Kernel and the Android File System have their own unique coding standards that we should comply with. Each Open Source Community will expect your patches to be in the correct format. Here are where you can find the coding standards:


The coding standards can be found within your kernel download. To read them:

cat $YOUR_DIRECTORY_STRUCTURE/documentation/CodingStyle

Android Filesystem:

The coding standards are listed here:

Compliance with these coding standards are a good step towards looking professional to the open source communities we are dealing with.

[edit] Unlock home screen without touchscreen

To unlock the home screen from the console prompt, enter the following on the console/adb shell:

input keyevent 82

[edit] Boot Process Performance Visualization

Bootchart is a tool for performance analysis and visualization of the GNU/Linux boot process. Resource utilization and process information are collected during the boot process and are later rendered in a PNG, SVG or EPS encoded chart. Bootchart provides a shell script to be run by the kernel in the init phase. The script will run in background and collect process information, CPU statistics and disk usage statistics from the /proc file system. The performance data are stored in memory and are written to disk once the boot process completes. The boot log file is later processed using a Java application (or the web form) which builds the process tree and renders a performance chart in different formats To use Bootchart on an Android System, you need to perform the following steps:

sudo apt-get install bootchart
build 'init' with bootchart support
       $ cd mydroid 
       $ export INIT_BOOTCHART=true   
       $ make clean  
       $ make  
       $ touch system/core/init/init.c  
       $ m INIT_BOOTCHART=true
$ scp out/target/product/generic/root/init root@device:/
$ adb shell 'echo 120 > /data/bootchart-start'
$ system/core/init/
$ java -jar /usr/share/bootchart/bootchart.jar ./bootchart.tgz

Use any image viewer to examine the graphic, if you created a png image. If you output the graphic in SVG format, then you can open the file with an SVG-capable program (such as Inkscape or a web browser)

For more information:

[edit] Query All Changes in Gerrit

Has it ever happened that you had submitted a patch which never got merged either because it wasn't important or wasn't required at point of time, it was abandoned (not open) - And you need to find it now? Gerrit only shows the open, recently closed & the review requests of recent patches and not the ones which were abandoned years ago. The following query in the search bar of gerrit -> project:kernel/omap branch:p-android-omap-2.6.35 enables one to dig up really old patches.

[edit] Creating a Call Log

Since not many development boards are connected to modem, and making a call isn't really enabled, the following commands enables to create a fake call log in Android. note: The number of fields to enter might vary from pastry to pastry.

sqlite3 data/data/
insert into calls values (1, 1234, 20100420, 20, 1, 1, 'pqr', 1, 'abc'); - dialled
insert into calls values (2, 5678, 20100420, 25, 2, 2, 'mno', 2, 'tnt'); - received
insert into calls values (3, 9012, 20100420, 30, 3, 3, 'xyz', 3, 'cbs'); - missed

[edit] Query Gerrit for: commit id, url, and more, from terminal!

You can query gerrit and get data in JSON format and grep/sed from your command line like so:

echo $(ssh -p 29418 $GERRIT_USER@$GERRIT_SERVER gerrit query --format=JSON --current-patch-set $CHANGEID)

Here are two script examples of how this query can be useful:

script to get the gerrit url from a gerrit changeid:

# Get a gerrit url for a specific gerrit changeid by connecting to the review
# server.
if [ $# -ne 1 ]; then
    echo "Usage: $0 <gerrit_changeid>"
    exit 1;
CHANGEID_URL=$(ssh -p 29418 $GERRIT_USER@$GERRIT_SERVER gerrit query --format=JSON --current-patch-set $CHANGEID | sed -rn 's_.*url":"__p' | sed 's_","last.*__')

script to get the current git commit id from a gerrit changeid:

# Get a commit id for a specific gerrit changeid by connecting to the review
# server.
if [ $# -ne 1 ]; then
    echo "Usage: $0 <gerrit_changeid>"
    exit 1;
COMMITID=$(ssh -p 29418 $GERRIT_USER@$GERRIT_SERVER gerrit query --format=JSON --current-patch-set $CHANGEID | sed -rn '\_revision_ s_.*revision":"__p' | sed 's_","ref.*__')

And of course these can be built upon to do more batch processing.

[edit] Understanding the Android makefile

For those who started developing android recently, here is a quick summary of how to create a make file / what does make file contain

A makefile defines how to build a particular application. Makefiles typically include all of the following elements:

  1. Name: Give your build a name (LOCAL_MODULE := <build_name>).
  2. Local Variables: Clear local variables with CLEAR_VARS (include $(CLEAR_VARS)).
  3. Files: Determine which files your application depends upon (LOCAL_SRC_FILES := main.c).
  4. Tags: Define tags, as necessary (LOCAL_MODULE_TAGS := eng development).
  5. Libraries: Define whether your application links with other libraries (LOCAL_SHARED_LIBRARIES := cutils).
  6. Template file: Include a template file to define underlining make tools for a particular target (include $(BUILD_EXECUTABLE)).

The following snippet illustrates a typical makefile.

 LOCAL_PATH := $(my-dir)
 include $(CLEAR_VARS)
 LOCAL_MODULE := <buil_name>
 LOCAL_SRC_FILES := main.c
 LOCAL_MODULE_TAGS := eng development

[edit] Understanding the Variants options in Android "lunch" command

These are the currently-defined build variants:

  1. eng - This is the default flavor. A plain make is the same as make eng.
    1. Installs modules tagged with: eng, debug, user, and/or development.
    2. Installs non-APK modules that have no tags specified.
    3. Installs APKs according to the product definition files, in addition to tagged APKs.
    5. ro.debuggable=1
    7. adb is enabled by default.
  2. user - make user. This is the flavor intended to be the final release bits.
    1. Installs modules tagged with user.
    2. Installs non-APK modules that have no tags specified.
    3. Installs APKs according to the product definition files; tags are ignored for APK modules.
    5. ro.debuggable=0
    6. adb is disabled by default.
  3. userdebug - make userdebug. The same as user, except:
    1. Also installs modules tagged with debug.
    2. ro.debuggable=1
    3. adb is enabled by default.

If you build one flavor and then want to build another, you should run "make installclean" between the two makes to guarantee that you don't pick up files installed by the previous flavor. "make clean" will also suffice, but it takes a lot longer.

[edit] Uploading a zImage to Ram for testing without flashing using fastboot

There is a way to upload a zImage into the RAM without flashing it into the eMMC or putting it on a SD Card.

By using fastboot you can use the following command:

fastboot -b 0x80008000 boot <path to zImage> <path to ramdisk>

Adding -c to this command will append additional bootargs to the command line.

fastboot -c "foo" -b 0x80008000 boot <path to zImage> <path to ramdisk>

This will add foo to the command line arguments.

You can also additionally flash this into the emmc using the following command.

fastboot -b 0x80008000 -c "foo" flash:raw boot <path to zImage> <path to ramdisk>

Tip started on the ICS mail list. This is the way to use it on the current HW.

[edit] Configuring a Git Alias

If you find that there's a particular git command which requires a lot of keystrokes that you tend to use a lot you can configure an alias. For instance if you frequently use:

git log --pretty=oneline can configure an alias using the following:

git config --global alias.slog 'log --pretty=oneline'

...which you can invoke using:

git slog

[edit] Input From Command Line

At the Android console you can enter text or keyevents avoiding the usage of the touch screen and screen keyboard.

This is very useful for instance for entering a WPA Enterprise password =)

 input text mylongpassword
usage: input [text|keyevent]
       input text <string>
       input keyevent <event_code>

[edit] Using git blame

Git blame is a nice tool that can be used for finding out who last modified a particular line of code and which commit made the change.

For instance if you want to see what were the most recent changes around line 50 of omap-mcbsp.c you could type:

git blame -L 50 sound/soc/omap/omap-mcbsp.c

...and would get output like the following.

2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  50)       unsigned int                    bus_id;
2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  51)       struct omap_mcbsp_reg_cfg       regs;
ba9d0fd0 (Jarkko Nikula            2008-10-20 15:29:59 +0300  52)       unsigned int                    fmt;
2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  53)       /*
2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  54)        * Flags indicating is the bus already activated and configured by
2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  55)        * another substream
2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  56)        */
2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  57)       int                             active;
2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  58)       int                             configured;
5f63ef99 (Graeme Gregory           2009-11-09 19:02:15 +0000  59)       unsigned int                    in_freq;
5f63ef99 (Graeme Gregory           2009-11-09 19:02:15 +0000  60)       int                             clk_div;
3f024039 (Peter Ujfalusi           2010-06-03 07:39:35 +0300  61)       int                             wlen;
2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  62) };
2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  63)
2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  64) static struct omap_mcbsp_data mcbsp_data[NUM_LINKS];
2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  65)
2e74796a (Jarkko Nikula            2008-04-25 13:55:19 +0200  66) /*

Then if you wanted to see the full patch for any of these commits you could use git show to see the entire patch:

git show 2e74796a

[edit] Adding a reviewer column to Gerrit

You can enable the ability to see the last reviewer of your patches or your watched patches in the code review dashboard view by:

  1. Going into and signing into gerrit
  2. Clicking on Settings (Usually next to your Name and email, top right corner).
  3. Click on Preferences on the left hand side
  4. Select "Display Person Name In Review Category"

And then you can see who was the last person to NACK your patch ;)

[edit] Show git branch name at command prompt

If you would like to be able to see what git branch you are currently on from the command line like this:

a0270655local@Dta0270655ub ~/ICS/kernel[barry/abe-00]$ can add the following to your .bashrc file:

function parse_git_dirty {
  [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"

This will also add an asterisk to the branch if the branch is "dirty" (if there are uncommitted changes on your branch) like this:

a0270655local@Dta0270655ub ~/ICS/kernel[barry/abe-00*]$

[edit] Diverting logcat prints to kernel log

Method to divert the logcat prints to kernel log, with this logcat prints also will come along with the kernel time stamp.

Add the below lines to the init.rc script

service logcat /system/bin/logcat -f /dev/kmsg

on property:ro.debuggable=1
     start logcat

Along with -f all the filter options that comes by default with the logcat also can be given in the above service, i.e. below is also possible

service logcat /system/bin/logcat -s 'InputReader:*' -s
'InputDispatcher:*' -s 'EventHub:*' -s 'WindowManager:*' -s
'power:*' >

if we don't want to run in the service, then below also will work

logcat -s 'InputReader:*' -s
'InputDispatcher:*' -s 'EventHub:*' -s 'WindowManager:*' -s
'power:*' >

[edit] Show git branch name at command prompt

If you would like to be able to see what git branch you are currently on from the command line like this:

a0270655local@Dta0270655ub ~/ICS/kernel[barry/abe-00]$ can add the following to your .bashrc file:

function parse_git_dirty {
  [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"

This will also add an asterisk to the branch if the branch is "dirty" (if there are uncommitted changes on your branch) like this:

a0270655local@Dta0270655ub ~/ICS/kernel[barry/abe-00*]$

[edit] Debugging libs in /system/lib/hw

By default, the debugging symbols for the .so files in /system/lib/hw are not picked up when using gdbclient. This means, for instance, that you can't set breakpoints or get stack traces from the Audio Hal (/system/lib/hw/

Adding them is simple:

  1. edit build/
  2. find where "function gdbclient()" is declared
  3. Near the bottom of the function make this change:
  4. -       echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
    +       echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw"
  5. Save file.
  6. Now, re-source the '' file.

If you have the debugging symbols for your .so files in /system/lib/hw, they will now be picked up when you use gdbclient.

[edit] Using trace-cmd and kernelshark to get system traces

[edit] SUMMARY

The Linux kernel has a system that allows real-time tracing of many kinds of events, such as irq handler entry/exit, scheduler context switches, block device events, etc. When debugging strange slow-downs and system interactions, this is a very powerful tool. It is similar to systemtap, but it's easier to use. This uses "stock" kernel trace events, whereas systemtap allows highly customized tracing.


Install trace-cmd and kernelshark on ubuntu. You can use the same techniques on your laptop, since the traces are enabled in the kernel by default:

 $ sudo apt-get install kernelshark trace-cmd 


Inside menuconfig:

   Kernel hacking --> 
     [*] Tracers --> 
       [*]   Kernel Function 
       [*]     Kernel Function Graph 
       [ ]   Interrupts-off Latency 
       [ ]   Preemption-off Latency 
       [*]   Scheduling Latency 
             Branch Profiling (No branch profiling) ---> 
       [ ]   Trace max 
       [*]   Support for tracing block IO 
       [*]   enable/disable ftrace tracepoints dynamically 
       [*]   Kernel function profiler 
       [ ]   Perform a startup test on ftrace 
       < >   Ring buffer benchmark stress tester 

Or add this to defconfig:



Note that the patch you need is attached.

$ git clone \ 
$ cd trace-cmd 
$ git am < 
$ ./ 
$ adb push trace-cmd /system/bin 


To get a list of available tracers, use the 'list' command:

   $ adb root 
   $ adb shell trace-cmd list 

For example, to get all sched:sched_switch events and all irq events:

   $ adb root 
   $ adb shell 
   $ cd /sdcard 
   $ trace-cmd record -e "sched:sched_switch" -e "irq:*" 
   Hit Ctrl^C to stop recording 

After you hit Ctrl^C, it will write the data to a file called trace.dat


Grab the data file from the device:

   $ adb pull /sdcard/trace.dat . 

Then open the file with the 'kernelshark' program.



[edit] Automatic logging kernel log

Assume if

  1. We don't have the UART connection and need to take a kernel log during suspend(so adb is not possible)
  2. Forgot to take a previous log from the console.
  3. Need to capture many logs for multiple reboots.
  4. Outside testing with reboots involved, without having a computer in place.
  5. Maintaining the time and date stamp of kernel log


Then here is the tool we can use for logging.

Steps to use:-

  1. Push the script to the /data folder of the filessystem through adb
  2. Add the following lines to the init.rc
  3. service kernel_logging /system/bin/sh /data/ 10
    on property:ro.debuggable=1
    start kernel_logging
  4. Where 10 is the maximum number of kernel logs it can store, after that it will delete the older log and creates the newer one.
  5. All the logs will be created with the time stamp in the file name,for example --> /data/kernel_26-12-11_20:15:27.log
  6. Logs will be stored in /data folder, changeable by changing the script.
  7. Note :- Please use "dos2unix" if the script doesn't start, before pushing.

[edit] Shell command to gather non consecutive GIT commits

In case you need to gather all commits with a same subject :

Example for omap_hsi driver:

i=1; for c in `git log --reverse drivers/omap_hsi | grep ^commit | awk '{print $2}'`; do git format-patch --start-number $i  "$c^..$c"; let "i += 1";   done 

Example for a particular author:

i=1; for c in `git log --reverse | grep ^commit | awk '{print $2}'`; do git format-patch --start-number $i  "$c^..$c"; let "i += 1"; done 


[edit] Android Screen Caster

Are you using a board that doesn't have a display, are you using a Panda, or your display doesn't come up? Did you know that you can view the Android UI via ADB? Yes, screen caster can help you do that.
You can download Screen Caster from the following URL

Then you can simply invoke it using Sun Java as follows /usr/lib/jvm/java-6-sun- ~/androidscreencast.jnlp

Make sure ADB is connected and working, once launched you should see the android console in the screen caster app :-)

[edit] Multiple Build variants/targets on a single source

Assume if

  1. Your PC speed is a bit slow, and you need to maintain both the Engineering and user builds of android at a time on a single source,so you need not rebuild again for the other build variant,meaning there will be two out directories, or
  2. You want to build multiple targets, example for blaze_tablet, blaze and panda boards on the same source and wanted to maintain three out directories.

Then you can use the the attached two patches, if space is not a constraint for you Also one more advantage is we can trigger the builds parallel , meaning at a time we can trigger the user and Eng builds leaving it overnight, or at a time we can trigger the builds for blaze_tablet,blaze and panda.

[edit] Speed up Android builds with CCACHE

Ref:, "Using ccache"

ccache caches previous compilations and detects when the same compilation is being done again. It can save a lot of time when rebuilding a repo sync'd AFS.

To enable set the USE_CCACHE env. variable before doing your Android build.

$ export USE_CCACHE=1 

The following steps only need to be done once:

Set the location of your CCACHE directory

$ export CCACHE_DIR=/<path_of_your_choice>/.ccache 

By default the cache is limited to 1GB, you can increase this by using the prebuilt version of ccache ( gets the binary location wrong for JellyBean):

$ prebuilt/misc/linux-x86/ccache/ccache -M 20G

[edit] VIM:Taglist: Lists functions while editing a file in VIM/GVIM editor

Many of us still using VIM/GVIM editor to modify the source files. Here is a way to view function/variable names for the current file in VIM editor as in GUI IDEs such as SourceInsight and Eclipse.

  1. Download and install the taglist script.
  2. mkdir ~/.vim       #-> if you don't have one already. 
    cd ~/.vim/ 
    wget -O 

    This will extract 2 files as below.

     inflating: plugin/taglist.vim      
     inflating: doc/taglist.txt  
  3. Update your .vimrc file for some options and a shortcut key.
  4. Add below lines in to your ~/.vimrc file

    Tag list options 
    let Tlist_WinWidth = 40 
    let Tlist_Auto_Open = 1 
    let Tlist_GainFocus_On_ToggleOpen = 1 
    nnoremap <silent> <F8> :TlistToggle<CR> 

  5. Now open a c/cpp/java file.
    • You will see a panel window at left side with list of tags/functions available in that current file.
    • You can use F8 key to toggle the taglist window on/off.
    • Use "Ctrl+w+w" to switch between taglist window and vi editor window.

For more details about the options and commands related to Taglist refer the document at ~/.vim/doc/taglist.txt.

Note: Taglist would require Exuberant ctags 5.0 or above. If you dont have the ctags installed, install that as follows:

sudo apt-get install exuberant-ctags

[edit] Generating Keyevents Through adb shell

We can automate any test scenario, by generating the key events in the adb shell.

Following is the syntax for generating the keyevents -

adb shell input keyevent <event_number> 

By generating the keyevents we can run, stop, launch apps and menus, select the options, lock and unlock the screen etc.


adb shell input keyevent 82 - unlock 
adb shell input keyevent 3  - Goto Home screen 

For more key events check

Personal tools