Commit Graph

3358 Commits

Author SHA1 Message Date
Leah Rowe 1bbc6ac890 util/nvmutil: only open /dev/urandom on setmac
otherwise, it's a pointless computation

i also added a guard to mitigate this, in the
read file function. this should have been there
anyway.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 02:39:53 +00:00
Leah Rowe 9bd7d04b49 util/nvmutil: say what randomiser is used
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 02:34:26 +00:00
Leah Rowe c1bfe6a438 util/nvmutil: rename command.args to argc
that way, it makes more sense sementantically

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 02:20:13 +00:00
Leah Rowe bf30cdd021 util/nvmutil: fix mistake in command
accidentally specified invert, for the brick
and setchecksum commands. oops!

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 02:18:34 +00:00
Leah Rowe 4cdf22cf8f util/nvmutil: minor cleanup
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 02:16:30 +00:00
Leah Rowe 7c3a4e253f util/nvmutil: remove stale comment
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 02:08:40 +00:00
Leah Rowe 26a69321ac util/nvmutil: use enum for command index
if the enum is messed up, this patch also prevents
that. this is not to catch a runtime error, but
to intentionally trip up a maintainer that screws
up, prompting them to fix their future mistake.

we previously used a pointer directly, without
even checking index/NULL - that too is now covered,
except that we now use an indice for command[] and
execute the command from that, rather than directly
declaring a pointer.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 02:04:10 +00:00
Leah Rowe 1d17a8ffcf util/nvmutil: call it nvmutil in makefile
a package manager by the name "nvm" exists, as
i discovered.

this is a courtesy to them.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 01:11:52 +00:00
Leah Rowe 6203f3ae61 util/nvmutil: print mac before setting
this way, if a user does e.g.

./nvm gbe.bin bullshit

It will say: bullshit

Right now, it just says invalid length. This
means if the user wanted to type e.g.

./nvm gbe.bin copy 0

but they typed:

./nvm gbe.bin coyp 0

Now it will tell them that it's trying
to set the MAC address "coyp".

This is because if an invalid command is given,
it's treated as a MAC address instead. This is
by design, to allow e.g.

./nvm gbe.bin xx:1x:1x:xx:xx:xx

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 01:11:52 +00:00
Leah Rowe 698d39dd06 util/nvmutil: store invert in command struct
handle inversion directly there

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 00:21:58 +00:00
Leah Rowe 50e20fb8bf util/nvmutil: make cmd an integer
point directly to the command table.

run through an intermediary function to check
bounds, for safety.

this will allow me to then set things like
the invert config directly in that struct.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-08 00:16:45 +00:00
Leah Rowe 3148d31798 util/clarity: name the gbe file half size
we need only declare it in the centralised gbe_file_offset
function, which determines whether a write to the gbe file
falls specifically within the 4KB range that is the gbe
part.

it is always half of the gbe file size, and then the first
4KB of each half stores the gbe part.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 13:36:46 +00:00
Leah Rowe 96cb52f21a util/nvmutil: only have newrandom on linux/oldunix
these variables newrandom and oldrandom are unused on
BSD systems, and their unused status may trigger
warnings on some compilers.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 13:18:54 +00:00
Leah Rowe c195e8cc2b util/nvmutil: tidy up open_dev_urandom
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 10:07:05 +00:00
Leah Rowe 6a505c9162 util/nvmutil: correct type on hextonum()
use uint16_t instead

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 03:28:15 +00:00
Leah Rowe 50ce806dfa util/nvmutil: fix a comment
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 03:16:20 +00:00
Leah Rowe a0da88d361 util/nvmutil: fix a comment
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 03:08:31 +00:00
Leah Rowe ea1046dc46 util/nvmutil: unambiguous sign conv_argv_part_num
yeah, do the verification manually, don't convert
to size_t. this avoids a bunch of theoretical
bugs that i can't be bothered to explain at 3AM

