From 7eb24a5da70b9e07de7162cb3793d43c0cc55e7d Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 12 Dec 2024 08:41:14 -0800 Subject: [PATCH] implement thundercomm adb implementation --- userspace/usr/comma/99-android.rules | 10 ++++ userspace/usr/comma/adb_usb.sh | 90 ---------------------------- userspace/usr/comma/comma.sh | 44 +++++++++++++- 3 files changed, 52 insertions(+), 92 deletions(-) create mode 100644 userspace/usr/comma/99-android.rules delete mode 100644 userspace/usr/comma/adb_usb.sh diff --git a/userspace/usr/comma/99-android.rules b/userspace/usr/comma/99-android.rules new file mode 100644 index 00000000..34abc162 --- /dev/null +++ b/userspace/usr/comma/99-android.rules @@ -0,0 +1,10 @@ +# Google vendor ID (18d1) +SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev", TAG+="uaccess" +SUBSYSTEM=="usb_device", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev", TAG+="uaccess" + +# Qualcomm vendor ID (05c6) +SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", MODE="0666", GROUP="plugdev", TAG+="uaccess" +SUBSYSTEM=="usb_device", ATTR{idVendor}=="05c6", MODE="0666", GROUP="plugdev", TAG+="uaccess" + +# Additional rules for ADB interface +SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0666" \ No newline at end of file diff --git a/userspace/usr/comma/adb_usb.sh b/userspace/usr/comma/adb_usb.sh deleted file mode 100644 index a8599ff5..00000000 --- a/userspace/usr/comma/adb_usb.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2012-2015, 2018, The Linux Foundation. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of The Linux Foundation nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO -# EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -case "$1" in - start) - # First, ensure configfs is mounted - if ! mount | grep -q "configfs on /sys/kernel/config"; then - mount -t configfs none /sys/kernel/config || exit 1 - fi - - # Clean up any existing gadget - if [ -d /sys/kernel/config/usb_gadget/g1 ]; then - echo "" > /sys/kernel/config/usb_gadget/g1/UDC - rm -rf /sys/kernel/config/usb_gadget/g1 - fi - - # Create new gadget - mkdir -p /sys/kernel/config/usb_gadget/g1 || exit 1 - cd /sys/kernel/config/usb_gadget/g1 - - # Configure gadget - echo "0xbbaa" > idVendor - echo "0xddcc" > idProduct - - # Create English locale - mkdir -p strings/0x409 - echo "6192" > strings/0x409/serialnumber - echo "comma.ai" > strings/0x409/manufacturer - echo "comma 3x" > strings/0x409/product - - # Create configuration - mkdir -p configs/c.1/strings/0x409 - echo "ADB Config" > configs/c.1/strings/0x409/configuration - echo 500 > configs/c.1/MaxPower - - # Create function - mkdir -p functions/ffs.adb - ln -s functions/ffs.adb configs/c.1/ - - # Set up ADB functionfs - mkdir -p /dev/usb-ffs/adb - mount -o uid=2000,gid=2000 -t functionfs adb /dev/usb-ffs/adb - - # Find and enable UDC - UDC=$(ls /sys/class/udc | head -n 1) - echo $UDC > UDC - - # Enable USB gadget - if [ -d /sys/class/android_usb/android0 ]; then - echo 1 > /sys/class/android_usb/android0/enable - fi - ;; - - stop) - echo "Stopping USB Android Gadget" - ;; - - restart) - $0 stop - $0 start - ;; - *) - echo "Usage usb { start | stop | restart}" >&2 - exit 1 - ;; -esac - diff --git a/userspace/usr/comma/comma.sh b/userspace/usr/comma/comma.sh index 90378b2d..8d040c96 100755 --- a/userspace/usr/comma/comma.sh +++ b/userspace/usr/comma/comma.sh @@ -44,8 +44,48 @@ handle_setup_keys () { } handle_adb () { - sudo systemctl start adbd - bash "$(dirname "$0")/adb_usb.sh start" + # Try to configure USB controller through configfs + sudo mkdir -p /sys/kernel/config/usb_gadget/g1 2>/dev/null || true + + cd /sys/kernel/config/usb_gadget/g1 + + # Basic USB configuration + sudo sh -c 'echo "0x18d1" > idVendor' # Google vendor ID + sudo sh -c 'echo "0x2d01" > idProduct' # Generic ADB product ID + + # Create strings directory and add basic info + sudo mkdir -p strings/0x409 + sudo sh -c 'echo "Comma.ai" > strings/0x409/manufacturer' + sudo sh -c 'echo "Comma Device" > strings/0x409/product' + + # Create configuration + sudo mkdir -p configs/c.1/strings/0x409 + sudo sh -c 'echo "ADB Configuration" > configs/c.1/strings/0x409/configuration' + + # Create function + sudo mkdir -p functions/ffs.adb + sudo ln -s functions/ffs.adb configs/c.1 + + sudo mount -o remount,rw / + sudo cp /usr/comma/99-android.rules /etc/udev/rules.d/99-android.rules + sudo chmod 777 /etc/udev/rules.d/99-android.rules + sudo chmod a+r /etc/udev/rules.d/99-android.rules + + # Create plugdev group if it doesn't exist + sudo groupadd -f plugdev + sudo usermod -aG plugdev comma + + # Restart udev and ADB with debug logging + sudo service udev restart + sudo udevadm control --reload-rules + sudo udevadm trigger + + sudo systemctl restart adbd + + # Print ADB status for debugging + systemctl status adbd + + sudo mount -o remount,ro / } # factory reset handling