- Built-in firmwareВ¶
- Built-in firmwareВ¶
- How does Linux Kernel know where to look for driver firmware?
- Linux firmware
- Contents
- Installation
- Kernel
- Ubuntu Wiki
- Firmware
- What is Firmware?
- Where Do You Get Firmware?
- How is Firmware Used?
- Debugging Firmware Loading
- Initial Step
- Kernel Event Sent to Udev
- Udev Sends Firmware to Kernel
- Kernel Reads the Firmware
- Kernel Gives Firmware to Driver
Built-in firmwareВ¶
Firmware can be built-in to the kernel, this means building the firmware into vmlinux directly, to enable avoiding having to look for firmware from the filesystem. Instead, firmware can be looked for inside the kernel directly. You can enable built-in firmware using the kernel configuration options:
- CONFIG_EXTRA_FIRMWARE
- CONFIG_EXTRA_FIRMWARE_DIR
This should not be confused with CONFIG_FIRMWARE_IN_KERNEL, this is for drivers which enables firmware to be built as part of the kernel build process. This option, CONFIG_FIRMWARE_IN_KERNEL, will build all firmware for all drivers enabled which ship its firmware inside the Linux kernel source tree.
There are a few reasons why you might want to consider building your firmware into the kernel with CONFIG_EXTRA_FIRMWARE though:
- Speed
- Firmware is needed for accessing the boot device, and the user doesn’t want to stuff the firmware into the boot initramfs.
Even if you have these needs there are a few reasons why you may not be able to make use of built-in firmware:
- Legalese — firmware is non-GPL compatible
- Some firmware may be optional
- Firmware upgrades are possible, therefore a new firmware would implicate a complete kernel rebuild.
- Some firmware files may be really large in size. The remote-proc subsystem is an example subsystem which deals with these sorts of firmware
- The firmware may need to be scraped out from some device specific location dynamically, an example is calibration data for for some WiFi chipsets. This calibration data can be unique per sold device.
© Copyright The kernel development community.
Источник
Built-in firmwareВ¶
Firmware can be built-in to the kernel, this means building the firmware into vmlinux directly, to enable avoiding having to look for firmware from the filesystem. Instead, firmware can be looked for inside the kernel directly. You can enable built-in firmware using the kernel configuration options:
- CONFIG_EXTRA_FIRMWARE
- CONFIG_EXTRA_FIRMWARE_DIR
This should not be confused with CONFIG_FIRMWARE_IN_KERNEL, this is for drivers which enables firmware to be built as part of the kernel build process. This option, CONFIG_FIRMWARE_IN_KERNEL, will build all firmware for all drivers enabled which ship its firmware inside the Linux kernel source tree.
There are a few reasons why you might want to consider building your firmware into the kernel with CONFIG_EXTRA_FIRMWARE though:
- Speed
- Firmware is needed for accessing the boot device, and the user doesn’t want to stuff the firmware into the boot initramfs.
Even if you have these needs there are a few reasons why you may not be able to make use of built-in firmware:
- Legalese — firmware is non-GPL compatible
- Some firmware may be optional
- Firmware upgrades are possible, therefore a new firmware would implicate a complete kernel rebuild.
- Some firmware files may be really large in size. The remote-proc subsystem is an example subsystem which deals with these sorts of firmware
- The firmware may need to be scraped out from some device specific location dynamically, an example is calibration data for for some WiFi chipsets. This calibration data can be unique per sold device.
© Copyright The kernel development community.
Источник
How does Linux Kernel know where to look for driver firmware?
I’m compiling a custom kernel under Ubuntu and I’m running into the problem that my kernel doesn’t seem to know where to look for firmware. Under Ubuntu 8.04, firmware is tied to kernel version the same way driver modules are. For example, kernel 2.6.24-24-generic stores its kernel modules in:
and its firmware in:
When I compile the 2.6.24-24-generic Ubuntu kernel according the «Alternate Build Method: The Old-Fashioned Debian Way» I get the appropriate modules directory and all my devices work except those requiring firmware such as my Intel wireless card (ipw2200 module).
The kernel log shows for example that when ipw2200 tries to load the firmware the kernel subsystem controlling the loading of firmware is unable to locate it:
errno-base.h defines this as:
(The function returning ENOENT puts a minus in front of it.)
I tried creating a symlink in /lib/firmware where my kernel’s name pointed to the 2.6.24-24-generic directory, however this resulted in the same error. This firmware is non-GPL, provided by Intel and packed by Ubuntu. I don’t believe it has any actual tie to a particular kernel version. cmp shows that the versions in the various directories are identical.
So how does the kernel know where to look for firmware?
Update
I found this solution to the exact problem I’m having, however it no longer works as Ubuntu has eliminated /etc/hotplug.d and no longer stores its firmware in /usr/lib/hotplug/firmware .
Update2
Some more research turned up some more answers. Up until version 92 of udev , the program firmware_helper was the way firmware got loaded. Starting with udev 93 this program was replaced with a script named firmware.sh providing identical functionality as far as I can tell. Both of these hardcode the firmware path to /lib/firmware . Ubuntu still seems to be using the /lib/udev/firmware_helper binary.
The name of the firmware file is passed to firmware_helper in the environment variable $FIRMWARE which is concatenated to the path /lib/firmware and used to load the firmware.
The actual request to load the firmware is made by the driver (ipw2200 in my case) via the system call:
Now somewhere in between the driver calling request_firmware and firmware_helper looking at the $FIRMWARE environment variable, the kernel package name is getting prepended to the firmware name.
Источник
Linux firmware
Linux firmware is a package distributed alongside the Linux kernel that contains firmware binary blobs necessary for partial or full functionality of certain hardware devices. These binary blobs are usually proprietary because some hardware manufacturers do not release source code necessary to build the firmware itself.
Modern graphics cards from AMD and NVIDIA almost certainly require binary blobs to be loaded for the hardware to operate correctly.
Starting at Broxton (a Skylake-based micro-architecture) Intel CPUs require binary blobs for additional low-power idle states (DMC), graphics workload scheduling on the various graphics parallel engines (GuC), and offloading some media functions from the CPU to GPU (HuC). [1]
Additionally, modern Intel Wi-Fi chipsets almost always require blobs. [2]
Contents
Installation
For security reasons, hotloading firmware into a running kernel has been shunned upon. Modern init systems such as systemd have strongly discouraged loading firmware from userspace.
Kernel
A few kernel options are important to consider when building in firmware support for certain devices in the Linux kernel:
For kernels before 4.18:
CONFIG_FIRMWARE_IN_KERNEL (DEPRECATED) Note this option has been removed as of versions v4.16 and above. [3] Enabling this option was previously necessary to build each required firmware blob specified by EXTRA_FIRMWARE into the kernel directly, where the request_firmware() function will find them without having to make a call out to userspace. On older kernels, it is necessary to enable it.
For kernels beginning with 4.18:
Firmware loading facility ( CONFIG_FW_LOADER ) This option is provided for the case where none of the in-tree modules require userspace firmware loading support, but a module built out-of-tree does. Build named firmware blobs into the kernel binary ( CONFIG_EXTRA_FIRMWARE ) This option is a string and takes the (space-separated) names of firmware files to be built into the kernel. These files will then be accessible to the kernel at runtime.
Источник
Ubuntu Wiki
Firmware
What is Firmware?
Many devices have two essential software pieces that make them function in your operating system. The first is a working driver, which is the software that lets your system talk to the hardware. The second is firmware, which is usually a small piece of code that is uploaded directly to the device for it to function correctly. You can think of the firmware as a way of programming the hardware inside the device. In fact, in almost all cases firmware is treated like hardware in that it’s a black box; there’s no accompanying source code that is freely distributed with it.
Where Do You Get Firmware?
The firmware is usually maintained by the company that develops the hardware device. In Windows land, firmware is usually a part of the driver you install. It’s often not seen by the user. In Linux, firmware may be distributed from a number of sources. Some firmware comes from the Linux kernel sources. Others that have redistribution licenses come from upstream. Some firmware unfortunately do not have licenses allowing free redistribution.
In Ubuntu, firmware comes from one of the following sources:
- The linux-image package (which contains the Linux kernel and licensed firmware)
- The linux-firmware package (which contains other licensed firmware)
- The linux-firmware-nonfree package in multiverse (which contains firmware that are missing redistribution licenses)
- A separate driver package
- Elsewhere (driver CD, email attachment, website)
Note that the linux-firmware-nonfree package is not installed by default.
The firmware files are placed into /lib/firmware. If you look inside there on your Ubuntu installation you will see hundreds of firmware files that have been installed by these packages.
How is Firmware Used?
Each driver for devices that require firmware have some special logic to retrieve firmware from files in /lib/firmware. The basic process is:
- Driver requests firmware file «ar9170.fw»
- The kernel sends an event to udev asking for the firmware
- The udev program runs a script that shoves the data in the firmware file into a special file created by the kernel
- The kernel reads the firmware data from the special file it created and hands the data to the driver
- The driver then does what it needs to do to load the firmware into the device
If everything goes well you should see something like the following in your /var/log/syslog:
If there’s an issue, you may see something like the following:
Debugging Firmware Loading
Luckily, the firmware loading process is not too difficult to watch in action. Using the following debugging steps we can pin point what step in the process is failing.
Initial Step
First, ensure that the firmware file is present. If you are missing the firmware file, try searching on the web for a copy of it. If you find it, consider filing a bug against linux-firmware if the firmware has a redistribution license or against linux-firmware-nonfree otherwise.
If the file is present, check that it’s not empty using ‘ls -l’:
The size of the file is the number listed after the user and group owners («root» and «root» in this case). It should be non-zero. At this point, you may want to search the web for an md5sum hash of the file and compare it to this file, but it’s not likely that the file is corrupted. If the firmware is corrupted, you will likely see an error message from the driver stating that the firmware was invalid or failed to upload anyways.
At this point we’ve verified that the firmware file exists, but wasn’t uploaded. We need to figure out which of steps 2-4 mentioned above are failing. Let’s start with step 2.
Kernel Event Sent to Udev
The second step involves the kernel sending an event to the udev subsystem. Luckily, there’s a handy tool we can use for monitoring these event messages: udevadm. Start with your driver unloaded. Then execute:
Now load your driver. Sometimes loading the driver alone will cause a firmware request. Other times, as with the e100 driver, you will need to do something to initiate a firmware request. In the case of the e100 driver, the firmware is requested after the user tries to bring up the ethernet interface by running ‘ip link set eth0 up’.
Once you have initiated a firmware request you should see a udev event that looks like the following:
There are three key pieces of information in this event:
- ACTION=add: This means the event is for the addition of the devices, as opposed to the removal of the device
- SUBSYSTEM=firmware: This means the event is a firmware request event
FIRMWARE= : This is the filename of the firmware requested by the driver.
If you do not see an event with these three items, then the kernel request is not being propagated to udev. You should file a bug at this point against the udev package. If you do see this event, continue to the next step.
Udev Sends Firmware to Kernel
Now that udev has seen the firmware request, it has to decide how to process it. There should be a «rules» file in /lib/udev/rules.d/50-firmware.rules with a single udev rule:
9.10 (Karmic Koala) and earlier:
10.04 (Lucid Lynx) and later:
This rule tells udev to run the firmware program, which may be found in /lib/udev/, whenever it sees an event with both ACTION=add and SUBSYSTEM=firmware. In 9.10 and earlier, the firmware program will be passed the rest of the udev event information as environment variables. In 10.04 and later, the firmware filename and device path will be passed as parameters.
We can watch udev process the event by turning on extra logging:
When you initiate a firmware request, udev will log what it does with the event to /var/log/syslog. For example, you should see something like:
If you do not see firmware.sh get run, then you likely have an issue with your udev rules. Check for any custome udev rules you have in /etc/udev/rules.d. Any files in this directory will override files with the same name under /lib/udev/rules.d. Rules in /etc/udev/rules.d may also prevent the firmware rule from executing properly. If you have any issues at this step you should seek help from the community. If you believe you have found an issue in udev, feel free to open a bug.
After you have debugged udev execution, you should return the logging output to the normal level:
Kernel Reads the Firmware
If the firmware.sh script has been executed by udev, any errors it encounters should show up in your /var/log/syslog file. If you see any errors here they may be caused by the firmware.sh script (which is part of udev), or by the kernel. If you see the following error:
you should open a kernel bug. If you see any other error, you should open a bug against udev.
Kernel Gives Firmware to Driver
If the firmware loading process properly runs firmware.sh without an error, but the driver complains about the firmware, one of two things may be wrong. First, the firmware file may be incorrect or corrupted. You can try to reinstall the firmware or get the firmware from another source. Second, there may be an issue with the driver itself. If you have tried all the firmware versions you could find, you should open a kernel bug.
Kernel/Firmware (последним исправлял пользователь khadgaray 2013-12-11 08:01:04)
Источник