teknomanzer
Posts: 7
Joined: Tue May 28, 2019 8:42 am

Buildroot Pi Zero Ethernet Gadget issues

Tue May 28, 2019 9:02 am

Hi,

I'm setting up a pi zero w as an ethernet gadget with a custom Buildroot distribution and I'm having some weird issues.

My config.txt:
dtoverlay=dwc2

My cmdline.txt:
vt.global_cursor_default=0 root=/dev/mmcblk0p2 rootfstype=ext4 console=tty1 fsck.repair=yes rootwait modules-load=dwc2,g_ether

My /etc/network/interfaces:
auto lo
iface lo inet loopback

auto usb0
iface usb0 inet static
address 192.168.7.2
netmask 255.255.255.0
network 192.168.7.0
broadcast 192.168.7.255
gateway 192.168.7.1

The first issue is that the modules-load from the command line seems to be ignored, the modules are not getting loaded. Therefore when connecting through usb to a computer, nothing happens.
After enabling Wifi and connecting through ssh, loading the modules manually with modprobe dwc2 g_ether and bringing up the interface with ifup usb0, it shows up on the computer.

So I created a new script in etc/init.d:
#!/bin/sh

start() {
echo "Starting ethernet gadget..."
modprobe dwc2
modprobe g_ether
echo "Ethernet gadget started."
}

stop() {
echo "Stopping ethernet gadget..."
modprobe -r dwc2
modprobe -r g_ether
echo "Ethernet gadget stopped."
}

