Commit graph

9282 commits

Author SHA1 Message Date
bunnie
dd14964ca6
Merge pull request #709 from rowr111/remove-version-checking
remove version checking from the extension tools
2025-10-30 15:06:11 +08:00
bunnie
0ddec3f7ba
Merge pull request #710 from betrusted-io/spim-xtx
Spim xtx
2025-10-30 15:05:46 +08:00
bunnie
e82b5e5a7f
cleanup after previous commit
now that the ensure QE command is part of the discovery API,
there's no longer a need to call it
2025-10-30 14:56:57 +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
da623430c6 add debug routines for spim 2025-10-30 04:16:59 +08:00
bunnie
5a8c7c7aa3 cleanup apis and reset spi memory mode at top of boot1 2025-10-30 04:15:12 +08:00
bunnie
60f1b90acb fixup apis 2025-10-30 04:14:48 +08:00
bunnie
3f46e8443c improve spi device detection code 2025-10-30 04:14:28 +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
Jeanie
e268172575 remove version checking 2025-10-29 23:41:08 +09: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
0e50a2591f ensure that boot wait is asserted exactly once in the device lifecycle 2025-10-29 03:43:17 +08:00
bunnie
a14c093da8 enable pullup on SE0 for dabao 2025-10-29 03:42:49 +08:00
bunnie
52b229a39c
Merge pull request #708 from betrusted-io/minor-fixes
Minor fixes
2025-10-29 00:56:33 +08:00
bunnie
cebc87d29a Revert "make acl correct by default for the data region"
This reverts commit 643946a82a.
2025-10-29 00:51:09 +08:00
bunnie
d9cc765419 add a feature to force board type
this is useful in the limited case that the board type is incorrect
in alt-boot mode. saves a step having to type in a command to fix
it.
2025-10-29 00:50:24 +08:00
bunnie
395791b70b make volume label different for alt-boot mode
this helps differentiate the modes to end users
2025-10-28 23:54:20 +08:00
bunnie
4235cba854
Merge pull request #705 from rowr111/tools-bao
tools for the baochip vscode extension
2025-10-28 23:15:27 +08:00
bunnie
997a10470b
Merge pull request #707 from betrusted-io/keystore
Keystore
2025-10-28 23:14:44 +08:00
Jeanie
694eba17fa Merge remote-tracking branch 'upstream/main' into tools-bao 2025-10-29 00:13:17 +09:00
bunnie
03f1c705ee
Merge pull request #706 from betrusted-io/keystore
Keystore
2025-10-28 23:11:39 +08:00
bunnie
3220e48015
add some more debug output on acl adjustment 2025-10-28 21:53:57 +08:00
bunnie
643946a82a
make acl correct by default for the data region 2025-10-28 21:53:33 +08:00
bunnie
bb801a16ed update docs 2025-10-28 21:40:37 +08:00
bunnie
90c46c65c3
add altboot support to bao1x targets
specify cargo xtask baot1x-alt-boot1 and dragging this UF2
file onto the disk boots into an alternat boot1 loader that
allows updating of boot1.
2025-10-28 21:38:44 +08:00
bunnie
09309eb3ae
better altboot support
for updating boot1 on dabao
2025-10-28 21:37:55 +08:00
bunnie
28f7a8d6b2 remove default feature used for testing 2025-10-28 18:54:37 +08:00
bunnie
4e0b5100b8
loader: detect dev key
loader was previously just accepting a dev key image and not
doing any countermeasures. now, kernel, detached-app, or swap
not being properly signed activates countermeasuers.

