summaryrefslogtreecommitdiff
path: root/meta-ampere/meta-common/recipes-ac01/usbnet/ampere-usbnet/ampere_add_usbnet_gadget.sh
diff options
context:
space:
mode:
authorThang Q. Nguyen <thang@os.amperecomputing.com>2020-12-24 05:22:46 +0300
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2021-02-01 16:44:47 +0300
commitac0d2b843d4ad4e3a92ac5b427021aaa43dd2612 (patch)
tree503b65a175fefa1fd6d6d3def64936f275e21729 /meta-ampere/meta-common/recipes-ac01/usbnet/ampere-usbnet/ampere_add_usbnet_gadget.sh
parentd76c413d1c8430cb26a5365988521815112e45f5 (diff)
downloadopenbmc-ac0d2b843d4ad4e3a92ac5b427021aaa43dd2612.tar.xz
meta-ampere: Support virtual Ethernet over USB device
Implement systemd service to create an Ethernet over USB interface for communication between CPU and BMC. Tested: 1. Check usb0 ethernet interface in BMC console root@mtjade:~# ifconfig usb0 usb0 Link encap:Ethernet HWaddr DA:F7:E9:A3:5A:0C inet addr:192.168.0.10 Bcast:192.168.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:2 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:412 (412.0 B) 2. Check USB Ethernet device on Host Linux $ lsusb | grep Ethernet Bus 001 Device 004: ID 1d6b:0103 Linux Foundation NCM (Ethernet) Gadget Signed-off-by: Chanh Nguyen <chanh@os.amperecomputing.com> Signed-off-by: Thang Q. Nguyen <thang@os.amperecomputing.com> Change-Id: Icb7c096df426233e8f2ee7318f2a1805f07ab3a7
Diffstat (limited to 'meta-ampere/meta-common/recipes-ac01/usbnet/ampere-usbnet/ampere_add_usbnet_gadget.sh')
-rw-r--r--meta-ampere/meta-common/recipes-ac01/usbnet/ampere-usbnet/ampere_add_usbnet_gadget.sh93
1 files changed, 93 insertions, 0 deletions
diff --git a/meta-ampere/meta-common/recipes-ac01/usbnet/ampere-usbnet/ampere_add_usbnet_gadget.sh b/meta-ampere/meta-common/recipes-ac01/usbnet/ampere-usbnet/ampere_add_usbnet_gadget.sh
new file mode 100644
index 000000000..c4c2c273f
--- /dev/null
+++ b/meta-ampere/meta-common/recipes-ac01/usbnet/ampere-usbnet/ampere_add_usbnet_gadget.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+
+# Add an Ethernet over USB gadget device and connect to a port of Aspeed USB
+# virtual hub. If can't find any free port on virtual hub, exit with failure.
+# If can't find the virtual hub, exit with failure.
+
+# Author: Thinh Hung Pham <thinh.pham@amperecomputing.com>
+# Signed-off-by: Chanh Nguyen <chnguyen@amperecomputing.com>
+
+UDC_SYSPATH=/sys/class/udc
+VHUB_DEVICE=1e6a0000.usb-vhub:p
+GADGET_CONFIG_SYSPATH=/sys/kernel/config/usb_gadget
+USBNET=usbnet
+# The number of port on AST2500 USB virtual hub
+NUM_PORT_USB_HUB=5
+# idVendor = 0x1d6b: Linux Foundation
+VENDORID=0x1d6b
+# idProduct = 0x0103: NCM (Ethernet) Gadget
+PRODUCTID=0x0103
+# Language code = 0x409: English – United States
+LANGUAGEID=0x409
+SERIALNUMBER=cafecafe
+MANUFACTURER=Aspeed
+FUNCTION=ecm.usb0
+
+if [ ! -d ${GADGET_CONFIG_SYSPATH} ]; then
+ # GADGET_CONFIG_SYSPATH is not exist
+ # Return 1 so that systemd knows the service failed to start
+ echo "ERROR: ${GADGET_CONFIG_SYSPATH} : doesn't exist!"
+ exit 1
+fi
+
+find_free_vhub_port(){
+ for ((i=1;i<=${NUM_PORT_USB_HUB};i++))
+ do
+ state=$(cat ${UDC_SYSPATH}/${VHUB_DEVICE}${i}/state)
+ func=$(cat ${UDC_SYSPATH}/${VHUB_DEVICE}${i}/function)
+ if [ "${state}" == "not attached" -a "${func}" == "" ]; then
+ FREEUDC=${VHUB_DEVICE}${i}
+ break
+ fi
+ done
+ if [ ${i} -eq 6 ]; then
+ # Can't find a free port
+ # Return 1 so that systemd knows the service failed to start
+ echo "ERROR: Can't find a free port !"
+ exit 1
+ fi
+}
+
+if [ -d ${GADGET_CONFIG_SYSPATH}/${USBNET} ]; then
+ cd ${GADGET_CONFIG_SYSPATH}/${USBNET}
+else
+ # Create the gadget
+ mkdir ${GADGET_CONFIG_SYSPATH}/${USBNET}
+ cd ${GADGET_CONFIG_SYSPATH}/${USBNET}
+
+ # Configure the gadget
+ echo ${VENDORID} > idVendor
+ echo ${PRODUCTID} > idProduct
+ mkdir strings/${LANGUAGEID}
+ echo ${SERIALNUMBER} > strings/${LANGUAGEID}/serialnumber
+ echo ${MANUFACTURER} > strings/${LANGUAGEID}/manufacturer
+ echo ${USBNET} > strings/${LANGUAGEID}/product
+
+ # Create the configuration
+ mkdir configs/c.1
+ mkdir configs/c.1/strings/${LANGUAGEID}
+
+ # Create the function
+ mkdir functions/${FUNCTION}
+
+ # Associate the function with its configuration
+ ln -s functions/${FUNCTION} configs/c.1
+fi
+
+# Find an available virtual hub port
+find_free_vhub_port
+
+# Enable the gadget
+echo ${FREEUDC} > UDC
+
+if [[ $? -ne 0 ]]; then
+ # End
+ cd - > /dev/null
+ # Virtual HUB is not available
+ # Return 1 so that systemd knows the service failed to start
+ exit 1
+fi
+
+# End
+cd - > /dev/null
+