12.03.2010
10.19.2010
fgetc, fgets, fflush
fgetc 是一次只get 一個字元
當 fgetc(stdin)執行時,
是要等有抓到 "enter" 或是 EOF 才會離開
如果user 打很多字,最後才按"enter"
則fgetc return 的值是第一個字,但後面第二個字到"enter"還在 steam 裡
所以下一次的fgetc(stdin)就會抓到下一個字元
可以用下列方式來清
void flush_input ( FILE *in )
{
int c;
while ( ( c = fgetc ( in ) ) != EOF && c != '\n' );
clearerr ( in );
}
printf 也是, 如果印的內容最後沒有"\n" 或 EOF
則不會印出,資料會被keep 在 stream裡
要在之後下 fflush(stdout);
才會印
當 fgetc(stdin)執行時,
是要等有抓到 "enter" 或是 EOF 才會離開
如果user 打很多字,最後才按"enter"
則fgetc return 的值是第一個字,但後面第二個字到"enter"還在 steam 裡
所以下一次的fgetc(stdin)就會抓到下一個字元
可以用下列方式來清
void flush_input ( FILE *in )
{
int c;
while ( ( c = fgetc ( in ) ) != EOF && c != '\n' );
clearerr ( in );
}
printf 也是, 如果印的內容最後沒有"\n" 或 EOF
則不會印出,資料會被keep 在 stream裡
要在之後下 fflush(stdout);
才會印
2.02.2010
如何訂立目標
第一步: 是把這組人員、專長、想做什麼都列出來~
第二步: 一口氣把這整篇都唸一遍
第三步: 重覆第二步九次~
第四步: 閉目放空然後才想看看要做什麼
第五步: 想像可以做到怎麼樣,有什麼benefit
第六步: 睜開眼睛,然後開始把想像依照實際的可掌握度打個五折
第七步: 告訴組員你的想法,然後充份討論
第八步: 給個時間讓目標確立、沈澱
第九步: 依照目標開始設立實施計畫
http://benson-privategarden.spaces.live.com/blog/cns!1A56B35B2B46AD49!288.entry
個人目標 ->
第一步: 閉上眼睛,想像目標可以做到怎麼樣,有什麼benefit
第二步: 睜開眼睛,然後開始把想像依照實際的可掌握度打個五折
第三步: 告訴別人,你的想法,然後充份討論
第四步: 給個時間讓目標確立、沈澱
第五步: 依照目標開始設立實施計畫
第二步: 一口氣把這整篇都唸一遍
第三步: 重覆第二步九次~
第四步: 閉目放空然後才想看看要做什麼
第五步: 想像可以做到怎麼樣,有什麼benefit
第六步: 睜開眼睛,然後開始把想像依照實際的可掌握度打個五折
第七步: 告訴組員你的想法,然後充份討論
第八步: 給個時間讓目標確立、沈澱
第九步: 依照目標開始設立實施計畫
http://benson-privategarden.spaces.live.com/blog/cns!1A56B35B2B46AD49!288.entry
個人目標 ->
第一步: 閉上眼睛,想像目標可以做到怎麼樣,有什麼benefit
第二步: 睜開眼睛,然後開始把想像依照實際的可掌握度打個五折
第三步: 告訴別人,你的想法,然後充份討論
第四步: 給個時間讓目標確立、沈澱
第五步: 依照目標開始設立實施計畫
11.20.2009
9.14.2009
7.09.2009
業餘跟職業的差別
最近看了Robert Kiyosaki 的文章裡提到的一段話,感同深受
"People say amateurs play for the love of the game and professionals play for money. That is not true. Amateurs are amateurs because they do not love the game enough. When it is cold and rainy, a professional golfer will play. The amateur will not. When they are sick, the professional will play. The amateur stays in bed. When they are losing, the professional will practice harder and enter more tournaments. The amateur will quit and take up tennis."
記得還是小學的時候,很喜歡玩棒球,常常在中午大熱天,同學想休息的時候,拉著他們一起去玩。很懷念那時單純渴望的感覺。那時如果我爸繼續讓我打球,也許現在我也是王建民 :P
現在看看自己再做的事,不至於厭惡,但也沒有小時的熱誠。我也算是業餘在我這一行 = ="
5.21.2009
USB On-The-Go Basics - Cable
在 USB 的世界裡,有分Host跟Peripheral ,任何的傳輸動作都是 Host先 send 封包出來,所以知道誰是 Host 誰是 Peripheral 是很重要的在USB的protocol 裡, 再因為 USB cable 是決定OTG devcie是當A-Device(Host)還是B-Device(peripheral)的依據,所以我們先認識一下USB OTG 的 cable.
- 一般標準的USB cable 的頭就有分A 頭跟B 頭,A頭就是接Host, B頭就是接peripheral.
- 後來多了一個叫 mini-USB 的B頭,是給像隨身聽這類小產品用的,也都只是當peripheral
- 後來又出了一個叫 OTG mini-AB receptacle.就是專給 OTG deivce 用的母頭. 它可接mini-A公頭也可接mini-B公頭
- 下圖上方,是Camera 當 Host, Printer當 Peripheral ,它可能的功能就是讓Camera 裡的照片直接透過Printer印出。下方那一個,兩個Camera 都是用OTG Mini-AB 母頭,也就是可插A頭也可插B頭,那要怎麼區分誰是 Host? 誰是 Peripheral呢? 就是靠 cable 的接頭來決定。在A頭跟B頭裡面的 ID pin 是不同的,A頭裡 ID是pull low, B頭裡ID是pull hi。而 device 再依照ID pin 來決定自己是Host 還是peripheral。
- 因為Mini-AB母頭可接A or B, 在這樣的情形下 user 有可能會接反,如下圖,原本Camera是要當Host,因為接反插入 B 頭而變為 Peripheral, 而 Printer 也是一樣,那不就不能動了。好再OTG 架構也想到這個問題,所以提供了一個叫 Host Negotiation Protocol (HNP) 來結決這個問題,讓 user 不用換 calbe 也可繼續用。





