Pages

Get it free, Try now

Free Cell Phones

Thursday, December 30, 2010

How to get Base address/PHYS_OFFSET for specific hardware

::::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)

Tuesday, December 28, 2010

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

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)

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

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

Tuesday, December 14, 2010

Android - Accessing Input device "msm_pcm_in" from User space

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.

Friday, December 10, 2010

Android- How to Create Executable

1. Setup ndk project with android.mk and native sources

Android.mk file should include BUILD_EXECUTABLE, sample android.mk is below.


LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := Modulename
LOCAL_SRC_FILES := file1.c\
file2.c

LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)


2. Building executable.

$ ndk-buld

3. Run executable

copy to device say /sdcard/data/Modulename
xxxx@xx:$> adb shell
$./sdcard/data/Modulename


Note:Make sure you place Android.mk file along with source(c/c++) in same folder and name it as jni. as libs and obj folders are created next to jni folder.