restart() {
stop
start
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

I setup the static ip in the computer to 192.168.7.1 and I can ping the pi without a problem.
However, when I try to ssh to the usb0 ip, it won't connect and after that, pinging will time out.

As far as Buildroot, I'm using kernel 4.9 with kernel configuration bcmrpi and for the device tree bcm2708-rpi-0-w.

Any help would be much appreciated!

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2279
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Buildroot Pi Zero Ethernet Gadget issues

Tue May 28, 2019 9:52 am

Merely loading the dwc2 module isn't enough - the kernel doesn't know what to do with it. Instead, use Device Tree to declare which address range and interrupt the driver should use by adding the following to config.txt:

Code: Select all

dtoverlay=dwc2,dr_mode=peripheral
You should then be able to remove the explicit loading of the dwc2 module, leaving a command line of:

Code: Select all

vt.global_cursor_default=0 root=/dev/mmcblk0p2 rootfstype=ext4 console=tty1 fsck.repair=yes rootwait modules-load=g_ether

teknomanzer
Posts: 7
Joined: Tue May 28, 2019 8:42 am

Re: Buildroot Pi Zero Ethernet Gadget issues

Tue May 28, 2019 8:20 pm

Thanks Phil. I'll give it a try tonight!

teknomanzer
Posts: 7
Joined: Tue May 28, 2019 8:42 am

Re: Buildroot Pi Zero Ethernet Gadget issues

Tue May 28, 2019 10:01 pm

PhilE, Do you know why with Raspbian Stretch or Stretch lite, the settings I provided just work?
Whats different? I suppose the Stretch is also using the "bcmrpi" configuration which defaults to "Dual Role Mode".
Is the stretch setting the peripheral model somewhere else in the boot sequence?

Thanks.
R.

incognitum
Posts: 300
Joined: Tue Oct 30, 2018 3:34 pm

Re: Buildroot Pi Zero Ethernet Gadget issues

Wed May 29, 2019 6:14 am

teknomanzer wrote:
Tue May 28, 2019 9:02 am
The first issue is that the modules-load from the command line seems to be ignored, the modules are not getting loaded.
modules-load is not a real command line option supported by the kernel.
It is interpreted by systemd instead.
So if you selected a different init system in buildroot, that option will indeed not load your g_ether.

dwc2 should still be loaded automatically due to the config.txt option, provided you do are using a program like eudev for device management (instead of the "use only devtmpfs" option in buildroot).
As far as Buildroot, I'm using kernel 4.9
I am assuming you mean 4.19?

teknomanzer
Posts: 7
Joined: Tue May 28, 2019 8:42 am

Re: Buildroot Pi Zero Ethernet Gadget issues

Wed May 29, 2019 9:54 am

Imodules-load is not a real command line option supported by the kernel.
It is interpreted by systemd instead.
So if you selected a different init system in buildroot, that option will indeed not load your g_ether.
Thank you! I didn't know. I am indeed not using systems but busybox init.
That would explain why the command is making no difference.

I am using dev in Buildroot and dwc2 seems to be loaded.

PhilE, I tried your suggestion and still, no luck. However based on incognito's point above it would make sense.

I'm gonna try a combination of both, using my own init script to load g_ether and using dr_mode=peripheral.

Thank you both.

teknomanzer
Posts: 7
Joined: Tue May 28, 2019 8:42 am

Re: Buildroot Pi Zero Ethernet Gadget issues

Wed May 29, 2019 9:57 am

So I removed modules-load=g_ether from the cmdline.txt
Added back my S02ethernet_gadget init script which does a modprobe g_ether
Added dtoverlay=dwc2,dr_mode=peripheral to the config.txt

Unfortunately I get the same result.
RNDIS connection pops up on Mac just fine, I can connect to it, I can ping the ip from the console.
As soon as I try to ssh, it fails. Then I try to ping again and the ping times out.

Firewall is off on the Mac.

I've tried it on a PC with Windows 10. RNDIS Network connection appears.
I setup ip: 192.168.7.1, Mask: 255.255.255.0, Gateway: 192.168.7.1
Pinging 192.168.7.2 returns a "host unreachable"
Also the firewall is off.

This is driving me a little crazy, I don't know what else to do.
Last edited by teknomanzer on Wed May 29, 2019 10:28 am, edited 2 times in total.

teknomanzer
Posts: 7
Joined: Tue May 28, 2019 8:42 am

Re: Buildroot Pi Zero Ethernet Gadget issues

Wed May 29, 2019 9:59 am

Here is my entire config.txt for completion:

Code: Select all

########################################################
### MAXDASH CONFIG
########################################################

### General
disable_splash=1
boot_delay=0

### Kernel
kernel=zImage

### Memory
gpu_mem_256=128
gpu_mem_512=196
gpu_mem_1024=384

### Overclock
arm_freq=1000
gpu_freq=500
sdram_freq=500
over_voltage=6
dtoverlay=sdtweak,overclock_50=80

### Display

## Adafruit 5 inch Kippah
# Disable spi and i2c, we need these pins.
dtparam=spi=off
dtparam=i2c_arm=off

# Set screen size and any overscan required
overscan_left=0
overscan_right=0
overscan_top=0
overscan_bottom=0
framebuffer_width=800
framebuffer_height=480

# enable the DPI display
enable_dpi_lcd=1
display_default_lcd=1

# set up the size to 800x480
dpi_group=2
dpi_mode=87

# set up the hsync/vsync/clock polarity and format
dpi_output_format=454661

# set up the size to 800x480
hdmi_timings=800 0 40 48 88 480 0 13 3 32 0 0 0 60 0 32000000 6

### Device Tree
dtoverlay=dwc2,dr_mode=peripheral

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

Re: Buildroot Pi Zero Ethernet Gadget issues

Wed May 29, 2019 11:50 am

You could try the libcomposite method.

Have a look at the source code for the RPF's gpioexpander project: https://github.com/raspberrypi/gpioexpander
This space unintentionally left blank.

teknomanzer
Posts: 7
Joined: Tue May 28, 2019 8:42 am

Re: Buildroot Pi Zero Ethernet Gadget issues

Thu May 30, 2019 12:37 am

thagrol, thanks for the link.
I'd like to keep it simple. I'd like to understand why this works on a Stretch lite and not on a Buildroot. What's missing and how to set it up.
I think it's close, the driver is loaded and the computer recognizes the gadget and creates the RNDIS connection.

Here is a dmesg dump if that's useful to anyone.

Code: Select all

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.9.80 ([email protected]) (gcc version 5.4.0 (Buildroot 2017.05-git-g3153d33-dirty) ) #1 Wed May 29 12:54:39 PDT 2019
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] OF: fdt:Machine model: Raspberry Pi Zero W Rev 1.1
[    0.000000] cma: Reserved 8 MiB at 0x13000000
[    0.000000] Memory policy: Data cache writeback
[    0.000000] On node 0 totalpages: 80896
[    0.000000] free_area_init_node: node 0, pgdat c09291cc, node_mem_map d3924c00
[    0.000000]   Normal zone: 711 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 80896 pages, LIFO batch:15
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0 
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 80185
[    0.000000] Kernel command line: 8250.nr_uarts=0 bcm2708_fb.fbwidth=800 bcm2708_fb.fbheight=480 bcm2708_fb.fbswap=1 smsc95xx.macaddr=B8:27:EB:9B:17:AB vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  vt.global_cursor_default=0 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline console=tty1 rootwait
[    0.000000] PID hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
[    0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Memory: 301884K/323584K available (6017K kernel code, 492K rwdata, 1968K rodata, 388K init, 725K bss, 13508K reserved, 8192K cma-reserved)
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
[    0.000000]     vmalloc : 0xd4000000 - 0xff800000   ( 696 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xd3c00000   ( 316 MB)
[    0.000000]     modules : 0xbf000000 - 0xc0000000   (  16 MB)
[    0.000000]       .text : 0xc0008000 - 0xc05e882c   (6019 kB)
[    0.000000]       .init : 0xc0857000 - 0xc08b8000   ( 388 kB)
[    0.000000]       .data : 0xc08b8000 - 0xc0933338   ( 493 kB)
[    0.000000]        .bss : 0xc0933338 - 0xc09e8960   ( 726 kB)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS:16 nr_irqs:16 16
[    0.000029] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 2147483647500ns
[    0.000074] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
[    0.000172] bcm2835: system timer (irq = 27)
[    0.000647] Console: colour dummy device 80x30
[    0.001390] console [tty1] enabled
[    0.001447] Calibrating delay loop... 697.95 BogoMIPS (lpj=3489792)
[    0.060353] pid_max: default: 32768 minimum: 301
[    0.060823] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.060898] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.062178] Disabling memory control group subsystem
[    0.062388] CPU: Testing write buffer coherency: ok
[    0.062492] ftrace: allocating 21834 entries in 65 pages
[    0.180862] Setting up static identity map for 0x8200 - 0x8238
[    0.182910] devtmpfs: initialized
[    0.192474] VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5
[    0.192984] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.193081] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.194421] pinctrl core: initialized pinctrl subsystem
[    0.195928] NET: Registered protocol family 16
[    0.198438] DMA: preallocated 1024 KiB pool for atomic coherent allocations
[    0.208573] hw-breakpoint: found 6 breakpoint and 1 watchpoint registers.
[    0.208666] hw-breakpoint: maximum watchpoint size is 4 bytes.
[    0.208809] Serial: AMBA PL011 UART driver
[    0.211850] bcm2835-mbox 2000b880.mailbox: mailbox enabled
[    0.212633] uart-pl011 20201000.serial: could not find pctldev for node /soc/[email protected]/uart0_pins, deferring probe
[    0.262452] bcm2835-dma 20007000.dma: DMA legacy API manager at d400d000, dmachans=0x1
[    0.265241] SCSI subsystem initialized
[    0.265805] usbcore: registered new interface driver usbfs
[    0.265979] usbcore: registered new interface driver hub
[    0.266214] usbcore: registered new device driver usb
[    0.270921] raspberrypi-firmware soc:firmware: Attached to firmware from 2018-09-10 17:26
[    0.272800] clocksource: Switched to clocksource timer
[    0.329238] VFS: Disk quotas dquot_6.6.0
[    0.329436] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    0.329793] FS-Cache: Loaded
[    0.330186] CacheFiles: Loaded
[    0.350096] NET: Registered protocol family 2
[    0.351546] TCP established hash table entries: 4096 (order: 2, 16384 bytes)
[    0.351704] TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
[    0.351836] TCP: Hash tables configured (established 4096 bind 4096)
[    0.351964] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.352031] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.352374] NET: Registered protocol family 1
[    0.353289] RPC: Registered named UNIX socket transport module.
[    0.353369] RPC: Registered udp transport module.
[    0.353410] RPC: Registered tcp transport module.
[    0.353447] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.354548] hw perfevents: enabled with armv6_1176 PMU driver, 3 counters available
[    0.357097] workingset: timestamp_bits=14 max_order=17 bucket_order=3
[    0.377405] FS-Cache: Netfs 'nfs' registered for caching
[    0.379224] NFS: Registering the id_resolver key type
[    0.379337] Key type id_resolver registered
[    0.379381] Key type id_legacy registered
[    0.383939] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)
[    0.384407] io scheduler noop registered
[    0.384473] io scheduler deadline registered (default)
[    0.384986] io scheduler cfq registered
[    0.391007] BCM2708FB: allocated DMA memory 53100000
[    0.391139] BCM2708FB: allocated DMA channel 0 @ d400d000
[    0.401643] Console: switching to colour frame buffer device 100x30
[    0.414576] bcm2835-rng 20104000.rng: hwrng registered
[    0.418044] vc-mem: phys_addr:0x00000000 mem_base=0x1ec00000 mem_size:0x20000000(512 MiB)
[    0.422394] vc-sm: Videocore shared memory driver
[    0.450803] brd: module loaded
[    0.466825] loop: module loaded
[    0.470075] Loading iSCSI transport class v2.0-870.
[    0.474631] libphy: Fixed MDIO Bus: probed
[    0.478047] usbcore: registered new interface driver lan78xx
[    0.481498] usbcore: registered new interface driver smsc95xx
[    0.484868] dwc_otg: version 3.00a 10-AUG-2012 (platform bus)
[    0.488321] dwc_otg: FIQ enabled
[    0.488328] dwc_otg: NAK holdoff enabled
[    0.488334] dwc_otg: FIQ split-transaction FSM enabled
[    0.488352] Module dwc_common_port init
[    0.488796] usbcore: registered new interface driver usb-storage
[    0.492513] mousedev: PS/2 mouse device common for all mice
[    0.497431] bcm2835-wdt 20100000.watchdog: Broadcom BCM2835 watchdog timer
[    0.501188] bcm2835-cpufreq: min=700000 max=1000000
[    0.505119] sdhci: Secure Digital Host Controller Interface driver
[    0.508354] sdhci: Copyright(c) Pierre Ossman
[    0.512084] sdhost-bcm2835 20202000.sdhost: could not get clk, deferring probe
[    0.518055] mmc-bcm2835 20300000.mmc: could not get clk, deferring probe
[    0.521587] sdhci-pltfm: SDHCI platform and OF driver helper
[    0.525509] ledtrig-cpu: registered to indicate activity on CPUs
[    0.529065] hidraw: raw HID events driver (C) Jiri Kosina
[    0.532746] usbcore: registered new interface driver usbhid
[    0.536253] usbhid: USB HID core driver
[    0.540909] vchiq: vchiq_init_state: slot_zero = 0xd3180000, is_master = 0
[    0.546539] [vc_sm_connected_init]: start
[    0.557181] [vc_sm_connected_init]: end - returning 0
[    0.561214] Initializing XFRM netlink socket
[    0.564648] NET: Registered protocol family 17
[    0.568057] Key type dns_resolver registered
[    0.573161] registered taskstats version 1
[    0.585790] uart-pl011 20201000.serial: cts_event_workaround enabled
[    0.589361] 20201000.serial: ttyAMA0 at MMIO 0x20201000 (irq = 81, base_baud = 0) is a PL011 rev2
[    0.595416] sdhost: log_buf @ d3110000 (53110000)
[    0.672876] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1)
[    0.679105] mmc-bcm2835 20300000.mmc: mmc_debug:0 mmc_debug2:0
[    0.682753] mmc-bcm2835 20300000.mmc: DMA channel allocated
[    0.718345] random: fast init done
[    0.760482] mmc0: host does not support reading read-only switch, assuming write-enable
[    0.764341] of_cfs_init
[    0.767994] of_cfs_init: OK
[    0.772303] Waiting for root device /dev/mmcblk0p2...
[    0.782189] mmc0: overclocking to 71428571Hz
[    0.788015] mmc0: new high speed SDHC card at address 59b4
[    0.794119] mmcblk0: mmc0:59b4 00000 14.9 GiB
[    0.800093]  mmcblk0: p1 p2
[    0.809968] mmc1: queuing unknown CIS tuple 0x80 (2 bytes)
[    0.815126] mmc1: queuing unknown CIS tuple 0x80 (3 bytes)
[    0.820070] mmc1: queuing unknown CIS tuple 0x80 (3 bytes)
[    0.826271] mmc1: queuing unknown CIS tuple 0x80 (7 bytes)
[    0.900969] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[    0.904474] VFS: Mounted root (ext4 filesystem) readonly on device 179:2.
[    0.911604] devtmpfs: mounted
[    0.916310] Freeing unused kernel memory: 388K
[    0.919503] This architecture does not have kernel memory protection.
[    0.955490] mmc1: new high speed SDIO card at address 0001
[    1.189414] EXT4-fs (mmcblk0p2): re-mounted. Opts: errors=remount-ro,data=ordered
[    1.251553] FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
[    1.429120] udc-core: couldn't find an available UDC - added [g_ether] to list of pending drivers
[    1.525346] udevd[89]: starting version 3.2.1
[    1.636364] udevd[90]: starting eudev-3.2.1
[    2.177898] gpiomem-bcm2835 20200000.gpiomem: Initialised: Registers at 0x20200000
[    2.391866] 20980000.usb supply vusb_d not found, using dummy regulator
[    2.438358] 20980000.usb supply vusb_a not found, using dummy regulator
[    2.542975] dwc2 20980000.usb: 256 invalid for host_nperio_tx_fifo_size. Check HW configuration.
[    2.547165] dwc2 20980000.usb: 512 invalid for host_perio_tx_fifo_size. Check HW configuration.
[    2.588164] dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM
[    2.742394] brcmfmac: F1 signature read @0x18000000=0x1541a9a6
[    2.761583] usbcore: registered new interface driver brcmfmac
[    2.870570] using random self ethernet address
[    2.874547] using random host ethernet address
[    2.888479] usb0: HOST MAC d6:36:3a:96:59:47
[    2.892461] usb0: MAC d6:bf:bb:81:8c:23
[    2.939479] using random self ethernet address
[    2.943538] using random host ethernet address
[    2.968741] g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
[    2.972580] g_ether gadget: g_ether ready
[    3.007225] dwc2 20980000.usb: bound driver g_ether
[    3.100376] brcmfmac: Firmware version = wl0: Oct 23 2017 03:55:53 version 7.45.98.38 (r674442 CY) FWID 01-e58d219f
[    3.118771] brcmfmac: brcmf_c_preinit_dcmds: CLM version = API: 12.2 Data: 7.11.15 Compiler: 1.24.2 ClmImport: 1.24.1 Creation: 2014-05-26 10:53:55 Inc Data: 9.10.39 Inc Compiler: 1.29.4 Inc ClmImport: 1.36.3 Creation: 2017-10-23 03:47:14 
[    3.268910] dwc2 20980000.usb: new device is high-speed
[    3.324163] dwc2 20980000.usb: new device is high-speed
[    3.345315] dwc2 20980000.usb: new address 12
[    3.419307] g_ether gadget: high-speed config #1: CDC Ethernet (ECM)
[    4.284616] NET: Registered protocol family 10

incognitum
Posts: 300
Joined: Tue Oct 30, 2018 3:34 pm

Re: Buildroot Pi Zero Ethernet Gadget issues

Fri May 31, 2019 12:25 pm

teknomanzer wrote:
Thu May 30, 2019 12:37 am
I think it's close, the driver is loaded and the computer recognizes the gadget and creates the RNDIS connection.
It is not using RNDIS but ECM.
(Should not be a problem if the host computer is running Linux though)

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

Re: Buildroot Pi Zero Ethernet Gadget issues

Fri May 31, 2019 3:42 pm

incognitum wrote:
Fri May 31, 2019 12:25 pm
teknomanzer wrote:
Thu May 30, 2019 12:37 am
I think it's close, the driver is loaded and the computer recognizes the gadget and creates the RNDIS connection.
It is not using RNDIS but ECM.
(Should not be a problem if the host computer is running Linux though)
Don't be too sure about that. The OP wasn't clear which end of the link that log was from (zero or host) and in my experience g_ether will enumerate as ECM to the zero and to linux hosts but RNDIS to windows hosts.

Dmesg output on the zero is going to tell us very little about what the host is seeing, likewise dmesg output on the host tells us very little about the Pi's end.
This space unintentionally left blank.

Return to “Device Tree”