![如何创建 ADB Gadget 配置?](https://linux22.com/image/224238/%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BA%20ADB%20Gadget%20%E9%85%8D%E7%BD%AE%EF%BC%9F.png)
我正在读小工具配置文档。我还使用工作的 Android 设备来引用和复制/config/usb_gadget/g1
.我现在正在启动 initramfs 并尝试将设备作为 adb 设备启动,而不运行任何 Linux 风格。我从设备的 boot.img 中提取了内核,并使用以下 init 脚本更改了 ramdisk.cpio.gz
#!/usr/bin/bash
PATH=/usr/bin:/usr/sbin
mount -a #mount dev sys proc and configfs
create_devices #make all necessary nodes
mkdir -p /config/usb_gadget/g1/strings/0x409
mkdir -p /config/usb_gadget/g1/functions/ffs.adb
mkdir -p /config/usb_gadget/g1/functions/configs/b.1/strings/0x409
ln -s /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f1
echo "0x0e8d" > /config/usb_gadget/g1/idVendor
echo "0x201c" > /config/usb_gadget/g1/idProduct
echo "0123456789101112" > /config/usb_gadget/g1/strings/0x409/serialnumber
echo "TECNO" > /config/usb_gadget/g1/strings/0x409/manufacturer
echo "TECNO KI7" > /config/usb_gadget/g1/strings/0x409/product
echo adb > /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration
echo "0x80" > /config/usb_gadget/g1/configs/b.1/bmAttributes
echo musb-hdrc > /config/usb_gadget/g1/UDC
echo "0x00" > /config/usb_gadget/g1/bDeviceClass
echo "0x00" > /config/usb_gadget/g1/bDeviceProtocol
echo "0x00" > /config/usb_gadget/g1/bDeviceSubClasss
echo "0x0404" > /config/usb_gadget/g1/bcdDevice
echo "0x0200" > /config/usb_gadget/g1/bcdUSB
echo "0x40" > /config/usb_gadget/g1/bMaxPacketSize0
设备启动正常,但无法启动 ADB USB Gadget。这是一个初始化日志
[1.550749] (7) [1:init] gadgets_make name=g1
[1.552088] (7) [1:init] function_make name=ffs.adb
[1.552104] (7) [1:init] file system registered
[1.558890] (1) [1:init] function_make name=configs
[1.558911] (1) [1:init] Unable to locate . in FUNC.INSTANCE
[1.562824] (2) [1:init] gadget_dev_desc_UDC_store write musb-hdrc
[1.562839] (2) [1:init] configfs_composite_bind
[1.562852] (2) [1:init] composite_dev_prepare 0000000037341456
[1.562870] (2) [1:init] Need at least one configuration in g1.
[1.562878] (2) [1:init] composite_dev_cleanup os_desc_req[0]=(null)cdev>req[0]=0000000037341456
[1.562892] (2) [1:init] configfs-gadget musb-hdrc: failed to start g1: -22
我怀疑也许我没有正确链接 configs 文件夹,但以下结果相同
ln -s /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/ffs.adb
它继续说明Need at least one configuration in g1.
当我运行时find /config/usb_gadget/g1
它找不到任何文件,/config/usb_gadget/g1/configs
但它确实列出了/config/usb_gadget/g1/configs
可能的路径。这意味着我尝试写入配置的任何文件都不会被写入,因为/config/usb_gadget/g1/configs/b.1
当我尝试查找它时它不存在。我怎样才能写入文件/config/usb_gadget/g1/configs
?
答案1
事实证明我需要分开制作这些目录
GADGET=/sys/kernel/config/usb_gadget/g1
mkdir -p "$GADGET"
mkdir -p "$GADGET"/strings/0x409
mkdir -p "$GADGET"/configs/b.1
mkdir -p "$GADGET"/configs/b.1/strings/0x409
mkdir -p "$GADGET"/functions/ffs.adb
可能是因为configfs需要自动填充模板文件