From 4fc47a7985cb462b660a55a2861e1e094fbc21f4 Mon Sep 17 00:00:00 2001 From: afresh1 Date: Fri, 26 Dec 2025 18:19:46 +0000 Subject: [PATCH] Scan both dmesg.boot and dmesg(8) output for devices This allows us to detect newly plugged in devices that need firmware added while still making sure to detect devices available at boot even if dmesg rolls over with noisy messages. fixes and ok kn@ I think this is good deraadt@ --- usr.sbin/fw_update/fw_update.8 | 12 ++++++------ usr.sbin/fw_update/fw_update.sh | 22 +++++++++++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/usr.sbin/fw_update/fw_update.8 b/usr.sbin/fw_update/fw_update.8 index 99b99475c8a..a533cff9862 100644 --- a/usr.sbin/fw_update/fw_update.8 +++ b/usr.sbin/fw_update/fw_update.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fw_update.8,v 1.8 2025/03/22 19:51:29 jmc Exp $ +.\" $OpenBSD: fw_update.8,v 1.9 2025/12/26 18:19:46 afresh1 Exp $ .\" .\" Copyright (c) 2011 Alexander Hall .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: March 22 2025 $ +.Dd $Mdocdate: December 26 2025 $ .Dt FW_UPDATE 8 .Os .Sh NAME @@ -59,11 +59,11 @@ If used in conjunction with .Fl a , delete firmware for all drivers. .It Fl D Ar path -Use the -.Xr dmesg 8 -output from +Use the content of .Ar path -rather than +rather than output from +.Xr dmesg 8 +and .Pa /var/run/dmesg.boot to determine which firmware are needed. .It Fl F diff --git a/usr.sbin/fw_update/fw_update.sh b/usr.sbin/fw_update/fw_update.sh index 3a36205ddbc..596fa3ae6a5 100644 --- a/usr.sbin/fw_update/fw_update.sh +++ b/usr.sbin/fw_update/fw_update.sh @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: fw_update.sh,v 1.65 2025/05/12 23:48:12 afresh1 Exp $ +# $OpenBSD: fw_update.sh,v 1.66 2025/12/26 18:19:46 afresh1 Exp $ # # Copyright (c) 2021,2023 Andrew Hewus Fresh # @@ -239,12 +239,25 @@ verify_existing() { } devices_in_dmesg() { + if [ "${DMESG:-}" ]; then + _devices_in_dmesg "$DMESG" + return + fi + + dmesg > "$FD_DIR/dmesg" + + _devices_in_dmesg /var/run/dmesg.boot + _devices_in_dmesg "$FD_DIR/dmesg" +} + +_devices_in_dmesg() { + local _dmesg=$1 local IFS local _d _m _dmesgtail _last='' _nl=' ' # The dmesg can contain multiple boots, only look in the last one - _dmesgtail="$( echo ; sed -n 'H;/^OpenBSD/h;${g;p;}' "$DMESG" )" + _dmesgtail="$( echo ; sed -n 'H;/^OpenBSD/h;${g;p;}' "$_dmesg" )" grep -v '^[[:space:]]*#' "$FWPATTERNS" | while read -r _d _m; do @@ -489,7 +502,7 @@ set_fw_paths() { if [ ! "$_version" ]; then _version=$(sed -nE \ '/^OpenBSD ([0-9]+\.[0-9][^ ]*) .*/{s//\1/;h;};${g;p;}' \ - "$DMESG") + "${DMESG:-/var/run/dmesg.boot}") # If VNAME was set in the environment instead of the DMESG, # looking in the DMESG for "current" is wrong. @@ -514,7 +527,6 @@ usage() { ALL=false LIST=false -DMESG=/var/run/dmesg.boot while getopts :adD:Flnp:v name do @@ -561,7 +573,7 @@ if [ "${FWURL:-}" ] && ! "$INSTALL" ; then usage fi -if [ ! -s "$DMESG" ]; then +if [ "${DMESG:-}" ] && [ ! -s "$DMESG" ]; then warn "${0##*/}: $DMESG: No such file or directory" exit 1 fi