2011年9月19日 星期一

Android Sensor Path

Application layer: application
Application Framwork : Sensor Manager
Sensor JNI
Libraries: Sensor Manager <--> Sensor Service <--> Sensor HAL
Kernel : Input dirver subsystem and Event Dev
Sensor driver


# Sensor Manager Application Layer: /frameworks/base/core/java/android/hardware folder
# Sensor JNI layer: /frameworks/base/core/jni/android_hardware_SensorManager.cpp file
# Sensor Manager Library: /frameworks/base/libs/gui folder
# Sensor Service: /frameworks/base/services/sensorservice folder
# Sensor HAL: /hardware/ti/omap3/libsensors folder
# Accelerometer Sensor driver: /drivers/input/misc/xxxxx.c file



Note: Android 2.3 change the sensor service as Native Sensor code.

2011年9月7日 星期三

Linux script : backslash "\"

backslash "\" : escape next special characters

Ex:
echo "Path is $PATH" ---> This will show $PATH content
echo "Path is \$PATH" ---> This will show $PATH string

The backslash wiil remove the specail meaning of dollar($) sign

Linux script : echo -e

echo -e "My name is \t test"

You will see the My name is test

-e: enable backslash ascapes

The backslash-escaped characters


\a     alert (bell)
\b backspace
\e an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\' single quote
\nnn the eight-bit character whose value is the octal value nnn (one to three digits)
\xHH the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
\cx a control-x character
reference :http://bash.cyberciti.biz/guide/Quoting

Linux script: Quoting

http://bash.cyberciti.biz/guide/Quoting

The double quote " : variable and command will be run

The single quote ' : variable and command will not be run

Ex:
echo "$PATH" --> The $PATH will be expand
echo '$PATH' --> The $PATH will not be expand

echo "$(date)" --> show date
echo '$(date)' --> only show $(date)

2011年9月6日 星期二

Linux script: grep in a test/if statement

http://www.unix.com/shell-programming-scripting/57761-using-grep-test-if-statement.html
exampe1:

cd ${PATH}

if [ 'grep SOME_STRING $PATH/$LOGFILE' ]
then
rm ${FILE}
./anotherScript
else
exit 1
fi
exit 1


Example 2:
cd ${PATH}

if [ $(grep -c SOME_STRING $PATH/$LOGFILE) -ne 0 ]
then
rm ${FILE}
./anotherScript
else
exit 1
fi

exit 0

Exampe 3:
cd ${PATH}

grep -q SOME_STRING $PATH/$LOGFILE
if [ $? -eq 0 ]
then
rm ${FILE}
./anotherScript
else
exit 1
fi

exit 0

Linux script : 2>&1

2>&1 表示將stderr導向輸出stdout

0: stdin
1: stdout
2: stderr

exampe: # /tmp/test.sh > /tmp/test.log 2&1

2011年9月5日 星期一

Using printk debug

Using printk debug
There three method
1. KERN_EMERG to KERN_DEBUG
- pr_energe to pr_debug

2. Change the kernel command line
- loglevel = parameter
We can refer Kernel/doc/kernel-parameters.txt

3. Change the printk level after bootup
- /proc/sys/kernel/printk
ex: echo 8 > /proc/sys/kernel/printk
Then read /proc/kmsg

- /proc/sysrq-trigger

You can modify the #DEFAULT_CONSOLE_LOGLEVEL 8
at kernel/prink source code

There are prink tips andd tricks
1. CONFIG_PRINTK_TIME

2. CONFIG_EARLY_PRINTK
- CONFIG_DEBUG_LL and added some patch

3. CONFIG_LOG_BUF_SHIFT
- you can use the dmesg to change the printk buffer
"dmesg -s 128000" this mean we open 128k buffer


You can open the kernel configuration with #make menuconfig
kernel hacking --> <> show timming information as printks
<> debug filesystem
<> kernel low-level debugging function


There are two topic need to study
- debug system
debug system at /sys/kernel/debug
You can mount it by mount -t debugfs none /sys/kernel/debug
Or write it in /etc/fstab
debugfs /sys/kernel/debug debugfs 0 0

- dynamic debug
- CONFIG_DYNAMIC_DEBUG
- Operate on pr_debug or dev_dbg

