recovery调试方法

来源:互联网 发布:淘宝联名信用卡哪个好 编辑:程序博客网 时间:2024/06/14 12:27


转自: http://blog.csdn.net/u011477661/article/details/17116993

有客户反馈不知道如何调试recovery,在这里介绍下recovery的调试方法。

1. 如何在recovery模式使用adb

在recovery模式下,init程序加载的rc文件是bootable/recovery/etc/init.rc。

view plain
  1. service adbd /sbin/adbd recovery  
  2.     disabled  
  3.   
  4. # Always start adbd on userdebug and eng builds  
  5. on property:ro.debuggable=1  
  6.     write /sys/class/android_usb/android0/enable 1  
  7.     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
  1. void ScreenRecoveryUI::Print(const char *fmt, ...)  
  2. {  
  3.     char buf[256];  
  4.     va_list ap;  
  5.     va_start(ap, fmt);  
  6.     vsnprintf(buf, 256, fmt, ap);  
  7.     va_end(ap);  
  8.   
  9.     fputs(buf, stdout);  
除了显示在屏幕上,也将信息输出到了stdout标准输出。


3. 标准输出信息在哪

view plain
  1. int  
  2. main(int argc, char **argv) {  
  3.       
  4.     // If these fail, there's not really anywhere to complain...  
  5.     freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL);  
  6.     freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL);  
view plain
  1. static const char *LAST_LOG_FILE = "/cache/recovery/last_log";  
  2. static const char *LAST_INSTALL_FILE = "/cache/recovery/last_install";  
  3. static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log";  
recovery.cpp的main函数中,最开始就将stdout的输出信息保存在了/tmp/recovery.log文件中。也就是说我们需要查看的log信息都在这里。

再看看recovery结束时做了什么

view plain
  1. static void  
  2. finish_recovery(const char *send_intent) {  
  3.     // Copy logs to cache so the system can find out what happened.  
  4.     copy_log_file(TEMPORARY_LOG_FILE, LOG_FILE, true);  
  5.     copy_log_file(TEMPORARY_LOG_FILE, LAST_LOG_FILE, false);  
  6.     copy_log_file(TEMPORARY_INSTALL_FILE, LAST_INSTALL_FILE, false);  
  7.     chmod(LOG_FILE, 0600);  
  8.     chown(LOG_FILE, 1000, 1000);   // system user  
  9.     chmod(LAST_LOG_FILE, 0640);  
  10.     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包

0 0
原创粉丝点击