From e6a0556147a62b18a81237024c9d8c5278a7ed31 Mon Sep 17 00:00:00 2001 From: Joe Foley Date: Fri, 4 Sep 2026 10:01:40 +0000 Subject: [PATCH] Check for GADGET_MODE in boot/firmware to enable --- Scripts/gadget.sh | 7 ++++++ gadget.md | 54 ++++++++++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/Scripts/gadget.sh b/Scripts/gadget.sh index 719aa08..de1e432 100755 --- a/Scripts/gadget.sh +++ b/Scripts/gadget.sh @@ -9,6 +9,13 @@ if [ $(id -u) -ne 0 ]; then exit 1 fi +if [ -f /boot/firmware/GADGET_MODE ]; then + systemd-cat -t gadget.sh -p info echo "/boot/firmware/GADGET_MODE exists: GADGET mode enabled" +else + systemd-cat -t gadget.sh -p warning echo "/boot/firmware/GADGET_MODE missing: GADGET mode disabled" + systemctl disable serial-getty@ttyGS0.service + exit 1 +fi # Is the dwc2 overlay installed? Nothing will work if it isn't. if [ -d /sys/class/udc ] && [ -n "$(ls -A /sys/class/udc)" ]; then diff --git a/gadget.md b/gadget.md index 2b46559..d36483b 100644 --- a/gadget.md +++ b/gadget.md @@ -18,14 +18,6 @@ Make sure you have your USB cable plugged into the left port **USB** and not the ``` sudo su ``` -1. Enable the DWC version 2 USB peripheral device tree overlay by appending it to the end after the `[all]` category (which is at the end) -``` -echo "dtoverlay=dwc2" >> /boot/firmware/config.txt -``` -1. We add the required module `dwc2` for loading at startup -``` -echo "dwc2" >> /etc/modules -``` 1. Check that we can load the libcomposite module ``` modprobe libcomposite @@ -94,7 +86,38 @@ This is similar to the procedure for accessing an Arduino. ``` 1. Press enter and you will be prompted to log in to the Pi with default credentials. User: pi - PW: raspberry -# Disabling the OTG mode to use a keyboard and mouse again +# Enabling/Disabling the OTG mode to use a keyboard and mouse again + +**WARNING: Untested** +1. Disable: Delete a file called `GADGET_MODE` in the boot partition/drive when not on a pi. If the Pi is booted, you can delete `sudo rm /boot/firmware/GADGET_MODE` and reboot +1. Enable: create a file called `GADGET_MODE` in the boot partition/drive when not on a pi. If the Pi is booted, you can create `sudo touch /boot/firmware/GADGET_MODE` and reboot + +# Connecting over the USB ethernet to ssh into your Pi + +I have not tested this procedure because the serial console and normal network connection is sufficient for me --foley + +https://www.raspberrypi.com/news/usb-gadget-mode-in-raspberry-pi-os-ssh-over-usb/ + + +# Untested + Here are items that bear investigating but haven't been tested yet + + - [Modify Imager manifest to install otg](https://github.com/raspberrypi/rpi-imager/tree/main/doc/local_json) + +# Old DWC Instructions (for older versions) + +## Setting up +1. Enable the DWC version 2 USB peripheral device tree overlay by appending it to the end after the `[all]` category (which is at the end) +``` +echo "dtoverlay=dwc2" >> /boot/firmware/config.txt +``` +1. We add the required module `dwc2` for loading at startup +``` +echo "dwc2" >> /etc/modules +``` + + +## Disabling the OTG mode to use a keyboard and mouse again **WARNING: Untested** 1. Comment out the dwg2 line in `/boot/firmware/config.txt` using a `#` in front of the line @@ -114,16 +137,3 @@ This is similar to the procedure for accessing an Arduino. ``` systemctl disable serial-getty@ttyGS0.service ``` - -# Connecting over the USB ethernet to ssh into your Pi - -I have not tested this procedure because the serial console and normal network connection is sufficient for me --foley - -https://www.raspberrypi.com/news/usb-gadget-mode-in-raspberry-pi-os-ssh-over-usb/ - - -# Untested - Here are items that bear investigating but haven't been tested yet - - - [Modify Imager manifest to install otg](https://github.com/raspberrypi/rpi-imager/tree/main/doc/local_json) -