also select the swap key fallback for checking swap. this is
"half" of the solution, the other half will have to be implemented
in userspace - if we do it at all. i'm starting to think that
the swap encryption is not necessary, it was introduced
under the assumption that signature checking swap would be
too slow, but it's not. so maybe this feature will get dropped.
2025-10-28 18:50:40 +08:00
bunnie
c827a0ed12
add swap key slot 2025-10-28 18:50:09 +08:00
bunnie
d37f74f51d
lockfile update for the commit set 2025-10-28 18:03:14 +08:00
bunnie
b557cd5ebc
add some trng tests to the console 2025-10-28 18:02:33 +08:00
bunnie
79eab7da5e add feedback on boardtype resetting 2025-10-28 18:02:11 +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
3e22f5f9cf add board type specifier for dabao-console 2025-10-28 18:00:56 +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
5f137aac96
add TRNG service for baosec target
dabao has no external TRNG, and so it can "cheat" and use the
server ID api call from the kernel to get random numbers (the
server ID is just TRNG output from the kernel's TRNG).

baosec has an external TRNG, and it needs a userspace
server to blend both kernel TRNG output and this external TRNG.
the TRNG requires the BIO block to aggregate the random data.
This commit adds that implementation.
2025-10-28 17:55:06 +08:00
bunnie
cb6bc4d2c6
add keystore master key derivation
the master key is currently derived from a number of factors:

- the key seed
- chaff keys
- nuisance keys

and then a salt of the uuid/cpid and some info based on the
developer bit is added.

The info addition ensures that the key rotates if developer
mode is entered, so in addition to the key material being
deleted, the info itself is different which should cause
the master key to rotate and "be lost" even if the key
erasure routine is flawed.

Chaff keys harden against side channel analysis of data
in flight from the RRAM array - under the theory that
the RRAM array is a big, long set of wires (on the order
of mm's) that should make a great target for EM microprobes.
The chaff keys are read out in a random order every boot,
to make it harder to accumulate enough samples to average
out what's going on.

The nuisance keys are just read straight out of the array.
They might be recoverable by side channel analysis, but
their purpose is to make it annoying for a brute-force
read-out of the key array by a microscopist. The location
and size of the nuisance keys are picked to force the attacker
to really dial in their polishing process so that they have
to hit the right layer across the entire chip (or at least
a couple mm's); and then a set of bits are packed closely
together to try and induce as much cross talk on the word
lines, running under the theory that any attack relying
on stray electrons activating the bitlines to enable read-out
are likely to non-selectively activate bitlines, so the
resulting "glow" of the word line is going to be a superposition
of several bits at once. An attacker could, of course, cap
each bit line with a FIB, read the word lines, then uncap/recap
them one by one - but this drives up the cost of the attack
and ensures that it's not just a single imaging run but
will take at least hours if not days for a skilled adversary
with the most modern equipment to extract the data. Furthermore,
the large amount of bits demands that the attacker read out
the data with better than 97% accuracy (the last 3% can be
cleaned by the ECC coded into the array), so mistakes
are costly.

The chaff/nuisance keys are read out where the chaff keys
(which are order-independent) are interleaved with the nuisance
key readout. The chaff keys are read roughly twice, using
a continuous-time algorithm to pick which version of the
chaff key is read, making it a bit harder for sidechannel
analysis to pick out which key is in flight.

It's an attempt at sidechannel hardening, we'll see how it
holds up. Pretty sure there's still some low hanging fruit
in the read-out, it'll be interesting to see what the red
team comes up with.

Hopefully this at least makes the keystore not the low hanging
fruit, and we're back at looking at bootloader/kernel exploits etc.
to do key extraction, which I'm sure there are many; but at
least those can be patched.
2025-10-28 17:29:06 +08:00
bunnie
d8aa8cddd7
harden boot0
- setup rram security bits immediately
- setup coreuser mapping immediately
- check boot0 pubkey region against data slots, and note if
issues are found (and erase keys)
2025-10-28 03:39:20 +08:00
bunnie
28e5484c57
expand audit and add boot0 key indelibility test
audit is now expanded to track one way counters and
summarizes security state

boot0 key indelibility test added as a feature, to be
used in the future for CI
2025-10-28 03:37:28 +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
1549a87772
update blobs
include artifacts that burn pubkeys and write-protects into
the data array
2025-10-28 03:32:12 +08:00
Jeanie
ceab531852 remove item unused by extension 2025-10-27 23:15:20 +09:00
Jeanie
eb34d121ac docs tidying and proper readme 2025-10-27 22:51:57 +09:00
bunnie
fb3c89949c fix boot delay calibrations 2025-10-27 19:07:33 +08:00
bunnie
4486438df3 add loader code that configures the board type for baosec
only when the baosec feature is specified for the loader.

Note: Will blow up if you try to load a baosec image on a dabao board.
2025-10-27 19:06:42 +08:00
bunnie
763c0e8193 make boardtype return the current boardtype when no args given 2025-10-27 19:06: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