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 就會看到選取的這幾行都被 # 註解掉了