Commit graph

216 commits

Author SHA1 Message Date
bunnie
5964328bcf on second thought, best to keep the command undocumented
since dabao users might try to run it. the command only has
meaning on baosec devices
2025-11-24 18:44:08 +08:00
bunnie
2556b40614 add baosec-init to help list in boot1 2025-11-24 18:43:21 +08:00
bunnie
87b3bbba4d add RTC initialization
a random offset is added to the base RTC value to obscure how
long the device has been in continuous use for
2025-11-24 18:26:36 +08:00
bunnie
8a60f771af add a tailored command to setup baosec boards in boot1
this simplifies CI a bit instead of having to bounce over
to a baremetal image to set things up.
2025-11-23 18:05:48 +08:00
bunnie
9a1cd5429d turn off console printing to USB when USB is shut down 2025-11-23 18:05:28 +08:00
bunnie
31d0a6c691 use the opportunity to introduce a little jitter in the reboot timing 2025-11-23 09:05:03 +08:00
bunnie
47428f40ff add backup register initialization
this will cause a "double boot" of boot0 on the very first
power-up
2025-11-23 08:49:50 +08:00
bunnie
5bf4a6416a add configurations for security testing 2025-11-21 00:58:23 +08:00
bunnie
dc710b3498 add ability to directly set bootwait
instead of having to read and then figure out which state we're in
2025-11-19 17:07:39 +08:00
bunnie
5e805196e6 fix typo 2025-11-14 19:14:25 +08:00
bunnie
c5fb3f282d fix handlers to adjust max packet size to enumeration speed
this seems to make enumeration more reliable with weird cables
2025-11-14 16:15:56 +08:00
bunnie
78f0fcac1a add more differentiation of alt-boot/boot configs
also clear the baosec flag when dabao is forced
2025-11-13 22:20:10 +08:00
bunnie
fd0f684ee3 fix stale api in repl 2025-11-13 21:57:41 +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
6af2001810
fix write protect bits
Each write protect bit in the IFR array covers *8* key slots.
This scopes the write protect down to just the 8 slots we care about.
2025-11-13 18:20:12 +08:00
bunnie
bd37ffde5c
Move in-system keying to system code
Since in-system keying has to happen in the factory, it doesn't
add anything to burn it into the bootloader. Furthermore, the
access controls are already set up so that the keys can only
be accessed by the OS code.
2025-11-13 10:57:04 +08:00
bunnie
47e8f96ccb update release description 2025-11-12 22:08:28 +08:00
bunnie
5c98af9dfa fix errors in TRNG setup
- qdiv frac non-zero
- only enable core 0
2025-11-11 07:53:18 +08:00
bunnie
69c93caadf remap PROG pin to effectively reset for alt-boot mode
this makes it a little easier to explain the procedure in
exiting alt-boot mode
2025-11-08 08:59:19 +08:00
bunnie
815621d829 update handling of id numbers 2025-11-06 14:10:38 +08:00
bunnie
137c70a629 add routines for manipulating and using the serial numbers in boot1 context 2025-11-04 13:15:28 +08:00
bunnie
2f0895b46c Merge branch 'main' of github.com:betrusted-io/xous-core into keystore-dabao 2025-11-02 08:02:17 +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
3f60e48793 Fix 'boot' command not re-enumerating USB
The "press button" path cleanly shuts down the USB stack
before going into the next stage.

"boot" does not; it missed the additional code added at the
end of the main routine.

Refactor the "boot" routine to be a function call now, so any
future improvements to the boot process are used by both paths.
2025-11-01 20:09:43 +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
5a8c7c7aa3 cleanup apis and reset spi memory mode at top of boot1 2025-10-30 04:15:12 +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
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
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
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
1549a87772
update blobs
include artifacts that burn pubkeys and write-protects into
the data array
2025-10-28 03:32:12 +08:00
bunnie
fb3c89949c fix boot delay calibrations 2025-10-27 19:07:33 +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
bunnie
5f7b3d6442
commit more boot blobs
these are burned in at CP and define the accessibility of various
regions in the RRAM
2025-10-27 18:20:58 +08:00
bunnie
2f957d3f35 improve error messages 2025-10-26 19:30:18 +08:00
bunnie
72e8c1a6fa
print errors on slot initialization instead of crashing
these errors mostly trigger when transitioning between
board types during testing
2025-10-26 19:29:11 +08:00
bunnie
72a7ea3a56 add settings for IFR locations 0x280 and 0xc0
Setting these JTAG-only accessible locations will set
write protection on boot0. This effectively makes the public keys
used to establish the boot chain indelible.
2025-10-26 01:31:34 +08:00
bunnie
392cd64493
cleanup options in slot management code
- feature gate some unsafe-debug
- tie akey_id to 0xff which should disable key chaining, which
is not used in our scheme because authentication is not hmac-based,
uses public keys instead
2025-10-25 22:27:50 +08:00
bunnie
b4502854f1 adjust dabao default frequency to full speed
latest rev of the board seems to handle the heat load OK.

