Skip to contentSkip to conversation

firmware_loader: Expose requested firmware names as sysfs entries

PATCH In review Javier Martinez Canillas 2 participants 3 messages Oct 17 – Nov 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware_loader: Expose requested firmware names as sysfs entries

Most initramfs image creation tools (e.g., dracut or initramfs-tools) have options to create initramfs images that are either generic or tailored to a running system. For example, dracut has the --host-only option for this.

That option allows to have a smaller initramfs image which only contains a sub-set of the kernel modules, libraries, binaries and configuration data.

One thing that can't be queried in a running system is the set of firmware names that were requested by the kernel to support the different devices.

Let's expose this information as sysfs entries to allow initramfs creation tools to determine the set of firmware names that are needed by a system.

On an AM625 BeaglePlay board, the following will be exposed through sysfs:

  $ grep -H . /sys/class/firmware/requested*
  /sys/class/firmware/requested0:powervr/rogue_33.15.11.3_v1.fw
  /sys/class/firmware/requested1:ath3k-1.fw
  /sys/class/firmware/requested2:regulatory.db
  /sys/class/firmware/requested3:regulatory.db.p7s
  /sys/class/firmware/requested4:ti-connectivity/wl1271-nvs.bin
  /sys/class/firmware/requested5:ti-connectivity/wl18xx-conf.bin
  /sys/class/firmware/requested6:ti-connectivity/wl18xx-fw-4.bin

---

 .../ABI/testing/sysfs-class-firmware          | 19 +++++
 drivers/base/firmware_loader/Kconfig          | 14 ++++
 drivers/base/firmware_loader/main.c           |  2 +
 drivers/base/firmware_loader/sysfs.c          | 75 +++++++++++++++++++
 drivers/base/firmware_loader/sysfs.h          |  8 ++
 5 files changed, 118 insertions(+)
Documentation/ABI/testing/sysfs-class-firmware +19 -0
index 44ca1b78a0e1..bae9d4bca0fb 100644
@@ -75,3 +75,22 @@ Description:	This file supports the timeout mechanism for firmware
 		fallback.  This file has no affect on firmware uploads. For
 		more information on timeouts please see the documentation
 		for firmware fallback.
+
+What:		/sys/class/firmware/requestedN
+Date:		October 2026
+KernelVersion:	7.4
+Contact:	[email protected]
+Description:
+		Read-only, each file contains a string with the name of a
+		firmware that was requested and successfully loaded via the
+		firmware loader. The N number is a monotonically increasing
+		integer starting at 0, assigned in the order that the names
+		were requested.
+
+		The entries are global and deduplicated, if multiple devices
+		request to load the same firmware, it will appear just once.
+
+		Entries are never removed, so they represent all the firmware
+		names that were requested since the system booted. This list
+		is useful for user-space tools (such as initramfs generators)
+		to determine the set of firmware required by a running system.
drivers/base/firmware_loader/Kconfig +14 -0
index 15eff8a4b505..368aa8289d4f 100644
@@ -221,6 +221,20 @@ config FW_CACHE
 
 	  If unsure, say Y.
 
+config FW_REQUESTED_SYSFS
+	bool "Expose requested firmware files as sysfs entries"
+	select FW_LOADER_SYSFS
+	help
+	  Enabling this option will track the names of firmware files requested
+	  and successfully loaded by the firmware loader. Each requestedN file
+	  under /sys/class/firmware/ contains the name of a requested firmware
+	  file that was loaded since the system booted.
+
+	  This information is useful for userspace tools (e.g. initramfs image
+	  generators), to determine the set of firmware required by a system.
+
+	  If unsure, say N.
+
 config FW_UPLOAD
 	bool "Enable users to initiate firmware updates using sysfs"
 	select FW_LOADER_SYSFS
drivers/base/firmware_loader/main.c +2 -0
index 24213a0ea831..409b6274156e 100644
@@ -909,6 +909,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
 		fw = NULL;
 	} else {
 		fw_log_firmware_info(fw, name, device);
+		fw_add_requested_name(name);
 	}
 
 	*firmware_p = fw;
@@ -1736,6 +1737,7 @@ static int __init firmware_class_init(void)
 
 static void __exit firmware_class_exit(void)
 {
+	fw_requested_cleanup();
 	unregister_fw_pm_ops();
 	unregister_reboot_notifier(&fw_shutdown_nb);
 	unregister_sysfs_loader();
drivers/base/firmware_loader/sysfs.c +75 -0

78 lines not on this page · raw message

drivers/base/firmware_loader/sysfs.h +8 -0
index 1cabea544a40..6ed79ad7f6c7 100644
@@ -115,4 +115,12 @@ static inline void fw_upload_free(struct fw_sysfs *fw_sysfs)
 }
 #endif
 
+#ifdef CONFIG_FW_REQUESTED_SYSFS
+void fw_add_requested_name(const char *name);
+void __exit fw_requested_cleanup(void);
+#else
+static inline void fw_add_requested_name(const char *name) {}
+static inline void fw_requested_cleanup(void) {}
+#endif
+
 #endif /* __FIRMWARE_SYSFS_H */
