hdtodd
Posts: 37
Joined: Tue Mar 04, 2014 1:53 am

Pi Zero Buster OTG to OSX Mojave setup tips?

Fri Aug 16, 2019 3:46 am

Is OTG USB-Ethernet known by others to work between Buster on the Pi Zero and Mac OSX Mojave? If so, has the setup process changed from Stretch?

I've followed the instructions to set up an OTG USB-Ethernet connection between my Pi Zero-W running Buster and both a 2019 Mac Mini (USB-3 ports) and 2013 Macbook Air (USB-2 ports) but have been unable to make the ssh connection. It appears that the Pi isn't really activating the USB0 device to get an IP address for the connection.

My cmdline.txt is

Code: Select all

dwc_otg.lpm_enable=0 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p3 rootfstype=ext4 elevator=deadline rootwait modules-load=dwc2,g_ether
The end of my config.txt is

Code: Select all

#  Enable OTG ethernet service
dtoverlay=dwc2
I did the

Code: Select all

ssh-keygen -R raspberrypi.local
; I did the

Code: Select all

touch /boot/ssh
I've rebooted the Pi Zero many times now, and ifconfig on the Pi Zero shows

Code: Select all

usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 3e:f4:e1:99:9a:fa  txqueuelen 1000  (Ethernet)
        RX packets 1882  bytes 539169 (526.5 KiB)
        RX errors 0  dropped 320  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
The Mac sees the Pi boot up, creates a RNDIS/Ethernet Gadget, and then reports that it has a self-assigned IP. The Network panel says that the RNDIS gadget is connected, but the status message reads

Code: Select all

RNDIS/Ethernet Gadget has a self-assigned IP address and will not be able to connect to the Internet.
It lists the devices IP as 169.254.217.31.

Attempts to

Code: Select all

ssh raspberrypi.local
from the Mac simply sits. Pings fail.

"dmesg" on the Pi Zero reports:

Code: Select all

[    6.670809] dwc2 20980000.usb: 20980000.usb supply vusb_d not found, using dummy regulator
[    6.670999] dwc2 20980000.usb: Linked as a consumer to regulator.0
[    6.671030] dwc2 20980000.usb: 20980000.usb supply vusb_a not found, using dummy regulator
[    6.893759] dwc2 20980000.usb: dwc2_check_params: Invalid parameter lpm=1
[    6.906120] dwc2 20980000.usb: dwc2_check_params: Invalid parameter lpm_clock_gating=1
[    6.918216] dwc2 20980000.usb: dwc2_check_params: Invalid parameter besl=1
[    6.930363] dwc2 20980000.usb: dwc2_check_params: Invalid parameter hird_threshold_en=1
[    7.037365] dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM
[    7.082794] dwc2 20980000.usb: DWC OTG Controller
[    7.082876] dwc2 20980000.usb: new USB bus registered, assigned bus number 1
[    7.082974] dwc2 20980000.usb: irq 33, io mem 0x20980000
[    7.083922] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 4.19
[    7.083942] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    7.083953] usb usb1: Product: DWC OTG Controller
[    7.083965] usb usb1: Manufacturer: Linux 4.19.58+ dwc2_hsotg
[    7.083974] usb usb1: SerialNumber: 20980000.usb
[    7.105891] hub 1-0:1.0: USB hub found
[    7.106020] hub 1-0:1.0: 1 port detected
[    7.311452] systemd[1]: Reached target Slices.
[    7.379499] using random self ethernet address
[    7.379519] using random host ethernet address
[    7.380714] usb0: HOST MAC 5a:67:6f:f8:97:57
[    7.380814] usb0: MAC 3e:f4:e1:99:9a:fa
[    7.380886] using random self ethernet address
[    7.380901] using random host ethernet address
[    7.381041] g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
[    7.381055] g_ether gadget: g_ether ready
[    7.381076] dwc2 20980000.usb: bound driver g_ether
[    7.519471] systemd[1]: Reached target System Time Synchronized.
[    7.537165] media: Linux media interface: v0.10
[    7.563906] dwc2 20980000.usb: new device is high-speed
[    7.604457] videodev: Linux video capture interface: v2.00
[    7.614751] dwc2 20980000.usb: new address 23
[    7.628064] systemd[1]: Starting Set the console keyboard layout...
[    7.638959] g_ether gadget: high-speed config #1: CDC Ethernet (ECM)
Any hints as to things I've missed would be greatly appreciated!

