Segmentation Fault when creating a USB audio gadget (UAC2)

Hi, I would like to add a USB audio gadget (UAC2) to the composite device used on the jetson nano (l4t). I have so far not been successful.

As a first step, I am now first disabling the composite device, and then creating a new USB gadget just for audio.

Here is the script I use to create the UAC2 audio gadget and saved in the file create_usb_audio_gadget.sh.

#!/bin/bash

 cd /sys/kernel/config/usb_gadget

 # create new gadget
 mkdir -p g1
 cd g1

 echo 0x0955 > idVendor
 echo 0xB400 > idProduct
 echo 0x001 > bcdDevice

 mkdir -p strings/0x409
 echo 0x123456789 > strings/0x409/serialnumber
 echo "NVIDIA" > strings/0x409/manufacturer
 echo "USB Audio Gadget" > strings/0x409/product

 mkdir -p configs/c.1

 # create the audio gadget
 mkdir -p functions/uac2.aud0
 ln -s functions/uac2.aud0 configs/c.1

 # activate the gadget
 ls /sys/class/udc > UDC

Here are the steps I have used

  1. sudo systemctl stop nv-l4t-usb-device-mode to deactivate the composite device
  2. ./create_usb_audio_gadget.sh

This results in a segementation fault and here is the log I obtained from dmesg.

[  470.226448]  (null): afunc_bind:1071 Error!
[  470.230788] Unexpected driver unregister!
[  470.230864] ------------[ cut here ]------------
[  470.235489] WARNING: CPU: 0 PID: 6725 at /dvs/git/dirty/git-master_linux/kernel/kernel-4.9/drivers/base/driver.c:191 driver_unregister+0x4c/0x58
[  470.248437] Modules linked in: overlay zram spidev nvgpu bluedroid_pm ip_tables x_tables

[  470.248586] CPU: 0 PID: 6725 Comm: ls Not tainted 4.9.140-tegra #1
[  470.248602] Hardware name: NVIDIA Jetson Nano Developer Kit (DT)
[  470.248621] task: ffffffc0c991f000 task.stack: ffffffc0f5a7c000
[  470.248647] PC is at driver_unregister+0x4c/0x58
[  470.248670] LR is at driver_unregister+0x4c/0x58
[  470.248692] pc : [<ffffff8008782fdc>] lr : [<ffffff8008782fdc>] pstate: 40400145
[  470.248705] sp : ffffffc0f5a7fb70
[  470.248721] x29: ffffffc0f5a7fb70 x28: ffffffc0d21480c8
[  470.248765] x27: ffffffc0f3af4550 x26: ffffffc0f3af4600
[  470.248802] x25: ffffffc0f5ab4c88 x24: ffffff80094a2758
[  470.248838] x23: ffffff800a103e90 x22: ffffffc0f5ab4800
[  470.248872] x21: ffffffc0f3af4568 x20: ffffffc0d21480f0
[  470.248905] x19: ffffffc0d2148458 x18: 0000000000000010
[  470.248939] x17: 0000000000000001 x16: 0000000000000007
[  470.248973] x15: ffffffffffffffff x14: ffffff808a138a02
[  470.249006] x13: 0000000000000000 x12: 0000000000000006
[  470.249038] x11: 0000000000000002 x10: 0000000000000322
[  470.249072] x9 : 0000000000000001 x8 : ffffffc0fefa1e6b
[  470.249104] x7 : 0000000000000000 x6 : 000000000b3ae2d3
[  470.249137] x5 : 0000000000000000 x4 : ffffffc0fefb5be8
[  470.249169] x3 : ffffffc0fefb5be8 x2 : 0000000000000007
[  470.249201] x1 : ffffffc0c991f000 x0 : 000000000000001d

