[RK3288][Android6.0] 调试笔记 --- 恢复出厂设置掉电保护

Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92

Recovery在做清data的时候, 会做一个掉电保护,如果在wipe data中途中掉电,那么下一次重启还是
会进入recovery模式重新做wipe data动作.

比如当前使用命令恢复出厂设置:

echo –wipe_data > /cache/recovery/command
reboot recovery

那么这段code就会被跑到
recovery.cpp:

    // --- if that doesn't work, try the command file
    if (*argc <= 1) {
        FILE *fp = fopen_path(COMMAND_FILE, "r");
        if (fp != NULL) {
            char *token;
            char *argv0 = (*argv)[0];
            *argv = (char **) malloc(sizeof(char *) * MAX_ARGS);
            (*argv)[0] = argv0;  // use the same program name

            char buf[MAX_ARG_LENGTH];
            for (*argc = 1; *argc < MAX_ARGS; ++*argc) {
                if (!fgets(buf, sizeof(buf), fp)) break;
                token = strtok(buf, "\r\n");
                if (token != NULL) {
                    (*argv)[*argc] = strdup(token);  // Strip newline.
                } else {
                    --*argc;
                }
            }

            check_and_fclose(fp, COMMAND_FILE);
            LOGI("Got arguments from %s\n", COMMAND_FILE);
        }
    }

然后对应参数会被存到misc分区

    // --> write the arguments we have back into the bootloader control block
    // always boot into recovery after this (until finish_recovery() is called)
    strlcpy(boot.command, "boot-recovery", sizeof(boot.command));
    strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery));
    int i;
    for (i = 1; i < *argc; ++i) {
        strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery));
        strlcat(boot.recovery, "\n", sizeof(boot.recovery));
    }
    set_bootloader_message(&boot);

接着才做wipe data/cache动作.

当掉电重启时,u-boot会检查misc分区, 进而又会进入recovery模式.

[RK3288][Android6.0] 调试笔记 --- 恢复出厂设置掉电保护_第1张图片

你可能感兴趣的:(子类__Recovery)