Commit graph

37 commits

Author SHA1 Message Date
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
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
bunnie
9815e33f4e fix missing packet issue due to storage overflow 2026-04-23 00:34:35 +08:00
bunnie
0d2c7233d6 improve stability of USB when not plugged in
don't try to use the USB stack when nothing is plugged in
2026-04-21 01:21:13 +08:00
bunnie
3f869ca389 bump utralib version for publication 2026-01-29 19:12:00 +08:00
bunnie
ca630c6472 add maintenance comment on USB driver 2026-01-29 18:59:29 +08:00
bunnie
b2cf705c59 bump ticktimer version to drop susres dependency 2026-01-28 20:53:57 +08:00
bunnie
8b06b212bb add oem-baosec-lite support to usb driver
there is currently no method to detect USB power connect
in this board. Considering adding a simple circuit to enable
this. This design is not meant to be battery powered but
it is possible that an aftermarket modification would introduce
a battery, in which case, vbus detection does become A Thing.
2026-01-24 23:54:21 +08:00
bunnie
fba011db3a commit version bump so that we may publish our packages 2026-01-08 03:04:19 +08:00
bunnie
77f55941f0 cleanup import path 2025-12-24 13:17:19 +08:00
bunnie
a313887c26 re-organize usb server so that hosted mode can be cleanly turned on 2025-12-24 13:14:11 +08:00
bunnie
d874c3e5c2 commit for version bump 2025-12-16 02:02:37 +08:00
bunnie
8950a24327 move i2c in bao1x-hal-services into bao1x-hal
this makes i2c accessible without having to rely explicitly
on the server itself, making the library callable in more contexts.
necessitated avoiding a name space collision and moving the
I2C hardware drivers to a stucture named I2cDriver; the I2C
object now unambiguously refers to the userspace interface
to I2C.
2025-12-11 02:13:21 +08:00
bunnie
543f455ad0 fix scalar return discipline in usb-bao1x
also add ability to read keyboard led state
2025-11-24 18:54:50 +08:00
bunnie
664ef0a6c4 use serial numbers & interim pid/vid in USB stack 2025-11-06 14:07:30 +08:00
bunnie
5863296632 cleanup the feature tree; add double-lock detection printing
this cleans up the feature dependency tree a bit and also adds
some ability to print an error when the double lock condition
is discovered. it should be solved but it can only be detected
at runtime. Insntead of it being a silent failure (because
the server hung in an interrupt context and couldn't emit any characters),
it sets an atomic bool that can be checked and reported upon by
the main thread.

also cleans up debug uart acquisition.
2025-11-03 08:02:21 +08:00
bunnie
03aeafc21a release SE0 using the tristate, not by driving the pin
this reduces current draw when the prog button is depressed.
2025-10-29 03:43:45 +08:00
bunnie
37ff052b34 chunk data to the USB subsystem
the chunks match the size of the application buffer, eliminating
the possibility of an overrun (of the buffer at least)

there is a possibility still i think of overrunning USB itself
but i think the CPU can't produce data fast enough to actually
do that.
2025-10-25 22:23:36 +08:00
bunnie
8f208cac4c
refactor debug-print in bao1x-hal
on dabao targets the duart is unavailable, so, it's convenient to
have a uart-based debug option in the HAL. this patch creates a
flag that can allow either target.
2025-10-19 01:19:30 +08:00
bunnie
dbb0a75118 bump versions
have to absorb a version change due to xous-semver change

might as well also update the utra/svd generator dependencies
since that's been held off for a long time now.
2025-10-06 13:23:18 +08:00
bunnie
140f1ae538 add dabao support to usb-bao1x
the minimal set of envisioned services for the dabao would
include a USB handler. Seems like too useful a thing to not
have it enabled.
2025-10-05 17:17:31 +08:00
bunnie
e00606538c add SE0 release to userspace usb driver 2025-10-04 16:21:34 +08:00
bunnie
8e4d1d047f remove debug prints from usb userspace
these conflict with the kernel debug prints.
2025-10-01 23:34:53 +08:00
bunnie
1255bf12d9 FLAG DAY: fix all names to harmonize around 'bao1x'
The code base had evolved through several code names, interim
names, company names and chip names that alternatively did or did
not exist.

Baochip is the definitive name of the company, and the Baochip1x
(full part number BAO1X2S4F-WA) is the definitivey part number of
the SoC. For convenience, the part number is shortened to 'bao1x'
in most feature flags and variable references.

This commit fixes all of the odd names and removes some unmaintained
early targets.
2025-09-18 21:25:51 +08:00
bunnie
9b515a042f add serial port library functions and handlers
this creates hooks for applications to listen to the serial port,
as well as to send and receive data. some improvements to code
ordering for readability are bundled in this as well.

very lightly tested, most of the code comes from other more tested
code in the Precursor stack.

the TRNG test stuff is not put into this stack because I think
it belongs in the baremetal environment, as it's only ever
run for characterization. We don't need to bog down the production
stack with test code.
2025-09-13 15:37:08 +08:00
bunnie
c47334704a PoC USB serial on top of the HID modes.
this now works with windows, after much testing and patching.
2025-09-13 01:12:12 +08:00
bunnie
b99da45c38 fixup dependencies to point to local fork versions
the local forks are needed to layer in high speed support,
debug, and a couple of other minor improvements.
2025-09-12 02:51:19 +08:00
bunnie
1b9c0c7143 gate off duart mapping when not debugging deep in the usb stack 2025-09-12 02:50:45 +08:00
bunnie
d20a1e4ed9 gate of unused functions without mass-storage 2025-09-12 02:50:24 +08:00
bunnie
e79f907bb7 add basic usb-serial support
some test code to echo characters back, needs to be improved
fix some reset edge cases, needs more work as stack still
does not enumerate on second plugin
2025-09-12 02:49:21 +08:00
bunnie
5ff4b6c317 turn off debug-print by default in usb 2025-09-09 22:20:02 +08:00
bunnie
1cd6a3c4d0 clean up warning 2025-09-09 18:41:25 +08:00
bunnie
16b3c43e31 get OUT packets working; in particular, HID/U2F seems good to go 2025-09-09 17:53:47 +08:00
bunnie
51adf0e76c clean up interrupt handler & remove page allocation from handler
handler works in an interrupt context, so it can't allocate
a page to return data. this cleans up that problem, and also
removes some redundant brute-forced checks that were copypasta
from previous merging of several routines.
2025-09-09 17:52:12 +08:00
bunnie
5978de6a22 cleanup warning 2025-09-09 17:51:48 +08:00
bunnie
6cf4757323 rename usb-cramium to usb-bao1x 2025-09-08 17:21:32 +08:00