Index | Thread | Search

From:
Andrew Hewus Fresh <andrew@afresh1.com>
Subject:
Re: fw_update(8) use local patterns and dmesg for testing
To:
tech@openbsd.org
Date:
Sun, 24 Nov 2024 17:35:26 -0800

Download raw body.

Thread
  • Stuart Henderson:

    fw_update(8) use local patterns and dmesg for testing

  • On Sat, Nov 23, 2024 at 11:05:39AM +0000, Stuart Henderson wrote:
    > On 2024/11/22 19:40, Andrew Hewus Fresh wrote:
    > > + * Testing changes:
    > > + *
    > > + * For testing, fw_update(8) has a special case for when it is named
    > > + * "fw_update.sh" and "firmware_patterns" exists in the current
    > > + * directory.  It uses those patterns instead of the default.  If
    > > + * there is also a file called "dmesg" it will use that instead.
    > > + *
    > > + * `make firmware_patterns          && ksh ./fw_update.sh`
    > > + * `scp other-host:/var/run/dmesg . && ksh ./fw_update.sh`
    > 
    > I don't think firmware_patterns hugely needs anything special, you can
    > install it on a test machine easily enough.
    > 
    > For using an alternative dmesg (which _is_ useful for testing), special
    > magic based on the filename seems an awkward way to do it. How about
    > adding a flag to specify the path to the file containing dmesg instead?
    > That would allow writing some tests feeding fw_update -l -n with various
    > dmesg, too.
    
    So, something like this?
    
    
    Index: fw_update.8
    ===================================================================
    RCS file: /cvs/src/usr.sbin/fw_update/fw_update.8,v
    diff -u -p -r1.6 fw_update.8
    --- fw_update.8	9 Nov 2024 02:19:48 -0000	1.6
    +++ fw_update.8	25 Nov 2024 01:32:34 -0000
    @@ -57,6 +57,11 @@ a driver.
     If used in conjunction with
     .Fl a ,
     delete firmware for all drivers.
    +.It Fl D Ar path
    +Detect firmware from the
    +.Xr dmesg 8
    +at
    +.Ar path .
     .It Fl F
     Download SHA256.sig and firmware .tgz to the current directory.
     .It Fl l
    Index: fw_update.sh
    ===================================================================
    RCS file: /cvs/src/usr.sbin/fw_update/fw_update.sh,v
    diff -u -p -r1.62 fw_update.sh
    --- fw_update.sh	24 Nov 2024 21:27:04 -0000	1.62
    +++ fw_update.sh	25 Nov 2024 01:32:34 -0000
    @@ -26,13 +26,10 @@ FWPATTERNS="${DESTDIR}/usr/share/misc/fi
     VNAME=${VNAME:-$(sysctl -n kern.osrelease)}
     VERSION=${VERSION:-"${VNAME%.*}${VNAME#*.}"}
     
    -HTTP_FWDIR="$VNAME"
    -VTYPE=$( sed -n "/^OpenBSD $VNAME\([^ ]*\).*$/s//\1/p" \
    -    /var/run/dmesg.boot | sed '$!d' )
    -[ "$VTYPE" = -current ] && HTTP_FWDIR=snapshots
    -
    -FWURL=http://firmware.openbsd.org/firmware/${HTTP_FWDIR}
    -FWPUB_KEY=${DESTDIR}/etc/signify/openbsd-${VERSION}-fw.pub
    +unset DMESG
    +unset HTTP_FWDIR
    +unset FWURL
    +unset FWPUB_KEY
     
     DRYRUN=false
     integer VERBOSE=0
    @@ -251,7 +248,7 @@ devices_in_dmesg() {
     '
     
     	# The dmesg can contain multiple boots, only look in the last one
    -	_dmesgtail="$( echo ; sed -n 'H;/^OpenBSD/h;${g;p;}' /var/run/dmesg.boot )"
    +	_dmesgtail="$( echo ; sed -n 'H;/^OpenBSD/h;${g;p;}' "$DMESG" )"
     
     	grep -v '^[[:space:]]*#' "$FWPATTERNS" |
     	    while read -r _d _m; do
    @@ -496,11 +493,14 @@ usage() {
     
     ALL=false
     LIST=false
    -while getopts :adFlnp:v name
    +DMESG=/var/run/dmesg.boot
    +
    +while getopts :adD:Flnp:v name
     do
     	case "$name" in
     	a) ALL=true ;;
     	d) DELETE=true ;;
    +	D) DMESG="$OPTARG" ;;
     	F) INSTALL=false ;;
     	l) LIST=true ;;
     	n) DRYRUN=true ;;
    @@ -523,6 +523,19 @@ shift $((OPTIND - 1))
     
     # Progress bars, not spinner When VERBOSE > 1
     ((VERBOSE > 1)) && ENABLE_SPINNER=false
    +
    +if [ ! -s "$DMESG" ]; then
    +	warn "${0##*/}: $DMESG: No such file or directory"
    +	exit 1
    +fi
    +
    +HTTP_FWDIR="$VNAME"
    +VTYPE=$( sed -n "/^OpenBSD $VNAME\([^ ]*\).*$/s//\1/p" \
    +    "$DMESG" | sed '$!d' )
    +[ "$VTYPE" = -current ] && HTTP_FWDIR=snapshots
    +
    +FWURL=http://firmware.openbsd.org/firmware/${HTTP_FWDIR}
    +FWPUB_KEY=${DESTDIR}/etc/signify/openbsd-${VERSION}-fw.pub
     
     if [[ $FWURL != @(ftp|http?(s))://* ]]; then
     	FWURL="${FWURL#file:}"
    
    
    
  • Stuart Henderson:

    fw_update(8) use local patterns and dmesg for testing