18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_cimenu "Firmware loader"
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciconfig FW_LOADER
58c2ecf20Sopenharmony_ci	tristate "Firmware loading facility" if EXPERT
68c2ecf20Sopenharmony_ci	default y
78c2ecf20Sopenharmony_ci	help
88c2ecf20Sopenharmony_ci	  This enables the firmware loading facility in the kernel. The kernel
98c2ecf20Sopenharmony_ci	  will first look for built-in firmware, if it has any. Next, it will
108c2ecf20Sopenharmony_ci	  look for the requested firmware in a series of filesystem paths:
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci		o firmware_class path module parameter or kernel boot param
138c2ecf20Sopenharmony_ci		o /lib/firmware/updates/UTS_RELEASE
148c2ecf20Sopenharmony_ci		o /lib/firmware/updates
158c2ecf20Sopenharmony_ci		o /lib/firmware/UTS_RELEASE
168c2ecf20Sopenharmony_ci		o /lib/firmware
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci	  Enabling this feature only increases your kernel image by about
198c2ecf20Sopenharmony_ci	  828 bytes, enable this option unless you are certain you don't
208c2ecf20Sopenharmony_ci	  need firmware.
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci	  You typically want this built-in (=y) but you can also enable this
238c2ecf20Sopenharmony_ci	  as a module, in which case the firmware_class module will be built.
248c2ecf20Sopenharmony_ci	  You also want to be sure to enable this built-in if you are going to
258c2ecf20Sopenharmony_ci	  enable built-in firmware (CONFIG_EXTRA_FIRMWARE).
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciif FW_LOADER
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciconfig FW_LOADER_PAGED_BUF
308c2ecf20Sopenharmony_ci	bool
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciconfig EXTRA_FIRMWARE
338c2ecf20Sopenharmony_ci	string "Build named firmware blobs into the kernel binary"
348c2ecf20Sopenharmony_ci	help
358c2ecf20Sopenharmony_ci	  Device drivers which require firmware can typically deal with
368c2ecf20Sopenharmony_ci	  having the kernel load firmware from the various supported
378c2ecf20Sopenharmony_ci	  /lib/firmware/ paths. This option enables you to build into the
388c2ecf20Sopenharmony_ci	  kernel firmware files. Built-in firmware searches are preceded
398c2ecf20Sopenharmony_ci	  over firmware lookups using your filesystem over the supported
408c2ecf20Sopenharmony_ci	  /lib/firmware paths documented on CONFIG_FW_LOADER.
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	  This may be useful for testing or if the firmware is required early on
438c2ecf20Sopenharmony_ci	  in boot and cannot rely on the firmware being placed in an initrd or
448c2ecf20Sopenharmony_ci	  initramfs.
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	  This option is a string and takes the (space-separated) names of the
478c2ecf20Sopenharmony_ci	  firmware files -- the same names that appear in MODULE_FIRMWARE()
488c2ecf20Sopenharmony_ci	  and request_firmware() in the source. These files should exist under
498c2ecf20Sopenharmony_ci	  the directory specified by the EXTRA_FIRMWARE_DIR option, which is
508c2ecf20Sopenharmony_ci	  /lib/firmware by default.
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	  For example, you might set CONFIG_EXTRA_FIRMWARE="usb8388.bin", copy
538c2ecf20Sopenharmony_ci	  the usb8388.bin file into /lib/firmware, and build the kernel. Then
548c2ecf20Sopenharmony_ci	  any request_firmware("usb8388.bin") will be satisfied internally
558c2ecf20Sopenharmony_ci	  inside the kernel without ever looking at your filesystem at runtime.
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	  WARNING: If you include additional firmware files into your binary
588c2ecf20Sopenharmony_ci	  kernel image that are not available under the terms of the GPL,
598c2ecf20Sopenharmony_ci	  then it may be a violation of the GPL to distribute the resulting
608c2ecf20Sopenharmony_ci	  image since it combines both GPL and non-GPL work. You should
618c2ecf20Sopenharmony_ci	  consult a lawyer of your own before distributing such an image.
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ciconfig EXTRA_FIRMWARE_DIR
648c2ecf20Sopenharmony_ci	string "Firmware blobs root directory"
658c2ecf20Sopenharmony_ci	depends on EXTRA_FIRMWARE != ""
668c2ecf20Sopenharmony_ci	default "/lib/firmware"
678c2ecf20Sopenharmony_ci	help
688c2ecf20Sopenharmony_ci	  This option controls the directory in which the kernel build system
698c2ecf20Sopenharmony_ci	  looks for the firmware files listed in the EXTRA_FIRMWARE option.
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ciconfig FW_LOADER_USER_HELPER
728c2ecf20Sopenharmony_ci	bool "Enable the firmware sysfs fallback mechanism"
738c2ecf20Sopenharmony_ci	select FW_LOADER_PAGED_BUF
748c2ecf20Sopenharmony_ci	help
758c2ecf20Sopenharmony_ci	  This option enables a sysfs loading facility to enable firmware
768c2ecf20Sopenharmony_ci	  loading to the kernel through userspace as a fallback mechanism
778c2ecf20Sopenharmony_ci	  if and only if the kernel's direct filesystem lookup for the
788c2ecf20Sopenharmony_ci	  firmware failed using the different /lib/firmware/ paths, or the
798c2ecf20Sopenharmony_ci	  path specified in the firmware_class path module parameter, or the
808c2ecf20Sopenharmony_ci	  firmware_class path kernel boot parameter if the firmware_class is
818c2ecf20Sopenharmony_ci	  built-in. For details on how to work with the sysfs fallback mechanism
828c2ecf20Sopenharmony_ci	  refer to Documentation/driver-api/firmware/fallback-mechanisms.rst.
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	  The direct filesystem lookup for firmware is always used first now.
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	  If the kernel's direct filesystem lookup for firmware fails to find
878c2ecf20Sopenharmony_ci	  the requested firmware a sysfs fallback loading facility is made
888c2ecf20Sopenharmony_ci	  available and userspace is informed about this through uevents.
898c2ecf20Sopenharmony_ci	  The uevent can be suppressed if the driver explicitly requested it,
908c2ecf20Sopenharmony_ci	  this is known as the driver using the custom fallback mechanism.
918c2ecf20Sopenharmony_ci	  If the custom fallback mechanism is used userspace must always
928c2ecf20Sopenharmony_ci	  acknowledge failure to find firmware as the timeout for the fallback
938c2ecf20Sopenharmony_ci	  mechanism is disabled, and failed requests will linger forever.
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	  This used to be the default firmware loading facility, and udev used
968c2ecf20Sopenharmony_ci	  to listen for uvents to load firmware for the kernel. The firmware
978c2ecf20Sopenharmony_ci	  loading facility functionality in udev has been removed, as such it
988c2ecf20Sopenharmony_ci	  can no longer be relied upon as a fallback mechanism. Linux no longer
998c2ecf20Sopenharmony_ci	  relies on or uses a fallback mechanism in userspace. If you need to
1008c2ecf20Sopenharmony_ci	  rely on one refer to the permissively licensed firmwared:
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	  https://github.com/teg/firmwared
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	  Since this was the default firmware loading facility at one point,
1058c2ecf20Sopenharmony_ci	  old userspace may exist which relies upon it, and as such this
1068c2ecf20Sopenharmony_ci	  mechanism can never be removed from the kernel.
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	  You should only enable this functionality if you are certain you
1098c2ecf20Sopenharmony_ci	  require a fallback mechanism and have a userspace mechanism ready to
1108c2ecf20Sopenharmony_ci	  load firmware in case it is not found. One main reason for this may
1118c2ecf20Sopenharmony_ci	  be if you have drivers which require firmware built-in and for
1128c2ecf20Sopenharmony_ci	  whatever reason cannot place the required firmware in initramfs.
1138c2ecf20Sopenharmony_ci	  Another reason kernels may have this feature enabled is to support a
1148c2ecf20Sopenharmony_ci	  driver which explicitly relies on this fallback mechanism. Only two
1158c2ecf20Sopenharmony_ci	  drivers need this today:
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	    o CONFIG_LEDS_LP55XX_COMMON
1188c2ecf20Sopenharmony_ci	    o CONFIG_DELL_RBU
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	  Outside of supporting the above drivers, another reason for needing
1218c2ecf20Sopenharmony_ci	  this may be that your firmware resides outside of the paths the kernel
1228c2ecf20Sopenharmony_ci	  looks for and cannot possibly be specified using the firmware_class
1238c2ecf20Sopenharmony_ci	  path module parameter or kernel firmware_class path boot parameter
1248c2ecf20Sopenharmony_ci	  if firmware_class is built-in.
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	  A modern use case may be to temporarily mount a custom partition
1278c2ecf20Sopenharmony_ci	  during provisioning which is only accessible to userspace, and then
1288c2ecf20Sopenharmony_ci	  to use it to look for and fetch the required firmware. Such type of
1298c2ecf20Sopenharmony_ci	  driver functionality may not even ever be desirable upstream by
1308c2ecf20Sopenharmony_ci	  vendors, and as such is only required to be supported as an interface
1318c2ecf20Sopenharmony_ci	  for provisioning. Since udev's firmware loading facility has been
1328c2ecf20Sopenharmony_ci	  removed you can use firmwared or a fork of it to customize how you
1338c2ecf20Sopenharmony_ci	  want to load firmware based on uevents issued.
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	  Enabling this option will increase your kernel image size by about
1368c2ecf20Sopenharmony_ci	  13436 bytes.
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	  If you are unsure about this, say N here, unless you are Linux
1398c2ecf20Sopenharmony_ci	  distribution and need to support the above two drivers, or you are
1408c2ecf20Sopenharmony_ci	  certain you need to support some really custom firmware loading
1418c2ecf20Sopenharmony_ci	  facility in userspace.
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ciconfig FW_LOADER_USER_HELPER_FALLBACK
1448c2ecf20Sopenharmony_ci	bool "Force the firmware sysfs fallback mechanism when possible"
1458c2ecf20Sopenharmony_ci	depends on FW_LOADER_USER_HELPER
1468c2ecf20Sopenharmony_ci	help
1478c2ecf20Sopenharmony_ci	  Enabling this option forces a sysfs userspace fallback mechanism
1488c2ecf20Sopenharmony_ci	  to be used for all firmware requests which explicitly do not disable a
1498c2ecf20Sopenharmony_ci	  a fallback mechanism. Firmware calls which do prohibit a fallback
1508c2ecf20Sopenharmony_ci	  mechanism is request_firmware_direct(). This option is kept for
1518c2ecf20Sopenharmony_ci	  backward compatibility purposes given this precise mechanism can also
1528c2ecf20Sopenharmony_ci	  be enabled by setting the proc sysctl value to true:
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	       /proc/sys/kernel/firmware_config/force_sysfs_fallback
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci	  If you are unsure about this, say N here.
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ciconfig FW_LOADER_COMPRESS
1598c2ecf20Sopenharmony_ci	bool "Enable compressed firmware support"
1608c2ecf20Sopenharmony_ci	select FW_LOADER_PAGED_BUF
1618c2ecf20Sopenharmony_ci	select XZ_DEC
1628c2ecf20Sopenharmony_ci	help
1638c2ecf20Sopenharmony_ci	  This option enables the support for loading compressed firmware
1648c2ecf20Sopenharmony_ci	  files. The caller of firmware API receives the decompressed file
1658c2ecf20Sopenharmony_ci	  content. The compressed file is loaded as a fallback, only after
1668c2ecf20Sopenharmony_ci	  loading the raw file failed at first.
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	  Currently only XZ-compressed files are supported, and they have to
1698c2ecf20Sopenharmony_ci	  be compressed with either none or crc32 integrity check type (pass
1708c2ecf20Sopenharmony_ci	  "-C crc32" option to xz command).
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ciconfig FW_CACHE
1738c2ecf20Sopenharmony_ci	bool "Enable firmware caching during suspend"
1748c2ecf20Sopenharmony_ci	depends on PM_SLEEP
1758c2ecf20Sopenharmony_ci	default y if PM_SLEEP
1768c2ecf20Sopenharmony_ci	help
1778c2ecf20Sopenharmony_ci	  Because firmware caching generates uevent messages that are sent
1788c2ecf20Sopenharmony_ci	  over a netlink socket, it can prevent suspend on many platforms.
1798c2ecf20Sopenharmony_ci	  It is also not always useful, so on such platforms we have the
1808c2ecf20Sopenharmony_ci	  option.
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	  If unsure, say Y.
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ciendif # FW_LOADER
1858c2ecf20Sopenharmony_ciendmenu
186