Commit graph

99 commits

Author SHA1 Message Date
bunnie
e9d8ec8f1d add better debug output from the image generator
this helps to see when address ranges are truncated or missing
2025-11-25 19:05:32 +08:00
bunnie
0efcd0af90 clean up a debug print 2025-10-16 23:26:30 +08:00
bunnie
ea8927fc55
Fixup sign_image to generate records with the new auth_data format 2025-10-06 23:34:30 +08:00
bunnie
54ee8ffd83 update sign_image to work with the new public key records 2025-10-06 15:19:52 +08:00
bunnie
3c68eea714
Merge branch 'main' into signing 2025-10-06 13:45:29 +08:00
bunnie
6d4f8004d3 fix breakage associated with changes to xous-semver 2025-10-06 13:17:21 +08:00
bunnie
4413b95162 place the public key in the correct location 2025-10-06 03:50:09 +08:00
bunnie
12e6292325 extend the image building tools to handle detached apps 2025-10-05 17:11:30 +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
d21e99a3f3 implement swap header length reference 2025-10-04 18:52:50 +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
f8c92c4c23 fix loader function code mapping 2025-10-01 14:55:19 +08:00
bunnie
f04a856037 allow .bin as uf2 conversion target 2025-10-01 02:56:53 +08:00
bunnie
76f6f1fda5 pack offsets into a u16-sized pointer
the data section is generally pretty small, a few k, and there
are cases where we need more initialization entries. This keeps
the structure from growing beyond 256 bytes.
2025-09-30 21:50:17 +08:00
bunnie
d9347e46fb update tools to generate a uf2 image 2025-09-29 16:17:45 +08:00
bunnie
a9112a743a add mapping for loader in image signing (synonymous with baremetal) 2025-09-29 13:51:58 +08:00
bunnie
d502aed5af refactor image creation to be cleaner
use struct-based API and bytemuck instead of manual byte serialization.
this is for the bao1x target, precursor still uses the legacy code.
2025-09-26 22:55:39 +08:00
bunnie
198e584369 add adjustable signature sector sizes
can be smaller than 4k now because on baochip the erase sector
size is just 32 bytes.
2025-09-24 23:50:13 +08:00
bunnie
024c8131bc extend image builder to handle baking in statics 2025-09-21 21:50:31 +08:00
bunnie
1255bf12d9 FLAG DAY: fix all names to harmonize around 'bao1x'
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.
2025-09-18 21:25:51 +08:00
bunnie
c61a521c7d add size on disk reporting 2025-09-10 09:16:53 +08:00
bunnie
7d89deacb4 auto-generate code snippet for baremetal to bootstrap its .data region 2025-08-10 15:48:48 +08:00
bunnie
c58edf9598 use the loader version of copy object call for copying the loader
this handles the special case of not inserting RAM-based data segments into
the ROM.
2025-02-28 16:33:58 +08:00
bunnie
46b0e6b842 fix loader edge case with static data
include a check for assumption violations, and some explanation
on how this all comes about
2025-02-28 16:23:54 +08:00
bunnie
4f14a67504 formatting changes due to changes in nightly rust
needed to get a clean check on gh
2025-02-01 22:26:40 +08:00
bunnie
043dfd84ae update formatting to latest nightly rules 2024-09-24 01:49:45 +08:00
bunnie
80dbf071be don't map errors so we can see what the underlying problem is 2024-05-21 04:03:45 +08:00
bunnie
63c316f32a fix image creation
1. nonce should be generated from the LSB of the commit hash.
security doesn't come from the nonce, and having the commit hash
in the nonce is helpful for version control of the swap image
(although it doesn't capture "dirty" builds, e.g. builds
made with uncommitted changes).

2. fix IniS regions to not require special alignment. Since the
data is copied (similar to IniE), we don't have to waste space
page-aligning things so that offsets map perfectly between
the image on disk and in RAM.

3. add checks that the loading position of data inside the
swap image matches our expectations. We should have 0x1000
bytes of unencrypted header, then 0x1000 bytes of XArgs + padding,
and then image data should start.

