aboutsummaryrefslogtreecommitdiffstats
path: root/package/boot/uboot-mediatek/patches/301-mt7623-generic-reset-button-ignore-env.patch
blob: d082155f145f8b5f9a4f72023d89d4f5f1366bd1 (plain)
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
--- a/board/mediatek/mt7623/Kconfig
+++ b/board/mediatek/mt7623/Kconfig
@@ -10,4 +10,8 @@ config MTK_BROM_HEADER_INFO
 	string
 	default "lk=1"
 
+config RESET_BUTTON_LABEL
+	string "Button to trigger factory reset"
+	default "reset"
+
 endif
--- a/board/mediatek/mt7623/mt7623_rfb.c
+++ b/board/mediatek/mt7623/mt7623_rfb.c
@@ -4,8 +4,17 @@
  */
 
 #include <common.h>
+#include <dm.h>
+#include <button.h>
+#include <env.h>
+#include <init.h>
 #include <mmc.h>
 #include <asm/global_data.h>
+#include <linux/delay.h>
+
+#ifndef CONFIG_RESET_BUTTON_LABEL
+#define CONFIG_RESET_BUTTON_LABEL "reset"
+#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -41,3 +50,22 @@ int mmc_get_env_dev(void)
 	return mmc_get_boot_dev();
 }
 #endif
+
+int board_late_init(void)
+{
+	struct udevice *dev;
+
+	if (!button_get_by_label(CONFIG_RESET_BUTTON_LABEL, &dev)) {
+		puts("reset button found\n");
+#ifdef CONFIG_RESET_BUTTON_SETTLE_DELAY
+		mdelay(CONFIG_RESET_BUTTON_SETTLE_DELAY);
+#endif
+		if (button_get_state(dev) == BUTTON_ON) {
+			puts("button pushed, resetting environment\n");
+			gd->env_valid = ENV_INVALID;
+		}
+	}
+
+	env_relocate();
+	return 0;
+}