Commit Graph

3432 Commits

Author SHA1 Message Date
Leah Rowe
f2a5f2de45 move nvmutil .gitignore rules to util/nvmutil/
i plan to release this as a standalone utility at
some point, once it's perfect (on its current
feature set)

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 14:38:21 +00:00
Leah Rowe
7e0b052412 util/nvmutil: remove empty ChangeLog/README
i will write a *manpage* at some point. for now, the
documentation on libreboot.org shall suffice.

i'm nearly ready to submit this code to coreboot.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 14:35:44 +00:00
Leah Rowe
f05a273cb4 util/nvmutil: clean up the Makefile
that option there is already defined in the code

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 14:33:21 +00:00
Leah Rowe
3f566d3250 util/nvmutil: tidy up the main comment header
merge it into one

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 14:32:15 +00:00
Leah Rowe
4fd6bdc4ef util/nvmutil: say what the program does!
and with this, i'm probably done for a while

i've obsessively audited this code for a week

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 07:03:55 +00:00
Leah Rowe
f266e2a16c util/nvmutil: standardised Makefile (add all)
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 06:46:12 +00:00
Leah Rowe
c96254be8b util/nvmutil: Makefile cleanup
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 06:38:18 +00:00
Leah Rowe
6a4ad68273 util/nvmutil: add phone section to Makefile
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 06:33:52 +00:00
Leah Rowe
ec1e6bd7e8 util/nvmutil: safer / more portable install
explicitly declare the directory path for the given
file (nvmutil), otherwise it's implementation-defined;
on some systems, /bin/nvmutil means a directory named
nvmutil could then contain nvmutil.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 06:31:52 +00:00
Leah Rowe
1446df01f2 util/nvmutil: create install dir in Makefile
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 06:30:14 +00:00
Leah Rowe
9f75a23a84 util/nvmutil: fix target in Makefile
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 06:28:50 +00:00
Leah Rowe
d0bf316edf util/nvmutil: directly compare fd/urandom_fd
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 06:24:22 +00:00
Leah Rowe
dbc7fadcbc util/nvmutil: allow partial reads of /dev/urandom
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 06:09:34 +00:00
Leah Rowe
e092b2ce0b util/nvmutil: explicit cast in nvm_word
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 05:31:51 +00:00
Leah Rowe
3b73ea4288 util/nvmutil: clarify CFLAGS in code
makefile is correct, but lots of people don't read it.

putting it iin code helps people avoid confusion.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 05:25:58 +00:00
Leah Rowe
3b188b4d2b util/nvmutil: specifically enable -std=c99
I also needed: #define _POSIX_C_SOURCE 200809L

I use -pedantic with -Wall -Wextra -Werror, which
forces very strict error handling and ISO C; this
means pread and pwrite aren't available.

The define fixes this.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 05:18:53 +00:00
Leah Rowe
532d723ccd util/nvmutil: fix indentation in setmac
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 04:37:48 +00:00
Leah Rowe
14c2588772 util/nvmutil: err sooner, on bad command
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 04:04:12 +00:00
Leah Rowe
1a60eabcfe util/nvmutil: print expected checksums
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 03:56:50 +00:00
Leah Rowe
c27f8b709a util/nvmutil: rename cmd helper functions
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 03:29:08 +00:00
Leah Rowe
2cf1d1bed8 util/nvmutil: remove MAC address short-commands
only allow the long form: setmac [MAC]

specifying gbe.bin just shows the help/usage now.
this is a safety feature, so that someone doesn't
accidentally write the gbe file. we want it to be
that the user specifically requested setmac.

setmac with mac address as the 3rd argument is
also disabled. this is done as part of a general
simplification and safety improvement to nvmutil.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 03:25:33 +00:00
Leah Rowe
aeb076b30e util/nvmutil: remove cmd_brick
this is an extremely dangerous feature, and serves
no purpose to the user.

this change is part of a series of extreme safety
improvements, part of a larger nvmutil audit.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 02:23:22 +00:00
Leah Rowe
0c64907a9e util/nvmutil: remove the setchecksum command
This feature is extremely dangerous, and we should
discourage against its use.

This is part of a series of changes that I've made
to make the code safer. You should only ever run
this on a valid GbE file, and nothing else.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 02:19:24 +00:00
Leah Rowe
f7dfb0d265 util/nvmutil: re-order functions by execution
linear, top-down order. re-order the prototypes

also some general cleanup:

argc enums now validated. ifdefs for pledge
and arc4random now use a consistent naming
scheme.

