Archive

Archive for the ‘MOD and HACK’ Category

How to get Base address/PHYS_OFFSET for specific hardware

December 30, 2010 Leave a comment

::::Quick description:::
Search for PHYS_OFFSET  in .config if not See at kernel sources at the file: arch\arm\mach-msm\include\mach\memory.h

HTC- Buzz

/* physical offset of RAM */
#if defined(CONFIG_ARCH_QSD8X50)
#define PHYS_OFFSET        UL(0x20000000)
#elif defined(CONFIG_ARCH_MSM7225) // make sure CONFIG_ARCH_MSM7225 is set to ‘y’ in .config
#define PHYS_OFFSET        UL(0x02E00000)
#elif defined(CONFIG_ARCH_MSM7200A)
#define PHYS_OFFSET        UL(0x19200000)
#elif defined(CONFIG_ARCH_MSM7201A)
#define PHYS_OFFSET        UL(0x19200000)
#elif defined(CONFIG_ARCH_MSM7X00A) && defined(CONFIG_MACH_DESIREC)
#define PHYS_OFFSET        UL(0x11200000)
#elif defined(CONFIG_ARCH_MSM7X00A)
#define PHYS_OFFSET        UL(0x19200000)
#elif defined(CONFIG_ARCH_MSM7227)
#define PHYS_OFFSET        UL(0x12C00000)
#else
#define PHYS_OFFSET        UL(0x10000000)

For LG-GT540 Base address is PHYS_OFFSET  UL(0x00200000)

Categories: MOD and HACK

How to compile Android Device Driver as a Module(.ko)

December 28, 2010 2 comments

Here are the quick steps to be followed.

Prerequisite:
1. kernel sources from vendor say HTC wildfire(2.1 update-1)
2. Android source code for Éclair
3. Create a new folder called Kernel and copy the contents from the sources download via vendor

Step1: Copy config.gz from running hardware

adb pull /proc/config.gz
gunzip config.gz
mv config .config

Step 2: Copy/Overwrite the .config file to the kenel root directory

open .config file and search for
CONFIG_MODULE_NAME1=y
CONFIG_MODULE_NAME2=y

and replace ‘y’ with ‘m’, we use CONFIG_MODULE_NAME1 as module

CONFIG_MODULE_NAME1=m
CONFIG_MODULE_NAME2=y

Step 3: Check the active kernel version on the hardware using ‘OR’ if you are using own Boot.img then skip this and move on to step 4:

adb shell
# uname -a

or you may get the details of the kernel from the Settings->Aboutphone->SoftwareInformation: Kernel version

2.6.29-6fb59e13 HTC-kernel@xxxxxxxx

open Makefile in the kernel folder, search and replace “EXTRAVERSION =” with “EXTRAVERSION =-6fb59e13

Step 4: Set the Env variables

export ARCH=arm
exprot CROSS_COMPILE=arm-eabi-
export PATH=$PATH:~/eclair/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/

now perform make modules for make from the kernel sources

kernel:$ make modules or make

after successful compilation, check out the .ko files next to the sources in the same directory

Complete example: How to get LG headset sources compile in to kernel module(.ko)

Categories: MOD and HACK

How to get LG headset sources compile in to kernel module(.ko).

December 28, 2010 1 comment

This article is about compiling specific sources into Kernel Module in Android, read this first before you proceed further

I have taken Headset Driver as a use case.

1. Create a folder headset_lg at location: ~/gt540_2.1/kernel/arch/arm/mach-msm/headset_LG

2. Copy board-swift-headset.c from ~/gt540_2.1/kernel/arch/arm/mach-msm/swift to headset_LG folder and make changes to it below

change //static int __init lge_hsd_init(void) to static int lge_hsd_init(void)
change // actuall call is static void __exit lge_hsd_exit(void) to static void lge_hsd_exit(void)
also comment this line
//device_initcall(hsd_debug_init);

write make file to compile the .c file

makefile
#
# Makefile for the swift specific files
#

#obj-y += board-swift-bl-rt9393.o
obj-m = board-swift-headset.o // replace obj-y to obj-m // were m stand for Module

3. also change need to be made inside /home/br/gt540_2.1/kernel/arch/arm/mach-msm/rpc_server_misc.c

comment the global variable “headset_inserted” which is used to udpate the status of actual hardware

4. change to root folder of the kernel and run make. you shall see the .ko file at location given below

 Kernel: arch/arm/boot/Image is ready
Kernel: arch/arm/boot/zImage is ready
Building modules, stage 2.
MODPOST 16 modules
LD [M] arch/arm/mach-msm/headset_LG/board-swift-headset.ko

Installing Kernel Module

~/arch/arm/mach-msm/headset_LG/$adb push /sdcard/board-swift-headset.ko
~/arch/arm/mach-msm/headset_LG/$adb shell
$su
# insmod /sdcard/board-swift-headset.ko //dont panic, filesystem should restart after executing insmod stmt
# lsmod // to verify the driver
# rmmod board-swift-headset.ko // to remove kernel module

Categories: MOD and HACK

Android – Accessing Input device "msm_pcm_in" from User space

December 14, 2010 6 comments

This article shows code snippet on how to access input device driver from user space.

Recording from input device (msm_pcm_in: a char Device Driver) follows the below events

Open device :

int ret = open("/dev/msm_pcm_in", O_RDWR); // open device

struct msm_audio_config confg;

ioctl(ret, AUDIO_GET_CONFIG, &confg) // this call fill the structure with default driver values.

