[System] android android system upgrade process analysis (four) --- recovery during the upgrade log debugging method

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/twk121109281/article/details/90898861

Previous article we introduce recovery mode upgrade process, and upgrade basic syntax of the script. Today we look at how the upgrade process, we should add debug information, how to obtain more convenient debugging information.


Basic environment

Android version: android 6.0

Chip Hardware: H6 Chi

Common log acquisition mode

We debugging recovery upgrade, we often need to see the recovery of the log, Google primitive logic of, the recovery log is not output directly to the serial port, enter the command we need to get, we have three ways:

    The first: the recovery, enter commands, cat /tmp/recovery.log

    The second: the next android, enter the command, cat / cache / recovery / last_log

In this environment, I can not enter commands, so each time you view the debugging information is needed to restart, and then log a second way to see the process through. There is no more convenient way to get debug information yet. Yes, that is the log output directly to the serial port.

Output to the serial port

Sometimes we need to put the recovery log output directly to the terminal serial port, then we need to modify the code to the next recovery:

Code path: bootable / recovery / recovery.cpp

Source:

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);
    ... ...
}

modify:

We just need to redirect_stdio function parameters, there are "/tmp/recovery.log" changed to "/ dev / console" can be.

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

Different platforms may be different, so you can first verify

echo “111111111” > /dev/console

Whether the test under normal print output to the serial port.

Of course, there are also some pots Friends of mine at home, there is an external screen, so even more convenient to view the log.

Printed to the screen

Call recovery inside interface will be able to print directly to the screen.

path:

bootable/recovery/updater/install.h

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

Example:

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

Source:

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);
}

Above are talking about in recovery mode applications is how to print, let's look at how updater-script scripting language print is viewed.

updater-script script debugging information

General print debug information directly through ui_print () method. Use as follows:

grammar:

ui_print("str");

Description:

Screen print output "str"

E.g:

ui_print("It's ready!");

Screen printing It's ready!

Conclusion

These are the upgrade process debugging log, we hope to help. Interested students can focus our micro-channel public number.

à ¥  ¥ ¨è¿à © à ¥ ¥ Ã|à ¾çÃ|è¿ °

Previous: [] android android system upgrade process analysis system (C) --- updater-script syntax (examples including paper tail analysis)

Next: Contents

Guess you like

Origin blog.csdn.net/twk121109281/article/details/90898861