Commit graph

656 commits

Author SHA1 Message Date
bunnie
47dd23b1e1 remove a page table dump
cleans up boot log slightly; slightly improves screen-up time
2026-03-20 15:50:00 +08:00
bunnie
7f3dddd74d fix loader edge case: gap in incoming minielf
If there is a gap > 4k in an incoming minielf, the swap offset
becomes desynchronized with the loading offset.

This patch catches that case and increments the swap offset. The
gap data is simply uninit and unused by the system.
2026-03-20 15:48:51 +08:00
bunnie
eb2017f845
fix off-target feature for precursor builds 2026-02-15 03:59:52 +08:00
bunnie
000c4effab
panic in loader should call die instead of just looping 2026-02-15 03:19:32 +08:00
bunnie
c499087d5a
remove redundant prints in loader
the first check should *never* print a message because an attacker
can trigger a glitch off of the UART. this eliminates the diagnostic
print on the first check.
2026-02-08 12:49:50 +08:00
bunnie
3f869ca389 bump utralib version for publication 2026-01-29 19:12:00 +08:00
bunnie
00e70d8c1d add oem-baosec-lite support to loader 2026-01-24 23:51:02 +08:00
bunnie
fba011db3a commit version bump so that we may publish our packages 2026-01-08 03:04:19 +08:00
bunnie
e27b30d818 fix edge case in swapper
A particular edge case was finally reproduced & fixed. The edge
case occurs when a swap is triggered while handling an interrupt,
and an OOM happens during the context switch to/from the interrupt.

The background on this is that the hardware drivers for the swapper,
as well as much of the logical heavy lifting on e.g. what pages to
swap out, live in a userspace process known as xous-swapper.

The userspace process has to run free of interrupts - when you're
OOM'd or trying to swap, interrupts should not happen. The way to
do this in Xous is to run that code inside an interurpt context,
as interrupts are not interruptable.

Thus, the xous swapper userspace consists of two halves: a regular
userspace stub that provides some amount of control/debug over
the swapper, and a handler that gets run in a "pseudo-interrupt"
context.

Like all other interrupts, the handler "borrows" the stack of the currently
running thread - interrupt contexts don't have an explicit stack, they
just grow on top of the current stack of the current thread in the
current process at the time of the interrupt.

This is broken because when you have a swap event inside an interrupt
context, there are conditions where you might not have a stack. What
was in fact happening is that the stack pointer was being orphaned
as being the "exception stack" - which is a temporary location,
only accessible by the kernel, used for storing all the registers
going into and out of exceptions. Since no stack pointer is set up,
the moment the userspace starts to run and spill its registers to
stack, the system trips a "nested swap" event, which leads to a panic
because this is not allowed.

The fix to this is to devote two hard-wired pages, mapped in the
loader, to be the swapper's private stack area. Instead of behaving
like an interrupt and borrowing the caller's stack, the swapper instead
goes back to its hard-wired stack to do all the processing.

This should also improve the performance of swap handling in some
cases because we can now guarantee the stack is always in-memory
and doesn't need to be swapped in during swap processing.

One complication is that the "reserved memory" that the swapper
puts aside in case it *does* need to allocate extra pages during
handling can't be freed at the top of the OOM routine. Thus if
the swapper ends up using new pages, we should expect yet another
crash.

However, in practice, this doesn't seem to happen, because the
cases in which we hit needing a new page are typically related
to cases early on in boot where superpages/new page table entries
are being allocated, or if we're growing the heap that passes
data back and forth between swap and userspace. Because this call
triggers in such a specific condition, I hypothesize that actually
in practice it should generally be able to run without allocations.