board gets a little warm to touch when the system is clocked
at max frequency, but not unpleasantly so.
2025-10-25 21:37:38 +08:00
bunnie
2be1b48653 fix import path 2025-10-25 01:38:55 +08:00
bunnie
d11d2f8cd5 modify default voltages; normalize the setting location 2025-10-25 01:37:21 +08:00
bunnie
e1f685f70d fix missing path 2025-10-25 01:32:22 +08:00
bunnie
0d369f8a9f add feature for printing the ifr in boot 2025-10-24 21:15:12 +08:00
bunnie
04d46b9549 update location of system timer interval definition 2025-10-24 21:12:00 +08:00
bunnie
41f09420cd
clean out some old debug, and activate erase_secrets on dev boot
this has only been lightly tested - much, much more testing
is needed.
2025-10-21 23:47:51 +08:00
bunnie
11c23c3b1c
refactor coreuser setting and boot flow
this accommodates the notion of erasing secret keys when
a developer key is detected. Some hackery in the API is
required, because I'm trying to use the same signature
routine for both boot0 and boot1, but coreuser settings
should not be set until boot1.

Boot0 has *no* coreuser settings, whereas boot1 starts
to lay them in - this interferes with key erasure, and
so the nice clean "boot or die" abstraction disappears
because we have to now just check if a key matches a criteria
and then return because we have to handle the environment
dependent case of coreuser settings.
2025-10-21 19:06:12 +08:00
bunnie
e1c07cbf0b cleanup some debug output & fix ref link 2025-10-21 04:16:45 +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
4affb7e979
add the code for initializing keys & setting up ACLs
this code audits the status of the data/key slots,
initializes them according to the platform, and sets
the permissions on them to prevent read-out later on.

A TRNG routine is built into boot1 now, I think it's
reasonably conservatively coded but more testing/inspection
is always good.
2025-10-20 23:39:04 +08:00
bunnie
1eeaa23516
Realizing that the permission level settings could change
Not locking them down in boot0: allowing them to be set up
in boot1. this is less hermetic, but already I have thought
of a couple of reasons to modify the tables; for example,
the dabao configuraiton if someone wanted to make a secured
version, you might not want PID 3 to be the trusted PID;
or if you wanted to have two different sets of keys for
different purposes, you can use the other permission levels
to separate them.

