Commit graph

4007 commits

Author SHA1 Message Date
bunnie
f720314dc4 add mising dependency on owc-inc feature flag 2026-06-10 14:37:49 +08:00
bunnie
69c68db711 remove a warning in dabao build 2026-06-09 00:00:23 +08:00
bunnie
a3e7a9fc9c add note documenting app-keys feature gate 2026-06-08 23:59:32 +08:00
bunnie
9f4421dadd add AppKey implementation
this adds, with a feature-gate, the option for userspace
programs to use & access keys in the APPLICATION data slots.

The implementation bounds-checks the requested indices to ensure
sensitive data in slots around the APPLICATION region cannot
be accessed. Even with corrupted AppKeyOp packets, it shouldn't
be possible to access other slot ranges, but because this code
is so intimate with importan secrets it's recommended to
gate the feature off unless required by the end user application
code.
2026-06-08 23:55:35 +08:00
bunnie
2005a801c9
Merge pull request #877 from tunnell/pr-net-encoding-fix
Write NetError code at byte 1 too, so std-recv decode works
2026-06-03 00:41:58 +08:00
Jeanie
e9058268ce fix cfg gating for gdb-stub in xous-log 2026-05-30 17:18:38 +09:00
bunnie
b9d4b0578d
Merge pull request #888 from finnmglas/finn/constant-time-pw-verify
use constant-time password verification
2026-05-30 01:36:02 +08:00
bunnie
a421b7abfa replace watchdog hack with an atomicbool; reset cam on setup
This patch replaces the watchdog thread with a spin-wait on
an atomicbool that is set by the IRQ handler once an IRQ
triggers. This is a much cleaner, lower-overhead way to handle
the time out.

This patch also puts the camera setup into a retry loop, and
by default on setup it does a hardware reset of the display
subsystem (this includes the OLED screen). This hopefully
gives the subsystem a much better chance of recovering from
the camera being in a scrambled state. The working theory
for why the camera might get scrambled is that it assumes
it is a sole I2C device, and when its init sequence is
interrupted by other devices handling requests it does
not handle this situation gracefully.
2026-05-29 00:08:02 +08:00
Finn Glas
2eeacada70 use constant-time password verification
The password verification in RootKeys compared hashed passwords
byte-by-byte with an early return on mismatch. This leaks how many
leading bytes match through timing, weakening the protection that
bcrypt provides.

Replace the loop with subtle::ConstantTimeEq::ct_eq, which is
already used elsewhere in this crate (backups.rs, FPGA key check).

Signed-off-by: Finn Glas <finn@finnmglas.com>
2026-05-27 23:29:40 +02:00
bunnie
db60bca7fb fix formatting 2026-05-27 13:30:13 +08:00
bunnie
d325f80e31 gate camera wdt behind a feature flag
not needed in all scenarios
2026-05-27 13:19:11 +08:00
bunnie
f0c80a17fa adjust camera wakeup params 2026-05-26 02:22:01 +08:00
bunnie
a4316e2aa7 add dry-run api to gfx
dry-runs are useful for warming up "hot paths" in UI code
to improve latency. This is specifically a feature for tuning
interactions on systems that have swap memory.
2026-05-24 00:45:13 +08:00
Chris Tunnell
1f08ab57fc
Merge branch 'dev' into pr-net-encoding-fix 2026-05-18 21:26:05 +02:00
bunnie
9232b87139 fix camera inconsistent start issue
on first boot, camera may not always start (some boards it never starts)
it always starts on a second prompting

the issue is related to the relevant code being swapped out, it seems;
i think an event fires and gets missed in the fray of all the data
being swapped in from off-chip storage.

this patch:

- re-orders the pipe warming and system bring-up
- adds a watchdog thread that ensures the camera interrupt fires,
and if it does not, issues a manual camera interrupt to kick
start the system

This greatly improves the reliability of first-start success. Across
several trials on many units i had only one misfire - not sure what
it was, can't reproduce, but this is much better than the roughly
80-90% misfire rate I was seeing before.

