Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions images/usb-modules/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: GPL-2.0
# Out-of-tree build: no kernel .config needed.
# Use: make -C /lib/modules/$(uname -r)/build M=$(pwd) modules

obj-m += usbip-core.o
usbip-core-y := usbip_common.o usbip_event.o

obj-m += vhci-hcd.o
vhci-hcd-y := vhci_sysfs.o vhci_tx.o vhci_rx.o vhci_hcd.o

obj-m += usbip-host.o
usbip-host-y := stub_dev.o stub_main.o stub_rx.o stub_tx.o
56 changes: 56 additions & 0 deletions images/usb-modules/apply-patches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

# Copyright 2026 Flant JSC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Apply patches from patches/ to each kernel version tree in .out/
# Usage: ./apply-patches.sh [out-dir]
# Default out-dir is .out (relative to script directory)

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUT_DIR="${1:-.out}"
PATCHES_DIR="${SCRIPT_DIR}/patches"

cd "$SCRIPT_DIR"
OUT_DIR="$(realpath "$OUT_DIR")"

if [[ ! -d "$OUT_DIR" ]]; then
echo "Error: output directory '$OUT_DIR' does not exist" >&2
exit 1
fi

if [[ ! -d "$PATCHES_DIR" ]]; then
echo "Error: patches directory '$PATCHES_DIR' does not exist" >&2
exit 1
fi

for version_dir in "$OUT_DIR"/*/; do
[[ -d "$version_dir" ]] || continue
version="$(basename "$version_dir")"
for patch in "$PATCHES_DIR"/*.patch; do
[[ -f "$patch" ]] || continue
echo "Applying $(basename "$patch") to $version..."
if ! patch -d "$version_dir" -p0 --forward --silent < "$patch"; then
if patch -d "$version_dir" -p0 --reverse --check --silent < "$patch" 2>/dev/null; then
echo " (already applied, skipping)"
else
echo " FAILED" >&2
exit 1
fi
fi
done
done

echo "Done."
72 changes: 72 additions & 0 deletions images/usb-modules/build-usbip-modules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash

# Copyright 2026 Flant JSC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Build usbip-core, usbip-host, vhci-hcd for the running kernel and put .ko into a tmp dir.
# Needs: kernel headers (e.g. linux-headers-$(uname -r)), make, gcc. No full kernel source.
#
# Usage:
# ./build-usbip-modules.sh [OUTPUT_DIR]
# OUTPUT_DIR defaults to /tmp/usbip-modules-$(uname -r)
# USBIP_SRC defaults to the directory where this script lives (driver source).
#
# Env:
# KVER - kernel version to build for (default: uname -r)
# USBIP_SRC - path to driver source (must contain .c and Makefile.standalone)
# OUTPUT_DIR - output directory (overrides optional argument)
#
# Minimal deps: bash, make, gcc, kernel headers package (e.g. linux-headers-${KVER}).

set -e

KVER="${KVER:-$(uname -r)}"
for base in /lib/modules /usr/lib/modules; do
[[ -d "${base}/${KVER}/build" || -L "${base}/${KVER}/build" ]] || continue
KBUILD="${base}/${KVER}/build"
break
done
KBUILD="${KBUILD:-/lib/modules/${KVER}/build}"
USBIP_SRC="${USBIP_SRC:-$(cd "$(dirname "$0")" && pwd)}"
OUTPUT_DIR="${OUTPUT_DIR:-${1:-/tmp/usbip-modules-${KVER}}}"

if [[ ! -d "$KBUILD" && ! -L "$KBUILD" ]]; then
echo "build-usbip-modules: kernel build dir not found for ${KVER}" >&2
echo "Install kernel headers (kernel-devel or linux-headers-${KVER}) on the host." >&2
exit 1
fi

# Resolve symlink so make sees the real path (must be visible in container)
if [[ -L "$KBUILD" ]]; then
KBUILD=$(readlink -f "$KBUILD")
fi
if [[ ! -d "$KBUILD" ]]; then
echo "build-usbip-modules: build is a symlink but its target is not visible in the container." >&2
echo " resolved path: $KBUILD" >&2
echo "Mount the kernel build tree from the host, e.g.:" >&2
echo " -v /usr/src/kernels:/usr/src/kernels:ro" >&2
exit 1
fi

if [[ ! -f "$USBIP_SRC/Makefile" ]]; then
echo "build-usbip-modules: $USBIP_SRC/Makefile not found" >&2
exit 1
fi

make -C "$KBUILD" M="$USBIP_SRC" CC="${CC:-gcc}" modules

mkdir -p "$OUTPUT_DIR"
cp -f "$USBIP_SRC"/usbip-core.ko "$USBIP_SRC"/usbip-host.ko "$USBIP_SRC"/vhci-hcd.ko "$OUTPUT_DIR/"

echo "Built for ${KVER}; modules in: ${OUTPUT_DIR}"
ls -la "$OUTPUT_DIR"/*.ko
20 changes: 20 additions & 0 deletions images/usb-modules/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# Copyright 2026 Flant JSC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

KVER=$(uname -r | cut -d. -f1,2)
USBIP_SRC="/src/linux/$KVER/drivers/usb/usbip" ./build-usbip-modules.sh "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--- drivers/usb/usbip/vhci.h
+++ drivers/usb/usbip/vhci.h
@@ -73,19 +73,11 @@ enum hub_speed {
};

/* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
-#ifdef CONFIG_USBIP_VHCI_HC_PORTS
-#define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS
-#else
-#define VHCI_HC_PORTS 8
-#endif
+#define VHCI_HC_PORTS 16

/* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */
#define VHCI_PORTS (VHCI_HC_PORTS*2)

-#ifdef CONFIG_USBIP_VHCI_NR_HCS
-#define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
-#else
-#define VHCI_NR_HCS 1
-#endif
+#define VHCI_NR_HCS 4

#define MAX_STATUS_NAME 16
34 changes: 34 additions & 0 deletions images/usb-modules/patches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

This directory contains patches used to build the following out-of-tree kernel modules:

- `usbip-core`
- `usbip-host`
- `vhci-hcd`

---

## 001-vhci-increase-ports-and-controllers.patch

This patch modifies the default configuration of the `vhci-hcd` (Virtual Host Controller Interface) driver.

### Changes

- Sets the number of ports per virtual hub to **16** (hardcoded).
- Sets the number of virtual host controllers to **4** (hardcoded).
- Removes dependency on:
- `CONFIG_USBIP_VHCI_HC_PORTS`
- `CONFIG_USBIP_VHCI_NR_HCS`

### Resulting Capacity

Each VHCI controller provides:
- 2 hubs (USB 2.0 and USB 3.0)
- 16 ports per hub

With 4 controllers total:

4 controllers × 2 hubs × 16 ports = **128 ports**

This allows up to **128 USB devices** to be attached simultaneously via USB/IP (subject to kernel and system limitations).

> Note: The number of ports and controllers is now fixed at compile time and no longer configurable via kernel config options.
10 changes: 10 additions & 0 deletions images/usb-modules/tools/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module tools

go 1.25.0

require (
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.9
)

require github.com/inconshreveable/mousetrap v1.1.0 // indirect
10 changes: 10 additions & 0 deletions images/usb-modules/tools/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Loading
Loading