Jump to content

Recommended Posts

Posted

I can't seem to get the Orange Pi Zero working as a USB gadget (libcomposite) to emulate a keyboard.  Here's the script I'm using to test:

#!/bin/bash 
cd /sys/kernel/config/usb_gadget
mkdir g1
cd g1
echo "0x1d6b" > idVendor
echo "0x0104" > idProduct
mkdir strings/0x409
echo "1234567890" > strings/0x409/serialnumber
echo "0x1d6b" > strings/0x409/manufacturer
echo "0x0104" > strings/0x409/product
mkdir functions/hid.usb0
echo 1 > functions/hid.usb0/protocol
echo 1 > functions/hid.usb0/subclass
echo 8 > functions/hid.usb0/report_length
/bin/echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\
x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.usb0/report_desc
mkdir configs/c.1
mkdir configs/c.1/strings/0x409
echo Conf 1 > configs/c.1/strings/0x409/configuration
echo 120 > configs/c.1/MaxPower
ln -s functions/hid.usb0 configs/c.1
echo musb-hdrc.1.auto > UDC

When trying to execute the script I get this crash:

root@orangepizero:/usr/local/bin# bash -x hid_testing.sh 
+ modprobe libcomposite
+ cd /sys/kernel/config/usb_gadget/
+ mkdir -p g1
+ cd g1
+ echo 0x1d6b
+ echo 0x0104
+ echo 0x0100
+ echo 0x0200
+ mkdir -p strings/0x409
+ echo fedcba9876543210
+ echo girst
+ echo Hardpass
+ N=usb0
+ mkdir -p functions/hid.usb0
+ echo 1
+ echo 1
+ echo 8
+ echo -ne '\x05\x01\x09\x06\xa1\x01\x05\x07\x19\xe0\x29\xe7\x15\x00\x25\x01\x75\x01\x95\x08\x81\x02\x95\x01\x75\x08\x81\x03\x95\x05\x75\x01\x05\x08\x19\x01\x29\x05\x91\x02\x95\x01\x[   84.870357] Unable to handle kernel NULL pointer dereference at virtual address 000000
02
75\x03\x91\x03\x95\x06\x75\x08\x15\x00\x25\x65\x05\x07\x19\x00\x[   84.879054] pgd = ce2b8000
29\x65\x81\x00\xc0'
+ C=1
+ mkdir -p configs/c.1/strings/0x409[   84.887248] [00000002] *pgd=4e2c9835
+ echo 'Config 1: ECM network'
+ echo 250
+ ln -s functions/, *pte=00000000hid.usb0 configs/c.1/
+ ls /sys/class/udc
, *ppte=00000000
[   84.908434] Internal error: Oops: 17 [#1] SMP THUMB2
[   84.913394] Modules linked in: usb_f_hid libcomposite evdev sun8i_ths gpio_keys cpufreq_dt uio_pdrv_genirq uio thermal_sys
[   84.924552] CPU: 3 PID: 1208 Comm: ls Not tainted 4.9.0-sun8i #14
[   84.930639] Hardware name: Allwinner sun8i Family
[   84.935339] task: ce1bb900 task.stack: ce26e000
[   84.939914] PC is at alloc_ep_req+0x15/0x50 [libcomposite]
[   84.945396] LR is at kmem_cache_alloc+0xe3/0xf0
[   84.949923] pc : [<bf84ad76>]    lr : [<c01c1cb7>]    psr: 200e0033
[   84.949923] sp : ce26fde8  ip : 00000000  fp : c9d8e1ec
[   84.961388] r10: c9c61e94  r9 : cd402ac4  r8 : cd402b1c
[   84.966608] r7 : cd402aa8  r6 : ce0a2418  r5 : ce178480  r4 : 00000008
[   84.973128] r3 : 00000000  r2 : ffffffff  r1 : 00000000  r0 : ce178480
[   84.979651] Flags: nzCv  IRQs on  FIQs on  Mode SVC_32  ISA Thumb  Segment none
[   84.986953] Control: 50c5387d  Table: 4e2b806a  DAC: 00000051
[   84.992693] Process ls (pid: 1208, stack limit = 0xce26e210)
[   84.998347] Stack: (0xce26fde8 to 0xce270000)
[   85.002703] fde0:                   bf8570a4 00000000 c9c61e94 bf856461 c0b48ba8 cdbd9000
[   85.010874] fe00: c9d8e1ec bf847923 c9c61e94 cd402aa8 cd402aa8 00000000 cd402b1c bf84778b
[   85.019046] fe20: cd402b1c c9c61eec 00000200 cd402aa8 00000100 bf84a4b9 00000055 c9d8e000
[   85.027235] fe40: c9d8e260 ce0a3148 bf84c100 c9d8e298 00000000 cd220200 00000000 c9d8e1ec
[   85.035419] fe60: cd1b06c0 c9d8e1ec c0b48ba8 cdbd9000 00000051 c05429c3 cd220200 00000000
[   85.043603] fe80: c0b48bc0 c0542ca1 00000000 cd1b06c0 fffffff0 c9d8e000 c9d8e190 00000011
[   85.051792] fea0: cdadc180 bf84ab99 00037e98 00000000 00000011 cd4278c0 00000011 cd4278d8
[   85.059982] fec0: ce26ff80 c021de13 ce26ff80 cdadc180 c021dd81 c0712138 ce26ff80 00037e98
[   85.068172] fee0: 00000011 00000000 00000000 c01cf3f7 50c5387d ce26ffb0 c0b08f2c 000001ff
[   85.076361] ff00: b6f2f120 c010121b 00000000 00000000 585423be 2aedab11 585423be 2aedab11
[   85.084551] ff20: 585423be 2aedab11 00003077 00000000 bec70370 b6f4bd58 cdadc180 00000011
[   85.092740] ff40: 00037e98 ce26ff80 00037e98 00000000 00000000 c01cfe5f 0000000e 000081a4
[   85.100929] ff60: 00000001 cdadc180 cdadc180 00000000 00000000 00037e98 00000011 c01d09df
[   85.109118] ff80: 00000000 00000000 585423be 00000011 00037e98 b6f4bd58 00000004 c0105fe4
[   85.117307] ffa0: ce26e000 c0105e21 00000011 00037e98 00000001 00037e98 00000011 00000000
[   85.125496] ffc0: 00000011 00037e98 b6f4bd58 00000004 b6f4c0ac 00000001 b6f9c000 00000000
[   85.133686] ffe0: 00000000 bec72ae4 b6eaf79b b6eeaf96 000e0030 00000001 4eff6861 4eff6c61
[   85.141926] [<bf84ad76>] (alloc_ep_req [libcomposite]) from [<bf856461>] (hidg_bind+0x64/0x1d0 [usb_f_hid]) 
[   85.151699] [<bf856461>] (hidg_bind [usb_f_hid]) from [<bf84778b>] (usb_add_function+0x3a/0xc4 [libcomposite])
[   85.161740] [<bf84778b>] (usb_add_function [libcomposite]) from [<bf84a4b9>] (configfs_composite_bind+0x1cc/0x2d8 [libcomposite])
[   85.173421] [<bf84a4b9>] (configfs_composite_bind [libcomposite]) from [<c05429c3>] (udc_bind_to_driver+0x1b/0x74)
[   85.183785] [<c05429c3>] (udc_bind_to_driver) from [<c0542ca1>] (usb_gadget_probe_driver+0xa1/0xe4)
[   85.192859] [<c0542ca1>] (usb_gadget_probe_driver) from [<bf84ab99>] (gadget_dev_desc_UDC_store+0x80/0x94 [libcomposite])
[   85.203845] [<bf84ab99>] (gadget_dev_desc_UDC_store [libcomposite]) from [<c021de13>] (configfs_write_file+0x93/0xec)
[   85.214469] [<c021de13>] (configfs_write_file) from [<c01cf3f7>] (__vfs_write+0xf/0xb4)
[   85.222487] [<c01cf3f7>] (__vfs_write) from [<c01cfe5f>] (vfs_write+0x6f/0x13c)
[   85.229811] [<c01cfe5f>] (vfs_write) from [<c01d09df>] (SyS_write+0x2b/0x64)
[   85.236871] [<c01d09df>] (SyS_write) from [<c0105e21>] (ret_fast_syscall+0x1/0x4c)
[   85.244456] Code: d0d8 4605 b190 6a73 (f993) 2002
[   85.249310] ---[ end trace 5a400d152710de10 ]---
hid_testing.sh: line 27:  1208 Segmentation fault      ls /sys/class/udc > UDC

Apparently this line is what kicks it off:

ls /sys/class/udc > UDC

Running this command you can see that it should simply output "musb-hdrc.1.auto" to the "UDC" file:

root@orangepizero:/usr/local/bin# ls /sys/class/udc 
musb-hdrc.1.auto

Sending that to the UDC file is basically the final step in initializing a USB gadget.  So something in the USB gadget driver is failing to work properly and I haven't the foggiest idea of how to troubleshoot this further.  It *seems* like it's a bug but I could be doing something wrong.

 

Any assistance is appreciated.

 

 

Posted

The latest beta kernel and device tree blobs as of today still have this problem. Ideas anyone?

root@orangepizero:/usr/local/bin# dpkg -l | grep -i "linux-image-dev-sun8i\|linux-dtb-dev-sun8i"
ii  linux-dtb-dev-sun8i                5.24.170121                              armhf        Linux DTB, version 4.9.4-sun8i
ii  linux-image-dev-sun8i              5.24.170121                              armhf        Linux kernel, version 4.9.4-sun8i
root@orangepizero:/usr/local/bin# uname -a
Linux orangepizero 4.9.4-sun8i #2 SMP Fri Jan 20 10:22:01 CET 2017 armv7l armv7l armv7l GNU/Linux
root@orangepizero:/usr/local/bin# cat /proc/device-tree/model; echo 
Xunlong Orange Pi Zero
root@orangepizero:/usr/local/bin# bash -x hid_testing.sh
+ cd /sys/kernel/config/usb_gadget
+ mkdir g1
+ cd g1
+ echo 0x1d6b
+ echo 0x0104
+ mkdir strings/0x409
+ echo 1234567890
+ echo 0x1d6b
+ echo 0x0104
+ mkdir functions/hid.usb0
+ echo 1
+ echo 1
+ echo 8
+ /bin/echo -ne '\x05\x01\x09\x06\xa1\x01\x05\x07\x19\xe0\x29\xe7\x15\x00\x25\x01\x75\x01\x95\x08\x81\x02\x95\x01\x75\x08\x81\x03\x95\x05\x75\x01\x05\x08\x19\x01\x29\x05\x91\x02\x95\x01\x75\x03\x91\x03\x95\x06\x75\x08\x15\x00\x25\x65\x05\x07\x19\x00\x29\x65\x81\x00\xc0'
+ mkdir configs/c.1
+ mkdir configs/c.1/strings/0x409
+ echo Conf 1
+ echo 120
+ ln -s functions/hid.usb0 configs/c.1
+ echo musb-hdrc.1.auto
Segmentation fault
root@orangepizero:/usr/local/bin# dmesg
[SNIP]
[   58.756380] Unable to handle kernel NULL pointer dereference at virtual address 00000002
[   58.765376] pgd = cdb44000
[   58.768237] [00000002] *pgd=4d891835, *pte=00000000, *ppte=00000000
[   58.775106] Internal error: Oops: 17 [#1] SMP THUMB2
[   58.780210] Modules linked in: usb_f_hid evdev xradio_wlan mac80211 cfg80211 rfkill sun8i_ths gpio_keys uio_pdrv_genirq cpufreq_dt uio thermal_sys libcomposite
[   58.795335] CPU: 0 PID: 1000 Comm: bash Not tainted 4.9.4-sun8i #2
[   58.801660] Hardware name: Allwinner sun8i Family
[   58.806508] task: ce142ac0 task.stack: cd9ee000
[   58.811426] PC is at alloc_ep_req+0x15/0x50 [libcomposite]
[   58.817101] LR is at kmem_cache_alloc+0xe5/0xec
[   58.821792] pc : [<bf803e06>]    lr : [<c01c2aad>]    psr: 200e0033
               sp : cd9efdf0  ip : 00000000  fp : cda86298
[   58.833519] r10: c9c734c4  r9 : ceb77cec  r8 : 00000100
[   58.838890] r7 : c9c734a8  r6 : cd244418  r5 : cda3e900  r4 : 00000008
[   58.845568] r3 : 00000000  r2 : ffffffff  r1 : 00000000  r0 : cda3e900
[   58.852254] Flags: nzCv  IRQs on  FIQs on  Mode SVC_32  ISA Thumb  Segment none
[   58.859784] Control: 50c5387d  Table: 4db4406a  DAC: 00000051
[   58.865679] Process bash (pid: 1000, stack limit = 0xcd9ee210)
[   58.871661] Stack: (0xcd9efdf0 to 0xcd9f0000)
[   58.876179] fde0:                                     bf9200c0 ceb77c94 00000000 bf91f47d
[   58.884617] fe00: c9c73524 cdbbf840 cda861ec bf80090f ceb77c94 c9c734a8 00000200 00000000
[   58.893055] fe20: 00000100 bf800773 c9c7351c ceb77c94 c9c734a8 00000200 c9c7351c bf803541
[   58.901491] fe40: cda86000 cda86260 00000000 cd245148 bf805180 cda861ec d0e30270 cd23ac00
[   58.909926] fe60: c0b48f60 cda861ec cda861ec c0b48f48 cdbbf840 cda26000 00000051 c054e6e3
[   58.918362] fe80: cd23ac00 c0b48f60 cd41d940 c054e9bb cd41d940 cda86000 cda86190 fffffff0
[   58.926796] fea0: 00000011 bf803c3b 000cd408 00000000 00000011 cd41d040 000cd408 cd41d058
[   58.935233] fec0: cd9eff80 c021e91d cd9eff80 cdbbf840 c021e88d c07121f8 cd9eff80 00000000
[   58.943667] fee0: 00000011 00000000 000c475c c01d032f cc28b700 00000301 00000000 0000034e
[   58.952099] ff00: 00000000 00000000 00000000 cd9eff10 cd9efefc 00000001 cd20f300 00000000
[   58.960532] ff20: 0000000a 00000100 cdaddf00 cdad0bc0 0000000a c01e5a11 cdbbf840 00000011
[   58.968966] ff40: 000cd408 cd9eff80 00000000 00000000 000c475c c01d0d95 cd9b0a80 00000000
[   58.977400] ff60: 00000002 cdbbf840 cdbbf840 00000000 00000000 000cd408 00000011 c01d1937
[   58.985834] ff80: 00000000 00000000 ce142ac0 00000011 000cd408 b6f70d58 00000004 c0106024
[   58.994268] ffa0: cd9ee000 c0105e61 00000011 000cd408 00000001 000cd408 00000011 00000000
[   59.002702] ffc0: 00000011 000cd408 b6f70d58 00000004 00000000 000aa538 000c715c 000c475c
[   59.011135] ffe0: 00000000 bee220ec b6ed479b b6f0ff96 000e0030 00000001 00000000 00000000
[   59.019800] [<bf803e06>] (alloc_ep_req [libcomposite]) from [<bf91f47d>] (hidg_bind+0x68/0x1c8 [usb_f_hid])
[   59.030017] [<bf91f47d>] (hidg_bind [usb_f_hid]) from [<bf800773>] (usb_add_function+0x3a/0xcc [libcomposite])
[   59.040555] [<bf800773>] (usb_add_function [libcomposite]) from [<bf803541>] (configfs_composite_bind+0x1cc/0x2f0 [libcomposite])
[   59.052638] [<bf803541>] (configfs_composite_bind [libcomposite]) from [<c054e6e3>] (udc_bind_to_driver+0x1b/0x74)
[   59.063279] [<c054e6e3>] (udc_bind_to_driver) from [<c054e9bb>] (usb_gadget_probe_driver+0x9f/0xd4)
[   59.072730] [<c054e9bb>] (usb_gadget_probe_driver) from [<bf803c3b>] (gadget_dev_desc_UDC_store+0x82/0x98 [libcomposite])
[   59.084118] [<bf803c3b>] (gadget_dev_desc_UDC_store [libcomposite]) from [<c021e91d>] (configfs_write_file+0x91/0xf8)
[   59.095028] [<c021e91d>] (configfs_write_file) from [<c01d032f>] (__vfs_write+0xf/0xb4)
[   59.103302] [<c01d032f>] (__vfs_write) from [<c01d0d95>] (vfs_write+0x71/0x13c)
[   59.110875] [<c01d0d95>] (vfs_write) from [<c01d1937>] (SyS_write+0x2b/0x64)
[   59.118137] [<c01d1937>] (SyS_write) from [<c0105e61>] (ret_fast_syscall+0x1/0x4c)
[   59.125965] Code: d722 4605 b1a0 6a73 (f993) 2002 
[   59.131522] ---[ end trace 05e0855db8c4b557 ]---
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines