Commit graph

4007 commits

Author SHA1 Message Date
bunnie
da44e98257 add chaffing implementation to AES 2025-12-02 01:04:17 +08:00
bunnie
9034a08b5e fix TTS target API change 2025-11-30 22:21:31 +08:00
bunnie
d9a65a51d9 fix hosted mode 2025-11-30 21:56:32 +08:00
bunnie
381dee01eb fix interfaces in GAM for stateful lists 2025-11-30 21:32:26 +08:00
bunnie
49456db837 fix typos 2025-11-30 21:32:08 +08:00
bunnie
98e9d99de8 add stateful list creation
this allows us to have "pre-checked" checklists
2025-11-30 21:31:39 +08:00
bunnie
7d7fa75e7d add debug telemetry for keyboard connect error
sometimes on boot, a process tries to send keyboard an incorrectly
formatted message. I think this might be the IOX interrupt handler
firing due to random noise. Corrective action towards debugging
includes instrumenting the keyboard call with debug info, and also
ensuring that the iox interrupt handler banks are initialized to 0.
2025-11-29 15:49:40 +08:00
bunnie
b702a68c1c test what local time returns 2025-11-29 01:01:24 +08:00
bunnie
4ec0eda2b5 migrate service name to some place public 2025-11-29 01:01:04 +08:00
bunnie
6918e275d0 map the center key to "fire"
This allows the center key to be used as a UI trigger action
without creating a carriage return on the console. this prevents
console actions from errantly triggering during complex ui navs.

probably later on we should filter out more of the UI nav items
going to the console because the console is always listening
2025-11-28 18:43:59 +08:00
bunnie
3b1784d346 make screen panic messages somewhat more useful
some panic messages are hundreds of characters long, most of them
are path hashes or paths to crates that are less useful.

truncate any panic messages to the last set of displayable
characters, so that the "most useful" portion (e.g. file name
and line number) are always visible in a panic.
2025-11-28 18:41:53 +08:00
bunnie
106f7153a1 filter key presses through the video layer
the video layer is the "traffic cop" managing when modals
get focus. This patch creates a feed from the video layer
that listers to subscribe to that filters out key presses
destined for modals.
2025-11-28 18:40:56 +08:00
bunnie
647ec0dfb4 fix dabao target - keyboard server
dabao needs to have a vestigial keyboard server which handles
forwarding USB/serial key events to listeners. otherwise, there
is no input interface.
2025-11-28 11:35:17 +08:00
bunnie
84a083017c gate off incompatible features for hosted mode 2025-11-27 22:11:13 +08:00
bunnie
80eba30099 use screen real estate a bit more efficiently on panic 2025-11-27 17:57:41 +08:00
bunnie
6df070e95e notify waiters that mount is successful 2025-11-27 17:57:24 +08:00
bunnie
fbb04d96ab make center keypress a unique key so we handle it separately 2025-11-27 16:51:15 +08:00
bunnie
1f9ab022f2 implement on-demand QR code scanning 2025-11-27 16:50:47 +08:00
bunnie
a24aaaa944 increase keyup delay slightly
this prevents some keyboard stutter in case of ui lag
2025-11-27 12:34:13 +08:00
bunnie
72144ad35d builds with no timestamp should still display a git version
version descriptions should be reproducible, by definition.
2025-11-27 12:33:43 +08:00
bunnie
434e0c7ae5 refactor organization of code to fix dabao target
kpc isn't possible on dabao due to the pins not being broken out,
so gate out the service entirely for that target.
2025-11-26 21:37:31 +08:00
bunnie
cdf4a56d76 add backup manager ref in keystore
this claims the backup memory region - eventually we'll do
something with it
2025-11-26 20:48:29 +08:00
bunnie
601d2763e8 add keyboard userland abstractions 2025-11-26 20:45:50 +08:00
bunnie
40c94b5abc add kpc_aoint abstraction layers 2025-11-26 20:45:12 +08:00
bunnie
41f750163f change timing of PDDB mount
moving it a shy later into the boot makes the mount process faster
because it's not fighting for swap memory with everything else
trying to initialize at the time.
2025-11-25 01:08:47 +08:00
bunnie
c677f6f78a add apis & services for the rtc 2025-11-24 18:56:03 +08:00
bunnie
543f455ad0 fix scalar return discipline in usb-bao1x
also add ability to read keyboard led state
2025-11-24 18:54:50 +08:00
bunnie
62b656db8a add some test routines for checking RTC functions 2025-11-24 18:28:50 +08:00
bunnie
d30d889774 add rtc hardware drivers and service 2025-11-24 18:28:00 +08:00
bunnie
49dcc7aaa2 add CI telemetry for keystore init 2025-11-19 14:00:59 +08:00
bunnie
90362b2604 fix hosted mode 2025-11-18 23:59:17 +08:00
bunnie
22f44f82b9
add debug telemetry to the keystore
this is constructed in a way such that

1. it's gated off in production builds
2. if it was accidentally gated on, there is some security impact
but not a significant loss of security

