main/postmarketos-mkinitfs: make USB configfs attrs customizable (!706)

Some devices' downstream kernels may have different RNDIS/functionfs
drivers (ex. QCRNDIS) that require different values for some
configfs gadget attributes. Make it possible to customize with
deviceinfo file from device- package.

The idea is that each device- package can optionally specify a
bunch of `deviceinfo_usb_*` variables to customize the way it is
visible on USB bus. The ability to override
`deviceinfo_usb_rndis_function` is essential to make downstream
sdm660 based device to appear on USB bus.

While at it, make `idVendor`, `idProduct` and `serialnumber` also
customizable. So that we can make, for example, PineTab appear on
USB bus as PineTab, not as "Google Inc. Nexus 4 (fastboot)".
This commit is contained in:
Alexey Min 2019-09-12 18:18:19 +03:00 committed by Oliver Smith
parent fc30659221
commit 68821d2cb2
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 29 additions and 14 deletions

View file

@ -1,5 +1,5 @@
pkgname=postmarketos-mkinitfs
pkgver=0.7.19
pkgver=0.7.20
pkgrel=0
pkgdesc="Tool to generate initramfs images for postmarketOS"
url="https://postmarketos.org"
@ -25,5 +25,5 @@ package() {
}
sha512sums="8be7f29394f8cd4e1c4b93f018f6314350f7e37e20d242c97284c1b112a106f882318a101bc0c70b391590b969023901580c677ee9f869850e90e69171a44e80 init.sh.in
0a74a5be08ecc0e07ea4f4e361865327bf1e56006da0aa1bc2c5716ea2951dcdc9c9fcb9f5a6205aeedfff08e027b2bb44913c891378144d0fe264b53257f359 init_functions.sh
4131608b597cf750d0f3931623088d0e11896fb3dd99c3c5699a3ff995d932d72b4c80d4a29edc34007b9fc5b17d41492bd21dc532199dfc7054d6a4c8349043 init_functions.sh
3f918f8b5967b73e507c2ddf36dccc24fee98298f05ca23e22605400de95137f8877e09769616e7db388557c645fb45c03e1e6b5bab815ec9f853c318f0431f1 mkinitfs.sh"

View file

@ -238,6 +238,7 @@ setup_usb_network_android() {
}
setup_usb_network_configfs() {
# See: https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt
CONFIGFS=/config/usb_gadget
if ! [ -e "$CONFIGFS" ]; then
@ -245,28 +246,42 @@ setup_usb_network_configfs() {
return
fi
# Default values for USB-related deviceinfo variables
usb_idVendor="${deviceinfo_usb_idVendor:-0x18D1}" # default: Google Inc.
usb_idProduct="${deviceinfo_usb_idProduct:-0xD001}" # default: Nexus 4 (fastboot)
usb_serialnumber="${deviceinfo_usb_serialnumber:-postmarketOS}"
usb_rndis_function="${deviceinfo_usb_rndis_function:-rndis.usb0}"
echo " Setting up an USB gadget through configfs"
# Create an usb gadet configuration
mkdir $CONFIGFS/g1 || echo " Couldn't create $CONFIGFS/g1"
printf "%s" "0x18D1" >"$CONFIGFS/g1/idVendor"
printf "%s" "0xD001" >"$CONFIGFS/g1/idProduct"
echo "$usb_idVendor" > "$CONFIGFS/g1/idVendor"
echo "$usb_idProduct" > "$CONFIGFS/g1/idProduct"
# Create english (0x409) strings
mkdir $CONFIGFS/g1/strings/0x409 || echo " Couldn't create $CONFIGFS/g1/strings/0x409"
echo "postmarketOS" > "$CONFIGFS/g1/strings/0x409/manufacturer"
echo "postmarketOS" > "$CONFIGFS/g1/strings/0x409/serialnumber"
echo "Debug network interface" > "$CONFIGFS/g1/strings/0x409/product"
# Create rndis function
mkdir $CONFIGFS/g1/functions/rndis.usb0 || echo " Couldn't create $CONFIGFS/g1/functions/rndis.usb0"
# shellcheck disable=SC2154
echo "$deviceinfo_manufacturer" > "$CONFIGFS/g1/strings/0x409/manufacturer"
echo "$usb_serialnumber" > "$CONFIGFS/g1/strings/0x409/serialnumber"
# shellcheck disable=SC2154
echo "$deviceinfo_name" > "$CONFIGFS/g1/strings/0x409/product"
# Create rndis function. The function can be named differently in downstream kernels.
mkdir $CONFIGFS/g1/functions/"$usb_rndis_function" \
|| echo " Couldn't create $CONFIGFS/g1/functions/$usb_rndis_function"
# Create configuration instance for the gadget
mkdir $CONFIGFS/g1/configs/c.1 || echo " Couldn't create $CONFIGFS/g1/configs/c.1"
mkdir $CONFIGFS/g1/configs/c.1/strings/0x409 || echo " Couldn't create $CONFIGFS/g1/configs/c.1/strings/0x409"
printf "%s" "rndis" > $CONFIGFS/g1/configs/c.1/strings/0x409/configuration || echo " Couldn't write configration name"
mkdir $CONFIGFS/g1/configs/c.1 \
|| echo " Couldn't create $CONFIGFS/g1/configs/c.1"
mkdir $CONFIGFS/g1/configs/c.1/strings/0x409 \
|| echo " Couldn't create $CONFIGFS/g1/configs/c.1/strings/0x409"
echo "rndis" > $CONFIGFS/g1/configs/c.1/strings/0x409/configuration \
|| echo " Couldn't write configration name"
# Link the rndis instance to the configuration
ln -s $CONFIGFS/g1/functions/rndis.usb0 $CONFIGFS/g1/configs/c.1 || echo " Couldn't symlink rndis.usb0"
ln -s $CONFIGFS/g1/functions/"$usb_rndis_function" $CONFIGFS/g1/configs/c.1 \
|| echo " Couldn't symlink $usb_rndis_function"
# Check if there's an USB Device Controller
if [ -z "$(ls /sys/class/udc)" ]; then
@ -274,7 +289,7 @@ setup_usb_network_configfs() {
return
fi
# Link the gadget instance to an USB Device Controller
# Link the gadget instance to an USB Device Controller. This activates the gadget.
# See also: https://github.com/postmarketOS/pmbootstrap/issues/338
# shellcheck disable=SC2005
echo "$(ls /sys/class/udc)" > $CONFIGFS/g1/UDC || echo " Couldn't write UDC"