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

2019-04-14 08:52发布

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, " "); if (token != NULL) { (*argv)[*argc] = strdup(token); // Strip newline. } else { --*argc; } } check_and_fclose(fp, COMMAND_FILE); LOGI("Got arguments from %s ", 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 ", sizeof(boot.recovery)); int i; for (i = 1; i < *argc; ++i) { strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery)); strlcat(boot.recovery, " ", sizeof(boot.recovery)); } set_bootloader_message(&boot); 接着才做wipe data/cache动作. 当掉电重启时,u-boot会检查misc分区, 进而又会进入recovery模式. 这里写图片描述