-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathboot_sel.c
88 lines (75 loc) · 2.12 KB
/
boot_sel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Copyright (C) 2016 Ingenic Semiconductor Co.,Ltd
*
* X1000 series bootloader for u-boot/rtos/linux
*
* Zhang YanMing <yanming.zhang@ingenic.com, jamincheung@126.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <common.h>
#ifdef CONFIG_RECOVERY
#if (CONFIG_RECOVERY_BOOT_KEY > 0)
static int get_key_level(unsigned pin)
{
#define GPIO_DEBOUNCE 20
int cnt = GPIO_DEBOUNCE,v = 0, t = 0;
while (cnt--) {
t = !!gpio_get_value(pin);
if (v != t) {
cnt = GPIO_DEBOUNCE;
mdelay(1);
}
v = t;
}
return v;
}
static int get_key_status(int pin, int en_level)
{
gpio_direction_input(pin);
gpio_disable_pull(pin);
return en_level == get_key_level(pin) ? KEY_PRESS : KEY_UNPRESS;
}
#endif
static int get_signature(const int signature)
{
unsigned int flag = cpm_get_scrpad();
if ((flag & 0xffff) == signature) {
/*
* Clear the signature,
* reset the signature to force into normal boot after factory reset
*/
cpm_set_scrpad(flag & ~(0xffff));
return KEY_PRESS;
} else {
return KEY_UNPRESS;
}
}
#endif /* CONFIG_RECOVERY */
int get_boot_sel(void) {
#ifdef CONFIG_RECOVERY
/* Recovery update flag check */
#ifdef RECOVERY_UPDATE_FLAG_CHECK
if (is_recovery_update_failed() == 1) {
return RECOVERY_BOOT;
}
#endif
/* Recovery signature */
if (get_signature(RECOVERY_SIGNATURE))
return RECOVERY_BOOT;
#if (CONFIG_RECOVERY_BOOT_KEY > 0)
/* Recovery boot keys */
if (get_key_status(CONFIG_RECOVERY_BOOT_KEY, CONFIG_RECOVERY_BOOT_KEY_ENLEVEL))
return RECOVERY_BOOT;
#endif
#endif /* CONFIG_RECOVERY */
return NORMAL_BOOT;
}