ship it.
2026-05-18 17:51:32 +08:00
bunnie
d3970eaa80 remove potential race condition in sending U2F packets over USB
The hardware handler structure passes through an interrupt
request boundary that breaks assumptions around the borrow
handler due to the unsafe transmutation of the record pointer
at the interrupt handler entry. This means that records shared
between the userspace and machine handler space are not part
of the borrow-checker's review.

This patch adds an AtomicBool flag that indicates if the ISR
has completed running, and forces the userspace to wait until
the ISR has completed before returning. This does potentially
slow down the rate of packet transmission but it ensures that
the `fido_tx_queue` structure does not have concurrency issues
in the case where the following happens:

1. U2fTx opcode encountered
2. fido_tx_queue has a u2f_msg put on it
3. ISR triggered
4. in the process of handling the ISR, a page fault is hit, so
the ISR doesn't start for some time.
5. Before the ISR returns, another U2FTx opcode is encountered
6. fido_tx_queue is being modified by userspace
7. The ISR is able to resume
8. You have a simultaneous modification to the fido_tx_queue
which is UB.

I think it's maybe possible that this scenario above can't
structurally happen due to an ISR page fault not allowing
the system to resume through to "normal" code running (iirc
the swapper will handle a page fault in ISR and resume directly
into the ISR routine) but this patch guards against incorrectness
in that implementation.

for what it's worth, later tests show that this bug was not
actually at the root cause of the behavior I was chasing down,
so in fact this was not happening. However I think it's still
a good idea to fix this potential problem.
2026-05-18 12:54:17 +08:00
Chris Tunnell
84aa303605
Merge branch 'dev' into pr-net-encoding-fix 2026-05-17 12:06:48 +02:00
bunnie
3d05954f95 fix broken test case 2026-05-13 00:26:04 +08:00
hanatonikkou
ead2e9dda0 Merge branch 'dev' into dali 2026-05-11 15:26:11 +02:00
tunnell
cfcc12eee3 fix(net): write NetError code at byte 1 too, so std-side recv decodes correctly
Mirror the error code at byte 1 (in addition to byte 4) in
respond_with_error. The std-side Xous net backend's send path
reads byte 4 (correct vs. the historical [1,1,1,1,code,0,0,0]
layout), but the recv paths read byte 1 (which is always 1
under the old layout, so ErrorKind::TimedOut and WouldBlock
were unreachable from the recv side). With this change both
decoders see the right value; existing byte-4 readers are
unaffected; the "buf as u32-LE != 0" error marker still holds
because byte 0 stays 1.

Companion PR to rust-lang/rust will fix the std side to read
byte 4 and match the send path. This kernel-side mirror is the
shippable workaround until that lands and works with any
Rust-toolchain version.
2026-05-10 20:30:49 +02:00
bunnie
f12996a1ab logger loop must never exit, handle exit message with panic 2026-05-09 16:31:12 +08:00
bunnie
0f1cae49f0 make i2c/peri conns lazy
this prevents race conditions on boot between the various
hardware manager dependencies.
2026-05-09 16:06:57 +08:00
bunnie
0c894b05dd disable interrupts before installing interrupt handler
kernel can lock on boot if keys are pressed in the loader. This
would cause the interrupt handler to trigger while the handler is
being registered, before everything is set up, leading to an IRQ
storm and the kernel hanging.

the fix is to simply disable interrupts while the setup is happening

a further refactor is the run() method is marked as diverging,
so that it's clear what's going on in the code. this refactor
touches other targets as well, since it's at an api level and
not just a target level.
2026-05-08 23:28:32 +08:00
bunnie
5336b7825b fix formatting issue 2026-05-08 04:25:35 +08:00
bunnie
b669d65f80 fix startup race-condition on baosec platform 2026-05-08 04:22:29 +08:00
bunnie
679b709d2c
Merge pull request #864 from tunnell/fix/root-keys-fpga-key-ct-eq
Use constant-time compare for FPGA key check
2026-05-08 03:22:01 +08:00
bunnie
12268b32f3
Merge pull request #863 from tunnell/fix/gam-token-ct-eq
Use constant-time compare for GAM auth tokens
2026-05-08 03:21:21 +08:00
bunnie
b48df7182b make preemption switching infalliable
this allows suspend/resume to complete even if there's
a back-up in the hal processing these requests
2026-05-08 03:11:58 +08:00
bunnie
ae0eee60c5 make bio-op infalliable
this allows suspends to proceed even if the subsystem has an error
2026-05-08 03:11:30 +08:00
bunnie
ccb5912c1a fix timeout on suspend/resume
the susres process timeout timer was not cancellable, which means
that there was always a timeout pending regardless of the
success or failure of a suspend/resume process.

This fixes the implementation so that the timer is cancelled
in the case of a successful suspend/resume.
2026-05-08 03:10:33 +08:00
bunnie
2ddc5563f6 fix hosted mode 2026-05-06 07:28:08 +08:00
bunnie
7ca009d2b0 Revert "remove api call for reset_reason"
This reverts commit 1dd514f4be.

not sure why but this breaks stability. suspect a loader bug.
2026-05-06 03:28:52 +08:00
bunnie
1dd514f4be remove api call for reset_reason
the register doesn't seem to work.
2026-05-06 02:36:56 +08:00
bunnie
7097164b23 cleanup errant info message 2026-05-06 02:02:05 +08:00
bunnie
761b713d72 add key repeat filtering 2026-05-06 01:29:20 +08:00
bunnie
e2a229faf2 refactor service start order for the main hardware loop
- move susres service up in order
- move clock mangaer up
- move i2c into its own thread
- move keyboard server down
- add centralized hnadlers for perclk update
  - TODO: actually call perclk update on perclk changes
  (but at least now both ADC and I2C have a hook for updating)
- make main loop stall at the end by calling a dummy server
  - This reduces CPU load by removing a future-dummy-wait timer
2026-05-06 00:09:51 +08:00
bunnie
3b4d6a90ed add reset reason userspace apis 2026-05-06 00:09:21 +08:00
bunnie
c6b1b6bb79 refactor i2c implementation into an independent thread
prevents i2c from blocking progress on other critcial hardware
API activities
2026-05-06 00:00:33 +08:00
bunnie
4208ba2e0b reduce debug spew and add userspace api for reset reason 2026-05-05 23:59:39 +08:00
bunnie
602e028402 add some debug tracking on keyboard listeers 2026-05-05 23:59:18 +08:00
bunnie
351830c7d0 implementation side of non-blocking dimming 2026-05-05 23:54:51 +08:00
bunnie
d46fa5a153 fix windows related regression in hosted mode run 2026-05-05 23:53:40 +08:00
bunnie
8440706279 reduce debug 2026-05-05 23:53:18 +08:00
bunnie
e9a0b59ab0 soft-fail on request for console 2026-05-05 23:53:02 +08:00
Chris Tunnell
9e76e0d15f
Merge branch 'dev' into fix/root-keys-fpga-key-ct-eq 2026-04-29 11:42:05 +02:00
Chris Tunnell
afd814166d
Merge branch 'dev' into fix/gam-token-ct-eq 2026-04-29 11:36:50 +02:00
hanatonikkou
d69a03393b fix formatting, fix bitfield offsets 2026-04-28 20:01:34 +02:00
hanatonikkou
d26b04f043 allow changing fclk through susres server 2026-04-28 15:16:33 +02:00
bunnie
6a7caff54c improve display boot stability
an instance of the SPI interface timing out was observed on boot.
It's rare, but it happens.

This wraps those early calls with a retry loop and then
fail to reboot in case something really goes wrong.

Assisted-by: qwen3.6:27b (local)
2026-04-26 17:32:05 +08:00
bunnie
4d1dc33ef1 add a diffusive transition option to the graphics library
makes changing between bitmaps less jarring
2026-04-23 15:14:27 +08:00