this is a fully abstracted API that should be fully hardware
independent. This is meant to supercede the xous-bio-bdma library.
The xous-bio-bdma library will stick around, but its main purpose
is as an experimental, baremetal library that contains low
level code and test code for developing the hardware. We could
try to merge this into the abstract APIs but I think it doesn't
make sense from a methodology standpoint - hardware development has
a different tempo and flow from the software development process,
and so by keeping these two separate we end up with potentially
diverging APIs - but actually, this is a good thing. It allows
us to develop e.g. v2 of the hardware without having to roll
uncertain/experimental v2 hardware APIs into the abstract APIs
right away.
there is one hairy point in all of this, which is I'm trying to
get fancy and have a hardware "handle" be dropped automatically
when it goes out of scope. This requires me to pass around
a phantom lifetime parameter, something I haven't done before.
If this works, it could be a good template for dealing with other
abstract hardware APIs that will help remove some unsafe code.
turns out that when the keyboard is activated, *all* the keyboard
lines take over the GPIOs - and this will fight with the the doubled-up
PF7_PA2/PF8_PA1/PF9_PA0 I/Os.
Using the keyboard controller means that *all* of the PF2-PF9 pins
are now driven by the keyboard controller, regardless of the GPIO
setting.
This is because when the core is powered off, the GPIO output mappings
are lost (they are in the core domain, not always on), and the KPC
was implemented without the ability to selectively demux unused
rows/cols.
In particular on baosec this can lead to high power consumption on
the 24MHz clock when driving the camera, because the KPC fights
with the clock.
The mitigation for the current baosec hardware is to configure
the KPC such that the internal pull-up is responsible for the
"high" level, and it's only driven when "low". This reduces the
amount of fighting with the oscillator.
A future rev of hardware will move the osc to the PA3 pin, where
there is a PWM output but no muxing with the KPC, eliminating
the conflict entirely.
the problem with it being default in most configurations is that
it pulls in a sha-2 and ed25519 dependency into routines that
never rely on them. now libs that rely on the sigcheck need to
specify the feature explicitly to pull in the depedency.
- shipmode is for long-term storage. it disconnects the battery
from the system so that the shelf life can be ~years
- deep sleep effectively shuts down the system but leaves the
real time clock running. Requires a full reboot to recover
from deep sleep.
the backup RAM region is being used as a way to check if the
system is coming out of a cold power-on. Deep sleep is indistinguishable
from a power-on from the hashing perspective. Check if the RTC is
*enabled* and if not, enable it and reset the time; don't always
reset it if the backup ram is scrambled.
- backup RAM has an erratum where two locations are corruptable
and should not be used between soft resets to store data
- the reserved 32 bits in the bureg are now accessible as flags.
these flag bits are used between boots to coordinate system state
information.
this allows us to refer to it in boot1 if we eventually decide
it's useful to do it there.
however, as a matter of policy, boot1 checks loader signatures
against *boot1*'s public key block - so if the loader is to be
signed with a different key, boot1 needs to be updated.
there is a circular dependency that has to be broken: the board
type wants to be set via USB, but you can't set the board type
until the USB enumerates. USB enumeration can be unreliable on
baosec because the SE0 pin isn't mapped as the board type defaults
to dabao.
The baosec SE0 pin is PF5 - this is inaccesible in dabao. Thus
the decision was mode to pull both possibilities during the boot1
initialization phase.
This could cause some trouble for OEM configurations that are relying
on these pins to be e.g. inputs or some other value, but this will
need to be documented as a hazard for OEM designers.
removing prints in boot0 gives less handle for glitchers to time
off of. Also makes debugging chips harder, but I think the boot0
is starting to get stable enough that this is OK?
also removed the frac-PLL setting because it's broken. this causes
the PLL in the boot0 to be subtly different from boot1, and I
think I like it - it makes the timing of glitches between the
two phases different.
actually there's no reason i think to have it print all
four checks - just have it print on two of them, just in
case for some reason the prints could be used to time a glitch.
The "attack" counter notches up when a board goes through a
"slow" powerdown, as would be the case on a system that has
a lot of capacitance relative to the chip. This is a false
signal.
It's hard to tell this apart from a glitch attack, so a
heuristic was applied where at least two glitches have to
be seen before declaring we're under attack.
Note that in paranoid mode, the board instantly resets
when the power gets too low, so the counter doesn't notch
up.
A print statement indicating when a mesh violation was
added - this is to help debug chips that have a weak/marginal
mesh. Because the mesh is so long, small manufacturing defects
in the mesh are also picked up by the mesh sensor...
this should erase the secret keys if the boot1 pubkeys don't match
this enables OEM-signed boot1 images. the policy is that all OEM
images signed by baochip are considered to be untrusted, and thus
loading them onto a device would wipe any secret keys, making
them less useful for extracting secrets.
There are 2048 keys and about 500 keys are used by baochip,
so there are still plenty of keyslots available for OEMs to
use to implement their own version of security.
this reduces the amount of prints for a key range being
erased so if the debug flags are on boot isn't delayed
while the debug prints. instead, a total tally of the
erased keys for a key range is printed.
The developer function was decided to be overly-broad: the
issue is you could slot that in to *any* boot position and
it'd be accepted, and we already have a mechanism to deal
with developer mode (developer-signed images). Thus eliminate
the extra case and simplify the code base to reduce
potential bugs.
the init check is a bit too broad, we can still accept an honest
devkey answer as devkey mode in the case that the security keys haven't
been set up yet.