- How to install a device driver on Linux
- Learn how Linux drivers work and how to use them.
- Subscribe now
- Two approaches to finding drivers
- 1. User interfaces
- 2. Command line
- Check if a driver is already installed
- Add the repository and install
- Linux and PEAK-System’s CAN Interfaces
- Drivers Included in Linux Kernel
- Key Features
- Check: Are CAN drivers part of your Linux environment?
- Check: Is the CAN device initialized?
- Driver Package for Proprietary Purposes
- Key Features
- When to Use the Package
- Linux Real Time Drivers for PEAK-System PC CAN/CAN FD Interfaces
- Linux-RT
- Xenomai
- Known Issue in RTAI 5.3
- PCAN-Basic for Linux
- API for Connecting to CAN and CAN FD Buses
- PCAN-View for Linux
- Software for Displaying CAN and CAN FD Messages
- How to install PCAN-View via repository
How to install a device driver on Linux
Learn how Linux drivers work and how to use them.
Subscribe now
Get the highlights in your inbox every week.
One of the most daunting challenges for people switching from a familiar Windows or MacOS system to Linux is installing and configuring a driver. This is understandable, as Windows and MacOS have mechanisms that make this process user-friendly. For example, when you plug in a new piece of hardware, Windows automatically detects it and shows a pop-up window asking if you want to continue with the driver’s installation. You can also download a driver from the internet, then just double-click it to run a wizard or import the driver through Device Manager.
Second, most default Linux drivers are open source and integrated into the system, which makes installing any drivers that are not included quite complicated, even though most hardware devices can be automatically detected. Third, license policies vary among the different Linux distributions. For example, Fedora prohibits including drivers that are proprietary, legally encumbered, or that violate US laws. And Ubuntu asks users to avoid using proprietary or closed hardware.
To learn more about how Linux drivers work, I recommend reading An Introduction to Device Drivers in the book Linux Device Drivers.
Two approaches to finding drivers
1. User interfaces
If you are new to Linux and coming from the Windows or MacOS world, you’ll be glad to know that Linux offers ways to see whether a driver is available through wizard-like programs. Ubuntu offers the Additional Drivers option. Other Linux distributions provide helper programs, like Package Manager for GNOME, that you can check for available drivers.
2. Command line
What if you can’t find a driver through your nice user interface application? Or you only have access through the shell with no graphic interface whatsoever? Maybe you’ve even decided to expand your skills by using a console. You have two options:
- Use a repository
This is similar to the homebrew command in MacOS. By using yum, dnf, apt-get, etc., you’re basically adding a repository and updating the package cache.
- Download, compile, and build it yourself
This usually involves downloading a package directly from a website or using the wget command and running the configuration file and Makefile to install it. This is beyond the scope of this article, but you should be able to find online guides if you choose to go this route.
Check if a driver is already installed
Before jumping further into installing a driver in Linux, let’s look at some commands that will determine whether the driver is already available on your system.
The lspci command shows detailed information about all PCI buses and devices on the system:
Or with grep:
For example, you can type lspci | grep SAMSUNG if you want to know if a Samsung driver is installed.
The dmesg command shows all device drivers recognized by the kernel:
Or with grep:
Any driver that’s recognized will show in the results.
If nothing is recognized by the dmesg or lscpi commands, try these two commands to see if the driver is at least loaded on the disk:
Tip: As with lspci or dmesg, append | grep to either command above to filter the results.
If a driver is recognized by those commands but not by lscpi or dmesg, it means the driver is on the disk but not in the kernel. In this case, load the module with the modprobe command:
Run as this command as sudo since this module must be installed as a root user.
Add the repository and install
There are different ways to add the repository through yum, dnf, and apt-get; describing them all is beyond the scope of this article. To make it simple, this example will use apt-get, but the idea is similar for the other options.
1. Delete the existing repository, if it exists.
where NAME_OF_DRIVER is the probable name of your driver. You can also add pattern match to your regular expression to filter further.
2. Add the repository to the repolist, which should be specified in the driver guide.
where REPOLIST_OF_DRIVER should be specified from the driver documentation (e.g., epel-list).
3. Update the repository list.
4. Install the package.
5. Check the installation.
Run the lscpi command (as above) to check that the driver was installed successfully.
Источник
Linux and PEAK-System’s CAN Interfaces
The PEAK-System PC-CAN interfaces product family is fully operational with any Linux OS.
Many Linux distributions, or rather the used Linux Kernels, already contain the drivers for PEAK-System’s CAN interfaces. The CAN interfaces are then accessed via the common SocketCAN framework as network devices (aka netdev).
If you are using Linux environments missing a driver (e.g. minimized Linux environments, older Kernels) or you want to use our character-based driver (chardev) e.g. in connection with the PCAN-Basic API, you need our PCAN Driver for Linux package and compile the driver yourself.
Drivers Included in Linux Kernel
Key Features
- Out-of-the-box usage, suitable for most cases
- Part of the Linux mainline kernel, classic CAN since 3.2 (peak_pci), CAN FD since 4.0 (peak_usb)
- CAN channels are handled as network devices (netdev)
Check: Are CAN drivers part of your Linux environment?
Open a terminal and type:
grep PEAK_ /boot/config-`uname -r`
All PEAK drivers are listed (y = included in kernel, m = separate module) but this may not work in every Linux environment.
Check: Is the CAN device initialized?
Open a terminal and type: lsmod | grep ^peak
If, for example, a USB-based CAN interface from PEAK is connected and initialized, the output will be at least one line starting with peak_usb .
Driver Package for Proprietary Purposes
Key Features
- Contains sources for chardev and for netdev drivers
- Monolithic driver in contrast to mainline SocketCAN environment with several drivers
- Must be compiled for the target system
- Can be build for real-time Linux extensions like Xenomai or RTAI (RTDM)
- Enables the use of PCAN-Basic Linux API calls (not possible via SocketCAN)
- Provides extra information like the bus load (depending on used CAN interface)
- Support of specific hardware features
- True hardware time stamps with handling of clock drifts
- Mainline kernel drivers are blacklisted when using the PCAN driver
When to Use the Package
- Your CAN application relies on PCAN-Basic for Linux API (based on chardev driver).
- The Kernel you run is too old to include one of the peak_* mainline drivers you need.
- The Kernel you run includes peak_* mainline drivers that are out-of-date or might contain issues.
Implementation DetailsDownload PCAN Driver PackageDocumentation
Linux Real Time Drivers for PEAK-System PC CAN/CAN FD Interfaces
Since the CAN bus is a real-time network, it obviously may need a real-time system. PEAK-System offers several solutions to support its interfaces in different real-time environments based on the Linux kernel.
- «real-time» does not mean «faster». It means «lower and stable latency». Response times may even be a little longer than in a standard Linux kernel, but they will always be the same.
- Because its nature is to be a packet-oriented protocol, USB is not supported in real-time. The received frames are received in the USB interface which will decide by itself when to transmit them to the host.
As in the standard Linux environment, the choice of the solution depends on the desired application interface: in standard Linux, if the choice is made according to the chardev or netdev interface, in the real-time world, it is made according to the RTDM or RT-socket-CAN interface. Whatever the chosen interface, the PEAK-System software offer will provide an adapted solution. The table below summarizes this offer:
RT extension | Linux-RT | Xenomai 3.1 (Mercury skin) | Xenomai 3.1 (Cobalt co-kernel) | RTAI 5.x | ||
---|---|---|---|---|---|---|
Driver API | chardev | netdev | See linux-rt | RTDM | RT-Socket-CAN | RTDM |
PCAN | ||||||
Driver name | PCAN | peak_pci | PCAN | xeno_can_peak_pci | PCAN | |
peak_pciefd | xeno_can_peak_pciefd |
Linux-RT
Linux-RT is the real-time version of the Linux kernel that brought real-time facilities to the standard kernel (see https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/). Applications don’t care about it. Real-time is entirely handled by the patched kernel.
Xenomai
Xenomai is a living project that regularly proposes real-time extensions to the various longterm Linux kernels, for different hardware architectures like ARM, PPC, or x86 (see https://source.denx.de/Xenomai/xenomai/-/wikis/home).
Xenomai 3.1 Mercury is not supported here since it is a simple Xenomai interface (skin) to a Linux-RT patched kernel.
Xenoma 3.1 Cobalt co-kernel is the hard real-time version of Xenomai. Like RTAI, it implements the Real Time Driver Model interface the RT version of the «pcan» driver supports when it is built with «make xeno». Xenomai 3.1 also includes the support of the real-time socket for the CAN bus (aka «RT-Socket-CAN»). With the driver «xeno_can_peak_pci», the RT-Socket-CAN core natively includes support of all the PCI/PCIe CAN 2.0 interfaces of PEAK-System. At the time this note is written (2021/05/06), the PCIe CAN FD interfaces are supported by the driver «xeno_can_peak_pciefd» from the git version of Xenomai (see https://xenomai.org/gitlab/xenomai), in CAN 2.0 mode *ONLY* (CAN FD is not yet supported by the RT-Socket-CAN core).
To take advantage of real-time under Xenomai, an application must be compiled and linked with the real-time libraries that offer access to the real-time facilities added by the Xenomai extension. That’s the reason why the pcan library (which encapsulates the calls to the kernel entry points) must be compiled in real-time mode too.
Finally, as shown in the table above, RT-Socket-CAN is not supported by the «pcan» driver.
RTAI is another Linux kernel extension coming with user libraries and RTDM API that also supports different hardware architectures like ARM, PPC, x86, and m68k (see https://www.rtai.org/).
Unlike Xenomai, RTAI doesn’t propose any native support of real-time CAN sockets. Therefore, the RTDM version of the «pcan» driver and its library (built with «make rtai») is the only way to take advantage of the benefits brought by real-time under RTAI when using the PC CAN interfaces of PEAK-System.
Known Issue in RTAI 5.3
About RTAI 5.3 (release date: May 19, 2021): the x86 version of the base modules prevents the pcan driver to run correctly. This is a confirmed bug in RTAI 5.3 (only) that must be manually fixed until a new version of RTAI 5 is delivered:
- edit «base/arch/x86/hal/hal.c»
- Change line 373 (function «rt_set_irq_ack()») to add the missing «!»:
if (irq >= RTAI_NR_IRQS || !(desc = &rtai_irq_desc(irq))) <
PCAN-Basic for Linux
API for Connecting to CAN and CAN FD Buses
We provide the PCAN-Basic API to allow the development of your own CAN applications for Linux. Programmers can use the languages C++, Java, and Python 3.x. More information about PCAN-Basic is available at its product web page.
Warning: this archive file SHOULD NOT be uncompressed nor installed from the PCAN driver own directory. Please uncompress and install it from any other directory than «peak-linux-driver-x.y.z». The source files contained in it cannot replace those provided by the peak-linux-driver-x.y.z package.
System requirements: This API requires the chardev driver. Please use the Driver Package for Proprietary Purposes.
PCAN-View for Linux
Software for Displaying CAN and CAN FD Messages
PCAN-View is a simple CAN monitor software for receiving and transmitting CAN and CAN FD messages. PCAN-View for Linux is based on the NCurses library.
System requirements: This software requires the chardev driver. Please use the Driver Package for Proprietary Purposes.
How to install PCAN-View via repository
Installing software through repository needs first to register the repository only once. Next to the first installation of the software, there is nothing you have to do, except installing available updates when prompted by your system.
Debian-based Linux distributions
Download and install the following file peak-system.list from the PEAK-System website:
Note: If the lsb_release tool is not installed on your Linux system then replace `lsb_release -cs` by the name of your Linux distribution. For example:
Then, download and install the PEAK-System public key for apt-secure , so that the repository is trusted:
Источник