linux script :Using while loop

http://www.cyberciti.biz/faq/bash-while-loop/

bash while loop syntax


while [ condition ]
do
command1
command2
command3
done
================================
Example:
#!/bin/bash
x=1
while [ $x -le 5 ]
do
echo "Welcome $x times"
x=$(( $x + 1 ))
done



=======================================

#!/bin/bash
while :
do
echo "infinite loops [ hit CTRL+C to stop]"
done
==========================================

Conditional while loop exit with break statement


while [ condition ]
do
statements1 #Executed as long as condition is true and/or, up to a disaster-condition if any.
statements2
if (disaster-condition)
then
break #Abandon the while lopp.
fi
statements3 #While good and, no disaster-condition.
done

2011年9月1日 星期四

linux driver sample : only init

Makefile:
===============================================================
KDIR :=/work/kernel/android-2.6.35
PWD := $(shell pwd)
ARCH=arm
CROSS_COMPILE=/work/tools/arm-2010q1/bin/arm-none-linux-gnueabi-
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld

obj-m := foo.o

all:
$(MAKE) -C $(KDIR) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) M=$(PWD) modules

clean:
rm -rf *.o *~ core.depend .*.cmd *.ko *.mod.c .tmp_versions
===============================================================


source code:
===============================================================

#include "linux/module.h"
#include "linux/kernel.h"
#include "linux/init.h"

static int __init foo_init(void)
{
printk("foo module init !!! \n");
return 0;
}
static void __exit foo_exit(void)
{
printk("foo module exit !!!! \n");
}

module_init(foo_init);
module_exit(foo_exit);

===============================================================

2011年8月31日 星期三

linux and android power management information

@ Normal Linux suspend
- Source code : kernel_src/kernel/main.c
kernel_src/kernel/arch/arm/mach-xxx/pm.c

- userspace interface: /sys/power/state
You can trace kernel_src/kernel/main.c
echo mem > /sys/power/state
echo standby > /sys/power/syste


- Process
1. suspend_prepare()
2. suspend_freeze_processes(): freeze all process.
3. suspend all devices : suppend_device_and_enter() at kernel/power/suspend.c suspend_device_and_enter() {
.......
dpm_suspend_start(PMSG_SUSPEND)
.......
}


dpm_suspend_start(PMSG_SUSPEND)
{
.......
dpm_suspend()
......
}

dpm_suspend()
{
......
;call all device callback function suspend()
get_device(dev);
device_suspend(dev);
......
}



4. Resume:
1. Get wake up event
2. Resume the devices /sys/devices/system
3. call suspend_ops -> finish() and let it start resume
4. call every devices resume in suspend_devices_and_enter()
5. call suspend_ops -> end()
6. call suspend_finish which will thaw the process and enter user mode helper




@ Android suspend : request_suspend_state() in kernel/power/earlysuspend.c
- Early suspend function
- wakelock function

You can study
- kernel_src/kernel/power/main.c
- kernel_src/kernel/power/earlysuspend.c
- kernel-src/kernel/power/wakelock.c



Definition:
http://kzjblog.appspot.com/2010/11/20/suspend-en.html

- Early Suspend
Early suspend is a mechanism that android introduced into linux kernel.
This state is btween really suspend, and trun off screen. After Screen is off,
several device such as LCD backlight, gsensor, touchscreen will stop for battery life and functional requirement.

- Late Resume
Late resume is a mechinism pairs to early suspend, executed after the kernel and system resume finished.
It will resume the devices suspended during early suspend.

- Wake Lock
Wake lock acts as a core member in android power management system.
wake lock is a lock can be hold by kernel space ,system servers and applications with or without timeout.
In an android patched linux kernel (referenced as android kernel below) will timing how many and how long the lock have.
If there isn't any of wake lock prevent suspend(WAKE_LOCK_SUSPEND),
android kernel will call linux suspend (pm_suspend()) to let entire system going to suspend.


Trace code :
Early suspend :
- state_store() /kernel/power/main()
you write "mem > /sys/power/state" and it will call this function
- state_store(){
request_suspend_state(); ---> call early_suspend_work -> early_suspend()
}

- early_suspend()
{
call early_suspend_handler () function in evenry deivces
}



