FIRMWARE(9)
πΎ FIRMWARE(9) β the kernel dev's manual, bestie edition β¨
okay so this is the kernel developer's manual page for FIRMWARE(9) β the whole firmware image loading + management situation. if you write kernel code and you've ever been like "where do the firmware blobs even come from π", this is your page. let's go π«Ά
πΈ NAME πΈ
firmware_register, firmware_unregister, firmware_get, firmware_put β firmware image loading and management. that's the whole friend group right there π
β¨ SYNOPSIS β¨
first, the includes, because you literally cannot do anything without them:
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/linker.h>
#include <sys/firmware.h>
and here's the struct, the moment, the main character herself π
struct firmware {
const char *name; /* system-wide name */
const void *data; /* location of image */
size_t datasize; /* size of image in bytes */
unsigned int version; /* version of the image */
};
the function signatures, verbatim, no notes:
const struct firmware *
firmware_register(const char *imagename, const void *data,
size_t datasize, unsigned int version,
const struct firmware *parent);
int
firmware_unregister(const char *imagename);
const struct firmware *
firmware_get(const char *imagename);
void
firmware_put(const struct firmware *fp, int flags);
π¦ DESCRIPTION π¦
so the firmware abstraction is basically a convenient interface for loading firmware images into the kernel and for letting kernel components access them. that's the vibe. it's giving "glue layer, but make it elegant".
a firmware image (or just image, for brevity, we're casual here) is an opaque block of data living in kernel memory. it's associated with a unique imagename, which is the search key, and with an integer version number β and the version is also just an opaque piece of info for the firmware subsystem. no one's reading it, it's just there for the aesthetic. π
an image gets registered with the firmware subsystem by calling firmware_register(), and unregistered by calling firmware_unregister(). these functions are usually β but not exclusively β called by specially crafted kernel modules that contain the firmware image. those modules can be:
- statically compiled into the kernel,
- loaded by
/boot/loader, - loaded manually at runtime,
- or loaded on demand by the firmware subsystem.
flexible queen behavior tbh π
clients of the firmware subsystem request access to a given image by calling firmware_get() with the imagename they want as an argument. if a matching image isn't already registered, the firmware subsystem will try to load it using the mechanisms described below β typically, a kernel module with firmware_register under the same name as the image. iykyk π§
π API DESCRIPTION π
the kernel firmware_register firmware API is made of these functions:
firmware_register()β registers with the kernel an image of sizedatasizelocated at addressdata, under the nameimagename.firmware_unregister()β tries to unregister the firmware imageimagenamefrom the system. the function is successful and returns0if there are no pending references to the image; otherwise it does not unregister the image and returnsEBUSY.firmware_get()β returns the requested firmware image. if the image isn't yet registered with the system, the function tries to load it. this involves the linker subsystem and disk access, sofirmware_get()must not be called with any locks (except forGiant). also note that if the firmware image is loaded from a filesystem, that filesystem must already be mounted. in particular, this means it may be necessary to defer requests from a driver attach method unless it's known that the root filesystem is already mounted.firmware_put()β drops a reference to a firmware image.
and the return-value tea β:
firmware_register() returns NULL on error (e.g. because an image with the same name already exists, or the image table is full), or a const struct firmware * pointer to the image requested.
firmware_get() on success returns a pointer to the image description and increases the reference count for this image. on failure, the function returns NULL.
for firmware_put(), the flags argument may be set to FIRMWARE_UNLOAD to indicate that firmware_put is free to reclaim resources associated with the firmware image if this is the last reference. by default a firmware image will be deferred to a 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. π€
π¨ bestie listen: no locks exceptGiantwhen you callfirmware_get(). it touches the linker and the disk. respect the constraint or suffer.
π₯ FIRMWARE LOADING MECHANISMS π₯
as mentioned before, any component of the system can register firmware images at any time by simply calling firmware_register(). so empowering honestly π
this is typically done when a module containing a firmware image is given control β whether compiled in, or preloaded by /boot/loader, or manually loaded with kldload(8). however, a system can implement additional mechanisms to bring these images into memory before calling firmware_register().
when firmware_get() doesn't find the requested image, it tries to load it using one of the available loading mechanisms. at the moment, there is only one, namely loadable kernel modules:
- a firmware image named
foois looked up by trying to load the module namedfoo.ko, using the facilities described inkld(4). in particular, images are looked up in the directories specified by the sysctl variablekern.module_path, which on most systems defaults to/boot/kernel;/boot/modules.
β οΈ heads up: in case a module contains multiple images, the caller should first request a firmware_get() for the first image contained in the module, followed by requests for the other images. order matters, don't freestyle it π
π BUILDING FIRMWARE LOADABLE MODULES π
a firmware module is built by embedding the firmware image into a suitable loadable kernel module that calls firmware_register() on loading, and firmware_unregister() on unloading. iconic lifecycle π«
various system scripts and makefiles let you build a module by simply writing a Makefile with the following entries:
KMOD= imagename
FIRMWS= image_file:imagename[:version]
.include <bsd.kmod.mk>
where:
KMODis the basename of the module;FIRMWSis a list of colon-separated tuples indicating theimage_file's to be embedded in the module, theimagenameandversionof each firmware image.
if you need to embed firmware images into a system, you should write appropriate entries in the <files.arch> file, e.g. this example is from sys/arm/xscale/ixp425/files.ixp425:
ixp425_npe_fw.c optional npe_fw \
compile-with "${AWK} -f $S/tools/fw_stub.awk \
IxNpeMicrocode.dat:npe_fw -mnpe -c${.TARGET}" \
no-implicit-rule before-depend local \
clean "ixp425_npe_fw.c"
#
# NB: ld encodes the path in the binary symbols generated for the
# firmware image so link the file to the object directory to
# get known values for reference in the _fw.c file.
#
IxNpeMicrocode.fwo optional npe_fw \
dependency "IxNpeMicrocode.dat" \
compile-with "${LD} -b binary -d -warn-common \
-r -d -o ${.TARGET} IxNpeMicrocode.dat" \
no-implicit-rule \
clean "IxNpeMicrocode.fwo"
IxNpeMicrocode.dat optional npe_fw \
dependency ".PHONY" \
compile-with "uudecode < $S/contrib/dev/npe/IxNpeMicrocode.dat.uu" \
no-obj no-implicit-rule \
clean "IxNpeMicrocode.dat"
note that generating the firmware modules in this way requires the availability of the following tools: awk(1), make(1), the compiler and the linker. the whole squad π«Ά
π SEE ALSO π
β HISTORY β
the firmware system was introduced in FreeBSD 6.1. a classic, an elder, we respect her π
π AUTHORS π
this manual page was written by Max Laier <mlaier@FreeBSD.org>. thank you king π
and that's the page!! this was the Debian flavor of FIRMWARE(9), dated August 2, 2008 β so if you're reading this in a group chat from the future, yes, the firmware subsystem is older than you and it's still slaying. go register some images bestie, you got this π¦β¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2006 Max Laier <mlaier@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms