Commit Graph

3785 Commits

Author SHA1 Message Date
Leah Rowe
5ba0b98fbc util/nvmutil: correct install usage
one for directory, then copy the binary

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 14:01:24 +00:00
Leah Rowe
35ba3aef91 util/nvmutil: fix makefile
forgot to include the binary in the path

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 13:56:47 +00:00
Leah Rowe
af1a219e40 util/nvmutil: remove errno extern
may break modern systems. and all old systems that
i care about will handle errno just fine.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 13:54:04 +00:00
Leah Rowe
8269b05a63 util/nvmutil: use install -d instead of mkdir -p
-p isn't portable

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 13:53:02 +00:00
Leah Rowe
e931f66b99 util/nvmutil: fix comment
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 13:48:53 +00:00
Leah Rowe
fe630cba5e util/nvmutil: use chmod instead, in Makefile
yeah, why not use a tool that's been around since the
80s?

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 13:43:20 +00:00
Leah Rowe
478c994f34 util/nvmutil: add -m to install on Makefile
also support LDFLAGS

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 13:42:12 +00:00
Leah Rowe
ea4deb98b5 util/nvmutil: simplify flags on urandom
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 13:31:35 +00:00
Leah Rowe
55e071c381 util/nvmutil: fix mistake in random check
forgot this. oops

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 13:28:18 +00:00
Leah Rowe
a9e5f9ef4f util/nvmutil: portable errno
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 13:25:35 +00:00
Leah Rowe
87b74aadbc util/nvmutil: fix non-portable variable declaration
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 13:22:30 +00:00
Leah Rowe
1184dcb05c util/nvmutil: disable urandom if not found
disable random mac address generation on really old
operating systems.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 13:21:03 +00:00
Leah Rowe
74f2d9a1f3 util/nvmutil: use ECANCELED on checksum err
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 13:10:10 +00:00
Leah Rowe
a40d14fcd6 util/nvmutil: don't use errno for program state
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 12:52:22 +00:00
Leah Rowe
a4f5061297 util/spkmodem-recv: code cleanup
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 07:13:42 +00:00
Leah Rowe
2479633368 util/spkmodem-recv: optimise pulse check
the last change was good, but this code, again,
has to do these calculations 48,000 times a second.

trivial on new computers. but now try it on a
computer from 1992.

we should try to make this as fast as possible :)

older compilers especially don't optimise these
checks. this patch shifts it to one subtraction and
one unsigned comparison, rather than checking less
than or greater than both. often used in... literally
exactly this type of program.

on a good compiler this will compile to an add, cmp
and conditional jump.

less readable, but the results (set 1 or 0) make it
pretty obvious what it does, after a few seconds.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 05:31:44 +00:00
Leah Rowe
e23cecb496 util/spkmodem-recv: clearer pulse decoding
i turned this into abs() call earlier, but this isn't
obviously readable by some people.

make it absolutely clear what this does. also reduces
use of syscalls.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 05:28:34 +00:00
Leah Rowe
1d2ee1cabc util/spkmodem-recv: say what freq_sep/data are
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 05:25:24 +00:00
Leah Rowe
fcecb1229e util/spkmodem-recv: add a usage function
replace the err call in getopt

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 05:22:25 +00:00
Leah Rowe
69fb0618cc util/spkmodem-recv: tidy up the getopt loop
more knf-compliant

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 05:20:09 +00:00
Leah Rowe
65a6205dab util/spkmodem-recv: allow short sample reads
fread() may return short reads, whereas the current
code assumes either EOF or a full read.

change if to a while. really, it's that simple.
just loop until it's done. i probably b0rked this
myself when refactoring the GNU code.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 05:17:09 +00:00
Leah Rowe
59f04eba9e util/spkmodem-recv: don't exit in print_stats
i treated ftell errors as fatal, but if fttell fails
with ESPIPE, and someone's using -d, the program may
exit immediately, even though there's no problem.

instead, skip printing the offset (basically no debug).

this fixes a bug that i introduced myself, when i forked
this code, because i added that error check; the GNU
code didn't have any check whatsoever.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 05:13:44 +00:00
Leah Rowe
9ac0331595 util/spkmodem-recv: buffer calls to fread()
we currently read small amounts of data with fread,
repeatedly, which is quite taxing on the CPU, on
very old systems.

48khz audio. 48000 calls to fread() per second?

yeah. let's optimise this.

performance now should be roughly O(1) in practise.
this and the other recent changes means no modulo
or division, reduced branching, memory memory roads,
and lots of buffering.

the buffering here is quite conservative, so the human
won't notice any difference. we're cutting the number
of times we call fread by a factor of several thousand,
but you'll still see text scrolling down pretty quick,
with minimal lag.

