WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Pi Zero as USB Gadget  (Read 2730 times)

Offline PingPing

  • Jr. Member
  • **
  • Posts: 99
Pi Zero as USB Gadget
« on: September 11, 2018, 01:36:50 AM »
I'm having problems trying to communicate with a Raspberry Pi Zero attached to my Windows10 over USB a.k.a. 'USB gadget'. 
Although I can get it to work with Raspian, for some reason, I can't get it to work with Tiny Core linux.
I've read the forums here and followed them as best as I could understand them.
I was hoping someone could help me by pointing out what I'm doing wrong.

Here are the steps I took:

I downloaded the modules package, extracted the 'usb/dwc2' and 'usb/gadget' directories to /tmp, created a .tcz package from them, installed it, loaded the 'dwc2' and 'g_ether' modules, ran 'depmod', cleaned up /home/tc, backed up with 'filetool.sh' and, finally, updated onboot.lst to load the modules package on reboot:

Code: [Select]
$ wget http://tinycorelinux.net/9.x/armv6/releases/RPi/src/kernel/4.9.22-piCore_modules.tar.xz
$ tar -xJf 4.9.22-piCore_modules.tar.xz
$ mkdir -p /tmp/package/usr/local/lib/modules/4.9.22-piCore/kernel/drivers/usb
$ mv lib/modules/4.9.22-piCore/kernel/drivers/usb/dwc2 /tmp/package/usr/local/lib/modules/4.9.22-piCore/kernel/drivers/usb/
$ mv lib/modules/4.9.22-piCore/kernel/drivers/usb/gadget /tmp/package/usr/local/lib/modules/4.9.22-piCore/kernel/drivers/usb/
$ tce-load -wil squashfs-tools.tcz
$ mksquashfs /tmp/package/ usb-gadget-4.9.22-piCore.tz
$ mv usb-gadget-4.9.22-piCore.tz /mnt/mmcblk0p2/tce/optional/
$ tce-load -i usb-gadget-4.9.22-piCore.tcz
$ sudo modprobe dwc2
$ sudo modprobe g_ether
$ lsmod
$ sudo depmod
$ rm -rf /tmp/package
$ rm -rf lib
$ rm -f 4.9.22-piCore_modules.tar.xz
$ filetool.sh -b
$ echo usb-gadget-4.9.22-piCore.tcz >> /mnt/mmcblk0p2/tce/onboot.lst

I then mounted partition 1, amended the config.txt file for dtoverlay, added a line in bootlocal.sh to ensure the 'g_ether' module is loaded at boot, and rebooted:

Code: [Select]
$ sudo mount /dev/mmcblk0p1 /mnt/mmcblk0p1
$ echo "" | sudo tee -a /mnt/mmcblk0p1/config.txt > /dev/null
$ echo [PI0] | sudo tee -a /mnt/mmcblk0p1/config.txt > /dev/null
$ echo dtoverlay=dwc2 | sudo tee -a /mnt/mmcblk0p1/config.txt > /dev/null
$ echo /sbin/modprobe g_ether >> /opt/bootlocal.sh
$ filetool.sh -b
$ sudo exitcheck.sh reboot

This time, both 'dwc2' and 'g_ether' had loaded, so I shutdown, attached my Raspberry Pi Zero to my Windows10 laptop via usb cable and, using PuTTY (with 'box.local' as the hostname), tried to ssh into it.
I watched the 'Network Connections' folder in Windows10 and, a short while after the the Pi Zero had begun to boot, it showed up as 'Ethernet 3' with 'USB Ethernet/RNDIS Gadget' and, er, 'Network Cable Unplugged'.
So I added a line in bootlocal.sh to ensure the usb interface came up:

Code: [Select]
$ echo /sbin/ifconfig usb0 up >> /opt/bootlocal.sh
$ filetool.sh -b
$ sudo exitcheck.sh reboot

This changed the Windows10 Network Configuration description from 'Network Cable Unplugged' to 'Identifying...' and then to 'Unidentified Network'.
Right-click > Status > Details > shows the 'Autoconfiguration IPv4 Address' has a value of 169.254.135.39.
If I try and PuTTY into this IP address I get the response 'Network error: Connection refused'.
I can ping it.  I just can't ssh into it.

As I stated at the opening, I have successfully run the RaspberryPiZero-USB-gadget thing under Raspian (following the various blog posts on the internet), so I know the Windows10 configuration I have is working. 
I'm guessing my problem is TinyCore-side - I just don't know what it is.

If someone has successfully managed to set up their Raspberry Pi Zero as a USB gadget using Tiny Core Linux and Windows10, please could they help me out and point out what I've missed?

Kind regards