Commit graph

663 commits

Author SHA1 Message Date
bunnie
1f148a6136 update readme 2024-10-10 02:10:10 +08:00
bunnie
e806421141 add camera test to loader
this loops an image from the camera to the oled display in real time.
it will also dump the Y (luminance) data to to a serial port for
offline development & testing of the QR code algorithm.
2024-10-10 02:05:40 +08:00
bunnie
70de9c707d cleanup bootlogo routine 2024-10-10 02:05:18 +08:00
bunnie
4e6c2706c9 employ the axp2101 driver to setup the voltages 2024-10-07 22:53:10 +08:00
bunnie
b87c9f7672 add I2C tests & code for setting the LDO initial value 2024-10-06 02:45:18 +08:00
bunnie
d7af82261e did *not* mean to commit the font-out hack
this is just to make cycle times faster during debug only
2024-10-04 22:53:00 +08:00
bunnie
9867a3e488 cleanup loader path to use dynamically derived perclk 2024-10-04 22:52:25 +08:00
bunnie
9527dcfbaf move sh1107 to platform-independent lib 2024-10-04 13:07:59 +08:00
bunnie
6fedae8e73 implement logo drawing for oled 2024-10-04 13:07:34 +08:00
bunnie
b572db3f3f update boot logo to a 128x128 suitable black/white test image 2024-10-04 13:07:00 +08:00
bunnie
18c4413ae9 update udma_global api in bootloader swap 2024-10-04 13:06:28 +08:00
bunnie
843d928126 update manifests to point to board descriptions 2024-10-04 13:05:59 +08:00
bunnie
c44f117331 fixes to udma SPIM for tx-only mode
- fix tx_await() condition to consider both control and tx channels
- make tx_async more efficient for the common case that the buffer
fits in a single transaction by appending the CS de-assert as part
of the initial command stream
- make trait for the udma global clock setting

The high bit in this exploration is that there seems to be no
way to actually confirm when a UDMA transaction has fully completed
on the hardware interface. All the completion signals tell you
when the software-side UDMA resources are freed up. However, in this
case, the hardware-side resources may still be transmitting/receiving
data.

This is a problem for the case of a '4-wire SPI' display where you
need to set an extra line to control command/data mode addressing.

In this case, the current work-around is to read back the state of
the chip select pin as a GPIO to determine when the hardware has
finished.

I suspect that if we can figure out how to use UDMA in a full duplex
mode that we could do something more essentially linked to the
hardware, but this would also require having a dummy Rx buffer allocated
that is the same depth as the hardware Tx buffer if all you cared about
is the hardware conclusion of a Tx.
2024-10-04 12:53:55 +08:00
bunnie
b2f81666d0 fix formatting 2024-10-02 01:47:51 +08:00
bunnie
1eb1a1a671 migrate loader board parameters to board files 2024-10-02 01:44:57 +08:00
bunnie
2e086f4152 consolidate spi pin setup 2024-10-02 00:23:48 +08:00
bunnie
0733b65ead firmware updater strategy and thoughts jotted into a file 2024-10-01 23:19:14 +08:00
bunnie
cddd971aa9 remap to the setup_pin() trait
this is an intermediate step on the way to moving these all into
a common area for board definitions
2024-10-01 23:18:31 +08:00
bunnie
482b815f44 convert to using the new setup_pin trait 2024-10-01 23:17:36 +08:00
bunnie
a66cd1c077 add modules from previous commit 2024-10-01 23:16:57 +08:00
bunnie
59b15541f3 add stubs for lifecycle management and update checking in loader
this is just a reminder to me on how i was planning to implement
this after going through a big side-quest to change other things.
2024-10-01 23:15:54 +08:00
bunnie
19741d3615 add new flash IDs to swap routine as well 2024-10-01 14:40:36 +08:00
bunnie
cb466c24a3 recognize more flash chip types
1. System works with 1.8V VDD I/O now, needs a new chip ID for
flash

2. Add direct c-translated version of init_clock_asic() for reference
testing.
2024-10-01 14:39:40 +08:00
bunnie
043dfd84ae update formatting to latest nightly rules 2024-09-24 01:49:45 +08:00
bunnie
75954de8d6 commit the version bump 2024-09-23 01:46:25 +08:00
bunnie
423bfe93ea clean up a warning in loader crate
minor cleanup because the warning is distracting from chasing
down all the other warnings
2024-09-22 11:34:59 +08:00
bunnie
89f92c28a2
Merge branch 'main' into nto-work 2024-08-19 02:30:35 +08:00
bunnie
6eab1c48bb patches to clean up warnings in rust-1.80 2024-08-19 02:24:24 +08:00
bunnie
4884ee51d9 reserve the top-most word of RAM as a "gutter" for filtered DMA
it's much easier to gutter a blocked AXI transaction, than to
squash it. So we reserve a region of memory as a gutter for blocked
transactions.
2024-08-02 17:26:24 +08:00
bunnie
8015b16cb8 clock tests 2024-07-19 17:16:02 +08:00
bunnie
9c227d2a93 beginning of clock tests 2024-07-13 22:45:58 +08:00
bunnie
30eb2f145f fix a bug where the last seeded value was not being used.
Realized that the last round of mixed values wasn't actually being
used because we nuke the `seed` value at the top of the loop.

We effectively had a round of ChaCha8 that we were doing but then
throwing away.

