Download raw body.
fw_update(8) use local patterns and dmesg for testing
On Fri, Nov 08, 2024 at 07:12:40PM -0800, Andrew Hewus Fresh wrote:
> Here is a change to be used for testing changes to patterns.c. The idea
> is that if you are modifying the patterns you want to know what they
> match. Since I just committed support for listing with -l (although you
> could have used dry-run) it would work something like this.
>
> $ cd /usr/src/usr.sbin/fw_update
> $ make firmware_patterns
> $ ksh ./fw_update.sh -l
>
> However, sometimes your development machine isn't the same as the one
> you are adding firmware for. Or maybe you are testing the dmesg from
> the installer, but getting that dmesg is left as an exercise for the
> reader.
>
> $ # assuming we've done the steps above
> $ scp weird-machine:/var/run/dmesg.boot dmesg
> $ ksh ./fw_update.sh -l
>
>
> Comments, questions, OK?
>
> How should I document this? A comment in patterns.c? Something else?
>
> Should I use flags ("-D /path/to/dmesg" and "-P /path/to/patterns")
> instead of just doing it?
Here it is again with a comment in the patterns file that folks may see
when they edit it.
Index: patterns.c
===================================================================
RCS file: /cvs/src/usr.sbin/fw_update/patterns.c,v
diff -u -p -r1.16 patterns.c
--- patterns.c 30 Oct 2024 00:04:46 -0000 1.16
+++ patterns.c 23 Nov 2024 03:39:19 -0000
@@ -43,6 +43,18 @@
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
+/*
+ * 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`
+ */
+
const char *
pci_findvendor(pci_vendor_id_t vendor)
{
Index: fw_update.sh
===================================================================
RCS file: /cvs/src/usr.sbin/fw_update/fw_update.sh,v
diff -u -p -r1.61 fw_update.sh
--- fw_update.sh 9 Nov 2024 02:40:57 -0000 1.61
+++ fw_update.sh 23 Nov 2024 03:39:19 -0000
@@ -20,15 +20,26 @@ set +o monitor
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
CFILE=SHA256.sig
+DMESG=/var/run/dmesg.boot
DESTDIR=${DESTDIR:-}
FWPATTERNS="${DESTDIR}/usr/share/misc/firmware_patterns"
VNAME=${VNAME:-$(sysctl -n kern.osrelease)}
VERSION=${VERSION:-"${VNAME%.*}${VNAME#*.}"}
+if [ "${0##*/}" == fw_update.sh ] && [ -e firmware_patterns ]; then
+ FWPATTERNS=$PWD/firmware_patterns
+ echo "Using patterns from $FWPATTERNS" >&2
+
+ if [ -e dmesg ]; then
+ DMESG=$PWD/dmesg
+ echo "Using dmesg from $DMESG" >&2
+ fi
+fi
+
HTTP_FWDIR="$VNAME"
VTYPE=$( sed -n "/^OpenBSD $VNAME\([^ ]*\).*$/s//\1/p" \
- /var/run/dmesg.boot | sed '$!d' )
+ "$DMESG" | sed '$!d' )
[ "$VTYPE" = -current ] && HTTP_FWDIR=snapshots
FWURL=http://firmware.openbsd.org/firmware/${HTTP_FWDIR}
@@ -251,7 +262,7 @@ firmware_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
fw_update(8) use local patterns and dmesg for testing