Commit graph

10340 commits

Author SHA1 Message Date
bunnie
40a275232c udpate tomls to explicitly enumerate features used 2026-02-20 23:54:07 +08:00
bunnie
905939d8f1 featurify all BIO modules
the reason we do this is that if we don't switch off library
modules, they are compiled in and just become dead code in the
OS image. with enough modules, this will eventually become
a significant drag on binary size.
2026-02-20 23:53:09 +08:00
bunnie
85a9579626 update readme with toolflow and erratum 2026-02-20 23:52:42 +08:00
bunnie
9e34da0bf7 add autogeneration header to output artifacts 2026-02-20 23:52:16 +08:00
bunnie
6176d3379d streamline zig build flow 2026-02-20 23:51:58 +08:00
bunnie
aa06be9c82 commit an initial c test program
this is a "math test" that can compute cosines in fixed point
using the BIO.
2026-02-20 21:02:54 +08:00
bunnie
cdf489d2b1 fix std-implementation for code size/offset/padding specification 2026-02-20 21:02:19 +08:00
bunnie
6cc9e2d5f7 fix constant table in cosine 2026-02-20 21:01:55 +08:00
bunnie
9d23703e45 fix API for new code specification method 2026-02-20 21:01:23 +08:00
bunnie
c1571479d6 remove out of place comment 2026-02-20 21:01:00 +08:00
bunnie
60d0126f37 implementation of code-length & padding for BIO code segments 2026-02-20 20:58:40 +08:00
bunnie
29437c1ae8 Add an aligned bio_code macro
This macro introduces page-level padding around the BIO code
regions, so that the rust assembler/linker computes relative
offsets correctly. This is necessary for code that is
autogenerated from C that uses `statics`

It's not recommended to be used *everywhere* because even
tiny BIO snippets of a few bytes would be blow up to 4k each.
2026-02-20 20:57:10 +08:00
bunnie
a97675592c Add erratum notes to README and a tool to check & repair erratum
erratum_check.py will automatically scan bio_code! segments
in a .rs file, flag patterns that could be a problem, and
can automatically patch these, if requested.
2026-02-20 20:55:34 +08:00
bunnie
a6a8341223 Fix BIO erratum in assembly translator.
Getting compiled code going has revealed a couple of frankly
embarassing erratum in the BIO. Kind of shameful to make such
a n00b mistake but I guess my sole defense is I had to put it
together in a hurry with little resources.

Here's the bugs:

BUG 1 ("phantom rs1"): For lui/auipc/jal, the 5-bit field at
instruction bits [19:15] is not gated off. If that field decodes
to register 16-19 (x16-x19) for just these instruction types,
a spurious pending read is made from the corresponding FIFO,
which affects correctnes and can block execution.

BUG 2 ("phantom rs2"): For non-R/S/B-type instructions, the 5-bit
field at instruction bits [24:20] should be gated off but isn't.
When that field equals 20 (0b10100), a spurious `quantum` signal
triggers, which can affect the instruction fetch pipeline

This script inspects the output of the Clang assembly, and in the
process of translating it to Rust assembly, transparently patches
almost all of the cases with work-arounds. The assumptions and
exceptions for the work-arounds are:

- The stack pointer is initialized and valid. This is always
true for Clang-derived scripts because it's in the _start()
routine

- No interrupts that can mutate stack: true because interrupts aren't
supported in this implementation.

There is one edge case that isn't covered: J-type instructions
aren't patchable at this stage because the label offsets haven't
been resolved into instructions. However, "naked" jal instructions
are rare in compiled code - it's always jalr, which is an I-type
instruction. This is noted as a warning when the script runs, and
is fixable by simply inserting a "nop" after the jal instruction
if the target is at the wrong address - this will shift the immediate
so that it no longer contains the 0x14 (decimal 20) pattern in
the immediate field.
2026-02-20 18:40:37 +08:00
bunnie
db78b28b37 checkpoint the c -> rust asm flow for the BIO
An abomination: a zig-based C toolchain, installed via python,
compiles to clang assembly, translated by python script, into
Rust assembly. Then compiled and linked into your app.