User avatar
thagrol
Posts: 1903
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi Zero Buster OTG to OSX Mojave setup tips?

Fri Aug 16, 2019 7:12 am

Can't comment on the Mac end as I don't have one.

The default on the Pi end is to use dhcp to get an IP address falling back to a self assigned one if a dhcp server is not found. This is what apears to be ahppening in your case.

Generally speaking, unless the USB host is running a dhcp server or is bridging the USB connection with it's own connection to your lan the pi won't see a dhcp server.

The quick fix is to set static IP addresses for both the Pi end and the Mac end of the USB link. Use a different subnet to the rest of your lan.

The next quickest fix would be to enable bridging on the Mac but I can't advise on how to do that.

However, there is one potential problem: g_ether generates random MAC addresses each time it starts. This may mean your Mac sees it as a new interfeace every time it's connected and may cause problems with dhcp leases leading to a new IP each time too.

See my post here for a workaround to this issue: https://www.raspberrypi.org/forums/view ... 3#p1519479
Attempts to contact me outside of thes forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

hdtodd
Posts: 37
Joined: Tue Mar 04, 2014 1:53 am

Re: [Solution] Pi Zero Buster OTG to OSX Mojave setup tips?

Thu Aug 22, 2019 1:18 am

Thanks, Thagrol: your posting helped me figure it out.

Again, my configuration is OS X Mojave running on a Mac Mini and Buster running on a Pi Zero-w.

To make this work, do all the steps I cited earlier. Make sure you plug the USB mini connector into the data port on the Zero (nearest the HDMI). Then plug into the Mac and let the Zero boot up.

You should end up with a Mac with an RNDIS gadget listed in the "Apple/System Preferences/Network" panel, along with your WiFi and Ethernet connections. Mine has a yellow dot indicating that it has a self-assigned IP address, but that seems not to be a problem.

You need to tell your Mac to share its IP connections with that RNDIS device in order for the Zero to be able to connect through its USB port to the Mac's RNDIS gadget. On your Mac, go to "System Preferences/Sharing", click the "Internet Sharing" box, and share with the RNDIS/Ethernet Gadet.

If you ssh into the WiFi port on your Zero and do a "ifconfig", you'll see a usb0 device but no IP address assigned. To make it work, you have to tell /etc/network/interfaces about it. Here's my interfaces file:

Code: Select all

auto lo
iface lo inet loopback

auto usb0
allow-hotplug usb0
#iface usb0 inet dhcp
iface usb0 inet static
      address 192.168.2.2
      netmask 255.255.255.0
      gateway 192.168.2.1
      network 192.168.2.0

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp
If you edit that usb0 device information into the "interfaces" file, then do a "sudo ifup usb0", check with an "ifconfig" and you should see that the usb0 device now has an IP address. And you'll be
able to "ssh 192.168.2.2" into your Zero over the USB port. The configuration in my example "interfaces" file assigns a static address of 192.168.2.2 to the USB network interface rather than using DHCP. DHCP works, but the MAC address changes on every reboot, and the IP address assigned then changes for every reboot, too. Rather than guess what the next IP address is, I just assigned a static address. I haven't been able to get "ssh raspberrypi.local" to work ... doesn't know that host name from the Mac side. But it's not all that important as I can list it in my Mac's /etc/hosts file now that I've assigned it a static IP.

Again, the DHCP option works (comment out the static assignment and addresses following it), so give that a try if it's important to you ... but you'll need to figure out how to get the Mac to know what IP address raspberrypi.local is using in that case. If you figure it out, please post. :-)

