imx6 手动进入recovery

写在前面

平板项目,需要音量减+关机键进入recovery模式。中间遇到了一些问题,记录一下。

配置音量键

uboot启动以后会检测音量上下键是否被按,然后进入不同的分支
board/freescale/common/recovery.c

/* export to lib_arm/board.c */
void check_recovery_mode(void)
{
    if (check_key_pressing()) {
        puts("Fastboot: Recovery key pressing got!\n");
        setup_recovery_env();
    } else if (check_recovery_cmd_file()) {
        puts("Fastboot: Recovery command file found!\n");
        setup_recovery_env();
    } else {
        puts("Fastboot: Normal\n");
    }
}
#define GPIO_VOL_DN_KEY IMX_GPIO_NR(2, 1)
iomux_v3_cfg_t const recovery_key_pads[] = {
    (MX6_PAD_NANDF_D1__GPIO2_IO01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
};

int check_recovery_cmd_file(void)
{
    int button_pressed = 0;
    int recovery_mode = 0;

    recovery_mode = recovery_check_and_clean_flag();

    /* Check Recovery Combo Button press or not. */
    imx_iomux_v3_setup_multiple_pads(recovery_key_pads,
            ARRAY_SIZE(recovery_key_pads));

    gpio_direction_input(GPIO_VOL_DN_KEY);      //由此可见,uboot阶段,会读取一个gpio口,把这个gpio设置为自己主板对应的就能进入recovery了

    if (gpio_get_value(GPIO_VOL_DN_KEY) == 0) { /* VOL_DN key is low assert */
        button_pressed = 1;
        printf("Recovery key pressed\n");
    }

    return recovery_mode || button_pressed;
}

图形模式和show_text模式

上面已经做好了开机时按住音量减进入recovery模式,但是发现进入recovery后,什么显示都没有。
然后在代码中发现了,由show_text这个变量,如果像要有问题提示,就要把show_text变量设置为1,这个变量的修改是从/cache/recovery/command文件中解析出来的
然后我正常进入系统,执行下面的命令,成功进入带文字提示的recovery

echo "--show_text" > /cache/recovery/command
static const struct option OPTIONS[] = {
  { "send_intent", required_argument, NULL, 's' },
  { "update_package", required_argument, NULL, 'u' },
  { "wipe_data", no_argument, NULL, 'w' },
  { "wipe_cache", no_argument, NULL, 'c' },
  { "show_text", no_argument, NULL, 't' },
  { "just_exit", no_argument, NULL, 'x' },
  { "locale", required_argument, NULL, 'l' },
  { "stages", required_argument, NULL, 'g' },
  { "shutdown_after", no_argument, NULL, 'p' },
  { "reason", required_argument, NULL, 'r' },
  { NULL, 0, NULL, 0 },
};
//bootable/recovery/recovery.cpp
main()
{
    ......
    int wipe_data = 0, wipe_cache = 0, show_text = 0;
    ......
    while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
        switch (arg) {
        case 's': send_intent = optarg; break;
        case 'u': update_package = optarg; break;
        case 'w': wipe_data = wipe_cache = 1; break;
        case 'c': wipe_cache = 1; break;
        case 't': show_text = 1; break;
        case 'x': just_exit = true; break;
        case 'l': locale = optarg; break;
        case 'g': {
            if (stage == NULL || *stage == '\0') {
                char buffer[20] = "1/";
                strncat(buffer, optarg, sizeof(buffer)-3);
                stage = strdup(buffer);
            }
            break;
        }
        case 'p': shutdown_after = true; break;
        case 'r': reason = optarg; break;
        case '?':
            LOGE("Invalid command argument\n");
            continue;
        }
    }
}

根据项目需要,用户从过app升级/恢复出厂,要进入图形模式,手动按键进入recovery,要进入文字模式。
修改代码如下,解决问题

main()
{
    ......
    int wipe_data = 0, wipe_cache = 0, show_text = 1;
    ......
    while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
        switch (arg) {
        case 's': {send_intent = optarg; break;}
        case 'u': {show_text = 0; update_package = optarg; break;}
        case 'w': {show_text = 0; wipe_data = wipe_cache = 1; break;}
        case 'c': {show_text = 0; wipe_cache = 1; break;}
        case 't': {show_text = 1; break;}
        case 'x': {show_text = 0; just_exit = true; break;}
        case 'l': {locale = optarg; break;}
        case 'g': {
            if (stage == NULL || *stage == '\0') {
                char buffer[20] = "1/";
                strncat(buffer, optarg, sizeof(buffer)-3);
                stage = strdup(buffer);
            }
            break;
        }
        case 'p': shutdown_after = true; break;
        case 'r': reason = optarg; break;
        case '?':
            LOGE("Invalid command argument\n");
            continue;
        }
    }
}

也就是,默认是显示文字,不显示图形的。 如果用户通过app进行恢复出厂/升级系统,那么设置show_text=0,进入图形模式。

你可能感兴趣的:(imx6 手动进入recovery)