How to configure embedded-linux USB? - linux

Why doesn't this correctly configure file_storage device USB?
On the embedded-linux target:
/ # modprobe g_file_storage file=/dev/mmcblk0
musb_hdrc: version 6.0, cppi-dma, peripheral, debug=0
musb_hdrc: USB Peripheral mode controller at fec64000 using DMA, IRQ 12
g_file_storage gadget: File-backed Storage Gadget, version: 20 November 2008
g_file_storage gadget: Number of LUNs=1
g_file_storage gadget-lun0: ro=0, file: /dev/mmcblk0
/ # lsusb
lsusb: /sys/bus/usb/devices: No such file or directory
/ # cat /lib/modules/2.6.32-17-ridgerun/modules.dep | grep usb
kernel/drivers/usb/otg/nop-usb-xceiv.ko:
kernel/drivers/usb/musb/musb_hdrc.ko: kernel/drivers/usb/otg/nop-usb-xceiv.ko
kernel/drivers/usb/gadget/g_file_storage.ko: kernel/drivers/usb/musb/musb_hdrc.ko kernel/drivers/usb/otg/nop-usb-xceiv.ko
On the Ubuntu 10.04 host:
$ fgrep USB $DEVDIR/kernel/linux*/.config | grep -v '^#'
CONFIG_USB_SUPPORT=y
CONFIG_USB_ARCH_HAS_HCD=y
CONFIG_USB_MUSB_HDRC=m
CONFIG_USB_MUSB_SOC=y
CONFIG_USB_MUSB_PERIPHERAL=y
CONFIG_USB_GADGET_MUSB_HDRC=y
CONFIG_USB_TI_CPPI_DMA=y
CONFIG_USB_GADGET=m
CONFIG_USB_GADGET_VBUS_DRAW=2
CONFIG_USB_GADGET_SELECTED=y
CONFIG_USB_GADGET_DUALSPEED=y
CONFIG_USB_FILE_STORAGE=m
CONFIG_USB_OTG_UTILS=y
CONFIG_NOP_USB_XCEIV=m
$ lsusb
Bus 002 Device 003: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 002 Device 002: ID 8087:0024
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 005: ID 058f:6362 Alcor Micro Corp. Hi-Speed 21-in-1 Flash Card Reader/Writer (Internal/External)
Bus 001 Device 004: ID 04ca:003a Lite-On Technology Corp.

Needed usb_composite_msd_acm.patch (solved with help from RidgeRun).

Related

Adalm Pluto works on Ubuntu but NOT on Ubuntu Server 20.04 LTS

I'm running ubuntu server and have tried installing libiio packages from both source and apt-get repositories. I can detect the adalm pluto sdr device with iio_info -s (as root because I have not installed the udev rules) but it does not assume an ip address (e.g. 192.168.2.1) like it does on ubuntu 20.04 LTS.
>iio_info -s
Library version: 0.19 (git tag: v0.19)
Compiled with backends: local xml ip usb serial
Available contexts:
0: 0456:b673 (Analog Devices Inc. PlutoSDR (ADALM-PLUTO)), serial=104473b04a060006ffff1c00dd1f8473f8 [usb:3.2.5]
I've followed the instructions here: https://wiki.analog.com/university/tools/pluto/drivers/linux
The output of dmesg when the pluto is plugged in is this:
[380299.366375] usb 3-1: new high-speed USB device number 2 using xhci_hcd
[380299.520117] usb 3-1: New USB device found, idVendor=0456, idProduct=b673, bcdDevice= 4.19
[380299.520120] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[380299.520122] usb 3-1: Product: PlutoSDR (ADALM-PLUTO)
[380299.520123] usb 3-1: Manufacturer: Analog Devices Inc.
[380299.520124] usb 3-1: SerialNumber: 104473b04a060006ffff1c00dd1f8473f8
[380299.553556] usb-storage 3-1:1.2: USB Mass Storage device detected
[380299.555040] scsi host4: usb-storage 3-1:1.2
[380299.555206] usbcore: registered new interface driver usb-storage
[380299.555732] cdc_acm 3-1:1.3: ttyACM0: USB ACM device
[380299.558342] usbcore: registered new interface driver cdc_acm
[380299.558344] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[380299.560691] usbcore: registered new interface driver uas
[380299.569781] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[380299.570205] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[380299.574968] usbcore: registered new interface driver cdc_ether
[380299.578953] rndis_host 3-1:1.0 eth0: register 'rndis_host' at usb-0000:00:14.0-1, RNDIS device, 00:e0:22:81:0c:b6
[380299.579489] usbcore: registered new interface driver rndis_host
[380299.583238] usbcore: registered new interface driver rndis_wlan
[380299.595374] rndis_host 3-1:1.0 enx00e022810cb6: renamed from eth0
[380300.582838] scsi 4:0:0:0: Direct-Access Linux File-Stor Gadget 0419 PQ: 0 ANSI: 2
[380300.583349] sd 4:0:0:0: Attached scsi generic sg1 type 0
[380300.584030] sd 4:0:0:0: [sdb] 61441 512-byte logical blocks: (31.5 MB/30.0 MiB)
[380300.584266] sd 4:0:0:0: [sdb] Write Protect is off
[380300.584274] sd 4:0:0:0: [sdb] Mode Sense: 0f 00 00 00
[380300.584510] sd 4:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[380300.607978] sdb: sdb1
[380300.623364] sd 4:0:0:0: [sdb] Attached SCSI removable disk
This is not consistent with what the guide shows from analog devices' wiki.
I'm at a loss here as to what I'm doing wrong. The device shows up and I have the drivers and required kernel modules (I check with lsmod). Any ideas on what would make this work in ubuntu but not ubuntu server.

