大网数据广告活动
服务器运维问答

Know which firmware my linux kernel has loaded since booting

· 52CE 我爱测

On routinely updating my Debian system, I've never took the time to pick which firmware packages I do really need; basically I have them all installed, and always up-to-date. I've been wondering how can I pick which ones I do rea…

问题原文

原帖链接 · rslemos · CC BY-SA 4.0

On routinely updating my Debian system, I've never took the time to pick which firmware packages I do really need; basically I have them all installed, and always up-to-date.

I've been wondering how can I pick which ones I do really need. I was thinking of using every device I have in my system (even the ones I rarely use like bluetooth, ethernet, camera, touchpad, multimedia keys and so on) and look at the list of loaded firmware.

Is there an easy way to find out which firmware is currently loaded, or were loaded since last kernel boot?

已采纳解答

原帖链接 · James Luke · CC BY-SA 4.0

If your kernel is built with dynamic debug support (CONFIG_DYNAMIC_DEBUG), you can use a boot parameter to enable debug messages for the firmware loader. It should catch all firmware loads, unless a particular driver does something strange and does not use the kernel's firmware loading API for some reason.

Add the following to your boot parameters:

For kernels 2.6 - 4.16: dyndbg="file drivers/base/firmware_class.c +fmp"

For kernels 4.17 and later: dyndbg="file drivers/base/firmware_loader/main.c +fmp"

(For reference, file blah/foo.c +fmp means "for all debug calls in the kernel source file blah/foo.c, enable dynamic debug printing, and make the message show the filename and module name". See the kernel docs for more detail.)

After booting, run dmesg | grep firmware_class. Of particular interest are lines with firmware_class:fw_get_filesystem_firmware, which should be sandwiched between calls to __allocate_fw_priv and __free_fw_priv.

All firmware loads will be logged until you reboot or disable dynamic debugging.


Background information:

You cannot query for "currently loaded" firmware, because firmware doesn't necessarily remain in system memory. It is often uploaded to some chip in some device outside the system. Most drivers will load a firmware file into a kernel buffer, use that buffer to program the device, then discard the buffer without keeping any record of what the file was. Some drivers do log their firmware loading to the kernel log, but that is by choice of whoever wrote the driver; it's not universal.

When I was trying to figure out how to log firmware loads, my first thought was to "get between" the kernel and whatever userspace program must be responsible for grabbing firmware files. I could add some debug messages and the problem would be solved. But it turns out this is not always possible: the kernel itself is capable of getting firmware straight from the filesystem, with no userspace mechanism involved. (In fact, the kernel prefers to direct load straight from /lib/firmware/ when possible.)

The next thought I had was to use kprobe or some other tracing system to trace kernel function calls that are involved in firmware loading. But it turns out I didn't have to go that far: the firmware loader already includes some debug messages that — once enabled — are enough to see what files are being loaded. The dyndbg above takes advantage of these.


Other information:

The kernel's firmware loading API is generally accessed by calls to request_firmware() or request_firmware_nowait(). A driver calls one of these functions with the name of the firmware file it wants, and the kernel attempts to load it using this process:

  • Check for firmware in the kernel image, load from there if found.
  • Check for firmware on the filesystem, load from there if found.
  • [If kernel is configured for it] use a sysfs "fallback": create /sys/firmware/<xxx>/loading, wait for some program to write firmware to it.
    • [If kernel is configured for it] create a uevent to inform udev or whoever is listening that "it would be really great if you could write to this file".
    • If too much time passes (specifically whatever length of time is in /sys/firmware/timeout), give up with an error.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-07-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。