Commit graph

7935 commits

Author SHA1 Message Date
bunnie
4f21bf3c3e raw pointer dance for memory allocations and extra allocations
this is probably the most significant source of consternation but
also this code path has been fairly well-trodden.

That being said it might be worth considering if there is any
way to use some of the new Rust const based reasoning logic
to see if we can't tighten this up someday, but today is not
that day.
2024-12-02 19:10:39 +08:00
bunnie
b59177176b raw pointer dance for the SWITCHTO_CALLER 2024-12-02 19:06:25 +08:00
bunnie
8876f6e7f5 raw pointer dance for IRQ handlers 2024-12-02 19:05:56 +08:00
bunnie
9662f13d31 raw pointer dance for kernel TRNG 2024-12-02 19:05:24 +08:00
bunnie
64612352d3 raw pointer dance for debug UART 2024-12-02 19:04:37 +08:00
bunnie
95611d9598 This begins a series of commits to cleanup a static_mut warning
So in Rust 1.83, we now get a strongly worded warning telling
us to really, really don't use static muts. They aren't wrong,
except that in some places like the kernel we have few options:
we are conjuring pointers out of thin air, creating memory mappings,
and then doing things with them that are hard for the compiler
to reason about.

I think the newly minted warning was made because the intention
is that we could use the new fancy `const` semantics to take
the place of static mut usage by wrapping things in UnsafeCell,
and I think maaaaybe in some
cases this could apply here, but as a simple example a dive
into the kernel debug UART indicates that to initialize the
shared variable we have to allocate pages in the page table,
which involves calling the memory manager and doing some
decidedly non-const type of things. So one option is we could
just push the debug UART initialization into the loader and
paper over the whole thing by pretending it's static.

Instead of that, we adopt a pattern of casting all our static
muts to a raw pointer, and then back into what we want. The
cast to raw pointer is like an "uber unsafe" marker that says
"no we really mean that this pointer is where it is and we
conjured it out of thin air and we promise that the behavior
is defined and values are representable, etc.".

In general we're fairly judicious about the use of static
mut in the kernel, and when in the kernel there's no thread
pre-emption (although we could take an interrupt or page
fault) so generally we are single-threaded. The trickiest
spots are when we have to take a page fault while handling
a page fault (for example, allocating a new L1 page table
entry would require something like this) but this code path
is fairly carefully vetted.

So instead of just doing a global lint silence, we use an
`&raw` idiom to call out the fact that we're doing something
naughty wherever we do it, which makes the compiler "happy"
(for now) while still making the code ugly enough that it
looks sufficiently scary and you have to apply some
cognitive burden to even reason about what's going on,
which I *think* is the intention of Rust in this case.

Basically you get a get out of jail free card but you can't
simply wear it on a lanyard and pass through the gate -- every
time we need to use it, we have to do a little dance and
wash ourselves in the waters of unsafety and recite the
mantras about defined behavior, representable numbers, thread
safety, etc.
2024-12-02 18:55:18 +08:00
bunnie
2ace34abee cleanup static mut warning in hosted mode 2024-12-02 18:54:44 +08:00
bunnie
e4e6db8bc9 fix implicit lifetime warning 2024-12-02 18:54:26 +08:00
bunnie
83e26ff4c7 update num-derive dependency
this became mandatory in 1.83 to remove warnings. I think it
should have no impact on functionality.
2024-12-02 18:52:59 +08:00
bunnie
4cf9c96f7a
Merge pull request #597 from betrusted-io/cram-dev
more cleanup for cram dev target
2024-12-02 02:54:18 +08:00
bunnie
33f3e2fed8 pull in the actually corrected iox block 2024-12-02 02:50:31 +08:00
bunnie
678bb5c1f1 update lockfile and top-level toml file to remove pio refs 2024-12-02 01:22:30 +08:00
bunnie
41078a71fe feature-out the quantum time 2024-12-02 01:22:18 +08:00
bunnie
147cfb8c97 remove xous-pio references in cargo files 2024-12-02 01:21:57 +08:00
bunnie
c9865e11c2 remove pio dep from loader 2024-12-02 01:01:22 +08:00
bunnie
00744cf61a remove quantum-timer feature to simplify builds
we don't have pio block on nto; let's avoid maintaining two
versions of the code base for a non-essential feature (the
downside of not having this is that the system could end
up locking up if no processes call yield_slice(), but in
practice this happens often enough that we can get away with
it -- at least at this stage).
2024-12-02 01:00:02 +08:00
bunnie
5bbf7cc1ba update soc.svd to nto-compliant version 2024-12-02 00:59:40 +08:00
bunnie
189611f3c4 add updates, verilator-only, and simulation-only feature gates
- updates enables or disables updates in the loader
- verilator-only will turn off routines that access hardware not
present in verilator (e.g. leads to a bus lockup)
- simulation-only turns of features that take a long amount of time
and aren't necessary in simulation, such as bulk clearing of
all RAM - in simulation, we can configure the simulator to do this
for us prior to boot; but in HW, of course, RAM is just random,
or worse, has the previous session's secrets in it.
2024-11-30 02:27:35 +08:00
bunnie
1710fb7ee2 cleanup the cramium hw implementation feature flags
this re-oragnizes the feature matrix of the loader to
reflect the chip/board division of feature flags better.
2024-11-30 02:26:56 +08:00
bunnie
43988bde05 cleanup warning on a debug routine
this is not used under certain combinations of e.g. printing
and swap
2024-11-30 02:25:58 +08:00
bunnie
b85b9d2dc2 improve assert message 2024-11-30 02:25:40 +08:00
bunnie
d3eda68b42 move features from cramium-soc into specific boards
cramium-soc is moving closer to the platonic SoC specifier,
and the board-* features are for the specific boards that use
cramium-soc