5.12.2009
5.11.2009
USB OTG flow at Qaulcomm
BOOL Cl13611OTG::ISTProcess() @ Cl13611.cpp (\wm\platform\qcmsm\src\drivers\usb\highspeed\otg)
-> BOOL Cl13611OTG::UpdateInput()
-> BOOL Cl13611OTG::EventNotification()
-> BOOL USBOTG::EventNotification() @ Usbotg.cpp (\wm\public\common\oak\drivers\usbotg\mdd)
do
-> BOOL Cl13611OTG::UpdateInput() @ Cl13611.cpp (\wm\platform\qcmsm\src\drivers\usb\highspeed\otg)
-> USBOTG_STATES USBOTG::StateChange(USBOTG_STATES usbOtgState) @ Usbotg.cpp (\wm\public\common\oak\drivers\usbotg\mdd)
-> BOOL USBOTG::EnterState(USBOTG_STATES usbOtgState)
if (OTG state has changed)
BOOL Cl13611OTG::NewStateAction(USBOTG_STATES usbOtgState , USBOTG_OUTPUT usbOtgOutput) @Cl13611.cpp (\wm\platform\qcmsm\src\drivers\usb\highspeed\otg)
-> BOOL Cl13611OTG::SetupTransCtr(USBOTG_OUTPUT usbOtgOutput)
if(usbOtgOutput.bit.drv_vbus)(A-device is driving Vbus)
turn on Vbus
else
turn off Vbus
if (usbOtgOutput.bit.loc_sof = true) (loccal device is generating activity on the bus)
LoadUnloadHCD(TRUE)
else
LoadUnloadUSBFN(TRUE)
-> BOOL USBOTG::NewStateAction(USBOTG_STATES usbOtgState , USBOTG_OUTPUT usbOtgOutput )
elsebreak while()
while(OTG state != USBOTG_states_unknow)
5.05.2009
USB and Chargering
在USBIF 裡有測到下列狀況的VBUS電流:
1. USB 有認到時的電流: 100mA/500mA
2. USB 沒(還沒)認到時的電流: 100mA/500mA
3. 電腦 suspend 時的電流: 2.5mA
4. 正常運作時的電流: 100mA/500mA
所以有兩個地方,USB 需通知charging driver
1. 電腦認到 USB 時
2. 電腦 suspend 時
*以下是 Quallcomm 認到通知的flow(quallcomm 是以有被設了new address 才開始充電)
UfnPdd_SetAddress() @Msm_usbhs.cpp (\wm\platform\qcmsm\src\drivers\usb\highspeed\fn)
-> UfnPDD_NotifyChargerCurrent(), 帶pdd->dChargerCurrent進去,init 在 s_deviceRegParams @Msm_subhs.cpp, 目前設定100, 意思是 100 mA
-> DeviceIOControl 帶IOCTL_OTG_SET_REMOTE_DEV_A_INFO 參數,和要充的電流大小
Cl13611OTG::IOControl() @Cl13611.cpp (\wm\platform\qcmsm\src\drivers\usb\highspeed\otg)
這裡會收到 IOCTL_OTG_SET_REMOTE_DEV_A_INFO , pBufIn 就是要充的電流大小
*以下是 電腦 suspend 通知的 flow
UfnPDD_NotifySuspend() @Msm_usbhs.cpp (\wm\platform\qcmsm\src\drivers\usb\highspeed\fn)
這個不是WINAPI ,找不到從哪裡call 來,可能是 Quallcomm 的lib
-> UfnPDD_NotifyChargerCurrent(), 帶current 變數進去,如果是suspend, current=0
如果不是,current=100
-> DeviceIOControl 帶IOCTL_OTG_SET_REMOTE_DEV_A_INFO 參數,和要充的電流大小
Cl13611OTG::IOControl() @Cl13611.cpp (\wm\platform\qcmsm\src\drivers\usb\highspeed\otg)
這裡會收到 IOCTL_OTG_SET_REMOTE_DEV_A_INFO , pBufIn 就是要充的電流大小
1. USB 有認到時的電流: 100mA/500mA
2. USB 沒(還沒)認到時的電流: 100mA/500mA
3. 電腦 suspend 時的電流: 2.5mA
4. 正常運作時的電流: 100mA/500mA
所以有兩個地方,USB 需通知charging driver
1. 電腦認到 USB 時
2. 電腦 suspend 時
*以下是 Quallcomm 認到通知的flow(quallcomm 是以有被設了new address 才開始充電)
UfnPdd_SetAddress() @Msm_usbhs.cpp (\wm\platform\qcmsm\src\drivers\usb\highspeed\fn)
-> UfnPDD_NotifyChargerCurrent(), 帶pdd->dChargerCurrent進去,init 在 s_deviceRegParams @Msm_subhs.cpp, 目前設定100, 意思是 100 mA
-> DeviceIOControl 帶IOCTL_OTG_SET_REMOTE_DEV_A_INFO 參數,和要充的電流大小
Cl13611OTG::IOControl() @Cl13611.cpp (\wm\platform\qcmsm\src\drivers\usb\highspeed\otg)
這裡會收到 IOCTL_OTG_SET_REMOTE_DEV_A_INFO , pBufIn 就是要充的電流大小
*以下是 電腦 suspend 通知的 flow
UfnPDD_NotifySuspend() @Msm_usbhs.cpp (\wm\platform\qcmsm\src\drivers\usb\highspeed\fn)
這個不是WINAPI ,找不到從哪裡call 來,可能是 Quallcomm 的lib
-> UfnPDD_NotifyChargerCurrent(), 帶current 變數進去,如果是suspend, current=0
如果不是,current=100
-> DeviceIOControl 帶IOCTL_OTG_SET_REMOTE_DEV_A_INFO 參數,和要充的電流大小
Cl13611OTG::IOControl() @Cl13611.cpp (\wm\platform\qcmsm\src\drivers\usb\highspeed\otg)
這裡會收到 IOCTL_OTG_SET_REMOTE_DEV_A_INFO , pBufIn 就是要充的電流大小
4.29.2009
add external jar file as part of a system library
FWIW, it appears that if you add the external jar file as part of a user library, specify that the user library is a system library, and add the user library to the Java Build Path then it will work.
For completeness to do this you can do the following:
1. Right-click the project in Eclipse and select "Build Path -> Add Libraries...".
2. Select User Library from the list and click Next.
3. Click the "User Libraries..." button.
4. Click "New..." in the User Libraries dialog.
5. Give the user library a name and select the System library checkbox and click OK.
6. Highlight the newly added user library in the list and click the "Add JARs..." button and add the desired jar files.
7. Click OK on the User Libraries dialog.
8. Make sure the new user library is checked in the Add Library dialog and click Finish.
For completeness to do this you can do the following:
1. Right-click the project in Eclipse and select "Build Path -> Add Libraries...".
2. Select User Library from the list and click Next.
3. Click the "User Libraries..." button.
4. Click "New..." in the User Libraries dialog.
5. Give the user library a name and select the System library checkbox and click OK.
6. Highlight the newly added user library in the list and click the "Add JARs..." button and add the desired jar files.
7. Click OK on the User Libraries dialog.
8. Make sure the new user library is checked in the Add Library dialog and click Finish.
4.28.2009
AVD(Android Viutual Device)的注意事項
當你正在選擇system image target for 你的AVD時,請心存下列三項
1. target 的 API level 很重要,因為你的應用程式沒辦法在比它的 API Level 還少的 system image 上跑,在應用程式的 manifest 檔的 attribute 裡的 minSdkVersion 有定義.想知道更多資訊有關 system API Level 跟應用程式 minSdkVersion 之間的關系,請看Specifying Minimum System API Version
2. 強烈鼓勵,建立至少一個AVD, 它的 API Level 大於你的應用程式, 因為這可以讓你測試你的應用程式的forward-compatibility. forward-compatibility 的測試可用來保證,使用者透過system update download 你的應用程式之後,可以運作正常。
3. 如果你的應用程式宣告了一個 user-library 元件在它的 manifest 檔,那這個應用程式只能跑在有外部 library 的 system image.如果你要你的應用程試跑在你建立的 AVD 上, 請確定應用程式的 uses-library element 還有所選的 system image target 有無 includes 那個 library.
Keep these points in mind when you are selecting a system image target for your AVD:
1. target 的 API level 很重要,因為你的應用程式沒辦法在比它的 API Level 還少的 system image 上跑,在應用程式的 manifest 檔的 attribute 裡的 minSdkVersion 有定義.想知道更多資訊有關 system API Level 跟應用程式 minSdkVersion 之間的關系,請看Specifying Minimum System API Version
The API Level of the target is important, because your application will not be able to run on a system image whose API Level is less than that required by your application, as specified in the minSdkVersion attribute of the application's manifest file. For more information about the relationship between system API Level and application minSdkVersion, see Specifying Minimum System API Version.
2. 強烈鼓勵,建立至少一個AVD, 它的 API Level 大於你的應用程式, 因為這可以讓你測試你的應用程式的forward-compatibility. forward-compatibility 的測試可用來保證,使用者透過system update download 你的應用程式之後,可以運作正常。
Creating at least one AVD that uses a target whose API Level is greater than that required by your application is strongly encouraged, because it allows you to test the forward-compatibility of your application. Forward-compatibility testing ensures that, when users who have downloaded your application receive a system update, your application will continue to function normally.
3. 如果你的應用程式宣告了一個 user-library 元件在它的 manifest 檔,那這個應用程式只能跑在有外部 library 的 system image.如果你要你的應用程試跑在你建立的 AVD 上, 請確定應用程式的 uses-library element 還有所選的 system image target 有無 includes 那個 library.
If your application declares a uses-library element in its manifest file, the application can only run on a system image in which that external library is present. If you want your application to run on the AVD you are creating, check the application's uses-library element and select a system image target that includes that library.
4.27.2009
實作一個假的 character driver 在emulator 上跑
大致上的做法就是將自己 build 的 kernel 放到 emulator, 然後再將自製假的 driver 放進 emulator 裡跑
1. 將 .config 從模擬器裡抓出來
因為模擬器裡的 kernel 的 CONFIG_MODULE 是關掉的。所以我們需要將它打開,否則不能 insmod 。
開了之後就要重 build 出 kernel image (zImage). 而要 build kernel 就需要模擬器裡的 kernel 的 .config。
先下載 Android 的 sdk , 因為 emulator 就在 SDK 裡,可到下面網址 download(註:我是以SDK 1.1為例子,SDK 1.5 還沒試過)
a. 解壓之後,執行 emulator
b. 在 emulator 執行的狀況下抓/proc/config.gz ,放到 \pulldata下
2. 改 CONFIG_MODULES
將 config.gz 解壓之後放到 /mydroid/kernel 下, 然後找 CONFIG_MODULES ,並改為
3. 改 kernel 的 Makefile
因為我們是跑 arm archtecture ,所以要改 tool chain
在 /mydroid/kernel/Makefile 裡,將 ARCH 跟 CROSS_COMPILE 改為下面
然後將 LDFLAGS_BUILD_ID mark 掉,如下
4. build kernel
(1) 先清乾淨
(2) 將第二步驟的 config 改名為 .config ,放到 /mydroid/kernel 下
(3) make
一開始會問你一些問題,一律都答N
build 完之後,會在 /mydroid/kernel/arch/arm/boot 找到 image, 叫 zImage
5. build fake driver
(1) 從 Linux Device Driver Programming 一書裡,copy 個範例 driver, source C 如下
Makefile 如下,你需要改 KERNELDIR ,這需要指到已經好的kernel,還有命令之前一定要是"tab"
6. 將我們 build 的 zImage 放進 emulator 上跑
-kernel 後面的參數就是指到之前 build 出來的 kernel image
7. 把 busybox 放進 emulator
因為待會要用 busybox 的 mknod 指令( emulator 好像沒有), 所以要將 busybox 放進 emulator
(1) 讓 emulator 的 /system 這個目錄變成可 read/write. 開另一個 cmd 下
(2) 下載 busybox
(3) 把 busybox 放進 emulator
(4) 更改 busybox 權限,否則不能用
8. 把 ko 檔放進 emulator
跟放 busybox 一樣, 把假 driver 放進, 注意 emulator 裡只有 /system 目錄才可對外讀寫, 這裡我是放在 /system/bin
9. 載入 module
跟在 linux 下做的一樣
10. 將 driver 掛上
掛上之前,要先知道它的 major id
知道是 252 之後,就 mknod 上去
1. 將 .config 從模擬器裡抓出來
因為模擬器裡的 kernel 的 CONFIG_MODULE 是關掉的。所以我們需要將它打開,否則不能 insmod 。
開了之後就要重 build 出 kernel image (zImage). 而要 build kernel 就需要模擬器裡的 kernel 的 .config。
先下載 Android 的 sdk , 因為 emulator 就在 SDK 裡,可到下面網址 download(註:我是以SDK 1.1為例子,SDK 1.5 還沒試過)
http://developer.android.com/sdk/1.1_r1/index.html |
a. 解壓之後,執行 emulator
D:\workplace\android-sdk-windows-1.1_r1\tools>emulator |
b. 在 emulator 執行的狀況下抓/proc/config.gz ,放到 \pulldata下
D:\workplace\android-sdk-windows-1.1_r1\tools>adb pull /proc/config.gz |
2. 改 CONFIG_MODULES
將 config.gz 解壓之後放到 /mydroid/kernel 下, 然後找 CONFIG_MODULES ,並改為
CONFIG_MODULES=y |
3. 改 kernel 的 Makefile
因為我們是跑 arm archtecture ,所以要改 tool chain
在 /mydroid/kernel/Makefile 裡,將 ARCH 跟 CROSS_COMPILE 改為下面
ARCH ?=arm CROSS_COMPILE ?=../prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- |
然後將 LDFLAGS_BUILD_ID mark 掉,如下
# LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,$(call ld-option, -Wl$(comma)--build-id,)) |
4. build kernel
(1) 先清乾淨
$make mrproper |
(2) 將第二步驟的 config 改名為 .config ,放到 /mydroid/kernel 下
(3) make
$make |
一開始會問你一些問題,一律都答N
build 完之後,會在 /mydroid/kernel/arch/arm/boot 找到 image, 叫 zImage
5. build fake driver
(1) 從 Linux Device Driver Programming 一書裡,copy 個範例 driver, source C 如下
/* * devone.c * */ #include linux/init.h #include linux/module.h #include linux/types.h #include linux/kernel.h #include linux/fs.h #include linux/cdev.h #include asm/uaccess.h MODULE_LICENSE("Dual BSD/GPL"); static int devone_devs = 1; /* device count */ static int devone_major = 0; /* dynamic allocation */ static int devone_minor = 0; static struct cdev devone_cdev; ssize_t devone_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos) { int i; unsigned char val = 0xff; int retval; for (i = 0 ; i < count ; i++) { if (copy_to_user(&buf[i], &val, 1)) { retval = -EFAULT; goto out; } } retval = count; out: return (retval); } struct file_operations devone_fops = { .read = devone_read, }; static int devone_init(void) { dev_t dev = MKDEV(devone_major, 0); int alloc_ret = 0; int major; int cdev_err = 0; alloc_ret = alloc_chrdev_region(&dev, 0, devone_devs, "devone"); if (alloc_ret) goto error; devone_major = major = MAJOR(dev); cdev_init(&devone_cdev, &devone_fops); devone_cdev.owner = THIS_MODULE; devone_cdev.ops = &devone_fops; cdev_err = cdev_add(&devone_cdev, MKDEV(devone_major, devone_minor), 1); if (cdev_err) goto error; printk(KERN_ALERT "devone driver(major %d) installed.\n", major); return 0; error: if (cdev_err == 0) cdev_del(&devone_cdev); if (alloc_ret == 0) unregister_chrdev_region(dev, devone_devs); return -1; } static void devone_exit(void) { dev_t dev = MKDEV(devone_major, 0); cdev_del(&devone_cdev); unregister_chrdev_region(dev, devone_devs); printk(KERN_ALERT "devone driver removed.\n"); } module_init(devone_init); module_exit(devone_exit); |
Makefile 如下,你需要改 KERNELDIR ,這需要指到已經好的kernel,還有命令之前一定要是"tab"
KERNELDIR=/home/arik/Workspace/aydroid/kernel/ PWD := $(shell pwd) obj-m := devone.o modules: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: rm -rf *.o *~ core.depend .*.cmd *.ko *.mod.c .tmp_versions |
6. 將我們 build 的 zImage 放進 emulator 上跑
D:\workplace\android-sdk-windows-1.1_r1\tools>emulator.exe -kernel D:\workplace\ android-sdk-windows-1.1_r1\tools\lib\images\zImage |
-kernel 後面的參數就是指到之前 build 出來的 kernel image
7. 把 busybox 放進 emulator
因為待會要用 busybox 的 mknod 指令( emulator 好像沒有), 所以要將 busybox 放進 emulator
(1) 讓 emulator 的 /system 這個目錄變成可 read/write. 開另一個 cmd 下
D:\workplace\android-sdk-windows-1.1_r1\tools>adb remount * daemon not running. starting it now * * daemon started successfully * remount succeeded |
(2) 下載 busybox
http://benno.id.au/android/busybox |
(3) 把 busybox 放進 emulator
D:\workplace\android-sdk-windows-1.1_r1\tools>adb push busybox /system/bin 1703 KB/s (0 bytes in 1745016.001s) |
(4) 更改 busybox 權限,否則不能用
D:\workplace\android-sdk-windows-1.1_r1\tools>adb shell # chmod 566 /system/bin/busybox chmod 566 /system/bin/busybox #_ |
8. 把 ko 檔放進 emulator
跟放 busybox 一樣, 把假 driver 放進, 注意 emulator 裡只有 /system 目錄才可對外讀寫, 這裡我是放在 /system/bin
D:\workplace\android-sdk-windows-1.1_r1\tools>adb push devone.ko /system/bin 117 KB/s (0 bytes in 3763.000s) |
9. 載入 module
跟在 linux 下做的一樣
D:\workplace\android-sdk-windows-1.1_r1\tools>adb shell # busybox insmod /system/bin/devone.ko busybox insmod /system/bin/devone.ko # busybox lsmod busybox lsmod Module Size Used by Not tainted devone 2624 0 # |
10. 將 driver 掛上
掛上之前,要先知道它的 major id
# busybox cat /proc/devices busybox cat /proc/devices Character devices: 1 mem 4 /dev/vc/0 4 tty 5 /dev/tty 5 /dev/console 5 /dev/ptmx 7 vcs 10 misc 13 input 29 fb 90 mtd 128 ptm 136 pts 252 devone 253 ttyS 254 rtc Block devices: 1 ramdisk 7 loop 31 mtdblock 43 nbd 179 mmc # |
知道是 252 之後,就 mknod 上去
# busybox mknod /dev/devone c 252 0 busybox mknod /dev/devone c 252 0 # busybox ls -l /dev/devone busybox ls -l /dev/devone crw-rw-rw- 1 0 0 252, 0 Apr 30 02:26 [1;35m/dev/devone[0m # |
4.23.2009
compile android & kernel
* build android
If you just want to force the generation of the systemimage without
rebuilding anything, you should just be able to do
make snod
(snod == systemimage-nodeps)
清除之前make 習
make clean
*build kernel
(1)
.config 要從模擬器上的kernel 拿
下完config.gz 就會在\tools\pulldata\裡
config.gz 就是.config,將它解壓並copy 到你要 build 的kernel 目錄下
其中有個flag CONFIG_MODULE 要設成y ,才可手動載入module
(2)
make mrproper (clean)
make msm_defconfig ARCH=arm
make ARCH=arm CROSS_COMPILE=../prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
(3)載入映像檔到模擬器中:
映像檔位置: (1) 依照android官方網頁的說明,映像檔是放在lib/images下,在我的電腦(os: xp)上是位於
用指令來指定image的方式如下:
如果要重載kernel的image則如下:
如果直接把image檔覆蓋掉在lib/images的檔案也能正常執行。如果使用指令則會啟動模擬器並載入參數路徑所指的映像檔,如下,其實上原本存在於lib/images的映像檔並沒有被參數載入的覆蓋掉!
這裡有講到如何build image for emulator
編譯android原始碼到模擬器上執行
http://www.cookbus.com/show-85-1.html
If you just want to force the generation of the systemimage without
rebuilding anything, you should just be able to do
make snod
(snod == systemimage-nodeps)
清除之前make 習
make clean
*build kernel
(1)
.config 要從模擬器上的kernel 拿
cd\tools
adb pull /proc/config.gz pulldata\config.gz
下完config.gz 就會在
config.gz 就是.config,將它解壓並copy 到你要 build 的kernel 目錄下
其中有個flag CONFIG_MODULE 要設成y ,才可手動載入module
(2)
make mrproper (clean)
make msm_defconfig ARCH=arm
make ARCH=arm CROSS_COMPILE=../prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
(3)載入映像檔到模擬器中:
映像檔位置: (1) 依照android官方網頁的說明,映像檔是放在lib/images下,在我的電腦(os: xp)上是位於
C:\WT\SoftWare\eclipse\android-sdk-windows-1.1_r1\tools\lib\images。
用指令來指定image的方式如下:
emulator -image system.img -data userdata.img -ramdisk ramdisk.img
如果要重載kernel的image則如下:
emulator -kernel/zImage
如果直接把image檔覆蓋掉在lib/images的檔案也能正常執行。如果使用指令則會啟動模擬器並載入參數路徑所指的映像檔,如下,其實上原本存在於lib/images的映像檔並沒有被參數載入的覆蓋掉!
emulator -image backup\system.img
這裡有講到如何build image for emulator
編譯android原始碼到模擬器上執行
http://www.cookbus.com/show-85-1.html
4.22.2009
android permission
我試著建立一個假的character device.
然後想讓它可以被使用在 Android emulator上。
首先, 我在.config 檔加了CONFIG_MODULES,並重編譯了Android Kernel
然後, 我寫了個module 來控制"/dev/mydev"(它扮演著一個 80char 的buffer),並跨平台組譯成arm 架構。
我ran了emulator ,然後將 busybox 放進去(用來建立/dev/mydev 透過 mknod),並用insmod 載入module
目前,透過使用 open/close/write/等.. shell 和 common activities 都可以對它互動
我想要建一個特別的permission給這個device,然後人不能透過 common Activities 來讀取它。
有任何的文件/提醒/連結嘛?
我知道Android 有一個特別的HAL,但沒有文件。
就application style permissions來說,你一般要做的就是去define一個新的gid, 就是你的device 會被發布的gid(如此它就不會被讀/寫),
加一個entry 在\frameworks\base\data\etc\permissions.xml 去對映到 permission string,
然後加一個item在 frameworks/base/core/res/AndroidManifest.xml 來描述這個permission.
gid 的group 是被defined 在user space, 有個 system/init 來defines 這些standard groups.
然後想讓它可以被使用在 Android emulator上。
首先, 我在.config 檔加了CONFIG_MODULES,並重編譯了Android Kernel
然後, 我寫了個module 來控制"/dev/mydev"(它扮演著一個 80char 的buffer),並跨平台組譯成arm 架構。
我ran了emulator ,然後將 busybox 放進去(用來建立/dev/mydev 透過 mknod),並用insmod 載入module
目前,透過使用 open/close/write/等.. shell 和 common activities 都可以對它互動
我想要建一個特別的permission給這個device,然後人不能透過 common Activities 來讀取它。
有任何的文件/提醒/連結嘛?
我知道Android 有一個特別的HAL,但沒有文件。
I'm trying to create a fake character device.
I want to make it usable within the provided Android emulator.
Firstly, I recompiled the Android Kernel editing the .config file,
adding CONFIG_MODULES.
Then, I wrote a module managing "/dev/mydev" (it acts as a 80 char
buffer) and crosscompiled it for arm architecture.
I ran the emulator and pushed busybox (for creating the /dev/mydev
with mknod) and loaded the module with insmod.
Now, both shell and common activities can interact with it, by using
standard open/close/write/etc...
I would like to create a specific permission for that device and make
it not readable from common Activities.
Is there some documentation/hints/links?
I know Android has a specific HAL but there's no documentation.
就application style permissions來說,你一般要做的就是去define一個新的gid, 就是你的device 會被發布的gid(如此它就不會被讀/寫),
加一個entry 在
然後加一個item在 frameworks/base/core/res/AndroidManifest.xml 來描述這個permission.
gid 的group 是被defined 在user space, 有個 system/init 來defines 這些standard groups.
For application style permissions, what you generally do is define a new gid
that your device is published under (so it is not world readable/writeable),
add an entry to etc/permissions.xml mapping that gid to a permission string,
and add an item in the frameworks AndroidManifest.xml describing that
permission.
The meaning of groups is purely defined by user space. There is a
system/init header that defines the standard groups.
4.19.2009
股票模擬遊戲
最近開始再研究股票
就再想怎麼沒有一個網站模擬台股來弄個線上遊戲,每天life 跟真實台股連線
每個人從20萬台幣開始玩,最後也有融資融卷等工具可用
這樣就有地方可以練習,又可累積經驗,但又不用擔心真的了錢
等練到贏率大於80%時就可真的下場投資了
最好是可以真的摸擬實際的市場機制,也就是說當這個遊戲愈多人玩,表示愈多散戶投入,那也應該要反應在遊戲裡面
或者不要反應,也許會比較準對於練習來說
找了一下,如果要玩美股的話有這個網站
Practice Investing, Stock Market Game
如果不用自己的錢去玩,真的可以學到東西嘛?
如何讓人真的serious 去玩就像真的一樣?
就再想怎麼沒有一個網站模擬台股來弄個線上遊戲,每天life 跟真實台股連線
每個人從20萬台幣開始玩,最後也有融資融卷等工具可用
這樣就有地方可以練習,又可累積經驗,但又不用擔心真的了錢
等練到贏率大於80%時就可真的下場投資了
最好是可以真的摸擬實際的市場機制,也就是說當這個遊戲愈多人玩,表示愈多散戶投入,那也應該要反應在遊戲裡面
或者不要反應,也許會比較準對於練習來說
找了一下,如果要玩美股的話有這個網站
Practice Investing, Stock Market Game
如果不用自己的錢去玩,真的可以學到東西嘛?
如何讓人真的serious 去玩就像真的一樣?
4.13.2009
How Linux kernel Init
要了解kernel 如何init
先了解kernel image 的架構

