Skip to content

Commit

Permalink
Implement device wipe using the hardware button on Green
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sairon committed Aug 13, 2024
1 parent ae4c997 commit 513808c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
24 changes: 24 additions & 0 deletions buildroot-external/board/nabucasa/green/uboot-boot.ush
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions buildroot-external/board/nabucasa/green/uboot.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_LED=y
CONFIG_LED_GPIO=y
CONFIG_CMD_LED=y
2 changes: 1 addition & 1 deletion buildroot-external/configs/green_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 513808c

Please sign in to comment.