summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
14 hoursutil/spkmodem-decode: also auto-detect separatorLeah Rowe
the tone detection currently only tracks data, not the separator. track both instead, for improved detection reliability. e.g. separator tone ≈ 9 data low tone ≈ 18 data high tone ≈ 24 two fir windows produce e.g. freq data 9 sep 0 then 18, 9 then 24, 9 18, 9 so we take min(data, separator) that gives 9,9,9,9 now we have the separator cluster however, if both windows are active during transitions, you can also capture the higher clusters, which would allow freq_max to grow so when you learn e.g.: freq min = 9 freq max 24 then the learned threshold would be: (9 + 24) / 2 = 16 and now you know how to separate the tones fir already suppresses noise so the pulse should be reliable. so freq/sep only go non-zero when an actual tone exists this should now result in being able to sync with spkmodem encoders with no prior knowledge of the correct tone frequences. we just use maths. Signed-off-by: Leah Rowe <leah@libreboot.org>
15 hoursutil/spkmodem-decode: simplify valid_signalLeah Rowe
since we have auto-detection now, we only need to know that two signals exist, not that they are valid, since the auto-detection now handles validation and fallback. Signed-off-by: Leah Rowe <leah@libreboot.org>
15 hoursutil/spkmodem-decode: automatic tone detectionLeah Rowe
a continuation of the previous patch. this waits for currently one second, before defaulting to the hardcoded value. otherwise, it tries to use whatever timing it gets automatically. this way, the program should now reconfigure its own timing, without intervention by the user, if the timing differs from sensible defaults. this is because spkmodem is implementation-defined; it's just however coreboot and/or GRUB happen to set it up, and on the hardware in question. Signed-off-by: Leah Rowe <leah@libreboot.org>
15 hoursutil/spkmodem-decode: automatic tone calibrationLeah Rowe
current logic is hardcoded, as in the original spkmodem-recv. with this change, small differences are observed and averaged, then the detection thresholds are adjusted accordingly. the existing macros serve as a baseline, but real signals differ. with this change, we therefore account for possible drift in timings, which can change in real-time; the old code could possibly get out of sync beccause of that, which may have resulted in corrupt characters on the screen. this change therefore should make the output a bit more stable. the detection window is continually adjusted, so that the output timings don't drift. the tolerances are automatically adjusted based on base timings (see new define in patch) Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursutil-spkmodem-decode: tidy up print_statsLeah Rowe
make the frequencies clearer in printf Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursutil/spkmodem-decode: do getopt firstLeah Rowe
much cleaner. do it right after zero-init memset. Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursutil/spkmodem-decode: init argv0 before pledgeLeah Rowe
otherwise, it'll be empty/undefined Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursutil/spkmodem-decode: frequency meter in debugLeah Rowe
useful timing now displayed Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursutil/spkmodem-recv: reset char precisely on timeoutLeah Rowe
instead of when it goes above, do it precisely on the timeout. otherwise, if by sheer chance the signal pauses and we reset the byte - sure, ok, but it's a bit tight and we run the risk of advancing another frame, depending on the timing. this is a minor edge case, probably rarely ever triggered in practise. Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursrename util/spkmodem-recv to spkmodem-decodeLeah Rowe
it's no longer resembling the original util at all, so a rename seems indicated. yes. Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursadd missing starLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
17 hoursutil/spkmodem-recv: extensive commentingLeah Rowe
and with this, i'm now pretty much done modifying grub's crappy code. this experiment started in 2023 has now pretty much concluded. the original GNU code was poorly written, hardcoded everywhere, and not documented or commented at all. i had to learn what the code is doing through inference instead, and i'm pretty sure that these explanations cover everything. i hope? maybe the frenchman can explain anything i missed. haha. Signed-off-by: Leah Rowe <leah@libreboot.org>
17 hoursutil/spkmodem: explain what the defines areLeah Rowe
and calculate some of them instead of hard coding Signed-off-by: Leah Rowe <leah@libreboot.org>
17 hoursuseful commentsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
18 hoursutil/spkmodem-recv: also cache sep_pos in decodeLeah Rowe
yet another optimisation for weaker compilers - but some modern compilers may not optimise well for this code either. this reduces the amount of references to the struct, which is very expensive (48000 times per second) on very old CPUs. Signed-off-by: Leah Rowe <leah@libreboot.org>
18 hoursutil/spkmodem-recv: optimise decode_pulseLeah Rowe
the frame[] array is never actually used meaningfully. that setting of frame[ringpos] on the decode_state is only set here, but then the value isn't really used at all. the entire size of the annay is used for sizeof in print_stats, but then we can just declare that manually. since we also know that this value never changes, we can use a global define for the sizeof entry in print_stats, thereby simplifying operation further Signed-off-by: Leah Rowe <leah@libreboot.org>
18 hoursutil/spkmodem-recv: clean up decode_pulseLeah Rowe
make it easier to read by clearer variable naming. this change also reduces memory accesses (fewer struct dereferences - see: struct decoder_state), when using much weaker/older compilers that don't optimise properly. this, in the most active part of the code, which is called.... 48000 times a second. peanuts on modern CPUs, but on old (early 90s) CPUs it makes a big difference. Signed-off-by: Leah Rowe <leah@libreboot.org>
18 hoursutil/spkmodem-recv: byte swap on big endian CPULeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/spkmodem-recv: remove errno defineLeah Rowe
may break on modern systems (macro) Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursadd endianness check to spkmodem-recvLeah Rowe
a bit dirty. should handle this at runtime. Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/spkmodem-recv: properly handle stdin errLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursanother correctionLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
19 hoursutil/nvmutil: fix regression on openbsdLeah Rowe
when i removed arc4random integration, i forgot to change this line back. oops! Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursTODOLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursTODOLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
20 hoursTODOLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: mitigate buggy libc i/oLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: implement zero-byte r/w timeoutLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursTODOLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
21 hoursutil/nvmutil: add some useful commentsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: split up rw_file_exactLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursfix indentationLeah Rowe
i was editting this in another editor Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: add jitter to fallback_rand entropyLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: improved entropy in fallback_randLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: remove /dev/random fallbackLeah Rowe
only use the old fallback, or /dev/urandom /dev/random blocks on some older unix machines, or in embedded environments that may never have enough entropy, causing the code to hang. urandom is most certainly expected to exist on pretty much anything since the mid 90s. i could probably re-add the arc4random setup for BSDs. i'll think about it. gotta do that portably too. Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: include time.h after types.hLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: mitigate fast calls to randLeah Rowe
if someone calls rhex fast enough, the timestamp may not change. this mitigates that by adding a counter value to the mix Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: fallback randomiserLeah Rowe
used when a random device isn't available, on old unix, or on certain chroot environments. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: correct install usageLeah Rowe
one for directory, then copy the binary Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: fix makefileLeah Rowe
forgot to include the binary in the path Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: remove errno externLeah Rowe
may break modern systems. and all old systems that i care about will handle errno just fine. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: use install -d instead of mkdir -pLeah Rowe
-p isn't portable Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: fix commentLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: use chmod instead, in MakefileLeah Rowe
yeah, why not use a tool that's been around since the 80s? Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: add -m to install on MakefileLeah Rowe
also support LDFLAGS Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: simplify flags on urandomLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: fix mistake in random checkLeah Rowe
forgot this. oops Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: portable errnoLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: fix non-portable variable declarationLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: disable urandom if not foundLeah Rowe
disable random mac address generation on really old operating systems. Signed-off-by: Leah Rowe <leah@libreboot.org>