Skip to content

Commit 2c11371

Browse files
committed
fix: more install fixes for gadget modprobing and loading
1 parent 3e5c68c commit 2c11371

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

init-raspbian.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ echo 1 | sudo tee /sys/module/bluetooth/parameters/disable_ertm > /dev/null
1010
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
1111
INSTALL_HOME="$(dirname "$SCRIPT_DIR")"
1212
RAW_GADGET_DIR="${RAW_GADGET_DIR:-$INSTALL_HOME/raw-gadget}"
13+
sudo modprobe dwc2 2>/dev/null || true
14+
sudo modprobe libcomposite 2>/dev/null || true
1315
lsmod | grep -q raw_gadget || (cd "$RAW_GADGET_DIR/raw_gadget" && sudo bash ./insmod.sh)

install.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,21 @@ if grep -qxF "dtoverlay=dwc2,dr_mode=host" "$BOOT_CONFIG" 2>/dev/null; then
160160
sudo sed -i 's/^dtoverlay=dwc2,dr_mode=host$/dtoverlay=dwc2/' "$BOOT_CONFIG"
161161
NEED_REBOOT=1
162162
fi
163-
if ! grep -qxF "dtoverlay=dwc2" "$BOOT_CONFIG"; then
163+
# Check that dtoverlay=dwc2 exists OUTSIDE CM-specific conditional blocks.
164+
# The default Pi OS image ships dtoverlay=dwc2 inside [cm5]; a naive grep
165+
# would match it there and skip adding it to [all], leaving it ineffective
166+
# on Pi Zero / Zero 2 W.
167+
if ! awk '/^\[cm[0-9]/{skip=1;next} /^\[/{skip=0} !skip && /^dtoverlay=dwc2$/{found=1;exit} END{exit !found}' "$BOOT_CONFIG" 2>/dev/null; then
164168
info "Enabling USB OTG overlay in $BOOT_CONFIG..."
165169
ensure_boot_config_line "dtoverlay=dwc2"
166170
fi
171+
BOOT_CMDLINE="/boot/firmware/cmdline.txt"
172+
[ -f "$BOOT_CMDLINE" ] || BOOT_CMDLINE="/boot/cmdline.txt"
173+
if [ -f "$BOOT_CMDLINE" ] && ! grep -q "modules-load=.*dwc2" "$BOOT_CMDLINE"; then
174+
info "Adding modules-load=dwc2,libcomposite to $BOOT_CMDLINE..."
175+
sudo sed -i 's/$/ modules-load=dwc2,libcomposite/' "$BOOT_CMDLINE"
176+
NEED_REBOOT=1
177+
fi
167178
if ! grep -q "^dwc2$" /etc/modules; then
168179
echo "dwc2" | sudo tee -a /etc/modules >/dev/null
169180
NEED_REBOOT=1

0 commit comments

Comments
 (0)