Commit graph

74 commits

Author SHA1 Message Date
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
bunnie
08ae66a264 fix: #320
this commit adds the facilities to extract eh_frame[_header]
sections and pass it to each process.

A bump is required to `std` to extract the passed parameters.
2023-02-15 19:55:08 +08:00
bunnie
43c73c0d6c align sections of the MiniElf
Sections of the MiniElf are now aligned as required by the
source ELF requirements. This is required for direct-mapping
with XIP.

the overhead is just a few bytes every couple of programs, so it's
a small price to pay for XIP.
2023-02-12 01:13:30 +08:00
bunnie
68c9865072 fix the assumption about all alignments being identical
figured out a way to modify the trait so that alignments
are 0 by default, and only set/reported for IniF,
on a per-process basis so if for some reason the alignments
change we should be OK.
2023-02-08 04:57:52 +08:00
bunnie
29f050a8ad fix alignment for IniF region so page mappings are 1:1
Turns out, the pointing end of the stick for ELF sections don't start
at a page boundary. For example:

5    IniF: entrypoint @ 0001e42e, loaded from 000440f4.  Sections:
    Loaded from 000440f4 - Section .rodata        16924 bytes loading into 000100f4..00014310 flags: NONE
    Loaded from 00048310 - Section .eh_frame_hdr   1772 bytes loading into 00014310..000149fc flags: NONE
    Loaded from 000489fc - Section .eh_frame       6004 bytes loading into 000149fc..00016170 flags: NONE
    Loaded from 0004a170 - Section .text          59876 bytes loading into 00017170..00025b54 flags: EXECUTE
    Loaded from 00058b54 - Section .sdata            48 bytes loading into 00026b54..00026b84 flags: WRITE
    Loaded from 00058b84 - Section .sbss             48 bytes loading into 00026b84..00026bb4 flags: WRITE | NOCOPY
    Loaded from 00058bb4 - Section .bss             516 bytes loading into 00026bb8..00026dbc flags: WRITE | NOCOPY

Here you can see, the data is "loading into" 0x100f4, not
0x10000. The original PR would align things to a page, which means
you'd still have an offset mismatch if you tried to map these directly
over.

This patch causes IniF to insert extra padding to target
the offset necessary for the MiniElf to map 1:1.

An important assumption is the offset is constant across all
programs being linked. This seems to be the case, but, if this
assumption breaks, then the padding will also break.
2023-02-08 04:47:29 +08:00
bunnie
9889856ede page-align processes within the kernel image 2023-02-07 21:10:23 +08:00
Sean Cross
f861af7620 tools: elf: fix copy-elf when gcc links program
GCC will set the text size to `0` in a certain case that `rust-lld` did
not. This causes the elf copier to add about 512 MB to the image which
it otherwise shouldn't be doing.

Add a workaround that appears to fix the issue.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-11-04 12:27:13 +08:00
Sean Cross
bad8ba5ea2 tools: sign-image: write remainder of file
During the previous port, we only wrote the first 4096 bytes. Write the
remainder of the file to the destination.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-10-26 23:40:09 +08:00
Sean Cross
22de2bc614 tools: sign_image: fix utterly broken git signing
The previous approach didn't work, for unknown reasons.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-10-26 22:32:24 +08:00
Sean Cross
2cf8ff12a6 tools: add make-renode-boot
This experimental tool can be used to create all-in-one images based
on precomputed file lists. It generates "test images" using just the
bare minimum number of processes.

This program includes all the keys, kernel, and initial images required
to support a simple program.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-10-26 22:22:31 +08:00
Sean Cross
2382d57dd6 tools: add sign_image.rs
Signed-off-by: Sean Cross <sean@xobs.io>
2022-10-26 22:22:18 +08:00
Sean Cross
46cd5e7098 tools: elf: allow loading files from &[u8]
Instead of assuming everything is a file or a path, allow
loading ELF files from u8 slices. This will enable us to create
images with `include_bytes!()`.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-10-26 22:21:24 +08:00
Sean Cross
c50314d4a8 tools: sign-image: break image signing into a library
Move the code used to sign images into its own library file. This will
enable us to use the image signing functions from other code.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-10-26 22:20:33 +08:00
bunnie
86d2437f03 improve formatting so section alignments are easier to debug 2022-10-20 16:14:56 +08:00
Sean Cross
ff3f307a14 tools: read-tags: call output xous_presign.img
The use of the name `args.bin` is now deprecated.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-10-20 14:11:48 +08:00
bunnie
7248f47ca8 fix self-signing to reflect extra data for semvers
the loader is a little funky, and requires some maintainer hand-holding
due to the split of the page ownership between the root-keys
crate and the graphics-server crate.

Improved docs so I don't forget this detail in the future.
2022-07-11 16:11:32 +08:00
bunnie
1256fcb411 add min version requirement and current version to kernel and loader 2022-07-08 18:56:05 +08:00