This construction should capture all the benefit of the computation
without wasting computation.
2024-06-22 21:18:59 +08:00
bunnie
d75624cfe4 reduce fclk on target, reoragnize feature flags into groups
Not all chips can hit rated speed, so for bringup we're defaulting
to the slower setting.
2024-06-19 21:33:14 +08:00
bunnie
8838fa6162 add loader test mode for entropy output 2024-06-18 00:08:57 +08:00
bunnie
c6a0f7f629 apply more autoformat. Why did that not trigger on save? 2024-06-16 02:34:46 +08:00
bunnie
8414f08aae autoformat the logo file 2024-06-16 02:10:27 +08:00
bunnie
d40e92b52d add code to dump the TRNG output via the DUART
gotta move on to other things, can't fully debug the USB
serial thing now. :-/
2024-06-16 02:07:33 +08:00
bunnie
28ab6ae311 add a quick-on boot logo in the loader
the swap load can take a little while, so a graphic at power-on
makes the UI feel more smooth
2024-06-16 01:53:45 +08:00
bunnie
975b44f894 improve visibility of setup_port so it can be re-used 2024-06-16 01:53:00 +08:00
bunnie
84fe4c96ff fix seeding algorithm
- use proper seeding of entire state
- chacha8 does not evolve internal state when extracting the seed,
so we have to run the cipher some to force mixing of the seed
state.
2024-06-15 00:37:38 +08:00
bunnie
7743d96e91
Merge branch 'main' into trng-test 2024-06-14 19:17:11 +08:00
bunnie
0fd6ad7c0e
Merge branch 'main' into new-rust-warnings 2024-06-14 19:14:02 +08:00
bunnie
0036c46ea1 clean up warnings in the latest rust 2024-06-14 19:10:18 +08:00
bunnie
eceea1db0b re-introduce the boot delay 2024-06-14 16:08:45 +08:00
bunnie
f91cab4f5d harden swap key generation
trng entropy rate is low, so get a lot of it before using anything
out of the pool.
2024-06-14 16:08:15 +08:00
bunnie
b72a00dd2d restore fonts into loader 2024-06-13 22:04:30 +08:00
bunnie
76fb67dbe6 add global SFR setup for TRNG proper operation inside loader 2024-06-13 15:43:18 +08:00
bunnie
cf99fd99eb trng baseline test code 2024-06-13 00:35:02 +08:00
bunnie
ac7b58b702 trying to back-trace to a working bootloader state 2024-06-10 18:45:44 +08:00
bunnie
99be442d16 working demo of first couple packets in loader 2024-06-09 23:51:30 +08:00
bunnie
971bfea83d more telemetry on boot
also, it seems that some amount of boot setup is necessary
for stability? unsure, this has to be chased out, but later.
2024-06-08 00:52:11 +08:00
bunnie
9f43e1df0a fix edgecase in nocopy section
do not try to decrypt data for sections that are nocopy,
this can lead to spurious decryption errors
2024-06-06 22:19:42 +08:00
bunnie
519ae31485 loader mods to harmonize with driver bounds 2024-06-06 17:55:10 +08:00
bunnie
8ef46fd081 move usb driver to a common location 2024-06-06 03:58:35 +08:00
bunnie
4261e70d3f update usb test 2024-06-05 22:54:27 +08:00
bunnie
65df5b3066 remove uccr structure
the ram-mapped uccr structure does not guarantee synchronization
well enough. go back to UTRA functions. This gets us to the point
of setup packets!
2024-06-05 22:50:48 +08:00
bunnie
545b51e8d3 rote port of C driver into Rust
lots of terrible stuff going on, nothing tested, but we have
a baseline of whatever they put in C directly forced into Rust.

A lot of really naughty things going on with raw pointers in this
driver -- it's going to be a challenge to oxidize.
2024-06-05 02:24:12 +08:00
bunnie
df6528edcf refactor to use structured usb object 2024-06-03 17:04:47 +08:00
bunnie
9673624a4e add usb register model and basic init structs 2024-06-03 17:04:21 +08:00
bunnie
e415fd44e7 start to lay in foundations for USB integration 2024-06-01 13:35:31 +08:00
bunnie
5f42ee6ecf move PFD into happy zone
apparently we were not running it in its recommended band before.
2024-05-31 22:34:28 +08:00
bunnie
968440ec7e add stand-alone IRQ testing to the loader environment
The loader bringup now has some IRQ testing built into it.
Couldn't actually get an IRQ to trigger, but it has to do something
more with me not getting the RV IRQ machine bits configured right
than anything else. However, the stub is useful for confirming
which IRQ bits actually fire on the UDMA UART implementation,
which is the big point. There's an ambiguity in the wiring
of the UDMA block which isn't explained at all, which is the
fact that there's an RX interrupt and an RX_CHAR interrupt.

I still don't know what RX_CHAR does, but the RX interrupt
does fire when a character is received, so that's the one
we're going to use.
2024-05-31 03:36:08 +08:00
bunnie
8d0a1f2ae6 reminder to self about some tech debt 2024-05-24 23:57:47 +08:00
bunnie
3fd383a7aa approximate cram target better in precursor staging environment 2024-05-23 16:51:20 +08:00
bunnie
aa8d84f007 print a message if memory reads timeout 2024-05-23 14:48:11 +08:00
bunnie
818372a604 report timeouts during the SPIM test in the loader 2024-05-22 18:10:32 +08:00
bunnie
e705dba13f quite down swap debug in loader 2024-05-21 17:57:41 +08:00
bunnie
32a9413f34 cleanup warnings when debug-print is off 2024-05-21 17:57:24 +08:00
bunnie
bae408b466 fix app_uart default memory mapping
was pointing to the wrong uart initially >_<
2024-05-21 16:33:11 +08:00
bunnie
71d7a2a3ae update api in test routine 2024-05-21 16:33:03 +08:00
bunnie
2e1ad6e1a4 remove T:Copy bounds on bzero
not quite sure why it is even there, might just be a thing from
really old code we never removed. Removing this allows us to
specify pointer types to non-copy elements, making Rust do
the hard work of figuring out how big of a block we need to zero.
2024-05-21 16:02:59 +08:00
bunnie
0153b3b96e allow guard memory to be differentiated across platforms 2024-05-21 16:00:56 +08:00
bunnie
8b487361b2 clean up bzero
some errors were made in clearing memory because we weren't
using the Rust type system to our advantage. This cleans up
the phase 1 loader to use the native types of the block plus
the slice length we intend to create to block-zero the correct
region size.

