Commit graph

546 commits

Author SHA1 Message Date
bunnie
8ce400dde3 add more feature flags 2024-10-27 23:28:38 +08:00
bunnie
6c4cd3bc67 add qr option 2024-10-27 23:28:08 +08:00
bunnie
8625dae0db add more swap sram support and change resolution api name 2024-10-27 23:27:26 +08:00
bunnie
4f85deaecb change api name for resolutions to dimensions 2024-10-27 23:26:45 +08:00
bunnie
bceb08afb8 recognize 8MiB swap chip 2024-10-27 23:24:42 +08:00
bunnie
38ad0363ce fix capacity units 2024-10-26 18:45:36 +08:00
bunnie
1a90df9d53 add descriptor chaining for large bulk transfers 2024-10-26 03:06:37 +08:00
bunnie
2a92932850 cleanup some debug 2024-10-26 03:06:10 +08:00
bunnie
f9e99a4ff3 add assembly stub for cramium boot
this fixes a stability issue observed at boot
2024-10-24 01:29:04 +08:00
bunnie
e7f706e9cd revert statics clearing routine
this turns out to be a bad idea because it corrupts systems
that have suspend/resume.
2024-10-21 03:28:58 +08:00
bunnie
9647202366 cleanup testing code for QR code
now it will overlay crosshairs on finder patterns and do affine
correction when the finders are found.
2024-10-21 01:18:12 +08:00
bunnie
5d49d2dbb7 add libraries for math and make usb a feature 2024-10-21 01:17:41 +08:00
bunnie
2fd59a1f87 tweaks for platform agnostic API 2024-10-21 01:16:59 +08:00
bunnie
b3f038ca06 add affine skew correction step 2024-10-21 01:16:37 +08:00
bunnie
c0b942b801 platform-specific implementations for graphics 2024-10-21 01:14:04 +08:00
bunnie
5c6be58056 revise camera code - capture 256x240 frames
this improves decoding for e.g. type 5 codes, which is
a bit too tight with a 128x120 frame.
2024-10-20 17:05:45 +08:00
bunnie
f16e3721be add some QR code debugging stuffs 2024-10-20 17:03:50 +08:00
bunnie
b6fbc4ef36 clean up some gross static mut state stuff
still have to resolve the static mut issue of getting the USB
controller state into the interrupt controller.

I'm not sure there *is* a good way to do it - this might actually
be "the" use case for static mut's - but the point of this
exercise was to just diff out the driver in machine mode versus
OS mode to try and figure out if there's a hardware problem
causing instability or if it's a driver issue

the conclusion so far is that the USB stack requires extremely
tight interrupt handling timing, and so, for better stability
we may have to mirgate away from the heavily user-space dependent
implementation currently in use.
2024-10-19 00:15:12 +08:00
bunnie
37ceefef21 add usb mass storage command handlers
disk enumerates now, and initiates r/w transactions but
the reference driver does not match the implementation in that
the USB stack can't access all of RAM, so we have to add
an intermediate stage that splits the command requests into
smaller chunks
2024-10-19 00:14:12 +08:00
bunnie
dabd87aa3a add usb mass storage command handling 2024-10-19 00:13:52 +08:00
bunnie
ed9759f524 remove a debug statement 2024-10-18 17:18:06 +08:00
bunnie
90d7f45f0a adjust locations of memory for USB loader
and document the rationale
2024-10-18 17:17:29 +08:00
bunnie
452ba4adff cleanup area for statics used by the loader 2024-10-18 17:16:21 +08:00
bunnie
6c655e9358 re-enable interrupts immediately in the handler
we need to catch an interrupt that gets issued while we
are still handling the pending interrupt.
2024-10-18 17:15:24 +08:00
bunnie
a6e7459cdd re-organize the USB subsystem into modules 2024-10-18 14:45:15 +08:00
bunnie
e4f5c32ff3 update link locations to make space in loader for USB stack
this is in preparation for loader-based updates

may have to increase space even more when we pull in e.g.
firmware signing and verification primitives.
2024-10-18 04:17:36 +08:00
bunnie
d8cd9ba5c5 add hook to USB testing, and also move the kernel to make space for loader USB 2024-10-18 04:16:31 +08:00
bunnie
3a4ae8f09f add usb to cramium platform 2024-10-18 04:16:08 +08:00
bunnie
8b14494a15 fix some bugs in gpio twiddle code 2024-10-18 04:15:47 +08:00
bunnie
af6f4766ff translated reference USB stack into Rust
implements mass storage; needs debugging
2024-10-18 04:13:57 +08:00
bunnie
3b61a60a2c remove boot delay, add reset-debug feature targets 2024-10-16 03:06:41 +08:00
bunnie
4c810ec447 add various debugging assembly routines for the loader 2024-10-16 03:05:54 +08:00
bunnie
778af25414 add handler for pmic open failure; add test case for self-powerdown 2024-10-12 00:46:47 +08:00
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