Commit graph

1074 commits

Author SHA1 Message Date
bunnie
b02f1563ae don't put pin snapping into ws2812 implementation
the pin snapping makes the application not composable with
other applications that don't use the exact same snapping mode.
2026-01-05 08:56:38 +08:00
bunnie
40e740d869 implementation for the composeable I/O modes 2026-01-05 08:56:20 +08:00
bunnie
d647e41822 fix API to allow for composition of IO configurations
the main issue is that if the IO configuration fully replaces
a previous configuration, two apps can't be loaded at the same
time because the later one replaces the previous one's configuration.
now the I/O settings take an option for a configuration mode,
which is somewhat clumsily expressed as either replacing the
I/O configuration, setting bits only, or clearing bits only.

This maybe could use a cleaner API but not quite sure how to
do it yet.
2026-01-05 08:54:29 +08:00
bunnie
9a94ea48ad add captouch demo
some basic APIs in place to help make touch a little easier
to use.
2026-01-05 08:53:13 +08:00
bunnie
6398415265 update lib refs 2026-01-03 22:55:47 +08:00
bunnie
e2097f171e add demo for doing multiply instructions 2026-01-03 22:55:20 +08:00
bunnie
e0fddfbe04 improve readme slightly 2026-01-03 22:55:04 +08:00
bunnie
c81911e498 move readme to a customary location 2026-01-02 12:54:01 +08:00
bunnie
f1b9212b75 re-organize code so that the APIs are up top 2026-01-02 12:45:40 +08:00
bunnie
f9e17f7a63 add a README for the BIO libraries 2026-01-02 12:42:46 +08:00
bunnie
785daf253c update comments 2026-01-02 12:30:10 +08:00
bunnie
acaa3b6874 cleanup warnings 2026-01-02 12:26:09 +08:00
bunnie
437c5e1d85 start the bio-lib
this is where a collection of BIO applications will eventually live...
2026-01-02 11:25:49 +08:00
bunnie
35cdc0c0f5 resource tracking implementation 2026-01-02 11:25:37 +08:00
bunnie
8d84345444 add resource tracking 2026-01-02 11:25:18 +08:00
bunnie
24b6d4cb42 fix bugs in implementation 2025-12-31 23:34:35 +08:00
bunnie
06501a9032 fix handle API to reflect actual implementation
I had a bit of a brain fart while drafting the original code
2025-12-31 23:32:39 +08:00
bunnie
5be682b37f cleanup apis after std implementation 2025-12-26 21:03:19 +08:00
bunnie
acc9771886 first cut at the low level implementation 2025-12-26 20:18:06 +08:00
bunnie
c239d79ead cleanup the API after running through an implementation 2025-12-26 20:17:34 +08:00
bunnie
8c3c23ea85 add the core hardware API implemenation for bio
should work for both no-std and std environments, but lots and
lots of testing TBD...
2025-12-26 20:16:47 +08:00
bunnie
9eb40aceb0 move comments to the correct file 2025-12-26 01:06:10 +08:00
bunnie
68679f41ba add the 'std' implementation side of the abstract BIO API
this is essentially the getter/setter that translates
BIO api calls into messages that would be sent to the BIO
server implementation. The BIO server implementation would
have the actual BIO hardware calls in it. These calls, if
written correctly, also double as the no-std implemnetation
of the BIO API.
2025-12-26 00:58:49 +08:00
bunnie
60b18303ed define the BIO API in the abstract API
this is a fully abstracted API that should be fully hardware
independent. This is meant to supercede the xous-bio-bdma library.
The xous-bio-bdma library will stick around, but its main purpose
is as an experimental, baremetal library that contains low
level code and test code for developing the hardware. We could
try to merge this into the abstract APIs but I think it doesn't
make sense from a methodology standpoint - hardware development has
a different tempo and flow from the software development process,
and so by keeping these two separate we end up with potentially
diverging APIs - but actually, this is a good thing. It allows
us to develop e.g. v2 of the hardware without having to roll
uncertain/experimental v2 hardware APIs into the abstract APIs
right away.

there is one hairy point in all of this, which is I'm trying to
get fancy and have a hardware "handle" be dropped automatically
when it goes out of scope. This requires me to pass around
a phantom lifetime parameter, something I haven't done before.
If this works, it could be a good template for dealing with other
abstract hardware APIs that will help remove some unsafe code.
2025-12-26 00:55:00 +08:00
bunnie
444d7b310e re-enable keyboard bouncer inside bao-video hosted mode 2025-12-24 13:14:48 +08:00
bunnie
88a6492481 make the signature check/security elements more clearly optional
the problem with it being default in most configurations is that
it pulls in a sha-2 and ed25519 dependency into routines that
never rely on them. now libs that rely on the sigcheck need to
specify the feature explicitly to pull in the depedency.
2025-12-22 16:17:08 +08:00
bunnie
30725c5169 add deep sleep mode 2025-12-22 02:10:09 +08:00
bunnie
a5303a707f define backup flags 2025-12-22 02:05:46 +08:00
bunnie
39eb15003d work around buram erratum; convert reserved field to flags
- backup RAM has an erratum where two locations are corruptable
and should not be used between soft resets to store data

- the reserved 32 bits in the bureg are now accessible as flags.
these flag bits are used between boots to coordinate system state
information.
2025-12-22 02:04:31 +08:00
bunnie
b195447fcb add swap key to the list of keys managed on baosec
not sure why this wasn't added earlier....
2025-12-19 16:42:04 +08:00
bunnie
68841a45b4 add self destruct support
this will wipe a chip to a factory-blank state. It's unrecoverable
on dabao: fully bricks the board.
2025-12-19 16:41:16 +08:00
bunnie
0c18c62d0a move the key consistency check to a library
this allows us to refer to it in boot1 if we eventually decide
it's useful to do it there.

however, as a matter of policy, boot1 checks loader signatures
against *boot1*'s public key block - so if the loader is to be
signed with a different key, boot1 needs to be updated.
2025-12-19 16:06:50 +08:00
bunnie
5195d46d7b add println_d! macro to bao1x-hal
this allows forcing prints to go to the duart

this is useful for debugging early boot issues
2025-12-19 03:30:20 +08:00
bunnie
e5790d76a3
lighten up the mesh debug
actually there's no reason i think to have it print all
four checks - just have it print on two of them, just in
case for some reason the prints could be used to time a glitch.
2025-12-19 03:29:30 +08:00
bunnie
2c80de4933
modulate countermeasure sensitivity & reporting
The "attack" counter notches up when a board goes through a
"slow" powerdown, as would be the case on a system that has
a lot of capacitance relative to the chip. This is a false
signal.

It's hard to tell this apart from a glitch attack, so a
heuristic was applied where at least two glitches have to
be seen before declaring we're under attack.

Note that in paranoid mode, the board instantly resets
when the power gets too low, so the counter doesn't notch
up.

A print statement indicating when a mesh violation was
added - this is to help debug chips that have a weak/marginal
mesh. Because the mesh is so long, small manufacturing defects
in the mesh are also picked up by the mesh sensor...
2025-12-19 03:24:11 +08:00
bunnie
0c690d8be4
add boot1 pubkey integrity checking
this should erase the secret keys if the boot1 pubkeys don't match

this enables OEM-signed boot1 images. the policy is that all OEM
images signed by baochip are considered to be untrusted, and thus
loading them onto a device would wipe any secret keys, making
them less useful for extracting secrets.

There are 2048 keys and about 500 keys are used by baochip,
so there are still plenty of keyslots available for OEMs to
use to implement their own version of security.
2025-12-19 01:14:51 +08:00
bunnie
49e526f60b
simplify erased key reporting on debug
this reduces the amount of prints for a key range being
erased so if the debug flags are on boot isn't delayed
while the debug prints. instead, a total tally of the
erased keys for a key range is printed.
2025-12-19 01:12:57 +08:00
bunnie
36b103ef6c
remove the developer function from the function code list
The developer function was decided to be overly-broad: the
issue is you could slot that in to *any* boot position and
it'd be accepted, and we already have a mechanism to deal
with developer mode (developer-signed images). Thus eliminate
the extra case and simplify the code base to reduce
potential bugs.
2025-12-19 01:09:44 +08:00
bunnie
d6c662b378 memoize some common clock settings
this reduces boot time because the space to search for
an arbitrary clock setting is pretty big.
2025-12-18 02:22:38 +08:00
bunnie
9093bb4ed7 simplify keystore setup
The TL;DR is this now treats dabao exactly the same as
baosec in terms of keystore setup from the security flow perspective.

baosec & dabao were different originally because baosec would
rely upon the Avalanche generator TRNG as supplemental randomness
and dabao would not. This special case had to be handled in the
bootloader and propagated through.

However, in a previous commit, the keystore setup was moved to
the OS *anyways* - thus making this difference moot.

This patch backs out the one-way counters that would track the
dabao initialization state.

It also doesn't fail the boot on the erase key proof check
failing if the keystores aren't initialized yet. This creates
yet another condition that could be glitched over to bypass
the erase check but it is checked twice indepedently.
2025-12-18 02:16:50 +08:00
bunnie
d874c3e5c2 commit for version bump 2025-12-16 02:02:37 +08:00
bunnie
b31c7d411d major rework to clock settings
this is a big, ugly, multi-file commit but it turns out when
you start shaking one part of the clock tree everything rattles
along with it.

Basically this updates the clock tree to use a search for an
optimal setting instead of a hueristic/table lookup, and then
a bunch of small bugs in the clock settings were found that had
to be proopagated to dependent crates.

i2c clock set now seems ... more correct, the frequency is
not overclocking the bus (was at 600khz before, now just below 400khz)

the uart equations finally sees sane

the spi clocks check out

the only inconsistency left is that i can't seem to get a fractional
division on peri clk. it would be really nice to be able to do a
fractional divide and get a little more peformance out of the spi
busses but i think it just doesn't work that way - the "fractional"
division is actually more of a "time-average frequency is correct"
but when you go into fractional mode it's spending some time pulsing
at 2x the rate and some time at 1x the rate to get to the time average
frequency, and when you're at the 2x rate things break.
2025-12-16 01:02:00 +08:00
bunnie
679ece9b19 major rework of the clock-set routines
the routines provided in the reference crossbar libraries are
not great and the recco of their team is to just use hard-coded
table lookups. Replaced this with a computational method that can
find arbitrary clocks; however, the computation *is* somewhat expensive
because you have to iterate through a fairly large solution space
to find an "optimal" solution.

That being said, these solutions can be memoized if they are
frequently re-used. I rather prefer this method than just an undocumented
table lookup.

More testing is needed but the initial results look pretty good.

Also peripheral clock setting is reworked to be more clear as to what
is going on. I think I finally have some clarity on why a mysterious
"divide by 2" was ending up in everything; other dependencies have
been reworked to clean that up. I think actually I may have been
overclocking the peripheral bus by a factor of 2 prior to now :-/
2025-12-16 00:58:37 +08:00
bunnie
021cf609e4 remove wfi apis from hal
this is now in the susres crate
2025-12-16 00:58:10 +08:00
bunnie
8dc1e9c837 rework backup RAM hashing to ignore the erase proof slice
a slice of key material is written to backup RAM from boot0
all the way to the loader, to prove to the loader that secret
keys were erased in a higher privilege state (loader then erases
the key, and this key is considered leakable without harm to
security).

The problem is that writing the key to backup RAM in boot0
was fixing the hash on the backup block, which is before
the check happens to see if it was a cold power-on. This would
defeat the RTC setting & backup setup logic.

THe solution to this is to exclude that one key from the hashing
area and special case it. A set of routines and API names were
added to help enforce this case.
2025-12-15 15:19:01 +08:00
bunnie
3fd9087b7f commit a partially working wfi cycle 2025-12-11 02:28:37 +08:00
bunnie
df3529d595 add power down/up opcodes to the gfx layer 2025-12-11 02:21:40 +08:00
bunnie
261ea7a880 update apis in hal-service 2025-12-11 02:18:44 +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
8269f9f759 update apis to accommodate power savings mode 2025-12-11 02:10:25 +08:00
bunnie
0a47620da2 add powerdown api to sh1107 2025-12-11 02:09:15 +08:00
bunnie
a3a566b240 add API calls for debugging kernel under baochip targets
also updated some really bit-rotted docs

we will deprecate the docs/ directory soon, they are wrong
and misleading at this point.
2025-12-09 16:19:04 +08:00
bunnie
41d09786ae tighten up clock gates in boot0
confirmed that these settings do not affect the glitch sensors.
2025-12-08 16:54:23 +08:00
bunnie
a3f9a9942d update APIs to use the central clocking implementation 2025-12-08 15:58:27 +08:00
bunnie
11b506bdc4 build a consolidated clock setting routine
This routine pares down the clock setting routine to hopefully
a core minimum set of side-effects while allowing the system
to boot.

It also takes the register bank offsets as arguments, as well
as various functions to accomplish different tasks as argument,
so that it can be used in different contexts (such as in `std`).

Finally, the BIO clock rate can be set to slow or fast. The power
cost of the fast setting is about 12mW. If you're not needing
the high speed features of the BIO, slow setting is probably what
you want.

Currently, the system is configured such that after boot1, the
BIO is running in slow mode (to save power for battery powered
configurations); and then the clock set calls in baremetal and
dabao bump this up to the fast speed since these two configurations
are assumed to be running off of a USB wire with ample power.
2025-12-08 15:55:20 +08:00
bunnie
4e0b67878a remove old code 2025-12-07 19:00:29 +08:00
bunnie
ebb7e8dfae refactor QR code notification implementation
Previous implementation sent the QR code as draw commands.
This is inefficient as it would require hundreds of draw
commands to be sent per QR code rendered.

This implementation codes the QR code as a bool and sends
it in a single memory message, and implements a QR code renderer
on the receiver side.

The QR code rendering is also cleaned up so that the QR code is
always centered and takes the full screen, to give the best
conditions for someone scanning the code from another device.
2025-12-07 18:58:33 +08:00
bunnie
53c7a729f7
add primitives for interrupt-based glitch handlers
glitches can trigger interrupts from several sources:

- ECC errors on multiple blocks
- consistency check errors on hardened logic
- light sensor
- voltage sensor
- glue cells

These primitives respond to these glitches in an interrupt
context. At the moment, by default a fairly lax approach is
taken to responding to the glitches: partially, we want to make
sure that the sensors aren't too sensitive and trigger by accident.
The final thresholds can be adjusted fairly readily.

In addition, the mesh can trigger an interrupt, and typically,
that interrupt is a false reading (because the mesh takes a
long time to settle, and we boot the system while the mesh
settles). Thus, we take an approach of polling the mesh
effectively, and when interrupts happen due to the mesh we
just clear it and ignore it and allow the polling routine
to manage the mesh. The mesh is theorized to be a static
attack, anyways.
2025-12-07 01:33:53 +08:00
bunnie
15ac4d8529
add primitives to buram for storing slices
this is used by the key erase proof routine, but will be
useful in general for storing data in the buram

also, the ranges of slices are currently defined at
the top of the file but might be moved somewhere more
maintainable later.

RRAM writing got bollards added to it, as RRAM write could
be a glitch target: if a glitch could manipulate the
address somehow to stick stuff at an arbitrary location,
during write, that would be bad. However, it's probably
also reasonably dangerous to try and glitch RRAM writes
because there's a chance you spray over off-target items
and thus trigger a signature check failure on your next
boot.
2025-12-06 18:36:51 +08:00
bunnie
09e68291cf
during key erasure, add the proof that secret keys were erased 2025-12-06 18:35:43 +08:00
bunnie
eee9cd62c9
enable secure erase confirmation in loader (leaks one chaff key)
A problem was discovered while implementing the secure boot
hardening. Namely, an attacker could trick the loader into
loading a devkey-signed kernel by incrementing the
developer mode counter without actually triggering the
secure erase of the keys, and finding a way to glitch
over the check of the developer mode counter check.

Two countermeasuers are implemented:

1. if the developer mode flag is set, trigger a secure erase
even if the image signatures aren't developer mode

2. leak one of the chaff keys into the loader, so there are
now at least two indpendent checks of being in developer
mode in the loader. One is based on the counter, which
is only weakly correlated with the erased state. The
other is checking for the erase value in the leaked key,
which is a strong indicator of being in developer mode.

The leaked key is, of course, erased before entering the
kernel (and the key is leaked into a region of memory
that is, in theory, securely claimed by the keystore, so
it's not like anyone can just read it; however, it is
in a less secure location than the protected key area).

The impact of an adversary obtaining the key is only
a slight weakening of security because the chaff keys
are numerous, they still have thousands of bits to
guess even if they got a couple hundred of them.

The next series of patches implements the scheme outlined
above, starting with defining the key to be leaked. The
leaked key is intentionally the last key in the slice
of keys used in the erasure algorithm, so that presumably
if the leaked key is showing an erased value, all other
keys have been erased.
2025-12-06 18:24:40 +08:00
bunnie
9ddf6beae6
move the kernel start address
this correctly gives the loader 256k of space, which is what
its link file specifies. The loader was previously under 128k
by chance, but with glitch hardening it's grown past that
boundary.
2025-12-06 18:23:10 +08:00
bunnie
b99b4cb665
cleanup signature checking API
Signature checking parameters are now consolidated into
a single "SecurityConfiguration" record. This allows the
sum total of security state transitions to be summarized in
the bao1x-api/src/pubkeys/mod.rs file, easing maintenance
and audit.

Reaction to the signature check is split into a `hardened_erase_policy`
API call which can take the results of the signature check and
react to it if necessary.

This allows the signature check routine to be used for both
audit (where reaction is not necessary) and for live testing
of the code (where reaction is required). It also simplifies
the implementation of double-checking signatures in the case
of paranoid mode.

Another important improvement is that the signature checking
API outputs the target address for the jump, but masked with
an XOR of the function code of the signed block. The purpose
of the XOR mask isn't to obfuscate the value; rather, it's
to prevent there being a single, simple, fixed-constant
jump instruction laying around that a glitcher can use as
a target: instead, a pair of registers must be loaded
with the target and its mask. This is an example of what
the final jump looks like:

```
60003a8e:	ffffffff          	.word	0xffffffff
60003a92:	0440006f          	j	60003ad6 <bao1x_hal::hardening::die>
60003a96:	ffffffff          	.word	0xffffffff
60003a9a:	167d                	addi	a2,a2,-1
60003a9c:	fe71                	bnez	a2,60003a78 <rust_entry+0x2f74>
60003a9e:	a00d                	j	60003ac0 <rust_entry+0x2fbc>
60003aa0:	0360006f          	j	60003ad6 <bao1x_hal::hardening::die>
60003aa4:	ffffffff          	.word	0xffffffff
60003aa8:	02e0006f          	j	60003ad6 <bao1x_hal::hardening::die>
60003aac:	ffffffff          	.word	0xffffffff
60003ab0:	0260006f          	j	60003ad6 <bao1x_hal::hardening::die>
60003ab4:	ffffffff          	.word	0xffffffff
60003ab8:	01e0006f          	j	60003ad6 <bao1x_hal::hardening::die>
60003abc:	ffffffff          	.word	0xffffffff
60003ac0:	0149c533          	xor	a0,s3,s4
60003ac4:	600805b7          	lui	a1,0x60080
60003ac8:	d0058593          	addi	a1,a1,-768 # 6007fd00 <_etext+0x6e9dc>
60003acc:	82aa                	mv	t0,a0
60003ace:	852e                	mv	a0,a1
60003ad0:	4581                	li	a1,0
60003ad2:	8282                	jr	t0
```

So here you can see the alternating bollards in the region that
will cause any glitches that don't land exactly right to
either halt the machine or cause a reaction.

Line 0x6003ac0 is where the xor happens to compute the target
address. Should a glitcher land on that address, `s3` and `s4`
will need to be loaded with the target address and a value when
XOR'd with it that yields a meaningful result. While there is
a non-zero chance that this can be arranged, it's definitely
not as easy as targeting a jump-to-fixed address exit sequence.
2025-12-05 22:57:34 +08:00
bunnie
d9d146352f
ensure that hardened_get2 is used correctly with an assert 2025-12-05 22:43:49 +08:00
bunnie
32ffba0931
introduce security configurations
The management of different security configurations was getting
a bit out of hand, so all the security configurations used by
the system and their transitions are now consolidated into a single
file, This will make auditing and checking the transitions a lot
easier.
2025-12-05 21:37:21 +08:00
bunnie
1dbb65cc97
zerorize backup registers & fix aoram range in zeroize
backup registers are a high priority target on zeroizing
because it would contain the ephemeral unlock secret, e.g.
PIN code.
2025-12-05 00:59:59 +08:00
bunnie
9e5c57b7de
inline the pll check
this prevents it from being a single area that has to be patched
to bypass the pll check
2025-12-04 15:30:43 +08:00
bunnie
362124127e
add redundant counters, paranoid mode, attack counters
This allocates some additional one way counters dedicated
to hardening:

- Paranoid mode is duplicated in slots 65 & 67
- An attack counter is in slot 66
- Redundant revocation counters are seated in slot 68

The primary revocation counters are in slot 116. This means
that cutting out the revocation counters would probably require
at least two edits to the memory array - simply cutting the
word addressing line for those columns might be enough to
defeat a counter.

Paranoid mode duplicate is stored somewhat close to the
primary counter, which means it could be subject to a single
line cut to fully defeat the counter, but the space is getting
pretty crowded so I'll leave it like that; I really want to
leave the bottom 64 slots available for application use.

A "flag" key is allocated, plus a dummy flag is committed
to the repo. This is a value that, if retrieved, would
ostensibly bring the retriever glory and bounty, to the
extent that any glory or bounty is to be had (ps: I'm poor
and this project is obscure). The actual flag, of course,
is not in the repo...I hope!

The flag value is different from all other values in that
this is the only shared, common secret across all devices.

All other device secrets are generated on a per-device
basis from the TRNGs. So the flag needs some special treatment
such that it's not overwritten during device keying.

The flag exists because I'm hoping that anyone who manages
to extract it will also provide a helpful explanation of
the procedure to get it out, so that the system could be
patched (if the error is patchable) or rev'd in future
silicon. That being said, a flag retrieval is not necessarily
equal to a full break of security across all devices because
as mentioned above, most device secrets are on a per-device
basis. The flag represents then, the amount of effort necessary
to apply to every device to retrieve the secrets within.
2025-12-04 14:56:07 +08:00
bunnie
31385a5599
start moving clock routines into an API library
clock setting calls, for legacy reasons, are duplicated in all the
stages of the bootloaders. This is a start toward moving these routines
into a common set of calls that improves maintainability.
2025-12-04 14:54:26 +08:00
bunnie
bd08328530
add bollard macro and HardenedBool
These macros are added to the platform-agnostic API crate.

bollard is a macro that can respond to the following argument
formats:

