FTDI Dual UART/FIFO: conflict with ftdi_sio - linux

I have a FPGA-Board with two serial connection over one USB-Connection.
Problem:
A program needed to flash the FPGA-Program doesn't work if ftdi_sio is loaded.
This program uses the first connection.
The other one, ttyUSB1, is needed to communicate with the FPGA directly (e.g. with Putty)
But this only works if the ftdi_sio is loaded and the ttyUSB* is available, which it isn't if I have disabled ftdi_so with this udev-rule:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", RUN+="/bin/sh -c 'echo $kernel > /sys/bus/usb/drivers/ftdi_sio/unbind'"
So:
Without this rule
I have ttyUSB0 and ttyUSB1
Programming (Lattice Programmer) doesn't work
Serial connection with ttyUSB1 to the FPGA works
With this rule
I have no ttyUSB*
Programming with the Programmer works
Serial connection to the FPGA does not work (no tty)
Is there a way to only disable ftdi_sio for one connection?
Or is there a way to disable/enable it with a command without reconnecting the USB-cable?
Currently I use a windows VM to program the FPGA but this is very annoying
If you need more information about the device, tell me.
aligator

you can load and unload kernel modules manually with modprobe i.e. load with modprobe ftdi_sio and unload it with modprobe -r ftdi_sio
a problem could be that you need to load dependent modules also
to check the dependencies of ftdi_sio run lsmod
( http://xmodulo.com/how-to-check-kernel-module-dependencies-on-linux.html )

Related

Vfio 0000:41:00.0: failed to open /dev/vfio/32: No such file or directory - QEMU

I have a NVME M.2 SSD that I would like to pass-through to my Virtual Machine as a boot, My SSD works fine with the Virtual Machine Manager, but when I attempt to the Qemu:Console, I get the following message Saying it is not a existing file?!
checked if it the pass-through worked!
This is the Qemu Console command I am using
-device vfio-pci,host=41:00.0
Reading on I found it was a QEMU Console Permission error. I can't find a way to set the vfio permission for manjaro, I heard something of setting a udev perms up, PCI Passthrough is working for other devices, Like my GT710 is working fine.
I then noticed that it was attached to the host and I could not find anyway to remove it, as seen here.
Please Help me!
You need bind your PCI device to the vfio-pci driver.
Unbind pci device from its previous driver
echo "0000:00:14.0" > /sys/devices/pci0000:00/0000:00:14.0/driver/unbind
Bind to vfio-pci driver
echo 8086 a36d > /sys/bus/pci/drivers/vfio-pci/new_id
Where 8086 is the vendor id of the PCI device, and a36d is device id of the PCI device
Check and vfio group should be present, and Qemu can run.
ls -l /dev/vfio/

How to automatically run 'sudo modprobe -r ftdi_sio' whenever the device is plugged into my computer

I have a USB device that I'm using and I'm developing an application using WebUSB with Google Chrome.
The thing is whenever I plug the USB device into my Linux computer, I have to manually run sudo modprobe -r ftdi_sio to unload it.
I want it to be unloaded automatically whenever I plug that device into my computer instead of having to type it manually every single time.
Any ideas on how this could be implemented ? Help would be much appreciated
One option would be to "blacklist" the ftdi_sio module to stop it being loaded automatically. To do that create the following file:
/etc/modprobe.d/ftdi_sio-blacklist.conf
# This is a comment. Change it if you want.
blacklist ftdi_sio
Put your command in /etc/rc.local and restart. See if it works. Or you can find how other .ko are configured to automatically load during system startup. Follow the same to make your module load automatically.
The proper way is to create a udev rule that is triggered when the specific USB device is attached.
Create a file /etc/udev/rules.d/99-usb-load.rules, and replace the "7523" and "1a86" with the Product ID and Vendor ID of your USB device.
# For debugging if the rule is working
ACTION=="add", ENV{ID_MODEL_ID}=="7523", ENV{ID_VENDOR}=="1a86", RUN+="/bin/sh -c '/bin/echo inserted device >> /tmp/udev_file'"
ACTION=="remove", ENV{ID_MODEL_ID}=="7523", ENV{ID_VENDOR}=="1a86", RUN+="/bin/sh -c '/bin/echo removed device >> /tmp/udev_file'"
# Actual rules
ACTION=="add", ENV{ID_MODEL_ID}=="7523", ENV{ID_VENDOR}=="1a86", RUN+="/sbin/rmmod ftdi_sio"
ACTION=="remove", ENV{ID_MODEL_ID}=="7523", ENV{ID_VENDOR}=="1a86", RUN+=""
Restart the udev daemon
sudo /etc/init.d/udev restart
The add rule will be executed whenever the USB device with matching PID/VID is attached and it will unload the module ftdi_sio. The first two rules are for debugging purposes which write a line into /tmp/udev_file and can be used to verify if the rules has been triggered.
Looks like USB device is new and there are no existing drivers to handle as soon as it is plugged in. You need an interrupt line and a USB driver code for your requirement. You need to register your device to that driver and driver to the USB bus. Also need to write appropriate interrupt routines to be called as soon as your device is plugged in. This will make it work as you want !!
If you already have a .rules file for the USB device then append the following to the pre-existing file in the /etc/udev/rules.d/ directory. Otherwise, create a file in the /etc/udev/rules.d/ directory with the following content:
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ACTION=="add", RUN+="/sbin/rmmod ftdi_sio"
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ACTION=="remove", RUN+=""
This means that when the device with vendorID 0403 and product ID 6010 is plugged in it runs /sbin/rmmod ftdi_sio which removes the ftdi_sio module. The second rule means nothing will be run when unplugged. See [writing udev rules] for more info on how to name the .rules file (e.g. 99-mydevice.rules)
You'll have to replace 0403 and 6010 with your device's vendor ID and prodcut ID. The vendor ID and product ID can be found by running lsusb on the command line after plugging in the USB device. It will have the format:
Bus xxx Device xxx: ID idVendor:idProduct ManufacturerName
After creating or editing the .rules file in /etc/udev/rules.d/ directory be sure to reload the .rules file with the following command:
sudo udevadm control --reload
Some further references on udev rules:
debian wiki
arch wiki
writing udev rules

libusb calls without sudo using udev-rules

Tested on Kubuntu 16.04 64 bit only. I have an application which source is not under my control. It uses some libusb calls which ends up in e.g.:
libusb: error [_get_usbfs_fd] libusb couldn't open USB device /dev/bus/usb/001/031: Permission denied
libusb: error [_get_usbfs_fd] libusb requires write access to USB device nodes.
When running the above mentioned application as root, it works as expected.
When I change the permissions of the regarding file like:
sudo chmod a+w /dev/bus/usb/001/031
then the application will work with standard user rights (until I disconnect / reconnect my usb device).
Now I'm looking for a way, to e.g. automatically execute the chmod a+w each time when the specific usb device is plugged in.
Might this be possible by writing a specific udev rule?
Maybe other solutions the libusb calls without root rights?
Solution: Based upon David Grayson's answer, I'd now added an additional line with SUBSYSTEM=="usb" to my rule file. My rules file now finally looks like this:
SUBSYSTEM=="tty", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", MODE="0666"
I suggest that you add a new file in /etc/udev/rules.d named usb.rules. It should have the following contents:
SUBSYSTEM=="usb", MODE="0666"
This will make all USB devices readable and writable by all users.
You could also narrow it down to specific USB devices using idVendor and idProduct attributes mentioned in Ignacio's answer.
Assuming Kubuntu 16.04 uses PolicyKit, put the following in a file in /etc/udev/rules.d, naming it similarly to the files that already exist there:
ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="xxxx", TAG+="uaccess", ENV{ID_MM_DEVICE_IGNORE}="1"
Replace the two sets of "xxxx" with the vendor ID and product ID of the device respectively.
Oldie but goldie. Help me to solve my issue with sharing the usb with virtual machines under AQEMU. Thanks a lot.
I added to the /etc/udev/rules.d file usb.rules with this line
SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", MODE="0666"
and virtual machine can see USB stick being connected life.

Trouble locating my serial ports using bash on Windows 10

I want to be able to read from serial ports on my computer and write to a file. Inside /dev (using Bash shell on Windows 10) I can't seem to locate my USB serial ports (I have tty, tty0, tty1, and that's it for tty).
Is it located somewhere else, or even accessible through the bash shell? I just want to be able to know how to access it at this point.
In device manager, COM4 shows up under ports when I plug in my USB. I also ran the command wmic path Win32_SerialPort in the Windows command prompt and it said "No Instance(s) Available." So I'm very confused as to how I can view my Serial Ports and why they aren't showing up in certain instances.
Any clarification on how serial ports work, especially with USB, would be greatly appreciated, as I am pretty new with this stuff.
Soon, Windows will officially support serial on the Windows Subsystem for Linux (WSL). The COM_n_ ports will be available at /dev/ttyS_n_
Mapping:
COM1 >> /dev/ttyS0
COM2 >> /dev/ttyS1
...
COM192 >> /dev/ttyS191
A good functional description can be found here:
https://blogs.msdn.microsoft.com/wsl/2017/04/14/serial-support-on-the-windows-subsystem-for-linux/
NOTE: At time of writing this feature is only available on the insider builds.
I have the same problem. Apparently you still can`t use serial ports in Bash on Ubuntu on Windows (BoUoW).
You can do basic read and write operations using socat. I used Cygwin to create a socat server that sees my serial ports. I had problems with DTR and RTS pins though.
With socat you can create virtual serial ports or forward a serial port over TCP. (And much more.)
In Cygwin serial ports are listed under /dev/ as ttyS*.
For example COM3 is /dev/ttyS2 and COM4 is /dev/ttyS3.
Start the server in Cygwin with
socat -d -d -d TCP4-LISTEN:2022,reuseaddr,fork /dev/ttyS3
Start the client on BoUoW with
socat PTY,link=/tmp/vmodem0 TCP:localhost:2022
This will create a virtual serial port in BoUoW at /tmp/vmodem0 that is connected to COM4 on your machine.

Linux - Kickstart stops with dialog about which networking device - how to avoid

Using a kickstart file that stops with a dialog "You have multiple
network devices on this system. Which one do you want to install through?"
The machine being configured with PXEboot has two Ethernet interfaces. What's
missing from the network entries below? I'd like this install to proceed
without asking which Ethernet interface.
PXE begins the install with DHCP, so Kickstart should already know which of
eth0, eth1, etc. to use.
Here is the Ethernet line in the ks.cfg file:
network --onboot yes --device eth0 --bootproto dhcp --noipv6
Any ideas appreciated.
NOTE: I have already tried the below option and it didn't work:
In pxelinux config file:
add ksdevice=bootif
also add "IPAPPEND 2" to the end of the file
In kickstart file, don't specify a device:
"network --bootproto dhcp"
How to force an kickstart installation to take place over a specific Ethernet device?
Maybe your network devices' names had been renamed, for example, em1, em2 ... in Dell servers.
In that case you can add biosdevname=0 to the kernel boot arguments, that will prevent biosdevname from being invoked.

Resources