There is a "just so" coincidence in that the image data by
the MiniElf program always lines up at an address > 0x1000, making
space for the XArgs. I actually don't know why this padding is
there, but the "section" doesn't decode to anything we
can parse. Maybe it's some reserved space for OS-specific
loader shenanigans?
2024-05-06 18:49:18 +08:00
bunnie
9499a41739 fix padding computations in ELF file read-in
Not sure how this even worked in the first place....I think we
always just got lucky with the size of .gcc_except_table. However,
something changed in the last rustc update that causes this section
to align to a 256-byte boundary instead of a 4-byte boundary, which
exposes downstream alignment issues.

This patch now captures the actual offset alignment + padding,
which is somewhat complicated by the fact that we throw away
the first section (not sure why??? it doesn't seem to have
a valid name or header, but the first 0x114 bytes are non-existent)
so we have to factor this into all the downstream padding efforts.
2024-05-01 02:19:10 +08:00
bunnie
9ca720f188 add an assert to sanity-check that IniF sections are aligned
There is no hope for success if the alignment of an IniF is not
aligned, since we directly map the data into memory.
2024-05-01 02:18:29 +08:00
bunnie
9d2218488b add jump past signature block
Make the first word in the signature block a jump past the block
this is for the cramium target, where the best memory efficiency
happens if we align the data to the bottom of the memory. This
means that the signature block ends up "in the way" of the boot
process, because the reset vector can only be configured to something
on a 16k-page boundary (e.g., we'd waste 15k of memory without this).

This will require some reworking of the existing code base for
checking signatures down the line.
2024-04-26 18:13:06 +08:00
bunnie
4ace363abc this resolves comments from @xobs' code review 2024-04-09 18:23:09 +08:00
bunnie
400088fb42 add debug file generation for swap 2024-04-08 23:47:54 +08:00
bunnie
d489e14f3a fix nonce generation (offset should be bytes, not pages) 2024-04-07 22:37:22 +08:00
bunnie
3079da3a57 add debug provisions to encryption; limit AAD to 64 bytes 2024-04-07 00:38:34 +08:00
bunnie
d9b29c2d06 move the MAC (i.e. tag) above the variable length AAD field. 2024-04-06 22:55:39 +08:00
bunnie
28d07da7f1 add the flash offset of the swap region in swap args
Each platform interprets this differently.

On Precursor, it's the offset in FLASH of the swap region.

Probably, flags should be added to configure this somehow for each
platform, but still figuring a lot of things out.

The plan is on Cramium for the swap data to always be at 0
in the external SPI, so, we don't store an offset (field is
ignored).
2024-04-05 16:45:24 +08:00
bunnie
2a68ee098f fix main memory patching for swap config on precursor 2024-04-04 19:24:38 +08:00
bunnie
cf32b4edb5 patching routine for memory regions.
ended up not being used because main memory is a special case :P
2024-04-04 19:24:17 +08:00
bunnie
aff3620bdf make argument start/offset visible
so we can patch it up for the swap testing on precursor
2024-04-04 19:23:49 +08:00
bunnie
9c0ac72aae add storage for the swap encryption key
This is set to 0 in the image creator, but the keying ceremony
should set this to something more secure after the device has
been initialized (and likewise, re-encrypt the swap region
to match the new, secure key).
2024-04-04 18:45:16 +08:00
bunnie
39e8184b5d chore: add a comment 2024-04-04 18:45:02 +08:00
bunnie
932f13b532 rework create-image to put inis objects into the detached swap region 2024-04-04 18:34:00 +08:00
bunnie
e1dbd6726b add the swap_writer module to the library 2024-04-04 18:33:29 +08:00
bunnie
9eebf5dd05 add the swap writer
This will take the buffer that is generated from a xous argument
and encrypts it to the prescribed "detached swap" format.
2024-04-04 18:32:45 +08:00
bunnie
c0484ca607 chore: fix formatting 2024-03-23 12:02:54 +08:00
bunnie
fdbdea5ab0 add swap tag to image creation 2024-03-23 11:59:31 +08:00
bunnie
38f0002294 partial progress on create-image
create-image can now genereate inis sections

still needs to kick out a `swap` argument for the bootloader
so it knows where swap should go.
2024-03-23 11:59:31 +08:00
bunnie
01cec25388 upgrade API on helper tools
even though they run on the host, old pins inflate the codespace
since they are part of the workspace
2024-02-08 14:21:10 +08:00
bunnie
a09fa70bc9 format tools 2024-01-14 23:00:13 +08:00