Commit graph

10340 commits

Author SHA1 Message Date
bunnie
c6fb0565ff add frequency/voltage exports from api into the hal
also cleanup some small debug messages
2025-10-05 17:12:04 +08:00
bunnie
12e6292325 extend the image building tools to handle detached apps 2025-10-05 17:11:30 +08:00
bunnie
fd6077a64d add dabao target with detached apps
cargo xtask dabao

will now generate a Xous image that targets dabao

it features 'detached apps' so that user applications can
be rapidly developed without nuking the kernel itelf each time.

the current configuration bakes the console into the app section,
but maybe that's a questionable decision.
2025-10-05 17:10:27 +08:00
bunnie
b665e799ee add detached-app handling
"detached-apps" are Xous applications loaded into a region
of memory-mapped FLASH (and thus memory-mapped applications)
that are separate from the main xous.img image.

This allows developers to work on "just their app" instead
of having to upload the whole Xous ball.

Currently the only configuration that supports this is the
dabao configuration.
2025-10-05 17:08:42 +08:00
bunnie
ee1f3f3cb7 add detached-app handling in argument copy
also add some extra debugging to argument extensions.
2025-10-05 17:08:09 +08:00
bunnie
ac7a1b86e0 fixup bugs in arg extension processing.
Turns out we 'just got lucky' with our previous success
in getting arg extension to work (scary!!): the arg format
is pretty uhh...flexible...in terms of what it will accept
for arguments.

This fixes those bugs, the arg copy looks clean now, and
also removed the over-allocation problem by descending
the new argument list twice, once to sum the space needed,
and once to actually do the copy.
2025-10-05 17:06:33 +08:00
bunnie
afd64aa2b2 add a helper program to create "detached apps"
detached apps are ROM-loaded apps that are detached from the
main xous.img.
2025-10-05 17:05:49 +08:00
bunnie
60ccf93b78 add some readme's to differentiate the different app directories 2025-10-05 17:05:28 +08:00
bunnie
5fcfab95cc add 'dabao' series of apps
these are apps that are meant to be targeting "headless"
dabao style configurations. the decision was made to split
'apps' and 'apps-dabao' because for sure people are going
to try to load 'apps' onto a a 'dabao' board and wonder
why they don't work.

And the reason is the dabao just doesn't have the features
of a fully-featured system. so the 'apps-dabao' hopefully gives
people a clue that there's a difference between the two types
of apps.

also a very simple hello world app is added.
2025-10-05 17:01:28 +08:00
bunnie
d1f5aa19a8 map clock sources to API files, cleanup irqs on boot
- clock freq/voltage now in API definitions
- IRQ is disabled (or re-disabled) on all exit paths
2025-10-05 17:00:39 +08:00
bunnie
46b5c6f17d missing command option in help 2025-10-05 17:00:20 +08:00
bunnie
07ec63a1b3 add better loading feedback in various configs 2025-10-05 16:59:55 +08:00
bunnie
0f98c3bea1 implement signature checking on the off-chip swap image
Swap can be "secured" in two ways:

1) it can be re-encrypted to a secure, locally generated key

2) it can be signature-checked with a public key.

(2) is provided as a path to receive updates. Updates are distributed
as "encrypted" (with the "0" key), but signed with a public key.
Once the update is validated, it's meant to be re-encrypted
with a per-device unique key.

A big reason for the re-encryption is because the swap is already
encrypted, we can rely on the AEAD for validation, and skip the
signature check (saves time on boot). Recall that the reason
we don't just do a sig-check and run is that is a TOCTOU:
it's pretty trivial to execute a mux that swaps out the FLASH
memory after the signature check with another version that has
malicious stuff in it. So we go with a sector-by-sector
AEAD that's ideally encrypted to a locally generated key.

It also offers the possibility to prevent malleability of the
swap data between devices, as many public-key signed images
could be floating around, including old versions that include
insecurities (e.g. prevents downgrade attack by replacing
an up to date image with an older signed image with an insecurity).