We do need the telemetry so that during CI we can confirm that things
are actually working. I think the risk of being too buttoned-up
and then accidentally doing something like accidentally never
initializing keys and leaving them all zero is greater than the
risk of accidental partial leakage of information due to a procedural
mix-up in the image signing ceremony.
2025-11-18 23:20:31 +08:00
bunnie
ad116b5af6 reduce leakage during hazardous-debug
in theory, no production images should be signed that have this
feature enabled. But, reducing the amount of leakage just in
case an accident happens and this flag is somehow slipped
into a signed production image.
2025-11-18 22:46:20 +08:00
bunnie
0723306085 update docstring 2025-11-18 22:40:36 +08:00
bunnie
fdb613cfb3 fix corner case on non-word aligned buffers 2025-11-18 22:40:09 +08:00
bunnie
69b77f3072 allow gen2 to use the seeded trng fill 2025-11-18 19:35:59 +08:00
bunnie
0942858bbc add test cases for trng 2025-11-18 19:35:48 +08:00
bunnie
4f39532471 clean up filling API
previous implementation was full of too many special cases

also add a version that allows us to fill using a seeded CSPRNG
for better performance on bulk fills
2025-11-18 19:34:57 +08:00
bunnie
52c5400fca
cleanup debug 2025-11-13 18:36:03 +08:00
bunnie
9213755a6b
move keystore init to userspace
This moves the key store initialization to the key manager
process itself.

It has been tested to work with signed images, and to also
protect the system in case of another process trying to access
the key data as well as in the case of developer keys being
used.
2025-11-13 18:32:04 +08:00
bunnie
c3c86e857b improve pddb init 2025-11-12 22:08:01 +08:00
bunnie
59325e0571 fix warnings in placeholders in bao1x-emu 2025-11-12 15:28:42 +08:00
bunnie
f4b88ce964 fix deps in other build modes 2025-11-12 15:27:00 +08:00
bunnie
315bee22dc add placeholders for ephemeral/volatile data in keystore 2025-11-12 15:26:35 +08:00
bunnie
8c421c6050
Merge branch 'main' into vault2 2025-11-11 08:47:10 +08:00
bunnie
dd42267eb9 fix mount/format on boot ordering
pddb is working again in hardware, this time with real keys
2025-11-11 08:18:57 +08:00
bunnie
c2c135bfdc fix trng service in baosec environment
fix missing initializers
2025-11-11 07:53:52 +08:00
bunnie
54f476edd3 fixup hosted mode emulation for baosec 2025-11-08 04:20:30 +08:00
bunnie
fa8325c2ed cleanup pddb for gen2 targets
gate out modals entirely from gen2 pddb

passwords in gen2 are now entirely handled outside of the
respective service crates, cleaning up the APIs

some history - on gen1 (precursor) devices, the thesis was to
reduce the amount of distance a password has to travel from
the point of a user entering it to the point of use. I think this
is academically interesting, but it pulls in a lot of code
into each service to manage the passwords, conflating services
with UI layers.

it was a nice experiment.

in gen2 (and hopefully beyond) targets, we now commit to
the idea that something else is passing in the sensitive key
materials. This means that, in fact, keying material has to
transition between process spaces, which increases the attack
surface to recover this. However, it also makes the crates
more portable and maintainable.