So, leaving it configurable. for now.
2025-10-20 23:36:34 +08:00
bunnie
1d5cc0806b
update boot1 to use slotmanager API
also add the hook for setting up/checking all the other slots
2025-10-20 02:20:45 +08:00
bunnie
356ab47c3c
add coreuser table setup to boot0
I think it belongs here, because this "should" be a "baked in"
setting. Maybe I'll regret that, because it really enforces
a hardware one-way door on changing/updating the coreuser maps,
but also, I think it makes it a bit stronger if there is no
easy way to bypass/override that setting.
2025-10-20 02:18:28 +08:00
bunnie
972450e306
propagate flag changes to crates that can configure it 2025-10-19 01:20:53 +08:00
bunnie
7383bd5356 move boot1 to also use the lower boot frequency
this does not seem to have a large effect on update times and
allows us to operate over more platform configurations absent
specific power-on control code
2025-10-19 01:04:21 +08:00
bunnie
7bd43d6499 change s/n readout API to use the new SlotManager API 2025-10-19 01:03:55 +08:00
bunnie
92a3b05627 reduce boot freq / voltage even lower
this allows boot on extremely "weak" systems where very little
power is available.
2025-10-19 01:02:43 +08:00
bunnie
b864445dff version generators should not be checked in 2025-10-19 01:02:20 +08:00
bunnie
a5704d292d
Merge branch 'main' into protected-rram 2025-10-18 01:19:50 +08:00
bunnie
201c143762
Merge pull request #701 from betrusted-io/db-selfstest
Add selftest feature for dabao
2025-10-18 01:19:37 +08:00
bunnie
464d26e7b0 adjust default voltages & freqs to be in-line with validation numbers 2025-10-18 01:15:52 +08:00
bunnie
59c3ca5c7e
Merge branch 'main' into protected-rram 2025-10-16 23:39:35 +08:00
bunnie
36b1868fc4 add ram zeorization to top of boot
this slows down boot a little bit but I think this is a good
idea from a security perspective.
2025-10-16 23:37:35 +08:00
bunnie
0bd4de961a I think I won't regret putting a semver into the boot0 stage too
Even though boot0 DUART output may be inaccessible, the string
could still be found by looking in the binary and searching
for it.
2025-10-16 23:25:44 +08:00
bunnie
254780b382 add some artifacts for an early sample run
These are a bit rushed but wanted to be able to have some
serialization/tracking in the earliest samples sent to
'alpha-zero' developers.
2025-10-16 23:21:07 +08:00
bunnie
e80a3dadfb cleanup some testing code that should have been eliminated from boot 1
also remove an unused dependency
2025-10-08 02:56:26 +08:00
bunnie
dbcf346ffb add security audit & lockdown features to the boot1 stage 2025-10-06 23:24:01 +08:00
bunnie
9c9c6f67a7 fixup tag return API
returns a [u8;4] instead of a u32
2025-10-06 15:20:56 +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
3c341d0f8e handle return codes that include tags 2025-10-06 03:49:55 +08:00
bunnie
d1f5aa19a8 map clock sources to API files, cleanup irqs on boot
- clock freq/voltage now in API definitions
- IRQ is disabled (or re-disabled) on all exit paths
2025-10-05 17:00:39 +08:00
bunnie
46b5c6f17d missing command option in help 2025-10-05 17:00:20 +08:00
bunnie
07ec63a1b3 add better loading feedback in various configs 2025-10-05 16:59:55 +08:00
bunnie
2fb72be487 update signature check api in boot0/boot1
pass `None` for the spim field as these are direct RRAM checks.
2025-10-04 18:53:13 +08:00
bunnie
6da0482831 add screen feedback for baosec target on updates 2025-10-04 16:21:06 +08:00
bunnie
1b36c34341 add swap/spim writing to boot1 2025-10-04 00:48:23 +08:00
bunnie
73192dc2d8 cleanup on boot1
main thing in this commit is remembering to activate PWM
mode on DCDC2 for a quieter power supply. the chip draws
so little power that the power-saving regulator hiccups
and has too much ripple.
2025-10-01 23:33:35 +08:00
bunnie
faa13e71f3 speedup firmware update writes by eliminating debug print 2025-10-01 23:32:54 +08:00
bunnie
444ae53a11 add cleanup for USB stack
have to shut it down gracefully or the next stage won't run.
2025-10-01 23:32:21 +08:00
bunnie
1d9c8e8121 cleanup unused code and make ifram mappings extremely clear 2025-10-01 14:57:10 +08:00
bunnie
e95550cb52 add oled ui for baosec board targets on boot1 2025-10-01 14:27:51 +08:00
bunnie
b85ed18cd8 boot1 improvements
- add boardtype setting
- work around usb serial tx timeout hangs - not sure why they happen,
but let's not hang the repl on them.
- various cleanup code & comments
- note boot frequency
2025-10-01 02:48:36 +08:00
bunnie
4e2fc04d5d cleanup legacy code 2025-10-01 00:42:02 +08:00
bunnie
91232fd57b cleanup comments on boot1 code 2025-09-30 23:47:50 +08:00
bunnie
c1544ca5e7 fix initialization bug in statics
this unstucks the console when USB comes up.
2025-09-30 21:51:54 +08:00
bunnie
a6769c46ba track change in statics struct 2025-09-30 21:51:28 +08:00
bunnie
52e9cd0630 make trailing whitespace CI happy 2025-09-30 17:35:19 +08:00
bunnie
d9ff07a32f redo the fat emulation layer
present a 128MiB FAT32 disk based on a dumped image that was
clean-initialized on a windows machine (windows is the most
picky so it is used as the template maker).

