WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Raspberry Pi Zero, OTG and HID module  (Read 7329 times)

Offline pic0refan

  • Newbie
  • *
  • Posts: 12
Raspberry Pi Zero, OTG and HID module
« on: November 19, 2018, 08:42:33 AM »
I was able to setup RPi Zero in OTG mode with Ethernet on, and now i'm trying to enable HID module ( emulate keyboard ).

Code: [Select]
Module                  Size  Used by    Not tainted
dm9601                  7137  0
usb_f_ecm               7416  1
g_ether                 5005  0
usb_f_rndis            17035  2 g_ether
libcomposite           50185  3 usb_f_ecm,g_ether,usb_f_rndis
u_ether                13511  3 usb_f_ecm,g_ether,usb_f_rndis
i2c_dev                 6802  0
sr9700                  6190  0
dwc2                  122591  0
udc_core               40439  5 usb_f_ecm,usb_f_rndis,libcomposite,u_ether,dwc2
squashfs               33444 17
zram                   20761  1
zsmalloc               17097  1 zram
i2c_bcm2835             6337  0
spi_bcm2835             7468  0
bcm2835_gpiomem         3751  0
fixed                   3029  0
uio_pdrv_genirq         3718  0
uio                    10281  1 uio_pdrv_genirq

and still modprobe complains about no such device

Code: [Select]
sudo modprobe g_hid
modprobe: can't load module g_hid (kernel.tclocal/drivers/usb/gadget/legacy/g_hid.ko): No such device

modinfo:

Code: [Select]
modinfo g_hid
filename:       /lib/modules/4.9.22-piCore/kernel.tclocal/drivers/usb/gadget/legacy/g_hid.ko
author:         Fabien Chouteau, Peter Korsgaard
description:    HID Gadget
license:        GPL
parm:           iProduct:USB Product string
parm:           iManufacturer:USB Manufacturer string
parm:           iSerialNumber:SerialNumber string
parm:           bcdDevice:USB Device version (BCD)
parm:           idProduct:USB Product ID
parm:           idVendor:USB Vendor ID
srcversion:     B2AEAA7314C9326B59C1974
depends:        libcomposite
intree:         Y
vermagic:       4.9.22-piCore mod_unload modversions ARMv6 p2v8

and the kernel version itself:
Code: [Select]
uname -a
Linux box 4.9.22-piCore #1 Sat Apr 15 15:30:03 UTC 2017 armv6l GNU/Linux

What am I missing here?

Thank you!

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14799
Re: Raspberry Pi Zero, OTG and HID module
« Reply #1 on: November 19, 2018, 08:51:45 AM »
does this link help:

http://isticktoit.net/?p=1383

Offline pic0refan

  • Newbie
  • *
  • Posts: 12
Re: Raspberry Pi Zero, OTG and HID module
« Reply #2 on: November 19, 2018, 09:10:06 AM »
I tried that first ( in fact this is my bookmark for doing the same for Arch Linux :) ) and got stuck over "/sys/kernel/config/usb_gadget/" - this folder doesn't exist.

So I was looking on what is missing there, and stumbled over g_hid.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: Raspberry Pi Zero, OTG and HID module
« Reply #3 on: November 19, 2018, 09:49:40 AM »
Hi pic0refan
Code: [Select]
sudo modprobe g_hid
modprobe: can't load module g_hid (kernel.tclocal/drivers/usb/gadget/legacy/g_hid.ko): No such device
If you look in here you'll find it includes:
Code: [Select]
/lib/modules/4.9.22-piCore/kernel/drivers/usb/gadget/legacy/g_hid.ko

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: Raspberry Pi Zero, OTG and HID module
« Reply #4 on: November 19, 2018, 10:20:07 AM »
Hi pic0refan
Sorry, my previous post should have said:
If you look in here:
http://tinycorelinux.net/9.x/armv6/releases/RPi/src/kernel/4.9.22-piCore_modules.tar.xz
you'll find it includes:
Code: [Select]
/lib/modules/4.9.22-piCore/kernel/drivers/usb/gadget/legacy/g_hid.ko

Offline pic0refan

  • Newbie
  • *
  • Posts: 12
Re: Raspberry Pi Zero, OTG and HID module
« Reply #5 on: November 19, 2018, 11:56:56 AM »
That's right, and I have this file in

Code: [Select]
/lib/modules/4.9.22-piCore/kernel.tclocal/drivers/usb/gadget/legacy/g_hid.ko -> /tmp/tcloop/usb-gadget-4.9.22-piCore/usr/local/lib/modules/4.9.22-piCore/kernel/drivers/usb/gadget/legacy/g_hid.ko

It doesn't seem that I have no driver, it seems that for some reason it can't be loaded. After some googling it looks like OTG depends on configfs to be operated, so it will be accessible via /sys/kernel/config/usb_gadget, but in my case there's no such folder.

Does piCore have configfs module?

Offline pic0refan

  • Newbie
  • *
  • Posts: 12
Re: Raspberry Pi Zero, OTG and HID module
« Reply #6 on: November 19, 2018, 12:04:37 PM »
Oh found this one :

