WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: USB gadget kernel module with RPi zero  (Read 49869 times)

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 714
Re: USB gadget kernel module with RPi zero
« Reply #15 on: December 16, 2016, 06:36:47 AM »
USB uart adapter connected to gpio pins.
Add console to cmdline.

Offline johannkraus

  • Newbie
  • *
  • Posts: 6
Re: USB gadget kernel module with RPi zero
« Reply #16 on: January 18, 2017, 11:21:12 AM »
Sorry but I just can't figure it out. I have enabled the `dwc2` overlay in config.txt and I created a tcz package with the following modules added:
This happened to me when I added dtoverlay=dwc2 to the last line of config.txt. As some lines above there is a [RPI3] statement your overlay will not be loaded on a RPI0.
So either move this some lines up to the [ALL] section or better add a [RPI0] statement before this line.

Quote
I also put `modules-load=dwc2,g_ether` after `rootwait` in cmdline.txt and then I reboot my rpi. It doesn't show up as a usb device on my machine. Is there something I forgot to do?
As far as I can tell adding modules-load to cmdline.txt will not work with Tiny Core Linux. This is a feature only available in Raspbian. So please add modprobe to /opt/bootlocal.sh.
As soon as g_multi is in lsmod you can setup usb0 via ifconfig. Your keyboard will still work after modprobing dwc2, g_multi, ... (until you unplug ;) ).
Nowhere, Nothing, Never

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Re: USB gadget kernel module with RPi zero
« Reply #17 on: February 01, 2017, 09:48:51 AM »
Alright, have not had much time to work on this project lately but I successfully added the modules and it seems like dwc2 module is loaded on boot now. Here is the output of lsmod:
Code: [Select]
usb_f_rndis            17023  0
u_ether                14023  1 usb_f_rndis
libcomposite           49319  1 usb_f_rndis
dwc2                  109939  0
udc_core               12750  2 libcomposite,dwc2
squashfs               32160 62
i2c_bcm2708             5740  0
spi_bcm2835             7424  0
bcm2835_gpiomem         3823  0
bcm2835_wdt             4133  0
zram                   22461  1
uio_pdrv_genirq         3718  0
zsmalloc               14329  1 zram
lz4_compress            3289  1 zram
uio                    10230  1 uio_pdrv_genirq
My problem now is that g_ether fails to load properly, here is the output of dmesg:
Code: [Select]
[   22.042841] dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM
[   22.573179] dwc2 20980000.usb: DWC OTG Controller
[   22.573255] dwc2 20980000.usb: new USB bus registered, assigned bus number 1
[   22.573318] dwc2 20980000.usb: irq 33, io mem 0x00000000
[   22.573590] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[   22.573609] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[   22.573622] usb usb1: Product: DWC OTG Controller
[   22.573634] usb usb1: Manufacturer: Linux 4.4.20-piCore+ dwc2_hsotg
[   22.573645] usb usb1: SerialNumber: 20980000.usb
[   22.577937] hub 1-0:1.0: USB hub found
[   22.578019] hub 1-0:1.0: 1 port detected
[   27.653659] g_ether 20980000.usb: failed to start g_ether: -2
This is the output I get from trying to manually do: sudo modprobe g_ether
Code: [Select]
modprobe: can't load module g_ether (kernel/drivers/usb/gadget/legacy/g_ether.ko): unknown symbol in module, or unknown parameter
« Last Edit: February 01, 2017, 10:04:35 AM by Linkan »

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: USB gadget kernel module with RPi zero
« Reply #18 on: February 01, 2017, 10:34:59 AM »
Check the kernel module dependencies. You have a missing module.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Re: USB gadget kernel module with RPi zero
« Reply #19 on: February 01, 2017, 03:31:53 PM »
@bmarkus
I checked the modules.dep file and it reported the following dependencies (same out as running modprobe --show-depends g_ether):
Code: [Select]
kernel/drivers/usb/gadget/function/usb_f_rndis.ko
kernel/drivers/usb/gadget/libcomposite.ko
kernel/drivers/usb/gadget/udc/udc-core.ko
kernel/drivers/usb/gadget/function/u_ether.ko
Here is the files I have in my package:
Code: [Select]
`-- lib
    `-- modules
        `-- 4.4.39-piCore+
            |-- kernel
            |   `-- drivers
            |       `-- usb
            |           |-- dwc2
            |           |   `-- dwc2.ko
            |           `-- gadget
            |               |-- function
            |               |   |-- u_ether.ko
            |               |   `-- usb_f_rndis.ko
            |               |-- legacy
            |               |   `-- g_ether.ko
            |               |-- libcomposite.ko
            |               `-- udc
            |                   `-- udc-core.ko
            `-- modules.dep
I couldn't find any other dependencies in modules.dep that g_ether requires or any of its dependencies.
« Last Edit: February 01, 2017, 03:34:03 PM by Linkan »

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 714
Re: USB gadget kernel module with RPi zero
« Reply #20 on: February 01, 2017, 03:36:44 PM »
By using the modinfo command.

modinfo g_ether

Sometimes the depends: shows what modules it needs.


Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 714
Re: USB gadget kernel module with RPi zero
« Reply #21 on: February 01, 2017, 04:20:30 PM »
Why not test to include the hole gadget directory to your own module extension pack.
And this is how to managed to do the module extension pack.


 http://forum.tinycorelinux.net/index.php/topic,18858.msg129216.html#msg129216