also simplify mem::size_of to size_of
2024-05-21 15:58:10 +08:00
bunnie
a57945e2c0 add helper to extract vaddr prefixes (used by swapper to fliter candidates) 2024-05-21 03:46:29 +08:00
bunnie
b7becf27e7 quiet down warnings when debug-print is off
because the print! macro becomes a dummy when debug printing is
off, we get a bunch of warnings about unused variables because
the print! arguments aren't used. Add _ before variable names
to quiet these warnings.
2024-05-21 01:52:30 +08:00
bunnie
75e938680d fix page table explanation to match reality better 2024-05-21 01:03:19 +08:00
bunnie
37109b19a8 fix ordering of the SwapAlloc for BinaryHeap impl 2024-05-16 03:52:22 +08:00
bunnie
e75f6d80db tone down some debug output 2024-05-16 03:51:59 +08:00
bunnie
03515934df clarify function of the thread context area 2024-05-16 03:51:38 +08:00
bunnie
6d01e69faf fix debug formatting 2024-05-16 03:51:03 +08:00
bunnie
ef5388a30e ensure that process descriptors aren't swapped out 2024-05-15 02:38:24 +08:00
bunnie
f66debdd01 make susres page ownership not hard coded; mark PTs as wired
also marks the ProcessImpl page as wired too
2024-05-15 02:31:40 +08:00
bunnie
b138f63f93 fix swapalloc ordering
we want a max-heap, because pops are cheaper on the sorted vec.
2024-05-13 19:19:15 +08:00
bunnie
a94dce11f7 add loader support for rpt tracking/mapping
trying to condense most of the RPT API into the loader so
that the userspace can use a single dependency for this.

We can't condense the kernel API into the loader unfortunately,
because the kernel actually uses a different type for representing
a process. This is probably a mistake, and is something that
may be fixed later so we can merge the representations.
2024-05-13 14:03:00 +08:00
bunnie
8606d0ae83 add some more tracking to the loader
this will give us some more pages to swap out beyond the initial
set of free pages.
2024-05-12 22:29:50 +08:00
bunnie
6bef111bf2 fix RPT/XPT alloc in swap; make swap resume-compatible 2024-05-12 21:50:53 +08:00
bunnie
903c903b2f split memory allocs into RAM and peripheral tables
RAM allocs can be augmented with more tracking data in the case of
swap.
2024-05-12 20:22:51 +08:00
bunnie
f657caa176 changes to atsama5d27 target for new kernel boot args
@eupn this could use a review, I have no way to test this
2024-05-12 20:22:07 +08:00
bunnie
6080bc45d8 attempt to re-type the runtime page tracker to something we can use for swap
This is too expensive to use generically - we're going to have
to split the RPT, but checking in this change as a checkpoint
2024-05-12 16:27:30 +08:00
bunnie
f6bfddcf20 add swap usage tracking via offset flags and fix bugs in RPT init
also optimize amount of memory used in RPT copy by just tracking
the data that is swappable,i.e. main RAM
2024-05-10 13:32:58 +08:00
bunnie
64071661a5 clarify variable roles 2024-05-10 13:32:19 +08:00
bunnie
95c27c765e refactor loader to use a single function to swap MAC offset in swap
also pre-map some pages to handle offset increment in swapper
2024-05-09 02:08:51 +08:00
bunnie
1523fb6b83 cleanup warning from rust 1.38 2024-05-07 17:07:36 +08:00
bunnie
5ab014e715 cleanup the offsets for decrypt_src_page_at()
We had a "coincidence" before that allowed things to work,
where we had some data line up that we happened to think
was some other header data, so we "fixed" it by
subtracting the offset of the header data.

Actually, it wasn't.

Clarify that decrypt_src_page_at() offsets are relative
to the beginning of encrypted data, and not relative
to the absolute beginning of the disk.

Image creation is now fixed so that stuff lines up to what
this routine expects, and some asserts added to try and
save ourselves in the future as we try to fix other bugs
we discover over time.

loaders are hard.
2024-05-06 18:55:11 +08:00
bunnie
cbcd27c7eb add missing clock commit 2024-05-06 03:59:04 +08:00
bunnie
0f79056ac7 refactor spim divider equation to reflect reality 2024-05-06 03:32:41 +08:00
bunnie
05844c7646 reflect API changes in code 2024-05-06 02:28:11 +08:00
bunnie
f6dd848ef4 this wasn't supposed to be checked in 2024-05-06 02:25:49 +08:00
bunnie
10d613b95d add some tests for the SPIM memory interface 2024-05-05 21:51:48 +08:00
bunnie
8ceaa1afe4 fix page tracking bug on physical swap addresses 2024-05-05 21:51:17 +08:00
bunnie
fe0db3e29a more stack space is needed due to the increased size of the RPT 2024-05-05 21:50:09 +08:00
bunnie
0a3375722b add an experimental routine to try and print the exception vector
this is in the loader and only valid for the cramium-soc target.
2024-05-05 16:30:45 +08:00
bunnie
bb4b01b04b facilitate access for debug access to CSR by adding riscv package 2024-05-05 03:28:13 +08:00
bunnie
64f5531ae6 fix dummy cycle bug on SPIM flash read
bus is running at 50MHz (or less!), so we can use the shortest
dummy cycling
2024-05-05 03:27:01 +08:00
bunnie
82be129df1 fix typo 2024-05-05 03:26:21 +08:00
bunnie
5fa955f507 fix typo, enforce alignment on the RawPage structure
I think i recall somewhere that an alignment of 16 is required
for certain structures in Rust for the RV32 target; since anything
could be put in there, let's enforce that.
2024-05-05 03:25:08 +08:00
bunnie
7ebfdf3ecd shorten boot wait 2024-05-05 03:24:50 +08:00
bunnie
62d16bb77f fix minor bugs 2024-05-04 22:07:16 +08:00
bunnie
dbd33ad220 don't commit the redacted fonts section
this is just for very early bringup to reduce blob size
and improve cycle time for experimentation.
2024-05-04 21:45:03 +08:00
bunnie
829ac28072 fixes for cramium target 2024-05-04 21:41:38 +08:00
bunnie
a6a3d29836 more warning cleanup, moving around app_uart visbility part 2 2024-05-04 01:46:05 +08:00
bunnie
721129781a cleanup some warnings 2024-05-04 01:45:36 +08:00
bunnie
0b63979614 fix visibility of app uart for cramium config 2024-05-04 01:45:10 +08:00
bunnie
8f0634845e add more userspace maps for loader-managed swap maps 2024-05-03 18:46:11 +08:00
bunnie
228558a722 add platform specific hw inits & key retrieval
- swap session key has to be stored so we can pass it on to
the kernel to access swap

- setup all PT maps necessary for swapper to be functional
before the swapper is started.

This is to break circular dependencies mapping pages inside the
swapper, especially during boot.

