【android系统】android系统升级流程分析(四)---recovery升级过程中log调试方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/twk121109281/article/details/90898861

前面的文章我们介绍recovery模式升级流程,以及升级脚本的的基本语法。今天我们来看下升级过程中我们应该怎么添加调试信息,怎么更方便的获取调试信息。


基本环境

Android 版本:android 6.0

芯片硬件:全志H6

常见的log获取方式

我们在调试recovery升级的时候,我们经常需要查看recovery的log,google的原始逻辑中,recovery的log并非直接输出到串口,我们需要输入命令才能获取,我们有三种方式:

    第一种:recovery下,输入命令,cat /tmp/recovery.log

    第二种:android下,输入命令,cat  /cache/recovery/last_log

在我这个环境下不可以输入命令,所以每次查看调试信息都是需要重启,然后通过第二种方式进程log个查看。有没有更方便的方式获取到调试信息呢。有,那就是将log直接输出到串口。

输出到串口

有时候我们需要把recovery的log直接输出到终端串口,则我们需要修改下recovery的代码即可:

代码路径:bootable/recovery/recovery.cpp

源代码:

static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log";
static void redirect_stdio(const char* filename) {
    // If these fail, there's not really anywhere to complain...
... ...
    //重定向输出
    freopen(filename, "a", stdout); setbuf(stdout, NULL);
    freopen(filename, "a", stderr); setbuf(stderr, NULL);
... ...
}
 
Int main(int argc, char **argv) {
    ... ...
    redirect_stdio(TEMPORARY_LOG_FILE);
    ... ...
}

修改:

我们只需要把redirect_stdio函数的参数,有”/tmp/recovery.log”修改为”/dev/console”即可。

static const char *TEMPORARY_LOG_FILE = ”/dev/console”;

不同的平台可能有所不一样,可以先这样验证

echo “111111111” > /dev/console

检验下是否能够把打印正常输出到串口。

当然还有些盆友家里有矿,是有外接屏的,这样查看log就更方便了。

打印到屏幕

调用recovery里面的接口就能直接打印到屏幕。

路径:

bootable/recovery/updater/install.h

void uiPrintf(State* state, const char* format, ...);

实例:

uiPrintf(state, "%s: failed to mount %s at %s: %s\n",name, location, mount_point, strerror(errno));

源码:

static void uiPrint(State* state, const std::string& buffer) {
    UpdaterInfo* ui = reinterpret_cast<UpdaterInfo*>(state->cookie);

    // "line1\nline2\n" will be split into 3 tokens: "line1", "line2" and "".
    // So skip sending empty strings to UI.
    std::vector<std::string> lines = android::base::Split(buffer, "\n");
    for (auto& line: lines) {
        if (!line.empty()) {
            fprintf(ui->cmd_pipe, "ui_print %s\n", line.c_str());
            fprintf(ui->cmd_pipe, "ui_print\n");
        }
    }

    // On the updater side, we need to dump the contents to stderr (which has
    // been redirected to the log file). Because the recovery will only print
    // the contents to screen when processing pipe command ui_print.
    fprintf(stderr, "%s", buffer.c_str());
}

__attribute__((__format__(printf, 2, 3))) __nonnull((2))
void uiPrintf(State* state, const char* format, ...) {
    std::string error_msg;

    va_list ap;
    va_start(ap, format);
    android::base::StringAppendV(&error_msg, format, ap);
    va_end(ap);

    uiPrint(state, error_msg);
}

以上讲的都是在recovery模式下应用是怎么打印的,下面我们看下updater-script脚本语言中的打印是怎么查看的。

updater-script脚本调试信息

一般直接通过ui_print()方法来打印调试信息。使用方法如下:

语法:

ui_print("str");

说明:

屏幕打印输出"str"

例如:

ui_print("It's ready!");

屏幕打印It’s ready!

结束语

以上就是对升级过程中调试log,希望对大家有所帮助。感兴趣的同学可以关注我们的微信公众号。

å¨è¿éæå¥å¾çæè¿°

上一篇:【android系统】android系统升级流程分析(三)---updater-script语法(文尾含实例分析)

下一篇:目录

猜你喜欢

转载自blog.csdn.net/twk121109281/article/details/90898861