Sunday, December 2, 2012

Taking wireless logs using wifi

Hey Guys,

Recently I have been trying to use connect USB devices to my Nexus S (running Android Jellybean 4.1.2) using an OTG cable. But unfortunately, on connecting the OTG cable we cant take logs to debug. I tried to find a way out of this to take real-time logs using wifi.

On googling I found a way which worked for me.

The task involved two steps:
1. rooting the device
2. using app to start wifi adb

Rooting the device:
a) Download  RootnexussJB.zip from
http://dl.xda-developers.com/attachdl/2b5b28d0b7d10c2d5529e0b8d6d92746/50bb3158/1/2/2/0/8/4/7/RootnexussJB.zip and unzip it in local machine.
b) use "fastboot flash recovery recovery-twrp-2.2.0-crespo.img" to flash recovery binary adn recovery boot using "fastboot reboot recovery".
c) Choose “Mount” > “Mount USB Storage” > Copy the Superuser 3.2_RC.zip to the internal storage of your Nexus S > Choose “Unmount” on your Nexus S.
d) Choose “Install” > Choose “Superuser 3.2_RC.zip”.
e) Choose "Swipe to flash" > Choose “Reboot System”.
f) Nexus S shows now superuser app in launcher. the phone is now rooted. Congratulations... !!!

jai@jai-laptop:~$ adb root
adbd is already running as root
Courtesy: http://forum.xda-developers.com/showthread.php?t=1795167

using app to start wifi adb:
download any of the wifi adb/wireless adb app from the GOOGLE PLAY STORE. I have downloaded "wifi adb" which requires superuser permissions for wifi adb to work.
a) Open the app and click on "Turn On"
b) Grant superuser permissions to the app when prompted.

c) On your PC connect adb using wifi:
$ adb connect 192.168.1.3.:5555
connected to 192.168.1.3:5555 --> on successful connection
$ adb shell
$ cat /proc/kmsg --> to take kernel logs




Hope this helps,
Jai

Friday, October 19, 2012

Creating an overlay on Android Framebuffer

Hey Guys,

Recently I tried something really crazy. I m not really good at Java, so I was trying to find out an easy way of displaying an image on frame buffer without having to write a Java program. Here is how it works

Prerequisites:
1. Phone must be rooted.
2. Android platform build setup ready. I have downloaded the Android jellybean 4.1.1 from source.google.com at $PROJECT = /home/jai/NexusS.


create a folder in lcdtest in $PROJECT/external/ and add the following two files
    $PROJECT/external/lcdtest/lcdtest1.cpp
    $PROJECT/external/lcdtest/Android.mk

lcdtest.cpp looks as follows:

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>

int main()
{
    int fbfd = 0;
    struct fb_var_screeninfo vinfo;
    struct fb_fix_screeninfo finfo;
    long int screensize = 0;
    char *fbp = 0;
    int x = 0, y = 0;
    long int location = 0;

    // Open the file for reading and writing
    fbfd = open("/dev/graphics/fb0", O_RDWR);  //use "/dev/fb0" in linux
    if (fbfd == -1) {
        perror("Error: cannot open framebuffer device");
        exit(1);
    }
    printf("The framebuffer device was opened successfully.\n");

    // Get fixed screen information
    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
        perror("Error reading fixed information");
        exit(2);
    }

    // Get variable screen information
    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
        perror("Error reading variable information");
        exit(3);
    }

    printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);

    // Figure out the size of the screen in bytes
    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
    // Map the device to memory
    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
    if ( fbp == NULL) {
        perror("Error: failed to map framebuffer device to memory");
        exit(4);
    }
    printf("The framebuffer device was mapped to memory successfully.\n");

    x = 100; y = 100;       // Where we are going to put the pixel

    // Figure out where in memory to put the pixel
    for (y = 100; y < 200; y++)
        for (x = 100; x < 200; x++) {

            location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
                       (y+vinfo.yoffset) * finfo.line_length;

            if (vinfo.bits_per_pixel == 32) {
                *(fbp + location) = 0;100; //100;        // Some blue
                *(fbp + location + 1) = 255;//15+(x-100)/2;     // A little green
                *(fbp + location + 2) = 0;//200-(y-100)/5;    // A lot of red
                *(fbp + location + 3) = 0;      // No transparency
            } else  { //assume 16bpp
                int b = 10;
                int g = (x-100)/6;     // A little green
                int r = 31-(y-100)/16;    // A lot of red
                unsigned short int t = r<<11 | g << 5 | b;
                *((unsigned short int*)(fbp + location)) = t;
            }

        }
    vinfo.activate |= FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
    if(0 > ioctl(fbfd, FBIOPUT_VSCREENINFO, &vinfo)) {
    printf("Failed to refresh\n");
    return -1;
    }
    munmap(fbp, screensize);
    close(fbfd);

    return 0;
}



