Removing USB, only reboot allows to detect it again - linux-kernel

In a DART-6UL linux based board, when I booted my system (both from eMMC or SD Card) with USB flash drive or a FTDI USB-to-serial converter inserted, it compared in: /run/media device list or in: /dev list.
When I removed it, USB devices are correctly removed, but it's no possible to inserted again. The only way is to reboot the system with USB inserted.
I tried the same on the EvKit and USB can be inserted and removed all times with no problem, without the need of reboot.
In Kernel usin Menuconfig I set CONFIG_USB_SERIAL=y and ftdi-sio module appears as regularly loaded at boot.
What can I check on my system?

Related

how to write a usb storage device driver

I used the usb driver template usb skeleton.c in the kernel and changed VENDOR_ID and PRODUCT_ID to be able to detect my usb storage device. Then compile this module and install it. Unfortunately, although the probe function works correctly, there is no my device when I execute fdisk -l
Before installing the module, I have uninstalled the two modules usb_storage and usa, and renamed usb_storage.ko to ensure that it will not install itself
I want to know how to make the usb storage device be able to display and access normally

USB bootable device is not showing

I have DELL inspiron 7560 which has pre installed with windows. I want to dual boot it with Ubuntu. I have created a booatable device. But on startup it is not showing USB drive to install Ubuntu.
What tool/utility did you use to create the bootable USB?
If you did use Rufus to create your USB, after setting up the USB and clicking "START", select "Write in DD Image Mode" instead of "Write in ISO Image Mode".
I have found that writing in ISO Image Mode tends to make bootable Linux USB's to not appear or work properly.
Computers nowadays use UEFI by default, so make sure that your bootable USB is formatted as GPT. Otherwise if you create a bootable USB with MBR instead of GPT, it may not be visible.
Make sure that you are going into either the F12 boot menu in the BIOS, or set the boot order priority in the BIOS, or else you won't be able to boot from the USB drive.

USB pop-up window?

I am wondering whether it is possible to display a message to the user when he connects a USB device. For example, I want to program the USB so that any PC that the device is connected to displays the pop-up window, saying Please leave the usb on this place.
It is NOT possible;
You wrote: " I want to program the usb so that any PC that the device is connected "
You'd rather program the PC not the USB
USB is a storage device only. Unfortunatelly you can't program all the PC's that USb might get into
The ONLY way this might be (yes it won't work in every case I guarantee) be tweaked is to have autorun.inf file in the USB pointing to a program on the USB that displays the message you want.
[Autorun]
Open=msg.exe
Due to most modern operating systems have tons of blocking mechanism to stop autorun programs this message has very slight chance to appear
You will need to first register for device notification. Then, you can implement a callback to detect when your USB device is inserted or removed. Within that callback you can do your messaging to the users based of your inspection of which device was inserted or removed.
This is only possible if the computer already has a driver installed for this device that implements this behavior. If, as I suspect, the device is actually a standard USB storage device, this is not possible.

Unload kernel module for only a specific device (preferrably from code in another kernel module)

I'm working on a project where I have a management system that exports PCIe hardware devices to other systems via PCI Express. I have a working management kernel module but need to find a way to ensure that a device I export doesn't have a driver already loaded for it on the management system. Without that, the device will end up with conflicts since the same driver will be accessing it from 2 different systems & obviously cause problems.
For example, assume I have a dual-port Intel 100MBps NIC device installed on the Manager which will show up 2 PCIe Endpoints in the system (eg Fn 0 & 1). The Intel module e1000 will be loaded for both devices. If I want to export port 2 of that device to another system, I would like to "detach" it from the e1000 module.
Does anyone know a clean way of doing this without hacking the kernel or tweaking the e1000's driver's probe function? I can't simply do an rmmod because that will remove the module all-together for both NIC devices. I would like the NIC I'm not exporting to remain functional in the Management system with the e1000 driver still loaded for it.
Essentially, rmmod does this but will remove the driver for all devices probed for & owned by the driver. Any way to tell Linux just "unload module for only this specific device"? On Windows, I guess this would be the equivalent of right-clicking on a device in Device Manager & select "Disable".
You can disable driver for your device by writting following method:
Use sudo -i or before any command write sudo to operate as root user.And follow below procedure:
Goto /sys/bus/pci/<driver_name>/ folder.
Give command echo -n 0000:03:00.1 > unbind
Where 0000:03:00.1 is device you want to detech your driver.
Read this link for getting idea about sysfs for pci bus.
The mechanism responsible for device/driver pairing in Linux driver model is called "bus" (usually controlled through entries in /sys/bus). The problem is, the particular bus driver your device is attached to must support this sort of action (and it is far from trivial supporting this functionality in general case).
Specifically for PCI, if you've got "pci hotplug" enabled, you will be able to kick devices off pci bus by writing numbers to corresponding "hotplug" entries in /sys/bus/pci (you can also reconnect them back by triggering the bus rescan). The problems will start later, as you will have to somehow convince the Linux device subsystem to prefer your driver over the one already registered for the device id in question.
Normally registered drivers are added to some sort of list and then tried out one by one to see if either of them is listing the new or re-enabled device in their "*_device_id" tables. If PCI subsystem prefers to try drivers in "first registered, first tried" order you will have to hack it to achieve your goal.
To unbind a PCI driver from a device, use the unbind file of the driver in sysfs.
From Documentation/ABI/testing/sysfs-bus-pci:
/sys/bus/pci/drivers/.../unbind
Description:
Writing a device location to this file will cause the
driver to attempt to unbind from the device found at
this location. This may be useful when overriding default
bindings. The format for the location is: DDDD:BB:DD.F.
That is Domain:Bus:Device.Function and is the same as
found in /sys/bus/pci/devices/. For example:
# echo 0000:00:19.0 > /sys/bus/pci/drivers/foo/unbind
you can disable a particular pci device by resetting enable value for the corresponding device
Eg:
echo 0 > /sys/bus/pci/devices/0000:00:1a.2/enable

Windows PC as a USB slave to emulate a thumbdrive

I need to create a application that will allow a Windows PC (XP/Vista) to emulate a thumbdrive. That is, when the PC is plugged into either another Windows system, or in this case, a piece of hardware that allows for USB thumbdrives to be plugged in, a folder on the computer looks like a giant thumbdrive. Any thoughts on where a guy would start to investigate this?
Update (more specific description):
I need to connect my PC to one of the newer multifuction devices that support scanning to a USB thumbdrive that is inserted into the front of the device. These units do not support WIA or TWAIN via the rear USB connector that you'd typically use for connectivity to a PC.
Most USB controllers in regular pc's dont have the possibility to function as an USB slave. So I'd start with investigating what kind of hardware you're going to use.
Another way to go: there are USB Link cables to link up 2 pc's over USB, maybe that's usable for you?
You cannot do this in an application. At the lowest level, the USB ports on your computer are controlled by an Host Controller Interface. This chip will manage up to 127 slave USB devices. You would need to seriously reprogram this chip before it implements the slave side of the USB protocol. Of course, at that point any USB hub in your PC will break down - those 8 USB ports you probably have are usually implemented by 2 smart USB hubs connecting to both USB1 and USB2 host controllers. Next, your USB keyboard and mouse will stop working.
Take an MCU with two Slave USBs. Write a simple frimware which makes one USB act as a Special Device Class and wait until PC on this USB provides mandatory data (including Device Class, of course) for the other USB. Write a PC program which connects to the Special Device (your MCU), uploads Mass Storage Device Class and redirects I/O to a dedicated partition. The other USB on the MCU will become an emulated Mass Storage Device.
Some of those code can be taken from Linux.

Resources