We might also need to statically map the LRU swap count structure,
not sure. We'll burn that bridge when we get there, right now,
let's just get a non count-managed swap even working...
2024-05-03 18:43:57 +08:00
bunnie
ef6a73d329 use the correct session key for swap ram
and also call platform-specific swap init
2024-05-03 18:43:19 +08:00
bunnie
d434e70075 move the IFRAM specifiers to a more public location
The IFRAM allocation used by the loader is now exposed so
we can pick it up and use it in the actual HAL implementation
in usermode.
2024-05-03 16:04:37 +08:00
bunnie
c8d4123ed7 fix the debug printout to walk the virtual addresses in swap PT
The check of mapping sanity happens after the VA mapping, so this
undoes that. I think this is a good idea, because we're also
checking the PA->VA mapping of the PTEs as well now.
2024-05-03 16:03:14 +08:00
bunnie
be98a88a75 patch PTEs mapped to swapper with virtual addresses
The addresses put into the swapper's page table are physical
addresses, which are unusable by the swapper itself. This
patches the PTEs with the repsective virtual address, so we
don't have to do a PT walk inside the swapper when handling
a swap event.

Also fix an off-by-one on the processes count. This is sort of
an old architectural bug in the loader that would be nice to fix
someday.
2024-05-03 16:01:25 +08:00
bunnie
b4d1b4e5bb add swap lib interface to loader
for use by the swapper
2024-05-02 22:15:32 +08:00
bunnie
67685db741 create the SwapSpec structure and mappings 2024-05-02 22:14:58 +08:00
bunnie
cd43157d1e refactor loader mac accessor interfaces
traits are kind of awful in Rust...it's true, they don't
know how big they are at compile time, so they have to be dyn,
reference, lifetimes, etc...

lot of baggage for a static structure. I guess there's probably
some idk bounds I could put on the traits to make it less poopy
but also just as easy to make it a static structure and not deal
with traits.
2024-05-02 22:13:11 +08:00
bunnie
51dd3b897b map arguments and rpt into loader memory space
this allows us to avoid the dance of getting args/values back
on boot through a syscall
2024-05-02 22:12:07 +08:00
bunnie
e201574eb8 put the verification in the right area 2024-04-30 17:47:57 +08:00
bunnie
c68e351bcc incorporate latest changes into the swap init routine 2024-04-30 17:47:36 +08:00
bunnie
7ae34ed717 add features for alt spi channel on bringup 2024-04-30 17:14:22 +08:00
bunnie
1810880723 add SPIM loader bringup code 2024-04-30 17:13:42 +08:00
bunnie
fd9f85ef58 adjust speeds to reflect actual spec 2024-04-30 17:13:21 +08:00
bunnie
4499097c74 add remainder of test code for spim 2024-04-29 04:13:01 +08:00
bunnie
c1b6f479d4 add some test code for SPIM interface 2024-04-29 04:10:54 +08:00
bunnie
31c51a2a7f add spim-test flag for loader 2024-04-29 04:09:53 +08:00
bunnie
506bcdc7b9 add pio tester feature flag 2024-04-29 03:44:46 +08:00
bunnie
0adb20b3d8 add a test stub for the quantum timer in the loader
a little easier to do low level peripheral testing here than in
the kernel
2024-04-29 03:42:34 +08:00
bunnie
4926e61fec cleanup mut warning 2024-04-28 02:57:44 +08:00
bunnie
07c9890919 fix location of kernel; attempt to debug loader 2024-04-28 02:43:11 +08:00
bunnie
c491c63e42 add PLL computation code 2024-04-27 22:24:27 +08:00
bunnie
2702b94c93 include signature block in kernel offset constant 2024-04-26 18:20:14 +08:00
bunnie
d85ff12ca2 rework the kernel offset 2024-04-26 18:19:59 +08:00
bunnie
6c2cb85a44 make sram-margin and boot delay feature flags 2024-04-26 18:16:56 +08:00
bunnie
a781b2e15d start to lay in code rework for booting on real chips 2024-04-26 18:16:12 +08:00
bunnie
05d2f3d6a9 configure boot addresses 2024-04-26 18:15:05 +08:00
bunnie
c407db877e change DUART ports to accommodate jtag breakout 2024-04-22 11:00:06 +08:00
bunnie
73c834d067 start debugging of swap in kernel
switching contexts to bringing up hardware.
2024-04-22 10:58:37 +08:00
bunnie
799d1554ae chore: CI fixes 2024-04-09 18:51:36 +08:00
bunnie
4ace363abc this resolves comments from @xobs' code review 2024-04-09 18:23:09 +08:00
bunnie
336e47eabe remove comment 2024-04-09 15:46:48 +08:00
bunnie
6735312444 add some more asserts & checks; undo kernel load last patch
kernel load last isn't necessary

add some asserts to help sanity check things. In particular,
the kernel mapped memory can't exceed 0xA000 in length, otherwise
it bumps into hard-coded constants in the kernel for where hardware
mapped pages should go (i.e., panic framebuffer, debug UART, etc.)
2024-04-09 15:30:21 +08:00
bunnie
d367c99a1f fix page mapping; allow kernel to load in arg order; swap_root breakout
Page mapping just can't be done during the phase 1 loading, because
we move the loading point by an unpredictable amount which messes
up phase 2. I mean, we could try to predict the amount, but it's easier
if we just stick with the current algorithm instead of trying to
do both at once. Basically, phase 1 must be "no-alloc" entirely
as it copies.

Phase 2 can allocate page table entries, because all the data
is copied to RAM and you know where that starts; and you can start
to append data to the end of that without affecting the loading
points of programs.

Undo a previous patch to force kernel to load last. Turns out
this is legal, it was only problematic because of other bugs.

Also, reflect swap_root in the BootConfig structure and not
in InitialProcess structure.

+ Various other debug fixes
2024-04-09 15:26:38 +08:00
bunnie
8c82d710bb reflect swap offset patches in atamsam5d27 arch 2024-04-09 15:25:59 +08:00
bunnie
8abb126577 break out swap_root & improve debug 2024-04-09 15:25:37 +08:00
bunnie
a66e4f5901 modify stack smash check to detect if non-PID is written
this is more robust, and should work across all architectures.

Note that the reliability of the check is slightly impacted
since we're now checking for a subset of valid numbers, so
the number of bytes checked is doubled.
2024-04-09 15:24:22 +08:00
bunnie
d6e7f7ce16 add debugging and asserts to detect stack smash in loader
In swap configuration, the loader does a lot more: it has
to decrypt full pages of RAM and hold them temporarily;
up to two pages at once, once for the decrypt of the source
swap image, and one for the encrypt to swap memory.

