Commit Graph

58 Commits (d8ac9d53b66a3a940962945c4102f1fcd644cde1)

Author SHA1 Message Date
Leah Rowe 4cdf60e60a util/spkmodem-recv: detailed copyright history
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-10-17 13:55:20 +01:00
Leah Rowe b727f9666b util/: use SPDX license and copyright headers
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-25 02:49:34 +01:00
Leah Rowe b508245451 util/spkmodem-recv: rename function for clarity
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-14 08:43:54 +01:00
Leah Rowe 17cd0af9c1 util/spkmodem-recv: remove unnecessary error check
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-13 22:52:12 +01:00
Leah Rowe a1758a7ab0 util/spkmodem-recv: say cc, not gcc, in comment
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-13 22:35:34 +01:00
Leah Rowe 2b5727310c util/spkmodem-recv: fix bad comment
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13 22:34:31 +01:00
Leah Rowe bd8b8919f9 util/spkmodem-recv: remove unnecessary assignment
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13 22:29:34 +01:00
Leah Rowe 5be3d67ced util/spkmodem-recv: simplify getopt handling
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13 21:01:15 +01:00
Leah Rowe 5c5c1c64fd util/spkmodem-recv: cleaner ring buffer handling
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-13 20:47:17 +01:00
Leah Rowe b52a7f4f86 util/spkmodem-recv: re-add full license header
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-12 23:37:58 +01:00
Leah Rowe dee8f44b37 util/spkmodem-recv: fix regression
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-08 12:35:36 +01:00
Leah Rowe f2822db9dd util/spkmodem-recv: make ringpos a global variable
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-05 15:38:36 +01:00
Leah Rowe 334bfedfd4 util/spkmodem-recv: simplify sample_cnt/char reset
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05 02:05:36 +01:00
Leah Rowe 4a6b582777 util/spkmodem-recv: print stats in other function
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05 01:57:20 +01:00
Leah Rowe 2652a1ddfa util/spkmodem-recv: only print unhandled err on -d
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05 01:53:24 +01:00
Leah Rowe 3fb99a017d util/spkmodem-recv: make debug a runtime option
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-05 01:37:06 +01:00
Leah Rowe 264a31b95d util/spkmodem-recv: always disable line buffering
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-05 01:05:38 +01:00
Leah Rowe 118bb19ff8 util/spkmodem-recv: simplify stdout flush logic
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-05 00:46:41 +01:00
Leah Rowe af36cc7f93 util/spkmodem-recv: rename variables for clarity
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05 00:34:44 +01:00
Leah Rowe f7fccb5963 util/spkmodem-recv: split print_char() up
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-04 17:16:26 +01:00
Leah Rowe b40a30b11b util/spkmodem-recv: reduce indent in print_char()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04 17:05:24 +01:00
Leah Rowe b21c1dd5e8 util/spkmodem-recv: squash a few code lines
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04 16:30:03 +01:00
Leah Rowe 3401f287b4 util/spkmodem-recv: bsd-style indent
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-04 15:42:01 +01:00
Leah Rowe 2a6ad97150 util/spkmodem-recv: order prototypes per function
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04 15:38:03 +01:00
Leah Rowe 212ce3a8ac util/spkmodem-recv: warn on unhandled exit error
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-04 15:33:23 +01:00
Leah Rowe 9a6d290871 util/spkmodem-recv: another minor code cleanup
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04 15:31:23 +01:00
Leah Rowe a61ab37b67 util/spkmodem-recv: always set errno on err()
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-04 15:27:29 +01:00
Leah Rowe e8889fd107 util/spkmodem-recv: minor code cleanup
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-04 15:23:51 +01:00
Leah Rowe 3c2a287eea util/spkmodem-recv: handle sample errors correctly
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-04 15:19:53 +01:00
Leah Rowe 979db74ca5 util/spkmodem-recv: simplify pulse check
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-04 15:10:35 +01:00
Leah Rowe 83ecf26833 util/*: Properly detect OpenBSD for pledge() call
The utils that are pledged checked HAVE_PLEDGE which was
bogus. OpenBSD defines __OpenBSD__, which you can check
for in ifdef.

This change makes nvmutil and spkmodem-recv *actually*
use pledge, when the utils are compiled on OpenBSD.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-30 16:02:25 +01:00
Leah Rowe 5b59490928 util/spkmodem_recv: Use pledge but only on OpenBSD
It will only be used on OpenBSD. Other operating
systems will behave in the same way.

Pledge is feature specific to OpenBSD that
restricts system operations, for security:

https://man.openbsd.org/pledge.2

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 25241ae222 util/spkmodem_recv: Add -u flag (no line buffer)
printf outputs to stdout, which is line buffered
by default.

Adding a -u option to disable buffering.

Exit when a non-support flag is given, but adhere
to current behaviour when no flag is given.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 01fdfa3ab6 util/spkmodem_recv: Tidy up global variables
They do not need to be initialised zero, because
global variables are always zero by default,
unless set differently by the programmer.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 50b35939de util/spkmodem_recv: Make pulse variable global
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 14190de9e8 util/spkmodem_recv: Use parentheses on comparisons
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe c0f2bf3077 util/spkmodem_recv: Move global variable: pulse
It is only used by a single function.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 5d03598b99 util/spkmodem_recv: Purge unused global: amplitude
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 63e43819b3 util/spkmodem_recv: Remove unused variable: pos
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe a0abcb9f53 util/spkmodem_recv: Re-order functions for clarity
print_char() is referenced last, so declare it last.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 93cc664254 util/spkmodem_recv: Handle output in new function
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 27866e65fb util/spkmodem_recv: Re-order prototypes
Put them in the same order as declared.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 8b851258e2 util/spkmodem_recv: Rename functions for clarity
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 6c1bf756d3 util/spkmodem_recv: Return errno in main
This is a good general practise, to catch errors.

Any errors found can then be handled in code.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe c23806e1f6 util/spkmodem_recv: Use correct printf specifier
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 0cc23b2363 util/spkmodem_recv: Add error handling
There was literally no error handling before.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 179323819b util/spkmodem_recv: Move logic out of main
Main should only be a skeletal structure.

Actual logic should always be handled externally.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 3d55429443 util/spkmodem_recv: Rename variable for clarity
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 697ae5e2ca util/spkmodem_recv: Remove use of static keyword
It is entirely superfluous in this program.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00
Leah Rowe 2c12e70cfe util/spkmodem_recv: Rename variable for clarity
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-05-16 23:11:35 +01:00