Skip to content

Commit 7e7612f

Browse files
authored
Implement device wipe using the hardware button on Green (#3523)
* Improve LED naming in U-Boot DTS Port Stefan's patch from Linux patchset to U-Boot. * Implement device wipe using the hardware button on Green Unlike Yellow, Green doesn't have a way to easily wipe the device, e.g. if the user forgets the password - in that case the only option is to use a microSD card and reflash the system. Fortunately, Green has a hardware button wired to the PMIC chip which exposes the button state in one of the registers. Read this value in U-Boot and decide if cmdline flag for device wipe should be set - same as we do on Yellow. Also enable LED driver and command in U-Boot. In the current implementation, if the button is held for ~5 seconds when plugging in the device (this time includes DDR training, SPL, etc.), the yellow LED turns solid to indicate wipe is about the start. When the Linux kernel starts, the kernel LED driver takes over and starts blinking in heartbeat pattern. Because it takes a while to load the kernel, the LED stays solid for 2-3 seconds, which should be enough to recognize it was acknowledged. * Wait for button to be released before wiping
1 parent 832b70b commit 7e7612f

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
From d3fb1ec2364b20025d71e2263514a71208cfb61e Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= <[email protected]>
3+
Date: Tue, 13 Aug 2024 17:51:29 +0200
4+
Subject: [PATCH] arch: arm64: dts: green: Improve LED representation
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; charset=UTF-8
7+
Content-Transfer-Encoding: 8bit
8+
9+
Fix color and use labels/node names according to the LEDs functionality.
10+
11+
Signed-off-by: Jan Čermák <[email protected]>
12+
Co-authored-by: Stefan Agner <[email protected]>
13+
---
14+
arch/arm/dts/rk3566-ha-green.dts | 11 +++++++----
15+
1 file changed, 7 insertions(+), 4 deletions(-)
16+
17+
diff --git a/arch/arm/dts/rk3566-ha-green.dts b/arch/arm/dts/rk3566-ha-green.dts
18+
index 68d836911e..c3adc59904 100644
19+
--- a/arch/arm/dts/rk3566-ha-green.dts
20+
+++ b/arch/arm/dts/rk3566-ha-green.dts
21+
@@ -48,16 +48,18 @@
22+
leds {
23+
compatible = "gpio-leds";
24+
25+
- led_power: led-0 {
26+
+ led_power: led-power {
27+
+ label = "power";
28+
gpios = <&gpio0 RK_PB6 GPIO_ACTIVE_HIGH>;
29+
function = LED_FUNCTION_POWER;
30+
- color = <LED_COLOR_ID_RED>;
31+
+ color = <LED_COLOR_ID_WHITE>;
32+
default-state = "keep";
33+
linux,default-trigger = "default-on";
34+
pinctrl-names = "default";
35+
pinctrl-0 = <&led_power_pin>;
36+
};
37+
- led_act: led-1 {
38+
+ led_act: led-activity {
39+
+ label = "activity";
40+
gpios = <&gpio0 RK_PB7 GPIO_ACTIVE_HIGH>;
41+
function = LED_FUNCTION_ACTIVITY;
42+
color = <LED_COLOR_ID_GREEN>;
43+
@@ -65,7 +67,8 @@
44+
pinctrl-names = "default";
45+
pinctrl-0 = <&led_act_pin>;
46+
};
47+
- led_user: led-2 {
48+
+ led_user: led-user {
49+
+ label = "user";
50+
gpios = <&gpio0 RK_PC5 GPIO_ACTIVE_HIGH>;
51+
function = LED_FUNCTION_HEARTBEAT;
52+
color = <LED_COLOR_ID_YELLOW>;

buildroot-external/board/nabucasa/green/uboot-boot.ush

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,36 @@ test -n "${MACHINE_ID}" || setenv BOOT_CONDITION "systemd.condition-first-boot=t
2727
# HassOS bootargs
2828
setenv bootargs_hassos "zram.enabled=1 zram.num_devices=3 rootwait systemd.machine_id=${MACHINE_ID} fsck.repair=yes ${BOOT_CONDITION}"
2929

30+
i2c dev 0
31+
setenv check_btn_pressed ' \
32+
i2c read 0x20 0xf0.1 1 ${loadaddr}; \
33+
setexpr PWRON_STS *${loadaddr} \\\& 0x80; \
34+
test ${PWRON_STS} -eq 0x0;'
35+
36+
# Check if button is held for device wipe
37+
setenv counter 0
38+
while test ${counter} -lt 2; do
39+
if run check_btn_pressed; then
40+
echo "Reset button pressed for ${counter} seconds"
41+
setexpr counter ${counter} + 1
42+
43+
if test ${counter} -eq 2; then
44+
led user on
45+
echo "Waiting for button to be released"
46+
while run check_btn_pressed; do
47+
sleep 0.5
48+
done
49+
echo "Proceeding with device wipe"
50+
setenv bootargs_hassos "${bootargs_hassos} haos.wipe=1"
51+
else
52+
sleep 1
53+
fi
54+
else
55+
# U-Boot has no break statement :')
56+
setenv counter 2
57+
fi
58+
done
59+
3060
# HassOS system A/B
3161
setenv bootargs_a "root=PARTUUID=8d3d53e3-6d49-4c38-8349-aff6859e82fd ro"
3262
setenv bootargs_b "root=PARTUUID=a3ec664e-32ce-4665-95ea-7ae90ce9aa20 ro"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_LED=y
2+
CONFIG_LED_GPIO=y
3+
CONFIG_CMD_LED=y

buildroot-external/configs/green_defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y
143143
BR2_TARGET_UBOOT_CUSTOM_VERSION=y
144144
BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE="2024.01"
145145
BR2_TARGET_UBOOT_BOARD_DEFCONFIG="green"
146-
BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES="$(BR2_EXTERNAL_HASSOS_PATH)/bootloader/uboot.config"
146+
BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES="$(BR2_EXTERNAL_HASSOS_PATH)/bootloader/uboot.config $(BR2_EXTERNAL_HASSOS_PATH)/board/nabucasa/green/uboot.config"
147147
BR2_TARGET_UBOOT_NEEDS_PYLIBFDT=y
148148
BR2_TARGET_UBOOT_NEEDS_PYELFTOOLS=y
149149
BR2_TARGET_UBOOT_NEEDS_ATF_BL31=y

0 commit comments

Comments
 (0)