bollard!(): inserts 4 illegal instructions and a jump over them
bollard!(#): inserts # of illegal instructions and a jump over them
bollard!(f, #): inserts # of an interleave of illegal instructions
and a jump to f

the last form is intended to "up the ante" by including a call
to a routine that can shut down the chip and/or wipe secrets
should the defender choose to do that. The other ones just
trampoline into an illegal instruction vector which is a fairly
weak defense because the CPU could once again get glitched out
of that.

HardenedBool is a boolean represented by a high-hamming distance
numeric value so that single-bit flips just lead to an invalid
bool, instead of a change in the meaning of the bool.
2025-12-04 14:50:33 +08:00
bunnie
75fb1a1889
Harden the signature check routine
- key revocation check is fully duplicated and tested twice
- bollards & random delays added throughout the code. Random
delays require passing in a csprng object from the calling
environment.
- the primary go/no-go decision on whether a signature passes
or not is unfortunately not hardenable because the API is in
a third party crate. However, the regions around that call are
random-delayed and surrounded with bollards
- the state bits that determine whether the system is secure
and/or in developer mode are implemented using HardenedBool
- erase_secrets has some delays added to it as well as bollards.
However, it does remain a weakness that an attacker
could pull RRAM power during the erase cycle by just isolating
the RRAM power supply and putting a fast current limit on it,
thus preventing effective erasure by starving the circuit
of power.

Nothing we can really do about an active attack on the power
supply to prevent erasure, I think. It is unfortunately required
by design to have an isolated power supply for the RRAM to perform
elevated-voltage forming at CP time, and so, it should always
be possible to limit the current going into it thus preventing,
at least somewhat, any programming operations on the array.
2025-12-04 14:36:28 +08:00
bunnie
05af4f3f62
add hardened_get() and hardened_get2() to one way counters
One way counters are used ot record some security-critical properties,
such as key revocations and paranoid mode.

Two methods of retrieving the counters so that they are hardened
are provide here. Both of them rely on the fact that any value
other than 0 for the counter means it is set.

`hardened_get()` retrieves the counter value and sums it several
times. It does this *twice*, and returns *both* values as a tuple.
By returning both values as a tuple, it reduces the likelihood
that the compiler optimizes out the redundant read. The receiver
should implement serial checks that operate on the hardened_get()
result (i.e., test one value of the tuple, then test the other
value of the tuple redundantly, instead of OR'ing them together
into a single test)

`hardened_get2()` is for counters that are fully duplicated in
the array. For extremely critical counters, they are stored in
two physically separate elements. This is done to make bypass
of the counter harder than just FIB'ing out a single bit in
the memory array. In the case of `hardened_get2()`, a tuple
is returned, but instead of reading the same value twice, the
tuple corresponds to the summed value over each of the redundant
counters.
2025-12-04 14:29:30 +08:00
bunnie
9294c06d45
Add glitch hardening library
This library contains the following primitives:

check_pll() - checks that the PLL is the primary clock source.
This is important because allowing direct clocking of the system
from the external clock pin makes glitching much, much easier.

die() - a routine that implements a reaction to attacks. At the
moment, we just note attacks and then halt the machine. Eventually,
this could be upgraded to be more reactive, e.g. erasing secrets
or bricking the chip.

Csprng - this is a chacha8 cipher seeded with ring oscillator
TRNG data, plus whatever tiny bit of entropy we can scavenge
from uninitialized RAM (to make it so that it's not as trivial
as cutting the RO wire and tying it to 0 to bypass the library).
There's also a tiny health check on the RO before using it, again,
to make it harder than just cutting the RO wire. The sole purpose
of the Csprng is to generate random delays that frustrate glitching
attacks. The delay is currently tuned to a range of 0-255 iterations
of a loop.

paranoid_mode() - turns on fully automatic reactive sensor
countermeasures. Whenever a voltage glitch is detected, the system
will just reboot.

mesh countermeasures - these set up the secure mesh and the
reaction policy to tamper detection on the secure meshes

apply_attack_policy() - an API call that applies the currently
determined countermeasure in case that the detected attacks
counter has gone above a threshold. The reason we don't simply
react right away is that some countermeasures are fairly
sensitive, and *also*, very importantly, the chip *is* packaged
in a CSP and thus especially for dabao users you will expect
to see random trips of the attack sensors due to environmental
noise (photoflashes, nearby lightning strikes, etc.).
2025-12-04 13:34:01 +08:00
bunnie
852a12645b round out stateful list creation in the ux-api libraries 2025-11-30 21:33:04 +08:00
bunnie
106f7153a1 filter key presses through the video layer
the video layer is the "traffic cop" managing when modals
get focus. This patch creates a feed from the video layer
that listers to subscribe to that filters out key presses
destined for modals.
2025-11-28 18:40:56 +08:00
bunnie
738797754b make widgets respond to the "fire" button 2025-11-28 18:40:33 +08:00
bunnie
720680a931 build a hosted mode dummy for aqcuire qr 2025-11-27 22:10:57 +08:00
bunnie
74134bfac2 add ux-api acquisition features 2025-11-27 16:52:44 +08:00
bunnie
bc4e459e28 convert spim txrx timeout from a hard-error into an error message
occassionally when the bus is loaded, some SPIM transactions won't
complete. this needs to be looked into a little more, i think...
2025-11-27 12:34:40 +08:00
bunnie
7e368d231f add mod refs for kpc_aoint 2025-11-26 20:47:28 +08:00
bunnie
59e8707b1a add hardware abstractions/translation maps for baosec keyboard 2025-11-26 20:47:10 +08:00
bunnie
b021a1bcd3 fix typo 2025-11-26 20:46:54 +08:00
bunnie
40c94b5abc add kpc_aoint abstraction layers 2025-11-26 20:45:12 +08:00
bunnie
1ca144f47f remove stale constants; add an irq handler storage class
constants made obsolete in the latest utra update are removed,
and a storage class for multi-purpose interrupt handlers is added.
2025-11-25 19:08:53 +08:00
bunnie
1ebf9b8d94 use the newly extracted utra; fix ranges
in xous, you can't make a range smaller than 4096 bytes,
so range lengths have to be enforced at an abstraction layer
above the page allocator
2025-11-25 19:08:07 +08:00
bunnie
765a36bd3a add option to defer draw updates
this is helpful for composited UIs
2025-11-25 19:07:32 +08:00
bunnie
d30d889774 add rtc hardware drivers and service 2025-11-24 18:28:00 +08:00
bunnie
960ba350cb add bu_mem locations
these failed to extract automatically from the RTL
2025-11-23 08:48:24 +08:00
bunnie
95c8046111 add backup region abstractions
these persist through a sleep cycle
2025-11-23 08:47:43 +08:00
bunnie
145c2e37b2 raise visibility of the erase value 2025-11-18 23:19:28 +08:00
bunnie
4477af6058 fix broken font rendering in rust 1.91
Rust 1.91 (or perhaps, more accurately llvm?) changed how link
ordering works.

Previously, modules would be linked in the order they were referenced
(e.g. pub mod b; pub mod a; would result in b being at a lower address
than a in the resulting binary).

However, apparently, this has changed and now someone in their
infinite wisdom decided that modules should be alphabetized before
linking.

I'm really not sure why the arbitrary ordering of the human alphabet
is superior to any other system, and also, if you really wanted
things alphabetized, you could just alphabetize them in your
reference order.

Previously the fonts were laid out in a way that tried to minimize
cache thrashing by co-locating certain sets of fonts together.

Now they are just sprayed around through the arbitrary and not
terribly useful permutation funtion of the english alphabet.

Rant off.

This changes the specification of the fonts in the code generator
to be in alphabetical order, making the screen once again legible.
2025-11-18 00:18:55 +08:00
bunnie
ff5cfa7b12 remove panic/resets on errors during secret erase
at the moment this runs a risk of boot-loops depending on the
configuration of the device.
2025-11-14 19:14:35 +08:00
bunnie
ed1f19984f
loosen restriction on zero keys seen during wiping
this is to handle an edge case where an improperly set ACL
on the alpha0 boards would cause a set of keys to be inaccessible
to the boot routine
2025-11-14 16:16:46 +08:00
bunnie
c79a891553 add api to determine current speed 2025-11-14 16:16:30 +08:00
bunnie
1e085a6548 don't make unknown flash a hard panic
this allows an accidental baosec recognition on a dabao board
to not brick the board
2025-11-13 22:19:13 +08:00
bunnie
faecc1cf27 pin RRAM data onto heap
this prevents optimization that move it around and can cause
troubles for `std` mode operations
2025-11-13 18:29:06 +08:00
bunnie
a7477ec53b
Remove key slot implementation; migrate keys to data slots
The -A1 stepping is going to tie the IFR access control
bits for data and key slots together. This is due to an RTL
bug where the key slot maps were typo'd and they ended
up mapping to the same IFR ACL.

We "could" continue to use key slots with a rule that
key and data slots would have to coordinate with each
other and not use the same slot number.

However, because of this linkage, and because there are
other bugs suspected in the keyslot implementation, an
executive decision was made to disregard the key slot
feature in the chip.

The main downsides of this are:

- fewer slots (2048 vs 4096)
- no key access linkage to HMAC auth on SCE

I *think* that's it.

Fewer slots - 2048 slots is still a lot of slots, about half are
used now, I think this is plenty.

Key access linkage to HMAC auth on SCE - I have reasons to
suspect this feature is broken anyways for subtle reasons
related to malleability of the HMAC round constants. Even
without that brokenness, it's hard to use HMAC auth to manage
the system because it requires per-device unique keys: so,
we're using a PKI scheme and no symmetric secrets to handle
access controls.

Removing the key slots also greatly simplifies the code
base analytically. This culling removes the key slot
abstraction the "simple" way, but without the weirdness
of the keyslots (in particular the key ID chaining which
makes them different from data slots) I could remove even
more abstractions and simplify the code.

One upside is now all elements can enjoy the write mode
behavior which can force the slot to be only 0->1 writeable,
which could be useful for other things down the road.

This was tested to not interfere with Dabao-Alpha 0
bootloaders.
2025-11-13 18:21:52 +08:00
bunnie
f88c801e01
update key ACL to r/w
this allows the OS to initialize the keys

note that including write access only gives it to the fw0 user,
which is the OS's secure user. thus any write primitive created
by this expansion of access should transitively also be a read
primitive (which is actually what the adversary desires).

In exchange the OS is allowed to initialize the keys, which
I think is the right place to do it given that it's too hard
at this point to nail down the exact key layout, etc.

Note that it is impossible for the OS to change ACLs - that is
a feature that can only be updated by the boot user - which
is why the boot user can change the ACL to gain access to
erase keys, but the OS user can't modify its own ACL.
2025-11-13 11:06:16 +08:00
bunnie
10bd1502d0 fix ACL to match actual usage of data slots 2025-11-12 22:08:12 +08:00
bunnie
94964f12a2 reduce debug noise 2025-11-12 17:46:38 +08:00
bunnie
0d1105fb25 fix index selection in menus 2025-11-12 16:26:35 +08:00
bunnie
564374dfd3 cleanup menu implementation warnings and shallow bugs 2025-11-12 15:28:11 +08:00
bunnie
93547fa2cd add ephemeral api 2025-11-12 15:27:55 +08:00
bunnie
c168c7d720 update ui to use builder pattern 2025-11-12 15:26:17 +08:00
bunnie
785293a440 add menu widget implementation 2025-11-12 13:15:07 +08:00
bunnie
54f476edd3 fixup hosted mode emulation for baosec 2025-11-08 04:20:30 +08:00
bunnie
99769d4622 cleanup the keystore api 2025-11-08 03:52:03 +08:00
bunnie
50962a6ba6 cleanup warning in latest rust
pointers to font tables are conjured out of thin air and
the standards have changed on how to do this.
2025-11-07 00:36:57 +08:00
bunnie
d91c2e7671 fix API to reflect that the 0-state is the most permissive state 2025-11-06 14:10:00 +08:00
bunnie
12d0728582 shorten the generic identifier
make it long enough that it's unlikely to have two identical
ones randomly connected to the same machine

but short enough that it's likely/conceivable to have a collision
2025-11-06 14:08:48 +08:00
bunnie
2d7ee0c614 ensure security bits are set according to -A1 stepping
in some modes these don't get side-effected elsewhere so make
sure they are set correctly upon entering the next stage
2025-11-06 14:08:05 +08:00
bunnie
aaf1cbd2f9 add base routines for deriving & controlling serial numbers 2025-11-04 13:13:52 +08:00
bunnie
0b92da5bab add better locking on core USB object
there is a lock that happens in serial console interactions with
local echo where the instant feedback of a character entered causes
the USB object to be locked when the interrupt handler enters to
receive a character that was just sent.

The fix to this is to add the ability to disable interrupts before
entering a critical section (such as enqueuing data for a write)
and then re-enabling after tha section is done.
2025-11-03 08:00:31 +08:00
bunnie
9d3da626f2 handle case where driver is called too early, before everything is setup 2025-11-02 10:37:04 +08:00
bunnie
d901c61846 modify boot sequence to generate keys for a dabao environment
also update the audit to check the respective flags
2025-11-01 23:56:47 +08:00
bunnie
26078dcc7d add keystore to dabao configuration
After some contemplation, we should include the keystore in the
core service set featured by the dabao-xous configuration.

The pros are: any compatibility/sharing of resources
that require access to RRAM, one-way counters, UUIDs, etc.
will either require a wholly separate implementation that is
"insecure" or it could just reuse the baosec work. Furthermore,
as cryptographic accelerators are laid into the keystore,
the APIs become available to the dabao environment

The cons are: more space is used in a space-constrained
dabao environment (roughly 140k "deadweight" at the start, but
as cryptographic APIs get layered in this can grow substantially);
the key slots are "used up" in part by the scheme, which leaves
less key slots available for user-defined purposes.

This is mitigated by the fact that there are a couple thousand
key slots, and so even though we use a couple hundred of them
it's still not the whole range.

Also, the baosec/dabao feature flag can be used to feature-out
cryptographic APIs/accelerators that are too obscure or not
useful for the dabao environment, to "lighten up" the
firmware load.
2025-11-01 22:59:07 +08:00
bunnie
ea43e9248a cleanup dangling debug code 2025-10-31 09:01:02 +08:00
bunnie
0c522ce914
refactor identify_flash_reset_qpi() to be all-in-one command
identify_flash_reset_qpi's behavior has been revised to
include setting all relevant parameters so that the device
that is identified behaves identically to the model device
(e.g. Macronix), to the extent that it is possible. This
includes setting the QE bit.

The routine to check QE has been renamed to `flash_ensure_eq()`
to reflect that it is safe to call multiple times: it checks
if the bit is already set, and if so, doesn't do anything.
Thus it can be routinely called without worry of wearing
out the device.
2025-10-30 14:56:04 +08:00
bunnie
94e1f6044a add spim flash autodetect routine and partial support for xtx devices
xtx devices still not fully working, but at least able to switch
in and out of spim modes in the face of uncertainty over which
device type is present.
2025-10-30 04:13:37 +08:00
bunnie
a14c093da8 enable pullup on SE0 for dabao 2025-10-29 03:42:49 +08:00
bunnie
c827a0ed12
add swap key slot 2025-10-28 18:50:09 +08:00
bunnie
82a47602c2 improve std interface for bio
- imem accessors are static-mapped slices
- AtomicCsr is used so that the bio structure is Sync allowing
it to be shared across threads
2025-10-28 18:01:17 +08:00
bunnie
52198821b0 cleanup typos 2025-10-28 18:00:38 +08:00
bunnie
c159ddd214
cleanup std interface for acram ranges
need to register memory windows to the rram object so that
writes can succeed in a virtual memory environment
2025-10-28 17:58:51 +08:00
bunnie
d10274b9ec
fixup pio->bio typos
also fixup a return-type bug in the std implementation for
bio pin settings

much more bio abstractions will be needed, but for now,
this branch is just focused on the keystore.
2025-10-28 17:57:33 +08:00
bunnie
6e41294854
only clear ACLs that need clearing
also clean up some comments/docs and increase visibility
of the security constant for RRAM so that it can be applied
early in boot
2025-10-28 03:36:12 +08:00
bunnie
290a662bc3
add pubkey block to the data sets, fix nuisance key range
just learned of another ECO incoming that will tie the key
and data areas together in terms of access control from
the IFR region, so the nuisance key range has to have
its access control redefined to steer clear of the data
slots allocated that have write-protects on them.

pubkey block is added to the data ranges

also a oneway counter to keep track of pubkey validation
failures in boot0 is added
2025-10-28 03:33:15 +08:00
bunnie
e6bef77b5f
change boot1 default behavior
The motivation for this is to make the tester configuration
exactly identical to that used in production. Right now a
"cheater" step is used to set the board type to dabao and
enable boot waiting because in the test environment there
isn't a physical switch anyone can press to invoke that
behavior.

So, in order to get the test environment to work just like
production, the behavior goes from insta-die if no valid
image is found on the next stage, to "wait for new image".
This is slightly less secure of a default, but only slightly
so. Basically the previous scheme required someone to be
physically present to press the "give me a new image" button,
this one causes the system to automatically accept a new image.
I suppose the main downside is this does allow the possibility
of say, a fully remote, automated exploit to be delivered
if an adversary can damage the loader image such that it
doesn't pass signature check and then it will automatically
go into a mode looking for a new image, at which point
an arbitrary image could be potentially loaded (although
because the image would need to be signed, and there is
a trap that destroys secrets if a developer image is
presented, it wouldn't instantly lead to secret disclosure,
but it would be a denial of service).

The flip side is that with the paranoid default, developers
are "confused" by the silent failure of a brand new chip that
has no code loaded in it (because it goes catatonic until
the developer knows to press the load button).

The loader image is protected from writes after boot, so
in theory there isn't a direct path to "spoil" the loader
image and trigger this path, so it's not like we're just
hanging in the wind. It just means that there isn't a
full human-presence requirement as a defense in depth against
a potential denial of service if an adversary could find
a way to spoil the loader image.

If the DoS path is a concern, one option is to configure
the system such that the developer key is revoked. This
would disallow that from being recognized as a valid
image, and would also prevent the DoS from happening,
as it would require the adversary to present a valid,
signed image which presumably they can't as long as
the signing keys are kept safe.
2025-10-27 18:22:00 +08:00
bunnie
70a0b62014
rram handler for std environment
rram handler for `std` requires the following additional features
over baremetal:

- mapped pages list, because a process has to "own" a page of RRAM
before writing to it. It's anticipated that the rram writer hardware is
"owned" by the keystore, so all write-access will be mediated by a
service in that PID

- irq-context handling of writes. this prevents writes from being
detached from their staging data, or other concurrent writes
from conflicting.
2025-10-26 22:18:23 +08:00
bunnie
fc3da61307 add duart debug support for std environment 2025-10-26 22:17:37 +08:00
bunnie
775726af23 standardize BAUD_RATE location
also slow down pre-emption timer a bit, on a slower system
like ours 100Hz is less overhead
2025-10-26 19:30:49 +08:00
bunnie
4e522873f0 add preemptionstate opcode to the hal api 2025-10-26 13:38:28 +08:00
bunnie
1c435909a2
fix the sense of the access permission bits
I had read the docs as saying 1 is denied access, but in fact,
1 is allowed access, at least empirically.
2025-10-26 01:55:27 +08:00
bunnie
bce08a1d27 clarify comments on coreuser protection 2025-10-26 01:46:57 +08:00
bunnie
0a1813b28c fix off by one in assert statement 2025-10-25 21:37:19 +08:00
bunnie
d11d2f8cd5 modify default voltages; normalize the setting location 2025-10-25 01:37:21 +08:00
bunnie
c92af3c25a fix up pin mappings for v2 board release 2025-10-25 01:30:58 +08:00
bunnie
d44f489a83 map out PID 0's access in going to secure mode 2025-10-24 21:16:00 +08:00
bunnie
04d46b9549 update location of system timer interval definition 2025-10-24 21:12:00 +08:00
bunnie
caf6fc3a61
Implement erase_secrets() on entry into developer mode 2025-10-21 23:46:06 +08:00
bunnie
391af0313f
fix typo 2025-10-21 19:15:22 +08:00
bunnie
917154ae74
fixup coreuser settings
the more i test things the less confidence i have.

this fixes up a missing table entry in the table definition,
and then also adds a bypass routine - this is not actually
a hidden vulnerability, it's an explicit vulnerability until
the protect() routine is called. But it looks like we may have
to exploit it in order to transform our userstate in
the bootloader to one that has write-access to keys in order
to erase them in case of a developer boot.
2025-10-21 19:12:30 +08:00
bunnie
be038e56aa
cleanup comments
figured out why the data region acl wouldn't write - had
to be in boot0 declared mode
2025-10-21 19:11:52 +08:00
bunnie
e3140609e4
designate the eraseable keys
only some keys are marked as writeable to harden against
potential oracle attacks, i.e., if we made all keys
erasable and an oracle attack was found, then the entire
key region can be exposed by the oracle attack.

Instead, some key material always persists, but a sufficiently
large amount of seed material is erased such that the key is not
recoverable by guessing the key.
2025-10-21 19:08:35 +08:00
bunnie
3e4b0b6571
Add bao2 signing keys 2025-10-21 02:39:11 +08:00
bunnie
2559ddd02d
stash state on some issues in ACL setup
the key setup seems to work correctly
but the data ACL setting doesn't "stick". The region
could be write-protected by some other element in the
CP/IFR config, need to dig a lot more. For now we need
to move on and crank out something to stick on the alpha
dabao boards...
2025-10-21 02:19:40 +08:00
bunnie
2095acfe13
slot manager debug.
add read/write specs as well to the slot definitions.

Not terribly happy with how this all worked out. The subtle
differences between Data and Keys is really irritating.
it's the sort of thing you would say "let's make a trait"
for it but then the two behave just differently enough
that I worry I can't make a trait generic enough to encompass
all the weird stuff that exists in the hardware.

The existing implementation definitely looks like trait
territory, but it currently hides the subtleties around
key/data chaining and secure crypto engine handling of
the two regions as distinct entities. so long as we don't
plan to use those things, traits are a good idea, but
i don't feel like I can reject using the crypto engine
features out of hand this early on just to make the
APIs nice and square.
2025-10-20 23:32:29 +08:00
bunnie
5c60de32ce
debug the slot manager and rram APIs 2025-10-20 23:31:01 +08:00
bunnie
0943b67972
implementation of the ACL APIs and coreuser functionality
'coreuser' is a slightly confusing term from the hardware
system because it's overloaded to mean some conceptually
related items that aren't implementation-wise essentially linked.

coreuser defines both some access protections on the main
array of the RRAM, and also some access protections on key
and data slots.

this patch includes some code that sets up the coreuser
functionality to a very simple scheme where just one PID
is trusted and the rest are not trusted. More complicated
schemes could be introduced with varying levels of trust
and dependencies but I like the analytical simplicity of
two states, so let's start there and complicate only when
absolutely necessary.
2025-10-20 02:15:20 +08:00
bunnie
a64337679f
Add API for defining key/data slots, and initial ranges for the same
Data and key slots are hardware access-controlled areas that
can store sensitive data. Slot definitions come with a "spec"
field that defines what the access controls *should* be,
so that we can check them later.

In practice no user code should be manipulating these, but
there is an initial stage where a totally blank device needs
to be provisioned, hence the focus on correct specification
and checking of state, rather than convenient runtime manipulation
and update of the same.
2025-10-20 02:07:19 +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
fe4ef1bc39
refactor rram API
- add range checking to control access to main array or secure
array. This is purely a software enforced check, but it is in
theory backed by hardware gating that is a back stop in case
an adversary can gain arbitrary code access
- rework the rram primitive to return an error type
- add a `std` implementation stub. It is still missing an IRQ
context handler which ensures that all RRAM writes are atomic,
e.g. you can't take an interrupt in the middle of an RRAM
write because it would screw up the buffer staging.
2025-10-19 01:09:58 +08:00
bunnie
951f088625
add coreuser templates
coreuser is the signal that sets the security level of the system
2025-10-19 01:09:15 +08:00
bunnie
39ceef55f3
Add protected-rram module
this lays the foundation for access control, data slots,
key slots, etc.
2025-10-19 01:07:44 +08:00
bunnie
b59bff2223 cleanup/redefine keyslot regions 2025-10-19 01:06:54 +08:00
bunnie
a40bb7c244 other half of the adjustment 2025-10-18 01:16:16 +08:00
bunnie
3b4e035a4f
revise auth_data handling for key header block
auth_data actually changes with each signing operation (ostensibly
to prevent replay of signatures coming from tokens) so it has
to be presented as data parallel to the signature, instead of
as a static filed baked into the key header.

This commit revises the header record to reflect this organizatio
of data and also revises the signature check to be in-line
with the protocol.
2025-10-06 23:31:02 +08:00
bunnie
7d6630b7ec fix one way counter offset calculations 2025-10-06 23:24:42 +08:00
bunnie
03ea3c9d0c changes to the apis to accommodate the public key record format 2025-10-06 15:20:34 +08:00
bunnie
a1a5ff1592 add public key templates
Beta/developer keys are fully filled out.

Placeholders for production signing keys are also provided.
2025-10-06 15:19:19 +08:00
bunnie
3c68eea714
Merge branch 'main' into signing 2025-10-06 13:45:29 +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
69d81042b9 upgrade signature check to handle domain separation data
this is needed to handle the fido2/webauthn style signatures
2025-10-06 03:49:11 +08:00
bunnie
95f192ca38 add dabao target 2025-10-05 17:15:05 +08:00
bunnie
01a78e4474 fixup app region start and add freq/voltage configs for board targets
this is the agnostic version of all of the board targets, which
allows the boot1 to lookup based on the current configuration
which configurations to apply.

I think I've talked myself into giving away $0.20 of parts with
every dabao board so that everyone can run at full frequency.
Originally I thought I'd limit to the minimal configuration with
low frequency operation but since this is the main developer
platform all the benchmarks and first impressions will come
through this board. Crippling it with a slower clock frequency
by omitting the supplementary digital regulator seems
short-sighted, even if it means up slightly subsidizing things
with this extra cost.
2025-10-05 17:12:40 +08:00
bunnie
c6fb0565ff add frequency/voltage exports from api into the hal
also cleanup some small debug messages
2025-10-05 17:12:04 +08:00
bunnie
2f5af89547 make the swap header length explicitly controlled
previously it was just "4096" in the image writer
2025-10-04 18:52:30 +08:00
bunnie
c86844a39a make signatureinflash structure data
this cleans up one unsafe step where we have to assume an
alignment of the data at the cost of the structure being copied
to stack. I think this is a fine trade-off.
2025-10-04 18:51:34 +08:00
bunnie
b91d54c5cf add SPIM optional target for signature checking
this allows us to check the signature on stuff in off-chip swap
memory through the SPI interface.
2025-10-04 18:50:49 +08:00
bunnie
7f9b783027 mirror board constants from API; make SPIM channel a const
this implements the API/HAL split on the HAL side, and also
reveals SPIM channel as a constant that can be just read out
so that spim accessors that need to build from raw parts
can do it without having to re-allocate IOs.
2025-10-04 00:53:22 +08:00
bunnie
869da85ef7 add swap descriptors as structures; add offsets for boards
In the API layer, the boards aren't setup with convenience flags.
they are all laid out and the caller needs to know which board
it's trying to resolve. This is because the API layer is agnostic
to board and assumes the tool working with it knows what board
it's working with already.

The HAL layer tries to hide the board-specific stuff, and so
API defines are re-imported there in a board-transparent fashion.

Also add swap descriptors to the API crate, so that the image
generation tools can refer to the exact same structures as
are used inside the code, simplifying image creation maintenance.
2025-10-04 00:51:25 +08:00
bunnie
07e7197517 upgrade the sigcheck boot routine to pass kernel arguments
all other boot modes would get an a0 with the address that the
kernel is "supposed" to be located. this is neither security
sensitive or problematic.
2025-10-01 23:36:14 +08:00
bunnie
ec9aed29dd fix kernel offset so signature doesn't shift the image
the image needs to be page-aligned so it can do direct-map
to memory.
2025-10-01 23:35:24 +08:00
bunnie
e77d412bad extract the peripheral reset line 2025-10-01 14:29:04 +08:00
bunnie
346d7cd4d4 indicate the space for the marquee line on the boot logo 2025-10-01 14:28:45 +08:00
bunnie
03744c2dca ops are no-std stafe 2025-10-01 14:28:13 +08:00
bunnie
2eaaa99f6e fix kernel config conflict
no signature checking is necessary in the kernel so don't
introduce the dependencies
2025-10-01 02:57:55 +08:00
bunnie
cdb60eed0f update the static table definition 2025-09-30 21:52:45 +08:00
bunnie
dec6c1944b add overflow handler to big reads (to fake big disks) 2025-09-30 17:28:42 +08:00
bunnie
cade3980cc fix double-offset error in oneway counter readback 2025-09-30 00:37:57 +08:00
bunnie
15562abf00 add functional code slice
this puts a domain separator in every signature block
a domain separator meaning, even though the same private key
maybe be used to sign multiple blocks, because a functional code
is embedded in the block that is tied to the block's function, you
can't take a pre-signed block and shove it into another block's slot
and expect it to work.
2025-09-29 22:17:56 +08:00
bunnie
e7135d9e80 narrow down functional codes allowed for signature validation 2025-09-29 22:17:09 +08:00
bunnie
f8e124f6f9 limit writeable area to the active data area
the top of memory is reserved for various security structures

the security structures do have some hardware protection

but life is better when we also help programmers avoid triggering
the protections by accident and then just being confused.
2025-09-29 18:41:29 +08:00
bunnie
0d8cf34b18 add docs to sigcheck routine and fetch public keys from the specified source
this fixes the issue where we're asking an untrusted image to
tell us what keys to check it with :P ~~~
2025-09-29 16:22:16 +08:00
bunnie
ba817cc1a9 add uf2 identifier for baochip-1x
just pulled it out of a uuid generator, checked it has no
collisions. At some point, maybe some official repo will allow
us to be "real" but ain't nobody got time for those politics
today.
2025-09-29 16:20:43 +08:00
bunnie
150e46d9c0 restructure the HAL's security primitives
- combohash constants are moved to API: these need to be in a
dependency-free library so that we can refer to these values in
any context without creating circular dependencies

- sigcheck code is now put into the HAL layer, instead of in the
individual bootloaders. This is because the sigcheck code is re-usable
between boot0/boot1.

- sram timing trimming data has been entered from the XLS file
and put into an array for easy access

- more board initialization functions have been adedd, and cleaned
up to adhere to the rule that pin allocations don't change the state
of the pins, allowing pin allocation calls to be idemptoent (e.g.
you can call it several times without negative effects - the reason
being that the pin setups also return the pin maps, which can then
be passed to the functions of interest to manipulate the pin states)
2025-09-29 13:42:23 +08:00
bunnie
c6445c9a9b add an API for accessing one-way counter values
A macro is added, a bit like this one:

```
encode_oneway! {
    #[offset = 80]
    pub enum BootWaitCoding {
        Disable,
        Enable,
    }
}
```

Which encodes possible one-way counter states along with their
offset in the one-way counter array.

The states in the enum correspond to the evolution of the counter,
modulo the number of elements in the enume.

The macro also creates a getter for the states, and an incrementer
to try and make this whole process less error-prone.
2025-09-29 13:40:14 +08:00
bunnie
f8967ebaec fix offsets in one way counter implementation 2025-09-26 22:57:27 +08:00
bunnie
094207fe40 add signatures API
this allows us to generate signatures using the same API
that we use to check 'em.
2025-09-26 22:56:19 +08:00
bunnie
9434bb5383 style_macro is how fonts are added to bao1x
By adding a resolver to a given glyph set, the glyph set is
automatically pulled into the image.

Glyph set is now co-located in the bao-video process, instead
of the loader.

The orignial argument for putting the font data in the loader
is that it's a large, static blob; by putting it in the loader,
updates can be more compact, and fonts don't need to be schlepped
over every time you have an application update.

This came with consequences. It made verifying the loader more
complicated (because its memory space is split between the graphics
manager and root keys). It also means we have to fix the partition
size for the loader at "fairly large" for fonts, even if we don't
need all of them in all of the configs.

With baochip, we have swap memory! Off-chip memory is cheap and
only the fonts actually used by the host get mapped into main memory.
This means we don't have as much of a trade-off in terms of
cost for fonts if we put them in off-chip swap storage. Also,
the updates are split between swap and main memory, and the roadmap
includes an item for swap to be individually loadable programs
so that if the video server doesn't need an update, it won't be
pulled into the update set.
2025-09-25 16:08:36 +08:00
bunnie
7724e38ca1 cleand up fontmap 2025-09-25 16:08:27 +08:00
bunnie
2d5039568c genearted artifacts corresponding to template update 2025-09-25 16:08:06 +08:00
bunnie
f30ab0d98e remove fonts from loader for bao1x: update codegen template 2025-09-25 16:07:31 +08:00
bunnie
26fefa7e5b add modules and bitflags to bitbybit migration todo 2025-09-24 01:03:43 +08:00
bunnie
cd182e9efc remove Drop on no-std
this saves a whole bunch of glue code that never gets called
in no-std
2025-09-24 01:03:09 +08:00
bunnie
d02df71bf1 beginnings of ACRAM support 2025-09-24 01:02:53 +08:00
bunnie
497bb74624 add combohash support 2025-09-24 01:02:39 +08:00
bunnie
a3a7bf9f3a add a format for passing static initialized data to baremetal
a small, 256-byte record is added to the top of baremetal records
that is a "poke table" that incorporates what values to put where
for baremetal targets, as well as a zeroization region.

This is generally more efficient because most values are set to
zero, and the only things that generally have a non-zero value
are 'static' variables, which are used extremely sparingly.
2025-09-21 21:50:48 +08:00
bunnie
5151553028 fix dabao target for lib1x-hal
this is the "effective" traget for simulation: no external
peripherals expected.
2025-09-20 22:16:16 +08:00
bunnie
179e178e96 fix up formatting that changed due to the flag day 2025-09-18 21:31:54 +08:00