12

I am using this usb wifi device on Debian running on my DE10-Nano board.

Looking at the product details, it seems like this uses the RT5370 chipset which is included in the RT2800USB driver. I have enabled this in the kernel as shown in the screenshot below:

enter image description here

However, the wifi device doesn't work unless I install the firmware also with the following command:

sudo apt install firmware-ralink

My question is - what does the firmware have to do with the driver? Shouldn't the wifi device already have the necessary firmware? What exactly is going on here?

I'm new to kernel drivers and devices so trying to understand the magic going on here. My understanding is that to use a device, I just need to make sure the relevant driver is either compiled into the kernel or available as a module that you can load in later.

Here is the dmesg output when I run ifup wlan0. The firmware file rt2870.bin is provided by the package firmware-ralink.

[   78.302351] ieee80211 phy0: rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'
[   78.311413] ieee80211 phy0: rt2x00lib_request_firmware: Info - Firmware detected - version: 0.36
[   80.175252] wlan0: authenticate with 30:23:03:41:73:67
[   80.206023] wlan0: send auth to 30:23:03:41:73:67 (try 1/3)
[   80.220665] wlan0: authenticated
[   80.232966] wlan0: associate with 30:23:03:41:73:67 (try 1/3)
[   80.257518] wlan0: RX AssocResp from 30:23:03:41:73:67 (capab=0x411 status=0 aid=5)
[   80.270065] wlan0: associated
[   80.503705] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
2
  • Are you compiling your own kernel? You may not have to; the Debian 10 kernels come with the rt2800usb driver as a module.
    – marcelm
    Aug 14, 2021 at 11:53
  • @marcelm - Yes, I'm compiling my own kernel for the de10-nano as per the guide here. Also, avoiding compiling anything to module since the kernel is being cross compiled for ARM on my debian virtualbox. It generates a single zImage file that I copy onto the sdcard of the device. Aug 15, 2021 at 9:16

3 Answers 3

29

Many hardware device manufacturers do not embed firmware into their devices, they require firmware to be loaded into the device by the operating system's driver.

Some other manufacturers embed an old version of the firmware but allow an updated version to be loaded by the driver - quite often the embedded version is ancient and/or buggy (and rarely, if ever, updated in the device itself because that might require changes to the manufacturing or testing process - this is generally a deliberate design decision. The rationale is that the embedded firmware version doesn't have to be good, it just has to resemble something that's minimally functional - updates can and should be loaded by the driver)

The firmware files almost always have a license which is incompatible with the GPL (or even no explicit or discernible license, just an implied "right to use" by being distributed with the device itself and the Windows driver it comes with) and thus can not be distributed with the kernel itself, and has to be distributed as a separate package.

To get the device working, you need both the driver and the firmware.

8
  • 3
    I had no idea, is this normally the case with all devices? Or just specific devices with low volume and low support like the wifi dongle? I'm guessing a regular joystick or external hard drive doesn't need the firmware updated by the driver? Aug 14, 2021 at 5:51
  • It's pretty common with devices like wifi or ethernet interfaces. lots of relatively simple devices like joysticks or keyboards don't need firmware (although some fancy models do).
    – cas
    Aug 14, 2021 at 5:59
  • 2
    @PlastyGrove It really depends. It’s very common with wireless hardware (not just cheap dongles) because they need to be able to update low-level behaviors of the device to allow for changes in regulatory compliance or to fix security issues (‘physical presence’ for an attack directly on wireless hardware could be dozens of meters away from the system). In general, you are unlikely to have to deal with this for almost any other hardware (pretty much everything else you’re likely to encounter will have functional firmware in the device itself and therefore not require loading it from the OS). Aug 14, 2021 at 12:33
  • 1
    It's also common for GPUs (to get anything more than very basic functionality out of them), and CPUs (where the firmware is called "microcode", and it's more about fixing bugs; the CPU will work without loading additional firmware).
    – marcelm
    Aug 14, 2021 at 18:05
  • 3
    @Vikki Most good wireless adapters are actually a specialized SDR, with the firmware (or configuration data loaded later) dictating what frequency bands it can transmit and receive on and how much power can be used when transmitting. The actual selection of channels is typically handled by a different component (called CRDA, but also maintained by the same people who handle the wireless drivers), but transmit power limits are typically firmware imposed. Aug 15, 2021 at 0:38
6

Firmware for the Linux kernel is distributed separately and has its own development tree.

https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/

As to why they are developed separately I've no idea. Some possible answers:

  • For one it may have a license which precludes it from being included.
  • Then you can update firmware without updating the kernel and by keeping them separately you kind of optimize it.

Yeah, looks like it was the case: https://lwn.net/Articles/284932/

Some good write up on it: https://www.linuxfromscratch.org/blfs/view/svn/postlfs/firmware.html

2
  • The LFS article is very interesting, thanks for sharing. I had no idea the firmware is updated by the drivers. Aug 14, 2021 at 5:55
  • 3
    Device firmware for linux isn't so much developed as collected. Likely none of them are open source, all are from the vendor. We see them as binary blobs, black boxes. We neither need to know nor care what is in them mostly.
    – user10489
    Aug 14, 2021 at 12:54
4

It would make no sense to include the firmware in the kernel because:

  • The firmware is not needed to boot the kernel; it is only needed to make the device function fully
  • The firmware does not affect the functioning of the kernel (only the device), and including all firmwares in the kernel would just make it bigger
  • Loading the firmware from a file on the filesystem (e.g., /lib/firmware ) at driver load works better than embedding it in the kernel
  • If it isn't embedded in the kernel, then the kernel doesn't have to do anything special to release its memory after loading it into the device
  • Having a single copy of the firmware in the filesystem is better than including a copy of it with each installed kernel, especially when firmware versions are unrelated to kernel versions

And, as others pointed out, including it in the kernel may not be legal anyway.

There are a few exceptions, mostly cases where a device's driver and/or firmware are not part of the kernel proper, but are needed to boot the system. In these cases, they are usually included in the initrd when it is built during either kernel or driver installation.

11
  • 1
    "The firmware is not needed to boot the kernel" - u sure about that? :-) What if it's the firmware for your storage or GPU? In both cases the kernel will boot but then will fail to mount your root filesystem or show anything on the screen which for all intents and purposes means the system has not booted (successfully). Likewise the second. Aug 14, 2021 at 20:58
  • 1
    "Loading the firmware from a file on the filesystem at driver load works better than embedding it in the kernel" this is wrong, e.g. when you need to load the CPU microcode early on boot to avoid any boot time security issues. In fact Gentoo and Arch used to recommend embedding the CPU firmware right into the kernel (not sure if it's still the case). Aug 14, 2021 at 21:00
  • "If it isn't embedded in the kernel, then the kernel doesn't have to do anything special to release its memory after loading it into the device" the kernel is very unlikely to allocate any memory to load firmware. If I'm not mistaken firmware is uploaded to the device directly. At most we're talking about temporary filesystem cache but then firmware is not that big to be any concern for modern systems. Aug 14, 2021 at 21:01
  • "Having a single copy of the firmware in the filesystem is better than including a copy of it with each installed kernel, especially when firmware versions are unrelated to kernel versions" firmware in Linux is stored in /lib/firmware and already shared between all installed kernels. Aug 14, 2021 at 21:02
  • 1
    In short all your bullet points are very much up to debate and likely wrong. Aug 14, 2021 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.