有客户反馈不知道如何调试recovery,在这里介绍下recovery的调试方法。
1. 如何在recovery模式使用adb
在recovery模式下,init程序加载的rc文件是bootable/recovery/etc/init.rc。
view plain service adbd /sbin/adbd recovery disabled # Always start adbd on userdebug and eng builds on property:ro.debuggable=1 write /sys/class/android_usb/android0/enable 1 start adbd 这里可以看到如果是在userdebug或者eng编译模式,adbd服务是启动的。执行adb shell时提示不存在system/bin/sh,因为这个时候recovery/root/system为空,并没有sh程序可执行。
虽然adb shell不能执行,但adb的其他很多命令都是能够使用的。
adb devices
adb push/pull
2. 如何增加log
在recovery的代码中能看到有两种方式添加的打印信息:printf和UI->Print。
printf输出到stdout好理解,UI->Print调用screen_ui的print函数,将信息显示在屏幕上。
view plain void ScreenRecoveryUI::Print(const char *fmt, ...) { char buf[256]; va_list ap; va_start(ap, fmt); vsnprintf(buf, 256, fmt, ap); va_end(ap); fputs(buf, stdout); 除了显示在屏幕上,也将信息输出到了stdout标准输出。
3. 标准输出信息在哪
view plain int main(int argc, char **argv) { // If these fail, there's not really anywhere to complain... freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL); freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL); view plain static const char *LAST_LOG_FILE = "/cache/recovery/last_log"; static const char *LAST_INSTALL_FILE = "/cache/recovery/last_install"; static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log"; recovery.cpp的main函数中,最开始就将stdout的输出信息保存在了/tmp/recovery.log文件中。也就是说我们需要查看的log信息都在这里。
再看看recovery结束时做了什么
view plain static void finish_recovery(const char *send_intent) { // Copy logs to cache so the system can find out what happened. copy_log_file(TEMPORARY_LOG_FILE, LOG_FILE, true); copy_log_file(TEMPORARY_LOG_FILE, LAST_LOG_FILE, false); copy_log_file(TEMPORARY_INSTALL_FILE, LAST_INSTALL_FILE, false); chmod(LOG_FILE, 0600); chown(LOG_FILE, 1000, 1000); // system user chmod(LAST_LOG_FILE, 0640); chmod(LAST_INSTALL_FILE, 0644); 将"/tmp/recovery.log"拷贝到了"/cache/recovery/last_log"。 4. 如何查看log
1)如果能使用adb,在recovery模式下就能使用adb pull出log信息
adb pull /tmp/recovery.log .\
2)即使adb服务不能使用,前一次recovery的log也会保存到cache/recovery目录下,在reboot正常进入系统后pull 出来查看。
adb pull /cache/recovery/last_log .\
cache/recovery/last_install保存的是最后一次更新的OTA包