Signature · 4 lines
2.56.0

base-commit: 902fdc5e6662a96de71887ce4c2a591231aed82d
branch: add-fw-sysfs
maintainer
#1 lore raw

(Cc: Corentin)

Quoted 24 lines · Javier Martinez Canillas

Most initramfs image creation tools (e.g., dracut or initramfs-tools) have options to create initramfs images that are either generic or tailored to a running system. For example, dracut has the --host-only option for this.

That option allows to have a smaller initramfs image which only contains a sub-set of the kernel modules, libraries, binaries and configuration data.

One thing that can't be queried in a running system is the set of firmware names that were requested by the kernel to support the different devices.

Let's expose this information as sysfs entries to allow initramfs creation tools to determine the set of firmware names that are needed by a system.

On an AM625 BeaglePlay board, the following will be exposed through sysfs:

  $ grep -H . /sys/class/firmware/requested*
  /sys/class/firmware/requested0:powervr/rogue_33.15.11.3_v1.fw
  /sys/class/firmware/requested1:ath3k-1.fw
  /sys/class/firmware/requested2:regulatory.db
  /sys/class/firmware/requested3:regulatory.db.p7s
  /sys/class/firmware/requested4:ti-connectivity/wl1271-nvs.bin
  /sys/class/firmware/requested5:ti-connectivity/wl18xx-conf.bin
  /sys/class/firmware/requested6:ti-connectivity/wl18xx-fw-4.bin
Quoted 1 line

This was discussed before in [1]. I rejected it back then because userspace can already collect this information through existing interfaces.

However, I can see how having a queryable history could simplify automated tooling like dracut. Has this been discussed with the dracut maintainers, and is there a concrete plan to use this interface?

[1] https://lore.kernel.org/all/[email protected]/

#2 lore raw

"Danilo Krummrich" <[email protected]> writes:

Hello Danilo,

Thanks a lot for your feedback.

Quoted 27 lines

(Cc: Corentin)

Quoted 24 lines · Javier Martinez Canillas

Most initramfs image creation tools (e.g., dracut or initramfs-tools) have options to create initramfs images that are either generic or tailored to a running system. For example, dracut has the --host-only option for this.

That option allows to have a smaller initramfs image which only contains a sub-set of the kernel modules, libraries, binaries and configuration data.

One thing that can't be queried in a running system is the set of firmware names that were requested by the kernel to support the different devices.

Let's expose this information as sysfs entries to allow initramfs creation tools to determine the set of firmware names that are needed by a system.

On an AM625 BeaglePlay board, the following will be exposed through sysfs:

  $ grep -H . /sys/class/firmware/requested*
  /sys/class/firmware/requested0:powervr/rogue_33.15.11.3_v1.fw
  /sys/class/firmware/requested1:ath3k-1.fw
  /sys/class/firmware/requested2:regulatory.db
  /sys/class/firmware/requested3:regulatory.db.p7s
  /sys/class/firmware/requested4:ti-connectivity/wl1271-nvs.bin
  /sys/class/firmware/requested5:ti-connectivity/wl18xx-conf.bin
  /sys/class/firmware/requested6:ti-connectivity/wl18xx-fw-4.bin
Quoted 5 lines
Quoted 1 line

This was discussed before in [1]. I rejected it back then because userspace can already collect this information through existing interfaces.

Oh, I missed that patch from Corentin and I did search if anyone else proposed something similar before...

Quoted 1 line

However, I can see how having a queryable history could simplify automated

Yeah, there is clearly a gap or otherwise we wouldn't need for example the 70devicetree-firmware [0] dracut's module to query "firmware-name" properties from the Device Tree that was added by Hans, Dave's proposal to add FW group MODULE_FIRMWARE_GROUP*() metadata to the Linux kernel modules' modinfo [1] or the Fedora [2] effort to split the linux-firmware package in several RPMs.

Quoted 3 lines

tooling like dracut. Has this been discussed with the dracut maintainers, and is there a concrete plan to use this interface?

I haven't discussed with the dracut developers yet. I thought it was too early, given that I didn't know wether this approach would be acceptable or not. I do have a dracut branch [3] though that I've used for testing purposes:

  $ lsinitrd /tmp/initramfs-hostonly.img | grep firmware | wc -l
  11
  $ lsinitrd /tmp/initramfs-nohostonly.img | grep firmware | wc -l
  61
Quoted 2 lines

[1] https://lore.kernel.org/all/[email protected]/

[0]: https://github.com/dracut-ng/dracut/blob/main/modules.d/70devicetree-firmware/module-setup.sh
[1]: https://lists.freedesktop.org/archives/dri-devel/2023-July/411884.html
[2]: https://fedoraproject.org/wiki/Changes/Linux_Firmware_Minimization
[3]: https://github.com/martinezjavier/dracut/tree/hostonly-firmware-support

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat