Commit graph

10340 commits

Author SHA1 Message Date
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
2293406f3a
Merge pull request #764 from betrusted-io/fix-emu
Fix hosted mode regressions
2025-12-24 13:23:06 +08:00
bunnie
77f55941f0 cleanup import path 2025-12-24 13:17:19 +08:00
bunnie
4914e9acd9 update lockfile 2025-12-24 13:15:02 +08:00
bunnie
444d7b310e re-enable keyboard bouncer inside bao-video hosted mode 2025-12-24 13:14:48 +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
8d8f3f4243 re-enable usb responder in hosted mode 2025-12-24 13:13:50 +08:00
bunnie
0859b01071 add susres skeleton to emulator 2025-12-24 13:13:33 +08:00
bunnie
68179117b5
Merge pull request #763 from betrusted-io/fix-kbd
fix keyboard scan configuration
2025-12-24 00:39:18 +08:00
bunnie
6f0a9c4275 fix keyboard scan configuration
turns out that when the keyboard is activated, *all* the keyboard
lines take over the GPIOs - and this will fight with the the doubled-up
PF7_PA2/PF8_PA1/PF9_PA0 I/Os.

Using the keyboard controller means that *all* of the PF2-PF9 pins
are now driven by the keyboard controller, regardless of the GPIO
setting.

This is because when the core is powered off, the GPIO output mappings
are lost (they are in the core domain, not always on), and the KPC
was implemented without the ability to selectively demux unused
rows/cols.

In particular on baosec this can lead to high power consumption on
the 24MHz clock when driving the camera, because the KPC fights
with the clock.

The mitigation for the current baosec hardware is to configure
the KPC such that the internal pull-up is responsible for the
"high" level, and it's only driven when "low". This reduces the
amount of fighting with the oscillator.

A future rev of hardware will move the osc to the PA3 pin, where
there is a PWM output but no muxing with the KPC, eliminating
the conflict entirely.
2025-12-23 23:36:17 +08:00
bunnie
d13fdb446e
Merge pull request #762 from betrusted-io/size-opt
add missing dependency
2025-12-22 18:08:48 +08:00
bunnie
f98dea3097 add missing dependency 2025-12-22 16:51:22 +08:00
bunnie
b0a70f385f
Merge pull request #761 from betrusted-io/size-opt
Size optimizations
2025-12-22 16:37:14 +08:00
bunnie
fd44f19fb7 "z" doesn't work
leads to an 'illegal instruction' panic in the bootloader. turn
it off for now.
2025-12-22 16:32:14 +08:00
bunnie
544a0368fc setup the security dependency to pull in sigcheck in crates that use it 2025-12-22 16:18:21 +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
c297ca5f2e add free space computation on kernel image generation 2025-12-22 16:16:21 +08:00
bunnie
bfdea56dff add provisional baosec-lite target
what does it take to fit baosec without swap....
2025-12-22 16:15:34 +08:00
bunnie
fb2626b408 try "z" flags for smaller code size 2025-12-22 16:15:22 +08:00
bunnie
6e4543f9c1
Merge pull request #760 from betrusted-io/bugfixes
RTC, backup register bug fixes; more power management modes
2025-12-22 02:25:15 +08:00
bunnie
192a9148dc catch the deep sleep request 2025-12-22 02:11:54 +08:00
bunnie
3427c4965e note RTC todo's 2025-12-22 02:11:29 +08:00
bunnie
0487d5a2a3 add shipmode and deepsleep mode tests
- shipmode is for long-term storage. it disconnects the battery
from the system so that the shelf life can be ~years
- deep sleep effectively shuts down the system but leaves the
real time clock running. Requires a full reboot to recover
from deep sleep.
2025-12-22 02:10:26 +08:00
bunnie
30725c5169 add deep sleep mode 2025-12-22 02:10:09 +08:00
bunnie
00fe25b28c fix RTC setting bug - don't reset if it's already set
the backup RAM region is being used as a way to check if the
system is coming out of a cold power-on. Deep sleep is indistinguishable
from a power-on from the hashing perspective. Check if the RTC is
*enabled* and if not, enable it and reset the time; don't always
reset it if the backup ram is scrambled.
2025-12-22 02:06:22 +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
7ceca0a0cf
Merge pull request #759 from betrusted-io/cleanup-debug
Cleanup debug
2025-12-19 16:51:47 +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
a6870a617f add a confirmation argument to erasing the disk 2025-12-19 16:22:24 +08:00
bunnie
1e4e9694e9 cleanup warning 2025-12-19 16:07:49 +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
88cbdbe076 cleanup a couple of remaining debug prints
boot chain is closing in on feature-complete
2025-12-19 15:56:19 +08:00
bunnie
f287ce457c
Merge pull request #758 from betrusted-io/cleanup-se0
Cleanup se0
2025-12-19 14:48:23 +08:00
bunnie
a6f7178dfc note reserved pins by the bootloader 2025-12-19 14:35:37 +08:00
bunnie
ae32be5e09 cleanup se0 pin setting
there is a circular dependency that has to be broken: the board
type wants to be set via USB, but you can't set the board type
until the USB enumerates. USB enumeration can be unreliable on
baosec because the SE0 pin isn't mapped as the board type defaults
to dabao.

The baosec SE0 pin is PF5 - this is inaccesible in dabao. Thus
the decision was mode to pull both possibilities during the boot1
initialization phase.

This could cause some trouble for OEM configurations that are relying
on these pins to be e.g. inputs or some other value, but this will
need to be documented as a hazard for OEM designers.
2025-12-19 14:27:41 +08:00
bunnie
9334f22788
Merge pull request #757 from betrusted-io/simplify-keysetup
Boot security & stability improvements
2025-12-19 03:40:18 +08:00
bunnie
2a70991d96
remove superfluous prints in boot0
removing prints in boot0 gives less handle for glitchers to time
off of. Also makes debugging chips harder, but I think the boot0
is starting to get stable enough that this is OK?

also removed the frac-PLL setting because it's broken. this causes
the PLL in the boot0 to be subtly different from boot1, and I
think I like it - it makes the timing of glitches between the
two phases different.
2025-12-19 03:30:56 +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
2f2a1bcd23 fix version string retrieval 2025-12-19 03:23:24 +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
5f2c6a0661
Merge pull request #756 from betrusted-io/simplify-keysetup
Zeroing in on dabao instability, CI fixes
2025-12-18 04:04:40 +08:00
bunnie
391927139a make the init check on erase secret pass-forward more narrowly scope
the init check is a bit too broad, we can still accept an honest
devkey answer as devkey mode in the case that the security keys haven't
been set up yet.
2025-12-18 03:57:04 +08:00
bunnie
bb29c53bad move the backup region check below IRQ handler setup
this seems to be necessary for stability on dabao
2025-12-18 03:56:18 +08:00
bunnie
e0402c1602
Merge pull request #755 from betrusted-io/simplify-keysetup
Simplify key setup
2025-12-18 02:30:09 +08:00