Really tempting fate with this one...will I come back to this
commit in a couple years and be filled with regret?

Already, I have some misgivings - the zig toolchain is
definitely not stable, and has been through some API changes,
and doesn't run on all platforms. But - I forge ahead.
2026-02-20 02:19:46 +08:00
bunnie
b932d7d755 fix a the mul demo
we don't have to do the weird mul coding anymore because
we added ".option arch, +m" to bio_code! macro
2026-02-20 02:11:09 +08:00
bunnie
b991a54b52 add debug call for bio 2026-02-20 02:09:09 +08:00
bunnie
a56ed768e8
Merge pull request #823 from betrusted-io/sram-tests
add tests to check sram glitch event triggers in baremetal
2026-02-18 21:27:55 +08:00
bunnie
2e0c7c2722 fix CI to run on dev branch as well as main 2026-02-18 21:22:47 +08:00
bunnie
7d6272fc8a fix formatting regression 2026-02-18 21:20:41 +08:00
bunnie
5397e1b488
Merge pull request #822 from betrusted-io/baobit-audit
Baobit audit
2026-02-16 20:14:47 +08:00
bunnie
eb2e370632
update audit print to facilitate build checking
- include the toolchain hash for reproduction iff it is
specified
- for the code hash, report *only* the code region, none of
the signature headers. This should match exactly what is
reported by the *_presign.img artifacts.
2026-02-16 18:11:34 +08:00
bunnie
da895b2c1f
extend sealed data to contain a toolchain hash field
the sealed data records are laid out with some extra space
at the end for future expansion.

The first such expansion added is a toolchain hash, which allows
us to note which toolchain is required to reproduce the current
image.

The change is backward compatible so the version field of
the record is *not* incremented.
2026-02-16 18:10:08 +08:00
bunnie
692fb5fed9
update signer to accept and inject baobit-commit hash
in order to prevent the recursive introspection issue, the
code image is built from a reproducible toolchain from
a given commit on xous-core. However, in order for us to
record *which* toolchain was used, it's impossible to do
this without modifying the commit hash of the toolchain -
thus making it impossible to know what toolchain was actually
used to build the reproducible code.

The fix to this is to out-of-band, at the final signature time,
patch over a field in the signature header expressly laid out
to accommodate the hash.
2026-02-16 18:07:42 +08:00
bunnie
9be2cbf99e remove baobit commit command line argument
the baobit commit will be injected at final file packaging time
2026-02-16 18:07:01 +08:00
bunnie
e68a61dd9a unrelated but update the restore.py script to refer to the new release tag 2026-02-16 17:23:02 +08:00
bunnie
a902b545e3
Merge pull request #821 from sbellem/bao1x-boot-baobit-toolchain
Add `--baobit-commit` flag for build provenance
2026-02-16 02:06:24 +08:00
bunnie
2c7150bc9b
Baobit version refinements
- add a function we can re-use to check if a file needs updating
- change the wording of the baobit commit when it's not specified
to "unspecified" vs. "unknown"
2026-02-16 01:33:06 +08:00
Sylvain Bellemare
3ea92d3bad
Add --baobit-commit flag for build provenance
Adds BAOBIT_COMMIT constant to boot0/boot1 version.rs, allowing
the Guix build channel commit to be embedded in firmware for
reproducibility verification.

