diff options
author | Xinyu Chen <xinyu.chen@freescale.com> | 2010-09-10 17:17:12 +0800 |
---|---|---|
committer | Xinyu Chen <xinyu.chen@freescale.com> | 2010-09-10 17:23:18 +0800 |
commit | daae245a544d8b23dfa74c6108c35cebef81b8e7 (patch) | |
tree | a35f6e1eb2b46e6a7431d4f071ebe5299917d093 /board/freescale/common/recovery.c | |
parent | 7bbe5d7a5203a07496ec372ab55563a2e230d03e (diff) | |
download | u-boot-imx-daae245a544d8b23dfa74c6108c35cebef81b8e7.zip u-boot-imx-daae245a544d8b23dfa74c6108c35cebef81b8e7.tar.gz u-boot-imx-daae245a544d8b23dfa74c6108c35cebef81b8e7.tar.bz2 |
ENGR00127368 UBOOT: Make the android recovery code common for platformsrel_imx_2.6.31_10.09.00
Move the android recovery codes into common/recovery.c.
Cut the keypad detecting time. Now we only need detect
there's POWER and HOME key pressing at the time scanning
keyboard matrix. So user must hold these two keys when bootup to
enter recovery mode. This can reduce the uboot boot time with
recovery mode configured.
Later /cache file checking for recovery command should be merged
into the common/recovery.c
Signed-off-by: Xinyu Chen <xinyu.chen@freescale.com>
Diffstat (limited to 'board/freescale/common/recovery.c')
-rw-r--r-- | board/freescale/common/recovery.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/board/freescale/common/recovery.c b/board/freescale/common/recovery.c new file mode 100644 index 0000000..d133a9d --- /dev/null +++ b/board/freescale/common/recovery.c @@ -0,0 +1,103 @@ +/* + * Freescale Android Recovery mode checking routing + + * Copyright (C) 2010 Freescale Semiconductor, Inc. + * + * This software may be used and distributed according to the + * terms of the GNU Public License, Version 2, incorporated + * herein by reference. + * + */ +#include <common.h> +#include <malloc.h> +#include "recovery.h" + +#ifndef CONFIG_MXC_KPD +#error "error! keypad must be configured to support recovery" +#endif +#include <mxc_keyb.h> + +#define PRESSED_HOME 0x01 +#define PRESSED_POWER 0x02 +#define RECOVERY_KEY_MASK (PRESSED_HOME | PRESSED_POWER) + +extern int check_recovery_cmd_file(void); +extern enum boot_device get_boot_device(void); + +inline int test_key(int value, struct kpp_key_info *ki) +{ + return (ki->val == value) && (ki->evt == KDepress); +} + +int check_key_pressing(void) +{ + struct kpp_key_info *key_info; + int state = 0, keys, i; + + mxc_kpp_init(); + + puts("Detecting HOME+POWER key for recovery ...\n"); + + /* Check for home + power */ + keys = mxc_kpp_getc(&key_info); + if (keys < 2) + return 0; + + for (i = 0; i < keys; i++) { + if (test_key(CONFIG_POWER_KEY, &key_info[i])) + state |= PRESSED_HOME; + else if (test_key(CONFIG_HOME_KEY, &key_info[i])) + state |= PRESSED_POWER; + } + + free(key_info); + + if ((state & RECOVERY_KEY_MASK) == RECOVERY_KEY_MASK) + return 1; + + return 0; +} + +extern struct reco_envs supported_reco_envs[]; + +void setup_recovery_env(void) +{ + char *env, *boot_args, *boot_cmd; + int bootdev = get_boot_device(); + + boot_cmd = supported_reco_envs[bootdev].cmd; + boot_args = supported_reco_envs[bootdev].args; + + if (boot_cmd == NULL) { + printf("Unsupported bootup device for recovery\n"); + return; + } + + printf("setup env for recovery..\n"); + + env = getenv("bootargs_android_recovery"); + /* Set env to recovery mode */ + if (!env) + setenv("bootargs_android", boot_args); + else + setenv("bootargs_android", env); + + env = getenv("bootcmd_android_recovery"); + if (!env) + setenv("bootcmd_android", boot_cmd); + else + setenv("bootcmd_android", env); + setenv("bootcmd", "run bootcmd_android"); + +} + +/* export to lib_arm/board.c */ +void check_recovery_mode(void) +{ + if (check_key_pressing()) + setup_recovery_env(); + else if (check_recovery_cmd_file()) { + puts("Recovery command file founded!\n"); + setup_recovery_env(); + } +} |