just trust me bro

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 03:00:35 +00:00
Leah Rowe b98f89c272 util/nvmutil: clean up hextonum()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 02:50:30 +00:00
Leah Rowe b8bd1ca65a util/nvmutil: tidy up some comments
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 02:44:11 +00:00
Leah Rowe 49eca198da util/nvmutil: make mac_updated a uint8_t
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 02:38:36 +00:00
Leah Rowe ef2937edbd util/nvmutil: fix prototype indentation
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 02:37:46 +00:00
Leah Rowe 7bfe134a19 util/nvmutil: reset mac_buf for mac parsing
preventative fix for later, if the tool is ever expanded
to have a better command syntax, for supporting more than
one file at a time.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 02:35:03 +00:00
Leah Rowe 14ad5a9818 util/nvmutil: comment the unhandled errno exit
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 02:09:56 +00:00
Leah Rowe 90bd395cb1 util/nvmutil: tidy up set_mac_byte
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 02:05:57 +00:00
Leah Rowe 4619dad0b7 util/nvmutil: further mac address parsing cleanup
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 02:00:14 +00:00
Leah Rowe 921144856c util/nvmutil: tidy up mac parsing code
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 01:39:57 +00:00
Leah Rowe 86357dbe52 util/nvmutil: fix a bad comment
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 01:28:50 +00:00
Leah Rowe 7e88f53e99 util/nvmutil: tidy up set_mac_byte
send the mac address byte directly to check_mac_separator

functionally identicaly, but cleaner, and uses
multiplication instead of division (faster).

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 01:21:29 +00:00
Leah Rowe c02f3166bb util/nvmutil: make do_read a uint8_t
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 01:11:07 +00:00
Leah Rowe a9f5cbb542 util/nvmutil: clearer commenting about commands
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 01:09:52 +00:00
Leah Rowe 0084452c4a util/nvmutil: comment regarding buf
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 01:01:44 +00:00
Leah Rowe 364abddeab util/nvmutil: minor code cleanup
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 00:52:57 +00:00
Leah Rowe 68d689336b util/nvmutil: fix an err string
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 00:10:36 +00:00
Leah Rowe 658ed55bc1 util/nvmutil: tidy up conv_argv_part_num
no need for strlen here (1-character string).

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 00:08:17 +00:00
Leah Rowe 330b2da20c util/nvmutil: Shorten a comment
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 00:04:57 +00:00
Leah Rowe 58182b48c3 util/nvmutil: fix a bad comment
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 00:03:10 +00:00
Leah Rowe 884a6779f9 util/nvmutil: make gbe_st local, not static/global
forgot to remove static when making it local

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-07 00:01:27 +00:00
Leah Rowe 44e6b00626 util/nvmutil: rename rfd to urandom_fd
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-06 23:58:04 +00:00
Leah Rowe 9e5736baa9 util/nvmutil: remove reset_global_state
it was put there for another change i haven't done yet,
and probably won't. the program currently just runs once
with one operation, on a given file.

the current defaults are initialised just fine without
this function, so let's remove this bloat for now.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-06 23:56:19 +00:00
Leah Rowe 13b35ed1fc util/nvmutil: rename arc4random define
specifically refer to the actual function i use.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-06 23:51:57 +00:00
Leah Rowe 79c972367e util/nvmutil: reset errno on /dev/random fallback
i didn't catch this before. stale error state would
have passed through, even on ultimate success.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-06 23:50:06 +00:00
Leah Rowe 6e47315192 util/nvmutil: remove rval from conv_argv_part_num
relic from an earlier uncommitted version

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-06 23:42:33 +00:00
Leah Rowe 85b09c4275 util/nvmutil: set part_modified to a uint8_t
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-06 23:15:50 +00:00
Leah Rowe e5b108a764 util/nvmutil: make invert a uint8_t
cleaner intention, and shorter

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-06 23:14:26 +00:00
Leah Rowe 69c4d70650 util/nvmutil: safer argv part number parsing
we now handle signedness properly, which is implementation
defined, on char integers where signed/unsigned is not
specified.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-06 23:07:29 +00:00
Leah Rowe 9b6f2a2f7e util/nvmutil: rename check_bound check_nvm_bound
this makes the intent clearer, because we only want to
access the 128-byte nvm area here.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-06 22:39:43 +00:00
Leah Rowe a7d7f68a5c util/nvmutil: be clearer about GbE file sizes
the partsize variable is also misleading, because it
refers to the full half of a file, which might be
bigger than 4KB. this variable name is a hangover
from when nvmutil only supported 8KB files.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-06 22:36:08 +00:00
Leah Rowe e273391792 util/nvmutil: rename fd to fd_ptr in xopen()
clearer intent

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-06 22:26:22 +00:00
Leah Rowe 4635a0eae9 util/nvmutil: cleaned up a few prototypes
make them match how they're declared

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-06 22:20:15 +00:00