[  470.249247] ---[ end trace 41e809c1c69c038a ]---
[  470.253903] Call trace:
[  470.253935] [<ffffff8008782fdc>] driver_unregister+0x4c/0x58
[  470.253967] [<ffffff8008784568>] platform_driver_unregister+0x20/0x30
[  470.254005] [<ffffff8008ab32d4>] afunc_unbind+0x24/0x50
[  470.254039] [<ffffff8008a8f094>] purge_configs_funcs+0xac/0x150
[  470.254068] [<ffffff8008a8f4a0>] configfs_composite_bind+0x300/0x478
[  470.254099] [<ffffff8008a928d8>] udc_bind_to_driver+0x48/0x120
[  470.254120] [<ffffff8008a930b8>] usb_gadget_probe_driver+0xa8/0x148
[  470.254147] [<ffffff8008a90334>] gadget_dev_desc_UDC_store+0xcc/0x110
[  470.254183] [<ffffff80082f43e8>] configfs_write_file+0xc0/0x198
[  470.254214] [<ffffff800825b560>] __vfs_write+0x48/0x118
[  470.254239] [<ffffff800825c554>] vfs_write+0xac/0x1b0
[  470.254263] [<ffffff800825db8c>] SyS_write+0x54/0xb0
[  470.254291] [<ffffff8008083900>] el0_svc_naked+0x34/0x38
[  470.254991] Internal error: Accessing user space memory outside uaccess.h routines: 96000005 [#1] PREEMPT SMP
[  470.264955] Modules linked in: overlay zram spidev nvgpu bluedroid_pm ip_tables x_tables
[  470.273290] CPU: 0 PID: 6725 Comm: ls Tainted: G        W       4.9.140-tegra #1
[  470.280708] Hardware name: NVIDIA Jetson Nano Developer Kit (DT)
[  470.286740] task: ffffffc0c991f000 task.stack: ffffffc0f5a7c000
[  470.292706] PC is at kernfs_find_ns+0x28/0x110
[  470.297184] LR is at kernfs_find_and_get_ns+0x44/0x68
[  470.302263] pc : [<ffffff80082eeda0>] lr : [<ffffff80082eeecc>] pstate: 40400145
[  470.309678] sp : ffffffc0f5a7fa60
[  470.313017] x29: ffffffc0f5a7fa60 x28: ffffffc0d21480c8
[  470.318397] x27: ffffffc0f3af4550 x26: ffffffc0f3af4600
[  470.323777] x25: ffffffc0f5ab4c88 x24: ffffff80094a2758
[  470.329157] x23: ffffff8009026968 x22: 0000000000000000
[  470.334532] x21: ffffff8009026968 x20: 0000000000000000
[  470.339907] x19: ffffff8009e92c98 x18: 0000000000000010
[  470.345278] x17: 0000000000000000 x16: 0000000000000000
[  470.350650] x15: ffffffffffffffff x14: ffffff808a138a02
[  470.356022] x13: 0000000000000000 x12: 0000000000000006
[  470.361396] x11: 0000000000000002 x10: 0000000000000322
[  470.366770] x9 : 0000000000000001 x8 : ffffffc0fefa1e6b
[  470.372142] x7 : 0000000000000000 x6 : 000000000b3ae2d3
[  470.377514] x5 : 0000000000000000 x4 : ffffffc0fefb5be8
[  470.382888] x3 : ffffffc0fefb5be8 x2 : 0000000000000000
[  470.388260] x1 : ffffff8009026968 x0 : ffffff80082eeecc

[  470.395157] Process ls (pid: 6725, stack limit = 0xffffffc0f5a7c000)
[  470.401531] Call trace:
[  470.404023] [<ffffff80082eeda0>] kernfs_find_ns+0x28/0x110
[  470.409545] [<ffffff80082eeecc>] kernfs_find_and_get_ns+0x44/0x68
[  470.415678] [<ffffff80082f2f34>] sysfs_unmerge_group+0x2c/0x70
[  470.421551] [<ffffff800878ca7c>] dpm_sysfs_remove+0x34/0x70
[  470.427163] [<ffffff800877c8f8>] device_del+0x48/0x248
[  470.432337] [<ffffff8008784d0c>] platform_device_del.part.6+0x2c/0x98
[  470.438808] [<ffffff8008784dcc>] platform_device_unregister+0x24/0x38
[  470.445283] [<ffffff8008ab32dc>] afunc_unbind+0x2c/0x50
[  470.450545] [<ffffff8008a8f094>] purge_configs_funcs+0xac/0x150
[  470.456497] [<ffffff8008a8f4a0>] configfs_composite_bind+0x300/0x478
[  470.462885] [<ffffff8008a928d8>] udc_bind_to_driver+0x48/0x120
[  470.468747] [<ffffff8008a930b8>] usb_gadget_probe_driver+0xa8/0x148
[  470.475048] [<ffffff8008a90334>] gadget_dev_desc_UDC_store+0xcc/0x110
[  470.481525] [<ffffff80082f43e8>] configfs_write_file+0xc0/0x198
[  470.487479] [<ffffff800825b560>] __vfs_write+0x48/0x118
[  470.492735] [<ffffff800825c554>] vfs_write+0xac/0x1b0
[  470.497820] [<ffffff800825db8c>] SyS_write+0x54/0xb0
[  470.502816] [<ffffff8008083900>] el0_svc_naked+0x34/0x38
[  470.508168] ---[ end trace 41e809c1c69c038b ]---

I have checked in /lib/modules/4.9.140-tegra/modules.builtin which contains the lines

kernel/drivers/usb/gadget/libcomposite.ko
kernel/drivers/usb/gadget/function/usb_f_acm.ko
kernel/drivers/usb/gadget/function/u_serial.ko
kernel/drivers/usb/gadget/function/u_ether.ko
kernel/drivers/usb/gadget/function/usb_f_ncm.ko
kernel/drivers/usb/gadget/function/usb_f_ecm.ko
kernel/drivers/usb/gadget/function/usb_f_rndis.ko
kernel/drivers/usb/gadget/function/usb_f_mass_storage.ko
kernel/drivers/usb/gadget/function/usb_f_fs.ko
kernel/drivers/usb/gadget/function/usb_f_uac1.ko
kernel/drivers/usb/gadget/function/usb_f_uac2.ko
kernel/drivers/usb/gadget/function/usb_f_uvc.ko
kernel/drivers/usb/gadget/function/usb_f_mtp.ko
kernel/drivers/usb/gadget/function/usb_f_ptp.ko
kernel/drivers/usb/gadget/function/usb_f_audio_source.ko
kernel/drivers/usb/gadget/function/usb_f_accessory.ko
kernel/drivers/usb/gadget/udc/udc-core.ko
kernel/drivers/usb/gadget/udc/tegra_xudc.ko

which seems to indicate that the usb audio gadget drivers are built into the kernel.
However, I have noticed that the u_audio module seems to be missing both from the built-in modules and the external modules. So I wonder if that might be the problem. I have previously managed to create a USB audio gadget in a pocketbeagle board and the module u_audio was required there.

I’d be very grateful for any help on this topic. Thank you in advance!

Hi,
May see if other users can share experience on this device. Usually we use USB headphone and can see the device listed in aplay -l or arecord -l.

Hi, thank you for taking the time to reply! Just to clarify a little bit more my first post, my goal is to use the Jetson Nano itself as a USB audio device so that it can provide an audio input/output to another host computer. If successfull, the Jetson Nano would appear as an audio input/output when typing aplay -l or arecord -l on the host computer (not the Nano itself).

By default, the Jetson Nano is configured as a composite USB device with both ethernet and serial devices. I would like to add a uac2 device to the composite device.