This is mitigated partially by the fact that in gen2 targets
the entirety of the code base runs within a piece of silicon,
so "sniffing" (passive observation of data going to memory)
attacks are a good bit harder.
2025-11-08 03:52:39 +08:00
bunnie
792de177b0 implement keystore calls needed for pddb compatibility 2025-11-08 03:52:20 +08:00
bunnie
308529bd75 cleanup warning 2025-11-08 03:51:42 +08:00
bunnie
664ef0a6c4 use serial numbers & interim pid/vid in USB stack 2025-11-06 14:07:30 +08:00
bunnie
5863296632 cleanup the feature tree; add double-lock detection printing
this cleans up the feature dependency tree a bit and also adds
some ability to print an error when the double lock condition
is discovered. it should be solved but it can only be detected
at runtime. Insntead of it being a silent failure (because
the server hung in an interrupt context and couldn't emit any characters),
it sets an atomic bool that can be checked and reported upon by
the main thread.

also cleans up debug uart acquisition.
2025-11-03 08:02:21 +08:00
bunnie
fe136ff820
Merge branch 'main' into vault2 2025-11-02 10:40:47 +08:00
bunnie
5de6581698 include chaff output into the hazardous-debug 2025-11-02 10:38:29 +08:00
bunnie
ed94245a5c enable trng server in dabao mode
this allows the rand core crates to work
2025-11-02 10:37:47 +08:00
bunnie
26078dcc7d add keystore to dabao configuration
After some contemplation, we should include the keystore in the
core service set featured by the dabao-xous configuration.

The pros are: any compatibility/sharing of resources
that require access to RRAM, one-way counters, UUIDs, etc.
will either require a wholly separate implementation that is
"insecure" or it could just reuse the baosec work. Furthermore,
as cryptographic accelerators are laid into the keystore,
the APIs become available to the dabao environment

The cons are: more space is used in a space-constrained
dabao environment (roughly 140k "deadweight" at the start, but
as cryptographic APIs get layered in this can grow substantially);
the key slots are "used up" in part by the scheme, which leaves
less key slots available for user-defined purposes.

This is mitigated by the fact that there are a couple thousand
key slots, and so even though we use a couple hundred of them
it's still not the whole range.

Also, the baosec/dabao feature flag can be used to feature-out
cryptographic APIs/accelerators that are too obscure or not
useful for the dabao environment, to "lighten up" the
firmware load.
2025-11-01 22:59:07 +08:00
bunnie
9d07d19361
Merge branch 'main' into vault2 2025-10-30 15:06:23 +08:00
bunnie
60f1b90acb fixup apis 2025-10-30 04:14:48 +08: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
9336bdab6a
Merge branch 'main' into vault2 2025-10-28 23:15:41 +08:00
bunnie
b557cd5ebc
add some trng tests to the console 2025-10-28 18:02: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
6a548de693
Merge branch 'main' into vault2 2025-10-27 00:02:26 +08:00
bunnie
3a02dc125c add rram debug commands & duart-debug mode for the HAL in std 2025-10-26 22:22:46 +08:00
bunnie
0003921eb1 disable preemption during video capture
the camirq is a perfectly good source of preemption,
and xous will run other threads when the handler is finished.

having both natural timer preemption and camera preemption running
at the sime time seems unnecessary and hurts performance.
2025-10-26 13:37:31 +08:00
bunnie
d2254e2ce4
add HAL to keystore dependencies 2025-10-26 13:37:04 +08:00
bunnie
2a2863c11a
put keystore in charge of enabling preemption
this is done after critical setup is done. it doesn't guarantee
that it has an infinite time slice, but it makes the startup sequence
more deterministic.
2025-10-26 13:35:57 +08:00
bunnie
21c9089de2 make pre-emption controllable 2025-10-26 13:35:35 +08:00
bunnie
6dd2a1f554
update dependencies for keystore 2025-10-26 02:00:19 +08:00
bunnie
ba91aa5b58
Add audit code for the keystore
the snippet `attack_keystore()` is left in place along with hints
on how to attack the keystore. Nominally, the attack should fail,
but there are some critical pre-assumptions that can be violated.

I am interested in knowing how robust those assumptions are, so,
documentation and sample code is provided to would-be attackers.

Do me a solid and if you do find a vulnerability, open an issue
ASAP and let me know. Full well aware that some vulns may well
be unpatchable; it is what it is. Hardware is hard, but maybe
we can work together to make it better.
2025-10-26 01:57:06 +08:00
bunnie
f68cc0ba83 reorder some bao-video operation for a cleaner init sequence 2025-10-25 22:55:23 +08:00
bunnie
37ff052b34 chunk data to the USB subsystem
the chunks match the size of the application buffer, eliminating
the possibility of an overrun (of the buffer at least)

there is a possibility still i think of overrunning USB itself
but i think the CPU can't produce data fast enough to actually
do that.
2025-10-25 22:23:36 +08:00
bunnie
8a3e9ea3f5 fix crlf issue in logging crate 2025-10-25 21:36:46 +08:00
bunnie
63b848df28 fix timing interval to match the CPU clock frequency 2025-10-25 21:36:21 +08:00
bunnie
5fb7743d3b add preemption timer to the kernel
we can use the TIMER0 mechanism now that this is available in NTO!
2025-10-24 21:10:19 +08:00
bunnie
8f208cac4c
refactor debug-print in bao1x-hal
on dabao targets the duart is unavailable, so, it's convenient to
have a uart-based debug option in the HAL. this patch creates a
flag that can allow either target.
2025-10-19 01:19:30 +08:00
bunnie
c32dde7b06
Merge branch 'main' into vault2 2025-10-06 13:45:17 +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
6d4f8004d3 fix breakage associated with changes to xous-semver 2025-10-06 13:17:21 +08:00
bunnie
8fcca4f873 cleanup bitrot 2025-10-06 01:34:13 +08:00
bunnie
8d067e6819 Merge branch 'main' into vault2 2025-10-06 01:23:21 +08:00
bunnie
140f1ae538 add dabao support to usb-bao1x
the minimal set of envisioned services for the dabao would
include a USB handler. Seems like too useful a thing to not
have it enabled.
2025-10-05 17:17:31 +08:00
bunnie
4069b623c4 add note about where to get dabao console from in bao-console 2025-10-05 17:17:07 +08:00
bunnie
e00606538c add SE0 release to userspace usb driver 2025-10-04 16:21:34 +08:00
bunnie
8e4d1d047f remove debug prints from usb userspace
these conflict with the kernel debug prints.
2025-10-01 23:34:53 +08:00
bunnie
d3c55b218f turn on the power supply for the camera 2025-10-01 23:34:35 +08:00
bunnie
b86664d279 move camera clock pin setup into the camera driver in Xous.
previously this was setup in the loader, which is a bit of an
abstraction bodge.
2025-10-01 15:00:40 +08:00
bunnie
d265ce3398 note deprecated pin config 2025-10-01 02:56:40 +08:00
bunnie
889262d20c remove font mapping from bao-video; fonts are now in our space by default 2025-09-25 16:12:47 +08:00
bunnie
0fe5fcdc35 this autogenerated file should not be in the tree 2025-09-24 01:09:19 +08:00
bunnie
ff6ff8841a fix missing api in precursor target from previous PR
also fixup some warnings from the new rustc.
2025-09-21 23:33:37 +08:00
bunnie
0b1f2796f7 for hwsim target make xous-log output to the duart
this removes the kernel log but you have the verilator sim trace
to debug things
2025-09-20 22:12:19 +08:00
bunnie
179e178e96 fix up formatting that changed due to the flag day 2025-09-18 21:31:54 +08:00
bunnie
1255bf12d9 FLAG DAY: fix all names to harmonize around 'bao1x'
The code base had evolved through several code names, interim
names, company names and chip names that alternatively did or did
not exist.

Baochip is the definitive name of the company, and the Baochip1x
(full part number BAO1X2S4F-WA) is the definitivey part number of
the SoC. For convenience, the part number is shortened to 'bao1x'
in most feature flags and variable references.

This commit fixes all of the odd names and removes some unmaintained
early targets.
2025-09-18 21:25:51 +08:00
bunnie
edf5206846 test code for shutdown/keep-on
at the moment not working, will resume debug once new rev of board
is back.
2025-09-18 20:19:48 +08:00
bunnie
e697b2da77 add bio pin setup handler for xous env 2025-09-14 02:14:41 +08:00
bunnie
b0d2a18122 add some debug info for spurious irqs 2025-09-13 16:18:15 +08:00
bunnie
9b515a042f add serial port library functions and handlers
this creates hooks for applications to listen to the serial port,
as well as to send and receive data. some improvements to code
ordering for readability are bundled in this as well.

very lightly tested, most of the code comes from other more tested
code in the Precursor stack.

the TRNG test stuff is not put into this stack because I think
it belongs in the baremetal environment, as it's only ever
run for characterization. We don't need to bog down the production
stack with test code.
2025-09-13 15:37:08 +08:00
bunnie
890c311102 make the logger serial path more robust to failures
the logger should not fail under any circumstances, so
any errors in the USB stack should be ignored.
2025-09-13 15:36:36 +08:00
bunnie
7f5a288090 add some commands for testing the serial console & port setup 2025-09-13 15:36:16 +08:00
bunnie
5dae83d404 improve panic screen formatting 2025-09-13 15:35:34 +08:00
bunnie
c47334704a PoC USB serial on top of the HID modes.
this now works with windows, after much testing and patching.
2025-09-13 01:12:12 +08:00
bunnie
b99da45c38 fixup dependencies to point to local fork versions
the local forks are needed to layer in high speed support,
debug, and a couple of other minor improvements.
2025-09-12 02:51:19 +08:00
bunnie
1b9c0c7143 gate off duart mapping when not debugging deep in the usb stack 2025-09-12 02:50:45 +08:00
bunnie
d20a1e4ed9 gate of unused functions without mass-storage 2025-09-12 02:50:24 +08:00
bunnie
e79f907bb7 add basic usb-serial support
some test code to echo characters back, needs to be improved
fix some reset edge cases, needs more work as stack still
does not enumerate on second plugin
2025-09-12 02:49:21 +08:00
bunnie
08aa40e557 add ctap protocol testing routines 2025-09-09 23:11:30 +08:00
bunnie
0df2cb73f7 fixup bao-video deps 2025-09-09 22:24:55 +08:00
bunnie
5ff4b6c317 turn off debug-print by default in usb 2025-09-09 22:20:02 +08:00
bunnie
1cd6a3c4d0 clean up warning 2025-09-09 18:41:25 +08:00
bunnie
16b3c43e31 get OUT packets working; in particular, HID/U2F seems good to go 2025-09-09 17:53:47 +08:00
bunnie
51adf0e76c clean up interrupt handler & remove page allocation from handler
handler works in an interrupt context, so it can't allocate
a page to return data. this cleans up that problem, and also
removes some redundant brute-forced checks that were copypasta
from previous merging of several routines.
2025-09-09 17:52:12 +08:00
bunnie
5978de6a22 cleanup warning 2025-09-09 17:51:48 +08:00
bunnie
9931daf131 fix broken links from rename 2025-09-08 17:21:49 +08:00
bunnie
6cf4757323 rename usb-cramium to usb-bao1x 2025-09-08 17:21:32 +08:00
bunnie
7fa4bb0cc5
Merge branch 'main' into vault2 2025-09-07 11:54:17 +08:00
bunnie
75a9373fea fix AES dependencies so that the correct acceleration is enabled
This relies on a trick I was not aware of previously, which is
that transitive dependencies absorb the additive set of features
enabled within a crate.

see

https://doc.rust-lang.org/cargo/reference/features.html#feature-unification

for the full description. but basically by referring to the feature
required in "aes" despite not being used in the crate but pulled
in by aes-gcm-siv, i can ensure that the transitive dependency
is in fact used.

I think this was always there but previously I just didn't understand
it correctly or didn't use it right when I tried to deploy it, but
this time I think I got it right.
2025-09-07 11:50:12 +08:00
bunnie
1c8a3a3ee9 migrate to using the latest rqrr with perfromance enhancements 2025-09-06 22:47:48 +08:00
bunnie
ac458c4b07 reduce pixel math (do mirroring in camera module)
also add some more analytics output
2025-08-20 03:07:12 +08:00
bunnie
a403f0c5f9 fix rust warinings 2025-08-20 03:06:24 +08:00
bunnie
1d950033af add base64 dumping of captured images for off-line optimization 2025-08-19 22:44:15 +08:00
bunnie
ffc226b9a8
Merge branch 'main' into nto-bringup 2025-08-19 19:51:16 +08:00
bunnie
ecbac27e76 fix rustc-1.89 warnings 2025-08-19 19:45:29 +08:00
bunnie
f2c61e44cc add aes test options to command environment 2025-08-10 22:28:32 +08:00
bunnie
55d0a6c947 add aes testing feature to console 2025-08-10 22:28:14 +08:00
bunnie
4eacde470f add commands for AES testing and for calibrating delay loop 2025-08-10 22:27:30 +08:00
bunnie
781c74ba79 make ticktimer scale with system clock setting in loader 2025-08-10 17:54:45 +08:00
bunnie
857e54c5af move the console to its final location 2025-08-10 01:56:07 +08:00
bunnie
381b7ec90e remove gpio frame-sync 2025-08-10 01:55:25 +08:00
bunnie
e3664738bc remove AES bodges due to broken AES unit in MPW 2025-08-10 01:43:03 +08:00
bunnie
508c38cfdd refer cache flush to hal version 2025-08-05 23:01:03 +08:00
bunnie
345e8868cf make bao-console work with hosted mode 2025-08-02 00:49:55 +08:00
bunnie
d91b7843cc cleanup bit-rot in I2C API in this branch 2025-08-02 00:49:38 +08:00
bunnie
0e1018797e implement HW acceleration for AES128. 2025-07-27 03:17:40 +08:00
bunnie
098d326b55 note performance improvements 2025-07-27 03:17:15 +08:00
bunnie
6fd1757a04 optimize AES routines
- change ordering of aes instructions to remove pipeline bubbles
- port the aes-256 encryption routine from assembly
2025-07-27 02:15:05 +08:00
bunnie
bd45919944 add aes test option into the mbox1 test 2025-07-25 18:59:33 +08:00
bunnie
2e8e2e0364 introduce a message passing test before mbox test 2025-07-24 00:30:04 +08:00
bunnie
1f55dd8ab1 add the messaging test into the mbox environment 2025-07-23 01:23:45 +08:00
bunnie
c0735374f0 fix hosted mode 2025-07-22 01:43:58 +08:00
bunnie
815c082153 add breadcrumb for improving the cbo.flush instruction
whenever rust stabilizes "zicbom" in RV we can remove the ugly
.word hard-coding of the flush instruction.
2025-07-21 19:12:37 +08:00
bunnie
6eaf3501bd add cbo.flush support for vexii targets
Spinor is the one location where memory changes out "from underneath
the CPU" in a cacheable region. This happens when we update a block
of FLASH.

Vex-ii has a physically tagged d-cache, but the cbo.flush instruction
needs the *virtual* address to be passed (it then goes through a page
walk or TLB lookup to resolve the tag). The virtual address only
exists and can be correctly resolved to a physical address in the
process space of the owner of the region that maps to the SPINOR
FLASH. Thus, we introduce a flush routine in the lib.rs side that
calls the cbo.flush instruction on every line that has been potentially
modified by the flash write routine.

Note that cbo.flush is not yet natively supported by Rust stable,
so it's coded as a series of hex words fixed to a given register (a0)
to avoid introducing a nightly dependency. Once the cbo.flush
assembly instructions stabilize we can make the assembly read more
nicely, but functionally it should compile to exactly the same code.
2025-07-21 19:09:05 +08:00
bunnie
75556b2321 add feature flags for vexii-test in rootkeys and shellchat 2025-07-21 19:02:21 +08:00
bunnie
a3d350b86f note aes performance on vex-ii; fix typo on aes256soft_test
aes256 soft test was running on hw before by accident.
2025-07-21 17:19:22 +08:00
bunnie
cb7f6d50b1 add vexii-test feature to pddb 2025-07-21 17:14:02 +08:00
bunnie
7dc09bbc73 updated AES library with Vex-II drivers
This will also be the version we'll use for the daric chip once
it's available; the prior software-only version hack for MPW will
be retired soon.

Note that only AES-256 is implemented in this commit, AES-128
isn't used on the system and so is provided as a software-only
fallback path.
2025-07-21 16:34:05 +08:00
bunnie
a858c09e53 add vexii-test feature to aes lib 2025-07-21 03:10:04 +08:00
Sam Chin
04bf756b8e theoretically clean version which has been tested with and without the feature 2025-06-11 15:05:59 +08:00
Sam Chin
0412a401d8 no more deadcode 2025-06-10 21:51:55 +08:00
Sam Chin
2659fc0894 wip'
'
2025-06-10 21:51:55 +08:00
Sam Chin
c9116cffd9 adding line back in 2025-06-10 16:00:16 +08:00
bunnie
59db16aa99
remove debug message 2025-06-09 18:49:28 +08:00
Sam Chin
a25f20d045 making console flags happy 2025-06-09 17:47:00 +08:00
Sam Chin
90d88820dd dropped a ; 2025-06-09 17:37:12 +08:00
Sam Chin
d1b5a41e82 fixing help text 2025-06-09 17:37:12 +08:00
Sam Chin
c291b6a11f now passing the linter 2025-06-09 17:37:12 +08:00
Sam Chin
e5cdeaf2ca adding some cute command line arguments 2025-06-09 17:37:12 +08:00
Sam Chin
1b8554b8f2 removing the BMP180 code 2025-06-09 17:37:12 +08:00
Sam Chin
916c93e276 now with SI units 2025-06-09 17:37:12 +08:00
Sam Chin
b35f9cad33 working read 2025-06-09 17:37:12 +08:00
Sam Chin
b0b29f7d78 reestablishing devenv 2025-06-09 17:37:12 +08:00
bunnie
0d0267f0ea scaffolding the i2cdetect command 2025-06-09 17:37:12 +08:00
Sam Chin
526d8353fd hello world exercise 2025-06-09 17:37:12 +08:00
bunnie
ea3b032fbe add build flags to bao-console
two flags are added:

with-pddb - puts the PDDB commands into the console
battery-readout - turns on the periodic battery readout
2025-06-09 17:20:46 +08:00
bunnie
d17f9881b2 modify user mode i2c lib calls to return nacks
Note that a NACK is returned as an Ok(I2cResult::Nack) - this is
because the Err() path is still reserved for "OS failure" errors.
A Nack isn't a terminal failure, it is a recoverable fault, and
so it's handled in the Ok() path.
2025-06-07 22:56:51 +08:00
bunnie
63c1d975b4 modify result interpretation to allow i2c nacks 2025-06-07 22:56:29 +08:00
bunnie
76a45ff47d add code to the server
this is the actual handler inside the Xous service which, when
receiving the opcode, dereferences its exclusive pointer to the
IRQ bank and then returns the result to the caller.
2025-06-07 02:48:58 +08:00
bunnie
f3e7eec6cf add 'lib' side code for sending the API call to cramium_hal_service
this is the code that exists on the caller's side. It creates
a message with the correct opcode and decodes the result.
2025-06-07 02:48:10 +08:00
bunnie
cfe9b3c845 modify base API for GlobalConfig to auto-infer the API address
the switch based on target is now absorbed into the new() function.
This paves the way for us to add more CSR ranges into the global
configuration object, i.e. IRQ csrs for I2C.
2025-06-07 01:52:25 +08:00
bunnie
6741cba3bd fix hosted mode config issue 2025-05-23 13:18:04 +08:00
bunnie
eb379e22ba figured out my "mystery problem"
I had a feature override in the shell script I was using to wrap
the build. :-/ oops
2025-05-23 13:04:31 +08:00
bunnie
dbdc157ccf cleanup unrelated warning that crept in due to Rust version change 2025-05-23 10:56:43 +08:00
bunnie
d12bdf1494 fix the case of trying to retrieve shell history when none exists
fortunately rust handles this with a panic because it has strict
bounds checking, so this cleans up that panic.
2025-05-23 10:55:38 +08:00
bunnie
73fba43d04 fix emulation mode for baochip target after bringing up metal 2025-05-22 23:48:28 +08:00
bunnie
942a64ea3b fix saturation bug in index computation code 2025-05-21 18:22:30 +08:00
bunnie
f6aa07c20f add domain separator for gen2 keys 2025-05-21 18:22:12 +08:00
bunnie
4526e04abc cleanup some debug output in xous-swapper 2025-05-21 18:21:41 +08:00
bunnie
938f808a8a revert debug flag 2025-05-21 18:05:57 +08:00
bunnie
3004c4ab7f work around a weird feature flag not behaving as we expect 2025-05-21 18:04:02 +08:00
bunnie
8c7edaf107 add a "fake" implementation for the keystore
allows us to test pddb crate before final hardware arrives
2025-05-21 18:03:08 +08:00
bunnie
183916b548 first attempt at layering in a real SPI HAL into PDDB for gen2 targets 2025-05-21 10:23:51 +08:00
bunnie
fe190ea4f1 cleanup warning 2025-05-21 10:23:37 +08:00
bunnie
b63371a56f turn off autotest for now 2025-05-21 10:23:15 +08:00
bunnie
dd5e19878c update flash test routine to remove write flag request 2025-05-21 10:22:27 +08:00
bunnie
1810825744 add block erase routine 2025-05-21 10:20:23 +08:00
bunnie
6c9edc26a3 cleanup some of the HAL dependencies in PDDB
still have some...mysterious...problems around feature
flags that aren't being invoked when i think they should be.

but let's commit this checkpoint because I suspect I may need to
roll back to here several times and I try to figure out the
root cause of the issues.
2025-05-20 14:39:47 +08:00
bunnie
821c6ce47c cleanup dependency tree going down to the cramium-hal layer
remove features that we don't need so as to make the tree as
simple as possible to descend

in particular if we're just pinging the HAL layer for some simple
constants we don't have to pull in the hairball of std targets
2025-05-20 14:38:03 +08:00
bunnie
5d288ec9a8 cleanup dependencies to allow for hosted builds 2025-05-18 09:25:33 +08:00
bunnie
4251686c1f make the flash test optional based on the configuration
allow the console to be built for hosted targets
2025-05-18 09:25:01 +08:00
bunnie
9b13f46741 cleanup notes in toml file so i don't forget to toggle a loader flag 2025-05-18 04:41:21 +08:00
bunnie
de06522499 cleanup debug statement 2025-05-18 04:40:38 +08:00
bunnie
1a34847b19 implement the writepage mechanism
1 - lock the CPU
2 - go into userspace to do the write
3 - on exit from userspace, mark the page as swapped in the original
process so that if it tries to read the data it fetches a new clean
copy
4 - free the page from the RPT so the data can be grabbed later
5 - unlock the CPU
2025-05-18 04:30:52 +08:00
bunnie
24a70b0eb5 implement writepage mechanism, deprecate sync/dirty
writepage uses a *direct* memory message (no rkyv) for efficiency
this saves us an extra page spent on the sideband data shuffling
by loading those args directly into the cpu registers that
get shuttled along with a memory message (the now increasingly
misnamed "advisory" fields of length/valid).
2025-05-18 04:29:06 +08:00
bunnie
4c69961448 rework the test program
this uses the new writepage mechanism, and also tests a couple
of cases. not hard edge cases, but enough that we're not just
testing the 0 case.
2025-05-18 04:28:15 +08:00
bunnie
0bf3366911 attempted cleanup on the sync api to improve the race condition
unfortunately this doesn't get us all the way there. There
is always a chance that the call that marks a page as dirty
is not coupled closely enough to the actual update of the page
data. Without actual hardware support for this we can't use this
approach.
2025-05-17 16:28:57 +08:00
bunnie
7cad369a82 test cases for flash writing on real hardware
reading works fine

writing is still a work in progress.
2025-05-17 16:28:24 +08:00
bunnie
5db2b3449e remove unused "spinor" implementation now that access is delegated to swapper
the explicity "spinor" interface is no longer needed (or even
compatible!) because we now have the swap-mapped spinor layer

the main concern I have at this point is there is a potential race
condition between marking a page as dirty and when the data is actually
updated on the page. Some locking might be necessary to fix this,
but possibly it might be sufficient just to mark a page as dirty
immediately before it's written?

another option might be to handle the writes in an interrupt context
so that the write data + dirty mark are atomic. Need to think about
this a bit.
2025-05-16 19:16:20 +08:00
bunnie
432c2a528e implement dealloc dirty and write to flash
These routines provide for two types of behaviors:

1. deallocating dirty pages. Here, pages are unmapped from RAM
after they are committed to FLASH.

2. write dirty pages to flash. Here, pages are kept mapped in RAM
for future use, but the dirty bit is cleared. This allows the
pages to be quickly released in case of memory pressure.
2025-05-16 19:07:07 +08:00
bunnie
5e2472fa7f add dummy routines so code compiles for precursor target 2025-05-16 19:06:40 +08:00
bunnie
c68d8b1a77 prelim take at a HAL for cramium targets for flash read/write 2025-05-16 19:06:17 +08:00
bunnie
22a72125bd add precursor-hal to dependencies for xous-swapper 2025-05-16 19:05:52 +08:00
bunnie
7533e09f70 move swap abi into lib section; add syscall wrappers for dirty/sync 2025-05-16 19:05:09 +08:00
bunnie
3f96f876c7 more renode tests for flash access 2025-05-16 19:04:30 +08:00
bunnie
e47ed41726 add some prelim test routines for flash access 2025-05-16 19:04:12 +08:00
bunnie
230c577af0 update progress 2025-05-15 11:58:44 +08:00
bunnie
e34dbb4e6f implement a demonstration of successful map decoding of the spi flash request
this just puts dummy data in, next set of commits will do "live"
ROM access.
2025-05-15 11:58:03 +08:00
bunnie
148679af42 more constants location cleanup 2025-05-15 11:56:51 +08:00
bunnie
409e381c2d fix some bit-rotted constants in xous-swapper debug 2025-05-15 11:56:28 +08:00
bunnie
b962bfe26d add some test code for spi flash mapping
this is just to facilitate renode-based testing
2025-05-15 11:55:25 +08:00
bunnie
e2379821e6 republish xous-rs to fix cargo test 2025-05-11 15:36:17 +08:00
bunnie
8a4959056b bump version for xous crate update - commit so we can publish crates 2025-05-11 14:45:24 +08:00
bunnie
ed345ba4d7 cleanup dependency hacks from debbuging pddb issue 2025-05-11 14:42:26 +08:00
bunnie
f76dd23067 fix weird PDDB dependency issue
more of a work-around than anything else. the observation is
the PDDB_A* series of constants aren't used outide of the crate
for gen2-targets and so we just remove it as a dependency in
the lib.rs side of things.

This clears up the cargo error we're getting. still don't know
why the dependency tree is not working for that particular target,
but someone is pulling a pddb dependency and it's not obvious who.
2025-05-11 14:40:19 +08:00
bunnie
fbcb59c69e migrations applied to pddb
still broken, there is a weird dependency problem on
board-baosec target that is still to be debugged, but
wanted to get everything committed so i can try bigger
experiments without losing state
2025-05-11 12:59:00 +08:00
bunnie
52ee66e1a5 migrate kernel-to-board platform constants for swapper 2025-05-11 12:46:01 +08:00
bunnie
805ebd22a3 revert a couple things that were not meant to be committed 2025-05-11 12:45:29 +08:00
bunnie
4ef4b22cfc incorporate hal migration into bao-console 2025-05-11 12:41:39 +08:00
bunnie
ca04a3ea82 incorporate arch migrations into early-settings 2025-05-11 12:37:51 +08:00
bunnie
ee6fb3ef4f arch migrations make PDDB_LEN harder to reach in modals
this constant was just used to create a "realistic" test case
instead of trying to add the dependency we just hard-code the
constant into the test case, because in the end what we wanted
was that specific constant to test a specific edge case of
a progress bar.
2025-05-11 12:36:46 +08:00
bunnie
42c6417e46 incorporate rach mirgations into net 2025-05-11 12:36:33 +08:00
bunnie
6de085657a incorporate arch migrations into dns 2025-05-11 12:36:20 +08:00
bunnie
a71873cb7a incorporate migrations into root-keys 2025-05-11 12:34:17 +08:00
bunnie
b6ab55c6b8 incorporate arch migration into shellchat 2025-05-11 12:33:50 +08:00
bunnie
8a74ed6078 incorporate arch migrations into spinor 2025-05-11 12:32:29 +08:00
bunnie
ee22ff783c incorporate arch migrations to status 2025-05-11 12:32:05 +08:00
bunnie
a0c1b1e75a incorporate arch migrations to usb-device-xous 2025-05-11 12:31:46 +08:00
bunnie
ae2d137e12 incorporate arch migrations to xous-susres 2025-05-11 12:29:55 +08:00
bunnie
58f20057b4 update strategy 2025-05-10 08:22:38 +08:00
bunnie
c7225d227d migrate pddb size to board:: and fix boot init
the policy is to format the PDDB automatically on boot if
it can't be mounted.

Need to think about whether this is the right thing to do
or not for the product: if there is any sort of error, it will
just wipe the PDDB entirely, making it unrecoverable.

That being said, why would there be an error? if that happens,
something bad probably happened to the hardware. I feel like
if the SPI interface is reliable this shouldn't be a problem.
So the solution is to make sure the hardware is reliable...
on the other hand, fundamentally, SPI flash can wear out, so
this could aggravate problems at EOL for the device (i.e.
it will take small problems and "amplify them up" into a huge
problem).

The trade-off is...the auto-format makes the token "just work"
on boot. Maybe the right thing to do is to add some code that
checks to see if we're in a true blank state, and if so,
autoformat; and if it looks like something was there before,
prompt for a format?

tbd.
2025-05-08 16:06:42 +08:00
bunnie
f92839602e feature flag fixes for moving sizes to board:: 2025-05-08 16:04:36 +08:00
bunnie
fe599c2fe0 migrate lengths to board:: for gen2; fix opcode numbering bug
opcode numbering bug only affects test mode, fortunately. just
bit-rot from tests long not run...
2025-05-08 16:03:48 +08:00
bunnie
2ea777e04f fix key encoding bug; set DNA to "0" in emulation mode
this matches what's done in hosted mode, allowing the analysis
scripts to work on the images generated by this version
2025-05-08 16:02:52 +08:00
bunnie
34a1a33165 fix off-by-one arg error on Dna routine
this is a common api problem because yes, while arg1 is strictly
the second item, previously arg0 was hidden and in the argument
list arg1 took the first place not the second. so i make this
mistake a lot...
2025-05-08 16:01:46 +08:00
bunnie
0cb80c2afb remove sizes from the emu lib, so it can live in board:: 2025-05-08 16:01:11 +08:00
bunnie
5417c2bd87 add more test features to the console; absorb board:: api for sizes 2025-05-08 16:00:28 +08:00
bunnie
399742a3d4 feature-out some battery testing code in hosted mode 2025-05-07 23:10:04 +08:00
bunnie
231aff1f80
Merge pull request #641 from betrusted-io/axp-batt
Battery settings to confirm/test prior to fusing out TG28
2025-05-06 19:14:43 +08:00
bunnie
a2d9699bee fix argument change in api 2025-05-06 19:06:23 +08:00
bunnie
c5d2689e12 add periodic updates from the charger 2025-05-06 19:06:04 +08:00
bunnie
1a3b9131d1 reduce debug out put as this makes it hard to see what's going on in CI 2025-05-06 12:54:34 +08:00
bunnie
ef97e33ae4 fix pddb in doc-deps target 2025-05-06 03:15:51 +08:00
bunnie
4640213410 fix hosted mode 2025-05-06 03:06:21 +08:00
bunnie
89d6b0e81f debug checkpoint
left off at trying to debug the PDDB mount process.
2025-05-06 02:07:31 +08:00
bunnie
15dd0a7f17 cleanup warnings 2025-05-06 02:07:16 +08:00
bunnie
feeaa6341c improve bao-console interaction and add pddb mount call 2025-05-06 02:06:41 +08:00
bunnie
8e161d7e9d we're at least booting now and talking to the pddb service 2025-05-06 01:51:29 +08:00
bunnie
a4e86eead5 cleanup some gen1/gen2 differences 2025-05-06 01:49:42 +08:00
bunnie
095939ee53 allow multiple listeners in gen2 targets
this simplifies a bunch of stuff when we can trust the internal
code base
2025-05-06 01:48:37 +08:00