vmlinux 是kernel 本身再加了一些符號什麼的
然後把那些符號拿掉就成了image 的binary
之後用gzip 壓成piggy.gz
然後用asmbaly build 成piggy.o

*bootstrap loader and bootloader的不同
bootloader 只負責POWER ON
*bootstrap loader(second-stage loader),head.o @bootstrap loader
1.creat the proper environment to decompress,
2.relocate the kernel,
3.pass control to head.o@kernel

*head.o @kernel
1.Checks for valid processor and architecture
2.Creates initial page table entries
3.Enables the processor's memory management unit (MMU)
4.Establishes limited error detection and reporting
5.Jumps to the start of the kernel proper, main.c
在這個時候只有有限的memory maping.. 所以如果想在這加個firmwave 去down load到特定的device,是會crash的
要init driver 就透過device driver model
*start_kernel() @ .../init/main.c
先了解kernel image 的架構

vmlinux 是kernel 本身再加了一些符號什麼的
然後把那些符號拿掉就成了image 的binary
之後用gzip 壓成piggy.gz
然後用asmbaly build 成piggy.o

*bootstrap loader and bootloader的不同
bootloader 只負責POWER ON
*bootstrap loader(second-stage loader),head.o @bootstrap loader
1.creat the proper environment to decompress,
2.relocate the kernel,
3.pass control to head.o@kernel