This causes a lot more stack to be used than the original loader.

Add some debugging for this, and an assert based on a heuristic
that the RPT (runtime page tracker) last few entries ought to
be 0. This I think is probably true on most platforms. If this
fails to be true, then, we can probably modify the assert to
fail if any number in the RPT is greater than the number of
processes: this should be true in *all* cases, but a stack smash
is very likely to write something in there that's larger than
the number of allowable processes in the system.
2024-04-09 15:17:49 +08:00
bunnie
630a81b185 we need more stack to decrypt memory in the loader. 2024-04-09 15:17:21 +08:00
bunnie
30202d962c don't build swap_root into the InitialProcess structure
the kernel doesn't use it, so it just ends up being wasted
space.
2024-04-09 15:16:26 +08:00
bunnie
9992d29b40 chore: cleanup warning in non-swap mode 2024-04-09 00:06:18 +08:00
bunnie
d318134bdc fix default flags for swap; add load checking for swap
load checking is aware of all three types of sections, and
can natively call the encrypt/decrypt ops to ensure that
the encrypted swap is set up correctly.
2024-04-09 00:04:47 +08:00
bunnie
62f1ad09f0 ensure that the kernel is loaded last, even after argument extension
The kernel is supposed to be loaded last, but, when we append
arguments that isn't true anymore. This fix makes sure the
kernel is loaded last.
2024-04-09 00:03:48 +08:00
bunnie
dbacbb609b fix argument appending and mutability issues
The argument appending code in copy_args() is truly abominable.
Suspect more latent bugs in there. Definitely some deep technical
debt in this routine, it's basically just a pile of unsafe pointers
jammed together with no checks. This has to do in part with the
underlying implementation of the argument iterators, which
understandably try to do a lot with no allocations, but it's
brittle and does not play nicely with the idea of extending
the argument records.
2024-04-09 00:01:08 +08:00
bunnie
d6a9c85acb extended debugging; make check_load aware of swap 2024-04-08 23:58:19 +08:00
bunnie
bd58d9187e make secboot's stack test adjust to the platform-defined RAM available 2024-04-08 23:56:35 +08:00
bunnie
8811114a9b remove unused alignment feature
we're not passing pages around like I thought I would. svae
the stack space, so in the future if we do stuff with e.g.
suspend/resume we don't have to reserve such a huge
chunk of RAM for boot.
2024-04-08 23:55:40 +08:00
bunnie
1d0f34779a extend debug to print swap bits 2024-04-08 23:55:24 +08:00
bunnie
03c3f61ba3 fixes to encrypt/decrypt routines to adjust offsets etc. 2024-04-08 23:54:36 +08:00
bunnie
36173fde95 adjust ram available size when swap is enabled 2024-04-08 23:54:24 +08:00
bunnie
58ce8a2923 make resume not a default feature in renode
this is compensated for in xtask to put it back into
your usual builds, but it allows us to not have it in the
swap config.
2024-04-08 23:43:45 +08:00
bunnie
cd140769ac add code to map swap page tables into swapper memory space 2024-04-08 12:41:08 +08:00
bunnie
2b5fabb2fd add swap pt routines 2024-04-08 12:40:42 +08:00
bunnie
25cbf0dc67 add swap pt map handling 2024-04-08 12:40:23 +08:00
bunnie
287ad58c8a add the swapper PID as a constant 2024-04-08 12:39:52 +08:00
bunnie
379d4e81c5 cleanup swap top mod now that most of the implementation is done 2024-04-08 12:39:29 +08:00
bunnie
30b5be7a79 remove superfluous import 2024-04-08 12:39:07 +08:00
bunnie
6ce157b20d add swap handling to minielf 2024-04-08 12:38:42 +08:00
bunnie
63a8b51fe9 gate SDBG behind feature flag 2024-04-08 12:38:02 +08:00
bunnie
2ce579b221 phase 1 changes for swap 2024-04-07 22:37:40 +08:00
bunnie
26efde0a71 track address of the decrypt buffer 2024-04-07 22:36:54 +08:00
bunnie
a478af445d fix IniS arg copying. lay down boilerplate for phase 1 copy
the hard part - the core inner loop of the copy -- is still
to be done.
2024-04-07 19:01:09 +08:00
bunnie
8aa20e65f6 match new API for accessing swap 2024-04-07 19:00:18 +08:00
bunnie
bd54417e44 add routines for shuttling encrypted data to/from swap RAM region
RAM is assumed to be off-chip, and thus the data is encrypted
in the region. We also encrypt it in the Precursor case, even
though it's on-chip, because we want to capture this as a test case
in a known working environment.

