The code base had evolved through several code names, interim
names, company names and chip names that alternatively did or did
not exist.
Baochip is the definitive name of the company, and the Baochip1x
(full part number BAO1X2S4F-WA) is the definitivey part number of
the SoC. For convenience, the part number is shortened to 'bao1x'
in most feature flags and variable references.
This commit fixes all of the odd names and removes some unmaintained
early targets.
usb-device has a limitation for this hardware in that it can't
initiate an ep0-receive. It has a hook for flipping ep0 from
IN to OUT (as a modal thing) but for our stack you need to
explicitly setup EP0 to receive - an exact amount of data based
on what's expected - exactly at the point of the setup packet
arriving saying an OUT transaction is pending.
The hack to work-around this is to simply intercept those setup
packets in the handle_event_inner() interrupt handler and initiate
the receive. In fact, the data is completely ignored (in our
application it's setting a baud rate which is fictional in our
system). However, clients such as windows will time out and
refuse to communicate if the OUT packet is not ACK'd, even if
it is ignored.
- endpoint allocator now handles more edge cases. likely there
are still more weird cases to be considered, but it at least
handles the CDC-ACM case of a lone interrupt endpoint that
can't be mix-and-matched with other devices
- initiate OUT to kick off reads
- remove dead code
- handle bulk and interrupt cases for both read and write
- clean up reset edge cases - still more work to do there,
the stack does not recover on second plugin
- better debug output
previously we had no way to correlate an incoming packet
to an actual read from the USB stack because we didn't store
the EP that originated the request
This fixes that issue and also passes on the pending EP requests
correctly to the rest of the stack
there is either a code bug or a compiler issue that is causing
something on stack to be smashed that is causing trouble for
the code base as a whole. Or it could be improperly initialized
statics? unclear. this needs to be worked through.
however, a series of changes were made that make the code
work. The biggest tell is that the code generally works perfectly
when optimizations are off, but when optimizations are on some
shenanigans have to happen to convince the compiler to not split
constant values across the entire arc of the function. More
diagnostics to follow.
NACK bit is now checked after running the transaction, and if
it is set an appropriate error code is returned.
The trait implementation for i2c baremetal calls is also
updated in this commit
in the Xous context, because the IRQ banks are owned by a global
object, not every server can simply refer to the IRQ bits by just
dereferencing a pointer. Instead, it needs to send a message to
the cram_hal_service with an API number which then catches this
and does the dereference on behalf of the caller.
multiple IRQs related to the UDMA will eventually get mapped into
the global IRQ handler for UDMA. Create an enum type that will
help us differentiate this and add a trait that returns the raw bits
for a given IRQ type.
Probably a fancier wrapper should be made to interptet the IRQ
bits but unfortunately there isn't a uniform pattern to the IRQ
mappings, it's pretty much whatever fit into the IRQ space based
on the underlying function. At the moment not even sure if this
is the right register to be chasing, so we'll use this for probing
that aspect and then get fancy later, maybe.
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.
our implementantation of Buffer can't (currently) dynamically grow
the size of the object to serialize things that are bigger than
a page, so we have to enforce Vec-like objects to have a serialized
size of less than the page limit.
This is a bit of a moving target because it depends on implementation
specific details. A conservative bodge was put in to try and
work around this problem for now.
This was introducing a mysterious "line" artifact on text rendering
in new systems.
Probably need to do some real on-device testing of this change
because the automated tests won't catch a dirty bit error on
the LCD.
cramium-soc i think should be deprecated everywhere because
it is redundant with the board targets: anywhere you see a board
target that includes the crossbar soc it should also transitively
pull in the cramium-soc dependency equivalents.
we'll chase this out more later, but for now we're just trying
to get the PDDB to compile
This is a bad idea because yield_slice() causes the active
process to hand off to a new one (without an IRQ). However,
the idea of most flash operations is we really want them
atomic - we can't have something else decide to go and muck
with flash while say, we are waiting for a page erase to
complete. So, implement spin locking to block the CPU
during phases where the hardware operation is non-interruptable.
BOOKEND test sentinels are moved out of xous-rs, and into the
board definitions allowing us more flexibility on configuration
board-specific test configs (before it was a xous-wide constant,
which seems a bad idea because it makes migrating test infra
hard as the manufacturing infra updates)
MMAP_VIRT as a range is also added is this commit
this allows us move board-specific parameters out of xous-rs
and into a board library that is consistent with the new board
libraries, reducing special case code for Precursor
- 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.