You modify the example above with just two lines. And also the dwc2 driver.

Code: (bash) [Select]
mkdir -p /tmp/package/usr/local/lib/modules/4.4.39-piCore\+/kernel/drivers/usb/gadget/
cp -r /home/tc/modules/4.4.39-piCore\+/kernel/drivers/usb/gadget/* $_

There are also lots of parameters to be set.
Code: (bash) [Select]
modinfo g_ether.ko

filename:       g_ether.ko
license:        GPL
author:         David Brownell, Benedikt Spanger
description:    RNDIS/Ethernet Gadget
srcversion:     5E4C828D24F6E477C9CB5EE
depends:        libcomposite,u_ether,usb_f_rndis
intree:         Y
vermagic:       4.4.39-piCore+ mod_unload modversions ARMv6
parm:           idVendor:USB Vendor ID (ushort)
parm:           idProduct:USB Product ID (ushort)
parm:           bcdDevice:USB Device version (BCD) (ushort)
parm:           iSerialNumber:SerialNumber string (charp)
parm:           iManufacturer:USB Manufacturer string (charp)
parm:           iProduct:USB Product string (charp)
parm:           qmult:queue length multiplier at high/super speed (uint)
parm:           dev_addr:Device Ethernet Address (charp)
parm:           host_addr:Host Ethernet Address (charp)
parm:           use_eem:use CDC EEM mode (bool)
« Last Edit: February 01, 2017, 04:50:50 PM by patrikg »

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: USB gadget kernel module with RPi zero
« Reply #22 on: February 01, 2017, 10:07:58 PM »
See

depends:        libcomposite,u_ether,usb_f_rndis

Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Re: USB gadget kernel module with RPi zero
« Reply #23 on: February 03, 2017, 02:32:41 PM »
Okay, I think I've resolved the dependencies but still I can't load the module with the same error. Do I have to manually specify all the parameters listed by `modinfo` to the kernel module?

Offline jgrulich

  • Sr. Member
  • ****
  • Posts: 341
    • GRULICH DESIGN - R&D Lab.
Re: USB gadget kernel module with RPi zero
« Reply #24 on: February 06, 2017, 02:52:34 PM »
Hi, may be, that my approach is quite different, but why not to use the u-boot bootloader to do all that stuff?
It is designed exactly for this purpose. It has USB and ethernet drivers and you may simply flash the card and do even much more. It's really powerfull. Look: http://www.denx.de/wiki/U-Boot/WebHome

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Re: USB gadget kernel module with RPi zero
« Reply #25 on: February 08, 2017, 09:25:09 AM »
thanks for the tip @jgrulich it certainly looks like something interesting but I'm already commited to the approach with picore + g_ether but I'll keep this in mind if I run in to more problems.

Offline johannkraus

  • Newbie
  • *
  • Posts: 6
Re: USB gadget kernel module with RPi zero
« Reply #26 on: February 13, 2017, 04:55:23 AM »
Okay, I think I've resolved the dependencies but still I can't load the module with the same error. Do I have to manually specify all the parameters listed by `modinfo` to the kernel module?

Just to be curious: What happens if you load g_multi? I just tried to modprobe g_ether and got a "No such device error". But g_multi works on my Pi.

According to this site (http://trac.gateworks.com/wiki/linux/OTG) there seem to be alternative modes for ethernet:
- cdc eem
- rndis

This might be switched in g_ether via use_eem parameter (but probably only when compiled with support - and I was not able to switch).

From dmesg I don't see which one (rndis / eem) is used with g_multi. But my host tells me:
[1210370.212087] cdc_acm 1-4:1.2: ttyACM0: USB ACM device
[1210370.212363] usbcore: registered new interface driver cdc_acm
[1210370.212365] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[1210370.287192] usbcore: registered new interface driver cdc_ether
[1210370.293888] rndis_host 1-4:1.0 usb0: register 'rndis_host' at usb-0000:00:1a.7-4, RNDIS device, 12:88:92:94:83:ca
[1210370.293911] usbcore: registered new interface driver rndis_host
[1210370.317397] usbcore: registered new interface driver rndis_wlan
[1210370.319988] rndis_host 1-4:1.0 enp0s26f7u4: renamed from usb0
Nowhere, Nothing, Never

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Re: USB gadget kernel module with RPi zero
« Reply #27 on: February 14, 2017, 09:36:14 AM »
Thanks @johannkraus and others for the help I got it working now. Not sure what I was doing wrong but it seems that redoing the steps again got it working. `g_ether` works fine for me with the rndis mode for ethernet.

Offline CoraDias

  • Newbie
  • *
  • Posts: 1
Re: USB gadget kernel module with RPi zero
« Reply #28 on: April 24, 2018, 01:11:30 PM »
Hi...i am a new user here. As per my knowledge it can be useful to have when no ethernet is available. What we can do to make  kernel modules and support programs if any as tcz, test and add to the repo.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14819
Re: USB gadget kernel module with RPi zero
« Reply #29 on: April 24, 2018, 01:31:34 PM »
See the extension making section of the wiki here:

http://wiki.tinycorelinux.net/wiki:creating_extensions

In addition, for RPi, there are more kernel modules here:

http://tinycorelinux.net/9.x/armv6/releases/RPi/src/kernel/4.9.22-piCore_modules.tar.xz