summaryrefslogtreecommitdiff
path: root/util
AgeCommit message (Collapse)Author
21 hoursutil/nvmutil: fix more bad printf statementsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: fix a few bad printf statementsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: warn about partial gbe file writesLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: use size_t for part numbersLeah Rowe
not int Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: clean up file handlingLeah Rowe
inline check_read_or_die Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: minor cleanupLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: mem bound check on file read/writeLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: rename gbe_bound for clarityLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: make defines easier to understandLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: tidy up set_mac_nibLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: use portable printf on hexdumpLeah Rowe
lx means unsigned long, and row is size_t which often is, but this is not guaranteed. Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: make the MAC shifting easier to readLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: optimise hextonumLeah Rowe
there is 0x20 of different between a and A so we can just or 0x20 and compare only lowercase. we can also cast char (which may me signed on some systems) to unsigned, and then only check whether it's lower than 10. this code results in far less branching (in C), but a good optimising compiler probably wouldn't have cared about the old version anyway. it's just nicer C code. this also means we no longer need to check for X, only x. Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: fix parenthesis warning in GCCLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: tidy up set_mac_nibLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: clearer intent on struct dataLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: more readable NVM definesLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: more readable SIZE_nKB definesLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: use arc4random on DragonFly BSDLeah Rowe
it has arc4random, so we will use it there. Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: use strlen instead of strnlenLeah Rowe
strnlen isn't available on some older unices. we already know the string will be null-terminated, because it comes from argv, so runaway reads are extremely unlikely (read: impossible). Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: add bound checks for gbe read/writeLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: minor code cleanupLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: clearer macbuff init in set_mac_nibLeah Rowe
and 1 does the same thing as mod 2, but it's cleaner. i also now bitshift 3 times instead of times by 8, which again is clearer in purpose. i line breaked after h, to make it clear that all of the next part is being shifted in Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: don't reset rfd on openbsdLeah Rowe
it isn't defined there Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: tidy up rhex()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: properly handle sizeof in rhex()Leah Rowe
sizeof is size_t, so we must act accordingly. casting it to an int is unacceptable. this version is also branchless. Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: make rmac an array, not a literal.Leah Rowe
this prevents reassignment. Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: use arc4random when availableLeah Rowe
fall back to urandom. also add a /dev/random fallback, for older unices. with the posix compatibility changes, combined with this change as above, the code should be portable now. i expect it to compile on *many* unix systems! pretty much everything from the last 30 years. Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: inline pos calculation on word()Leah Rowe
we don't need a whole function. i previously did it for clarity, but simply setting a variable all in one line is totally fine. Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: remove pointless checkLeah Rowe
the input is already size_t, which is unsigned there's no point in checking for negative Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: cast inside check_bound, not callersLeah Rowe
the purpose of the cast is to check whether a given integer would underflow under any circumstance. Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: comment regarding endiannessLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: clean up set_wordLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: use size_t for offsets in wordsLeah Rowe
size_t is generally the size of the address space, so this is more reliable for our purposes; we're only working on small buffers, but even so, it's a good thing to do. Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: remove the swap() functionLeah Rowe
directly handle swapping in word and set_word in my testing, x86_64 and arm64 compilers actually produce more efficient code this way. i previously only did a big swap on the whole buffer on big-endian CPUs, and directly accessed without swaps on little-endian, as an optimisation. however, the old code is actually slower than what the compiler produces, with the new code! portability is retained with big-endian host CPUs and little-endian host CPUs. this also avoids the complication of memcpy and is just generally extremely reliable by comparison. Signed-off-by: Leah Rowe <leah@libreboot.org>
3 daysupdate nvmutil COPYING file (2026 copyright year)Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
3 daysutil/nvmutil: rhex: don't read twice!Leah Rowe
we currently never read the 0th byte, so if we need all 12, and we do when every byte is random, we read again just to get one byte. not really a bug, but it is a performance penalty, so let's fix it! Signed-off-by: Leah Rowe <leah@libreboot.org>
4 daysutil/nvmutil: unified file read error handlingLeah Rowe
it must be read perfectly, or else Signed-off-by: Leah Rowe <leah@libreboot.org>
4 daysutil/nvmutil: tidy up cmd_brickLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
4 daysutil/nvmutil: minor code cleanupLeah Rowe
mostly style changes Signed-off-by: Leah Rowe <leah@libreboot.org>
4 daysutil/nvmutil: provide comment about global stateLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
4 daysutil/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>
4 daysutil/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>
4 daysutil/nvmutil: minor code cleanupLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
4 daysutil/nvmutil: comment regarding memcpy endiannessLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
4 daysutil/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>
4 daysutil/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>
4 daysutil/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>
4 daysutil/nvmutil: simplified zero-mac-address checkLeah Rowe
it's just three words. access them directly. Signed-off-by: Leah Rowe <leah@libreboot.org>
4 daysutil/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>