Late Resume:
After all the kernel resume is finished,
the user space process and service is running, the wake up of system for these reasons:

* If In Calling, the modem will send command to rild (RING command),
and rild will send message to WindowManager and Application to deal with in call event,
PowerManagerSerivce also will write "on" to interface to let kernel execute late resume.

* User Key EventWhen system waked by a key event, such as a power key, or menu key,
these key event will send to WindowManager, and it will deal with it, if the key is not the key can wake up system,
such as return key/home key, the WindowManager will drop the wake lock to let system going to suspend again.
if the key is a wake key, the WindowManager will RPC PowerManagerSerivce interface to execute late resume.

* Late Resume will call the resume func in list of early suspend devices.






* Android power management :
reference:http://www.netmite.com/android/mydroid/development/pdk/docs/power_management.html

- Flow:
Application layer : application using wl.newWakeLock(), wl.acquire() and wl.release()

Application framwork: PowerManagement (Android.os.PowerManager)
Power (Android.os.Power)
PowerManagerService (Android.server.PowerManageService)

JNI layer : Power (lib/hardware/power.c)

Linux kernel : Android Power Management (driver/android/power.c)
Linux driver (android_register_early_suspend(), android_register_early_resume())
Linux power Management



- source :
frameworks/base/core/java/android/os/PowerManager.java
frameworks/base/services/java/com/android/server/PowerManagerService.java
frameworks/base/core/java/android/os/Power.java
frameworks/base/core/jni/android_os_power.cpp
hardware/libhardware/power/power.c

2011年8月18日 星期四

change bash when build android source code

build android error
--> dash can't run source
solution 1:

sudo dpkg-reconfigure dash ->No

default sh改成bash

solution2 :
Added "SHELL=/bin/bash" into Makefile

2011年8月7日 星期日

Using search and replace in vi

============================================================================
Using vi to search and replace
This is about as complicated as it gets in vi, since search and replace sytnax is taken from the UNIX sed (stream editor) command.

>> Global search and replace --> :1,$ s/old/new/g
^ ^ ^ ^ ^
In english, this means: | | | | |
| | | | |
From 1 to $ (end of file) | | | |
| | | |
substitute -----------------/ | | |
| | |
occurrences of "old" ----------/ | |
| |
with occurrences of "new" --------/ |
|
globally (i.e., all instances of "old")


========================================================================
Using sed command to replace string in file
#sed -i 's/old/new/g' filename.txt

linux find command

find command:
;find string in current folder all files
#find . -exec grep 'test' {} \;
*{}: this list all files
*\ : this is ending word

The -exec action takes a Unix command (along with its options) as an argument.
The arguments should contain {} (usually quoted), which is replaced in the command with the name of the currently found file.
The command is terminated by a semicolon, which must be quoted ("escaped") so the shell will pass it literally to the find command.


;rm file in current folder all files
#find . -name oo.txt -print -exec rm -f {} \;

;find 00.txt file only looking for file under this folder
#find . -name oo.txt -type f

;find 00.txt file only looking for folder type under this folder
#find . -name 00.txt -type d


using xargs command in find command
#find whatever....| args commnad

xargs is command to execute commnd line from standard input.

;list file
#find . -name xx.txt -print | xargs ls -l

;rmmove files from test folder
#find ./test -type f -print0 | xargs -0 rm

more information in "http://en.wikipedia.org/wiki/Xargs"

Android Makefile follow

reference:http://tw.myblog.yahoo.com/blue-comic/article?mid=676

Android Makefile follow:

Makefile -> build/core/main.mk -> build/core/config.mk -> build/core/envsetup.mk -> build/core/product_config.mk

由 build/core/config.mk 所進行。
build/core/envsetup.mk 檢查 developer 的設定 (buildspec.mk) ,並檢查執行環境,以決定輸出目錄、項目。
build/core/config.mk 本身還依據參數,決定解譯時的相關參數。像是 compiler 的路徑、flags, lex 、yacc 的路徑參數等。
關於 product 的相關設定,則是由 build/core/product_config.mk 所處理,使用 build/core/product.mk 提供之 macro 載入。根據 AndroidProduct.mk 的內容, product_config.mk 決定了