Also incorporate some routines to generate the per-boot random
key for swap encryption.
2024-04-07 18:58:54 +08:00
bunnie
c07f33a169 track the current free page in swap ram 2024-04-07 18:58:31 +08:00
bunnie
417fa16a22 add rand_chacha as a dependency for the loader
this is needed in the cramium-soc case because the raw TRNG
does not have a whitener, it should not be used directly to
generate keys.
2024-04-07 18:57:23 +08:00
bunnie
f2a8603e55 merge encrypted swap argument structure into kernel arguments 2024-04-07 14:29:25 +08:00
bunnie
999cb320ed add a function to nab the decrypt buffer
HIGHLY unsafe, but saves us a decryption operation as we
interleave between the various states of the loader.
2024-04-07 14:28:31 +08:00
bunnie
35082c4688 add crc handling to loader
for patching the argument structure
2024-04-07 14:28:05 +08:00
bunnie
c53515fc63 coalesce swap hal into boot config object; read initial swap args
this worked, so it validates the encryption/decryption of the swap
at least!
2024-04-07 00:41:18 +08:00
bunnie
f86d63aa41 add tracking for swap-specific data structures in bootconfig 2024-04-07 00:40:33 +08:00
bunnie
c7e1f22cfa fix pointer issue in resolving swap config
also a bunch of latent debug in case we need to muck around again
2024-04-07 00:39:34 +08:00
bunnie
8f94ecaf6c limit AAD to 64 bytes 2024-04-07 00:39:05 +08:00
bunnie
71336ebf3e start to sketch in bits and pieces of the swap HAL
this is far from complete but needed to check in for the
build check to pass
2024-04-06 23:04:03 +08:00
bunnie
4bb7c87646 gate loader todo behind feature flag 2024-04-06 23:01:33 +08:00
bunnie
903b2219db gate loader features behind flag 2024-04-06 23:01:04 +08:00
bunnie
32857a70b0 add platform-dependent drivers for swap
precursor does direct memory mapping
cramium uses a qspi interface
2024-04-06 22:59:43 +08:00
bunnie
dddbc3c163 add aes-gcm-siv dependency to loader 2024-04-06 22:58:20 +08:00
bunnie
8bae95ef72 put placeholders for inis handling, phase 2 2024-04-06 07:47:18 -07:00
bunnie
c354b75d97 put placeholders to handle inis in phase1 2024-04-06 07:47:18 -07:00
bunnie
c37349778e put todo! placeholders for minielf handling of inis 2024-04-06 07:47:18 -07:00
bunnie
cdbd5dc0f4 add structure to differentiate image type
we now have three image types: inie, inif, inis; migrate
away from a simple "xip" flag to something that can differentiate
between all three options.
2024-04-06 07:47:18 -07:00
bunnie
13790fc5e4
remove debug-print from loader
this shouldn't be here in main.
2024-04-05 16:12:11 +08:00
bunnie
fbffd9878f absorb engine25519-as warning fixes 2024-03-25 08:07:26 +08:00
bunnie
7c944fb4db upgrade zeroize to latest API level 2024-02-08 14:02:58 +08:00
bunnie
37d35b8e27 add small memory option for fonts to loader 2024-01-29 03:34:03 +08:00
bunnie
e4b0362024 make space for fonts in loader + sig verification code 2024-01-28 16:02:12 +08:00
bunnie
f432968678 add fonts back into the loader for the cramium target 2024-01-28 02:15:48 +08:00
bunnie
474d42ff87 pull in improved API to loader 2024-01-27 16:53:15 +08:00
bunnie
1e93171575 turn of rkyv derives in kernel and loader, as these are no-std 2024-01-23 03:59:49 +08:00
bunnie
d981bbe550 add more features to the loader for the cramium target
this *shouldn't* break other builds because the loader has
its arguments set by xtask for every target explicitly.
2024-01-21 01:14:51 +08:00
bunnie
6786efbb01 add PL230/PIO test to bringup section 2024-01-20 21:32:20 +08:00
bunnie
47dbecfd0b print trng status on bringup boot 2024-01-20 16:17:02 +08:00
bunnie
798183fe95 add TRNG output to board bring-up test 2024-01-20 01:26:30 +08:00
bunnie
0e14761641 cleanup loader code path
- print a banner on boot even without bringup
- stylistic improvements
2024-01-19 23:21:40 +08:00
bunnie
f12ddb09cb uart Rx in loader now seems to work. 2024-01-18 19:09:49 +08:00
bunnie
6f81024c77 refactor loader to use cramium-hal primitives
this is instead of the raw bitbang stuff we were doing before.
2024-01-18 18:02:23 +08:00
bunnie
659796916a chore: cleanup typos in docs, comments 2024-01-15 02:16:43 +08:00
bunnie
0267a56989 format Cargo.tomls
because apparently cargo fmt doesn't format Cargo.toml files???
2024-01-15 00:14:39 +08:00
bunnie
221972e955 remove trailing whitespace on loader 2024-01-14 23:59:20 +08:00
bunnie
454ecac95a fix rustfmt::skip warning
turns out, stackoverflow has out of date info. woohoo!
2024-01-14 23:12:52 +08:00
bunnie
a6a28b9d9e format loader 2024-01-14 22:02:55 +08:00
bunnie
3d6ba05c95 ok...@generated is useless, let's try a different approach.
@generated "marker" needs to be a naked comment on a line by
itself. I'm not quite sure how this is meant to be used, tbh.
2024-01-14 22:01:03 +08:00
bunnie
ee6190a12a prepare for format 2024-01-14 21:51:11 +08:00
bunnie
a5137e69b1 remove legacy script 2024-01-14 21:50:54 +08:00
bunnie
0692a25323 fix cramium build targets 2024-01-08 02:33:27 +08:00
bunnie
3da1ed181e set hash default value to 0x30 ("0")
this makes it much easier to detect if a loader failed to set
a hash in other routines.
2024-01-08 00:21:06 +08:00
bunnie
7b8a598020 wire up the hash computation to the hash consumption 2024-01-08 00:17:54 +08:00
bunnie
7719dbcb69 write hash into the environment variable
Convert the fs_prehash into a hex ascii string, suitable for environment variables
The initial loader environment is hard-coded, so we use a hard-coded offset for the string
destination. It was a deliberate decision to not include a generic environment variable
handler in the loader because we want to keep the loader compact and with a small attack
surface; a generic environment handling routine would add significant size without much
benefit.

Note that the main purpose for environment variables is for test & debug tooling, where
single programs are run in hosted or emulated environments with arguments passed for fast
debugging. The sole purpose for the environment variable in the loader's context is to
this computed hash onto the userspace environments.
2024-01-08 00:16:48 +08:00
bunnie
8f3229c9ea convert secboot to have an argument for returning the hash
also compute the hash and return the value as part of this patch
2024-01-08 00:16:20 +08:00
bunnie
2f47a9d4f2 more rework of pre-hash argument
While ideally we'd be as light-fingered as possible on the cryptographic
APIs, unfortunately the reality is we have exactly one hardware
hash engine and we can't just leave the context laying around.

Given that the verification routine would consume the hash, that
would make it unavailable for use later on to pass to the system.
So, this patch set causes the pre-hash algorithm to take a simple
slice-u8 instead of a whole hash context.

The downside of this is it erases the type information about
needing a 64-bit hash to go into the context. This is partially
mitigated with an assert that gives us a run-time check of this
property.
2024-01-08 00:13:35 +08:00
bunnie
4b002c34f5 Merge branch 'main' into prehash 2024-01-07 23:42:22 +08:00
Sean Cross
d8c6881554 loader: pass environment to processes via stack
Load environment variables to processes by placing the value onto the
stack. This will support additional data in the future such as command
line arguments.

