2010年12月9日 星期四

makefile中 : 與 :=的差別

這篇得知

由於Makefile會將檔案所有內容展開之後
在決定變數的值

如果你要在當下就決定變數值  而不要被後面的修改在改變

就要使用:=

:
代表makefile的規格 (而非用於變數宣告)
target: dependencies
Commands

透過Facebook分享

/dev/null vs /dev/zero

dd if=/dev/null of=a.img bs=1M count=50


0+0 records in
0+0 records out
0 bytes (0 B) copied, 2.3351e-05 s, 0.0 kB/s



dd if=/dev/zero of=b.img bs=1M count=50


50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 0.120844 s, 434 MB/s

產生的結果不同


-rw-r--r--  1 nelsonchung nelsonchung         0 2010-12-09 16:34 a.img
-rw-r--r--  1 nelsonchung nelsonchung  52428800 2010-12-09 16:34 b.img

可以把/dev/zero想成一個會產生0的鍵盤
所以b.img是一個全部值為0的檔案



透過Facebook分享

將busybox加入android中

  • 設定環境



============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.2
TARGET_PRODUCT=imx51_bbg
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=FRF85B
============================================



  • add busybox to /out/target/product/dependonyourplatform/system/bin


> make snod

將system內容打包成system.img (內容大小從原本的108863488變成110743552)

這樣子的方式可以讓你不用在重新build android就加入你已經build的程式


將產生出來的system.img mount起來

> mkdir system-another

> mount -o loop system.img system-another

> ls system-another


alsa_amixer        busybox       dhcpcd        getprop    iptables      mke2fs       pand          renice     servicemanager  surfaceflinger  vold
alsa_aplay         cat           dispd         gzip       keystore      monkey       ping          resize2fs  setconsole      svc             watchprops
alsa_ctl           check_prereq  dmesg         hciattach  keystore_cli  mount        pm            rild       setprop         sync            wipe
am                 chmod         dnsmasq       hd         kill          mtpd         pppd          rm         sh              system_server   wpa_cli
applypatch         chown         dumpstate     id         linker        mv           printenv      rmdir      showlease       tc              wpa_supplicant
applypatch_static  cmp           dumpsys       ifconfig   ln            nandread     ps            rmmod      skia_test       testid3
app_process        dalvikvm      dvz           iftop      log           ndc          qemud         route      sleep           toolbox
audioloop          date          e2fsck        ime        logcat        netcfg       qemu-props    run-as     smd             top
bash               dbus-daemon   flash_image   input      logwrapper    netd         racoon        schedtest  stagefright     tune2fs
bluetoothd         dd            fsck_msdos    insmod     ls            netstat      radiooptions  schedtop   stapio          umount
bmgr               debuggerd     gdbjithelper  installd   lsmod         newfs_msdos  reboot        sdptool    staprun         updater
bootanimation      dexopt        gdbserver     ioctl      mediaserver   notify       record        sendevent  start           vdc
bugreport          df            getevent      ionice     mkdir         omx_tests    recovery      service    stop            vmstat

果然看到busybox

將system.img放到sd卡上

開機執行  可以直接run 

busybox

以前是放到data folder下要執行需要

cd data
./busybox ls .....

現在
busybox ls....

透過Facebook分享

system.img and ramdisk.img的生成

system.img 是由 dd 將 system folder轉出生成
ramdisk.img 是由 dd 將 root folder轉出生成

android在build過程  會將各個需要的東西 放到system or root folder去
android使用android.mk來build所需要的東西

img格式是一個檔案
不是設備
linux掛載的時候需要用mount -o loop A.img B
將A.img 掛載到/dev/loopx下
在將/dev/loopx掛載給B

最後  你就可以操作B folder的時候  就等於在操作A.img
加檔案 刪除檔案  同時也會改變A.img

產生一個200M的A.img
dd if=/dev/zero of=A.img bs=1M count=200

mkfs.ext4 A.img

產生一個目錄
sudo mkdir system-another

掛載
sudo mount -o loop A.img system-another

cd system-another

vim test.txt

:wq

卸載
umount system-another

 此時text.txt已經在A.img裡面

透過Facebook分享

啟動thread on linux

使用kthread_run
第一個參數  function name
第二個參數  可以設成NULL, 除非你有要傳入的data
第三個參數  namefmt (猜測應該是這個thread的稱呼)


Reference:
http://blog.chinaunix.net/u1/35356/showart_1422907.html


在hub.c看到hub_port_init會一直被執行到
原來是因為usb_hub_init的地方有用kthread_run去run一個thread

當hub port改變的時候就會run到

透過Facebook分享