- Add --baobit-commit CLI flag to xtask
- Generate BAOBIT_COMMIT in boot version files
- Display in audit command output
- Simplify versioning.rs to always write files
2026-02-16 08:24:55 +09:00
bunnie
4efe50d870
Merge pull request #820 from betrusted-io/final-audit
Final audit
2026-02-15 04:24:28 +08:00
bunnie
eb2017f845
fix off-target feature for precursor builds 2026-02-15 03:59:52 +08:00
bunnie
4aeabd01ae
clocks has to work in std and no_std
thus the die routine doesn't work in the bollard for
the clocks routine
2026-02-15 03:43:47 +08:00
bunnie
b8206c2cfc
minor boot1 improvements
- improve bollards to use the die call
- fix panic to call die
2026-02-15 03:37:48 +08:00
bunnie
f079a1480b
fix more bounds checks in USB handler
- CBW block only derived after length is validated
- write offset to disk uses checked_add, necessary
since we're compiling in release mode
2026-02-15 03:36:32 +08:00
bunnie
6d77efc02e
upgrade jump api in boot1 to use asked jump format 2026-02-15 03:35:54 +08:00
bunnie
1a43540037
minor improvements across boot0 flow
- improve bollards to include "die" jumps where appropriate
- cleanup warnings in unsafe-dev feature
- panic handler calls die repeatedly
- upgrade jump api
2026-02-15 03:34:35 +08:00
bunnie
df10c50c14
add bounds checking on payload size in UF2
if the magic numbers match, the payload size field must also
pass the sanity check for the packet to be considered for
further processing.
2026-02-15 03:33:04 +08:00
bunnie
9780fe3ea4
same fix as previous commit but for boot1 2026-02-15 03:32:30 +08:00
bunnie
59bd74a01c
panic directly on illegal instruction
the original stub for illegal instruction handling advances
the program counter - this was copypasta from the kernel
irq routine, where this behavior is needed to handle syscalls.

However, this behavior is contra-indicated for the purpose
of dying on a bollard - you don't want to skip past the
bollard for any reason.
2026-02-15 03:29:50 +08:00
bunnie
f462e3dc3c repl code in boot0 is not used in production
strip out old stuff that doesn't work anymore -- eventually this
code may be entirely struck since it's not even been compiled
for many months.
2026-02-15 03:28:50 +08:00
bunnie
4d86e8a82b
use die_no_std in hardening; remove excess prints
also fix some math regarding birthday paradoxes and the
random number checking.
2026-02-15 03:27:20 +08:00
bunnie
70f219ba0a
sigcheck hardening
- xor-masking of jump target moved to immediately before the jump
- mscratch csr zeroed
- anti-rollback single-update distance limited to 512: let's hope we
never even get close to having 512 security revisions in a single
generation!
- sanity check untrusted signature/add length fields - constrains
hash-checks to within the right "range", preventing abuse of the
hash reads as an oracle to leak state about other things in memory.
- check valid_key != valid_key2 invariant before returning
2026-02-15 03:22:47 +08:00
bunnie
c71f472743
fix in-line directive on hardened bool
this prevents there being a single "hot spot" to attack for
hardened bool testing
2026-02-15 03:20:54 +08:00
bunnie
e8380aa0e7 clarify panic intent 2026-02-15 03:20:21 +08:00
bunnie
000c4effab
panic in loader should call die instead of just looping 2026-02-15 03:19:32 +08:00
bunnie
414cff252f chore: fix formatting
somehow some formatting regressions snuck in despite previously
being CI-clean on formatting.

I suspect this might have to do with the Rust 1.93.1 bump
that happened just recently, sometimes new versions of Rust
introduce small formatting changes.
2026-02-14 19:47:50 +08:00
bunnie
575efa6129
refactor function call to use macro
the macro will give relevant positional information when the
assert fails, whereas the function always fails in the same place
and we lose that valuable debugging info
2026-02-14 19:35:45 +08:00
bunnie
4a776852a9
add UDC pointer check macros throughout the USB driver library 2026-02-14 19:34:49 +08:00
bunnie
703a56b925
add pointer checks on USB hardware interfaces
The USB engine passes raw pointers around for DMA purposes;
most importantly, it passes *back* raw pointers and lengths.
There's no really good way to check these, and I suspect that
there may be USB protocol exploits that can be used to manipulate
these values. Thus, an assert is added on the touch points where
the raw pointers go to and from the USB hardware to check that,
at the very least, the entire buffer being referenced is strictly
within the USB hardware's memory space.
2026-02-14 18:31:31 +08:00
bunnie
0a4f8f832b add tests to check sram glitch event triggers in baremetal 2026-02-14 01:31:35 +08:00