From nobody Thu Feb 29 16:37:06 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TlxhL6qjsz5CVBJ; Thu, 29 Feb 2024 16:37:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TlxhL5c4Pz43pv; Thu, 29 Feb 2024 16:37:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709224626; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Z6qN4Nt1CGnOed4P8oIOYhERfi7o/p3bQ5YL79jkFjY=; b=Tnw0Rm8vK9jeyiIHrwNilE8dt7vOTE9lu253U5Qkp/Zj2YbgNFW9+9EBROTU3o016WreRG UoIXX64ByPHZjzdkNxjhzv4q3UZdu+P4VAnYRCZ4yT1RQSRFrXRKuwI14pRmHgFYnz5DlL bCHwKxNVVRB2wNy/KhBvuu90TQQCtarMZrGT7UA0U7n8WEzEjx26qWkqKr7DNFYUs9/iwj BA8ElBkZaXxxHV/1sqmnL/hg9su1QjBDthdW78B7qiB48o0u2CDcbbJln+RMXNDn8msXDZ VC+DQF1zR/Xfqbi5LNXw43svcObTIU5OtFIG+MJmFBd12ay+VziRK+lL/hn84A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1709224626; a=rsa-sha256; cv=none; b=K2kzgEoFk4TeGlTo7pcp9OFuOh+itCCeiNVDQMgnfzhm1LBPWmVaKa293F9e7cLoHlEGHI ufqyBNt264WVeRVygN0ikqIwA+AnF0ZCxdNtzDa5B8SqhVqH2lGwOmZJfkVmmiuYxh8bEr pYxW0OIhUQpyEE3GIgoUY8vgHCFfvJ53M+G7pbkS426dKuM0qMovPE9I1VOTZCgzacpcZJ Aat5S1nwuejHp0edVI4uGDfM8UMyafRldnCpVmpqdiD0AK4xzAoj+XnqKAdYcw1nN21uj6 c78zQktPuxB6d1+fMQnmp2rIZoc5CcsvjxeG6cm7U3twG5/6WBI9h+Txz08qvg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709224626; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Z6qN4Nt1CGnOed4P8oIOYhERfi7o/p3bQ5YL79jkFjY=; b=NpgsPfyJOh3jaTiAEiRO6CWm45Wa4RNEa5cwqlrZ+GxwKhIWs4DIIHDgjdlP+2Pt2PDzJQ TfF6h8PfeZJ09ANx1yV3fifqF04AmTrDDEH+FnaBnMci5DOlfsd6AjuqP9shKt4kvGRN/f 47IhqFvggDDOPj1qXwCWJ1bt7H59541M8+YTpxOsX7wd9FSw1Lze7XOjuFsBOGdyrYpU6D nHu5ML4ygPG2F1lHCvC98+5G65ncoFUO4QbI4deouC32RiqZGOn8UQCGRkbmYF/n4ptlP8 hgDclfeHtTLkIhdDfXWrDibkESTgb1lH1ULaRzqW2WDVjWMcCmEVYx5bzAGtMw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TlxhL5CZbzq8p; Thu, 29 Feb 2024 16:37:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41TGb6AQ041802; Thu, 29 Feb 2024 16:37:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41TGb6QV041799; Thu, 29 Feb 2024 16:37:06 GMT (envelope-from git) Date: Thu, 29 Feb 2024 16:37:06 GMT Message-Id: <202402291637.41TGb6QV041799@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 9478c7f5f80b - main - firmware: document new native file loading. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9478c7f5f80b9bba03632e9a13294defe354150e Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=9478c7f5f80b9bba03632e9a13294defe354150e commit 9478c7f5f80b9bba03632e9a13294defe354150e Author: Warner Losh AuthorDate: 2024-02-29 16:36:40 +0000 Commit: Warner Losh CommitDate: 2024-02-29 16:36:40 +0000 firmware: document new native file loading. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D43611 --- share/man/man9/firmware.9 | 99 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 5 deletions(-) diff --git a/share/man/man9/firmware.9 b/share/man/man9/firmware.9 index 1ee2cd655002..883f0a2634d4 100644 --- a/share/man/man9/firmware.9 +++ b/share/man/man9/firmware.9 @@ -21,7 +21,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd January 19, 2024 +.Dd January 25, 2024 .Dt FIRMWARE 9 .Os .Sh NAME @@ -89,9 +89,12 @@ and unregistered by calling These functions are usually (but not exclusively) called by specially crafted kernel modules that contain the firmware image. The modules can be statically compiled in the kernel, or loaded by -.Nm /boot/loader , +.Pa /boot/loader , manually at runtime, or on demand by the firmware subsystem. .Pp +Firmware binary files may also be loaded directly rather than embedded into +kernel modules. +.Pp .Nm Clients of the firmware subsystem can request access to a given image by calling the function @@ -186,7 +189,7 @@ By default a firmware image will be deferred to a .Xr taskqueue 9 thread so the call may be done while holding a lock. In certain cases, such as on driver detach, this cannot be allowed. -.Sh FIRMWARE LOADING MECHANISMS +.Sh FIRMWARE LOADING VIA MODULES As mentioned before, any component of the system can register firmware images at any time by simply calling .Fn firmware_register . @@ -194,7 +197,7 @@ firmware images at any time by simply calling This is typically done when a module containing a firmware image is given control, whether compiled in, or preloaded by -.Nm /boot/loader , +.Pa /boot/loader , or manually loaded with .Xr kldload 8 . However, a system can implement additional mechanisms to bring @@ -220,7 +223,7 @@ In particular, images are looked up in the directories specified by the sysctl variable .Nm kern.module_path which on most systems defaults to -.Nm /boot/kernel;/boot/modules . +.Pa /boot/kernel;/boot/modules . .Pp Note that in case a module contains multiple images, the caller should first request a @@ -281,16 +284,102 @@ the availability of the following tools: .Xr awk 1 , .Xr make 1 , the compiler and the linker. +.Sh LOADING BINARY FIRMWARE FILES +.Ss Binary Firmware Format +Binary firmware files can also be loaded, either from +.Pa /boot/loader , +or when +.Nm firmware_get +cannot find the registered firmware from a kernel module. +Binary firmware files are raw binary files that the creator of the firmware +made. +They offer an easier way to load firmware, but one that lacks the full +flexibility and generality of kernel modules with the following restrictions: +.Bl -bullet -compact +.It +Binary firmware files only hold one set of firmware. +.It +They do not offer kernel module dependencies to ensure they are loaded +automatically by the boot loader. +.It +They cannot be compiled into the kernel. +.It +The +.Nm imagename +is identical to the full path name used to load the module. +.It +The version number is assumed to be zero. +.El +.Ss Loading from Pa /boot/loader +Binary firmware files may be loaded either from the command line with +.Dq load -t firmware /boot/firmware/filename +or using the +.Xr loader.conf 5 +mechanism to load modules with a type of +.Dq firmware +For example +.Bd -literal +wififw_load="YES" +wififw_name="/boot/firmware/wifi2034_fw.bin" +wififw_type="firmware" +.Ed +.Ss On demand loading from Nm firmware_get +If no kernel module with an embedded firmware image named +.Nm imagename +is loaded, then +.Nm imagename +will be appended to the module path (by default +.Pa /boot/firmware/ ) +and if that file exists, it will be loaded and registered using +.Nm firmware_register +using the full path to the filename as +.Nm imagename . +.Ss Searching for imagename +.Nm firmware_get +uses the following algorithm to find firmware images: +.Bl -bullet -compact +.It +If an existing firmware image is registered for +.Fa imagename, +.that image is returned. +.It +If +.Fa imagename +matches the trailing subpath of a registered image with a full path, that image is returned. +.It +he kernel linker searches for a kernel module named +.Fa imagename . +If a kernel module is found, it is loaded, and +the list of registered firmware images is searched again. +If a match is found, the matching image is returned. +.It +The kernel searches for a file named +.Fa imagename +in the firmware image path +(by default +.Pa /boot/firmware/ ) . +If that file exists and can be read, +it contents are registered as a firmware image with the full path as the +.Nm imagename +and that firmware is returned. +Currently, there is an 8MB limit on the size of the firmware image. +This can be changed by by the sysctl variable +.Nm debug.max_firmware_size . +.El .Sh SEE ALSO .Xr kld 4 , .Xr module 9 .Pp +.Pa /boot/firmware +.Pp .Pa /usr/share/examples/kld/firmware .Sh HISTORY The .Nm firmware system was introduced in .Fx 6.1 . +Binary firmware loading was introduced in +.Fx 15.0 . .Sh AUTHORS This manual page was written by .An Max Laier Aq Mt mlaier@FreeBSD.org .