Contents of Android.mk

ifneq ($(TARGET_SIMULATOR), true)

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:=\
    lcdtest1.cpp

LOCAL_CFLAGS:= -g
LOCAL_MODULE:= lcdtest1
LOCAL_MODULE_TAGS := optional

include $(BUILD_EXECUTABLE)

endif


Now the files are ready. To build the file for Nexus S, first setup the build environment as follows.
Go to $PROJECT directory

$ source build/envsetup.sh
$ lunch full_crespo-eng


Now the build environment is ready. To build the android binary in the shell type

$ make -j4 lcdtest1

This would create a binary at out/target/product/crespo/system/bin/lcdtest1

To run this on Nexus, connected the rooted Nexus S device
$ adb remount
$ adb push out/target/product/crespo/system/bin/lcdtest1 system/lib
$ adb reboot


After phone has restarted:
$ adb shell
# lcdtest1

You would see a green overlay patch as shown.

Green patch on top of display

Good luck and Enjoyy !!!!

Sunday, October 7, 2012

Integrating GAPPS in custom binary

Hey Guys,

As I have mentioned in my last post that Google account is not integrated in the custom source that we download from the Android site. I later learnt that this violates the licensing agreement. So we don't get google account integration with the cyanogenmode binaries. So here is a method I found on the internet to integrated the Google account and apps with the custom binary built from the source code:
Now we are ready to flash on the device:
$ fastboot flash recovery recovery-clockwork-6.0.1.0-crespo.img
$ fastboot reboot recovery 

Device in Recovery boot mode
This will install the recovery binary onto your device. Now we can do a recovery boot to browse the menu and install updates from the sdcard. To browse use vol up, vol down and power button.
  • Go down to "mounts and storage" > "mount USB storage"
  • Copy the GAPPS zip gapps-jb-20120726-signed.zip to device sdcard storage.
  • Select "install zip fron sdcard" > "choose zip from sdcard"
  • locate gapps-jb-20120726-signed.zip.
  • Reboot the device. 
Integrated GAPPS to custom binary
Custom binary properties :-P
 Now google apps are integrated to your custom binary.
 - Jai

References:

http://jim-zimmerman.com/?p=821

Saturday, October 6, 2012

Using Fastboot to download binaries

Hey Guys,