*head.o @kernel
1.Checks for valid processor and architecture
2.Creates initial page table entries
3.Enables the processor's memory management unit (MMU)
4.Establishes limited error detection and reporting
5.Jumps to the start of the kernel proper, main.c
在這個時候只有有限的memory maping.. 所以如果想在這加個firmwave 去down load到特定的device,是會crash的
要init driver 就透過device driver model
*start_kernel() @ .../init/main.c
USB 裝置會挑電腦?
常聽人說我的手機接我的電腦不能連 ActiveSync,但接別台電腦就可連
就說這隻手機會挑電腦
其實這只說對了一部份
當連線的時候,如果USB的訊號差,則USB的protocol 一般都可cover 掉,只要重傳就好了,只是效能沒那麼好而已
但如果訊號差都一定的程度,那就會連不起來
所以我們知道USB的protocol 對壞的訊號有一定的容忍度。
而訊號的好壞取決於三個部份,手機端(device), cable/cradle, 電腦端(host)
手機的lay out 是不是符合標準
cable/ cradle 是不是有太多connector 轉接
電腦端是不是也轉接connector (一般桌機,USB port 前面的比後面的訊號差 )
這三個部份加起來,如果訊號壞到超過potocol的容忍度,就連不起來了
而理論上來說,device 及cable 再出貨時就是要有最佳的匹配,將errors 降到最低,
這樣就有空間,留給電腦的部份,也就比較不會挑電腦了
就說這隻手機會挑電腦
其實這只說對了一部份
當連線的時候,如果USB的訊號差,則USB的protocol 一般都可cover 掉,只要重傳就好了,只是效能沒那麼好而已
但如果訊號差都一定的程度,那就會連不起來
所以我們知道USB的protocol 對壞的訊號有一定的容忍度。
而訊號的好壞取決於三個部份,手機端(device), cable/cradle, 電腦端(host)
手機的lay out 是不是符合標準
cable/ cradle 是不是有太多connector 轉接
電腦端是不是也轉接connector (一般桌機,USB port 前面的比後面的訊號差 )
這三個部份加起來,如果訊號壞到超過potocol的容忍度,就連不起來了
而理論上來說,device 及cable 再出貨時就是要有最佳的匹配,將errors 降到最低,
這樣就有空間,留給電腦的部份,也就比較不會挑電腦了
4.12.2009
用英文,而不是學英文
一直覺得英文只是個工具
而工具,有人用的好,也有人用的不好
重點就是"用"
一個字或片語或句子結構 會不會用就決定你英文的好壞
但沒人規定說要用一個工具就一定要很會用
重點就是看你用它來做什麼
以TOEFL 為例,
就是要了解各個學科的字
及熟練如何表達自己的意思
而TOEIC,
則要多了解商業領域的字
及日常生活的用語
一些有趣的元素可以加入
1. 玩-動機, 新奇好玩
2. 演戲-角色扮演
3.
而工具,有人用的好,也有人用的不好
重點就是"用"
一個字或片語或句子結構 會不會用就決定你英文的好壞
但沒人規定說要用一個工具就一定要很會用
重點就是看你用它來做什麼
以TOEFL 為例,
就是要了解各個學科的字
及熟練如何表達自己的意思
而TOEIC,
則要多了解商業領域的字
及日常生活的用語
一些有趣的元素可以加入
1. 玩-動機, 新奇好玩
2. 演戲-角色扮演
3.
Subscribe to:
Posts (Atom)