cfg.channel_count = 1; // assign new number of channel(1= mono, 2 = stereo)
cfg.sample_rate = 8000;// assign sampling rate such as 8000 or 16000,.....
int val = ioctl(ret, AUDIO_SET_CONFIG, &confg);// set the new audio configuration

Before we being to start audio read/write operations, create a file to store buffers
const char *fn = /sdcard/tmp/file1;
int file = open(fn, O_CREAT | O_RDWR, 0666);

bool isrecording = true; // use this flag to stop recording (true default, false to disable reading)

ioctl(ret, AUDIO_START, 0);

fcntl(0, F_SETFL, O_NONBLOCK);// provides control of open file descriptors.

unsigned char buf[4092];

for (;;) {
while (!isrecording) {
// close all file descriptors and exit
}
if (read(ret, buf,confg.buffer_size ) != confg.buffer_size) {
// if fail to read
// close all file descriptors and exit
}

if (write(file, buf, confg.buffer_size) != confg.buffer_size) {
// if fail to read
// close all file descriptors and exit
}

}


Close device:

close(ret);
...
...
close (file);

Note: To run this as a recorder app, make sure you have root privileges.

Categories: MOD and HACK

Technicalities to build custom ROM for LG GT540

November 19, 2010 2 comments

::First things first::

Thanks to XDA developer and Modaco forums to share their experience

Below are the steps taken by me to build a working Android kernel image and system image for the GT540 (a.k.a. LG SWIFT). This image is based on linux kernel 2.6.29 and relies on the Android 2.1 “Eclair”.

This page is here as a reminder to me for when I come to do it again. This is what worked for me so far, your approach may vary.

1. Download required tools and software

-Download GT540 ROM sources from LG here.

I have used Eclair sources, the size should be 132MB after download. next unzip sources and follow the Readme.txt to ease I copy-paste below

1. How to download Android source.

refer to Android site – http://source.android.com/source/download.html

2. Check your build environment

whether it is successful in building downloaded Android source.

3. Untar open source package of GT540 into downloaded Android source

4. Kernel Build

dount$> source ./build/envsetup.sh

donut$> choosecombo 1 1 generic 1

donut$> cd kernel

donut/kernel$> make swift_defconfig

donut/kernel$> make

-> After build, you can find the built image at kernel/arch/arm/boot/

5. Android Source Build

donut$> source ./build/envsetup.sh

donut$> choosecombo 1 1 generic 1

donut$> make

-> After built, you can find the built image at out/target/product/generic

-Download Android source code for desired version like Eclair in this case, Details on how to download source code is here

2. Build kernel and system images

-Following the first steps in Readme.txt from LG sources will give you the kernel image i;e zImage at ~/eclair/kernel/arch/arm/boot/zImage

-Second step will build system.img, ramdisk.img, userdata.img which will be at ~home/br/eclair/out/target/product/generic/

you may run system.img to test on emulator(How to is here ) before NAND flashing

3. Unpack, Repack and Flashing

– Get the Boot image from existing target

 

# cat /proc/mtd

dev: size erasesize name

mtd0: 00500000 00020000 “boot”

mtd1: 04000000 00020000 “cache”

mtd2: 00500000 00020000 “recovery”

mtd3: 00060000 00020000 “splash”

mtd4: 0f500000 00020000 “system”

mtd5: 002c0000 00020000 “lgdrm”

mtd6: 08b80000 00020000 “userdata”

mtd7: 00080000 00020000 “usd”

mtd8: 005a0000 00020000 “pkg”

mtd9: 1cfc0000 00020000 “”

# cat /dev/mtd/mtd0 > /sdcard/boot.img pull the boot.img from sdcard and apply below scripts

– Download scripts from here (follow the instruction in the scripts) to add new kernel image with devicee ramdisk. I have a different set of scripts that I will share later.

– Used fastboot to flash images, fastboot usage is here

-First reboot may take while, or you may see weird behavior (stuck at boot screen or reboot loop…..)

Conclusion: Kernel up and running, but system image give a problem…

 

P.S : Dear readers, if you are able to run custom system image please do share your experiences. Read more…

Categories: MOD and HACK

How to Build a single module in Android and include in System image

November 10, 2010 Leave a comment

Go to build directory under Android sources
Execute source ./envsetup.sh
Go to corresponding application directory (~/eclair/hardware/msm7k/libaudio$)
Issue mm command to build the Module only in this case its libaudio.so

if you want to include in system.img in conjunction with ROM sources from vendor

run make from the root directory

~/eclair$ make
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.1-update1
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=ECLAIR
============================================
build/core/copy_headers.mk:15: warning: overriding commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
build/core/copy_headers.mk:15: warning: ignoring old commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
Install: out/host/linux-x86/lib/libneo_util.so
...
...
...
Install system fs image: out/target/product/generic/system.img
~/eclair$

Categories: MOD and HACK

Running Android emulator up with custom system image

November 10, 2010 1 comment

1.Run Terminal, and change to the ‘tools’ directory of the SDK
2.Type ‘./android list target’
3.Note the ‘id’ number of the ‘2.1’ target (in my case it’s ‘7’)
4.Type ‘./android create avd -n eclair -t 7’ (where 7 with the target number determined above if required)
5.You will be prompted to create a hardware profile. say YES and provide user defined values or leave as default.
6.Copy system.img to ~/.android/avd/eclair.avd/system.img
7.Type ‘./emulator -avd eclair’ command to run emulator with system.img! Note: initial boot may take a few minutes!

should you get any Java issues download the JDK for your system “jdk-6u14-windows-i586.exe”

Categories: MOD and HACK