add hooks for emulating sparse reads of file system structures
that are well outside our available memory range.

add hooks for writing uf2 files when valid sectors are encountered.

this basically works, you can whack a uf2 file into the disk
and the update happens.

the problem now is that something breaks in the repl loop
when USB disk traffic happens, this commit gives us a checkpoint
to work against.
2025-09-30 17:29:06 +08:00
bunnie
7ec9457854 cleanup the boot-wait code, and add autoboot toggle command 2025-09-30 00:38:19 +08:00
bunnie
6b8d8f09f7 cleanup functional code specifiers for boot partitions 2025-09-29 22:17:38 +08:00
bunnie
01cf1df330 u2f serial upload now working
works over both physical serial port and USB serial port.
2025-09-29 21:58:01 +08:00
bunnie
a511e3c591 add uf2 over serial protocol for writing e.g. baremetal images 2025-09-29 18:40:57 +08:00
bunnie
fa875158e3 add uf2 file sender that works over the serial port 2025-09-29 18:40:33 +08:00
bunnie
54b16cdf64 fix public key origin for signature checks
in general the public key should come from a trusted block, not
the image itself. The initial prototype of the image was written
for self-checking of boot0; but for other images, the public key
should "chain" from the trusted image (i.e. boot0's key should check
boot1, boot1's key should check baremetal/loader, etc.)
2025-09-29 16:18:21 +08:00
bunnie
d0bd60d93c fix USB handling
- statics origin set correctly
- debug prints on USB stack go to DUART to avoid a Tx storm
when debugging e.g. Tx packets on USB
2025-09-29 14:49:06 +08:00
bunnie
59ae767741 fix statics origin in boot0 2025-09-29 14:48:48 +08:00
bunnie
7b5c4e1cd8 add a draft boot1
boot1 contains all the ideas up to and including the console.

however, the actual file transfer bits are yet to be implemented.

onward!
2025-09-29 13:52:38 +08:00
bunnie
75022f0b63 track API change for location of combohash bits 2025-09-29 13:51:00 +08:00
bunnie
4375bf43d0 remove debug as a default option for ed25519 2025-09-29 13:49:39 +08:00
bunnie
8cbdb75dc8 cleanup boot0 code
remove things that we don't need in boot0. Boot0 originated from
a much larger, more featureful space and needs to be whittled down
to remove attack surface and space for bugs.

Some further cleanup to do would include:

- hardening the PLL setting. Right now it's done computationally
based on the demanded frequency. But in practice, because the
target frequency is hard-coded, we could just compute the actual PLL value
results and jam them into the register and lose a whole bunch of
code.

Actually I think that's all that needs to be cleaned up off the
top of my head.
2025-09-29 13:46:42 +08:00
bunnie
728072ebae add documentation of the boot0/boot1 flows 2025-09-29 13:39:37 +08:00
bunnie
63e2834e9d return the key index that passed from sigcheck 2025-09-27 00:31:24 +08:00
bunnie
6768f87ce8 vendor in the curve25519-dalek for bao1x boot
The *only* change is to make fiat-crypto a non-optional dependency.
For some reason the .cargo/config.toml only half-activates the
feature, in that in the .rs code files the feature is included
but in the Cargo.toml file the dependency is, for some reason,
not enabled.
2025-09-27 00:30:10 +08:00
bunnie
2d0c456929 add vendored-in ed25519-dalek crate for boot environment
Light-fingered changes include:

- debug UART integration for debugging things
- patching the sha2 crate to use hardware acceleration

Most changes are in Cargo.toml, with the exception of the debug.rs
module that was introduced for print-debugging.
2025-09-27 00:29:09 +08:00
bunnie
2f3cf06c16 helps to actually copy the data into the hash engine 2025-09-26 22:57:10 +08:00
bunnie
f76b85c95e signature checking now works
also some light benchmarking code.
2025-09-26 22:56:49 +08:00
bunnie
afba3040b3 cleanup print debugs in sha2 for bootloader 2025-09-25 16:13:25 +08:00
bunnie
a035bb669c add initial signature check code on bao1x 2025-09-25 16:13:09 +08:00
bunnie
c1ab8972fa update boot offsets to handle embedded signature block 2025-09-25 00:00:13 +08:00
bunnie
39142b4c18 add scaffolding for bao1x-boot and also the sha2 implementation for baremetal 2025-09-24 01:02:07 +08:00