Tiny Core Base > Raspberry Pi
USB gadget kernel module with RPi zero
johannkraus:
Hi there,
I'm using Tiny Core Linux on my different RPis for quite a while now. One of my projects is miniaturising an RFID-based attendance system currently running on a Raspberry Pi B. I bought a couple of RPi zeros and now I am experimenting with some new hardware, i.e. OLED vs LED, capacitive touch vs button, battery power vs power supply, ... AND ...
USB OTG vs. wlan/usblan/serial
The RPi zero supports gadget mode, i.e. one can program the RPi from another computer using only a single USB OTG cable. The available gadget modules enable mass storage mode, ethernet, serial, etc. I'm most interested in the mass storage mode, as it would enable mounting the gadget on a host computer and transferring some data without the need for LAN or a serial connection.
I was already able to do this with Raspbian following this guide http://blog.gbaman.info/?p=699
But I do have some issues with Tiny Core Linux and need your help. This is what I tried so far:
- I installed the newest beta as it has Kernel 4.4.15
- I added dtoverlay=dwc2 to config.txt
- trying modprobe dwc2 tells me that there is no module to load
- I downloaded http://tinycorelinux.net/8.x/armv6/releases/RPi/src/kernel/4.4.15-piCore+_modules.tar.xz and there it is
- I copied dwc2 and the gadget modules to lib/modules/.../usb and also copied modules.dep
- finally, I was able to modprobe dwc2
Then if I modprobe g_mass_storage it tells me that there is no such device. Shouldn't dtoverlay do it's magic?
I would really appreciate any help! I built my last kernel ~10 years ago in my Gentoo times and just learned that something like device tree exists.
To make some advertisement for USB OTG:
- one would not need a serial connection to the GPIO - you can use usb
- the Pi zero can be powered from it's usb port, i.e. the gadget mode one :)
- you can have ethernet over usb without additional hardware, i.e. wlan stick or breakout board
- and lot more fun stuff :)
- the obvious downside is that you loose the only usb port on the RPi zero
Best Johann
johannkraus:
Okay - I finally had some time to compare Raspbian to piCore:
* after adding dwc2 overlay to config.txt and modprobe dwc2 in Raspbian there is another tty in dev -> ttyGS0. I would assume this is the device the gadget modules use. And this device is not present in piCore. Remind that adding the overlay and modprobe dwc2 just works and does not give any error in piCore. But all the messages in dmesg about enabling the new usb (non host) device are missing.
* using Raspbian one can dynamically load overlays via dtoverlay in the bash. If I do so, the device is also not created. However, I think this is unrelated to my problem here.
* in piCore I can also modprobe further modules that seem to be needed by the gadget modules, i.e. libcomposite and usb_f_acm.
It seems that dtoverlay cannot handle the dwc2 overlay. Well, sit back and ... RTFM -> https://searchcode.com/codesearch/view/37919024/
--- Quote ---To use the gadget serial driver you must configure the Linux gadget side kernel for "Support for USB Gadgets", for a "USB Peripheral Controller" (for example, net2280), and for the "Serial Gadget" driver. All this are listed under "USB Gadget Support" when configuring the kernel. Then rebuild and install the kernel or modules.
--- End quote ---
I assume that the gadget side kernel was not configured. I will have a try rebuilding the kernel - will take some time ;D
and
--- Quote from: johannkraus on July 29, 2016, 11:29:05 AM ---- I copied dwc2 and the gadget modules to lib/modules/.../usb and also copied modules.dep
--- End quote ---
I assume depmod -a should be better than copying modules.dep
bmarkus:
piCore kernel configuration is the same as Raspbian, except few more features enabled, like zswap, etc. Nothing removed compared to Raspbian.
johannkraus:
Thanks Béla. I tried it once again now with piCore-8.0rc1 and succeeded. Probably last time I forgot to make the changes from depmod persistent. Gadget mode via g_multi (which includes mass storage, serial, and ether) now runs perfectly.
This is how I succeeded:
* Copy dwc2 and the gadget modules to lib/modules/.../usb
* Call depmod -a and make the result persistent
* Add /sbin/modprobe dwc2 to /opt/bootlocal.sh -> again don't forget to call backup
* Add dtoverlay=dwc2 to config.txt. Don't do that before your system loads dwc2 module at startup as your usb port will then probably not accept your keyboard anymore (as dwc_otg is replaced by dwc2).
* Create a container to share via g_multi, e.g. dd if=/dev/zero of=/home/tc/piusb.bin bs=512 count=2880 and mkdosfs piusb.bin
* After reboot call modprobe g_multi file=/home/tc/piusb.bin stall=0You now can add the g_multi modprobe to bootlocal. I needed a short sleep between modprobing dwc2 and g_multi, e.g. sleep 5. Otherwise I had strange errors on enumerating usbs on the host computer.
For a working ether over usb I just set up the usb0 interface via ifconfig as described elsewhere in this forum for static eth0.
For a working serial via /dev/ttyGS0 I modified cmdline.txt to use GS0 and the /usr/sbin/startserialtty script.
@bmarkus -> I would be interested in having the usb modules builtin the image. They're less than 1MB in size and really provide a benefit for Pi zero users. Any more Pi zero users here?
If the modules could be builtin - Is there a way to modprobe dwc2 and g_multi and setting up usb0 ethernet automatically iff dtoverlay=dwc2 was added to config.txt? This would make an out-of-the-box pi zero gadget with serial or ethernet via usb.
Best
Johann
Paul_123:
No two users will use the same hardware and driver. The base image is fine. My USB hub/ethernet uses the usbip-KERNEL.tcz package. After I burn the image, I mount the partition and add that extension to the drive, and edit onboot.lst Takes a minute to do.
Navigation
[0] Message Index
[#] Next page
Go to full version