android keycode

android keycode :
reference:
http://wadefs.blogspot.com/2010/12/android-remote-control-keyevent.html
http://blog.yam.com/hansonlin211/article/19171413


input keyevent xx
input text "xxx"

2011年8月4日 星期四

android boot process

reference:
Android boot process :
reference:

http://www.androidenea.com/2009/06/android-boot-process-from-power-on.html
http://huenlil.pixnet.net/blog/post/23862982

android boot img

reference : http://huenlil.pixnet.net/blog/post/23862982

*boot.img = zImage + ramdisk.img
zImage = kernel image
ramdisk.img = out/target/product/blaze/root/
%./out/host/linux-x86/bin/mkbootimg
--kernel zImage
--ramdisk ramdisk.img
--base 0x80000000
--cmdline "console=ttyO2,115200n8 mem=456M@0x80000000 mem=512M@0xA0000000 init=/init androidboot.console=ttyO2"
--board xxxx
-o boot.img.new
Output: boot.img.new
**Note: bootarg is passed to kernel via --cmdline option above



How to unpack/pack ramdisk.img
unpack:
#gunzip -c ../your-ramdisk-file | cpio -i
pack:
#find . | cpio -o -H newc | gzip > ../newramdisk.cpio.gz


+-----------------+
| boot header | 1 page
+-----------------+
| kernel | n pages
+-----------------+
| ramdisk | m pages
+-----------------+
| second stage | o pages
+-----------------+

n = (kernel_size + page_size - 1) / page_size
m = (ramdisk_size + page_size - 1) / page_size
o = (second_size + page_size - 1) / page_size

0. all entities are page_size aligned in flash
1. kernel and ramdisk are required (size != 0)
2. second is optional (second_size == 0 -> no second)

usage: mkbootimg
--kernel
--ramdisk
[ --second <2ndbootloader-filename> ]
[ --cmdline ]
[ --board ]
[ --base
]
[ --pagesize ]
-o|--output


bootimg:
mkdir -p $(IMAGES_PATH)
cd $(IMAGES_PATH) && $(MKIMAGE) --kernel $(KDIR)/arch/arm/boot/zImage \
--ramdisk $(OUT_TARGET_DIR)/ramdisk.img \
--base 0x80000000 --cmdline "$(KERNEL_BOOTPARAMS)" \
--board omap4 -o boot.img && cd -

ex: mkbootimg --cmdline 'no_console_suspend=1 console=null' --kernel your-kernel-file --ramdisk newramdisk.cpio.gz -o mynewimage.img


==========================================================================================================================================
* system.img
#uncompress
%./out/host/linux-x86/bin/simg2img system.img system.img.raw
#mount to directory mnt-point/
%mkdir mnt-point
%sudo mount -t ext4 -o loop system.img.raw mnt-point/
#modify any .so or apk in the mnt-point/ directory
#rezip
%sudo out/host/linux-x86/bin/make_ext4fs -s -l 512M -a system system.img.new mnt-point/
%sudo umount mnt-point/
Output: system.img.new
=====================================================================================

2011年8月3日 星期三

Android Build Number

reference: http://blog.roodo.com/thinkingmore/archives/14594619.html
http://blog.csdn.net/yrj/article/details/5785894


I only setting : mydroid/build/core/build_id.mk
BUILD_NUMBER := test-2011

2011年8月2日 星期二

vim 整段註解

‧執行 vim 某個 文字檔,進入vim:

1. 先按 Esc 離開 insert mode
2. 再按 ctrl+v 將要註解的這幾行選取(使用上下左右鍵 or + shift )
3. 再按大寫的 I (指的是進入Insert mode)
4. 再輸入 #
5. 最後按 Esc 就會看到選取的這幾行都被 # 註解掉了

2011年6月29日 星期三

i2c command on uboot

