Commit graph

90 commits

Author SHA1 Message Date
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
bunnie
d49d46ee0d pre-hash sign the kernel image; normal signing for loader image
The loader image uses the original signing method, because changing
that would require us to modify the gateware ROM, which is a huge
pain in the ass, and doesn't buy us anything.

Thus only the kernel signing uses the pre-hash method.
2024-01-05 16:14:09 +08:00
bunnie
259852c1c6 add a routine to the signer that can do pre-hash images
This requires us to modify our dependencies to have dalek-ed25519
as one of our dependencies.

Which requires another patch in this commit set to implement
sha512 for hosts, since we patch the sha2 crate for all targets
to our local version.
2024-01-05 16:12:55 +08:00
bunnie
069edbc255 support multi-svd file designs
This patch set goes across all the toolchains and brings
in the support for split SVD descriptions of SoCs.

This is helpful for dealing with designs that have multiple
"top" files for the same core IP set. For exmaple, you may have
a SoC that you are developing that targets silicon, but
you have a version that wraps this in additional peripherals
available only in an FPGA emulator that are used for debugging.

In this case, you can have one SVD file be the description of
the SoC itself, and another SVD file describe just the "delta"
introduced by the FPGA wrapper that emulates/controls the SoC.
2023-07-17 16:27:09 +08:00
bunnie
1300771a38 fixes to make PR work 2023-06-16 01:29:55 +08:00
bunnie
7d3f0cd0f8 revert #368
this somehow causes the build to break, and I just checked and
I don't see warnings on our build. There must be some config
differences on hosts, but I'm not sure what it is...
2023-04-21 14:16:28 +08:00
Jean-Pierre De Jesus DIAZ
60a5acbfcf
tools/sign_image: fix warnings
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2023-04-20 15:41:15 +02:00
bunnie
3ca8f669a3 breaking change in svd2utra: fix deprecation of quick-xml
quick-xml 0.19.0, a dependency of svd2utra, uses features
that Rust will deprecate.

Unfortunately, the only versions of quick-xml that do not
use the deprecated language features also break a portion
of the API. In particular, quick-xml will no longer take
a `File` as an input: it will only take a `Path`.

This means that the API for svd2utra is also broken, because
originally it was designed to take a `File`

This patch refactors svd2utra to work with the latest quick-xml,
but also breaks any code that calls svd2utra's generate
APIs.

Fortunately this is fairly easy to fix, the calling code
will typically already have the Path somewhere in it, so
instead of opening the Path and passing it into the function,
one may simply pass in the Path.
2023-04-04 02:03:35 +08:00
eupn
8694eaa004
elf.rs: fix alignment edge case (take 2) 2023-03-27 18:41:45 +04:00
eupn
199ab0a73c
elf: fix a section alignment edge case 2023-03-27 16:29:07 +04:00