"failed to open this device: LIBUSB_ERROR_ACCESS" on ubuntu16.04, have tried some solutions

After searching for long time on internet I think there is no proper answer so I put up this problem. As being new here, I apology if I made any mistakes.
I have a tof camera connected to ubuntu16.04 through usb and a software to operate it. When I try to receive the image through software:
./smartTOFViewer
it gives these error repeatedly:
2018/07/06 20:27:20.297[3249948416][DBG] [dmcam_dev_open] open dmcam device # 0x7f8ab88e29c0
2018/07/06 20:27:20.297[3249948416][DBG] [_usb_ll_dev_open] create usb context
2018/07/06 20:27:20.300[3249948416][ERR] [dmcam_dev_open] open device failed!
2018/07/06 20:27:21.301[3249948416][DBG] [dmcam_dev_open] open dmcam device # 0x7f8ab88e29c0
2018/07/06 20:27:21.301[3249948416][DBG] [_usb_ll_dev_open] create usb context
2018/07/06 20:27:21.303[3249948416][ERR] [dmcam_dev_open] open device failed!
2018/07/06 20:27:22.304[3249948416][DBG] [dmcam_dev_open] open dmcam device # 0x7f8ab88e29c0
2018/07/06 20:27:22.304[3249948416][DBG] [_usb_ll_dev_open] create usb context
2018/07/06 20:27:22.307[3249948416][DBG] [_usb_ll_dev_open] found dmcam device (speed=3) # 001:002:020
2018/07/06 20:27:22.307[3249948416][WRN] [_usb_ll_dev_open] failed to open this device: LIBUSB_ERROR_ACCESS, try next ...
2018/07/06 20:27:22.308[3249948416][ERR] [dmcam_dev_open] open device failed!
but if I run this command:
sudo ./smartTOFViewer
it works normally. So I think it's a permission issue, and create a udev rule file:
sudo nano /etc/udev/rules.d/99-persistent-usb.rules
and content:
SUBSYSTEMS=="usb",ATTRS{idVendor}=="111b", \
ATTRS{idProduct}==1238",GROUP="root", OWNER="root", \
MODE="0666"
The idVendor and idProduct are checked with:
$ lsusb
Bus 001 Device 002: ID 8087:8001 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 006: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 002 Device 005: ID 8087:07dc Intel Corp.
Bus 002 Device 004: ID 064e:920b Suyin Corp.
Bus 002 Device 003: ID 046d:c530 Logitech, Inc.
Bus 002 Device 021: ID 111b:1238
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
I also tried setting something:
GROUP="dongtu" or "adm" or "usrs" or "plugdev",
OWNER="dongtu" or just removing it,
adding TAG+="uaccess",
putting in one line and remove " \"
I run this command for reload:
sudo udevadm control --reload
However, all these make no change. I observed that there is no change under /dev/ when I connect the tof, but I failed to figure out why.
I hope to do my job in anaconda with python, which means I can't use sudo in case run under system python environment. Is there any one could help me? Apologize again if I wasted your time.

USB-Serial communication not working on Linux (Bill Validator GBA ST2)

