kmpm / rpi-usb-gadget

Script to set up a Raspberry PI 4 as a USB gadget.
103 stars 28 forks source link

Missing line in usb0 interface settings #9

Closed martinmCGG closed 4 months ago

martinmCGG commented 4 months ago

On RPi4 model B and a fresh raspios (2024-03-15-raspios-bookworm-arm64-lite.img.xz), after running the script ('y' on all prompts, default IP and choosing '2) ECM Network device type') and restarting, I get the following error:

$ systemctl status networking.service 
× networking.service - Raise network interfaces
     Loaded: loaded (/lib/systemd/system/networking.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Tue 2024-05-21 16:22:14 CEST; 2min 48s ago
       Docs: man:interfaces(5)
    Process: 499 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
    Process: 601 ExecStopPost=/usr/bin/touch /run/network/restart-hotplug (code=exited, status=0/SUCCESS)
   Main PID: 499 (code=exited, status=1/FAILURE)
        CPU: 131ms

May 21 16:22:14 raspberrypi systemd[1]: Starting networking.service - Raise network interfaces...
May 21 16:22:14 raspberrypi ifup[499]: ifup: /etc/network/interfaces.d/usb0:3: misplaced option
May 21 16:22:14 raspberrypi ifup[499]: ifup: unknown interface usb0
May 21 16:22:14 raspberrypi systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
May 21 16:22:14 raspberrypi systemd[1]: networking.service: Failed with result 'exit-code'.
May 21 16:22:14 raspberrypi systemd[1]: Failed to start networking.service - Raise network interfaces.

The reason is an invalid generated interface config for usb0:

$ cat /etc/network/interfaces.d/usb0
auto usb0
allow-hotplug usb0
  address 10.55.0.1
  netmask 255.255.255.248

It misses a line that says the interface should use a static IP address. After adding it, and a power cycle, the USB connection started working.

$ cat /etc/network/interfaces.d/usb0
auto usb0
allow-hotplug usb0
iface usb0 inet static
  address 10.55.0.1
  netmask 255.255.255.248

The interface config seems to be generated here: https://github.com/kmpm/rpi-usb-gadget/blob/596892fdbc1b3934e9f906c1a4955933d07dcf11/rpi4-usb.sh#L188 Adding the missing line should fix that.

Also "otg_mode=1" may need to be disabled in config.txt. (I did that during debugging and did not verify if it's necessary, and perhaps that relates only to the compute module 4 so it's not relevant)

metriics commented 4 months ago

This same issue occurs when specifying a custom subnet and selecting RNDIS.

I added the line mentioned by @martinmCGG (thanks, good catch!) to my interfaces file, rebooted and it is now working.

Edit: I created a pull request to fix the issue, see #10