summaryrefslogtreecommitdiff
path: root/util/nvmutil/nvmutil.c
AgeCommit message (Collapse)Author
12 hoursRevert "util/nvmutil: don't use zx printf specifier"Leah Rowe
This reverts commit ba3cf14faa0c1e55e82d92795a07ec82eb121fcf.
12 hoursutil/nvmutil: explain errval handling in err()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
12 hoursutil/nvmutil: make rc size_t (not ssize_t)Leah Rowe
i overlooked this when writing. it's comparing to a length which is size_t, so let's avoid an unnecessary cast. Signed-off-by: Leah Rowe <leah@libreboot.org>
12 hoursutil/nvmutil: don't use zx printf specifierLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
12 hoursutil/nvmutil: add portable asserts for integersLeah Rowe
we need this to be the case for our code, that char and uint8_t are 8 bits, and that uint16_t and uint32_t are 16- and 32-bit. these asserts protect us in case it's not (it will cause a compile time error). Signed-off-by: Leah Rowe <leah@libreboot.org>
12 hoursutil/nvmutil: abort if I/O len exceeds SSIZE_MAXLeah Rowe
in rw_file_exact otherwise, if length exceeds SSIZE_MAX, we could hit an overflow the buffers and lengths we deal with are relatively small anyway, so this fix is preventative Signed-off-by: Leah Rowe <leah@libreboot.org>
13 hoursutil/nvmutil: annotate the prototypesLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
13 hoursutil/nvmutil: unified gbe file part I/OLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
14 hoursutil/nvmutil: remove stale defineLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
14 hoursutil/nvmutil: unified I/O: stdout, urandom and gbeLeah Rowe
everything is a file Signed-off-by: Leah Rowe <leah@libreboot.org>
15 hoursutil/nvmutil: unified urandom/gbe file readingLeah Rowe
like before, but with the newly correct logic Signed-off-by: Leah Rowe <leah@libreboot.org>
15 hoursutil/nvmutil: safer read_gbe_file_exactLeah Rowe
it now retries infinitely on EINTR, except when the return of pread is precisely zero, at which point it errs. this is better than having an arbitrary maximum like before, and increases robustness on unreliable file systems, e.g. NFS shares. Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursutil/nvmutil: report checksum in cmd_dumpLeah Rowe
as it should be! Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursutil/nvmutil: reduce checksum report verbosityLeah Rowe
only print a message what arg_part is set. this means that a checksum error message won't be printed on cat commands. Signed-off-by: Leah Rowe <leah@libreboot.org>
17 hoursutil/nvmutil: unified io flagsLeah Rowe
don't hardcode it per command logically. do it in the command table instead. this also fixes a bug where the cat commands did not set the permissions read-only. Signed-off-by: Leah Rowe <leah@libreboot.org>
17 hoursutil/nvmutil: require good checksum on catLeah Rowe
since the cat command can be used to create bad gbe files, if the checksums don't match. my rule is that nvmutil must never be used to destroy data, only correct it (e.g. a file with just one valid part can have it copied to the other part, but you can't copy a bad part - and i removed the "brick" command). i *did* disable checksum requirements on the dump command. with this, you can check the nvm area and it tells you what the correct checksum could be. then you could just correct it in a hex editor if you wanted to, quite easily. the idea is to slow down the act of destroying or corrupting data as much as possible. someone wily enough can use a hex editor to patch up some files just fine. Signed-off-by: Leah Rowe <leah@libreboot.org>
17 hoursutil/nvmutil: initialise w in gbe_cat_bufLeah Rowe
no build error at the moment, nor would there be if using clang or gcc, but i imagine some buggy compilers might complain. remember: portability. i also want this code to compile on old, buggy compilers. logically, this initialisation is redundant. Signed-off-by: Leah Rowe <leah@libreboot.org>
17 hoursutil/nvmutil: simplify the cat commandLeah Rowe
the current test is a bit over-engineered, so i simplified it. Signed-off-by: Leah Rowe <leah@libreboot.org>
18 hoursutil/nvmutil: add cat16 and cat128 commandsLeah Rowe
these take any file size of gbe file: 8KB, 16KB or 128KB. so does the normal cat. then you can use cat, cat16 or cat128. these output to stdout, the corresponding size in KB. 0xFF padding used on the larger files. on the larger files, the first 4KB of each half is the GbE parts, and everything else is 0xFF padding. now you can resize gbe files easily, example: ./nvmutil gbe128.bin > gbe8.bin yes Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/nvmutil: nope. rename out back to cat.Leah Rowe
it *is* cat. it's catting two GbE parts. so its cat. (two 4KB areas, plus padding when i add cat16/cat128) Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/nvmutil: rename cat to outLeah Rowe
it doesn't cat. it outputs one file. Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: remove stale commentLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: added a "cat" commandLeah Rowe
with this, you can read 16KB and 128KB files, and output them to stdout, but it outputs 8KB for example: ./nvmutil gbe128.bin > gbe8.bin now you have a 8KB file i could probably easily add cat16 and cat128 too. nvmutil reads two 4KB parts regardless of GbE file size (one from the first 4KB of each half of the file), so this was easy to implement. Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: allow dump without good checksumsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: fix bad cast conversionLeah Rowe
don't cast unsigned to signed. no behaviour is changed, but this will prevent some silly compilers complaining about -Wsign-conversion Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: add guard in rhex()Leah Rowe
i removed this before, but it's good to put it here defensively, in case i ever mess up the urandom read function again. Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: fix EINTR detection on urandom readLeah Rowe
i forgot to handle it in the previous refactor not really a problem in practise, since the first read probably succeeds anyway. Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: reorder some functions linearlyLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: tidy up gbe/urandom readingLeah Rowe
split them up into their own functions, since they no longer operate according to the same policy. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: fix a bad commentLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: explicitly reset file descriptorsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: fix indentation in rhex()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: remove unused variable in rhexLeah Rowe
on bsd Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: fix bsd build issueLeah Rowe
urandom_fd is unavailable on bsd Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: even safer rhex()Leah Rowe
also handles possible overflows in read_gbe_file_exact it removes dead code on both paths: arc4random and urandom Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: only check n in rhex on linuxLeah Rowe
not bsd Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: safer calculated_checksumLeah Rowe
we rely on uint16_t wrapping, but some platforms may behave weirdly. cast as uint32_t and then cast back, on return, with an explicit mask beforehand. Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: much safer rhex()Leah Rowe
n could be zero under weird regression cases Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: tidy up hexdump()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: assert uint16_t as 16-bitsLeah Rowe
some platforms might get this wrong. define it explicitly. Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: safer cast in nvm_wordLeah Rowe
cast buf[x] directly. Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: define _FILE_OFFSET_BITSLeah Rowe
some older systems have 32-bit off_t. this makes them have 64-bit off_t Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: include sys/types.hLeah Rowe
some older systems need it for pread/pwrite it must come before stat.h Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: use even older define for preadLeah Rowe
with this new define, we can target even older systems from the late 90s. Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: tidied up a commentLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: don't include not-needed inttypes.hLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: reset errno on urandom partial readLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: consistent file location on err()Leah Rowe
put it at the start of the message Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: clean up the MakefileLeah Rowe
that option there is already defined in the code Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: tidy up the main comment headerLeah Rowe
merge it into one Signed-off-by: Leah Rowe <leah@libreboot.org>