meta-fii/meta-kudo: Add USB-NIC configuration

1. add USB-NIC functions

Signed-off-by: Lancelot Kao <lancelot.kao@fii-usa.com>
Change-Id: I1eba438c770c8ccd5794b1184d4a25ef7fbfb0e6
diff --git a/meta-fii/meta-kudo/recipes-kernel/linux/linux-nuvoton/kudo.cfg b/meta-fii/meta-kudo/recipes-kernel/linux/linux-nuvoton/kudo.cfg
index 0811dd9..9755d94 100644
--- a/meta-fii/meta-kudo/recipes-kernel/linux/linux-nuvoton/kudo.cfg
+++ b/meta-fii/meta-kudo/recipes-kernel/linux/linux-nuvoton/kudo.cfg
@@ -30,21 +30,15 @@
 CONFIG_JFFS2_FS=y
 CONFIG_EXT4_FS=y
 
+# SPI
 CONFIG_SPI=y
 CONFIG_SPI_NPCM_FIU=y
 CONFIG_MTD_M25P80=y
 CONFIG_SPI_NPCM_PSPI=y
 
-CONFIG_NET_NCSI=y
-
-CONFIG_EEPROM_AT24=y
-CONFIG_I2C_MUX=y
-CONFIG_I2C_MUX_PCA954x=y
-CONFIG_I2C_SLAVE_EEPROM=y
-CONFIG_GPIO_PCA953X=y
-CONFIG_GPIO_PCA953X_IRQ=y
-CONFIG_GPIO_PCF857X=y
-CONFIG_MUX_MMIO=y
+#
+# USB configuration
+#
 CONFIG_USB_U_ETHER=y
 CONFIG_USB_F_ECM=y
 CONFIG_USB_F_EEM=y
@@ -58,6 +52,18 @@
 CONFIG_USB_CONFIGFS_EEM=y
 CONFIG_USB_CONFIGFS_MASS_STORAGE=y
 CONFIG_USB_CONFIGFS_F_HID=y
+CONFIG_USB_GADGET_NPCM_USB2=y
+
+CONFIG_NET_NCSI=y
+
+CONFIG_EEPROM_AT24=y
+CONFIG_I2C_MUX=y
+CONFIG_I2C_MUX_PCA954x=y
+CONFIG_I2C_SLAVE_EEPROM=y
+CONFIG_GPIO_PCA953X=y
+CONFIG_GPIO_PCA953X_IRQ=y
+CONFIG_GPIO_PCF857X=y
+CONFIG_MUX_MMIO=y
 
 CONFIG_MEDIA_SUPPORT=y
 CONFIG_VIDEO_NUVOTON=y
@@ -65,8 +71,6 @@
 CONFIG_NPCM750_ECE=y
 CONFIG_FORCE_MAX_ZONEORDER=12
 
-CONFIG_USB_GADGET_NPCM_USB2=y
-
 CONFIG_NPCM7XX_PCI_MBOX=y
 
 CONFIG_RESET_NPCM=y
@@ -74,6 +78,9 @@
 CONFIG_I2C_SLAVE=y
 CONFIG_I2C_SLAVE_MQUEUE=y
 CONFIG_IPMB_DEVICE_INTERFACE=y
+
+#
+# JATG Configuration
 CONFIG_NUVOTON_JTAG=y
 CONFIG_NPCM7XX_JTAG_MASTER=y
 
@@ -103,6 +110,5 @@
 CONFIG_IP_NF_TARGET_REJECT=y
 CONFIG_NF_DEFRAG_IPV6=y
 
-
 CONFIG_TCG_TPM=y
 CONFIG_TCG_TIS_I2C_INFINEON=y
