Skip to content

Commit

Permalink
beluga: initrdscripts: Provide a means to access ADB from the boot image
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
MagneFire committed Jan 6, 2025
1 parent 9b2b309 commit 97414ae
Showing 1 changed file with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 97414ae

Please sign in to comment.