Leah Rowe
331a1af6df
util/nvmutil: add rule to create lib objdir
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:42 +00:00
Leah Rowe
a5a4e3d215
nvmutil: move lib files to lib/
...
only keep nvmutil.c in main
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:42 +00:00
Leah Rowe
275f8e6f05
util/nvmutil: put objects in obj/
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:42 +00:00
Leah Rowe
98aa88ad44
nvmutil makefile: use portable assignments
...
question mark respects environmental variables
but isn't portable
you can just pass as argument on the command line
question mark is more useful for build systems,
but i'm not really bothered. the old way works.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:42 +00:00
Leah Rowe
0fea4f69e0
nvmutil: split nvmutil.c into multiple files
...
this is a big program now. act like it.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:42 +00:00
Leah Rowe
3871b60124
util/nvmutil: default to clang on make-hell
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:42 +00:00
Leah Rowe
2fe71dfb90
nvmutil: add suffixes to makefile
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:42 +00:00
Leah Rowe
2457944d75
nvmutil: tidy up the makefile
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:42 +00:00
Leah Rowe
92580f0659
util/nvmutil: portable default make rules
...
older compilers might not have -std for example.
the code is portable, but old compilers can't
compile with just "make", you have to add lots
of flags
i will now use "make strict" and "make hell"
in testing, but otherwise make without flags
are fine.
move the current strictness to command:
make strict
added an extra command:
make hell
hell uses -Weverything, and is useful with
clang's strict testing, on which i only got
a very small number of errors (it's way less
than a lot of programs would get with this
flag, because -Weverything is REALLY STRICT):
ja, mich nvmutil$ make hell CC=clang
clang -I. -Wall -Wextra -pedantic -std=c90 -Os -Werror -Weverything nvmutil.c -o nvmutil
In file included from nvmutil.c:35:
./nvmutil.h:225:16: error: padding struct 'struct commands' with 1 byte to align 'rw_size' [-Werror,-Wpadded]
225 | unsigned long rw_size; /* within the 4KB GbE part */
| ^
./nvmutil.h:217:8: error: padding size of 'struct commands' with 4 bytes to alignment boundary [-Werror,-Wpadded]
217 | struct commands {
| ^
./nvmutil.h:235:8: error: padding size of 'struct xfile' with 4 bytes to alignment boundary [-Werror,-Wpadded]
235 | struct xfile {
| ^
./nvmutil.h:288:16: error: padding struct 'struct xstate' with 4 bytes to align 'xsize' [-Werror,-Wpadded]
288 | unsigned long xsize;
| ^
nvmutil.c:617:43: error: implicit conversion changes signedness: 'off_t' (aka 'long') to 'unsigned long' [-Werror,-Wsign-conversion]
617 | _r = rw_file_exact(f->gbe_fd, f->buf, f->gbe_file_size,
| ~~~~~~~~~~~~~ ~~~^~~~~~~~~~~~~
nvmutil.c:626:43: error: implicit conversion changes signedness: 'off_t' (aka 'long') to 'unsigned long' [-Werror,-Wsign-conversion]
626 | _r = rw_file_exact(f->tmp_fd, f->buf, f->gbe_file_size,
| ~~~~~~~~~~~~~ ~~~^~~~~~~~~~~~~
nvmutil.c:654:46: error: implicit conversion changes signedness: 'off_t' (aka 'long') to 'unsigned long' [-Werror,-Wsign-conversion]
654 | _r = rw_file_exact(f->tmp_fd, f->bufcmp, f->gbe_file_size,
| ~~~~~~~~~~~~~ ~~~^~~~~~~~~~~~~
nvmutil.c:661:39: error: implicit conversion changes signedness: 'off_t' (aka 'long') to 'unsigned long' [-Werror,-Wsign-conversion]
661 | if (x_i_memcmp(f->buf, f->bufcmp, f->gbe_file_size) != 0)
| ~~~~~~~~~~ ~~~^~~~~~~~~~~~~
nvmutil.c:702:23: error: implicit conversion loses integer precision: 'int' to 'unsigned char' [-Werror,-Wimplicit-int-conversion]
702 | f->part_valid[_p] = good_checksum(_p);
| ~ ^~~~~~~~~~~~~~~~~
nvmutil.c:1045:21: error: implicit conversion loses integer precision: 'int' to 'unsigned char' [-Werror,-Wimplicit-int-conversion]
1045 | f->part_valid[0] = good_checksum(0);
| ~ ^~~~~~~~~~~~~~~~
nvmutil.c:1046:21: error: implicit conversion loses integer precision: 'int' to 'unsigned char' [-Werror,-Wimplicit-int-conversion]
1046 | f->part_valid[1] = good_checksum(1);
| ~ ^~~~~~~~~~~~~~~~
nvmutil.c:1170:45: error: implicit conversion changes signedness: 'off_t' (aka 'long') to 'unsigned long' [-Werror,-Wsign-conversion]
1170 | (unsigned long)(p * (f->gbe_file_size >> 1)));
| ~ ~~~~~~~~~~~~~~~~~^~~~
nvmutil.c:1269:37: error: implicit conversion loses integer precision: 'int' to 'unsigned short' [-Werror,-Wimplicit-int-conversion]
1269 | return (unsigned short)f->buf[pos] |
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
1270 | ((unsigned short)f->buf[pos + 1] << 8);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nvmutil.c:1610:9: error: implicit conversion changes signedness: 'off_t' (aka 'long') to 'unsigned long' [-Werror,-Wsign-conversion]
1609 | r = rw_file_exact(f->tmp_fd, f->bufcmp,
| ~~~~~~~~~~~~~
1610 | f->gbe_file_size, 0, IO_PREAD,
| ~~~^~~~~~~~~~~~~
nvmutil.c:1618:9: error: implicit conversion changes signedness: 'off_t' (aka 'long') to 'unsigned long' [-Werror,-Wsign-conversion]
1617 | r = rw_file_exact(dest_fd, f->bufcmp,
| ~~~~~~~~~~~~~
1618 | f->gbe_file_size, 0, IO_PWRITE,
| ~~~^~~~~~~~~~~~~
nvmutil.c:1609:6: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
1609 | r = rw_file_exact(f->tmp_fd, f->bufcmp,
| ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1610 | f->gbe_file_size, 0, IO_PREAD,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1611 | NO_LOOP_EAGAIN, LOOP_EINTR,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1612 | MAX_ZERO_RW_RETRY, OFF_ERR);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
nvmutil.c:1617:6: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
1617 | r = rw_file_exact(dest_fd, f->bufcmp,
| ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1618 | f->gbe_file_size, 0, IO_PWRITE,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1619 | NO_LOOP_EAGAIN, LOOP_EINTR,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1620 | MAX_ZERO_RW_RETRY, OFF_ERR);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
nvmutil.c:1936:45: error: implicit conversion changes signedness: 'long' to 'unsigned long' [-Werror,-Wsign-conversion]
1936 | if (rv >= 0 && (unsigned long)rv > (nrw - rc))
| ~ ^~
nvmutil.c:2193:27: error: signed shift result (0x8000000000000000) sets the sign bit of the shift expression's type ('long') and becomes negative [-Werror,-Wshift-sign-overflow]
2193 | if (nrw > (unsigned long)X_LONG_MAX)
| ^~~~~~~~~~
./nvmutil.h:147:38: note: expanded from macro 'X_LONG_MAX'
147 | #define X_LONG_MAX ((long)(~((long)1 << (sizeof(long)*CHAR_BIT-1))))
| ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Makefile:42: hell] Fehler 1
in a future commit, i intend to fix all of these issues,
so that the code reliably compiles in hell-mode.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:42 +00:00
Leah Rowe
120241f1cf
util/nvmutil: tidy up makefile options
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
c46a634288
nope. put -Werror in the makefile
...
not compiling without it is a bug
don't let the default exclude it
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
71ce22a938
nvmutil makefile: define WERROR but blank it
...
settting it to -Werror is wrong, should set
it not -Werror.
however, put the WERROR variable in the make
command. that way, i could test with
make WERROR=-Werror
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
d7dea02fba
add -I. to nvmutil makefile
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
5b8ea71bbd
re-add strict flags
...
i need these. can always turn them off
when running make if you need to
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
e795e42f66
also remove -Wextra
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
7f14693e6c
util/nvmutil: more portable Makefile
...
-Werror removed, for older compilers
actual warnings still there
-std is configurable now
e.g.
make CSTD=-c90
make CSTD=-c99
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
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
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
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
6d27853f56
util/nvmutil: use C90 instead of C99
...
with the other changes made recently, super old
compilers now work.
yes, i needed to change some specifiers in printf.
typedefs provided for uint, and a define included
X OPEN SOURCE 500. and asserts for integers.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-10 09:25:27 +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
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
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
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
d1ca21628c
util/nvmutil: Remove the correct binary on uninstall
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2025-01-03 02:13:01 +00:00
Leah Rowe
efd50ee548
util/nvmutil: Honour the INSTALL variable
...
Don't assume "install" is the correct command.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2025-01-03 02:08:38 +00:00
Leah Rowe
8008838abb
util/nvmutil: Don't clean when doing uninstall
...
The user might wish to uninstall, but not remove the
build that they just did.
The user can still do make clean if they wish.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2025-01-03 02:06:12 +00:00
Leah Rowe
982f257f58
util/nvmutil: Proper DESTDIR/PREFIX handling
...
DESTDIR is the root directory where it goes, which
is normally an empty string; PREFIX is where the
bin directory is located, relative to DESTDIR
Default to /usr/local for PREFIX, not /usr, because
/usr/bin is for system utilities.
nvmutil is a local utility.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2025-01-03 02:03:44 +00:00
Leah Rowe
3f85ae5f85
util/nvmutil: Set CC and CFLAGS only if unset
...
We don't want to clobber anything that the user set themselves.
Instead, we should respect the user's choice.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2025-01-03 01:48:52 +00:00
Leah Rowe
57f9906f6d
util/nvmutil: Add uninstall to Makefile
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2025-01-03 01:41:46 +00:00
Leah Rowe
4defe2c608
util/nvmutil: Add distclean to Makefile
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2025-01-03 01:39:46 +00:00
Riku Viitanen
f12f5c3aee
nvmutil: fix makefile
...
Signed-off-by: Riku Viitanen <riku.viitanen@protonmail.com >
2023-11-06 12:53:14 +02:00
Riku Viitanen
9184940f34
nvmutil: make install
...
make install is nice to have. now respects$(PREFIX) as well.
Signed-off-by: Riku Viitanen <riku.viitanen@protonmail.com >
2023-11-06 01:06:16 +02:00
Leah Rowe
b727f9666b
util/: use SPDX license and copyright headers
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2023-09-25 02:49:34 +01:00
Leah Rowe
208620198c
Update email address for Leah Rowe copyrights
...
also, some of them were out of date; years now updated.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2023-09-25 02:27:26 +01:00
Leah Rowe
b3b3642fe2
assimilate nvmutil
2022-11-17 12:07:09 +00:00