One case where maybe it could hit an allocation is if the swapper
hit, for the first time, in an interrupt handler that was swapped
out, and never hit before, and the interrupt handler needed a
superpage to be allocated, thus triggering an allocation request
for a new PTE or two. I think this is probably pretty unlikely, but
if we do hit it, the fix would be to, for the purposes of targets
with "swap" enabled, to mark unmap_memory and map_memory to be
legal syscalls in interrupt contexts. These are normally illegal
because interrupts should always return - and these calls could
potentially fail or block. However, I think in this case it's
a trade-off between "we should be failing if we run out of memory"
and that failure being a potentially incorrect behavior that is guarded
against by a runtime check to discourage such calls.
2026-01-08 02:08:03 +08:00
bunnie
e676ccbed8 cleanup dead code warnings found by latest rustc 2026-01-06 13:41:04 +08:00
bunnie
1087405eb9 add compatibility for APS6064L SRAM parts 2026-01-06 12:14:20 +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
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
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
934d6e1082 remove more /2 errors now that peri clock is correct 2025-12-16 01:06:46 +08:00
bunnie
534e99216a cleanup the erase-check key code to reflect new APIs for managing buram 2025-12-16 01:05:57 +08:00
bunnie
a3f9a9942d update APIs to use the central clocking implementation 2025-12-08 15:58:27 +08:00
bunnie
03d318d2a9 fix precursor target 2025-12-06 20:44:20 +08:00
bunnie
b1480fa518
add secret key erasure value check in the loader 2025-12-06 18:34:20 +08:00
bunnie
3466115cce
harden loader/kernel/app/swap checks
At this point, some of the keys are partially locked out
which makes reacting to an attack slightly less effective
(keys are now locked into a particular process space configuration
which is not available in the loader's default config).

The reaction at this point sums up to seeing if the image is
a developer image, and if so, ensuring that the developer mode
bit is set (which would indicate that the keys have been
erased). I suppose an attacker could get around this by glitching
to some code that sets developer mode without also erasing
the keys. This weakness needs to be explored and hardened against.
2025-12-05 23:17:11 +08:00
bunnie
3293578d3e add second pll check in loader 2025-12-04 16:14:59 +08:00
bunnie
3f7dce3052
loader hardening
The loader is only lightly hardened at this point. Some minmal
random delay + bollards inserted. The signature check routine
inherits all the hardening of boot0 because it uses the same
code. PLL mode is checked at least once.

more loader hardening will happen in a future PR - at the
moment, we're focused on boot0/boot1 hardening.
2025-12-04 15:38:57 +08:00
bunnie
9b54fdb64f fix dabao target dependencies 2025-12-02 02:27:01 +08:00
bunnie
52215251a4 add a random seed to the environment
this is randomly genverated on boot and inserted into the
environment. it is unique per-PID.

This is useful for seeding psuedorandom number generators,
especially in environments where syscalls are not possible.
2025-12-02 01:40:49 +08:00
bunnie
cd8a312b8d switch on the xtal32 source for the rtc in baosec mode, in the loader 2025-11-24 18:27:04 +08:00
bunnie
3893bc78a7 add more annotations & set bootwait on setting board type
bootwait allows automation to load the swap image after the
board type is set correctly

breaks the paradox that you can't init swap on a blank chip
because it doesn't know it has swap
2025-11-19 14:00:08 +08:00
bunnie
b587f63279 emit CI diagnostic on kernel sigfail 2025-11-19 13:54:53 +08:00
bunnie
a208d59690
deny boot to any developer-key signed kernel/detached-app/swap images
Secret keys can't be erased after boot1 exits because the protection
bits are hardened from modification after that point.

thus it is not possible for the loader to switch the device
into developer mode.

Thus the only way to enter developer mode is through a dev-mode
signed loader. A system that has never been put into developer
mode will refuse to run any developer-mode xous kernel, app, swap
images.

Once a system has been exposed to a dev-mode signed loader,
the boot1 will flip the developer mode bit and erase the secret
keys.

Later on, if a production loader is replaced, it doesn't matter
that a production loader is loading dev-mode signed successors
because the secret keys are already erased.

Note that in all cases, the key revocations take precedence
so if the developer key is revoked, these cases should never
even be encountered.
2025-11-18 23:33:33 +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
5e805196e6 fix typo 2025-11-14 19:14:25 +08:00
bunnie
d754b86769 fix susres on precursor
heap can't be initialized before suspend/resume is checked

bao1x doesn't have suspend/resume, and requires heap early
on to check signatures

so heap initializationg is now optionally included in two
locations to meet the conflicting requirements per platform.
2025-11-07 08:01:31 +08:00
bunnie
5981d7afe4 make heap a standard feature available in precursor
this makes the env building uniform across platforms
2025-11-07 00:37:36 +08:00
bunnie
8402c601d2 refactor loader to use new env and pass serial #'s to bao-1x envs 2025-11-06 14:02:02 +08:00
bunnie
01efeb49cb refactor env parsing
make it extensible so that more env vars can be added easily
2025-11-06 13:55:21 +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
406e39a0d5 fix timebase of delays in loader
should be tied to the system clock frequency
2025-11-01 20:09:12 +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
3f46e8443c improve spi device detection code 2025-10-30 04:14:28 +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
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
79eab7da5e add feedback on boardtype resetting 2025-10-28 18:02:11 +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
e91eb176e7 cleanup warning 2025-10-26 19:34:00 +08:00
bunnie
f4fee4488c fix baud rate on console for dabao target
frequency changes means uart nees to be re-initialized
2025-10-26 19:31:36 +08:00
bunnie
e9bf366d3d update freq v voltage setting code in loader 2025-10-25 22:22:40 +08:00
bunnie
66131a59bf add speed-up setting for dabao
the boot1 loader on alpha0 release is conservative
2025-10-25 22:12:42 +08:00
bunnie
569e9526eb fix comment 2025-10-25 01:31:48 +08:00
bunnie
4a12668751 only check the flash ID after going to QPI mode
handles more cases of flash mode switching
2025-10-25 01:31:20 +08:00