Recently I have been experimenting a lot with The Nexus S. I have also compiled Jellybean Source code in my local machine running on Ubuntu 10.04 (64bit). But unfortunately, the build does not allow you to attach google acount to it :-( . And the default google apps like Play store/Gmail/Maps/Gtalk are absent in the binary. Will look for a method to integrate the Market !!!!

Its easier to flash using Odin (just tar the boot.img, system.img, recovery.img and userdata.img) in Windows platform. For Linux we have two options:

1. Use Fastboot (http://source.android.com/source/building-devices.html)
2. Use Heimdall (http://www.glassechidna.com.au/products/heimdall/)

To download binary using Fastboot:
Download the android-sdk from http://developer.android.com/sdk/index.html
Add tools and platform-tools to PATH variable to use it from any location.

$ gedit ~/.bashrc & and add the following line:
export PATH=$PATH:/home/jai/bin:/home/jai/Android/android-sdk-linux/tools:/home/jai/Android/android-sdk-linux/platform-tools

Now, Download the Nexus Factory image binary from https://developers.google.com/android/nexus/images#sojujro03l

Unzip it. It would have the following 5 files:
  1. bootloader-crespo-i9020xxlc2.img - bootloader binary
  2. flash-all.sh - shell script to install radio, bootloader and platform
  3. flash-base.sh - shell command to install radio and bootloader
  4. image-soju-jro03l.zip - the Platform package
  5. radio-crespo-i9020xxki1.img - Radio binary

I have skipped the bootloader and Radio binary, as its not good to mess with the bootloader. The device will be useless if the bootloader is corrupted. So better don't mess with it. Then unzip image-soju-jro03l.zip to get the following files:
  1. android-info.txt
  2. boot.img
  3. recovery.img
  4. system.img
  5. userdata.img

I modified android-info.txt to add a check my bootloader version:
require board=herring
require version-bootloader=I9020XXLC2|I9020XXKL1
require version-baseband=I9020XXKI1|I9020UCKJ1|M200KRKC1
and zipped them to JAI.zip
 zip JAI.zip android-info.txt boot.img recovery.img system.img userdata.img
Now we are ready to flash the binary. Get the device in fastboot mode using the key combination vol up + power button or just type:
fastboot reboot bootloader
fastboot -w update JAI.zip
To flash the binary made from the workspace.
export ANDROID_PRODUCT_OUT=/home/jai/NexusS/out/target/product/crespo/

fastboot -w flashall 
Now my self compiled binary is flashed. It feels great to see it working :-). For any queries mail me.

Jai

Monday, October 1, 2012

Got my Nexus S

Got my Nexus S from Korea today..... !!!!

I just love it...

Its was KOREAN phone ICS 4.0.4..(model: M200) , before I converted it to international version (I9020) by flashing the factory images from Google (https://developers.google.com/android/nexus/images) using ODIN.

The phone bootloaders are generally locked that means one can not flash custom binary till its unlocked. The bootloader can be unlocked by using fastboot tool (<android-sdk>/platform-tools) provided in the android-sdk.

To unlock the bootloader:
1. Get the phone in fastboot mode by pressing the key combination ( Press and hold volume up + Press and hold Power button) or by using adb type
Device in Fastboot mode

 $ adb rebootbootloader
 
2. Unlock the device by 
 $ fastboot oem unlock
 
3. Chose the unlock option from the menu.

Now the device is ready to download custom binary. Now Korean phone can be converted to Non-Korean by just flashing the Platform binary released from Google (https://developers.google.com/android/nexus/images). I downloaded
Factory Images "soju" for Nexus S (worldwide version, i9020t and i9023) version: 4.1.1 (JRO03L) and unzipped it to get boot.img, system.img, recovery.img and userdata.img.

Now to flash the platform binary using Odin:
1. create proper file for the Odin software 
 tar -cvf PLATFORM.tar boot.img system.img recovery.img userdata.img
2. Put the phone in Odin mode using appropriate key combination (Vol up + vol down + power (less than 1 sec and release power) in Nexus S).
Nexus in Odin mode
3. Once the device gets detected in Odin select PLATFORM.tar from PDA and start the download.

After flashing the device is now upgraded to Jellybean 4.1.1 and moreover its a non-Korean phone now.... !!!!

I am gonna dig more into Nexus S.... So many more things yet to come.... !!! ;-)

Jai

Tuesday, January 17, 2012

cross-compiling binaries for Android device on Windows 7/Ubuntu

C language is most commonly used basic programming language. Here is a method to run a C program on an Android device with ARM processor. We cross compile the program on windows machine and generate binary files for ARM. Cross compiling is a method of compiling executable for other platform other than the one in which compiler is run. Here we are creating an executable for ARM device (running Android) platform by compiling on windows. The same method should work on LINUX platform too.

1. Download and CodeSourcery's toolchain installer for IA32 Windows host from https://sourcery.mentor.com/sgpp/lite/arm/portal/release2029 .

2. Install the setup.

3. The toolchain provides the cross compiler arm-none-linux-gnueabi-gcc. Add directory path in default path variables.

4. write a sample program as follows

#include<stdio.h>
int main(){
     printf("\n Hello World! \n");
     return 0;
}
save the program as hello.c

5. compile hello.c as follows from the cmd/terminal:
$ arm-none-linux-gnueabi-gcc -o hello -static hello.c
6. Copy the binary to phone using adb tool or just copy it to phone memory.
$ adb push hello /data
7. There are two methods to run the program
i) Running on linux shell using adb
- open linux shell of the Android device using
$ adb shell
$ cd /data
$ ./hello

//output must be:

 Hello World!
ii) running it on virtual terminal on the Android device.
- download a virtual terminal emulator from android market (https://github.com/jackpal/Android-Terminal-Emulator/wiki)

-open the virtual terminal and run the program.
$ cd /data
$ ./hello

output displayed on terminal:
Hello world!


Its interesting to see the the C programs running on the linux shell. :) :D

Monday, January 16, 2012

Taking kernel and platform logs of an Android device together

I wanted to take both kernel and platform logs of an Android device together. So here is a piece of code that does that.

1. connect the Android target to Windows.
2. start cmd and type
$ adb shell       
$ logcat -v time -f /dev/kmsg | cat /proc/kmsg > /data/klog_plog.txt
$ exit
$ adb pull /data/klog_plog.txt > myfile.txt 

$ adb shell : this command moves user to linux shell of android device. Make sure adb location has been added to path variables in windows.
$ logcat -v time -f /dev/kmsg | cat /proc/kmsg > /data/klog_plog.txt

$logcat -v time prints the platform logs with time stamps. /dev/kmsg is a local buffer.
cat /proc/kmsg gives the kernel logs. So both platform and kernel logs are written to /data/klog_plog.txt

$ adb pull /data/klog_plog.txt > myfile.txt
it pulls the file from the Android device to local drive.

Saturday, January 14, 2012

Changing the default view in Windows File Explorer

I like the "Tiles view" in Windows  explorer. But by default it comes with some other view. So every time I open a new window I had to switch to the tiles view, as I find it comfortable. To avoid this here is a method to chage the default settings.

1. Open Windows explorer (for example My Computer).
2. Change the view to Tiles.


3. Go to tools menu and click Folder Options

4. Go to view tab and click on Apply to folders.