diff options
Diffstat (limited to 'board/freescale')
-rw-r--r-- | board/freescale/common/Makefile | 1 | ||||
-rw-r--r-- | board/freescale/common/recovery.c | 103 | ||||
-rw-r--r-- | board/freescale/common/recovery.h | 19 | ||||
-rw-r--r-- | board/freescale/mx51_3stack/mx51_3stack.c | 149 | ||||
-rw-r--r-- | board/freescale/mx51_bbg/mx51_bbg.c | 156 |
5 files changed, 160 insertions, 268 deletions
diff --git a/board/freescale/common/Makefile b/board/freescale/common/Makefile index 02a824d..fac485d 100644 --- a/board/freescale/common/Makefile +++ b/board/freescale/common/Makefile @@ -41,6 +41,7 @@ COBJS-${CONFIG_MPC8541CDS} += cds_pci_ft.o COBJS-${CONFIG_MPC8548CDS} += cds_pci_ft.o COBJS-${CONFIG_MPC8555CDS} += cds_pci_ft.o +COBJS-${CONFIG_ANDROID_RECOVERY} += recovery.o SRCS := $(SOBJS:.o=.S) $(COBJS-y:.o=.c) OBJS := $(addprefix $(obj),$(COBJS-y)) 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(); + } +} diff --git a/board/freescale/common/recovery.h b/board/freescale/common/recovery.h new file mode 100644 index 0000000..9958330 --- /dev/null +++ b/board/freescale/common/recovery.h @@ -0,0 +1,19 @@ +/* + * Android Recovery supported header file + * + * Copyright (C) 2010 Freescale Semiconductor. + * + * This software may be used and distributed according to the + * terms of the GNU Public License, Version 2, incorporated + * herein by reference. + */ + +#ifndef __RECOVERY_H_ +#define __RECOVERY_H_ + +struct reco_envs { + char *cmd; + char *args; +}; + +#endif diff --git a/board/freescale/mx51_3stack/mx51_3stack.c b/board/freescale/mx51_3stack/mx51_3stack.c index 1289118..77da23c 100644 --- a/board/freescale/mx51_3stack/mx51_3stack.c +++ b/board/freescale/mx51_3stack/mx51_3stack.c @@ -43,7 +43,8 @@ #include <asm/arch/mmu.h> #endif -#ifdef CONFIG_FSL_ANDROID +#ifdef CONFIG_ANDROID_RECOVERY +#include "../common/recovery.h" #include <mxc_keyb.h> #include <part.h> #include <ext2fs.h> @@ -611,125 +612,21 @@ int board_init(void) return 0; } -#ifdef BOARD_LATE_INIT - -#if defined(CONFIG_FSL_ANDROID) && defined(CONFIG_MXC_KPD) -static int waiting_for_func_key_pressing(void) -{ - struct kpp_key_info key_info = {0, 0}; - int switch_delay = CONFIG_ANDROID_BOOTMOD_DELAY; - int state = 0, boot_mode_switch = 0; - - mxc_kpp_init(); - - puts("Press home + power to enter recovery mode ...\n"); - - while ((switch_delay > 0) && (!boot_mode_switch)) { - int i; - - --switch_delay; - /* delay 100 * 10ms */ - for (i = 0; !boot_mode_switch && i < 100; ++i) { - /* A state machine to scan home + power key */ - /* Check for home + power */ - if (mxc_kpp_getc(&key_info)) { - switch (state) { - case 0: - /* First press */ - if (TEST_HOME_KEY_DEPRESS(key_info.val, key_info.evt)) { - /* Press Home */ - state = 1; - } else if (TEST_POWER_KEY_DEPRESS(key_info.val, key_info.evt)) { - state = 2; - } else { - state = 0; - } - break; - case 1: - /* Home is already pressed, try to detect Power */ - if (TEST_POWER_KEY_DEPRESS(key_info.val, - key_info.evt)) { - boot_mode_switch = 1; - } else { - if (TEST_HOME_KEY_DEPRESS(key_info.val, - key_info.evt)) - state = 2; - else - state = 0; - } - break; - case 2: - /* Power is already pressed, try to detect Home */ - if (TEST_HOME_KEY_DEPRESS(key_info.val, - key_info.evt)) { - boot_mode_switch = 1; - } else { - if (TEST_POWER_KEY_DEPRESS(key_info.val, - key_info.evt)) - state = 1; - else - state = 0; - } - break; - default: - break; - } - - if (1 == boot_mode_switch) - return 1; - } - } - for (i = 0; i < 100; ++i) - udelay(10000); - } - - return 0; -} - -static int switch_to_recovery_mode(void) -{ - char *env = NULL; - char *boot_args = NULL; - char *boot_cmd = NULL; - - printf("Boot mode switched to recovery mode!\n"); - - switch (get_boot_device()) { - case MMC_BOOT: - boot_args = CONFIG_ANDROID_RECOVERY_BOOTARGS_MMC; - boot_cmd = CONFIG_ANDROID_RECOVERY_BOOTCMD_MMC; - break; - case NAND_BOOT: - boot_args = CONFIG_ANDROID_RECOVERY_BOOTARGS_NAND; - boot_cmd = CONFIG_ANDROID_RECOVERY_BOOTCMD_NAND; - break; - case SPI_NOR_BOOT: - printf("Recovery mode not supported in SPI NOR boot\n"); - return -1; - break; - case UNKNOWN_BOOT: - default: - printf("Unknown boot device!\n"); - return -1; - break; - } - - 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"); - - return 0; -} +#ifdef CONFIG_ANDROID_RECOVERY +struct reco_envs supported_reco_envs[END_BOOT] = { + { + .cmd = CONFIG_ANDROID_RECOVERY_BOOTCMD_NAND, + .args = CONFIG_ANDROID_RECOVERY_BOOTARGS_NAND, + }, + { + .cmd = NULL, + .args = NULL, + }, + { + .cmd = CONFIG_ANDROID_RECOVERY_BOOTCMD_MMC, + .args = CONFIG_ANDROID_RECOVERY_BOOTARGS_MMC, + }, +}; static int check_mmc_recovery_cmd_file(int dev_num, int part_num, char *path) { @@ -905,19 +802,9 @@ static int check_recovery_cmd_file(void) } #endif +#ifdef BOARD_LATE_INIT int board_late_init(void) { -#if defined(CONFIG_FSL_ANDROID) && defined(CONFIG_MXC_KPD) - if (waiting_for_func_key_pressing()) - switch_to_recovery_mode(); - else { - if (check_recovery_cmd_file()) { - puts("Recovery command file detected!\n"); - switch_to_recovery_mode(); - } - } -#endif - return 0; } #endif diff --git a/board/freescale/mx51_bbg/mx51_bbg.c b/board/freescale/mx51_bbg/mx51_bbg.c index 30fed3d..83e8ca7 100644 --- a/board/freescale/mx51_bbg/mx51_bbg.c +++ b/board/freescale/mx51_bbg/mx51_bbg.c @@ -52,8 +52,8 @@ #include <asm/imx_iim.h> #endif -#ifdef CONFIG_FSL_ANDROID -#include <mxc_keyb.h> +#ifdef CONFIG_ANDROID_RECOVERY +#include "../common/recovery.h" #include <part.h> #include <ext2fs.h> #include <linux/mtd/mtd.h> @@ -873,131 +873,23 @@ int board_init(void) return 0; } -#ifdef BOARD_LATE_INIT -#if defined(CONFIG_FSL_ANDROID) && defined(CONFIG_MXC_KPD) -inline int waiting_for_func_key_pressing(void) -{ - struct kpp_key_info key_info = {0, 0}; - int switch_delay = CONFIG_ANDROID_BOOTMOD_DELAY; - int state = 0, boot_mode_switch = 0; - - mxc_kpp_init(); - - puts("Press home + power to enter recovery mode ...\n"); - - while ((switch_delay > 0) && (!boot_mode_switch)) { - int i; - - --switch_delay; - /* delay 100 * 10ms */ - for (i = 0; !boot_mode_switch && i < 100; ++i) { - /* A state machine to scan home + power key */ - /* Check for home + power */ - if (mxc_kpp_getc(&key_info)) { - switch (state) { - case 0: - /* First press */ - if (TEST_HOME_KEY_DEPRESS(key_info.val, key_info.evt)) { - /* Press Home */ - state = 1; - } else if (TEST_POWER_KEY_DEPRESS(key_info.val, key_info.evt)) { - /* Press Power */ - state = 2; - } else { - state = 0; - } - break; - case 1: - /* Home is already pressed, try to detect Power */ - if (TEST_POWER_KEY_DEPRESS(key_info.val, - key_info.evt)) { - /* Switch */ - boot_mode_switch = 1; - } else { - if (TEST_HOME_KEY_DEPRESS(key_info.val, - key_info.evt)) { - /* Not switch */ - state = 2; - } else - state = 0; - } - break; - case 2: - /* Power is already pressed, try to detect Home */ - if (TEST_HOME_KEY_DEPRESS(key_info.val, - key_info.evt)) { - /* Switch */ - boot_mode_switch = 1; - } else { - if (TEST_POWER_KEY_DEPRESS(key_info.val, - key_info.evt)) { - /* Not switch */ - state = 1; - } else - state = 0; - } - break; - default: - break; - } - - if (1 == boot_mode_switch) - return 1; - } - } - for (i = 0; i < 100; ++i) - udelay(10000); - } - - return 0; -} - -inline int switch_to_recovery_mode(void) -{ - char *env = NULL; - char *boot_args = NULL; - char *boot_cmd = NULL; - - printf("Boot mode switched to recovery mode!\n"); - - switch (get_boot_device()) { - case MMC_BOOT: - boot_args = CONFIG_ANDROID_RECOVERY_BOOTARGS_MMC; - boot_cmd = CONFIG_ANDROID_RECOVERY_BOOTCMD_MMC; - break; - case NAND_BOOT: - printf("Recovery mode not supported in NAND boot\n"); - return -1; - break; - case SPI_NOR_BOOT: - printf("Recovery mode not supported in SPI NOR boot\n"); - return -1; - break; - case UNKNOWN_BOOT: - default: - printf("Unknown boot device!\n"); - return -1; - break; - } - - 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"); - - return 0; -} +#ifdef CONFIG_ANDROID_RECOVERY +struct reco_envs supported_reco_envs[END_BOOT] = { + { + .cmd = NULL, + .args = NULL, + }, + { + .cmd = NULL, + .args = NULL, + }, + { + .cmd = CONFIG_ANDROID_RECOVERY_BOOTCMD_MMC, + .args = CONFIG_ANDROID_RECOVERY_BOOTARGS_MMC, + }, +}; -inline int check_recovery_cmd_file(void) +int check_recovery_cmd_file(void) { disk_partition_t info; ulong part_length; @@ -1064,6 +956,7 @@ inline int check_recovery_cmd_file(void) } #endif +#ifdef BOARD_LATE_INIT int board_late_init(void) { #ifdef CONFIG_I2C_MXC @@ -1076,17 +969,6 @@ int board_late_init(void) setup_core_voltage_spi(); #endif -#if defined(CONFIG_FSL_ANDROID) && defined(CONFIG_MXC_KPD) - if (waiting_for_func_key_pressing()) - switch_to_recovery_mode(); - else { - if (check_recovery_cmd_file()) { - puts("Recovery command file founded!\n"); - switch_to_recovery_mode(); - } - } -#endif - return 0; } #endif |