I haven't tried any of the other possible connection options for OTG, since the SSH connection seemed the most useful. But having gotten this one to work, I'm hopeful that some of the other options might work, too.

Thanks, again, Thagrol

David

hdtodd
Posts: 37
Joined: Tue Mar 04, 2014 1:53 am

Re: Pi Zero Buster OTG to OSX Mojave setup tips?

Thu Aug 22, 2019 2:44 pm

Ah, one small wrinkle. With the "interfaces" above, if you boot without the OTG connection, it boots fine but the Pi Zero can't get out to the rest of the world because 192.168.2.1 isn't connected. I thought the syntax was that the gateway spec would apply only to the usb0 interface, but it apparently doesn't.

The following does work, ssh into wlan0 or usb0 if OTG is connected, ssh into wlan0 if OTG is not connected, but in either case, the Pi Zero sees the rest of the world over the Internet (if at least your WiFi is connected):

Code: Select all

auto lo
iface lo inet loopback

auto usb0
allow-hotplug usb0
#iface usb0 inet dhcp
iface usb0 inet static
      address 192.168.2.2

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp
If your USB power input is NOT connected from your Mac to the OTG port and you log in to the Zero via WiFi, you'll still see the usb0 device assigned to 192.168.2.2 when you do an ifconfig, but there's nothing on the other end of that connection.

User avatar
thagrol
Posts: 1903
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi Zero Buster OTG to OSX Mojave setup tips?

Thu Aug 22, 2019 10:23 pm

hdtodd wrote:
Thu Aug 22, 2019 2:44 pm
If your USB power input is NOT connected from your Mac to the OTG port and you log in to the Zero via WiFi, you'll still see the usb0 device assigned to 192.168.2.2 when you do an ifconfig, but there's nothing on the other end of that connection.
Yeah, that's expected behaviour. The usb0 (Pi's end of the link) will show up when the module is loaded regardless of whether the other end is present or not.

Incidentally, you should be able to connect to your Pi over wifi even if the USB link is connected. Just use the IP address of the wifi interface rather than the Pi's hostname.

Another thing: just because the USB link defines which machine is the host (your Mac) and slave (your Pi) that doesn't mean you can't run servers on the zero and use the Mac as a client for said servers. For a while I had a 4B acting as a USB ethernet device to a 1B (1B host, USB C port on 4B as slave) but with the 4B acting as a bridge to the rest of my LAN for the 1B.

Lastly, did you make any changes to /etc/dhcpcd.conf? Or remove dhcpcd? I'd expect any thing in/etc/network/interfaces to conflict and/or be ignored if you haven't. Could easily be wrong about this though.
Attempts to contact me outside of thes forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

hdtodd
Posts: 37
Joined: Tue Mar 04, 2014 1:53 am

Re: Pi Zero Buster OTG to OSX Mojave setup tips?

Thu Aug 22, 2019 10:58 pm

Incidentally, you should be able to connect to your Pi over wifi even if the USB link is connected. Just use the IP address of the wifi interface rather than the Pi's hostname.
Yes, it was convenient to be able to log in via WiFi to fix the usb0 configuration settings, even though the usb0 port wasn't functioning correctly, then "ifup usb0" to test it. The problem occurred with static IP assignment to usb0 when I *didn't* have the OTG connection up: the gateway spec was still in effect, and I could get in via WiFi but couldn't get out (to do "apt-get update" for example); that's when I realized that the gateway assignment wasn't specific to the usb0 device. Syntactically I thought it would be (as the IP address is). But maybe I just had something else wrong. Anyway, removing the gateway assignment gave the behavior I was looking for: WiFi works whether or not OTG is up, and if OTG is up, I can ssh in through the USB port.
Lastly, did you make any changes to /etc/dhcpcd.conf? Or remove dhcpcd? I'd expect any thing in/etc/network/interfaces to conflict and/or be ignored if you haven't. Could easily be wrong about this though.
I disabled dhcpd services through systemctl. It was interfering with my efforts to configure networking the way I wanted it.

Return to “Troubleshooting”