From 513808cfa0068f7ecfe454df7b7e4b83d98a7429 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] 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 0e10a0d123b..884c03b9d5c 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