#iprobe : probe to discover i2c chip address
#ibus [idx] [spd] : testing i2c bus speed ex: ibus 0 64
64(ST),0x190(FS),0xD480(HS)
#imd: display i2c memory
imd [chip address] [register address] .[show byte .0 .1 .2] [num of byte]
> imd 0x55 0x10.0 10
#imm: write data via i2c address
imm [chip address] [register address>.[show byte .0 .1 .2]

2011年6月28日 星期二

capture log into file from minicom

Ctrl+A+L --> open capture to which file? > input your file which store log
Ctrl+A+L --> close or pause

vim & cscope

reference:
http://blog.chhsu.org/2009/03/multi-projects-of-vim-using-cscope.html
http://rickey-nctu.blogspot.com/2009/02/vim-srcexpl.html

Installing:
sudo apt-get install cscope ctags

Build my environment:
step1: Put debug.sh into ~/bin/
#!/bin/bash
CSCOPE_FILE=cscope.out
if [ -n "$1" ]; then
echo "Source code directory: " $1
echo "Create file map : " $CSCOPE_FILE
find $1 -name "*.h" -o -name "*.c" -o -name "*.cpp" > $CSCOPE_FILE
cscope -bkq -i $CSCOPE_FILE
# cscope -Rbkq
ctags -R
else
echo "Please key-in path of project"
fi

step2: modify cscope_map.bin on /usr/share/vim/vim72/plugin/cscope-map.bin
let i = 1
while i < 20
if filereadable("cscope.out")
let db = getcwd() . "/cscope.out"
"echo db
let $CSCOPE_DB = db
cs add $CSCOPE_DB
let i = 20
else
cd ..
let i += 1
endif
endwhile

Debug:
step1:
go to project and type: #debug.sh

step2:
Open you want to trace code via vi
ex: vi /arch/arm/mach-xxx/board_xxxx.c

Trace code :
(Ctrl+\+c) : who call this function --> (Ctrl+\+t): return back
(Ctrl+\+g) : find this function defination --> (Ctrl+\+t) : return back
(Ctrl+\+s) : which function uses this function --> (Ctrl+\+t) : retunn back

2011年6月27日 星期一

view code by ctags

Exuberant Ctags
Installing :apt-get install exuberant-ctags

@setup taglist

Edit: /etc/vim/vimrc

"Tglist edit
set tags=tags;
set autochdir
nnoremap :TlistToggle

@ Create tags into root directory of project
# ctags -R *

@ Operation
step1 : Don't open screen
step2: Open Tlist via F9
step3: Open you want to see functino via Ctrl+]
If you want to open new window to see this function, you can type Ctrl+w+]
step4: Return your main window Ctrl+t
Or, you can close your new winodw which see this function, you can type Ctrl+w+q

@You can change your window size by Ctrl+w+"+" or Ctrl+w+"-"

2011年4月19日 星期二

git tags

#git tag HEAD
#git push --tags origin

android
#repo forall -pv -c git tag HEAD
#repo forall -pv -c git push --tags

learning bash script

http://www.mgt.ncu.edu.tw/~dino/script/

http://www.twbsd.org/cht/book/ch24.htm

http://www.freeos.com/guides/lsst/

7za

http://www.dotnetperls.com/7-zip-examples

# 7za a -t7z test.7z ./test

2011年4月12日 星期二

create lib/modules

su -
/system/bb/dmesg -n1
/system/bb/ash
export PATH=/system/bb:$PATH; mount -oremount,rw /; mkdir -p /lib/modules/`uname -r`;

2011年4月11日 星期一

iperf udp

UDP throughput test
RX :
- DUT :iperf -s -u -i1 &
- PC : iperf.exe -c -b50M -t60 -i1 &
TX :
- PC : iperf.exe –s –u –i1 &
- DUT : iperf –c -b50M –t60 –i1 &

2011年2月24日 星期四

Generate git patch

step1:
#git format-patch -o /tmp/ xxxxx^..xxxx
^上一筆
..到
xxxxx^..xxxx : 給範圍
ex:

git format-patch -o /tmp/ 401dcd873a6550158429999039cc3c1fcbbc3ee9^..401dcd873a6550158429999039cc3c1fcbbc3ee9

step2:
Using vi to modify BSP (replace)
:%s/xxxxx/xxxx

step3: Patch file
#git --reject /tmp/xxxx.patch
(
if successfully,
this patch step3 is done
else
Please go step4. Please manually resolve rejected hunk!!
)


step4:
If patch successfully, you can git add
#git add xxxx file name

step5:
#git am --resolved

step6:
#git push