I am trying to communicate with a GBA ST2 Bill Validator using a USB-Serial connection. Everything works fine on Windows (the device is then attached to a COM port) but not on Linux (so far with Ubuntu 14.04, 16.04 and Debian 8).
By default the cdc_acm drivers are used it is attached to /dev/ttyACMx, but it does not answer any request. (However when requested while in sleep mode it wakes up instantly).
Related output of dmesg and lsusb:
$ dmesg
[26600.821389] usb 2-1: new full-speed USB device number 37 using ohci-pci
[26601.307233] usb 2-1: New USB device found, idVendor=16f9, idProduct=0003
[26601.307237] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[26601.307239] usb 2-1: Product: GBA ST2
[26601.307240] usb 2-1: Manufacturer: Astrosystems
[26601.307242] usb 2-1: SerialNumber: 06010010001
[26601.316173] cdc_acm 2-1:1.0: ttyACM0: USB ACM device
$ lsusb -t
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ohci-pci/12p, 12M
|__ Port 1: Dev 37, If 0, Class=Communications, Driver=cdc_acm, 12M
|__ Port 1: Dev 37, If 1, Class=CDC Data, Driver=cdc_acm, 12M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/12p, 480M
When forcing the device to use the usbserial driver, I was able to use it under a Linux VM (Virtualbox hosted on Windows), but not on a plain Linux machine. I used the following commands to use the usbserial driver:
sudo modprobe -r cdc_acm
sudo modprobe usbserial vendor=0x16f9 product=0x0003
Related dmesg and lsusb output:
$ sudo dmesg
[26022.203166] usbserial: USB Serial support registered for generic
[26022.203188] usbserial_generic 2-1:1.0: Generic device with no bulk out, not allowed.
[26022.206497] usbserial_generic: probe of 2-1:1.0 failed with error -5
[26022.206530] usbserial_generic 2-1:1.1: The "generic" usb-serial driver is only for testing and one-off prototypes.
[26022.206532] usbserial_generic 2-1:1.1: Tell linux-usb#vger.kernel.org to add your device to a proper driver.
[26022.206533] usbserial_generic 2-1:1.1: generic converter detected
[26022.207075] usb 2-1: generic converter now attached to ttyUSB0
lsusb -t
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ohci-pci/12p, 12M
|__ Port 1: Dev 35, If 0, Class=Communications, Driver=, 12M
|__ Port 1: Dev 35, If 1, Class=CDC Data, Driver=usbserial_generic, 12M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/12p, 480M
How can I communicate with this device under Linux? Any idea would be appreciated.
depends on what protocol the bill validator uses at the moment, according to http://www.intelligentvending.co.uk/payment-systems-telemetry/banknote-readers-note-stackers/gba-st2.htm it is able to communicate over ccTalk, MDB, Parallel, Pulse, Serial, SSP
you can communicate with a CDC ACM device using socat. an example for using socat to send AT commands is on https://unix.stackexchange.com/questions/97242/how-to-send-at-commands-to-a-modem-in-linux
socat establishes the connection what command sequences you have to send depends on the present protocol of the bill validator...
http://www.stackoverflow.com/questions/33811013/socat-two-serial-port-together

Cannot open /dev/video0 (No such device)

I am trying to install a webcam on a Synology NAS (arm, linux kernel 3.2.40).
I have compiled and installed the kernel modules, they seem to work. This is the kernel output when inserting the modules and plugging the camera (Logitech C270):
[ 130.963903] Linux video capture interface: v2.00
[ 136.098356] usbcore: registered new interface driver uvcvideo
[ 136.104135] USB Video Class driver (1.1.1)
[ 145.384393] usb 3-2: new high-speed USB device number 4 using etxhci_hcd_150119
[ 145.628583] uvcvideo: Found UVC 1.00 device USBDevice (046d:0825)
[ 145.726156] input: USBDevice as /devices/pci0000:00/0000:00:00.0/usb3/3-2/3-2:1.0/input/input0
This is the lsusb output:
# lsusb
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Function not implemented
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 004: ID 046d:0825 Logitech, Inc. Webcam C270
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
However, I cannot access the camera:
# v4l2-ctl --all
Failed to open /dev/video0: No such device
in strace:
open("/dev/video0", O_RDWR) = -1 ENODEV (No such device)
I have tried different camera model, the C270 on another computer (works fine), deleting /dev/video0 and re-creating it (mknod /dev/video0 c 81 0), changing permissions, etc. but I get the same error...
crw-rw-rw- 1 root video 81, 0 Jun 14 12:07 /dev/video0
lsmod shows that uvcvideo is not used for the camera:
# lsmod
Module Size Used by
uvcvideo 57657 0
videodev 72561 1 uvcvideo
usbcore 147080 7 ehci_hcd,etxhci_hcd,usb_storage,usblp,usbhid,uvcvideo
usb_common 592 1 usbcore
Any ideas?

Hacking USB devices: Any programs out there?

I would like to (A) run something under windows to eavesdrop on the communication between a USB device and windows, so I can then (B) write something to communicate with the USB device, under Linux. Can anybody recommend a program to do (A)?
Your best bet for watching USB traffic on Windows is Snoopy Pro which is based on USB Snoopy.
Once you move over to implementing your driver for Linux, you will want to make sure that usbmon is enabled in your kernel so you can get at the same information on your Linux box.
Make sure your kernel includes the necessary components:
$ cat /boot/config-`uname -r` | grep -P "CONFIG_USB_(MON|DEVICEFS)
CONFIG_USB_DEVICEFS=y
CONFIG_USB_MON=y
Mount the usbmon file system and make sure there is stuff in the usbmon directory:
$ sudo mount -t debugfs none_debugs /sys/kernel/debug
$ ls /sys/kernel/debug/usbmon/
0s 0u 1s 1t 1u 2s 2t 2u 3s 3t 3u 4s 4t 4u 5s 5t 5u 6s 6t 6u
Use lsusb to find the bus number of the device you are interested in:
$ lsusb
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 002: ID 045e:00d1 Microsoft Corp. Optical Mouse with Tilt Wheel
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 0a5c:2110 Broadcom Corp. Bluetooth Controller
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Start listening on the bus of your choice (I am listening on bus 4 below):
$ sudo cat /sys/kernel/debug/usbmon/4u > ~/Desktop/usbmon.txt
Stop collecting data with Control-C.
You can try:
usbsnoop
and
usbsnoopy
usbmon: http://biot.com/blog/usb-sniffing-on-linux

Resources