From 4f27cf9480dd0c98169c2e7ef8c024dfd2f6acc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Tue, 13 Aug 2024 18:18:54 +0200 Subject: [PATCH 1/3] Improve LED naming in U-Boot DTS Port Stefan's patch from Linux patchset to U-Boot. --- ...dts-green-Improve-LED-representation.patch | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 buildroot-external/board/nabucasa/green/patches/uboot/0010-arch-arm64-dts-green-Improve-LED-representation.patch diff --git a/buildroot-external/board/nabucasa/green/patches/uboot/0010-arch-arm64-dts-green-Improve-LED-representation.patch b/buildroot-external/board/nabucasa/green/patches/uboot/0010-arch-arm64-dts-green-Improve-LED-representation.patch new file mode 100644 index 00000000000..40b2c3f8abb --- /dev/null +++ b/buildroot-external/board/nabucasa/green/patches/uboot/0010-arch-arm64-dts-green-Improve-LED-representation.patch @@ -0,0 +1,52 @@ +From d3fb1ec2364b20025d71e2263514a71208cfb61e Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= +Date: Tue, 13 Aug 2024 17:51:29 +0200 +Subject: [PATCH] arch: arm64: dts: green: Improve LED representation +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Fix color and use labels/node names according to the LEDs functionality. + +Signed-off-by: Jan Čermák +Co-authored-by: Stefan Agner +--- + arch/arm/dts/rk3566-ha-green.dts | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +diff --git a/arch/arm/dts/rk3566-ha-green.dts b/arch/arm/dts/rk3566-ha-green.dts +index 68d836911e..c3adc59904 100644 +--- a/arch/arm/dts/rk3566-ha-green.dts ++++ b/arch/arm/dts/rk3566-ha-green.dts +@@ -48,16 +48,18 @@ + leds { + compatible = "gpio-leds"; + +- led_power: led-0 { ++ led_power: led-power { ++ label = "power"; + gpios = <&gpio0 RK_PB6 GPIO_ACTIVE_HIGH>; + function = LED_FUNCTION_POWER; +- color = ; ++ color = ; + default-state = "keep"; + linux,default-trigger = "default-on"; + pinctrl-names = "default"; + pinctrl-0 = <&led_power_pin>; + }; +- led_act: led-1 { ++ led_act: led-activity { ++ label = "activity"; + gpios = <&gpio0 RK_PB7 GPIO_ACTIVE_HIGH>; + function = LED_FUNCTION_ACTIVITY; + color = ; +@@ -65,7 +67,8 @@ + pinctrl-names = "default"; + pinctrl-0 = <&led_act_pin>; + }; +- led_user: led-2 { ++ led_user: led-user { ++ label = "user"; + gpios = <&gpio0 RK_PC5 GPIO_ACTIVE_HIGH>; + function = LED_FUNCTION_HEARTBEAT; + color = ; From 59f7f73ebfa24fbd6b7daffb4e8ba16c7c0f1822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Tue, 13 Aug 2024 18:20:40 +0200 Subject: [PATCH 2/3] 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. --- .../board/nabucasa/green/uboot-boot.ush | 24 +++++++++++++++++++ .../board/nabucasa/green/uboot.config | 3 +++ buildroot-external/configs/green_defconfig | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 buildroot-external/board/nabucasa/green/uboot.config diff --git a/buildroot-external/board/nabucasa/green/uboot-boot.ush b/buildroot-external/board/nabucasa/green/uboot-boot.ush index fce59905d6e..7505fdb3640 100755 --- a/buildroot-external/board/nabucasa/green/uboot-boot.ush +++ b/buildroot-external/board/nabucasa/green/uboot-boot.ush @@ -27,6 +27,30 @@ test -n "${MACHINE_ID}" || setenv BOOT_CONDITION "systemd.condition-first-boot=t # HassOS bootargs setenv bootargs_hassos "zram.enabled=1 zram.num_devices=3 rootwait systemd.machine_id=${MACHINE_ID} fsck.repair=yes ${BOOT_CONDITION}" +# Check if button is held for device wipe +setenv counter 0 +i2c dev 0 +while test ${counter} -lt 2; do + i2c read 0x20 0xf0.1 1 ${loadaddr} + setexpr PWRON_STS *${loadaddr} \& 0x80 + + if test ${PWRON_STS} -eq 0x0; then + echo "Reset button pressed for ${counter} seconds" + setexpr counter ${counter} + 1 + + if test ${counter} -eq 2; then + echo "Proceeding with device wipe" + led user on + setenv bootargs_hassos "${bootargs_hassos} haos.wipe=1" + else + sleep 1 + fi + else + # U-Boot has no break statement :') + setenv counter 2 + fi +done + # HassOS system A/B setenv bootargs_a "root=PARTUUID=8d3d53e3-6d49-4c38-8349-aff6859e82fd ro" setenv bootargs_b "root=PARTUUID=a3ec664e-32ce-4665-95ea-7ae90ce9aa20 ro" diff --git a/buildroot-external/board/nabucasa/green/uboot.config b/buildroot-external/board/nabucasa/green/uboot.config new file mode 100644 index 00000000000..35b908b49c8 --- /dev/null +++ b/buildroot-external/board/nabucasa/green/uboot.config @@ -0,0 +1,3 @@ +CONFIG_LED=y +CONFIG_LED_GPIO=y +CONFIG_CMD_LED=y diff --git a/buildroot-external/configs/green_defconfig b/buildroot-external/configs/green_defconfig index cc16d65db95..f43a8ad6e54 100755 --- a/buildroot-external/configs/green_defconfig +++ b/buildroot-external/configs/green_defconfig @@ -143,7 +143,7 @@ BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y BR2_TARGET_UBOOT_CUSTOM_VERSION=y BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE="2024.01" BR2_TARGET_UBOOT_BOARD_DEFCONFIG="green" -BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES="$(BR2_EXTERNAL_HASSOS_PATH)/bootloader/uboot.config" +BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES="$(BR2_EXTERNAL_HASSOS_PATH)/bootloader/uboot.config $(BR2_EXTERNAL_HASSOS_PATH)/board/nabucasa/green/uboot.config" BR2_TARGET_UBOOT_NEEDS_PYLIBFDT=y BR2_TARGET_UBOOT_NEEDS_PYELFTOOLS=y BR2_TARGET_UBOOT_NEEDS_ATF_BL31=y From 4e8a1cd266e8db71159a9020b5c473f7c226237a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Thu, 15 Aug 2024 16:38:37 +0200 Subject: [PATCH 3/3] Wait for button to be released before wiping --- .../board/nabucasa/green/uboot-boot.ush | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/buildroot-external/board/nabucasa/green/uboot-boot.ush b/buildroot-external/board/nabucasa/green/uboot-boot.ush index 7505fdb3640..5454e71c982 100755 --- a/buildroot-external/board/nabucasa/green/uboot-boot.ush +++ b/buildroot-external/board/nabucasa/green/uboot-boot.ush @@ -27,20 +27,26 @@ test -n "${MACHINE_ID}" || setenv BOOT_CONDITION "systemd.condition-first-boot=t # HassOS bootargs setenv bootargs_hassos "zram.enabled=1 zram.num_devices=3 rootwait systemd.machine_id=${MACHINE_ID} fsck.repair=yes ${BOOT_CONDITION}" +i2c dev 0 +setenv check_btn_pressed ' \ + i2c read 0x20 0xf0.1 1 ${loadaddr}; \ + setexpr PWRON_STS *${loadaddr} \\\& 0x80; \ + test ${PWRON_STS} -eq 0x0;' + # Check if button is held for device wipe setenv counter 0 -i2c dev 0 while test ${counter} -lt 2; do - i2c read 0x20 0xf0.1 1 ${loadaddr} - setexpr PWRON_STS *${loadaddr} \& 0x80 - - if test ${PWRON_STS} -eq 0x0; then + if run check_btn_pressed; then echo "Reset button pressed for ${counter} seconds" setexpr counter ${counter} + 1 if test ${counter} -eq 2; then - echo "Proceeding with device wipe" led user on + echo "Waiting for button to be released" + while run check_btn_pressed; do + sleep 0.5 + done + echo "Proceeding with device wipe" setenv bootargs_hassos "${bootargs_hassos} haos.wipe=1" else sleep 1