Note this is a breaking change and requires a kernel modification.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-07 22:36:34 +08:00
bunnie
1454637915 add sha as a depedency of the loader
this is exposed now that we have to explicitly pre-compute a hash
as part of boot.
2024-01-05 16:09:03 +08:00
bunnie
5894e71095 convert bootloader to use prehash method
This applies to the *kernel* image.

The loader itself is still signed with the conventional signature.

Version number of the loader is also incremented.
2024-01-05 16:08:22 +08:00
bunnie
d88e446a33 finalize pre-hash before initializing a new hash
we only have one hash engine in hardware, and we want to use
hardware hashing at boot to speed things up as much as possible
and reduce code size of the bootloader.

This patch causes the pre-hash to finalize before a new hash
is initialized which folds in all the other key parameters.
2024-01-05 16:07:23 +08:00
bunnie
8ec08c9c76 fix rust v1.75.0 warnings that are probably benign
a lot of re-import warnings have cropped up. While I appreciate
their studiousness on this, the problem is that removing some
of these exports in the API crate could mean that future users
who want access to some API features that aren't used in this
configuration are now unaccessible.

I think it's not a huge problem at the moment, just spam-cleaning
the warnings because there are too many to deal with carefully
at the moment.
2024-01-04 19:15:28 +08:00
Sean Cross
88020c99e0 loader: add pid to map_page() call
Add the pid as the page owner to `map_page()` calls. This ensures pages
are owned by their respective processes, and removes a lot of
`change_owner()` calls that immediately follow page mapping.

It also allows for superpages to be owned by their respective processes.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-12-29 18:42:16 +08:00
Sean Cross
e0c62e5480 loader: don't reserve the "susres" page
The "susres" page should be owned by the "susres" server and not the
kernel. Avoid mapping this page to the kernel to prevent it from getting
double-mapped.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-12-29 18:42:16 +08:00
Sean Cross
aee07683b7 loader: run cargo fmt
There are no changes to this project.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-12-27 14:12:26 +08:00
bunnie
e2ba706f4b modify loader to setup the console UART
this avoids a bunch of nasty pinmux stuff that would have to
go into the console logger at early boot
2023-09-15 16:25:44 +08:00
bunnie
07303dccc2 add FPGA target to loader clock settings
this might want to get a more graceful feature option wrapped
around it but i'm hoping the unpleasantness of developing on
the FPGA board is...temporary??
2023-09-15 11:25:35 +08:00
bunnie
53469a68d0 publish package updates, sync to release tag 2023-08-08 14:35:49 +08:00
bunnie
b127cd093f bump version pins for change to xous-rs 2023-08-03 13:29:39 +08:00
bunnie
51278451a0 update version pins to pull in cramium target 2023-07-19 21:07:56 +08:00
bunnie
ca14ed78d2 fix renode build 2023-07-18 13:58:14 +08:00
bunnie
8155c0cc8b loader fixes for cramium target 2023-07-18 03:56:09 +08:00
bunnie
a118cdaa6d fix link file integration 2023-07-17 18:52:28 +08:00
bunnie
3a32e3e7a0 fix visibility of cramium module 2023-07-17 18:49:54 +08:00
bunnie
e0c8cc1da4 add cramium to loader target 2023-07-17 18:23:17 +08:00
Sean Cross
b23f6717ef loader: remove unneeded muts
Rust 1.71.0 reports more cases of unneeded mutability. Remove these from
the loader.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-07-16 15:30:23 +08:00
bunnie
4454dffe4e generate loader files for the new font
also sort the font files in alphabetical order now,
instead of relying on arbitrary ordering of os.listdir() :P
2023-07-05 14:44:30 +08:00
bunnie
30c752db75 bump the loader's font tables 2023-07-05 13:38:28 +08:00
bunnie
952ba18fba commit vesrion pin bumps 2023-06-16 01:30:18 +08:00
bunnie
5a2df4432c technical debt: cleanup UTRA package
- make the "base" field no longer public. It is accessible, but only
through an `unsafe` method, because, it is unsafe.
- add accessors to offest/mask fields. Because, it's not at all
unsafe to access these, and it can be useful for bit-ops that are
not part of the generic set of UTRA.
- add Arc to AtomicCSR, and require `std` for AtomicCSR types.
This should not break anything, I checked inside @foundation-devices
keyOS and they don't seem to be using AtomicCSR anywhere.

The Arc makes it a bit safer to clone the AtomicCSR base pointer
and share it between threads, but it will have an impact on performance.
The USB stack (which requires AtomicCSR) was regression testing and the
impact seems minimal.

Recall that the main purpose of AtomicCSR is to provide a CSR accessor
that does not require a mutable reference to the base object. This
can make certain Rust idioms a bit cleaner. We wrap the base accessor
in Arc+Atomic to try and improve the safety of throwing the borrow
checker under the bus, but it's still not perfect because hardware
mutable state can have side-effects within hardware itself that cannot
be modeled or checked by Rust's borrow checker.
2023-05-23 18:11:24 +08:00
bunnie
697d44de3d bump version pins to absorb changes to svd2utra etc. 2023-05-03 23:11:12 +08:00
bunnie
8357ab31a5 bump all pins because utralib got updated 2023-04-09 00:48:35 +08:00
eupn
387c12d1ee
loader: fix precursor build 2023-04-05 16:42:58 +04:00
eupn
6ac2713f0a
loader/arm: allocate separate IRQ stack 2023-04-05 16:36:13 +04:00
bunnie
e469eba167 bump version for utralib patch 2023-04-04 02:13:02 +08:00
bunnie
57cea9b3ca cleanup a warning when debug is not turned on 2023-03-22 02:47:41 +08:00
bunnie
773bbc695a
Merge pull request #330 from Foundation-Devices/loader-arm
loader: add ARMv7-A support via sama5d27 chip
2023-03-22 00:34:00 +08:00
eupn
1f2b45e60f
loader: replace ssh git dependency with https 2023-03-20 23:54:56 +04:00
bunnie
d413100102 handle edge case of a "perfect fit" loader section
When a block of data perfectly fits we fail to allocate the
next page, violating the loop invariant that there's data available
to write.

However, we can't always allocate a new page when we run out
because if we're at the end of the process we shouldn't allocate
a new page (I think). Thus we track if the last section was
a perfect fit, and if it was, we force a new page allocation
before copying more data.

