From nobody Wed Oct 16 14:32:06 2024 X-Original-To: dev-commits-src-all@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 4XTD1z0RNwz5YbcH; Wed, 16 Oct 2024 14:32:07 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XTD1y6KQwz4Rch; Wed, 16 Oct 2024 14:32:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729089126; 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=OvVesz/kp6DO+yz24j2LIZRhvxir/hhwIq3xF5w1lX8=; b=ndQPhcNkjBUY03uPpxn1iB65i9wQJYRxXIAwvPJuuj42WXk10xo2zauge9veAE7z8M/Z0V KzFkpfuWmaWI2xC1yCh+5HejHJkJ01c2NiF+mBJz3L+y82jrnQcAJ4dFs1Y2sFw4FcbLgH P929/GNLucPP7uZIySMzBQFW8PScRXKz4ScgSrSu2duDyXFLOZlMfBvn4thmOMVQVbLVfm YPItdRYDWzQuMZsQ5gWCf/wAsHBl5Bu9PnzUlfRe/jlbcPGX0INRDabBWfCQLmX885n8Ip uH10KoAP6my4jId/zoycFS0min4ZJJGm/QUVAUIZhlrjjWCoUiOcea5fZiy+oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729089126; 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=OvVesz/kp6DO+yz24j2LIZRhvxir/hhwIq3xF5w1lX8=; b=N7KRsAPR6vDE1nEqOpvEqyrQjpsp/s3V47Pq5DB8Xln775+CQJe3UZ/+ZNlKCHYNrbpD7b YibPujrRymJVGPer4L+RG9Mm6pCx5GaWNAOYI89XNElhueQaipNiwNGOcbofrge6/rjRFy 1YjeMiGhWDiLTLRY3exujUjVZpKkttoSMgBsfD7U1p75zCSpqfaoN3pmNvVeAlWr6f8hSn e6qHFdKvYhWGpOduJmpR2scafiv9Ip1L6YNQJtdH5d2wJNQHHnK+d6OkI+4gaaTMBnYTq0 6xoqNpnavkuYkWKJ2tu/MdbPjtsjcYWUuDLFdCtvULz904ppquT+n9BHWXQM7g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729089126; a=rsa-sha256; cv=none; b=Hf+DhwKtatTYQGHw3RN5AKGrbmNZ5XInuRATuaAbtQU2PiZ57iBbcWHEG8g0hs0bvaviom WaLXSKfQfc4gp/0jZAtzo0qPpKdIPaR/71KvhKhS9TKAGAg+QcKSDtRcV03MADyMyLFg6q yO+FNcm/cwiq2AG35l5pZFcmsvLasPVIB3S9PoxX5/LfjuUc8mk1QT00Z+j5RiKgBxLSmv 4yICPTphijI1VbKV0q1AOKoF67Q0+owiN4gvZgXZrG3v12vFrbeWq4348xF+5OyqcLwMOj WoBvDCSTHEhu5O6FqwkAU3+j7Au4bPQYzT4DN5QqZwDh5N4dlaKka7aO6tH7Mg== 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 4XTD1y5Ymqz18Pw; Wed, 16 Oct 2024 14:32:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49GEW6WM089714; Wed, 16 Oct 2024 14:32:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49GEW6Su089711; Wed, 16 Oct 2024 14:32:06 GMT (envelope-from git) Date: Wed, 16 Oct 2024 14:32:06 GMT Message-Id: <202410161432.49GEW6Su089711@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 903ddc7f14bc - stable/14 - firmware: Allow binary files to be loaded by /boot/loader List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 903ddc7f14bc2f9977cec22e3f9f2f6c510b9538 Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=903ddc7f14bc2f9977cec22e3f9f2f6c510b9538 commit 903ddc7f14bc2f9977cec22e3f9f2f6c510b9538 Author: Warner Losh AuthorDate: 2024-02-29 16:36:31 +0000 Commit: Warner Losh CommitDate: 2024-10-16 14:19:21 +0000 firmware: Allow binary files to be loaded by /boot/loader Files loaded "-t firmware" (or module_type="firmware"). They are registered with the firmware system using the full path to the file. There's only one firmware per file, and it is the entire file. We do an extra firmware_get() on any firmware we find here to prevent them from ever being unloaded (we can't handle that case sanely). Sponsored by: Netflix Reviewed by: tsoome, jhb Differential Revision: https://reviews.freebsd.org/D43522 (cherry picked from commit 479905a1ed26c54ef29cdff65cf25f7feade654b) --- sys/kern/subr_firmware.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/sys/kern/subr_firmware.c b/sys/kern/subr_firmware.c index 138eb6a7fcd8..94538670e38c 100644 --- a/sys/kern/subr_firmware.c +++ b/sys/kern/subr_firmware.c @@ -162,6 +162,19 @@ lookup(const char *name) LIST_FOREACH(fp, &firmware_table, link) { if (fp->fw.name != NULL && strcasecmp(name, fp->fw.name) == 0) break; + + /* + * If the name looks like an absolute path, also try to match + * the last part of the string to the requested firmware if it + * matches the trailing components. This allows us to load + * /boot/firmware/abc/bca2233_fw.bin and match it against + * requests for bca2233_fw.bin or abc/bca2233_fw.bin. + */ + if (*fp->fw.name == '/' && strlen(fp->fw.name) > strlen(name)) { + const char *p = fp->fw.name + strlen(fp->fw.name) - strlen(name); + if (p[-1] == '/' && strcasecmp(name, p) == 0) + break; + } } return (fp); } @@ -549,6 +562,42 @@ restart: mtx_unlock(&firmware_mtx); } +/* + * Find all the binary firmware that was loaded in the boot loader via load -t + * firmware foo. There is only one firmware per file, it's the whole file, and + * there's no meaningful version passed in, so pass 0 for that. If version is + * needed by the consumer (and not just arbitrarily defined), the .ko version + * must be used instead. + */ +static void +firmware_binary_files(void) +{ + caddr_t file; + char *name; + const char *type; + const void *addr; + size_t size; + unsigned int version = 0; + const struct firmware *fw; + struct priv_fw *fp; + + file = 0; + for (;;) { + file = preload_search_next_name(file); + if (file == 0) + break; + type = (const char *)preload_search_info(file, MODINFO_TYPE); + if (type == NULL || strcmp(type, "firmware") != 0) + continue; + name = preload_search_info(file, MODINFO_NAME); + addr = preload_fetch_addr(file); + size = preload_fetch_size(file); + fw = firmware_register(name, addr, size, version, NULL); + fp = PRIV_FW(fw); + fp->refcnt++; /* Hold an extra reference so we never unload */ + } +} + /* * Module glue. */ @@ -567,6 +616,7 @@ firmware_modevent(module_t mod, int type, void *unused) /* NB: use our own loop routine that sets up context */ (void) taskqueue_start_threads(&firmware_tq, 1, PWAIT, "firmware taskq"); + firmware_binary_files(); if (rootvnode != NULL) { /* * Root is already mounted so we won't get an event;