| #!/bin/sh |
| # |
| # Copyright 2015 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| # |
| # Script that sets up the USB debug link. |
| |
| set -e |
| |
| CONFIG_ROOT="/sys/kernel/config" |
| NCM_GADGET="ncm1" |
| NETWORK_NAME="usb0" |
| STRING_FOLDER="strings/0x409" |
| # TODO (yimingc@) Change this to a board-specific variable. |
| UDC_DEVICE_NAME="ff580000.usb" |
| |
| # TODO (yimingc@) Change VID/PID to the actual assigned values. |
| VENDOR_ID="0x0101" |
| PRODUCT_ID="0x0202" |
| CONFIGURATION_NAME="NCM Network Configuration" |
| SERIAL_NUMBER="1" |
| MANUFACTURER_NAME="Google" |
| PRODUCT_NAME="Brillo Debug Link" |
| |
| main() { |
| if [ $# -ne 0 ]; then |
| echo "$0: error: program takes no args" > &2 |
| exit 1 |
| fi |
| |
| modprobe configfs || true |
| modprobe libcomposite || true |
| |
| # Create NCM gadget folder. |
| mount -t configfs none "${CONFIG_ROOT}" |
| mkdir "${CONFIG_ROOT}/usb_gadget/${NCM_GADGET}" |
| cd "${CONFIG_ROOT}/usb_gadget/${NCM_GADGET}" |
| |
| # Create NCM network function and configuration. |
| mkdir "functions/ncm.${NETWORK_NAME}" |
| mkdir configs/c.1 |
| |
| # Write the required strings for NCM descriptor enumeration. |
| echo "${VENDOR_ID}" > idVendor |
| echo "${PRODUCT_ID}" > idProduct |
| mkdir "${STRING_FOLDER}" |
| echo "${SERIAL_NUMBER}" > "${STRING_FOLDER}/serialnumber" |
| echo "${MANUFACTURER_NAME}" > "${STRING_FOLDER}/manufacturer" |
| echo "${PRODUCT_NAME}" > "${STRING_FOLDER}/product" |
| mkdir "configs/c.1/${STRING_FOLDER}" |
| echo "${CONFIGURATION_NAME}" > "configs/c.1/${STRING_FOLDER}/configuration" |
| |
| # Activate the NCM gadget. |
| ln -s "functions/ncm.${NETWORK_NAME}" configs/c.1 |
| echo "${UDC_DEVICE_NAME}" > UDC |
| echo "connect" > /sys/class/udc/"${UDC_DEVICE_NAME}"/soft_connect |
| sleep 3 |
| ifconfig "${NETWORK_NAME}" 169.254.100.2 netmask 255.255.255.0 |
| } |
| |
| main "$@" |