This is an edit in phase 1 of the loader.
2023-03-16 01:05:07 +08:00
bunnie
137f23039b fix formatting on check print 2023-03-16 01:04:45 +08:00
eupn
e7eb9ece2b
loader: remove unused imports 2023-03-14 17:15:17 +04:00
eupn
d4a85c7efa
loader: add FD to authors list 2023-03-14 17:15:17 +04:00
eupn
899351214b
loader: split hw specific details with feature gates in common modules 2023-03-14 17:15:17 +04:00
eupn
a0b9868068
loader: split panic handlers 2023-03-14 17:15:17 +04:00
eupn
3caf8dedd0
loader: split debug and asm modules between arm and riscv 2023-03-14 17:15:17 +04:00
eupn
787312bf82
loader: split consts between riscv and arm 2023-03-14 17:15:17 +04:00
eupn
319071ed73
loader: add sama5d27 feature 2023-03-14 17:15:14 +04:00
eupn
306fdee180
loader: add asm binary and ix build script to pick ARM asm and link.x 2023-03-14 17:13:53 +04:00
eupn
1867f6cf1a
loader: include atsama5d27 arm platform 2023-03-14 17:13:53 +04:00
bunnie
303f595d6f bump versions to cleanup renode.rs sync issue 2023-03-14 16:34:53 +08:00
bunnie
82e3aa322f bump toml files in prep for publish 2023-03-08 03:54:37 +08:00
bunnie
0dd74fe7b3 remove gitrev from precursor soc type
in practice this has not been a useful indicator, and we
have stabilized the SVD format so that changes in the code don't
cause the SVD files to go incompatible anymore.

this should make maintenance a bit easier going forward, hopefully.

also merge in cramium support to harmonize the forks for easier
cross-patches in the future.
2023-03-08 03:46:03 +08:00
bunnie
93bd7468e1 Merge branch 'main' of github.com:betrusted-io/xous-core into main 2023-03-08 03:03:40 +08:00
bunnie
df401d684a remove references to sram_ext so the hardware can be pruned 2023-03-02 17:03:41 +08:00
Sean Cross
ab353c1bee loader: move the kernel stack to kernel region
The kernel stack previously was located at the same relative offset as
all other programs. While this worked, it is poor form.

Move the kernel stack into the kernel memory region (located in the last
4 megabytes of virtual address).

Signed-off-by: Sean Cross <sean@xobs.io>
2023-02-27 20:21:16 +08:00
bunnie
d7c3266ec6 cleanup a warning; fix renode build 2023-02-27 02:19:21 +08:00
bunnie
dfd4c1ab40 fix precursor platform test
the precursor platform test is a RAM stress test. This patch
improves the test slightly by making it more parameterizeable,
and having it run a bit longer.
2023-02-27 01:30:20 +08:00
bunnie
0b25ede0c5 refactor phase 1 of the bootloader
Removes some of the redundant copying, and also simplifies the code
for easier readability and maintainability.
2023-02-22 03:29:14 +08:00
bunnie
b8cc156cfc compact phase 1 loader
merge inie/inif routines more intelligently
2023-02-22 00:58:26 +08:00
bunnie
039de0bfe9 split loader into modules 2023-02-22 00:36:16 +08:00
bunnie
3437b94807 clean up a warning 2023-02-21 23:38:40 +08:00
bunnie
e34d740bc6 some final tweaks for cross-platform integration 2023-02-21 23:19:02 +08:00
bunnie
032bd864db parameterize the loader so it can work with multiple targets 2023-02-21 22:51:53 +08:00
bunnie
bdc0b79906 move assembly header into in-line assembly 2023-02-21 22:17:10 +08:00
bunnie
0c9f8c57c2 remove warning on unused murmur lib when no resume is enabled 2023-02-21 18:24:39 +08:00
bunnie
c4a55a3cb5 fix multiplatform details; bump version number printed 2023-02-21 18:19:12 +08:00
bunnie
0c6ee68a3b make secboot optional 2023-02-21 18:11:32 +08:00
bunnie
f95b05fdb0 fix utralib entry 2023-02-21 17:46:56 +08:00
bunnie
dd105e25f7 update loader Cargo.toml to include platform options 2023-02-21 17:44:12 +08:00
bunnie
3d88a7b3de add platform option files to loader 2023-02-21 17:43:48 +08:00
bunnie
08ae66a264 fix: #320
this commit adds the facilities to extract eh_frame[_header]
sections and pass it to each process.

A bump is required to `std` to extract the passed parameters.
2023-02-15 19:55:08 +08:00
bunnie
ffe697b8c8 CHORE: cleanup some build warnings
put the load checker code behind the debug-print feature gate
2023-02-12 13:15:02 +08:00
bunnie
a6b46c6275 add check function to loader
This is very helpful for debugging loader errors. Basically
it prints out the first and last 20 bytes of each section
based on the source as specified in the MiniElf format, and
then it prints the corresponding data as loaded after walking
the page tables.

Loader errors really stand out with this debugging tool.
2023-02-12 01:12:20 +08:00
bunnie
4a2234f539 XIP works with some processes, but not others
it works with e.g. shellchat, but not vault.

still scratching my head on what's gone wrong -- it's
crashing in the pre-boot, which means something is not
mapped right for some case that wasn't caught in the
earlier testing.
2023-02-11 01:42:04 +08:00
bunnie
11c987c5f6 this loader commit was accidentally pulled into a previous mass-commit 2023-01-31 15:14:47 +08:00
bunnie
e5fdd0fec7 commit new versions to verifiers 2023-01-31 15:12:19 +08:00
bunnie
5370ce396d bump all revs due to SoC artifact update 2022-12-12 16:07:20 +08:00
bunnie
1d1b3a35b7 commit version bump 2022-11-26 10:00:44 +08:00
bunnie
aa9977cc58 bump all the things because we changed utralib again 2022-11-17 22:13:40 +08:00
bunnie
dabbfd6c35 bump all the things to absorb the SoC change 2022-11-17 19:39:18 +08:00
Sean Cross
3a8457852f loader: fix build with gcc-ld
With Rust 1.65.0, we may be forced to use gdb's linker due to bug that
appeared in llvm-15:

https://github.com/rust-lang/rust/issues/103949

Signed-off-by: Sean Cross <sean@xobs.io>
2022-11-04 12:26:05 +08:00