summaryrefslogtreecommitdiff
path: root/util
AgeCommit message (Collapse)Author
2023-09-18util/nvmutil: remove unnecessary xclose macroLeah Rowe
it is only used once. use err_if instead. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-18util/nvmutil: simplify pledge and unveil handlingLeah Rowe
there is no need to have these as defines, when err_if exists; get rid of xunveil and xpledge. use the bare pledge and unveil functions directly, with err_if(). 268 sloccount now on nvmutil.c, versus 289 sloccount before this change, with no loss of functionality. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-05util/nvmutil: put code all in nvmutil.cLeah Rowe
it doesn't really make sense to have nvmutil.h since this is only a very small program and not intended for use as a library Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-04move me7_update_parser.py to util/Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-03ich9m mainboards: use pre-assembled ifd/gbe filesLeah Rowe
This cuts down on build time, and it will allow libreboot to remove large chunks of code. these ifd/gbe configs are just binary-encoded config files, in a format well-understood. they can easily be opened up and displayed, using ich9show or ifdtool, and manipulated by these tools; bincfg can generate them from scratch, and nvmutil can change mac addresses, for example. so, do this and remove from lbmk the following: * ich9utils (which contains ich9gen) - not needed anymore * code in lbmk for handling ich9gen and insertions; the coreboot build system is now used, for this same purpose, so remove such code from lbmk this results in a massive code size reduction (thousands of lines) in lbmk; smaller when only looking at the build system, but much larger when you consider that ich9utils is also removed (about 3k sloc) Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-14util/nvmutil: reduced indentation inside loopLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-14util/spkmodem-recv: rename function for clarityLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13util/spkmodem-recv: remove unnecessary error checkLeah Rowe
the loop in main() already checks EOF, and errno is properly handled at the end of main() we only need to call ferror(), to check error state this fixes a bogus error message when pressing ctrl+D to terminate the program, *which is the intended way to terminate this program* (that, or EOF is reached in any other another way) do not treat intended behaviour as an error condition! Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13util/spkmodem-recv: say cc, not gcc, in commentLeah Rowe
i've build-tested this code with clang and that also works. in practise, a user is going to have clang or gcc Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13util/spkmodem-recv: fix bad commentLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13util/spkmodem-recv: remove unnecessary assignmentLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13util/spkmodem-recv: simplify getopt handlingLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13util/spkmodem-recv: cleaner ring buffer handlingLeah Rowe
make it more obvious that this *is* a ring buffer being handled, and make it more obvious when checking a pulse in the next frame Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13remove errant fileLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-12util/spkmodem-recv: re-add full license headerLeah Rowe
i forked spkmodem-recv from coreboot, who forked it from gnu grub. gnu grub's version has the full header, with copyright declared as belonging to the fsf coreboot made changes after forking it, and later replaced the license declaration with an equivalent SPDX header, but they also removed the FSF's copyright declaration, which by itself does not void the declaration anyway, i just feel better re-adding the full declaration. make it so! Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-12util/ich9gen: change default mac addressLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-08util/spkmodem-recv: fix regressionLeah Rowe
The last bit wasn't being handled, *and* ascii_bit wasn't being reduced at all. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05util/spkmodem-recv: make ringpos a global variableLeah Rowe
there's no point passing it as argument to a function. it's used across more than one function, so make it global Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05util/spkmodem-recv: simplify sample_cnt/char resetLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05util/spkmodem-recv: print stats in other functionLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05util/spkmodem-recv: only print unhandled err on -dLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05util/spkmodem-recv: make debug a runtime optionLeah Rowe
it's currently a build-time option make it a runtime option instead, so that every user can optionally make use of it, on all builds Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05util/spkmodem-recv: always disable line bufferingLeah Rowe
thus, there's no need to handle flushing of stdout whatsoever, and the code can be greatly simplified ascii bits are still reset, when no input on stdin is given Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05util/spkmodem-recv: simplify stdout flush logicLeah Rowe
when spkmodem-recv doesn't receive anything (via stdout) after a few frames, it's assumed that the console is dead and the buffered output is flushed this logic is assumed superfluous when -u is set Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05util/spkmodem-recv: rename variables for clarityLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04util/spkmodem-recv: split print_char() upLeah Rowe
the logic for *setting* a character, and the logic for outputting it, ought to be separate. do that. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04util/spkmodem-recv: reduce indent in print_char()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04util/spkmodem-recv: squash a few code linesLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04util/spkmodem-recv: bsd-style indentLeah Rowe
my style was: 2 tabs. bsd-style, for extending a line, is 4 spaces. this style has grown on me, so let's do it here Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04util/spkmodem-recv: order prototypes per functionLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04util/spkmodem-recv: warn on unhandled exit errorLeah Rowe
my style of C programming is this: always return errno upon exit from the program, or from a thread. handle errno in the calling/forking function. returning errno at the end of main has this intention: if an unhandled error occured, the program exits with non-zero status. a correctly written program should *never* return non-zero at the end of main, and if it does, this indicates a bug in the code (per my code style / philosophy). so, warn the user with a message if this occurs. the intention is that this message should never be printed. do not use assert() for this. i don't believe in that. such a test should always be present, for everyone. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04util/spkmodem-recv: another minor code cleanupLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04util/spkmodem-recv: always set errno on err()Leah Rowe
This version of spkmodem uses err() to indicate an error, and the value of errno is used as exit status at all times, even when it is zero. When calling err(), it is intended that errno always be non-zero, so modify the code accordingly. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04util/spkmodem-recv: minor code cleanupLeah Rowe
also be more thorough about errno value when calling pledge. rename variable in a for loop for clarity. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04util/spkmodem-recv: handle sample errors correctlyLeah Rowe
when calling fread(), errno may be set to EOVEFLOW if the range being read will cause an integer overflow if end-of-file is reached, errno may not be set. when calling this function, you must check errno or check feof() - ferror() should also be checked, so this check is added immediately afterwards in the code ferror() does not set errno, so ERR() is used to set errno to ECANCELED as program exit status further separate reading of frames into a new function Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04util/spkmodem-recv: simplify pulse checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-03util/nvmutil: call unveil earlier, and hardenLeah Rowe
The mentality behind pledge and unveil is that you should think ahead, so that large parts of code can run under extremely tight restrictions. The pledge calls have been adjusted accordingly, also. Disallow all unveil calls after the gbe file and the file /dev/urandom have been unveiled. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-03util/nvmutil: hardening: reduce pledges earlierLeah Rowe
also remove wpath if using the dump command Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-03util/nvmutil: fix faulty arg checkLeah Rowe
in practise, no other condition would be met and the program still worked. this is a pre-emptive fix.
2023-06-03util/nvmutil: cleanup: move logic out of main()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-03util/nvmutil: major cleanup. simpler arg handling.Leah Rowe
Also hardened the pledges. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-02util/nvmutil: simplify writeGbeFile()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-01util/nvmutil: don't call writeGbeFile if O_RDONLYLeah Rowe
This replaces a check in the function for O_RDONLY, and fixes the bug where the "dump" command triggers such error. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-01util/nvmutil: code cleanup (pledge/unveil calls)Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-01util/nvmutil: harden pledge/unveil calls (OpenBSD)Leah Rowe
*Open* files at the start, then unveil. The same overall behaviour is observed. In the case that invalid arguments are given, simply opening a file does not cause much performance impact (if any). Restrict operations as early as possible in code. Bonus: writeGbeFile also hardened; if flags is O_RDONLY, it aborts. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-01util/nvmutil: fix faulty fd checkLeah Rowe
i screwed up in an earlier commit this change fixes a bug where on rhex(), each call would re-open /dev/urandom, resetting rfd Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-01util/nvmutil: only swap/copy if checksum is validLeah Rowe
in practise, the file was never written unless the checksum was valid, but in the same of sloccount reduction i made it do the swap/copy before checking. while functionally ok, it never sat right with me. this is one example of where sloc count doesn't mean everything. code correctness is critical Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-01util/nvmutil: use bsd-style indentationLeah Rowe
the style was already quite similar, but extended lines in bsd are indented by 4 spaces instead of a tab. this style has grown on me, so i'm adopting it here Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-01util/nvmutil: clean up rhex()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-01util/nvmutil: check correct return value on close()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>