Android recovery支持adb shell
Android recovery支持adb shell
?
最近開發過程注意到recovery不支持adb shell,為了便于調試方便,決定增加此功能。
?
剛開始我們采用的是user版本系統,進入recovery后,輸入adb shell命令,提示“error: no devices/emulators found”,我們先確認recovery.img是否包含有adb,看out\debug\target\product\xxx\recovery\root\sbin是否有adb文件(源代碼\system\core\adb),然后檢查\bootable\recovery\etc\init.rc下關于adbd
service adbd /sbin/adbd--root_seclabel=u:r:su:s0 --device_banner=recoverydisabledsocket adbd stream 660 system systemseclabel u:r:adbd:s0# Always start adbd on userdebug and engbuilds on property:ro.debuggable=1write /sys/class/android_usb/android0/enable 1start adbd# Restart adbd so it can run as root on property:service.adb.root=1write /sys/class/android_usb/android0/enable 0restart adbd write/sys/class/android_usb/android0/enable 1從上面可知init.rc 中adbd 是配置的,disabled 表示開機不啟動,如? ro.debuggable 被置為1,那么adb 就會開啟,或是service.adb.root設置為1,則重啟adbd。
?
ro.debuggable 在\build\core\main.mk下面的內容賦值
ifeq (true,$(strip$(enable_target_debugging)))#Target is more debuggable and adbd is on by defaultADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1enable_target_debugging 在\build\core\main.mk下面的內容賦值:
## user/userdebug ##user_variant := $(filter useruserdebug,$(TARGET_BUILD_VARIANT)) enable_target_debugging := true tags_to_install := ifneq (,$(user_variant))#Target is secure in user builds.ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1ifeq ($(user_variant),userdebug)#Pick up some extra useful toolstags_to_install += debug#Enable Dalvik lock contention logging for userdebug builds.ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500else#Disable debugging in plain user builds.enable_target_debugging :=#Add for testUsbDebugging()ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=1Endif … Endif可知默認為enable_target_debugging := true,根據user_variant的值如果為user,則enable_target_debugging :=,這又和TARGET_BUILD_VARIANT有關,此變量對應于VARIANT_CHOICES=(user userdebug eng)中的一個值,由我們來選擇,相關的實現在\build\envsetup.sh中。
?
根據上面可知,編譯時如果選擇userdebug或是eng,則ro.debuggable=1,下面我們選擇eng版本編譯recovery.img,進入recovery后,輸入adb shell命令,提示:
Exec ‘/system/bin/sh’ failed:No such fileor directory(2)
表示沒有sh這個文件,無法進入shell,檢查ramdisk 文件系統 system 目錄為(out\debug\target\product\xxx\recovery\root\system)空,但我們知道boot.img下是可以的,看\system\core\rootdir\init.rc檢查boot.img 啟動的init.rc 關于sh的
service console /system/bin/shclass coreconsoledisableduser shellgroup shell logseclabel u:r:shell:s0on property:ro.debuggable=1 start console可知是啟動了sh這控制臺的,所以需要在bootable\recovery\etc\init.rc增加相應的內容:
?
圖1
我們知道out\debug\target\product\xxx\recovery\root\system下沒有bin文件夾(當然也沒有sh),所以需要在編譯的時候創建,需要\build\core\Makefile增加創建目錄和把out目錄下的/system/bin/sh拷貝到out/recovery/system/bin目錄下
?
圖2
但這樣還是不行,后來知道recovery可執行文件是靜態編譯的,之所以這樣是因為recovery模式中沒有共享庫還有缺動態鏈接庫加載器(/system/bin/linker,Android動態連接器linker與靜態連接器ld)。
?
所以\external\mksh\Android.mk
圖3
參考鏈接:
Android recovery.img 支持adb shell
http://blog.csdn.net/chituhuan/article/details/52383655
?
[IMX6Q][Android5.1]移植筆記 --- Recovery mode的shell功能實現(sh+toolbox)
http://blog.csdn.net/kris_fei/article/details/50921384
?
Android Recovery 支持 Adb
http://www.jianshu.com/p/a0bdcce0a5e1
?
總結
以上是生活随笔為你收集整理的Android recovery支持adb shell的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 修改Linux内核的printk缓冲区(
- 下一篇: linux内核 DebugFS