Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethernet Gadget mode on RPi Zero #216

Closed
Jojo-A opened this issue Dec 19, 2017 · 9 comments

Comments

@Jojo-A
Copy link

commented Dec 19, 2017

Hi,

the ethernet gadget mode seems to be not working properly.

Usecase:
Raspberrymatic is running on a Raspberry Pi Zero, while main home autoamtion system is running on another system (host).
To simplify the setup, I'd like to connect the RPiZ to the host via USB to provide both power and share the network/internet connection of the host to the RPiZ. In this scenario, the RpiZ needs to be detected as a USB network device by the host.

I modified the config.txt file to load the corresponding device tree overlay, as well as the boot command to load the corresponding driver modules according to various tutorials.

After these changes, the RPi should show up as a USB ethernet device, when plugged in into another host system. But it doesn't.

Problem: I can not debug this by myself, because the RPiZ has only one USB port, which needs to be used exclusively for ethernet (via USB). So I can not connect any input devices without cutting the (planned) network connection. But without network connection (via USB), I can not trace down the cause of the problem :( .

Greetings

@jens-maus

This comment has been minimized.

Copy link
Owner

commented Dec 19, 2017

As you correctly identified, Ethernet Gadget mode (see https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/ethernet-gadget) ist currently not supported by RaspberryMatic. In fact, you are the first one requesting it. :) Thus, I will flag this as a feature request but give it somewhat low priority, I am afraid.

@Jojo-A

This comment has been minimized.

Copy link
Author

commented Dec 19, 2017

Hi and thanks a ton for that quick reply!
Actually I am happy to hear, that it is really not supported. Otherwise I would have had to rearch the fault on my side ;) .

I fully understand, that this feature is flagged as "low priority", because nobody else requested it before. Nevertheless I think it will by a very valuable feature, as it opens up a broad range of possible system setups. I could imagine, that there are other people but me out there, who use the RPi (Zero) exclusively for Raspberrymatic, because the RF module is only supported on that platform, while having their main home automation system on another platform. In this case, the wiring setup would be simplified.

In case of the RPi Zero, it would be even more valuable, because there were people (in the past), who had problems with the initial WiFi network setup, because they had no SSH access because the network credentials were not configured, yet. No network, no SSH, no SSH, no way to edit network...
So another enhencement would be, if there would be an option to choose to use the USB normally (for USB-WiFi for example) or to use it as a USB ethernet device.

Long story made short: I understand and accept, that this feature is low prioritized. But maybe it is worth to have a look at how complicated it is to implement it. I have no idea about that. So if you say "no", then it is a "no" :) .

Thank you anyway!

@Jojo-A

This comment has been minimized.

Copy link
Author

commented Dec 21, 2017

Just in case, that you decide not to implement the gadget mode:
would it work OOTB the other way around? If there is another device (like another SBC with g_ether module and USB-OTG port), which provides Ethernet-over-USB as RNDIS-interface, will this be usable by Raspberrymatic as network interface?

Greetings

@fhirschmann

This comment has been minimized.

Copy link
Contributor

commented May 29, 2019

@Jojo-A, have you had any success with this by now? I'm also quite interested in this feature.

@fhirschmann

This comment has been minimized.

Copy link
Contributor

commented May 29, 2019

I just got this to work, but it's slightly involved:

RaspberryMatic setup

  1. Mount the SD card on a Linux machine
  2. Download dwc2.dtbo to bootfs/overlays/ on the sd card. I grabbed this during the compilation of RaspberryMatic.
  3. Add dtoverlay=dwc2 to bootfs/config.txt on the sd card
  4. Paste the following into rootfs/etc/init.d/S01USBGadget on the sd card
#!/bin/sh
#
# Enable USB Gadget mode
#

case "$1" in
  start)
    if grep -q "^dtoverlay=dwc2" /boot/config.txt; then
      printf "Starting usb gadget mode: "
      /sbin/modprobe dwc2
      /sbin/modprobe g_ether host_addr=00:11:22:33:44:55 dev_addr=00:55:66:77:88:99
      echo "OK"
    fi
    ;;
  stop)
    if grep -q "^dtoverlay=dwc2" /boot/config.txt; then
      printf "Stopping usb gadget mode: "
      /sbin/rmmod g_ether
      /sbin/rmmod dwc2
      echo "OK"
    fi
    ;;
  restart|reload)
    "$0" stop
    "$0" start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac

exit $?
  1. Add the following to rootfs/lib/udev/rules.d/76-netnames.rules
# Rename usb0 to eth0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",ATTR{address}=="00:55:66:77:88:99",ATTR{dev_id}=="0x0", ATTR{type}=="1",KERNEL=="usb*", NAME="eth0"

Host setup

In my use case, I use the pi zero on another home automation linux computer. I wanted the pi zero to be bridged to my home network like any other devices (and thus get an IP from my router's dhcp server). For this, I created a network bridge using netplan and udev:

  1. Adapt this into your /etc/netplan/01-netcfg.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
      dhcp4: no
      dhcp6: no
  bridges:
    br0:
      interfaces: [enp1s0]
      dhcp4: yes
      dhcp6: yes
  1. Add the following udev rule /etc/udev/rules.d/72-raspberrymatic.rules
SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="0525", ATTRS{idProduct}=="a4a2", NAME="enp0ccu", RUN="/bin/bash -c '/sbin/ifconfig enp0ccu up && /sbin/brctl addif br0 enp0ccu'"

As far as adding official support to RaspberryMatic for this, I can imagine that it's easy to add dwc2.dtbo to the RaspberryMatic image. Except for the udev rule, the other changes are only active if the user sets dtoverlay=dwc in config.txt.

@jens-maus

This comment has been minimized.

Copy link
Owner

commented May 30, 2019

Thanks for all these hints and suggestions. Feel free to pack all that into a proper PullRequest and propose it for integration as I would love to integrate gadget mode in one of the next releases.

@fhirschmann fhirschmann referenced this issue Jun 16, 2019
8 of 10 tasks complete

@jens-maus jens-maus added this to the next release milestone Aug 22, 2019

@jens-maus

This comment has been minimized.

Copy link
Owner

commented Aug 22, 2019

Thanks to @fhirschmann USB Ethernet Gadget mode is now available for the Pi Zero (W). Coming up with next upcoming RaspberryMatic release...

@jens-maus jens-maus closed this Aug 22, 2019

@jens-maus

This comment has been minimized.

Copy link
Owner

commented Aug 23, 2019

Hi. As @fhirschmann nicely implemented USB ethernet gadget mode now in RaspberryMatic I would like to ask anyone interested to test it in the latest release candidate version of RaspberryMatic. You can download the rpi0 version from here:

https://cloud.light-speed.de/s/xby5d4B7YFRCxyH

Any feedback is highly appreciated. If no issues are found this version will then be released during the next week.

@fhirschmann

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2019

Awesome! I'm happy to test this out, but I'm currently abroad and unable to test it for the next three weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.