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
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.
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.
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.
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.
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.
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.
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.
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.
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
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
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).
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.
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.
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.
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.
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
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.
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.
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...
i have decided that the current approach sucks, and i'm going
to abort the work in the pddb area. however, the stuff in
the rest of the branch is pretty useful, so we'll just revert
the stuff inside the pddb directory.
couple of notes:
- bw threshold is now dynamic, based on the average of the previous frame
- performance is a bit slower than ideal, because of the SPI back pressure
bug preventing us from reading out the video at full speed. This should
be better on NTO.
- rotation introduced so that the preview image should align up
with what we'll have in the final camera v. display orientation in
the baosec product
- tested against the TOTP test suite (edent.codeberg.page/TOTP_Test_Suite/)
and it can quickly capture all of the basic valid tests.
This new api allows for scalar-5 returns as well as more
efficient use of the scheduler's quantum by not simply yielding
time when a message is returned; it will fetch the next message
and process it until its time is up.
this is mostly a copy of what's in graphics-server. Perhaps
we can find a way to share the code between the two, but I
am going to leave it duplicated for now because it's unclear
if I can use this implementation as-is, or if it needs lots
of modifications.
If it turns out to basically work without mods, then, we can
wrap a bunch of the opcode dispatch into mega-function perhaps
that takes a display and opcode as parameters and wraps a lot
of the boilerplate into a re-usable routine.
i think it's becoming clearer at this point that other elements
need to be implemented before we can attack this. leaving notes
and bread crumbs so I can come back to this branch later
The Spinor struct will be pulled into the PDDB for the cramium
version. This is done in part to reduce the number of servers
(keep the memory footprint light) and also because the physical
spinor hardware is owned by the swapper crate (because the ROM
shares a bus with the swap RAM). So, all that is needed in
this case is a thin shim that can adapt the two APIs to be
compatible with each other.
THe currently checked in code is just a copy of the existing
spinor code tho - it has no bearing on reality, it's just there
as a placeholder that contains all the APIs.
the Iox block can register up to 8 interrupts on any of the
GPIO pins on the device. All the interrupts get OR'd together
to generate a single interrupt to the CPU, which has to be
disambiguated and forwarded on to the registering server as an
event.
Due to the protection model of Xous, the configuration of
the IRQ has to be centralized, and the handling is done with
a message. This means that the actual time from the interrupt
to the handling can be a bit variable, up to several ms, so
this method isn't suitable for hard real time.
For hard real time stuff, see the implementation in the USB
stack for Cramium, which has a very timing sensitive IRQ
handler requirement.
The overrun test needs to flush the fifo when it's done (it's a
deliberate error test).
Also remove access references to a peripheral that no longer exists
this all seems to work as expected now, next up: hooking the
interrupt handler for the IOX.
Probably should put the actual IRQ router in the HAL so that multiple
services can configure it, but have the handler actually invoke
a function in our address space.
programs should now use the usb-cramium crate for a USB
stack. It preserves the `lib` API, so you /should/ be able to
integrate it seamlessly by just renaming crates between
the two.
we're going to strip out the USB cramium support from this crate
eventually because it has migrated to a stand-alone crate
the hardware model is just too different to keep the two branches
in sync: one allows interrupts to be delegated to userspace, the other
requires the interrupts to happen all in the locked handler context
due to timing assumptions of the core.
the problem with the interrupt handler context is that panics
are really hard to debug - you can't actually send a panic message
from an interrupt context, because there is no IPC when the
handler is running. Normally we try to keep the handlers as
minimal as possible, but in this case we can't due to hardware
assumptions.
The approach here turns the usb-device crate "inside out". The
working hypothesis for the unreliability of the previous implementation
is that we try to do all the IRQ-handling in userspace, where
the operation can be pre-empted. Unfortunately, this doesn't set well
with the corigine USB hardware driver, as it assumes that it has
the full CPU attention while its state is being manipulated (and
some things must be responded to in basically real time otherwise
you get protocol inconsistencies).
In this implementation, we use the Xous subsystem to do the
API-level exchanges of information to a USB handler that, for the
most part, runs directly inside an IRQ context.
There's some trickiness in terms of sharing the hardware state
across the boundary between IRQ and userland, but most of it
got handled I think fairly cleanly in this implemnetation by
using the xous-native server queuing mechanism to shuttle data
in between the two domains. The main spot where I think panics
can creep in is in data transmission, where the Tx data is
shoved into a RefCell and then the IRQ is invoked to pull the
data from a RefCell. As long as we don't invoke the IRQ to
pull data from the RefCell while it's borrowed mutably, we should
be OK.
Wrapping the structure in a Mutex actually doesn't help here
because the IRQ context can't do a "wait" to get a lock - it
would never get it, because it's in an uninterruptable context.
Thus we skip the complexity of a Mutex and let Rust panic if
we mesesd up the data hand-off.
there's now unfortunately branch divergence in the NTO/MPW
code base
The methodology is to code like we're running on NTO, and
if the "mpw" feature is selected, we put hacks in to run
on MPW hardware.
Under the theory that MPW should be totally deprecated
once NTO comes out, and therefore the hacks should accumulate
in the MPW code base (and ideally be somewhat easy to cull when
the time comes).