Commit graph

157 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
b509fffc51 cleanup perclk setting 2025-12-16 00:57:24 +08:00
bunnie
a94595ca9f RTC: rework to give milliseconds time
The original RTC was set to a 1Hz tick, which isn't sufficient
for the time API

This has been reworked to give a 1/1024 second increment.
Rollover logic is implemented in the RTC. Requires the system
to be powered on at least once every 48 days to capture the
rollover, otherwise it could miss a rollover event. This is
fine because the backup battery doesn't last that long, and
scans of QR codes for password login always reset the RTC anyways.

The RTC offset randomization code is now gone because we're
not tracking long-term power-on information in the RTC.
2025-12-15 15:16:10 +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
a3f9a9942d update APIs to use the central clocking implementation 2025-12-08 15:58:27 +08:00
bunnie
c85425ae91
add dynamic glitch response via IRQs
non-paranoid mode responses happen through IRQs (recall that
paranoid mode is a hair-trigger hardware reset with no
exceptions). This patch installs the IRQ handlers in boot0
and boot1.

- boot0 in particular now even has an IRQ handler. Previously,
it didn't have the IRQ facility configured, because there was no need
for one.
- boot0 sets up the sensors, and the IRQs
- boot1 merely continues with boot0's settings, but re-installing
the trap handler to be its own and double-checking some
register settings.

An old testing IRQ handler stub for keyboard presses was also removed,
as it can never be triggered as that IRQ is never set up.
2025-12-07 01:37:55 +08:00
bunnie
66272a82e4
ensure secret erasure if developer mode bit is set
this is the final part of the developer mode bit hardening.
If an adversary manages to increment the developer mode
bit, the next reboot they have to contend with active counter-
measures that would attempt to erase the secrets due to
the developer mode bit being set.

As noted in the top of the commit set, previously, without
this, the attacker would have the luxury of being able to
flip the bit and try many times to bypass the developer
mode check.
2025-12-06 18:39:58 +08:00
bunnie
50d32ecb42
upgrade audit routines to use the new signature checking API 2025-12-05 23:16:04 +08:00
bunnie
8be0f1004b
upgrade boot1 path to implement signature hardening
multi-pass signature checking and jump target hardening
per boot0 standards implemented here
2025-12-05 23:15:15 +08:00
bunnie
4b25e24d7e
harden boot1
boot1 hardening is similar to boot0 hardening - bollard & delay
insertion, checking that we're in PLL mode. Also the first phase
mesh results are checked and second phase is setup for the loader
to finally check.

clocks are still local to the routine - there's a to-do to consolidate
that routine into the API layer later on.
2025-12-04 15:36:55 +08:00
bunnie
9217b9aff5
add a quick health check to the RO trng
takes 8 samples and makes sure those values aren't repeated in the
next 8 samples.

has a ~1 in 500 million chance of giving a false positive. But
generally should catch: stuck-at fault, and also, a highly trained
oscillator fault.
2025-12-04 15:34:39 +08:00
bunnie
c126f7b4f1
add repl commands to boot1 for security
- add `paranoid` command - when set, puts the chip into
paranoid mode. Not set by default because we need to check that
the security countermeasures are not too aggressive
- `lockdown` now revokes all developer keys in both main and
redundant array, and sets paranoid mode
- api fixes for sig validate
- audit now prints results of paranoid mode and attack count
2025-12-04 15:32:10 +08:00
bunnie
b12ce104ec fix altboot issues
- don't slot-check in altboot (altboot actually runs in a security
environment that doesn't have boot privileges)
- force bootwait ON by default if altboot is entered - otherwise
we enter a boot-loop
- update release description as towards beta-0
2025-11-25 00:15:36 +08:00
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
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
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
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
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
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
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
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
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
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
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
b864445dff version generators should not be checked in 2025-10-19 01:02:20 +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
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
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