1. 程式人生 > >Android核心開發 adb遠端除錯核心模組

Android核心開發 adb遠端除錯核心模組

PS:關於核心模組如何編寫編譯,有空再補上

1、連線遠端Android裝置

D:\test>adb.exe connect 192.168.1.3
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
connected to 192.168.1.3:5555

連線本地Android模擬器

adb.exe connect 127.0.0.1:5554

進入Android shell模式

D:\test>adb.exe shell
[email protected]
:/ #

2、建立目錄並遠端上傳核心模組檔案

建立目錄,因為只讀屬性會失敗,下面有解決方法。

[email protected]:/ # mkdir /llqqww

Ctrl+C退出Android shell,adb遠端上傳檔案

D:\test>adb push word_count.ko /llqqww
332 KB/s (72176 bytes in 0.212s)

進入shell模式檢視,檔案上傳成功

D:\test>adb.exe shell
[email protected]:/ # cd /llqqww
[email protected]:/ # ls
word_count.ko

mkdir failed for , Read-only file system的解決辦法

先:adb shell 後:mount -o remount ,rw /

ro只讀屬性

3、載入模組

載入核心模組前沒有"word_count"裝置

[email protected]:/llqqww # ls /dev/ | grep word_count

沒有相關日誌訊息

[email protected]:/llqqww # dmesg

載入核心模組後多了"word_count"裝置

[email protected]:/llqqww # insmod word_count.ko
[email protected]
:/llqqww # ls /dev/ | grep word_count word_count

向裝置輸入資料

[email protected]:/llqqww # echo hello > /dev/word_count
[email protected]:/llqqww # cat /dev/word_count
hello
[email protected]:/llqqww # cat /dev/word_count

解除安裝核心模組

[email protected]:/llqqww # rmmod word_count.ko

有核心載入成功、核心模組讀寫和解除安裝的相關日誌訊息

[email protected]:/llqqww # dmesg
<4>[ 4954.270000] word_count init success!
<4>[ 5110.280000] count_write:write_count:6
<4>[ 5130.860000] read:read_count:6
<4>[ 5130.860000] read:read_count:0
<4>[ 5134.530000] read:read_count:0
<4>[ 5403.450000] word_count exit success!