However, this latter possibility requires the user interface
to be correctly setup to prevent malleability by asking users
to opt-in to partition re-encryption. Need to consider this user
experience flow - kicking the can down the line, but that time
is coming soon.
2025-10-04 18:55:36 +08:00
bunnie
7ff1e438ff make decrypt_page_at fallible
previously we just panic'd (which is actually the right behavior
for this type of error) but because we now have a reason for it
to fail (e.g. testing the encryption key) we make this fallible.

in all other places we just unwrap() - there is no fallback if
decryption fails, boot should just halt.

but this allows us to check which decryption key is deployed
in phase 1.
2025-10-04 18:54:15 +08:00
bunnie
2fb72be487 update signature check api in boot0/boot1
pass `None` for the spim field as these are direct RRAM checks.
2025-10-04 18:53:13 +08:00
bunnie
d21e99a3f3 implement swap header length reference 2025-10-04 18:52:50 +08:00
bunnie
2f5af89547 make the swap header length explicitly controlled
previously it was just "4096" in the image writer
2025-10-04 18:52:30 +08:00
bunnie
c86844a39a make signatureinflash structure data
this cleans up one unsafe step where we have to assume an
alignment of the data at the cost of the structure being copied
to stack. I think this is a fine trade-off.
2025-10-04 18:51:34 +08:00
bunnie
b91d54c5cf add SPIM optional target for signature checking
this allows us to check the signature on stuff in off-chip swap
memory through the SPI interface.
2025-10-04 18:50:49 +08:00
bunnie
e00606538c add SE0 release to userspace usb driver 2025-10-04 16:21:34 +08:00
bunnie
6da0482831 add screen feedback for baosec target on updates 2025-10-04 16:21:06 +08:00
bunnie
9b11361256 fixup loader heap; move signature validation; fixup swap structures
- loader heap is now fixed in a "throw-away" region of memory.
this means the heap should only be used sparingly, and somewhat
dangerously, because the values can't persist beyond the lifetime
of the loader.

- signature validation moved earlier

- fixup swap structures to refer to the API so that image creation
is easier/consistent
2025-10-04 00:56:18 +08:00
bunnie
07e43d4459 minor cleanup in builder code for specifying swap regions 2025-10-04 00:55:17 +08:00
bunnie
7f9b783027 mirror board constants from API; make SPIM channel a const
this implements the API/HAL split on the HAL side, and also
reveals SPIM channel as a constant that can be just read out
so that spim accessors that need to build from raw parts
can do it without having to re-allocate IOs.
2025-10-04 00:53:22 +08:00
bunnie
869da85ef7 add swap descriptors as structures; add offsets for boards
In the API layer, the boards aren't setup with convenience flags.
they are all laid out and the caller needs to know which board
it's trying to resolve. This is because the API layer is agnostic
to board and assumes the tool working with it knows what board
it's working with already.

The HAL layer tries to hide the board-specific stuff, and so
API defines are re-imported there in a board-transparent fashion.

Also add swap descriptors to the API crate, so that the image
generation tools can refer to the exact same structures as
are used inside the code, simplifying image creation maintenance.
2025-10-04 00:51:25 +08:00
bunnie
2175ea60f1 improve the tools for creating images
- use more structural templating to place data, instead of
just hand-coded writes to a buffer

- add private key signature generation to the swap image
2025-10-04 00:49:56 +08:00
bunnie
1b36c34341 add swap/spim writing to boot1 2025-10-04 00:48:23 +08:00
bunnie
86f0c60d95 refactor argument merging
the original rather unsafe version is replaced with a more readable
version that has a number of safety checks applied.

in the process of doing this, we now support merging of multiple
argument regions and a variable number of tags to merge.

tested to work on at least the base case of one swap region to
merge into the list.
2025-10-02 16:35:16 +08:00
bunnie
e1537328fa light refactoring of kernel arguments structure
this is a fairly complicated bit of legacy code that we're
trying to make slightly better/more readable.

some docs are added, as well as getting rid of a bunch of
"magic" constants, instead preferring to map things into
structured data where possible.

