summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
20 hoursutil/nvmutil: reset errno on *successful* readLeah Rowe
otherwise, stale errno from an earlier syscall might cause a valid read to still fail. Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: don't reset errno in check_read_or_dieLeah Rowe
we want to debug it after the fact; this is now handled, in the calling functions (unhandled error exceptions). Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: minor code cleanupLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: comment regarding memcpy endiannessLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursutil/nvmutil: don't usleep on file readsLeah Rowe
i don't care. it's only 30 tries. usleep can fail, setting errno, and it can actually take longer, depending on the environment. it poisons errno, and makes debugging harder. just remove it. Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: handle error after check_read_or_dieLeah Rowe
we already exit reliably in that function. the current code is logically correct, but very weak against future changes. this extra check is essentially redundant, but prevantative against future changes. Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: handle errno after file readLeah Rowe
errno shouldn't be set, after reading a file successfully. if it is, that's a bug. handle it accordingly. Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: simplified zero-mac-address checkLeah Rowe
it's just three words. access them directly. Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: don't pass h as param in cmd_setmacLeah Rowe
it's only needed in one function (tmp variable). Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: cast SIZE_4KB on the pwrite checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: usleep 1 on check_read_or_dieLeah Rowe
This prevents hogging the CPU in a tight loop, while waiting for access. I've also reduced the number of tries to 30, rather than 200. This is more conservative, while still being somewhat permissive. The addition of the usleep delay probably makes this more reliable than the previous behaviour of quickly spinning through 200 tries, but without hogging CPU resources. I *could* allow this loop to be infinite, but I regard infinite spin-lock as an error state. Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: reset errno on successful file readsLeah Rowe
a non-fatal error could have set errno. when we return from check_read_or_die(), it should be assumed that all is well. i don't think this would mask anything important, but it may be regarded as a preventative bug fix, since it most likely only prevents false-positives. Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: reset fd/rfd to negative oneLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: reset buf in reset_global_state()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: reset macbuf in reset_global_stateLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: reset errno in reset_global_stateLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 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>
21 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>
22 hoursutil/nvmutil: improved some error messagesLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
22 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>
22 hoursutil/nvmutil: remove redundant castsLeah Rowe
these just bloat the code Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: more thorough global_state_resetLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: reset fname properlyLeah Rowe
do it after resetting global state. Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: simpler mac address totallingLeah Rowe
i know it's always going to be 3 Signed-off-by: Leah Rowe <leah@libreboot.org>
22 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>
22 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>
23 hoursutil/nvmutil: reset cmd in mainLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: reset fname in mainLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: reset part_modified in mainLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 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>
23 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>
23 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>
23 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>
23 hoursutil/nvmutil: clearer error messages on valid_readLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: comment valid_read for clarityLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: clearer errno reset in valid_readLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 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>
23 hoursutil/nvmutil: use zd for printf in valid_readLeah Rowe
more portable Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: minor cleanup in usage()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: minor cleanup in cmd_setmacLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 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>
24 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>
24 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>
25 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>
25 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>
26 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>
26 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>
26 hoursutil/nvmutil: consistent errors on close()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: print correct file name for urandomLeah Rowe
err_if reports fname, not /dev/urandom Signed-off-by: Leah Rowe <leah@libreboot.org>
26 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>