Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ run-esp32c6 = "run --release --target riscv32imac-unknown-none-elf --no-default-
run-esp32s2 = "run --profile esp32s2 --target xtensa-esp32s2-none-elf --no-default-features --features esp32s2 "
run-esp32s3 = "run --release --target xtensa-esp32s3-none-elf --no-default-features --features esp32s3 "

# Test alias
test-ota = "test --package ota --target x86_64-unknown-linux-gnu"

# ota-packer aliases
build-ota-packer = "build --package ota --bin ota-packer --target x86_64-unknown-linux-gnu"
ota-packer = "run --package ota --bin ota-packer --target x86_64-unknown-linux-gnu"


[target.xtensa-esp32-none-elf]
runner = "espflash flash --baud=921600 --monitor --chip esp32"
rustflags = ["-C", "link-arg=-nostartfiles", '--cfg=feature="esp32"']
Expand Down
21 changes: 18 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ on:
workflow_dispatch:

jobs:
build:
name: Build ${{ matrix.device.soc }}
espressif-targets:
name: Espressif target ${{ matrix.device.soc }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -53,4 +53,19 @@ jobs:
if: ${{ contains(fromJson('["esp32c6"]'), matrix.device.soc) }}
run: |
cargo +${{ matrix.device.toolchain }} clippy --features ${{ matrix.device.soc }} --target riscv32imac-unknown-none-elf -- -D warnings
cargo +${{ matrix.device.toolchain }} fmt -- --check
cargo +${{ matrix.device.toolchain }} fmt -- --check
ota-packer:
name: OTA Packer
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Stable Rust Toolchain
uses: dtolnay/rust-toolchain@v1
with:
target: riscv32imac-unknown-none-elf
toolchain: stable
- name: Build utility
run: cargo build-ota-packer
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Std tests

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
ota-packer:
name: OTA tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Stable Rust Toolchain
uses: dtolnay/rust-toolchain@v1
with:
target: riscv32imac-unknown-none-elf
toolchain: stable
- name: Package test
run: cargo test-ota
108 changes: 108 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions ota/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,16 @@ default = []
std = []

[dependencies]
sunset.workspace = true
sunset-async.workspace = true

log.workspace = true
sha2.workspace = true

# Only for helpers and tests
[target.'cfg(not(target_os = "none"))'.dependencies]
clap = "4.5"

[[bin]]
name = "ota-packer"
path = "src/bin/ota-packer.rs"
49 changes: 49 additions & 0 deletions ota/src/bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Purpose of ota-packer

The content of this file is provided for illustrative purposes. For a complete understanding of what this utility does read `ota-packer.rs`.

This binary is a helper cli application to pack binary files together with a header to allow for the sftp-ota procedure to validate the binary before applying the OTA.

## What this tool does

It takes one binary file and adds the following Type Length Value fields (TLV):

- ota type: SSH-Stamp "magic number" used to identify the ota file as SSH-Stamp. Any other value should be rejected in a OTA procedure by an SSH-Stamp binary.
- checksum: SHA256 checksum of the binary. SSH-Stamp will calculate the checksum of the binary uploaded and will abort the OTA if it does not match this field.
- binary length: Additional validation step. SSH-Stamp will only write/validate the announced bytes into flash memory. A target chip with an ota partition smaller than the announced binary length should abort the OTA.

## What this tool does not...

... and it might do in the future:

- Sign the binary
- Add information about the target architecture to help the target instance aborting a wrong binary.

... and will definitely not do:

- Upload the OTA to the target device (The user does this with any standard SFTP client and the appropriate credentials)
- Validate or test in any way the binary

## Usage

For updated information on how to use this tool build and run the binary from the `ssh-stamp/ota` directory

```sh
ssh-stamp/ota$ cargo run --bin ota-packer -- --help
```

At the moment of redaction, this command outputs:

```sh
SSH-Stamp utility 0.1.0 to pack (unpack) OTA update files adding the required metadata.

Usage: ota-packer [OPTIONS] <FILE>

Arguments:
<FILE> The file to process

Options:
-u, --unpack Unpacks a OTA file. Will save to <file> with .ota.npkd extension
-p, --pack (default) Packs a binary file as an OTA file. Will save to <file>.ota
-h, --help Print help
```
Loading
Loading