the old GNU code i forked was terrible at this.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 05:08:44 +00:00
Leah Rowe
2c3d0b5a3e util/spkmodem-recv: make new pulse calculation clearer
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 04:59:42 +00:00
Leah Rowe
62a496ec9e util/spkmodem-recv: tidy up pulse decoding
make it clearer about next/old, in the loop. this also
improves performance on older systems (cache the values
first, don't re-calculate)

again, this is GNU code. but you wouldn't know it, in my
current version. i forked this from GRUB several years
ago and started cleaning it for fun.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 04:55:18 +00:00
Leah Rowe
1953812efd util/spkmodem-recv: split up handle_audio()
the signal check should be its own function,
for clearer understanding

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 04:53:05 +00:00
Leah Rowe
a31ccd8c3d util/spkmodem-recv: tidy up handle_audio
frame handling, error checks, pulse decoding and
character decoding are all jumbled up. this patch
separates them a bit, making it clearer.

should also help codegen. this tool is dealing with
high bandwidth text, which on slower computers may
be cumbersome. every optimisation counts.

not really relevant on newer systems.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 04:49:03 +00:00
Leah Rowe
44c6b453bc util/spkmodem-recv: optimise ring buffer pos calc
instead of computing next every time, just advance
two indexes. another performance optimisation on
older machines, especially old compilers, because
it reduces the amount of logical branching.

the old code was pretty much just advancing two
indexes in lockstep, when getting the next pulse,
but recalculating one of them based on the other,
each time.

this is yet another hangover from the old GNU code
that i forked three years ago.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 04:44:44 +00:00
Leah Rowe
54936a45a5 util/spkmodem-recv: don't use modulus on decode
it's slow on older compilers/systems that don't optimise.

instead, we branch (cheaper) and just do an above or
equal comparison), resetting appropriately or subtracting.

should yield an actually useful performance gain, on older
systems. a bit theoretical on modern systems, which optimise
well (modern compilers will produce assembly code much like
what the new C code is doing)

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 04:39:00 +00:00
Leah Rowe
19e0249a8a spkmodemrecv makefile: add -c to install
a bit pedantic. but that's my intention.

for backwards compatibility with older systems.

this flag means: create the directory. on modern
versions on all systems, it's the default behaviour.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 04:36:29 +00:00
Leah Rowe
72eed0b12c util/spkmodem-recv: further portability / cleanup
i used a bunch of global variables. that's gone.

added proper externs, including for errno. lots of
old unix systems require this. this version should
be perfectly polished and portable now.

all status is now handled in a struct, making the
code a bit easier to understand, because the variables
now are clearly pertinent to the state of the decoder,
rather than being seemingly random.

some indentation reduced.

also cleaned up ftell/feof usage again. the new code
is a bit more robust when dealing with piped input(which
is literally what this program takes, exclusively)

i started my cleanup of this tool from GNU GRUB in 2023.

i finished it today.

also the Openbsd pledge is more portable now (code made
to compile on pre-pledge openbsd as well)

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-12 04:30:40 +00:00
Leah Rowe
bbb8825553 util/nvmutil: further clean up decode_pulse()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 23:40:34 +00:00
Leah Rowe
42cad20ffd util/spkmodem-recv: tidy up frame decoding
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 23:34:43 +00:00
Leah Rowe
bf9c4a67f8 util/spkmodem-recv: handle fread errors
also handle EOF condition and exit cleanly.

don't use dirty feof.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 23:30:22 +00:00
Leah Rowe
9195ff97b7 util/spkmodem-recv: fix getopt prototype
i use -pedantic and std=c90

also add the define

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 23:25:50 +00:00
Leah Rowe
62c0cc68c5 removed some unnecessary things
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 23:14:51 +00:00
Leah Rowe
361dbef41c another fix
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 23:13:33 +00:00
Leah Rowe
7af3015a89 tiny fix
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 23:12:27 +00:00
Leah Rowe
6962404ce5 util/spkmodem-recv: portability and code cleanup
borrowing recent improvements from nvmutil

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-11 22:39:16 +00:00
Leah Rowe
977c83873e util/nvmutil: re-use do_rw() from prw()
using a special leah-only technique

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 18:20:47 +00:00
Leah Rowe
5f8fe4fdc3 util/nvmutil: add missing sanitization tests
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 17:17:39 +00:00
Leah Rowe
48f65abb01 util/nvmutil: properly use rc in rw_File_exact
subtract and add iteratively

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:57:46 +00:00
Leah Rowe
9eb3895f4e util/nvmutil: tidy up gbe_cat_buf()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:52:38 +00:00
Leah Rowe
69cf4fe6ed util/nvmutil: split up rw_file_exact()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:43:47 +00:00
Leah Rowe
454af12153 util/nvmutil: update some comments
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:25:43 +00:00
Leah Rowe
1403bdf1cc util/nvmutil: re-add EINTR loop check on rw
accidentally removed it during re-factor

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:17:33 +00:00
Leah Rowe
f0240df229 util/nvmutil: rename set_err for code clarity
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:14:43 +00:00
Leah Rowe
c41483916a util/nvmutil: skip errno check in main
skip it if there is a valid checksum, to mitigate
erroneous errno state upon exit from run_cmd(),
because we can assume by this point that we
are in fact ready to write at this point.

the check at the end still exists, which will catch
any error set by write, and any error set before
that. this fixes a weird warning on cmd_dump.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:06:13 +00:00
Leah Rowe
13c759bf3a util/nvmutil: don't reset errno in rw_file_exact
reset it in callers instead.

this means that the main function is more generalised.

we know by the time we exit that there is no error.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:02:57 +00:00
Leah Rowe
82dbeb9736 util/nvmutil: reset errno in gbe_cat
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-10 16:00:16 +00:00