feature change:

the "dump" command now fails if both checksums
are invalid, and won't show anything.

my next commit will disable setchecksum when
both checksums are invalid. this and the other
insane auditing i've done over the last few
days has been part of a major effort to make
nvmutil extremely safe, and robust.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 02:12:28 +00:00
Leah Rowe
a6e271c86d util/nvmutil: unified checksum update
setchecksum and setmac update the checksum.

other commands don't.

this patch unified the logic, handling it
in write_gbe based on command[].chksum_write

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 01:20:59 +00:00
Leah Rowe
39cdd562d8 util/nvmutil: don't pledge on OLD openbsd
only pledge/unveil where available, on versions
that have it. this patch disables it on older
versions, allowing nvmutil to compile.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-09 00:20:30 +00:00
Leah Rowe
db440bd71d util/nvmutil: make write_mac_part() a void
its return value is never used, in the current code.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 23:42:11 +00:00
Leah Rowe
5dc3f323c3 util/nvmutil: fix typo in message
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 23:40:12 +00:00
Leah Rowe
07f9f607ab util/nvmutil: don't re-calculate skip_part
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 23:39:13 +00:00
Leah Rowe
dbd4d6d84a util/nvmutil: limit rw size on specific commands
i previously had this as a speed optimisation, but
removed it because it wouldn't make any real speed
difference, on most modern file systems / kernels.

however, this also has the dual purpose of ensuring
only what was verified gets written, on operations
that only touch the NVM area, since this relies on
checksum verification.

therefore, i have re-added this feature, but under
the new design of nvmutil. it is done policy-based,
instead of having if/else for specific commands.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 23:32:08 +00:00
Leah Rowe
70da9c3940 util/nvmutil: better error message for bin check
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 23:06:01 +00:00
Leah Rowe
4d6732dade util/nvmutil: EINTR looping on write_gbe_file
up to a maximum number of retries

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 23:03:42 +00:00
Leah Rowe
163bf8beac util/nvmutil: clean up obsessive comments
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 22:41:03 +00:00
Leah Rowe
848d575cea util/nvmutil: policy-only cmd_swap and cmd_copy
their functions now only return. not needed anymore.

these commands are still available, but they no longer
need helper functions.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 22:17:25 +00:00
Leah Rowe
61188ee9dc util/nvmutil: remove redundant checksum checks
we centralise this now. better not to over-engineer
our over-engineering.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 22:11:39 +00:00
Leah Rowe
c012d4ea5b util/nvmutil: clean up a few binary checks
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 22:06:09 +00:00
Leah Rowe
bd64d118f5 util/nvmutil: fix check in set_err()
errno must never be negative

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 21:37:53 +00:00
Leah Rowe
61e7147505 util/nvmutil: fix bad arc4random check
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 21:16:18 +00:00
Leah Rowe
c425c74c54 util/nvmutil: improved clarity on checksum check
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 21:03:06 +00:00
Leah Rowe
6abc150e89 util/nvmutil: close files in err()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 20:57:30 +00:00
Leah Rowe
840f79fd82 util/nvmutil: only close gbe fd if opened
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 20:50:44 +00:00
Leah Rowe
1400508400 util/nvmutil: generalised checksum verification
the existing verification is retained, an a few commands.

this is an additional security mechanism. redundancy is
best.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 20:43:57 +00:00
Leah Rowe
3330f005fd util/nvmutil: validate ARG_PART and ARG_NOPART
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 17:57:28 +00:00
Leah Rowe
5532a721f5 util/nvmutil: clean up some code
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 17:54:26 +00:00
Leah Rowe
35ffe64765 util/nvmutil: fix 3-arg setmac
3-arg arguments were broken, by recent generalisations.

this should fix it.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 17:48:22 +00:00
Leah Rowe
a0829f7a27 util/nvmutil: simplified exit error
no more command-specific logic here. this should be the
same in the rest of the code now.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 17:24:25 +00:00
Leah Rowe
624ecc4ce1 util/nvmutil: generalise skip-read on copy/brick
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 17:20:36 +00:00
Leah Rowe
dd320601c2 util/nvmutil: remove redundant code
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 17:06:41 +00:00
Leah Rowe
3c55808e27 util/nvmutil: call usage() on cmd validation err
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 16:53:24 +00:00
Leah Rowe
37c04ac218 util/nvmutil: generalised cmd copy/swap
now they only set checksums.

and generalised checksumming is next!

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 16:06:33 +00:00