From 97414aefb0badfe7d9114f6d46529b784344595b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Darrel=20Gri=C3=ABt?= Date: Mon, 6 Jan 2025 20:41:18 +0100 Subject: [PATCH] beluga: initrdscripts: Provide a means to access ADB from the boot image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change is analogous to https://github.com/AsteroidOS/meta-smartwatch/pull/254/files. However, on `beluga` only the bottom right button is sending an event so this is used. Signed-off-by: Darrel Griƫt --- .../initramfs-scripts-android/init.machine.sh | 54 ++++++++++++++----- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/meta-beluga/recipes-core/initrdscripts/initramfs-scripts-android/init.machine.sh b/meta-beluga/recipes-core/initrdscripts/initramfs-scripts-android/init.machine.sh index 413c8683..258d8198 100644 --- a/meta-beluga/recipes-core/initrdscripts/initramfs-scripts-android/init.machine.sh +++ b/meta-beluga/recipes-core/initrdscripts/initramfs-scripts-android/init.machine.sh @@ -2,19 +2,10 @@ BOOT_DIR=$1 -# Manually mount the system partition as it contains the boot image (ramdisk) as well as the system data (under /system/system). -mkdir -m 0777 $BOOT_DIR/boot -mount -t auto -o ro /dev/mmcblk0p36 $BOOT_DIR/boot -# Allow Android binaries to load libraries from /usr/libexec/ (for example /usr/libexec/hal-droid/system/lib/libselinux_stubs.so) -mount --bind /ld.config.28.txt $BOOT_DIR/boot/system/etc/ld.config.28.txt - -# Make the 'system' folder available as the system partition to the rootfs. -ln -s /boot/system/ $BOOT_DIR/system - -# Check if the AsteroidOS specific machine configuration file exists. -# If it doesn't then we know that the userdata partition is mounted but doesn't contain a valid AsteroidOS root. -if [ ! -e $BOOT_DIR/etc/asteroid/machine.conf ] ; then +# Start the ADB daemon +startadbd() { + trap - SIGUSR1 echo MSG "Push asteroidos.ext4 via ADB" > /run/psplash_fifo # Setup for use with ConfigFS @@ -27,4 +18,43 @@ if [ ! -e $BOOT_DIR/etc/asteroid/machine.conf ] ; then echo OPPO Watch > /sys/kernel/config/usb_gadget/g1/strings/0x409/product /usr/bin/adbd +} + +# wait for the middle button to be pressed, and if it is, +# kill the calling process group with SIGUSR1 +# The format of these events is documented here: +# https://github.com/torvalds/linux/blob/master/include/uapi/linux/input.h#L28-L47 +# u32 - tv_sec +# u32 - tv_usec +# u16 - type +# u16 - code +# s32 - value +# On this watch the bottom button has a type of 2ee +# The top button is encoded in a different event. +waitmidbutton() { + fmtstring='1/4 "%d." 1/4 "%d\t" 1/2 "%2x\t" 1/2 "%2x\t" 1/4 "%u\n"' + result=$(hexdump -n16 -e "${fmtstring}" /dev/input/event0 | cut -f3 -) + if [ ${result} == 2ee ] ; then kill -s USR1 $1 ; fi +} + +# Manually mount the system partition as it contains the boot image (ramdisk) as well as the system data (under /system/system). +mkdir -m 0777 $BOOT_DIR/boot +mount -t auto -o ro /dev/mmcblk0p36 $BOOT_DIR/boot + +# Allow Android binaries to load libraries from /usr/libexec/ (for example /usr/libexec/hal-droid/system/lib/libselinux_stubs.so) +mount --bind /ld.config.28.txt $BOOT_DIR/boot/system/etc/ld.config.28.txt + +# Make the 'system' folder available as the system partition to the rootfs. +ln -s /boot/system/ $BOOT_DIR/system + +# Check if the AsteroidOS specific machine configuration file exists. +# If it doesn't then we know that the userdata partition is mounted but doesn't contain a valid AsteroidOS root. +if [ ! -e $BOOT_DIR/etc/asteroid/machine.conf ] ; then + startadbd +else +# wait for either 5 seconds or for the user to hit the middle button +# If the timout expires, the watch boots normally; otherwise it starts ADB daemon + trap "startadbd" SIGUSR1 + waitmidbutton $$ & + sleep 5 fi