diff --git a/meta-fii/meta-kudo/recipes-kudo/network/usb-network.bb b/meta-fii/meta-kudo/recipes-kudo/network/usb-network.bb
new file mode 100644
index 0000000..249e454
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/network/usb-network.bb
@@ -0,0 +1,29 @@
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+inherit allarch systemd
+
+DEPENDS += "systemd"
+RDEPENDS_${PN} += "libsystemd"
+RDEPENDS_${PN} += "bash"
+
+SRC_URI_append += " \
+    file://usb_network.sh \
+    file://usb_network.service \
+    file://00-bmc-usb0.network \
+    "
+
+SYSTEMD_PACKAGES = "${PN}"
+SYSTEMD_SERVICE_${PN}_append = " usb_network.service"
+FILES_${PN} += "${sysconfdir_native}/systemd/network/00-bmc-usb0.network"
+
+do_install() {
+    install -d ${D}/${sbindir}
+    install -m 0755 ${WORKDIR}/usb_network.sh ${D}/${sbindir}
+
+    install -d ${D}${systemd_unitdir}/system/
+    install -m 0644 ${WORKDIR}/usb_network.service ${D}${systemd_unitdir}/system
+
+    install -d ${D}${sysconfdir_native}/systemd/network/
+    install -m 0644 ${WORKDIR}/00-bmc-usb0.network ${D}${sysconfdir_native}/systemd/network
+}
diff --git a/meta-fii/meta-kudo/recipes-kudo/network/usb-network/00-bmc-usb0.network b/meta-fii/meta-kudo/recipes-kudo/network/usb-network/00-bmc-usb0.network
new file mode 100644
index 0000000..1b8d66e
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/network/usb-network/00-bmc-usb0.network
@@ -0,0 +1,7 @@
+[Match]
+Name=usb0
+[Address]
+Address=169.254.95.118/16
+[Network]
+LinkLocalAddressing=ipv6
+IPv6AcceptRA=no
diff --git a/meta-fii/meta-kudo/recipes-kudo/network/usb-network/usb_network.service b/meta-fii/meta-kudo/recipes-kudo/network/usb-network/usb_network.service
new file mode 100644
index 0000000..81a4e42
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/network/usb-network/usb_network.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=enable usb network
+After=phosphor-ipmi-host.service
+
+[Service]
+Type=oneshot
+ExecStart=/bin/bash -c '/usr/sbin/usb_network.sh'
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-fii/meta-kudo/recipes-kudo/network/usb-network/usb_network.sh b/meta-fii/meta-kudo/recipes-kudo/network/usb-network/usb_network.sh
new file mode 100644
index 0000000..8d7804d
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/network/usb-network/usb_network.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+cd /sys/kernel/config/usb_gadget
+
+if [ ! -f "g1" ]; then
+    mkdir g1
+    cd g1
+
+    echo 0x1d6b > idVendor  # Linux foundation
+    echo 0x0104 > idProduct # Multifunction composite gadget
+    mkdir -p strings/0x409
+    echo "Linux" > strings/0x409/manufacturer
+    echo "Ethernet/ECM gadget" > strings/0x409/product
+
+    mkdir -p configs/c.1
+    echo 100 > configs/c.1/MaxPower
+    mkdir -p configs/c.1/strings/0x409
+    echo "ECM" > configs/c.1/strings/0x409/configuration
+
+    mkdir -p functions/ecm.usb0
+
+    ln -s functions/ecm.usb0 configs/c.1
+
+    echo f0835000.udc > UDC
+
+fi
+exit 0
diff --git a/meta-fii/meta-kudo/recipes-phosphor/image/obmc-phosphor-image.bbappend b/meta-fii/meta-kudo/recipes-phosphor/image/obmc-phosphor-image.bbappend
index d4d9d31..f0eb972 100644
--- a/meta-fii/meta-kudo/recipes-phosphor/image/obmc-phosphor-image.bbappend
+++ b/meta-fii/meta-kudo/recipes-phosphor/image/obmc-phosphor-image.bbappend
@@ -6,3 +6,4 @@
 OBMC_IMAGE_EXTRA_INSTALL_append_kudo = " phosphor-ipmi-blobs"
 OBMC_IMAGE_EXTRA_INSTALL_append_kudo = " phosphor-ipmi-ethstats"
 OBMC_IMAGE_EXTRA_INSTALL_append_kudo = " phosphor-ipmi-flash"
+OBMC_IMAGE_EXTRA_INSTALL_append_kudo = " usb-network"