also fixed the location of the heap allocation relative to
the boot flow. It's now in a spot where I think we can
safely put dynamically allocated kernel arguments.
2025-10-02 02:17:45 +08:00
bunnie
76e22e3d0a cleanup warnings 2025-10-01 23:58:49 +08:00
bunnie
a1c1c85a5f add signature check to kernel 2025-10-01 23:53:44 +08:00
bunnie
9d2311f9ce add remaining pin setups in the loader
this simplifies the kernel's boot job a little bit by
having all the I/O resources set up by the loader.
2025-10-01 23:39:43 +08:00
bunnie
634ccd6c38 add adjustable signature block offsets based on the target
bao1x has a smaller, more efficient signature block that
folds more data into the signed region.
2025-10-01 23:38:48 +08:00
bunnie
4c84fc523d remove deprecated testing feature 2025-10-01 23:38:28 +08:00
bunnie
0437a1263b remove deprecated loader features 2025-10-01 23:38:05 +08:00
bunnie
60d6e37b7d remove unused assembly code 2025-10-01 23:37:03 +08:00
bunnie
07e7197517 upgrade the sigcheck boot routine to pass kernel arguments
all other boot modes would get an a0 with the address that the
kernel is "supposed" to be located. this is neither security
sensitive or problematic.
2025-10-01 23:36:14 +08:00
bunnie
ec9aed29dd fix kernel offset so signature doesn't shift the image
the image needs to be page-aligned so it can do direct-map
to memory.
2025-10-01 23:35:24 +08:00
bunnie
8e4d1d047f remove debug prints from usb userspace
these conflict with the kernel debug prints.
2025-10-01 23:34:53 +08:00
bunnie
d3c55b218f turn on the power supply for the camera 2025-10-01 23:34:35 +08:00
bunnie
73192dc2d8 cleanup on boot1
main thing in this commit is remembering to activate PWM
mode on DCDC2 for a quieter power supply. the chip draws
so little power that the power-saving regulator hiccups
and has too much ripple.
2025-10-01 23:33:35 +08:00
bunnie
faa13e71f3 speedup firmware update writes by eliminating debug print 2025-10-01 23:32:54 +08:00
bunnie
444ae53a11 add cleanup for USB stack
have to shut it down gracefully or the next stage won't run.
2025-10-01 23:32:21 +08:00
bunnie
b86664d279 move camera clock pin setup into the camera driver in Xous.
previously this was setup in the loader, which is a bit of an
abstraction bodge.
2025-10-01 15:00:40 +08:00
bunnie
483e8f3508 the great loader culling
The loader grew a lot of hair over the past few months as it
was abused as a baremetal environment for chip bring-up.

A baremetal environment was explicitly created to help with that,
so we don't have to pollute the loader with lots of unused features
and ancilliary code.

Furthermore, a decision was made to eliminate updates from the
loader code base - the loader is just for setting up Xous. This
allows the loader to be more platform-agnostic.

Boot1 instead contains all the platform-specific code for doing updates.

For completeness, we note that boot0 is a minimal piece of code that is the
first step in the chain of trust and is intended to be a read-only
segment of code that has public keys baked into it that are used
to bootstrap the rest of the ecosystem.

At this point, the loader is now slimmed down and runs. Still needs
testing to make sure the culling wasn't too aggressive, but I am
much happier with where this is landing as the loader is once again
just focused on getting Xous up and running.
2025-10-01 14:57:40 +08:00
bunnie
1d9c8e8121 cleanup unused code and make ifram mappings extremely clear 2025-10-01 14:57:10 +08:00
bunnie
f8c92c4c23 fix loader function code mapping 2025-10-01 14:55:19 +08:00
bunnie
e77d412bad extract the peripheral reset line 2025-10-01 14:29:04 +08:00
bunnie
346d7cd4d4 indicate the space for the marquee line on the boot logo 2025-10-01 14:28:45 +08:00
bunnie
03744c2dca ops are no-std stafe 2025-10-01 14:28:13 +08:00