summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
19 hoursutil/nvmutil: reset errno in reset_global_stateLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/nvmutil: Comments relating to NVM size limitLeah Rowe
Part of the code currently assumes we only work on the smaller NVM area. I'm adding some comments to make this clear, for when and if the code is ever expanded to support operating on the Extended NVM area (just part the main 128-byte NVM area). Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/nvmutil: remove err_if()Leah Rowe
use of it was preventing more verbose error messages on exit. the code is actually cleaner without it, and easier to read, because of those verbose error messages. i also added some comments to cmd_swap/copy and did some other minor/related cleanup elsewhere. Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/nvmutil: improved some error messagesLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/nvmutil: rename valid_readLeah Rowe
it doesn't just validate, but also exits. rename it accordingly, to: check_read_or_die Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: remove redundant castsLeah Rowe
these just bloat the code Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: more thorough global_state_resetLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: reset fname properlyLeah Rowe
do it after resetting global state. Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: simpler mac address totallingLeah Rowe
i know it's always going to be 3 Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: less obscure mac address zero checkLeah Rowe
make it totally clear what's going on. Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: reset global state in one functionLeah Rowe
split it out of main. this is good hygiene and it's preparation for a planned expansion in the future, that allows operation on multiple files. Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: reset cmd in mainLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: reset fname in mainLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: reset part_modified in mainLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: reset invert in mainLeah Rowe
currently redundant, but again i might expand this in the future to allow multiple runs. putting this here as good practise (currently redundant). Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: reset mac in mainLeah Rowe
we currently only run the logic once, but i might expand nvmutil in the future, so that it can operate on multiple files. this would require using a different command syntax, e.g. getop-style syntax. this is a preventative bug fix, resetting global state. Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: reset macbuf in parse_mac_stringLeah Rowe
we only ever use it once, so it's fine, but future expansion of this code might trip us up. this is therefore a preventative bug fix. Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: use off_t for partsize (pread/pwrite)Leah Rowe
size_t can truncate on some platforms. it's best to use the proper variable type (a cast is insufficient). Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: clearer error messages on valid_readLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: comment valid_read for clarityLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: clearer errno reset in valid_readLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: pass size_t to read, not ssize_tLeah Rowe
ssize_t is signed, which could be negative. in practise, we control the value that's going in anyway. Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: use zd for printf in valid_readLeah Rowe
more portable Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: minor cleanup in usage()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: minor cleanup in cmd_setmacLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: don't use err_if in usageLeah Rowe
fname isn't set here, and fname is used in err_if Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: rename errval to nvm_errvalLeah Rowe
strtonum implementations in bsd sometimes have this variable name. rename it to avoid conflict. also removed the commentt errno values, since i'm only ever setting it to valid values, as are the syscalls that i'm using, so it should be ok. i'm not writing a stub to check errno. that would be far beyond the scope of nvmutil. Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: re-try reads if errno is EINTRLeah Rowe
this is a bit of fault tolerance. a bit bloated too, but it should make the code more resilient. we limited the number of retries to 200 retries. EINTR is when the syscall (read/pread) is interrupted. we still error out on other conditions; we also still error out on EINTR if the number of re-tries surpasses 200. during this re-try loop, if *another* error occurs, we exit as normal. this is done for both files: the gbe file, and /dev/urandom. Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: explicitly cast on read/pread/pwriteLeah Rowe
these functions return ssize_t, so compare explicitly to that, when using the SIZE_4KB define for example. Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: remove unnecessary checkLeah Rowe
we can just use errval as argument to set_err, because set_err itself now properly handles errno, ensuring that is is never set to zero. Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: stricter check_boundLeah Rowe
word/set_word are only meant to operate on the nvm area (128 bytes), but the current check is against the entire 4KB block. swap() only handles the nvm area, as per the design of nvmutil. this patch makes the boundary check truer to my real intent, guarding against future logical errors. Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: set errno only if x is not 0Leah Rowe
otherwise, some minor edge cases may result in err printing "success", when we want to signal an error. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: consistent errors on close()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: print correct file name for urandomLeah Rowe
err_if reports fname, not /dev/urandom Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: don't bother with strncmpLeah Rowe
these are strings provided from the shell, which are guaranteed to always be null-terminated. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: get rid of arg_cmdLeah Rowe
it's pointless. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: use memcpy in word/set_wordLeah Rowe
alignment isn't an issue, but aliasing between uintX_t types in C means that this code may fail on some weird systems. using memcpy here is advisable. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: use strncmp instead of strcmpLeah Rowe
set a constant maximum length. this seems reasonable, and it's even quite generous. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: remove checkdir()Leah Rowe
we don't need it. what follows is a call to open(), which would fail anyway if the path is a directory; further, this removes a theoretical race condition in the program, and makes open() happen sooner, making it more likely that we get the file first, before another program can take it. checking whether /dev/urandom is a directory is the height of absurdity. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: make rhex err_if consistentLeah Rowe
n + 1 is the same as saying sizeof(rnum) in this case. we should be clear about that, in code. n is irrelevant here, since it is only an index for the return value. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil rhex: check against sizeof(rnum)Leah Rowe
checking against -1 is incorrect, because we specifically want to ensure that it always read the number of bytes defined by the size of rnum. this still covers the case where the return value is -1, and therefore makes the error handling much stricter. Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil err: filter errval when zeroLeah Rowe
default to ECANCELED if zero Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: always exit non-zero on errLeah Rowe
the way err works here now is very different than the bsd one. here, we ALWAYS exit with EXIT_FAILURE, and we call set_err with, as argument, the first argument given to err. this then sets errno, but the exit value is always consistent. that's what happens when i control err(). i make it even better. the original bsd one is too conservative. Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: more consistent output in usage()Leah Rowe
and use getnvmprogname Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: use getnvmprogname in usageLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: use own implementation of errLeah Rowe
and getprogname, written as getnvmprogname this removes a dependency on err.h, which is non-standard. the remaining code is posix-compliant, or ifdef'd where use of openbsd pledge is concerned - someone could theoretically define __OpenBSD__ that isn't and OpenBSD base maintainer, and then use nvmutil in it, but i so don't care about that evermore hypothetical individual. Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: close rfd on exitLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: remove unnecessary includeLeah Rowe
dirent.h is no longer needed, because i'm no longer making use of opendir() Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: tidy up write_gbeLeah Rowe
by handling close() in main, we can reduce the indendation in write_gbe and generally make it much easier to read. Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: make the part check easier to readLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>