summaryrefslogtreecommitdiff
path: root/util
AgeCommit message (Collapse)Author
27 hoursutil/nvmutil: reduce the size of rnum to 12Leah Rowe
we only need 12 bytes at a maximum Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: tidy up check_mac_separatorLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: rename openFiles to open_filesLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvm: make variables and functions staticLeah Rowe
i don't intend for this to be used in a library Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: don't use spaces on err_ifLeah Rowe
this is inconsistent with the style in the rest of the code. Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: use const for string literal in opLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: no designated initialisers in opLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
27 hoursutil/nvmutil: declare one prototype per lineLeah Rowe
in the same order that functions are declared Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: don't declare variables in for loopsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: use size_t on op for loopLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: make global variable names clearerLeah Rowe
each variable is declared on its own line. Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: count the number of items in opLeah Rowe
don't hardcode it Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: set fname earlierLeah Rowe
this fixes the bug where if you specify an invalid command such as: ./nvm gbe brick 9 part 9 doesn't exist, but fname isn't yet set, here. same thing applys when running those pledge commands on openbsd. Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: obey the 79-character ruleLeah Rowe
only 79 characters or less, per line. Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: use spaces when calling err_ifLeah Rowe
this is separate from other function calls. err_if is used as though it was an if, where we always add a space. it's just a quirk of my coding style. Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: consistent variable/function namingLeah Rowe
use the same naming scheme throughout Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursutil/nvmutil: use the invert in goodChecksumLeah Rowe
this way, the correct part number is printed when an invalid part is being operated on, in cmd copy or swap. Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursutil/nvmutil: readGbe: use inverted part in swapLeah Rowe
i overlooked this in a previous modification Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursutil/nvmutil: clean up write_mac_partLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursutil/nvmutil: clean up cmd_dumpLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursutil/nvmutil: don't copy data in copy/swapLeah Rowe
instead, use a single integer, set to 1 if using these commands (otherwise set to 0) used as an XOR mask. use this to invert where data gets read. one quirk with this is that if a copy operation is performed from a part with a bad checksum, it's already done in advance, in memory, but then the check on the checksum in cmd_copy is now checking the other part, which will be all zeroes, so i invert that too; this means now when running cmd_copy, it'll complain about an invalid part, but the part number is inverted. it's a small price to pay, because this restores the previous performance optimisations but without being as unsafe. this is also true when doing the swap. Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/nvmutil: re-introduce do_read in readGbeLeah Rowe
lots of block devices use 4KB block size. it makes sense to have this optimisation here. i previously removed it, along with the one that only reads the NVM area - that one is still gone, because it was largely pointless. because of this modification returning, i also re-introduced the check in setWord against nvmPartModified - otherwise, for example, running cmd brick 0 would brick part 0 but then write all zeroes to part 1. Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/nvmutil: use read, not pread, on /dev/urandomLeah Rowe
we always read from offset zero, so use read Signed-off-by: Leah Rowe <leah@libreboot.org>
38 hoursutil/nvmutil: clean up checkdirLeah Rowe
those lines at the end are a hangover from the old opendir- based implementation. i also made the output more verbose in that first error check. Signed-off-by: Leah Rowe <leah@libreboot.org>
38 hoursutil/nvmutil: use separate st variable for urandomLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
38 hoursutil/nvmutil: cleaner directory checkingLeah Rowe
opendir allocates resources and causes a bunch of other error conditions which we need to catch. use of stat is more efficient here. Signed-off-by: Leah Rowe <leah@libreboot.org>
39 hoursutil/nvmutil: initialise fname to empty stringLeah Rowe
otherwise, early calls to err_if make use of a NULL string inside err() Signed-off-by: Leah Rowe <leah@libreboot.org>
39 hoursutil/nvmutil: fix code formatting on xopenLeah Rowe
it still had some leftovers from the old macro-style implementation. it still compiled, but this patch fixes the function properly. Signed-off-by: Leah Rowe <leah@libreboot.org>
39 hoursnvmutil: fix the swap functionLeah Rowe
irrelevant for most users, who are on little endian anyway, but i broke the swap function on big endian systems. this fixes it. the new function uses an intermediate variable instead of xor swapping, but i accidentally left some relics of of the old xor swaps in place. this fixes that. Signed-off-by: Leah Rowe <leah@libreboot.org>
39 hoursutil/nvmutil: use EXIT_FAILURE/SUCCESS for exitsLeah Rowe
this, in conjunction with the centralised exit scheme now used by nvmutil, means that we have portable exit status. notwithstanding the use of non-portable unix functions, and especially the use of non-standard err.c (which GNU and BSD libc implementations all have anyway, as does musl). this code should now run on essentially any computer with Linux or BSD on it. Signed-off-by: Leah Rowe <leah@libreboot.org>
39 hoursutil/nvmutil: make err_if a function, not a macroLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
39 hoursutil/nvmutil: properly cast void use of set_errLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
39 hoursutil/nvmutil: don't exit with errno as statusLeah Rowe
exit with 0 or 1, as is proper. errno is an int, but the return value on a shell can be e.g. byte, and depending how that number (errno) is valued, could overflow and cause a zero exit, where you want a non-zero exit. the code has been changed, in such a way to maintain current behaviour (don't change errno), except that when errno is set upon exit, the exit value is now one. Signed-off-by: Leah Rowe <leah@libreboot.org>
40 hoursutil/nvmutil: split up cmd_setmacLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
40 hoursutil/nvmutil: rename some functions for clarityLeah Rowe
also re-order the prototypes Signed-off-by: Leah Rowe <leah@libreboot.org>
40 hoursutil/nvmutil: split up parseMacStringLeah Rowe
split it into smaller, more readable functions Signed-off-by: Leah Rowe <leah@libreboot.org>
41 hoursutil/nvmutil: remove useless gbe variableLeah Rowe
use buf directly Signed-off-by: Leah Rowe <leah@libreboot.org>
41 hoursutil/nvmutil: cmd copy/swap: use word/setWordLeah Rowe
this means that we make use of the boundary checks. it's just a safer way of handling these functions. Signed-off-by: Leah Rowe <leah@libreboot.org>
41 hoursutil/nvmutil: remove variable nvmPartChangedLeah Rowe
pointless optimisation. we know that when a user requests an operation that would write, it will probably result in a change. therefore, this change is the real optimisation. to avoid writing the same half of a file twice, when using cmd_copy, we check (in writeGbe) whether gbe part 0 and 1 are the same; if they are, then we only loop once. this is important, because otherwise we would call swap() twice. this means that the optimisations in cmd_copy and cmd_swap must be removed. the point of this and other changes is to improve memory safety in nvmutil, so frivolous use of pointers has to go. Signed-off-by: Leah Rowe <leah@libreboot.org>
42 hoursutil/nvmutil: merge nvmalloc with readGbeLeah Rowe
it's so simply now, all it does is set the gbe pointers Signed-off-by: Leah Rowe <leah@libreboot.org>
42 hoursutil/nvmutil: remove do_readLeah Rowe
pointless code complication, that doesn't yield a noticeable performance increase. Signed-off-by: Leah Rowe <leah@libreboot.org>
42 hoursutil/nvmutil: read in fixed 4KB blocksLeah Rowe
modern file systems work in 4KB blocks. reading only a small part of it doesn't really make much difference in terms of performance. simplify the code instead. Signed-off-by: Leah Rowe <leah@libreboot.org>
42 hoursutil/nvmutil: use fixed bufferLeah Rowe
modern malloc implementations make the optimisation here pretty pointless. modern computers make this modification pointless. i'm not planning to run nvmutil on a VAX. openbsd removed support for it ages ago. 8KB fixed buffer is fine. Signed-off-by: Leah Rowe <leah@libreboot.org>
42 hoursutil/nvmutil: remove pointless arg in openFilesLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
43 hoursutil/nvmutil: don't use xor swapLeah Rowe
it doesn't save any time on modern systems, and it's just confusing for some people to read. i mean, i understand it instinctively, but normal people do it with a swap variable. Signed-off-by: Leah Rowe <leah@libreboot.org>
43 hoursutil/nvmutil: don't use size_t as pointerLeah Rowe
the only reason i did this was for that xor swap, but we can just use an intermediary value Signed-off-by: Leah Rowe <leah@libreboot.org>
43 hoursutil/nvmutil: don't capitalise set_errLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
43 hoursutil/nvmutil: make xopen a function, not a macroLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
44 hoursutil/nvmutil: merge block_unveil back with mainLeah Rowe
we always want unveil/pledge calls to be in main, when possible, so that they are more transparent and easier to understand when re-factoring, because it's extremely important that these syscalls be done correctly. main is small enough now, from other re-factoring changes, that i'm happy to have this back in main now. Signed-off-by: Leah Rowe <leah@libreboot.org>
2 daysutil/nvmutil: fix bad bound checkLeah Rowe
the current check is too liberal. make it sticter. the issue is that the previous check did not take into account that it's a check on a uint16_t array, against nf which refers to a number of bytes. Signed-off-by: Leah Rowe <leah@libreboot.org>