http://forum.tinycorelinux.net/index.php/topic,21996.msg139130.html#msg139130:


Code: [Select]
mount -t configfs none /sys/kernel/config

Now I have

Code: [Select]
ls /sys/kernel/config/
device-tree/ usb_gadget/

still modprobe g_hid doesn't work.

Offline pic0refan

  • Newbie
  • *
  • Posts: 12
Re: Raspberry Pi Zero, OTG and HID module
« Reply #7 on: November 19, 2018, 09:16:35 PM »
Some more insignts - with strace I've got this:

Code: [Select]
02:12:08 open("/proc/cmdline", O_RDONLY|O_LARGEFILE)                                                                                                            = 3
02:12:08 fstat64(3, {st_mode=S_IFREG|0444, st_size=0, ...})                                                                                                     = 0
02:12:08 read(3, "bcm2708_fb.fbwidth=656 bcm2708_f"..., 1024)                                                                                                   = 249
02:12:08 read(3, "", 775)                                                                                                                                       = 0
02:12:08 close(3)                                                                                                                                               = 0
02:12:08 open("/proc/cmdline", O_RDONLY|O_LARGEFILE)                                                                                                            = 3
02:12:08 fstat64(3, {st_mode=S_IFREG|0444, st_size=0, ...})                                                                                                     = 0
02:12:08 read(3, "bcm2708_fb.fbwidth=656 bcm2708_f"..., 1024)                                                                                                   = 249
02:12:08 read(3, "", 775)                                                                                                                                       = 0
02:12:08 close(3)                                                                                                                                               = 0
02:12:08 open("/proc/cmdline", O_RDONLY|O_LARGEFILE)                                                                                                            = 3
02:12:08 fstat64(3, {st_mode=S_IFREG|0444, st_size=0, ...})                                                                                                     = 0
02:12:08 read(3, "bcm2708_fb.fbwidth=656 bcm2708_f"..., 1024)                                                                                                   = 249
02:12:08 read(3, "", 775)                                                                                                                                       = 0
02:12:08 close(3)                                                                                                                                               = 0
02:12:08 open("kernel.tclocal/drivers/usb/gadget/legacy/g_hid.ko", O_RDONLY|O_LARGEFILE|O_CLOEXEC)                                                              = 3
02:12:08 finit_module(3, "", 0)                                                                                                                                 = -1 ENODEV (No such device)
02:12:08 close(3)                                                                                                                                               = 0
02:12:08 open("kernel.tclocal/drivers/usb/gadget/legacy/g_hid.ko", O_RDONLY|O_LARGEFILE)                                                                        = 3
02:12:08 read(3, "\177E", 2)                                                                                                                                    = 2
02:12:08 _llseek(3, -2, [0], SEEK_CUR)                                                                                                                          = 0
02:12:08 fstat64(3, {st_mode=S_IFREG|0644, st_size=10916, ...})                                                                                                 = 0
02:12:08 read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\1\0(\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 11264)                                                                    = 10916
02:12:08 read(3, "", 348)                                                                                                                                       = 0
02:12:08 close(3)                                                                                                                                               = 0
02:12:08 init_module(0x1fc5128, 10916, "")                                                                                                                      = -1 ENODEV (No such device)
02:12:08 write(2, "modprobe: can't load module g_hi"..., 102)                                                                                                   = 102
02:12:08 exit_group(1)                                                                                                                                          = ?
02:12:08 +++ exited with 1 +++

looks like something is definitely missing.

Offline pic0refan

  • Newbie
  • *
  • Posts: 12
Re: Raspberry Pi Zero, OTG and HID module
« Reply #8 on: November 28, 2018, 07:42:17 AM »
I created a custom Linux kernel with some userlevel tools with buildroot, verified that all devices work fine.

Is there an easy way to update kernel / userland in tinycore?

E.g - I already have the kernel and working image for RPi, so I'd rather update the modules / binaries from that build system I've got.
« Last Edit: November 28, 2018, 07:47:15 AM by pic0refan »

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14799
Re: Raspberry Pi Zero, OTG and HID module
« Reply #9 on: November 28, 2018, 08:05:25 AM »
Is your custom kernel the same kernel version or a different one?

Offline pic0refan

  • Newbie
  • *
  • Posts: 12
Re: Raspberry Pi Zero, OTG and HID module
« Reply #10 on: November 28, 2018, 11:57:03 AM »
It's the newer one, 4.14.39

I presume that I need to package the entire thing somehow (like the content of output/target or images/sdcard.img ).

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14799
Re: Raspberry Pi Zero, OTG and HID module
« Reply #11 on: November 29, 2018, 12:50:59 AM »
Assuming that you are using piCore-10.0beta3a, which has a 4.14.33 kernel, you would need to:

* replace kernel41433.img (Linux kernel ARM boot executable zImage) with your kernel41439.image
* replace 10.0beta3a.gz (gzipped ASCII cpio archive) with your modified 10.0beta3a.gz

..where the modified cpio archive would replace /lib/modules/4.14.33-piCore with /lib/modules/4.14.39-piCore and regenerate /lib/modules/$KERNEL/modules*