This division of feature flags feels a lot nicer and cleaner -
if it holds up to further development, I think this style might
become the new standard for Xous (as opposed to a single level
of feature flag where both SoC and board target are conflated in
terms of meaning - which kind of made sense when the CPU was
an FPGA and could actually have different features for different
boards, but for ASICs this wouldn't happen).
2024-11-30 02:23:35 +08:00
bunnie
a527b3a300 gate RAM clearing behind not(simulation-only) feature flag
RAM clearing takes a lot of time in simulation and is not necessary,
hence the feature gate option.
2024-11-30 02:22:47 +08:00
bunnie
c72607e0bf expand feature flags to be more specific to board types 2024-11-30 02:22:24 +08:00
bunnie
bee7be762f pass the verilator-only flag on to the cramium-hal dependency in kernel 2024-11-30 02:22:01 +08:00
bunnie
6961bb3e54 fix a bug in debug-print when swap is not specified
a field doesn't exist that is accesed by a debug-print resource
in the case of swap being inactivated
2024-11-30 02:21:20 +08:00
bunnie
20b0ecd592 add verilator-only modifications to the HAL
verilator doesn't implement the TRNG, so the TRNG is bodged.
A warning is left in to help remind us/alert us if the bodge
is accidentally put into production.

the 'dabao' board type is introduced, which is the breakout board
codename.

camera and display are feature-gated behind their respective board
definitions.
2024-11-30 02:19:55 +08:00
bunnie
56bd0decc9 add loader-feature flag; simplify cramium-soc target
the `cramium-soc` target is now the simulation target (just
the bare bones chip in a simulation harness, using the `dabao`
board configuration which is basically just a breakout board).
baosec continues to be the prototype for the first USB dongle
coming out.
2024-11-30 02:18:31 +08:00
bunnie
dbbd3d11a1 remove coreuser compression from the CPU
NTO can interpret the nearly full-width ASID (lower 8 bits)
as the lock target for key material, so no need to compress it
down to 1 bits anymore.
2024-11-30 02:17:35 +08:00
bunnie
cfc1114671
Merge pull request #596 from betrusted-io/cram-dev
merge dev mods to avoid branch divergence
2024-11-28 18:35:52 +08:00
bunnie
2dddae34fc add udma stresstest feature 2024-11-28 18:27:52 +08:00
bunnie
ffb00cf6ad turns out it helps if you put explicit pull-ups on the I/Os
reverting this change
2024-11-28 16:14:14 +08:00
bunnie
a3619618d0 slow down toggle rate on i2c so it is compatible with slow pullups
the strict verilog model has weak pull-ups which model the
"slowness" of the rise with an extended Z-condition that takes
3us to pull up to a solid 1.
2024-11-28 15:53:12 +08:00
bunnie
861b7ae3ff compromise on oscillator setting
I felt uncomfortable leaving the oscillator setting entirely
outside the PLL routine, so as a compromise I defer the oscillator
switch-over until after the initial PLL settings are loaded.

This makes both the simulation model and the actual hardware
happy. I think probably what the simulation model *should* have
done is consider the "powerdown" pin when checking the validity
of the signals going into the PLL model - but this is impossible
to modify/check because the PLL is provided as an encrypted blob :(
2024-11-28 15:32:19 +08:00
bunnie
6e8bff749c eliminate invalid PLL transition
this transition was in the reference C code, but in verilog simulation
it turns out it activates the PLL in an invalid mode which can lead
to glitching. Removing this makes both the simulation happy and
presumably the PLL happier as well.
2024-11-28 15:07:43 +08:00
bunnie
3738db9f5c fix io-direction issue in testbench 2024-11-28 01:28:39 +08:00
bunnie
13702f2df0 fix unit test to match actual testbench tooling 2024-11-22 15:23:38 +08:00
bunnie
c1564d2ca1
Merge pull request #595 from betrusted-io/usb-integrate
Usb integrate
2024-11-22 00:58:25 +08:00
bunnie
ec3d8b5042 handle swap image burning 2024-11-22 00:55:29 +08:00
bunnie
83dbb82500 add routines for programming SPI flash 2024-11-22 00:55:15 +08:00
bunnie
a7619e55a8 add progress bar to burn 2024-11-21 22:03:06 +08:00
bunnie
b944c51474 a simple update with verified image now working 2024-11-21 18:23:55 +08:00
bunnie
faa8a60843 add ref to mbox module 2024-11-21 18:23:36 +08:00
bunnie
ba87422903 add platform code for mailbox to CM7 2024-11-21 18:23:20 +08:00
bunnie
607d784eae cleanup lockfile after loader dependency fixes 2024-11-21 02:22:58 +08:00
bunnie
89fb9b4df6 add reference to the presign module 2024-11-21 02:22:39 +08:00
bunnie
30cb5f84f7 make more space in the cramium loader
need code space to handle image verification.

getting kind of heavy, but I think we're almost done.
2024-11-21 02:22:08 +08:00
bunnie
2437712b7b add some basic image integrity checking code
this doesn't protect against malicious tampering (because
the public key is the developer key) but it will at least
catch correctness errors in USB upload and filesystem
behavior.
2024-11-21 02:20:40 +08:00
bunnie
8aa633641f add new dependencies for image checking in loader 2024-11-21 02:20:10 +08:00
bunnie
3bf8598509 make slice cursor peekable 2024-11-21 02:19:45 +08:00