- writes need at least a "pipe cleaner" to set the pipe in the correct
state
- may also need a "double-write" to commit the data - this is to be
explored with a smaller test case
- DMA write only works over all corners at 700MHz when
FCLK=ACLK (i.e. FCLK is at half rate)
a lot of routines were left blank in the initial port to get
through the core graphics primitives porting. This commit
fills in those missing bits in a fashion that optimizes the
modals for drawing on small displays.
so, there is a fundamental abstraction mismatch in the blitstr
library. In Precursor, I created a rule that you can't draw text
on black backgrounds without some special permissions in highly
trusted contexts.
For baosec, this restriction is removed because the whole OS
can run inside a single chip (i.e. we have eliminated most
easy RAM modification attacks, requires probing/glitching; but
as a trade-off, we don't have as much RAM so we can't afford the
extra abstractions).
The compromise is for OLED-type platforms where inverse drawing
is very common to save power, all text ops are assumed to be XOR
operations (so you're always flipping pixels instead of drawing
at a defined color).
this can accelerate drawing of complicated objects, such as
QR codes, that are composed of many rectangles.
there are some warts...in theory, this should be able to seralize
arbitrary-sized lists, but there must be some bug somewhere
that is preventing it from happening. For now, the list length
is clipped to the capacity of a page of memory.
the text bounds api call is needed in v2 because there is no gam
to mediate this call
clear allows for a fast clear operation that may have hardware
dependent consequences
acquire/release of modals mode is added to the graphics server
as well to implement a feature previously handled by the gam
this is an unsafe bit of code that is necessary because the
panic handler needs to run in its own thread with a hardware
handle to the frame buffer. this allows panics in the main
graphics thread to not cause the panic handler to fail.
So the organization of the code is now the following tiers:
libs/cramium-api: contains hardware-abstracted API code to the hardware
layers (traits, some constants, enums, etc.). For example, "here is
an IO trait that lets you configure and set GPIO pins", which could
then be implemented in hardware or emulation. The APIs aren't entirely
generic across all SoCs because they are tweaked to accommodate
quirks of the cramium SoC.
libs/cramium-hal: contains board-specific driver codes that do not
require persistent services to be started. Possibly misnamed because
it also includes not just cramium-chip items, but also e.g. peripherals
to the cramium SoC, such as the PMIC and camera.
services/cramium-hal-service: contains the `main` process that manages
shared resources, such as UDMA, IO pins, IFRAM. These drivers cannot
be delegated to a `lib` crate because there can be only one instance
of these resources, and instead we have to dynamically allocate
access to these through IPC messaging.
services/cramium-emu: hosted mode emulation of things in
cramium-hal-service.
services/bao-video: contains a `main` process that integrates
the camera and OLED driver. This means that all graphic drawing
primitives also interface with this crate. These are condensed
into a single process space to speed up execution, and kept
separate from cramium-hal-services because we want the video
services to not be blocked by, for example, a thread that is
handling I2C things.
ux-api can't do rkyv derives and rely on std items in a
no-std environment. This is necessary because some of the
base layer APIs (frame buffers, points, etc.) are relied
upon in a no-std loader environment to render diagnostics
to the screen. Thus ux-api needs to have a baseline of
primitives available without a std flag.
I thought originally cramium-emu would be a library crate, but
actually, it makes more sense as a "services" crate. The APIs
that cramium-emu would live in cramium-api, and cramium-emu
itself is a bit closer to cramium-hal-service, filling in
the executable bits of code that allow emulation to run.
This is a distillation of cramium-hal items into "pure API"
items so that we can have a parallel cramium-emu crate.
The idea is that the API crate sits on top of both implementations;
the HAL goes to hardware, and EMU goes to hosted mode emulations.
a bunch of imports were in here that should be in blitstr2
let's test this out and see how well these abstractions hold up
as we configure the rest of the OS around it.
ux-api is meant to be a platform-independent set of APIs for
elements involving UX interchange in xous. In particular, it
sets up the path for portability of the gfx/minigfx crates and modals.
realizing a bunch of stuff like the stack expects you to enqueue
the OUT receiver with calls to read() that happen to block, fixing
max packet size that can be different for in and out end points,
and handling quirks of the core when sending setup packets longer than
64 bytes.
the UsbBus implementation is being totally rewritten for the
inside-out IRQ protected scheme.
we can now get past some preliminaries in the link protocol
(i.e., address setting and the first config descriptor), but
a long way to go still in debugging.
the uart in the shared library is claimed by the first process
that touches it, so prints in the shared library at early boot have
to be carefully configured
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.
mass storage is...somewhat stable now, on both linux and windows,
but there are some corrupt packets. need to look into whether
electrical issue, or if we're stomping the transfer buffers because
we've not managed them correctly.
Also need to reflect on how to turn this API into something
safer...the hardware is doing *so much* in this API, the driver
is basically global mutable state with arbitrary slices you can
write over the ends once you hand things off to the driver.
this is for higher resolution QR code scanning
makes it incompatible with simultaneous USB usage
however, when camera is off, the USB stack can be started, and
vice-versa. Basically, you can't both do active USB and camera
at the same time, but you can do one or the other.
- add USB mass storage state tracking for handler-based intervention
- fix some wait loops
need to regression test this againt a xous-mode USB operation
split the handler out into a function pointer
add callbacks for completion handling of EPs - in-line with
the reference code
improve the pei handling
change visibliity of structures to allow for out of crate
handlers
We use the txrx call instead, which does not signal a completion
until the rx transaction is finished (which is after the final
bit is received of a pending SPI transaction).
This allows us to do a "swap" transaction (transmit and receive)
asynchronously (the await returns a pointer to the receive buffer).
Note that a pure-rx-only variant is still todo, but should follow
pretty naturally from the pattern outlined here.
this is a CSR object that presents writes as an immutable on the
parent object. This simplifies traits, etc.
On the one hand, the CSR itself is truly immutable - the address
represented by the CSR does not change.
On the other hand, the underlying data inside the CSR is changing,
so, the CSR actually represesnts an immutable pointer to a mutable
piece of data.
For the case of the UDMA, we have a bank of globally shared state,
it is much more convenient to think of the CSR as immutable, and
we manage the underlying global shared state through other checks,
e.g. through dynamic allocators that track when various blocks
or resources have been parceled out.
- 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.
this allows us to tease out the clock setting code from the pin
setting code. probably will need to add more helpers for other
peripherals as we continue through with this exercise.
- filter setup can be impacted by previous engine running, make
sure engines are stopped and FIFOs flushed prior to test start
- when reading a filtered bank we can get garbage, so make the
test check for the specific value we should see.
This releases flatipc 0.1.2 with more documentation and a new
`Ipc::from_memory_message()` call to reconstitute an object from a
xous::MemoryMessage.
Signed-off-by: Sean Cross <sean@xobs.io>
prior use of `rkyv` reserves two bytes to record `pos` pre-pended
to the rkyv record
the new rkyv works without having to do that because it indexes
the rkyv data off the end of the stored records. Thus, all you
need to know is the total length of the byte slice that stores
the serialized data. This is available as the return argument
when you read a PDDB key, so we don't have to explicitly store it
anymore.
@nworbnhoj would love it if you could have a look at
the implementation and let me know if I've ported this correctly.
I think what was going on is you were using rkyv to serialize
a structure to the PDDB. I've just updated the ser/de to use
the latest `alloc` API (which is much simpler than the API used
in xous-ipc because it is no-alloc).
I'll try and run some tests that involve the TLS crate too down
the road under the theory that it would suss out any porting
errors.
flatipc is a new method for doing IPC. This is a zero-copy approach
where structs are given `repr(C)` implementations that are well-defined
and work across process boundaries.
If the same struct or enum is used in two processes that has the same
layout, then data can be freely passed between the two processes without
incurring a serialization or deserialization penalty, provided the
following hold:
1. The buffer must be page-aligned and be a multiple of the page size
2. The item must be `#[repr(C)]`
3. There must be no pointers or references of any kind
If these three things hold, then the object is safe to sling across the
process boundary.
This crate adds the ability to annotate structs with
`#[derive(flatipc::Ipc)]` to provide them with this functionality. When
doing so, objects gain the `.into_ipc()` call that turns them into
something that can be sent across process boundaries.
The resulting object has `.lend()`, `.lend_mut()`, `.try_lend()`, and
`.try_lend_mut()` as functions.
Signed-off-by: Sean Cross <sean@xobs.io>
a bunch of lines are shorter or different length now which
triggers a mandatory reformat. this patch cleans that up,
so that going forward the manual rework patches are clearer and
not tied up with formatting patches.
the filter is on by default (which blocks all DMA access with
the null settings) and can be configured to restrict access to
regions of memory that contain secret materials.
this exercises a simple stack-based routine to check that
the RAMs are correctly wired. Note that due to a lack of
creativity on my side, only cores 0, 1, and 3 are exercised;
it's just assumed that core 2 works as well since everything is
instantiated by loop.
BDMA memory pages for each core are now on separate pages, with
each core having a private memory space.
Also add code readback tests, debug PC & trap test
currently uses just a "dumb" 0-to-max scheme and then block until
drain. A more efficient implementation might implement a circular
buffer but it's more tricky to code -- just want to get something
working for now.
compression helps us reduce the amount of data we have to
shuttle between the hardware interface and the rest of the world.
It takes more samples from the TRNG and represents them in a compressed
form that effectively increases the bits per byte of entropy. It
does not increase the *rate* of entropy generation -- while each
byte has more entropy, the bytes come proportionally slower. However,
this is a reasonable trade-off because kernel space calls to fetch
the entropy feed are expensive, and what this does is effectively
amortize the price of a syscall: the time per syscall is longer,
but you get more entropy out per syscall, thus effectively reducing
the needed overhead to get a certain amount of entropy.
turns out that you *have* to enable the endpoints after your
address has been assigned. You can't do it before.
Very subtle one-liner in the docs that I missed until now. :-/
this is an actually usable driver for end applications.
maybe some massaging needs to be done on shared resources, but
from the i2c standpoint this can do SMB, I2C transactions with
a fairly "normal" API.
this works by blowing apart the structure and re-assembling
it on the other side. The reason we can't simply pass it
is because the hardware pointer to the core register violates
a Rust safety rule, but Rust doesn't know that this pointer
points to a hardware register that's immutable and static versus
a regular block of memory that can go away.
this API has the unfortunate problem that only one process
can manage all the IRQs for all the serial ports, due to the
concentration of all IRQs into a single register bank.
That being said, it does support registering multiple repsonders
in a somewhat ergonomic fashion.
UDMA Rx busy bit seems to get stuck occassionally. This seems
to be aggravated if we insert a dcache_flush in the poll loop.
The current time-out code seems to mitigate the problem, but
I have low confidencne that this is a 100% solution. I have a feeling
we'll be revisiting this again soon.
- need to be able to specify the mode that a SPIM could be in
that was set up by the bootloader
- make yield() optional - it could be useful if the API is used
in userland contexts, but in an interrupt context (e.g. swapper)
it should not be used.
if not in quad mode, command is ignored; but without this,
the command is never accepted if you are in quad mode.
the idea is you use this to reset the chip when you don't
know what mode it's in.
- improve visibility of core structures for debugging
- add qpi-mode ID readouts
- support different commands for flash/ram ID readout
- fix bit-shift bug on cmd (docus say to "align to MSB" but
I don't know what MSB they are talking about, it only works if
you align the commands to LSB).
I think I may have to be patient on waiting for docus on how to
tune the trng, so, turning off these warnings for now. trng tuning
will be "an event", I expect.
synthetic test that exercises multiple cores triggering each
other, waiting on each other to complete tasks, and waiting on
the host to meet conditions such as fifo fullness levels before
running.
this proves out the basic concept of inter-core eventing.
fifo input/output from host with back-pressure works
gpio loopback input testing works
framework for automated assertion testing is in place;
all tests from this point forward will endeavor to include
some asserts that will cause the test to fail, so we don't require
manual inspection to check test results.
This macro takes as arguments the name of the function
you want to use to retrieve the assembly code, and two labels,
one for the start and one for the end of the assembly code,
and the assembly code itself.
The labels for the start/end of assembly code are identifiers
and because of Rust's rules macros can't create identifiers out
of thin air (I wish instead of saying "partially hygienic", they
just said, "you can't create identifiers that don't exist". Yes,
I'm sure "partially hygienic" has some other meaning to computer
science people but to me it's just pretentious bullshit that
forces me to read through four blog posts and three issues to
come to the practical conclusion I really wanted to know; I
think maybe they wanted to refer to it as hygiene because the
limitation is super frustrating and hygiene sounds like a positive
way to spin something that is annoying. Sure. It's fine. You
didn't want to allow macros to make identifiers because it can lead
to surprising behavior and name space conflicts. That's your choice
as a language designer, just say it.).
Anyways. as usual, rust macro took way too long to write.
@nworbnhoj, i saw you had explicitly done a formatting pass.
However, I think maybe the +nightly flag was missing, it looks
like the formatting ignored our custom rule set, which requires
nightly?
In keeping with webpki-roots - the TrustAnchors are managed without the Der Tag::Sequence header
This in turn requires that:
- the header is removed from x509 fields before saving in the pddb, and
- the der Tag::Sequence is added to ota.subject before it can be decoded () see ota.subject()
looks like about 9 crates will be affected by this. Point them
all to the latest version of the API, and specify the
"precursor" feature (which activates our patch)
size, you can do this one liner:
let aligned_size = ((unasigned_size + alignment_quanta - 1) / (alignment_quanta)) * alignment_quanta;
before i was doing this with a `let mut` + `if` statement. this is not as obvious
but more compact, probably you'll start to see this idiom more and more in the code.
I think it's also computationally efficient, because as long as
the alignment_quanta is a power of 2, the compiler does something
like a shift right with the `/` operator (and it may also do something
like a shift left with the `*` operator as well).
there isn't an arg0 in the `ScalarMessage` return type but
that doesn't mean numbering starts at 1. So the first slot
should remain unused if you're not casting a return value
to `MessageId` (which is "just" a `usize` but "feels wrong")
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.
actually this is a correction of the names of these fn
these fn are actually handling trust_anchors rather than certificates
and in some cases we will need equivalent fn for certificates
the scroll-down freeze is actually because of the nature of
the test program hijacking the main loop. the test program
probably needs to be redesigned so it takes in events so we
don't eventually end up in deadlock
this is computed when the post is added to the list of posts.
Also split out the visual properties of a UI into a separate
struct so that we can pass it as a single argument to routines
that could handle layout-related tasks.
- the `post_add()` API on the 'lib' side of things says Add a new Post
to the current `Dialogue`, and it passes an empty `dialogue_id` string.
- the `post_add()` handler on the server dutifully unpacks the `dialog_id`
field with `post.dialogue_id.as_str().unwrap()`, and then passes on to
the `post_add()` call inside the UI object
- the `post_add()` implementation in the UI object then checks the
`dialog_id` with if `pddb_key.eq(&dialogue_id)`, expecting that the key
should match the dialog id. But through this path, the dialogue ID
is always the empty string, so the function can't work.
This patch causes the code to "fall through" and use the default
`pddb_key` if the length of the `dialog_id` is zero. Not sure if
this is the intended behavior, but in the test case at least I get
posts appearing now once this patch is in.
- rapid redraws are normally aborted by this routine. offer a forced
redraw in the case that a "final state" has to be rendered without
fail.
- fix a misdirected message (sending it to app instead of to ui by
accident)
this simplifies the problem of tracking concurrency if multiple threads
are requesting a busy-state to be presented. In this case, when the
final thread leaves its busy state, the idle-state will be shown.
- remove modal pop-up for wifi connection, and replace with
busy animation
- specify units of delay in the constants (_MS to indicate milliseconds;
this is a convention I'm trying to adhere to)
- partial progress on debugging why the animation isn't running
(value of animation variable is not being passed back at the GAM layer).
Also a general note on coding styles that probably is going to cause
confusion now that more people are contributing to the code base.
Generally, when a lot of "generic" library functions fail, we've been
passing an error message up the stack. However, these functions are
actually meant to be infalliable, and when you kick the error up the
stack you just end up with a panic at an unhelpful location (because
you finally catch the error only at the main loop or something and
by that point there's nothing you can really do about it but panic,
since it's supposed to be an infalliable operation).
As a result I have been trying to tamp down on needless error propagations
and having them fail with a unwrap or expect at the point where the
abstraction should be infalliable. This helps in debugging the actual
failure root cause because you're closer to the line of code that
actually broke, instead of just some line at a generic error handler.
Of course if you build with stack unwinding the top-level unwraps are more
useful because you can peer down into the call chain, but even then,
with the limited screen real estate I think deeply nested failures
would probably overflow any panic display. So even with panic unwinding
I think we stil want to keep the root cause within a few stack frames,
instead of errors being passed up sixteen levels of abstraction before
finally dying.
This only applies to things that are meant to be truly infalliable,
like syscalls that should not fail, or like unpacking a buffer or
memory message that has already been allocated. In this case the errors
are more like asserts, and are helpful if they fail at the line where
they break instead of being passed up the call stack (which was the
original architecture).
Probably I should add a note about this to the Xous Book.
- status bar text is just status bar text now
- idle animation runs/stops based on an explicit run/stop message
Note that at the moment if one starts the busy bar and a modal pops
up, you might overflow the queue of the ui drawing thread with animation
requests, because the thread blocks when the modal is summoned.
Modals "take the screen" anyways, so maybe the solution to this is
to add an additional interlock around any modal calls within the UI
main thread. Need to think about it a bit more.
Busy-wait animaitions are handled by a helper server that is normally
blocked. A single shared `bool` indicates whether the animation should
run or not.
When woken up, the busy-wait animator will check if the shared `bool`
is set, and if so, send a message to the main loop to update
the animation, then send wait an appropriate timeout and send itself
a message to re-check the animation status.
This particular format of server is fairly compact but can be vulnerable
to a "message storm" if busy state updates happen in rapid
succession without allowing the server to unblock and handle messages.
Thus, all messages to this server use a `try_send` method, with a silent
failure if the message can't be sent. In other words, if the animator
is already super busy and its queue is full, don't send it more messages,
just drop the existing updates so we can fail without a panic or deadlock.
The typical consequence of this is some UX inconsistency, which is
not a critical error.
- status bar gets some initial text on boot
- previous status message is saved when entering a busy state,
and restored on exit
- add routines for hopefully making the redraw a bit more efficient
if the only thing happening is a busy-wait update.
Set up tls with rustls::ClientConnection,
BUT - on Error::InvalidCertificate - then
probe the host for the untrusted certificate chain and prompt the user
to perhaps trust one of the certificates in the chain - then try again.
- add duart debug for bare iron testing
- add wait states on FIFO commits for when CPU clock is much
faster than PIO clock.
more wait states will be needed for correct operation in the
future
This is necessary because mounting the PDDB is a "secure" operation, and secure ops will fail until all UX contexts are occupied.
This problem does not manifest in hosted mode because we cheat and automount the PDDB in hosted mode.
this case is too sensitive to clock config outside of the PIO
block, because it relies on some specificts of how inter-bus sync
works and the environment is free to set PIO and PCLK relationship
arbitrarily