Commit graph

282 commits

Author SHA1 Message Date
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