diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 25cdcc8c..e4e5f671 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -50,9 +50,6 @@ jobs: - name: cargo fmt --check (bootloader-tool) run: cargo fmt --check working-directory: "./bootloader-tool" - - name: cargo fmt --check (mcxa-security-provisioning) - run: cargo fmt --check - working-directory: "./mcxa-security-provisioning" clippy: runs-on: ubuntu-latest @@ -85,9 +82,6 @@ jobs: - name: cargo clippy (bootloader-tool) run: cargo clippy --locked -- -D clippy::suspicious -D clippy::correctness -D clippy::perf -D clippy::style working-directory: "./bootloader-tool" - - name: cargo clippy (mcxa-security-provisioning) - run: cargo clippy --locked -- -F clippy::suspicious -D clippy::correctness -F clippy::perf -F clippy::style - working-directory: "./mcxa-security-provisioning" # Enable once we have a released crate # semver: @@ -207,12 +201,6 @@ jobs: log-level: warn manifest-path: ./examples/mcxa-577app/Cargo.toml command: check - - name: Cargo deny (mcxa-security-provisioning) - uses: EmbarkStudios/cargo-deny-action@v2 - with: - log-level: warn - manifest-path: ./mcxa-security-provisioning/Cargo.toml - command: check msrv: # check that we can build using the minimal rust version that is specified by this crate @@ -252,9 +240,6 @@ jobs: - name: cargo +${{ matrix.msrv }} check (bootloader-tool) run: cargo check --locked working-directory: "./bootloader-tool" - - name: cargo +${{ matrix.msrv }} check (mcxa-security-provisioning) - run: cargo check - working-directory: "./mcxa-security-provisioning" fuzz: runs-on: ubuntu-latest diff --git a/.vscode/settings.json b/.vscode/settings.json index f8a67fcd..5bbab06c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,22 +1,10 @@ { - "[markdown]": { - "editor.formatOnSave": false - }, - "[toml]": { - "editor.formatOnSave": true - }, - "[rust]": { - "editor.formatOnSave": true - }, "rust-analyzer.cargo.sysroot": "discover", "rust-analyzer.check.allTargets": false, "rust-analyzer.check.command": "clippy", "rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf", "rust-analyzer.linkedProjects": [ "${workspaceFolder}/libs/Cargo.toml", + "${workspaceFolder}/examples/mcxa-577app/Cargo.toml", ], - "rust-analyzer.cargo.features": [ - "mimxrt685s-evk", - "imxrt" - ] } diff --git a/examples/mcxa-577app/Cargo.lock b/examples/mcxa-577app/Cargo.lock index 248ea4ea..605efdd4 100644 --- a/examples/mcxa-577app/Cargo.lock +++ b/examples/mcxa-577app/Cargo.lock @@ -2,18 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.5" @@ -29,49 +17,6 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" -[[package]] -name = "arraydeque" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" - -[[package]] -name = "askama" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4" -dependencies = [ - "askama_derive", - "itoa", - "percent-encoding", - "serde", - "serde_json", -] - -[[package]] -name = "askama_derive" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f" -dependencies = [ - "askama_parser", - "memchr", - "proc-macro2", - "quote", - "rustc-hash", - "syn 2.0.119", -] - -[[package]] -name = "askama_parser" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358" -dependencies = [ - "memchr", - "winnow", -] - [[package]] name = "autocfg" version = "1.5.1" @@ -110,18 +55,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitvec" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddcec3d12c579d40898fe0a9a358a803c23e9c52ca3c425707f81c9436211837" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "byteorder" version = "1.5.0" @@ -130,9 +63,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.4.4" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad534f4357a5264cce5019c989cf66a4f0dc4e0d1b1d15f8aacec0ff7360273" +checksum = "005ec2760ca554fae18df7a11195552ec576cd665632a881bc011d5bb2fd4d80" dependencies = [ "find-msvc-tools", "shlex", @@ -156,15 +89,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bd422bfb4f24a97243f60b6a4443e63d810c925d8da4bb2d8fde26a7c1d57ec" -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "convert_case" version = "0.11.0" @@ -286,17 +210,6 @@ dependencies = [ "syn 2.0.119", ] -[[package]] -name = "dd-manifest-tree" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5793572036e0a6638977c7370c6afc423eac848ee8495f079b8fd3964de7b9f9" -dependencies = [ - "serde_json", - "toml", - "yaml-rust2", -] - [[package]] name = "defmt" version = "0.3.100" @@ -369,46 +282,6 @@ dependencies = [ "defmt 1.1.1", ] -[[package]] -name = "device-driver" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e4547bd66511372d2a38ac3c1b2892c7ebf83cf0d5411c3406e496c85a1d96" -dependencies = [ - "device-driver-macros", - "embedded-io 0.6.1", - "embedded-io-async 0.6.1", -] - -[[package]] -name = "device-driver-generation" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f0170a2ef7fb5a74029c3edcaff07a0d44dbfac3d9dcfbb06fc696f890bb877" -dependencies = [ - "anyhow", - "askama", - "bitvec", - "convert_case 0.6.0", - "dd-manifest-tree", - "itertools", - "prettyplease", - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "device-driver-macros" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176dbf719ece32afb641bf50d2d1881411ad1677aec6c8bf42011a7c279d97ff" -dependencies = [ - "device-driver-generation", - "proc-macro2", - "syn 2.0.119", -] - [[package]] name = "document-features" version = "0.2.12" @@ -435,12 +308,10 @@ dependencies = [ "cortex-m", "defmt 0.3.100", "defmt-or-log", - "device-driver", "ec-slimloader", "ec-slimloader-state", "embassy-mcxa", - "embassy-sync", - "embassy-time", + "embassy-sync 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-storage-async", "heapless 0.8.0", "partition-manager", @@ -459,20 +330,14 @@ dependencies = [ "num_enum", ] -[[package]] -name = "either" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34" - [[package]] name = "embassy-embedded-hal" version = "0.6.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ - "embassy-futures", + "embassy-futures 0.1.2 (git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e)", "embassy-hal-internal", - "embassy-sync", + "embassy-sync 0.8.0 (git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e)", "embedded-hal 0.2.7", "embedded-hal 1.0.0", "embedded-hal-async", @@ -484,20 +349,46 @@ dependencies = [ [[package]] name = "embassy-executor" version = "0.10.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0d3b15c9d7dc4fec1d8cb77112472fb008b3b28c51ad23838d83587a6d2f1e" dependencies = [ "cordyceps", "cortex-m", "critical-section", "document-features", - "embassy-executor-macros", - "embassy-executor-timer-queue", + "embassy-executor-macros 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "embassy-executor-timer-queue 0.1.0", +] + +[[package]] +name = "embassy-executor" +version = "0.10.0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" +dependencies = [ + "cordyceps", + "critical-section", + "document-features", + "embassy-executor-macros 0.8.0 (git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e)", + "embassy-executor-timer-queue 0.1.1", + "unitrait", ] [[package]] name = "embassy-executor-macros" version = "0.8.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d11a246f53de5f97a387f40ac24726817cd0b6f833e7603baac784f29d6ff276" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "embassy-executor-macros" +version = "0.8.0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ "darling", "proc-macro2", @@ -508,17 +399,32 @@ dependencies = [ [[package]] name = "embassy-executor-timer-queue" version = "0.1.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fc328bf943af66b80b98755db9106bf7e7471b0cf47dc8559cd9a6be504cc9c" + +[[package]] +name = "embassy-executor-timer-queue" +version = "0.1.1" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" +dependencies = [ + "unitrait", +] + +[[package]] +name = "embassy-futures" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc2d050bdc5c21e0862a89256ed8029ae6c290a93aecefc73084b3002cdebb01" [[package]] name = "embassy-futures" version = "0.1.2" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" [[package]] name = "embassy-hal-internal" version = "0.5.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ "cortex-m", "critical-section", @@ -528,20 +434,20 @@ dependencies = [ [[package]] name = "embassy-mcxa" version = "0.1.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ "bbqueue", - "convert_case 0.11.0", + "convert_case", "cortex-m", "cortex-m-rt", "critical-section", "defmt 1.1.1", "embassy-embedded-hal", - "embassy-executor", - "embassy-futures", + "embassy-executor 0.10.0 (git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e)", + "embassy-futures 0.1.2 (git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e)", "embassy-hal-internal", - "embassy-sync", - "embassy-time", + "embassy-sync 0.8.0 (git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e)", + "embassy-time 0.5.1 (git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e)", "embassy-time-driver", "embassy-time-queue-utils", "embedded-can", @@ -549,8 +455,8 @@ dependencies = [ "embedded-hal 1.0.0", "embedded-hal-async", "embedded-hal-nb", - "embedded-io 0.7.1", - "embedded-io-async 0.7.0", + "embedded-io", + "embedded-io-async", "embedded-storage", "grounded", "heapless 0.9.3", @@ -571,11 +477,25 @@ dependencies = [ [[package]] name = "embassy-sync" version = "0.8.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bbd85cf5a5ae56bdf26f618364af642d1d0a4e245cdd75cd9aabda382f65a81" dependencies = [ "cfg-if", "critical-section", - "embedded-io-async 0.7.0", + "embedded-io-async", + "futures-core", + "futures-sink", + "heapless 0.9.3", +] + +[[package]] +name = "embassy-sync" +version = "0.8.0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" +dependencies = [ + "cfg-if", + "critical-section", + "embedded-io-async", "futures-core", "futures-sink", "heapless 0.9.3", @@ -584,7 +504,8 @@ dependencies = [ [[package]] name = "embassy-time" version = "0.5.1" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "592b0c143ec626e821d4d90da51a2bd91d559d6c442b7c74a47d368c9e23d97a" dependencies = [ "cfg-if", "critical-section", @@ -597,10 +518,25 @@ dependencies = [ "futures-core", ] +[[package]] +name = "embassy-time" +version = "0.5.1" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" +dependencies = [ + "cfg-if", + "critical-section", + "document-features", + "embassy-time-driver", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-async", + "futures-core", +] + [[package]] name = "embassy-time-driver" version = "0.2.2" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ "document-features", ] @@ -608,9 +544,9 @@ dependencies = [ [[package]] name = "embassy-time-queue-utils" version = "0.3.2" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ - "embassy-executor-timer-queue", + "embassy-executor-timer-queue 0.1.1", "heapless 0.9.3", ] @@ -658,34 +594,19 @@ dependencies = [ "nb 1.1.0", ] -[[package]] -name = "embedded-io" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" - [[package]] name = "embedded-io" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9eb1aa714776b75c7e67e1da744b81a129b3ff919c8712b5e1b32252c1f07cc7" -[[package]] -name = "embedded-io-async" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff09972d4073aa8c299395be75161d582e7629cd663171d62af73c8d50dba3f" -dependencies = [ - "embedded-io 0.6.1", -] - [[package]] name = "embedded-io-async" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2564b9f813c544241430e147d8bc454815ef9ac998878d30cc3055449f7fd4c0" dependencies = [ - "embedded-io 0.7.1", + "embedded-io", ] [[package]] @@ -703,15 +624,6 @@ dependencies = [ "embedded-storage", ] -[[package]] -name = "encoding_rs" -version = "0.8.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" -dependencies = [ - "cfg-if", -] - [[package]] name = "equivalent" version = "1.0.2" @@ -720,9 +632,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "find-msvc-tools" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890" +checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d" [[package]] name = "fnv" @@ -730,12 +642,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "futures-core" version = "0.3.34" @@ -781,30 +687,12 @@ dependencies = [ "byteorder", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", -] - [[package]] name = "hashbrown" version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" -[[package]] -name = "hashlink" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" -dependencies = [ - "hashbrown 0.14.5", -] - [[package]] name = "heapless" version = "0.8.0" @@ -833,29 +721,14 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "2.14.0" +version = "2.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" dependencies = [ "equivalent", - "hashbrown 0.17.1", + "hashbrown", ] -[[package]] -name = "itertools" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" - [[package]] name = "lazy_static" version = "1.5.0" @@ -926,9 +799,9 @@ dependencies = [ "cortex-m-rt", "defmt 1.1.1", "defmt-rtt", - "embassy-executor", + "embassy-executor 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "embassy-mcxa", - "embassy-time", + "embassy-time 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "panic-probe", ] @@ -944,9 +817,9 @@ dependencies = [ "ec-slimloader", "ec-slimloader-mcxa", "ec-slimloader-state", - "embassy-executor", + "embassy-executor 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "embassy-mcxa", - "embassy-sync", + "embassy-sync 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapless 0.8.0", "mcxa-security-provisioning", "panic-probe", @@ -962,10 +835,9 @@ dependencies = [ "defmt 0.3.100", "defmt-or-log", "ec-slimloader-mcxa", - "embassy-futures", + "embassy-futures 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "embassy-mcxa", - "embassy-sync", - "embassy-time", + "embassy-sync 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-storage-async", "partition-manager", "partition-manager-macros", @@ -1076,7 +948,7 @@ name = "partition-manager" version = "0.1.0" source = "git+https://github.com/OpenDevicePartnership/embedded-services.git?tag=v0.1.0#6034c6bf3d2d7bfe50821370be7c1275fbf8520a" dependencies = [ - "embassy-sync", + "embassy-sync 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-storage-async", "partition-manager-macros", ] @@ -1110,12 +982,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" -[[package]] -name = "percent-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" - [[package]] name = "pin-project" version = "1.1.13" @@ -1151,16 +1017,6 @@ dependencies = [ "critical-section", ] -[[package]] -name = "prettyplease" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" -dependencies = [ - "proc-macro2", - "syn 2.0.119", -] - [[package]] name = "proc-macro2" version = "1.0.107" @@ -1179,12 +1035,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand_core" version = "0.6.4" @@ -1232,15 +1082,14 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" -[[package]] -name = "rustc-hash" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" - [[package]] name = "rustc_version" version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] [[package]] name = "rustversion" @@ -1254,6 +1103,21 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + [[package]] name = "serde" version = "1.0.229" @@ -1281,21 +1145,7 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn 3.0.4", -] - -[[package]] -name = "serde_json" -version = "1.0.151" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" -dependencies = [ - "indexmap", - "itoa", - "memchr", - "serde", - "serde_core", - "zmij", + "syn 3.0.5", ] [[package]] @@ -1324,9 +1174,9 @@ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" [[package]] name = "smallvec" -version = "1.15.2" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" +checksum = "b9be42f50aa861c555654aa3a37f52f4b1074bacf4e48fe0ef7fa584e80f1f0f" [[package]] name = "stable_deref_trait" @@ -1362,21 +1212,15 @@ dependencies = [ [[package]] name = "syn" -version = "3.0.4" +version = "3.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6275cddf4610d1775e6d1fe9469b2e77d0f39fd98fb7450901b821e0c53649f" +checksum = "12df2e0110f65b775f769bb17ef989067a1d931b2eb822bd4346631eeada89f9" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "thiserror" version = "2.0.20" @@ -1394,7 +1238,7 @@ checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" dependencies = [ "proc-macro2", "quote", - "syn 3.0.4", + "syn 3.0.5", ] [[package]] @@ -1438,16 +1282,9 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_write", "winnow", ] -[[package]] -name = "toml_write" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" - [[package]] name = "tracing" version = "0.1.44" @@ -1521,6 +1358,24 @@ version = "1.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" +[[package]] +name = "unitrait" +version = "2.0.0" +source = "git+https://github.com/embassy-rs/unitrait?rev=bb96601b3d293fa27d1ca2891f6ea148e534e433#bb96601b3d293fa27d1ca2891f6ea148e534e433" +dependencies = [ + "unitrait-macros", +] + +[[package]] +name = "unitrait-macros" +version = "2.0.0" +source = "git+https://github.com/embassy-rs/unitrait?rev=bb96601b3d293fa27d1ca2891f6ea148e534e433#bb96601b3d293fa27d1ca2891f6ea148e534e433" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "valuable" version = "0.1.1" @@ -1533,12 +1388,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "void" version = "1.0.2" @@ -1586,49 +1435,3 @@ checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" dependencies = [ "memchr", ] - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "yaml-rust2" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1a1c0bc9823338a3bdf8c61f994f23ac004c6fa32c08cd152984499b445e8d" -dependencies = [ - "arraydeque", - "encoding_rs", - "hashlink", -] - -[[package]] -name = "zerocopy" -version = "0.8.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556764e583adb45a9f8d413c2a147fa7e8d821e48e12b14fd560b607998b75eb" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.8.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ab42fc20575779bd240faa45f94a74256f755c0fa9e89f0ede20d91d0cdfc1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "zmij" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/examples/mcxa-577app/Cargo.toml b/examples/mcxa-577app/Cargo.toml index 881566bf..0584cb6c 100644 --- a/examples/mcxa-577app/Cargo.toml +++ b/examples/mcxa-577app/Cargo.toml @@ -5,33 +5,16 @@ members = [ "bootloader", ] -[workspace.package] -version = "0.1.0" -edition = "2021" -license = "MIT OR Apache-2.0" -repository = "https://github.com/OpenDevicePartnership/ec-slimloader" - [workspace.dependencies] -heapless = "0.8" partition-manager = { git = "https://github.com/OpenDevicePartnership/embedded-services.git", tag = "v0.1.0", default-features = false } partition-manager-macros = { git = "https://github.com/OpenDevicePartnership/embedded-services.git", tag = "v0.1.0" } -static_cell = "2.1" -embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-mcxa = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0", default-features = false } -embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0", default-features = false } -embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } +embassy-sync = "0.8.0" +embassy-mcxa = { git = "https://github.com/embassy-rs/embassy", rev = "f0fd6e2a8e9c505290498e316ad2bdda8b94da5e", default-features = false } +embassy-executor = "0.10.0" +embassy-time = "0.5.0" [patch.crates-io] -rustc_version = { path = "patches/rustc_version" } -embassy-embedded-hal = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-executor-macros = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-futures = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-hal-internal = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-time-driver = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-time-queue-utils = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } +embassy-time-driver = { git = "https://github.com/embassy-rs/embassy", rev = "f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" } [profile.dev] panic = "abort" diff --git a/examples/mcxa-577app/app/Cargo.toml b/examples/mcxa-577app/app/Cargo.toml index 405635ec..7b0bf1be 100644 --- a/examples/mcxa-577app/app/Cargo.toml +++ b/examples/mcxa-577app/app/Cargo.toml @@ -2,7 +2,7 @@ name = "mcxa-577app" version = "0.1.0" edition = "2021" -license.workspace = true +license = "MIT" [dependencies] cortex-m = { version = "0.7", features = ["critical-section-single-core"] } diff --git a/examples/mcxa-577app/bootloader/Cargo.toml b/examples/mcxa-577app/bootloader/Cargo.toml index 41dfbfb3..90e6b616 100644 --- a/examples/mcxa-577app/bootloader/Cargo.toml +++ b/examples/mcxa-577app/bootloader/Cargo.toml @@ -2,7 +2,7 @@ name = "mcxa-577app-bootloader" version = "0.1.0" edition = "2021" -license.workspace = true +license = "MIT" [features] default = ["defmt", "certificate-logging", "verification-logging", "mcxa"] @@ -33,7 +33,7 @@ embassy-sync = { workspace = true } ec-slimloader-mcxa = { path = "../../../libs/ec-slimloader-mcxa", default-features = false, features = ["mcxa5xx", "defmt"] } ec-slimloader = { path = "../../../libs/ec-slimloader", default-features = false } ec-slimloader-state = { path = "../../../libs/ec-slimloader-state", default-features = false } -mcxa-security-provisioning = { path = "../../../mcxa-security-provisioning", default-features = false, features = ["defmt"] } +mcxa-security-provisioning = { path = "../../../libs/mcxa-security-provisioning", default-features = false, features = ["defmt"] } embassy-mcxa = { workspace = true, features = ["rt", "mcxa5xx"] } embassy-executor = { workspace = true, features = ["platform-cortex-m", "executor-thread"] } diff --git a/examples/mcxa-577app/patches/rustc_version/Cargo.toml b/examples/mcxa-577app/patches/rustc_version/Cargo.toml deleted file mode 100644 index 6ee5e6af..00000000 --- a/examples/mcxa-577app/patches/rustc_version/Cargo.toml +++ /dev/null @@ -1,5 +0,0 @@ -[package] -name = "rustc_version" -version = "0.2.3" -edition = "2018" -license = "MIT OR Apache-2.0" diff --git a/examples/mcxa-577app/patches/rustc_version/src/lib.rs b/examples/mcxa-577app/patches/rustc_version/src/lib.rs deleted file mode 100644 index ebc9cfea..00000000 --- a/examples/mcxa-577app/patches/rustc_version/src/lib.rs +++ /dev/null @@ -1,34 +0,0 @@ -use std::process::Command; -use std::env; - -pub struct Version { - pub major: u64, - pub minor: u64, - pub patch: u64, -} - -#[derive(Debug)] -pub struct Error(String); - -impl std::fmt::Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0) - } -} - -pub fn version() -> Result { - let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string()); - let output = Command::new(&rustc) - .arg("--version") - .output() - .map_err(|e| Error(e.to_string()))?; - let s = std::str::from_utf8(&output.stdout).map_err(|e| Error(e.to_string()))?; - // "rustc 1.93.0 (..." or "rustc 1.93.0-nightly (..." - let ver = s.split_whitespace().nth(1).ok_or_else(|| Error("bad output".into()))?; - let ver = ver.split('-').next().unwrap_or(ver); - let mut parts = ver.split('.'); - let major = parts.next().and_then(|s| s.parse().ok()).ok_or_else(|| Error("bad major".into()))?; - let minor = parts.next().and_then(|s| s.parse().ok()).ok_or_else(|| Error("bad minor".into()))?; - let patch = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0); - Ok(Version { major, minor, patch }) -} diff --git a/libs/Cargo.lock b/libs/Cargo.lock index 416105ae..61ef7660 100644 --- a/libs/Cargo.lock +++ b/libs/Cargo.lock @@ -2,18 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.5" @@ -38,12 +26,6 @@ dependencies = [ "derive_arbitrary", ] -[[package]] -name = "arraydeque" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" - [[package]] name = "askama" version = "0.14.0" @@ -157,9 +139,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.4.4" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad534f4357a5264cce5019c989cf66a4f0dc4e0d1b1d15f8aacec0ff7360273" +checksum = "005ec2760ca554fae18df7a11195552ec576cd665632a881bc011d5bb2fd4d80" dependencies = [ "find-msvc-tools", "shlex", @@ -326,8 +308,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5793572036e0a6638977c7370c6afc423eac848ee8495f079b8fd3964de7b9f9" dependencies = [ "serde_json", - "toml", - "yaml-rust2", ] [[package]] @@ -475,7 +455,7 @@ dependencies = [ "ec-slimloader-state", "embassy-embedded-hal 0.5.0", "embassy-imxrt", - "embassy-sync 0.8.0", + "embassy-sync 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-storage", "embedded-storage-async", "heapless 0.8.0", @@ -493,12 +473,10 @@ dependencies = [ "cortex-m", "defmt 0.3.100", "defmt-or-log", - "device-driver", "ec-slimloader", "ec-slimloader-state", "embassy-mcxa", - "embassy-sync 0.8.0", - "embassy-time", + "embassy-sync 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-storage-async", "heapless 0.8.0", "log", @@ -515,7 +493,7 @@ dependencies = [ "crc", "defmt 0.3.100", "defmt-or-log", - "embassy-futures", + "embassy-futures 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-storage-async", "log", "num_enum", @@ -533,7 +511,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "554e3e840696f54b4c9afcf28a0f24da431c927f4151040020416e7393d6d0d8" dependencies = [ - "embassy-futures", + "embassy-futures 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "embassy-hal-internal 0.3.0", "embassy-sync 0.7.2", "embedded-hal 0.2.7", @@ -547,11 +525,28 @@ dependencies = [ [[package]] name = "embassy-embedded-hal" version = "0.6.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0641612053b2f34fc250bb63f6630ae75de46e02ade7f457268447081d709ce" dependencies = [ - "embassy-futures", + "embassy-futures 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "embassy-hal-internal 0.4.0", + "embassy-sync 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-async", + "embedded-storage", + "embedded-storage-async", + "nb 1.1.0", +] + +[[package]] +name = "embassy-embedded-hal" +version = "0.6.0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" +dependencies = [ + "embassy-futures 0.1.2 (git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e)", "embassy-hal-internal 0.5.0", - "embassy-sync 0.8.0", + "embassy-sync 0.8.0 (git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e)", "embedded-hal 0.2.7", "embedded-hal 1.0.0", "embedded-hal-async", @@ -563,19 +558,20 @@ dependencies = [ [[package]] name = "embassy-executor" version = "0.10.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ "cordyceps", "critical-section", "document-features", "embassy-executor-macros", "embassy-executor-timer-queue", + "unitrait", ] [[package]] name = "embassy-executor-macros" version = "0.8.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ "darling", "proc-macro2", @@ -585,13 +581,22 @@ dependencies = [ [[package]] name = "embassy-executor-timer-queue" -version = "0.1.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +version = "0.1.1" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" +dependencies = [ + "unitrait", +] [[package]] name = "embassy-futures" version = "0.1.2" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc2d050bdc5c21e0862a89256ed8029ae6c290a93aecefc73084b3002cdebb01" + +[[package]] +name = "embassy-futures" +version = "0.1.2" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" [[package]] name = "embassy-hal-internal" @@ -605,10 +610,19 @@ dependencies = [ "num-traits", ] +[[package]] +name = "embassy-hal-internal" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f10ce10a4dfdf6402d8e9bd63128986b96a736b1a0a6680547ed2ac55d55dba" +dependencies = [ + "num-traits", +] + [[package]] name = "embassy-hal-internal" version = "0.5.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ "cortex-m", "critical-section", @@ -626,10 +640,10 @@ dependencies = [ "critical-section", "defmt 1.1.1", "document-features", - "embassy-embedded-hal 0.6.0", - "embassy-futures", + "embassy-embedded-hal 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "embassy-futures 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "embassy-hal-internal 0.3.0", - "embassy-sync 0.8.0", + "embassy-sync 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-hal 0.2.7", "embedded-hal 1.0.0", "embedded-hal-async", @@ -654,18 +668,19 @@ dependencies = [ [[package]] name = "embassy-mcxa" version = "0.1.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ "bbqueue", "convert_case 0.11.0", "cortex-m", "cortex-m-rt", "critical-section", - "embassy-embedded-hal 0.6.0", + "defmt 1.1.1", + "embassy-embedded-hal 0.6.0 (git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e)", "embassy-executor", - "embassy-futures", + "embassy-futures 0.1.2 (git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e)", "embassy-hal-internal 0.5.0", - "embassy-sync 0.8.0", + "embassy-sync 0.8.0 (git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e)", "embassy-time", "embassy-time-driver", "embassy-time-queue-utils", @@ -710,7 +725,8 @@ dependencies = [ [[package]] name = "embassy-sync" version = "0.8.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bbd85cf5a5ae56bdf26f618364af642d1d0a4e245cdd75cd9aabda382f65a81" dependencies = [ "cfg-if", "critical-section", @@ -721,10 +737,23 @@ dependencies = [ "heapless 0.9.3", ] +[[package]] +name = "embassy-sync" +version = "0.8.0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" +dependencies = [ + "cfg-if", + "critical-section", + "embedded-io-async 0.7.0", + "futures-core", + "futures-sink", + "heapless 0.9.3", +] + [[package]] name = "embassy-time" version = "0.5.1" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ "cfg-if", "critical-section", @@ -739,7 +768,7 @@ dependencies = [ [[package]] name = "embassy-time-driver" version = "0.2.2" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ "document-features", ] @@ -747,7 +776,7 @@ dependencies = [ [[package]] name = "embassy-time-queue-utils" version = "0.3.2" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=f0fd6e2a8e9c505290498e316ad2bdda8b94da5e#f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" dependencies = [ "embassy-executor-timer-queue", "heapless 0.9.3", @@ -855,15 +884,6 @@ dependencies = [ "embedded-storage", ] -[[package]] -name = "encoding_rs" -version = "0.8.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" -dependencies = [ - "cfg-if", -] - [[package]] name = "equivalent" version = "1.0.2" @@ -872,9 +892,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "find-msvc-tools" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890" +checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d" [[package]] name = "fixed" @@ -956,30 +976,12 @@ dependencies = [ "byteorder", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", -] - [[package]] name = "hashbrown" version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" -[[package]] -name = "hashlink" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" -dependencies = [ - "hashbrown 0.14.5", -] - [[package]] name = "heapless" version = "0.8.0" @@ -1020,12 +1022,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.14.0" +version = "2.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" dependencies = [ "equivalent", - "hashbrown 0.17.1", + "hashbrown", ] [[package]] @@ -1114,6 +1116,24 @@ dependencies = [ "regex-automata", ] +[[package]] +name = "mcxa-security-provisioning" +version = "0.2.0" +dependencies = [ + "cortex-m", + "defmt 0.3.100", + "defmt-or-log", + "ec-slimloader-mcxa", + "embassy-futures 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "embassy-mcxa", + "embassy-sync 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-storage-async", + "log", + "partition-manager", + "partition-manager-macros", + "static_cell", +] + [[package]] name = "memchr" version = "2.8.3" @@ -1229,6 +1249,7 @@ dependencies = [ "cfg_aliases", "cortex-m", "cortex-m-rt", + "defmt 0.3.100", ] [[package]] @@ -1243,7 +1264,7 @@ version = "0.1.0" source = "git+https://github.com/OpenDevicePartnership/embedded-services.git?tag=v0.1.0#6034c6bf3d2d7bfe50821370be7c1275fbf8520a" dependencies = [ "defmt 0.3.100", - "embassy-sync 0.8.0", + "embassy-sync 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-storage-async", "partition-manager-macros", ] @@ -1408,6 +1429,11 @@ checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" [[package]] name = "rustc_version" version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] [[package]] name = "rustversion" @@ -1421,6 +1447,21 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + [[package]] name = "serde" version = "1.0.229" @@ -1448,7 +1489,7 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn 3.0.4", + "syn 3.0.5", ] [[package]] @@ -1491,9 +1532,9 @@ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" [[package]] name = "smallvec" -version = "1.15.2" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" +checksum = "b9be42f50aa861c555654aa3a37f52f4b1074bacf4e48fe0ef7fa584e80f1f0f" [[package]] name = "stable_deref_trait" @@ -1534,9 +1575,9 @@ dependencies = [ [[package]] name = "syn" -version = "3.0.4" +version = "3.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6275cddf4610d1775e6d1fe9469b2e77d0f39fd98fb7450901b821e0c53649f" +checksum = "12df2e0110f65b775f769bb17ef989067a1d931b2eb822bd4346631eeada89f9" dependencies = [ "proc-macro2", "quote", @@ -1566,7 +1607,7 @@ checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" dependencies = [ "proc-macro2", "quote", - "syn 3.0.4", + "syn 3.0.5", ] [[package]] @@ -1610,16 +1651,9 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_write", "winnow", ] -[[package]] -name = "toml_write" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" - [[package]] name = "tracing" version = "0.1.44" @@ -1699,6 +1733,24 @@ version = "1.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" +[[package]] +name = "unitrait" +version = "2.0.0" +source = "git+https://github.com/embassy-rs/unitrait?rev=bb96601b3d293fa27d1ca2891f6ea148e534e433#bb96601b3d293fa27d1ca2891f6ea148e534e433" +dependencies = [ + "unitrait-macros", +] + +[[package]] +name = "unitrait-macros" +version = "2.0.0" +source = "git+https://github.com/embassy-rs/unitrait?rev=bb96601b3d293fa27d1ca2891f6ea148e534e433#bb96601b3d293fa27d1ca2891f6ea148e534e433" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "valuable" version = "0.1.1" @@ -1711,12 +1763,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "void" version = "1.0.2" @@ -1774,17 +1820,6 @@ dependencies = [ "tap", ] -[[package]] -name = "yaml-rust2" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1a1c0bc9823338a3bdf8c61f994f23ac004c6fa32c08cd152984499b445e8d" -dependencies = [ - "arraydeque", - "encoding_rs", - "hashlink", -] - [[package]] name = "zerocopy" version = "0.8.56" diff --git a/libs/Cargo.toml b/libs/Cargo.toml index 76248e50..faaa5424 100644 --- a/libs/Cargo.toml +++ b/libs/Cargo.toml @@ -6,6 +6,7 @@ members = [ "ec-slimloader-state", "ec-slimloader-mcxa", "imxrt-rom", + "mcxa-security-provisioning" ] [workspace.package] @@ -36,18 +37,10 @@ partition-manager-macros = { git = "https://github.com/OpenDevicePartnership/emb embassy-sync = "0.8.0" embassy-time = "0.5.0" embassy-futures = "0.1.0" -embassy-mcxa = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0", default-features = false } -embassy-imxrt = { git = "https://github.com/OpenDevicePartnership/embassy-imxrt.git", default-features = false, features = ["mimxrt685s"] } +embassy-mcxa = { git = "https://github.com/embassy-rs/embassy", rev = "f0fd6e2a8e9c505290498e316ad2bdda8b94da5e", default-features = false } +embassy-imxrt = { git = "https://github.com/OpenDevicePartnership/embassy-imxrt.git", default-features = false, features = [ + "mimxrt685s", +] } -# Redirect crates.io embassy deps (e.g. pulled in by embassy-imxrt) to the same git rev. [patch.crates-io] -embassy-embedded-hal = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-executor-macros = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-futures = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-hal-internal = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-time-driver = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-time-queue-utils = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -rustc_version = { path = "../examples/mcxa-577app/patches/rustc_version" } +embassy-time-driver = { git = "https://github.com/embassy-rs/embassy", rev = "f0fd6e2a8e9c505290498e316ad2bdda8b94da5e" } diff --git a/libs/ci.sh b/libs/ci.sh index cd21a91b..1c5fe33a 100755 --- a/libs/ci.sh +++ b/libs/ci.sh @@ -21,19 +21,17 @@ TARGET="thumbv8m.main-none-eabihf" BUILD_EXTRA="" FEATURE_COMBINATIONS=( - "mimxrt633s" - "mimxrt633s,defmt" - "mimxrt633s,log" - "mimxrt633s,non-secure" - "mimxrt685s" - "mimxrt685s,defmt" - "mimxrt685s,log" - "mimxrt685s,non-secure" + "mcxa5xx,mimxrt633s,defmt" + "mcxa5xx,mimxrt633s,log" + "mcxa5xx,mimxrt633s,defmt,non-secure" + "mcxa5xx,mimxrt685s,defmt" + "mcxa5xx,mimxrt685s,log" + "mcxa5xx,mimxrt685s,defmt,non-secure" ) -cargo batch \ +DEFMT_LOG="off" cargo batch \ $(for features in "${FEATURE_COMBINATIONS[@]}"; do - echo "--- build --release --manifest-path Cargo.toml --target thumbv8m.main-none-eabihf --features $features " + echo "--- build --manifest-path Cargo.toml --target thumbv8m.main-none-eabihf --features $features --no-default-features" done) $BUILD_EXTRA -cargo test --locked --workspace --manifest-path Cargo.toml --target x86_64-unknown-linux-gnu --features "mimxrt633s" --exclude ec-slimloader-mcxa -cargo test --locked --workspace --manifest-path Cargo.toml --target x86_64-unknown-linux-gnu --features "mimxrt685s" --exclude ec-slimloader-mcxa +cargo test --locked --workspace --manifest-path Cargo.toml --target x86_64-unknown-linux-gnu --features "mimxrt633s" --exclude ec-slimloader-mcxa --exclude mcxa-security-provisioning --no-default-features +cargo test --locked --workspace --manifest-path Cargo.toml --target x86_64-unknown-linux-gnu --features "mimxrt685s" --exclude ec-slimloader-mcxa --exclude mcxa-security-provisioning --no-default-features diff --git a/libs/ec-slimloader-imxrt/Cargo.toml b/libs/ec-slimloader-imxrt/Cargo.toml index 7f11f062..043026b5 100644 --- a/libs/ec-slimloader-imxrt/Cargo.toml +++ b/libs/ec-slimloader-imxrt/Cargo.toml @@ -53,7 +53,7 @@ log = [ "ec-slimloader-state/log", ] -default = [] +default = ["defmt"] [dependencies] ec-slimloader = { path = "../ec-slimloader" } diff --git a/libs/ec-slimloader-mcxa/Cargo.toml b/libs/ec-slimloader-mcxa/Cargo.toml index cdd77c98..43fffb9a 100644 --- a/libs/ec-slimloader-mcxa/Cargo.toml +++ b/libs/ec-slimloader-mcxa/Cargo.toml @@ -6,7 +6,6 @@ license.workspace = true repository.workspace = true [dependencies] -device-driver.workspace = true defmt = { workspace = true, optional = true } defmt-or-log = { workspace = true } log = { workspace = true, optional = true } @@ -18,18 +17,16 @@ partition-manager = { workspace = true, features = ["esa"] } partition-manager-macros = { workspace = true } static_cell = { workspace = true } embassy-sync = { workspace = true } -embassy-time = { workspace = true } embassy-mcxa = { workspace = true, features = ["rt", "unstable-pac"] } embedded-storage-async = { workspace = true } [features] -default = ["mcxa5xx", "verification-logging", "certificate-logging"] +default = ["mcxa5xx", "verification-logging", "certificate-logging", "defmt"] defmt = ["dep:defmt", "defmt-or-log/defmt", "ec-slimloader/defmt"] log = ["dep:log", "defmt-or-log/log", "ec-slimloader/log"] certificate-logging = [] verification-logging = [] flexspi-selftest = [] -mcxa2xx = ["embassy-mcxa/mcxa2xx"] mcxa5xx = ["embassy-mcxa/mcxa5xx"] # Use this when targeting the FRDM-MCXA577 EVK (flash on FlexSPI Port A). # Without this flag the driver targets Port B (custom board wiring for end target HW). diff --git a/libs/ec-slimloader-mcxa/src/board.rs b/libs/ec-slimloader-mcxa/src/board.rs index cbf1aa27..25fe81e9 100644 --- a/libs/ec-slimloader-mcxa/src/board.rs +++ b/libs/ec-slimloader-mcxa/src/board.rs @@ -620,10 +620,8 @@ impl Board for Mcxa { } match verification::verify_authenticity(self.sgi.reborrow(), image_base) { - Ok(s) if s == crate::rom_api::NbootBoolValue::True as u32 => unsafe { - jump::jump_to_image(jump_address) - }, - Ok(_) => ec_slimloader::BootError::Authenticate, + Ok(true) => unsafe { jump::jump_to_image(jump_address) }, + Ok(false) => ec_slimloader::BootError::Authenticate, Err(e) => e, } } diff --git a/libs/ec-slimloader-mcxa/src/error.rs b/libs/ec-slimloader-mcxa/src/error.rs index 30d9561c..503aefd7 100644 --- a/libs/ec-slimloader-mcxa/src/error.rs +++ b/libs/ec-slimloader-mcxa/src/error.rs @@ -2,326 +2,74 @@ #![allow(dead_code)] use ec_slimloader::BootError; +use embassy_mcxa::rom::{FlashError, FlexspiError, KbError, NbootError, SpiFlashError}; -const KSTATUS_SUCCESS: u32 = 0; -const KSTATUS_FAIL: u32 = 1; -const KSTATUS_INVALID_ARGUMENT: u32 = 4; - -const KSTATUS_FLASH_SUCCESS: u32 = 0; -const KSTATUS_FLASH_INVALID_ARGUMENT: u32 = 4; -const KSTATUS_FLASH_ALIGNMENT_ERROR: u32 = 101; -const KSTATUS_FLASH_ADDRESS_ERROR: u32 = 102; -const KSTATUS_FLASH_SIZE_ERROR: u32 = 100; -const KSTATUS_FLASH_COMMAND_FAILURE: u32 = 105; -const KSTATUS_FLASH_UNKNOWN_PROPERTY: u32 = 106; -const KSTATUS_FLASH_ERASE_KEY_ERROR: u32 = 107; -const KSTATUS_FLASH_REGION_EXECUTE_ONLY: u32 = 108; -const KSTATUS_FLASH_COMMAND_NOT_SUPPORTED: u32 = 111; -const KSTATUS_FLASH_READ_ONLY_PROPERTY: u32 = 112; -const KSTATUS_FLASH_INVALID_PROPERTY_VALUE: u32 = 113; -const KSTATUS_FLASH_ECC_ERROR: u32 = 116; -const KSTATUS_FLASH_COMPARE_ERROR: u32 = 117; -const KSTATUS_FLASH_INVALID_WAIT_STATE_CYCLES: u32 = 119; - -// SPI flash driver status codes -const KSTATUS_SPIFLASH_SUCCESS: u32 = KSTATUS_SUCCESS; -const KSTATUS_SPIFLASH_FAIL: u32 = KSTATUS_FAIL; - -// FlexSPI flash driver status codes -const KSTATUS_FLEXSPI_SUCCESS: u32 = KSTATUS_SUCCESS; -const KSTATUS_FLEXSPI_FAIL: u32 = KSTATUS_FAIL; -const KSTATUS_FLEXSPI_INVALID_ARGUMENT: u32 = KSTATUS_INVALID_ARGUMENT; -const KSTATUS_FLEXSPI_SEQUENCE_EXECUTION_TIMEOUT: u32 = 6000; -const KSTATUS_FLEXSPI_INVALID_SEQUENCE: u32 = 6001; -const KSTATUS_FLEXSPI_DEVICE_TIMEOUT: u32 = 6002; - -const KSTATUS_FLEXSPINOR_PROGRAM_FAIL: u32 = 20100; -const KSTATUS_FLEXSPINOR_ERASE_SECTOR_FAIL: u32 = 20101; -const KSTATUS_FLEXSPINOR_ERASE_ALL_FAIL: u32 = 20102; -const KSTATUS_FLEXSPINOR_WAIT_TIMEOUT: u32 = 20103; -const KSTATUS_FLEXSPINOR_WRITE_ALIGNMENT_ERROR: u32 = 20105; -const KSTATUS_FLEXSPINOR_COMMAND_FAILURE: u32 = 20106; -const KSTATUS_FLEXSPINOR_SFDP_NOT_FOUND: u32 = 20107; -const KSTATUS_FLEXSPINOR_UNSUPPORTED_SFDP_VERSION: u32 = 20108; -const KSTATUS_FLEXSPINOR_FLASH_NOT_FOUND: u32 = 20109; -const KSTATUS_FLEXSPINOR_DTR_READ_DUMMY_PROBE_FAILED: u32 = 20110; - -const KSTATUS_NBOOT_SUCCESS: u32 = 0x5A5A_5A5A; -const KSTATUS_NBOOT_FAIL: u32 = 0x5A5A_A5A5; -const KSTATUS_NBOOT_INVALID_ARGUMENT: u32 = 0x5A5A_A5F0; - -// NBOOT API status codes (MCXA ROM, Table 46 / 9.2.5.11) -// These are returned by APIs such as `nboot_mem_crypt_range_checker`. -const KNBOOT_OPERATION_ALLOWED: u32 = 0x3C5A_33CC; -const KNBOOT_OPERATION_DISALLOWED: u32 = 0x5AA5_CC33; -const KSTATUS_NBOOT_KEY_NOT_AVAILABLE: u32 = 0x5A5A_A5E6; - -const KSTATUS_ROMLDR_DATA_UNDERRUN: u32 = 10109; -const KSTATUS_ROMLDR_JUMP_RETURNED: u32 = 10110; -const KSTATUS_ROMLDR_ROLLBACK_BLOCKED: u32 = 10115; -const KSTATUS_ROMLDR_PENDING_JUMP_COMMAND: u32 = 10119; - -// ROM API status codes -const KSTATUS_ROM_API_BUFFER_SIZE_NOT_ENOUGH: u32 = 10802; -const KSTATUS_ROM_API_INVALID_BUFFER: u32 = 10803; - -// KBoot (KB) status codes (Table 35); KB reuses generic/ROM loader/ROM API status space; these aliases make callsites clearer. -const KSTATUS_KB_SUCCESS: u32 = KSTATUS_SUCCESS; -const KSTATUS_KB_FAIL: u32 = KSTATUS_FAIL; -const KSTATUS_KB_INVALID_ARGUMENT: u32 = KSTATUS_INVALID_ARGUMENT; - -const KSTATUS_KB_ROMLDR_DATA_UNDERRUN: u32 = KSTATUS_ROMLDR_DATA_UNDERRUN; -const KSTATUS_KB_ROMLDR_JUMP_RETURNED: u32 = KSTATUS_ROMLDR_JUMP_RETURNED; -const KSTATUS_KB_ROMLDR_ROLLBACK_BLOCKED: u32 = KSTATUS_ROMLDR_ROLLBACK_BLOCKED; -const KSTATUS_KB_ROMLDR_PENDING_JUMP_COMMAND: u32 = KSTATUS_ROMLDR_PENDING_JUMP_COMMAND; - -const KSTATUS_KB_BUFFER_SIZE_NOT_ENOUGH: u32 = KSTATUS_ROM_API_BUFFER_SIZE_NOT_ENOUGH; -const KSTATUS_KB_INVALID_BUFFER: u32 = KSTATUS_ROM_API_INVALID_BUFFER; - -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -#[repr(u32)] -pub enum FlashStatus { - Success = KSTATUS_FLASH_SUCCESS, - InvalidArgument = KSTATUS_FLASH_INVALID_ARGUMENT, - AlignmentError = KSTATUS_FLASH_ALIGNMENT_ERROR, - AddressError = KSTATUS_FLASH_ADDRESS_ERROR, - SizeError = KSTATUS_FLASH_SIZE_ERROR, - CommandFailure = KSTATUS_FLASH_COMMAND_FAILURE, - UnknownProperty = KSTATUS_FLASH_UNKNOWN_PROPERTY, - EraseKeyError = KSTATUS_FLASH_ERASE_KEY_ERROR, - RegionExecuteOnly = KSTATUS_FLASH_REGION_EXECUTE_ONLY, - CommandNotSupported = KSTATUS_FLASH_COMMAND_NOT_SUPPORTED, - ReadOnlyProperty = KSTATUS_FLASH_READ_ONLY_PROPERTY, - InvalidPropertyValue = KSTATUS_FLASH_INVALID_PROPERTY_VALUE, - EccError = KSTATUS_FLASH_ECC_ERROR, - CompareError = KSTATUS_FLASH_COMPARE_ERROR, - InvalidWaitStateCycles = KSTATUS_FLASH_INVALID_WAIT_STATE_CYCLES, - Unknown(u32) = 0xFFFF_FFFF, -} - -impl From for FlashStatus { - fn from(raw: u32) -> Self { - match raw { - KSTATUS_FLASH_SUCCESS => Self::Success, - KSTATUS_FLASH_INVALID_ARGUMENT => Self::InvalidArgument, - KSTATUS_FLASH_ALIGNMENT_ERROR => Self::AlignmentError, - KSTATUS_FLASH_ADDRESS_ERROR => Self::AddressError, - KSTATUS_FLASH_SIZE_ERROR => Self::SizeError, - KSTATUS_FLASH_COMMAND_FAILURE => Self::CommandFailure, - KSTATUS_FLASH_UNKNOWN_PROPERTY => Self::UnknownProperty, - KSTATUS_FLASH_ERASE_KEY_ERROR => Self::EraseKeyError, - KSTATUS_FLASH_REGION_EXECUTE_ONLY => Self::RegionExecuteOnly, - KSTATUS_FLASH_COMMAND_NOT_SUPPORTED => Self::CommandNotSupported, - KSTATUS_FLASH_READ_ONLY_PROPERTY => Self::ReadOnlyProperty, - KSTATUS_FLASH_INVALID_PROPERTY_VALUE => Self::InvalidPropertyValue, - KSTATUS_FLASH_ECC_ERROR => Self::EccError, - KSTATUS_FLASH_COMPARE_ERROR => Self::CompareError, - KSTATUS_FLASH_INVALID_WAIT_STATE_CYCLES => Self::InvalidWaitStateCycles, - other => Self::Unknown(other), - } - } -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[repr(u32)] -pub enum SpiFlashStatus { - Success = KSTATUS_SPIFLASH_SUCCESS, - Fail = KSTATUS_SPIFLASH_FAIL, - Unknown(u32) = 0xFFFF_FFFF, -} - -impl From for SpiFlashStatus { - fn from(raw: u32) -> Self { - match raw { - KSTATUS_SPIFLASH_SUCCESS => Self::Success, - KSTATUS_SPIFLASH_FAIL => Self::Fail, - other => Self::Unknown(other), - } - } -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[repr(u32)] -pub enum FlexspiStatus { - Success = KSTATUS_FLEXSPI_SUCCESS, - Fail = KSTATUS_FLEXSPI_FAIL, - InvalidArgument = KSTATUS_FLEXSPI_INVALID_ARGUMENT, - SequenceExecutionTimeout = KSTATUS_FLEXSPI_SEQUENCE_EXECUTION_TIMEOUT, - InvalidSequence = KSTATUS_FLEXSPI_INVALID_SEQUENCE, - DeviceTimeout = KSTATUS_FLEXSPI_DEVICE_TIMEOUT, - ProgramFail = KSTATUS_FLEXSPINOR_PROGRAM_FAIL, - EraseSectorFail = KSTATUS_FLEXSPINOR_ERASE_SECTOR_FAIL, - EraseAllFail = KSTATUS_FLEXSPINOR_ERASE_ALL_FAIL, - WaitTimeout = KSTATUS_FLEXSPINOR_WAIT_TIMEOUT, - WriteAlignmentError = KSTATUS_FLEXSPINOR_WRITE_ALIGNMENT_ERROR, - CommandFailure = KSTATUS_FLEXSPINOR_COMMAND_FAILURE, - SfdpNotFound = KSTATUS_FLEXSPINOR_SFDP_NOT_FOUND, - UnsupportedSfdpVersion = KSTATUS_FLEXSPINOR_UNSUPPORTED_SFDP_VERSION, - FlashNotFound = KSTATUS_FLEXSPINOR_FLASH_NOT_FOUND, - DtrReadDummyProbeFailed = KSTATUS_FLEXSPINOR_DTR_READ_DUMMY_PROBE_FAILED, - Unknown(u32) = 0xFFFF_FFFF, -} - -impl From for FlexspiStatus { - fn from(raw: u32) -> Self { - match raw { - KSTATUS_FLEXSPI_SUCCESS => Self::Success, - KSTATUS_FLEXSPI_FAIL => Self::Fail, - KSTATUS_FLEXSPI_INVALID_ARGUMENT => Self::InvalidArgument, - KSTATUS_FLEXSPI_SEQUENCE_EXECUTION_TIMEOUT => Self::SequenceExecutionTimeout, - KSTATUS_FLEXSPI_INVALID_SEQUENCE => Self::InvalidSequence, - KSTATUS_FLEXSPI_DEVICE_TIMEOUT => Self::DeviceTimeout, - KSTATUS_FLEXSPINOR_PROGRAM_FAIL => Self::ProgramFail, - KSTATUS_FLEXSPINOR_ERASE_SECTOR_FAIL => Self::EraseSectorFail, - KSTATUS_FLEXSPINOR_ERASE_ALL_FAIL => Self::EraseAllFail, - KSTATUS_FLEXSPINOR_WAIT_TIMEOUT => Self::WaitTimeout, - KSTATUS_FLEXSPINOR_WRITE_ALIGNMENT_ERROR => Self::WriteAlignmentError, - KSTATUS_FLEXSPINOR_COMMAND_FAILURE => Self::CommandFailure, - KSTATUS_FLEXSPINOR_SFDP_NOT_FOUND => Self::SfdpNotFound, - KSTATUS_FLEXSPINOR_UNSUPPORTED_SFDP_VERSION => Self::UnsupportedSfdpVersion, - KSTATUS_FLEXSPINOR_FLASH_NOT_FOUND => Self::FlashNotFound, - KSTATUS_FLEXSPINOR_DTR_READ_DUMMY_PROBE_FAILED => Self::DtrReadDummyProbeFailed, - other => Self::Unknown(other), - } - } -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -#[repr(u32)] -pub enum NbootStatus { - Success = KSTATUS_NBOOT_SUCCESS, - Fail = KSTATUS_NBOOT_FAIL, - InvalidArgument = KSTATUS_NBOOT_INVALID_ARGUMENT, - OperationAllowed = KNBOOT_OPERATION_ALLOWED, - OperationDisallowed = KNBOOT_OPERATION_DISALLOWED, - KeyNotAvailable = KSTATUS_NBOOT_KEY_NOT_AVAILABLE, - Unknown(u32) = 0xFFFF_FFFF, // Catch-all for unknown status codes, including saturated values. -} - -impl From for NbootStatus { - fn from(raw: u64) -> Self { - // The ROM returns a usable 32-bit value; upper 32 bits are likely security related metadata/fault attack protection. - // TODO: Discuss the FI counter usage with NXP. - let raw = raw as u32; - match raw { - KSTATUS_NBOOT_SUCCESS => Self::Success, - KSTATUS_NBOOT_FAIL => Self::Fail, - KSTATUS_NBOOT_INVALID_ARGUMENT => Self::InvalidArgument, - KNBOOT_OPERATION_ALLOWED => Self::OperationAllowed, - KNBOOT_OPERATION_DISALLOWED => Self::OperationDisallowed, - KSTATUS_NBOOT_KEY_NOT_AVAILABLE => Self::KeyNotAvailable, - other => Self::Unknown(other), - } - } -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[repr(u32)] -pub enum KbStatus { - Success = KSTATUS_KB_SUCCESS, - Fail = KSTATUS_KB_FAIL, - InvalidArgument = KSTATUS_KB_INVALID_ARGUMENT, - RomLdrDataUnderrun = KSTATUS_KB_ROMLDR_DATA_UNDERRUN, - RomLdrJumpReturned = KSTATUS_KB_ROMLDR_JUMP_RETURNED, - RomLdrRollbackBlocked = KSTATUS_KB_ROMLDR_ROLLBACK_BLOCKED, - RomLdrPendingJumpCommand = KSTATUS_KB_ROMLDR_PENDING_JUMP_COMMAND, - RomApiBufferSizeNotEnough = KSTATUS_KB_BUFFER_SIZE_NOT_ENOUGH, - RomApiInvalidBuffer = KSTATUS_KB_INVALID_BUFFER, - Unknown(u32) = 0xFFFF_FFFF, -} - -impl From for KbStatus { - fn from(raw: u32) -> Self { - match raw { - KSTATUS_KB_SUCCESS => Self::Success, - KSTATUS_KB_FAIL => Self::Fail, - KSTATUS_KB_INVALID_ARGUMENT => Self::InvalidArgument, - KSTATUS_KB_ROMLDR_DATA_UNDERRUN => Self::RomLdrDataUnderrun, - KSTATUS_KB_ROMLDR_JUMP_RETURNED => Self::RomLdrJumpReturned, - KSTATUS_KB_ROMLDR_ROLLBACK_BLOCKED => Self::RomLdrRollbackBlocked, - KSTATUS_KB_ROMLDR_PENDING_JUMP_COMMAND => Self::RomLdrPendingJumpCommand, - KSTATUS_KB_BUFFER_SIZE_NOT_ENOUGH => Self::RomApiBufferSizeNotEnough, - KSTATUS_KB_INVALID_BUFFER => Self::RomApiInvalidBuffer, - other => Self::Unknown(other), - } - } -} - -#[allow(dead_code)] -pub fn map_flash_status_to_boot_error(status: FlashStatus) -> BootError { +pub(crate) fn map_flash_status_to_boot_error(status: FlashError) -> BootError { match status { - FlashStatus::InvalidArgument - | FlashStatus::AlignmentError - | FlashStatus::AddressError - | FlashStatus::SizeError - | FlashStatus::RegionExecuteOnly - | FlashStatus::ReadOnlyProperty => BootError::MemoryRegion, - FlashStatus::EccError | FlashStatus::CompareError | FlashStatus::CommandFailure => BootError::Integrity, - FlashStatus::EraseKeyError - | FlashStatus::UnknownProperty - | FlashStatus::CommandNotSupported - | FlashStatus::InvalidPropertyValue - | FlashStatus::InvalidWaitStateCycles => BootError::Markers, + FlashError::InvalidArgument + | FlashError::AlignmentError + | FlashError::AddressError + | FlashError::SizeError + | FlashError::RegionExecuteOnly + | FlashError::ReadOnlyProperty => BootError::MemoryRegion, + FlashError::EccError | FlashError::CompareError | FlashError::CommandFailure => BootError::Integrity, + FlashError::EraseKeyError + | FlashError::UnknownProperty + | FlashError::CommandNotSupported + | FlashError::InvalidPropertyValue + | FlashError::InvalidWaitStateCycles => BootError::Markers, _ => BootError::IO, } } -#[allow(dead_code)] -pub fn map_spiflash_status_to_boot_error(status: SpiFlashStatus) -> BootError { +pub(crate) fn map_spiflash_status_to_boot_error(status: SpiFlashError) -> BootError { match status { - SpiFlashStatus::Fail => BootError::IO, + SpiFlashError::Fail => BootError::IO, _ => BootError::IO, } } -#[allow(dead_code)] -pub fn map_flexspi_status_to_boot_error(status: FlexspiStatus) -> BootError { +pub(crate) fn map_flexspi_status_to_boot_error(status: FlexspiError) -> BootError { match status { - FlexspiStatus::InvalidArgument - | FlexspiStatus::InvalidSequence - | FlexspiStatus::SfdpNotFound - | FlexspiStatus::UnsupportedSfdpVersion => BootError::Markers, - FlexspiStatus::WriteAlignmentError => BootError::MemoryRegion, - FlexspiStatus::ProgramFail - | FlexspiStatus::EraseSectorFail - | FlexspiStatus::EraseAllFail - | FlexspiStatus::CommandFailure - | FlexspiStatus::DtrReadDummyProbeFailed => BootError::Integrity, - FlexspiStatus::Fail - | FlexspiStatus::Success - | FlexspiStatus::SequenceExecutionTimeout - | FlexspiStatus::DeviceTimeout - | FlexspiStatus::WaitTimeout - | FlexspiStatus::FlashNotFound => BootError::IO, + FlexspiError::InvalidArgument + | FlexspiError::InvalidSequence + | FlexspiError::SfdpNotFound + | FlexspiError::UnsupportedSfdpVersion => BootError::Markers, + FlexspiError::WriteAlignmentError => BootError::MemoryRegion, + FlexspiError::ProgramFail + | FlexspiError::EraseSectorFail + | FlexspiError::EraseAllFail + | FlexspiError::CommandFailure + | FlexspiError::DtrReadDummyProbeFailed => BootError::Integrity, + FlexspiError::Fail + | FlexspiError::SequenceExecutionTimeout + | FlexspiError::DeviceTimeout + | FlexspiError::WaitTimeout + | FlexspiError::FlashNotFound => BootError::IO, _ => BootError::IO, } } -pub fn map_nboot_status_to_boot_error(status: NbootStatus) -> BootError { +pub(crate) fn map_nboot_status_to_boot_error(status: NbootError) -> BootError { match status { - NbootStatus::OperationDisallowed => BootError::MemoryRegion, - NbootStatus::InvalidArgument => BootError::Markers, - NbootStatus::KeyNotAvailable => BootError::Authenticate, - NbootStatus::Fail => BootError::IO, + NbootError::OperationDisallowed => BootError::MemoryRegion, + NbootError::InvalidArgument => BootError::Markers, + NbootError::KeyNotAvailable => BootError::Authenticate, + NbootError::Fail => BootError::IO, _ => BootError::Authenticate, } } -#[allow(dead_code)] -pub fn map_kb_status_to_boot_error(status: KbStatus) -> BootError { +pub(crate) fn map_kb_status_to_boot_error(status: KbError) -> BootError { match status { - KbStatus::InvalidArgument | KbStatus::RomApiBufferSizeNotEnough | KbStatus::RomApiInvalidBuffer => { + KbError::InvalidArgument | KbError::RomApiBufferSizeNotEnough | KbError::RomApiInvalidBuffer => { BootError::Markers } - KbStatus::Fail => BootError::IO, - KbStatus::RomLdrRollbackBlocked => BootError::Markers, + KbError::Fail => BootError::IO, + KbError::RomLdrRollbackBlocked => BootError::Markers, // Data underrun / pending-jump are usually flow control for streaming loaders, // but if surfaced as an error, treat as I/O. - KbStatus::RomLdrDataUnderrun | KbStatus::RomLdrJumpReturned | KbStatus::RomLdrPendingJumpCommand => { - BootError::IO - } + KbError::RomLdrDataUnderrun | KbError::RomLdrJumpReturned | KbError::RomLdrPendingJumpCommand => BootError::IO, _ => BootError::IO, } } diff --git a/libs/ec-slimloader-mcxa/src/lib.rs b/libs/ec-slimloader-mcxa/src/lib.rs index d45e2ef1..fc4feef6 100644 --- a/libs/ec-slimloader-mcxa/src/lib.rs +++ b/libs/ec-slimloader-mcxa/src/lib.rs @@ -6,7 +6,6 @@ pub mod error; pub mod header; pub mod jump; pub mod lifecycle; -pub mod rom_api; pub mod verification; pub use board::{ExternalStorage, Mcxa, McxaConfig, Partitions, SlotPartition, StatePartition}; diff --git a/libs/ec-slimloader-mcxa/src/lifecycle.rs b/libs/ec-slimloader-mcxa/src/lifecycle.rs index bc3e7d69..e3f032f4 100644 --- a/libs/ec-slimloader-mcxa/src/lifecycle.rs +++ b/libs/ec-slimloader-mcxa/src/lifecycle.rs @@ -1,6 +1,7 @@ use core::mem; -use crate::rom_api::{NbootLifecycleDiscriminator, NbootLifecycleState, NbootRootKeyRevocation, NbootRootKeyUsage}; +use embassy_mcxa::rom::{NbootRootKeyRevocation, NbootRootKeyUsage}; + use crate::verification::zero_mask; // MCXA configuration flash layout (CFG vs SCRATCH) @@ -741,3 +742,114 @@ pub fn load_dice_inc_nxp_field_cfg_from_cmpa() -> bool { .map(|word| ((word >> 15) & 1) != 0) .unwrap_or(false) } + +// Lifecycle state codes (low-byte discriminators) and full CFPA LC_STATE values. +// Per Table 18 (Life Cycle States): LC_STATE is a u32 like 0x9635_FC03. +// Some call sites only carry the low-byte discriminator (e.g. 0x03 for Develop), +// so we keep both representations. +#[repr(u8)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum NbootLifecycleDiscriminator { + Develop = 0x03, + Develop2 = 0x07, + InField = 0x0F, + InFieldLocked = 0xCF, + OemFieldReturn = 0x1F, + FailureAnalysis = 0x3F, + Bricked = 0x5A, +} + +impl NbootLifecycleDiscriminator { + #[inline(always)] + pub const fn from_raw(raw: u8) -> Option { + match raw { + 0x03 => Some(Self::Develop), + 0x07 => Some(Self::Develop2), + 0x0F => Some(Self::InField), + 0xCF => Some(Self::InFieldLocked), + 0x1F => Some(Self::OemFieldReturn), + 0x3F => Some(Self::FailureAnalysis), + 0x5A => Some(Self::Bricked), + _ => None, + } + } + + #[inline(always)] + pub const fn state(self) -> NbootLifecycleState { + match self { + Self::Develop => NbootLifecycleState::Develop, + Self::Develop2 => NbootLifecycleState::Develop2, + Self::InField => NbootLifecycleState::InField, + Self::InFieldLocked => NbootLifecycleState::InFieldLocked, + Self::OemFieldReturn => NbootLifecycleState::OemFieldReturn, + Self::FailureAnalysis => NbootLifecycleState::FailureAnalysis, + Self::Bricked => NbootLifecycleState::Bricked, + } + } +} + +#[repr(u32)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum NbootLifecycleState { + Develop = 0x9635_FC03, + Develop2 = 0x9635_F807, + InField = 0x9635_F00F, + InFieldLocked = 0x9635_30CF, + OemFieldReturn = 0x9635_E01F, + FailureAnalysis = 0x9635_C03F, + Bricked = 0x9635_A55A, +} +impl TryFrom for NbootLifecycleState { + type Error = (); + + fn try_from(raw: u32) -> Result { + match raw { + 0x9635_FC03 => Ok(Self::Develop), + 0x9635_F807 => Ok(Self::Develop2), + 0x9635_F00F => Ok(Self::InField), + 0x9635_30CF => Ok(Self::InFieldLocked), + 0x9635_E01F => Ok(Self::OemFieldReturn), + 0x9635_C03F => Ok(Self::FailureAnalysis), + 0x9635_A55A => Ok(Self::Bricked), + _ => Err(()), + } + } +} + +impl NbootLifecycleState { + const fn discriminator(self) -> NbootLifecycleDiscriminator { + match self { + Self::Develop => NbootLifecycleDiscriminator::Develop, + Self::Develop2 => NbootLifecycleDiscriminator::Develop2, + Self::InField => NbootLifecycleDiscriminator::InField, + Self::InFieldLocked => NbootLifecycleDiscriminator::InFieldLocked, + Self::OemFieldReturn => NbootLifecycleDiscriminator::OemFieldReturn, + Self::FailureAnalysis => NbootLifecycleDiscriminator::FailureAnalysis, + Self::Bricked => NbootLifecycleDiscriminator::Bricked, + } + } + + pub const fn nboot_soc_lifecycle(self) -> u32 { + let discriminator = self.discriminator() as u16; + (((!discriminator) as u32) << 16) | (discriminator as u32) + } + + /// Returns a monotonic rank for forward-only progression checks. + /// Higher rank = further along the lifecycle. + const fn rank(self) -> u8 { + match self { + Self::Develop => 0, + Self::Develop2 => 1, + Self::InField => 2, + Self::InFieldLocked => 2, // Same rank as InField since locking is not a lifecycle progression. + Self::OemFieldReturn => 3, + Self::FailureAnalysis => 4, + Self::Bricked => 5, + } + } + + /// Returns true if advancing to `next` is a valid forward progression (no regressions, no same state). + pub const fn can_advance_to(self, next: Self) -> bool { + next.rank() >= self.rank() && (self as u32 != next as u32) + } +} diff --git a/libs/ec-slimloader-mcxa/src/rom_api.rs b/libs/ec-slimloader-mcxa/src/rom_api.rs deleted file mode 100644 index a1100ed0..00000000 --- a/libs/ec-slimloader-mcxa/src/rom_api.rs +++ /dev/null @@ -1,254 +0,0 @@ -#![allow(non_snake_case)] -#![allow(dead_code)] -#![allow(clippy::not_unsafe_ptr_arg_deref)] -use core::ffi::c_char; - -mod flash; -mod flexspi_nor; -mod kb; -mod nboot; -mod spi_flash; - -pub use flash::*; -pub use flexspi_nor::*; -pub use kb::*; -pub use nboot::*; -pub use spi_flash::*; - -use self::flash::FlashDriverRaw; -use self::flexspi_nor::FlexspiNorFlashDriverRaw; -use self::kb::KBApiDriverRaw; -use self::nboot::NbootDriverRaw; -use self::spi_flash::SpiFlashDriverRaw; - -pub type Status = u32; -pub type NbootBool = u32; -pub type NbootStatusProtected = u64; - -#[repr(C)] -#[derive(Clone, Copy)] -pub struct StandardVersionFields { - pub bugfix: u8, - pub minor: u8, - pub major: u8, - pub name: u8, -} - -#[repr(C)] -#[derive(Clone, Copy)] -pub union StandardVersion { - pub fields: StandardVersionFields, - pub version: u32, -} - -#[repr(C)] -struct RomApiRaw { - // NXP usage: uint32_t arg = ...; g_bootloaderTree->runBootloader(&arg); - // The ROM API takes a pointer to the argument word (NULL is allowed for default behavior). - pub run_bootloader: unsafe extern "C" fn(arg: *const u32), - // Flash driver interface table. - pub flash_api: *const FlashDriverRaw, - pub kb_api: *const KBApiDriverRaw, - pub nboot_api: *const NbootDriverRaw, - pub flex_spi_api: *const FlexspiNorFlashDriverRaw, - pub spi_flash_api: *const SpiFlashDriverRaw, - pub version: StandardVersion, - pub copyright: *const c_char, -} - -#[derive(Clone, Copy)] -pub struct RomApi { - raw: &'static RomApiRaw, -} - -impl RomApi { - const fn from_raw(raw: &'static RomApiRaw) -> Self { - Self { raw } - } - - pub fn run_bootloader(&self, arg: *const u32) { - unsafe { (self.raw.run_bootloader)(arg) } - } - - pub fn flash_api(&self) -> FlashDriver { - unsafe { FlashDriver::from_raw(&*self.raw.flash_api) } - } - - pub fn kb_api(&self) -> KBApiDriver { - unsafe { KBApiDriver::from_raw(&*self.raw.kb_api) } - } - - pub fn nboot_api(&self) -> NbootDriver { - unsafe { NbootDriver::from_raw(&*self.raw.nboot_api) } - } - - pub fn flex_spi_api(&self) -> FlexspiNorFlashDriver { - unsafe { FlexspiNorFlashDriver::from_raw(&*self.raw.flex_spi_api) } - } - - pub fn spi_flash_api(&self) -> SpiFlashDriver { - unsafe { SpiFlashDriver::from_raw(&*self.raw.spi_flash_api) } - } - - pub fn version(&self) -> StandardVersion { - self.raw.version - } - - pub fn copyright(&self) -> *const c_char { - self.raw.copyright - } -} - -pub type BootloaderTree = RomApi; - -#[inline(always)] -pub fn rom_api() -> RomApi { - const ROM_API_BASE: usize = 0x1303_D800; // from MCXA Reference Manual. - unsafe { - let ptr = ROM_API_BASE as *const RomApiRaw; - RomApi::from_raw(&*ptr) - } -} - -#[inline(always)] -pub fn bootloader_tree() -> BootloaderTree { - rom_api() -} - -// runBootloader API fields (Table 31) -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum RunBootTag { - EnterBoot = 0xEB << 24, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum RunBootMode { - PrimaryMasterBoot = 0x0 << 20, - IspBoot = 0x1 << 20, - ProvFwMode = 0x2 << 20, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum RunBootIspInterface { - AutoDetection = 0x0 << 16, - Uart = 0x1 << 16, - Spi = 0x2 << 16, - I2c = 0x8 << 16, - UsbHid = 0x10 << 16, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum RunBootMasterFlashBootOption { - InternalFlash = 0x0 << 16, - FlexspiFlash = 0x2 << 16, - OneBitSpiNorFlash = 0x3 << 16, - AutoDetection = 0x1F << 16, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum RunBootInterfaceInstance { - FlexspiPortA = 0x0 << 12, - FlexspiPortB = 0x1 << 12, - FlexspiPortAAndB = 0x2 << 12, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum RunBootImageIndex { - Image0 = 0x0 << 8, - Image1 = 0x1 << 8, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum RunBootRecoveryBootCfg1 { - SpiNorBaudRate0 = 0x0 << 6, - SpiNorBaudRate1 = 0x1 << 6, - SpiNorBaudRate2 = 0x2 << 6, - SpiNorBaudRate3 = 0x3 << 6, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum RunBootRecoveryBootCfg0 { - SpiNorChipSelect0 = 0x0 << 4, - SpiNorChipSelect1 = 0x1 << 4, - SpiNorChipSelect2 = 0x2 << 4, - SpiNorChipSelect3 = 0x3 << 4, -} - -/// Helper function to invoke the ROM API's run_bootloader function with the appropriate argument to enter ISP mode over UART. This can be used as a fallback if the main bootloader fails and we want to recover by flashing over UART using NXP's ISP tools. -/// The function will not return since the bootloader will take over execution after this call, but we still include an infinite loop after the call to satisfy the Rust type system since the function is declared to return ! (never). -pub fn run_bootloader_uart() -> ! { - // Build arg: tag 0xEB, mode ISP(1), interface UART(1) - let arg: u32 = RunBootTag::EnterBoot as u32 | RunBootMode::IspBoot as u32 | RunBootIspInterface::Uart as u32; - bootloader_tree().run_bootloader(&arg as *const u32); - loop { - core::hint::spin_loop() - } -} - -/// Helper function to get a pointer to the flash driver API from the ROM API tree. -pub fn flash_driver() -> FlashDriver { - // Match NXP usage: g_bootloaderTree->flashDriver->... - // The bootloader tree stores a direct pointer to the flash driver interface. - bootloader_tree().flash_api() -} - -/// Helper function to get a pointer to the nboot API from the ROM API tree. -pub fn nboot() -> NbootDriver { - // Match NXP usage: g_bootloaderTree->nbootDriver->... - bootloader_tree().nboot_api() -} - -/// Helper function to get a pointer to the KB driver API from the ROM API tree. -pub fn kb() -> KBApiDriver { - bootloader_tree().kb_api() -} - -/// Helper function to get a pointer to the FlexSPI NOR flash driver API from the ROM API tree. -pub fn flexspi_nor() -> FlexspiNorFlashDriver { - bootloader_tree().flex_spi_api() -} - -/// Helper function to get a pointer to the SPI flash driver API from the ROM API tree. -pub fn spi_flash() -> SpiFlashDriver { - bootloader_tree().spi_flash_api() -} - -#[inline(always)] -/// Used to get the default FlashConfig struct to be inited by flash_init(). -pub fn flash_cfg_for_rom_api() -> FlashConfig { - FlashConfig { - pflash_block_base: 0, - pflash_total_size: 0, - pflash_block_count: 0, - pflash_page_size: 0, - pflash_sector_size: 0, - ffr_config: FlashFfrConfig { - ffr_block_base: 0, - ffr_total_size: 0, - ffr_page_size: 0, - sector_size: 0, - cfpa_page_version: 0, - cfpa_page_offset: 0, - }, - mode_config: FlashModeConfig::new( - 0, - FlashReadSingleWordConfig::new( - FlashReadEccOption::On, - FlashReadMarginOption::Normal, - FlashReadDmaccOption::Disabled, - ), - FlashSetWriteModeConfig::new(FlashRampControlOption::Reserved, FlashRampControlOption::Reserved), - FlashSetReadModeConfig::new(0, 0, 0), - ), - nboot_ctx: core::ptr::null_mut(), - use_ahb_read: true, - } -} diff --git a/libs/ec-slimloader-mcxa/src/rom_api/flash.rs b/libs/ec-slimloader-mcxa/src/rom_api/flash.rs deleted file mode 100644 index 2a4e14ea..00000000 --- a/libs/ec-slimloader-mcxa/src/rom_api/flash.rs +++ /dev/null @@ -1,330 +0,0 @@ -#![allow(clippy::not_unsafe_ptr_arg_deref)] -// Safety: null, misaligned, invalid inputs or out of bounds references will cause ROM API to return an error code, which is handled by the caller. -use super::{StandardVersion, Status}; -use crate::error::FlashStatus; - -#[repr(C)] -pub struct FlashFfrConfig { - // FFR block base address. - pub ffr_block_base: u32, - // FFR total size in bytes. - pub ffr_total_size: u32, - // FFR page size in bytes. - pub ffr_page_size: u32, - // Sector size in bytes. - pub sector_size: u32, - // CFPA page version. - pub cfpa_page_version: u32, - // CFPA page offset within FFR. - pub cfpa_page_offset: u32, -} - -#[repr(u8)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum FlashReadEccOption { - On = 0, - Off = 1, -} - -#[repr(u8)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum FlashReadMarginOption { - Normal = 0, - VsProgram = 1, - VsErase = 2, - IllegalBitCombination = 3, -} - -#[repr(u8)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum FlashReadDmaccOption { - Disabled = 0, - Enabled = 1, -} - -#[repr(u8)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum FlashRampControlOption { - Reserved = 0, - DivisionFactor256 = 1, - DivisionFactor128 = 2, - DivisionFactor64 = 3, -} - -#[repr(C)] -pub struct FlashReadSingleWordConfig { - pub packed_options: u8, - pub reserved1: [u8; 3], -} - -impl FlashReadSingleWordConfig { - #[inline(always)] - pub const fn new(ecc: FlashReadEccOption, margin: FlashReadMarginOption, dmacc: FlashReadDmaccOption) -> Self { - Self { - packed_options: (ecc as u8) | ((margin as u8) << 1) | ((dmacc as u8) << 3), - reserved1: [0; 3], - } - } -} - -#[repr(C)] -pub struct FlashSetWriteModeConfig { - pub program_ramp_control: u8, - pub erase_ramp_control: u8, - pub reserved: [u8; 2], -} - -impl FlashSetWriteModeConfig { - #[inline(always)] - pub const fn new(program: FlashRampControlOption, erase: FlashRampControlOption) -> Self { - Self { - program_ramp_control: program as u8, - erase_ramp_control: erase as u8, - reserved: [0; 2], - } - } -} - -#[repr(C)] -pub struct FlashSetReadModeConfig { - pub read_interface_timing_trim: u16, - pub read_controller_timing_trim: u16, - pub read_wait_states: u8, - pub reserved: [u8; 3], -} - -impl FlashSetReadModeConfig { - #[inline(always)] - pub const fn new(read_interface_timing_trim: u16, read_controller_timing_trim: u16, read_wait_states: u8) -> Self { - Self { - read_interface_timing_trim, - read_controller_timing_trim, - read_wait_states, - reserved: [0; 3], - } - } -} - -#[repr(C)] -pub struct FlashModeConfig { - pub sys_freq_in_m_hz: u32, - pub read_single_word: FlashReadSingleWordConfig, - pub set_write_mode: FlashSetWriteModeConfig, - pub set_read_mode: FlashSetReadModeConfig, -} - -impl FlashModeConfig { - #[inline(always)] - pub const fn new( - sys_freq_in_m_hz: u32, - read_single_word: FlashReadSingleWordConfig, - set_write_mode: FlashSetWriteModeConfig, - set_read_mode: FlashSetReadModeConfig, - ) -> Self { - Self { - sys_freq_in_m_hz, - read_single_word, - set_write_mode, - set_read_mode, - } - } -} - -#[repr(C)] -pub struct FlashConfig { - // P-Flash block base address. - pub pflash_block_base: u32, - // P-Flash total size in bytes. - pub pflash_total_size: u32, - // P-Flash block count. - pub pflash_block_count: u32, - // P-Flash page size in bytes. - pub pflash_page_size: u32, - // P-Flash sector size in bytes. - pub pflash_sector_size: u32, - // FFR configuration. - pub ffr_config: FlashFfrConfig, - // Flash controller parameter configuration. - pub mode_config: FlashModeConfig, - // ROM NBOOT context pointer. - pub nboot_ctx: *mut u32, - // Use AHB read (true) or alternative read path (false), per ROM. - pub use_ahb_read: bool, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum FlashPropertyTag { - PflashSectorSize = 0x00, - PflashTotalSize = 0x01, - PflashBlockSize = 0x02, - PflashBlockCount = 0x03, - PflashBlockBaseAddr = 0x04, - PflashPageSize = 0x30, - PflashSystemFreq = 0x31, - FfrSectorSize = 0x40, - FfrTotalSize = 0x41, - FfrBlockBaseAddr = 0x42, - FfrPageSize = 0x43, -} - -// Flash erase key required by the ROM flash erase-sector entry point. -// Defined as FOUR_CHAR_CODE('l', 'f', 'e', 'k') = (('k' << 24) | ('e' << 16) | ('f' << 8) | ('l')) -pub const FLASH_API_ERASE_KEY: u32 = 0x6b65666c; - -#[repr(C)] -pub(super) struct FlashDriverRaw { - // Initialize flash driver/config. - pub flash_init: unsafe extern "C" fn(config: *mut FlashConfig) -> Status, - // Erase sector(s). Requires FLASH_API_ERASE_KEY. - pub flash_erase_sector: - unsafe extern "C" fn(config: *mut FlashConfig, start: u32, length_in_bytes: u32, key: u32) -> Status, - // Program phrase (alignment requirements apply). - pub flash_program_phrase: - unsafe extern "C" fn(config: *mut FlashConfig, start: u32, src: *const u8, length_in_bytes: u32) -> Status, - // Program page. - pub flash_program_page: - unsafe extern "C" fn(config: *mut FlashConfig, start: u32, src: *const u8, length_in_bytes: u32) -> Status, - // Verify programmed data. - pub flash_verify_program: unsafe extern "C" fn( - config: *mut FlashConfig, - start: u32, - length_in_bytes: u32, - expected_data: *const u8, - failed_address: *mut u32, - failed_data: *mut u32, - ) -> Status, - // Verify phrase erase. - pub flash_verify_erase_phrase: - unsafe extern "C" fn(config: *mut FlashConfig, start: u32, length_in_bytes: u32) -> Status, - // Verify page erase. - pub flash_verify_erase_page: - unsafe extern "C" fn(config: *mut FlashConfig, start: u32, length_in_bytes: u32) -> Status, - // Verify sector erase. - pub flash_verify_erase_sector: - unsafe extern "C" fn(config: *mut FlashConfig, start: u32, length_in_bytes: u32) -> Status, - // Get flash property. - pub flash_get_property: - unsafe extern "C" fn(config: *mut FlashConfig, which_property: u32, value: *mut u32) -> Status, - // Verify phrase erase in IFR. - pub ifr_verify_erase_phrase: - unsafe extern "C" fn(config: *mut FlashConfig, start: u32, length_in_bytes: u32) -> Status, - // Verify page erase in IFR. - pub ifr_verify_erase_page: - unsafe extern "C" fn(config: *mut FlashConfig, start: u32, length_in_bytes: u32) -> Status, - // Verify sector erase in IFR. - pub ifr_verify_erase_sector: - unsafe extern "C" fn(config: *mut FlashConfig, start: u32, length_in_bytes: u32) -> Status, - // Read flash into dest. - pub flash_read: - unsafe extern "C" fn(config: *mut FlashConfig, start: u32, dest: *mut u8, length_in_bytes: u32) -> Status, - // Flash API version. - pub version: StandardVersion, -} - -#[derive(Clone, Copy)] -pub struct FlashDriver { - raw: &'static FlashDriverRaw, -} - -impl FlashDriver { - pub(super) const fn from_raw(raw: &'static FlashDriverRaw) -> Self { - Self { raw } - } - - pub fn flash_init(&self, config: *mut FlashConfig) -> FlashStatus { - unsafe { FlashStatus::from((self.raw.flash_init)(config)) } - } - - pub fn flash_erase_sector( - &self, - config: *mut FlashConfig, - start: u32, - length_in_bytes: u32, - key: u32, - ) -> FlashStatus { - unsafe { FlashStatus::from((self.raw.flash_erase_sector)(config, start, length_in_bytes, key)) } - } - - pub fn flash_program_phrase( - &self, - config: *mut FlashConfig, - start: u32, - src: *const u8, - length_in_bytes: u32, - ) -> FlashStatus { - unsafe { FlashStatus::from((self.raw.flash_program_phrase)(config, start, src, length_in_bytes)) } - } - - pub fn flash_program_page( - &self, - config: *mut FlashConfig, - start: u32, - src: *const u8, - length_in_bytes: u32, - ) -> FlashStatus { - unsafe { FlashStatus::from((self.raw.flash_program_page)(config, start, src, length_in_bytes)) } - } - - pub fn flash_verify_program( - &self, - config: *mut FlashConfig, - start: u32, - length_in_bytes: u32, - expected_data: *const u8, - failed_address: *mut u32, - failed_data: *mut u32, - ) -> FlashStatus { - unsafe { - FlashStatus::from((self.raw.flash_verify_program)( - config, - start, - length_in_bytes, - expected_data, - failed_address, - failed_data, - )) - } - } - - pub fn flash_verify_erase_phrase(&self, config: *mut FlashConfig, start: u32, length_in_bytes: u32) -> FlashStatus { - unsafe { FlashStatus::from((self.raw.flash_verify_erase_phrase)(config, start, length_in_bytes)) } - } - - pub fn flash_verify_erase_page(&self, config: *mut FlashConfig, start: u32, length_in_bytes: u32) -> FlashStatus { - unsafe { FlashStatus::from((self.raw.flash_verify_erase_page)(config, start, length_in_bytes)) } - } - - pub fn flash_verify_erase_sector(&self, config: *mut FlashConfig, start: u32, length_in_bytes: u32) -> FlashStatus { - unsafe { FlashStatus::from((self.raw.flash_verify_erase_sector)(config, start, length_in_bytes)) } - } - - pub fn flash_get_property( - &self, - config: *mut FlashConfig, - which_property: FlashPropertyTag, - value: *mut u32, - ) -> FlashStatus { - unsafe { FlashStatus::from((self.raw.flash_get_property)(config, which_property as u32, value)) } - } - - pub fn ifr_verify_erase_phrase(&self, config: *mut FlashConfig, start: u32, length_in_bytes: u32) -> FlashStatus { - unsafe { FlashStatus::from((self.raw.ifr_verify_erase_phrase)(config, start, length_in_bytes)) } - } - - pub fn ifr_verify_erase_page(&self, config: *mut FlashConfig, start: u32, length_in_bytes: u32) -> FlashStatus { - unsafe { FlashStatus::from((self.raw.ifr_verify_erase_page)(config, start, length_in_bytes)) } - } - - pub fn ifr_verify_erase_sector(&self, config: *mut FlashConfig, start: u32, length_in_bytes: u32) -> FlashStatus { - unsafe { FlashStatus::from((self.raw.ifr_verify_erase_sector)(config, start, length_in_bytes)) } - } - - pub fn flash_read(&self, config: *mut FlashConfig, start: u32, dest: *mut u8, length_in_bytes: u32) -> FlashStatus { - unsafe { FlashStatus::from((self.raw.flash_read)(config, start, dest, length_in_bytes)) } - } - - pub fn version(&self) -> StandardVersion { - self.raw.version - } -} diff --git a/libs/ec-slimloader-mcxa/src/rom_api/flexspi_nor.rs b/libs/ec-slimloader-mcxa/src/rom_api/flexspi_nor.rs deleted file mode 100644 index ba263930..00000000 --- a/libs/ec-slimloader-mcxa/src/rom_api/flexspi_nor.rs +++ /dev/null @@ -1,410 +0,0 @@ -#![allow(clippy::not_unsafe_ptr_arg_deref)] -// Safety: null, misaligned, invalid inputs or out of bounds references will cause ROM API to return an error code, which is handled by the caller. -use super::Status; -use crate::error::FlexspiStatus; - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum SerialNorOptionTag { - Config = 0x0C, // SDK vs. RM mismatch; TODO: confirm correct value and semantics. -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum SerialNorOptionSize { - Option0Only = 0, - Option0AndOption1 = 1, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum SerialNorDeviceType { - ReadSfdpSdr = 0, - ReadSfdpDdr = 1, - Hyperflash1V8 = 2, - Hyperflash3V0 = 3, - MacronixOctalDdr = 4, - MacronixOctalSdr = 5, - MicronOctalDdr = 6, - MicronOctalSdr = 7, - AdestoOctalDdr = 8, - AdestoOctalSdr = 9, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum SerialNorOptionPadEncoding { - // Encoded values for option0.query_pads / option0.cmd_pads. - // These match the ROM option field encoding, not the literal kSerialFlash_*Pad values. - One = 0, - Four = 2, - Eight = 3, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum SerialNorQuadModeSetting { - NotConfigured = 0, - StatusReg1Bit6 = 1, - StatusReg2Bit1 = 2, - StatusReg2Bit7 = 3, - StatusReg2Bit1Via0x31 = 4, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum SerialNorMiscMode { - Disabled = 0, - Mode0_4_4 = 1, - Mode0_8_8 = 2, - DataOrderSwapped = 3, - SecondPinMux = 4, - InternalLoopback = 5, - SpiMode = 6, - ExternalDqs = 8, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum FlexspiSerialClockFrequency { - NoChange = 0, - MHz30 = 1, - MHz50 = 2, - MHz60 = 3, - MHz75 = 4, - MHz80 = 5, - MHz100 = 6, - MHz133 = 7, - MHz166 = 8, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum SerialNorFlashConnection { - SinglePortA = 0, - Parallel = 1, - SinglePortB = 2, - BothPorts = 3, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum FlexspiClockSource { - // Table 60 selector values for the ROM set_clock_source API. - NoClock = 0, - Pll0 = 1, - FroHf = 3, - Pll1 = 5, - UsbPll = 6, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum FlexspiClockConfigFrequency { - // Table 61 values for the ROM config_clock API. - MHz30 = 1, - MHz50 = 2, - MHz60 = 3, - MHz75 = 4, - MHz100 = 5, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum FlexspiClockConfigMode { - Sdr = 0, - Ddr = 1, -} - -#[inline(always)] -pub const fn pack_serial_nor_option0( - option_size: SerialNorOptionSize, - device_type: SerialNorDeviceType, - query_pad: SerialNorOptionPadEncoding, - cmd_pad: SerialNorOptionPadEncoding, - quad_mode_setting: SerialNorQuadModeSetting, - misc_mode: SerialNorMiscMode, - max_freq: FlexspiSerialClockFrequency, -) -> u32 { - ((SerialNorOptionTag::Config as u32) << 28) - | ((option_size as u32) << 24) - | ((device_type as u32) << 20) - | ((query_pad as u32) << 16) - | ((cmd_pad as u32) << 12) - | ((quad_mode_setting as u32) << 8) - | ((misc_mode as u32) << 4) - | (max_freq as u32) -} - -#[inline(always)] -pub const fn pack_serial_nor_option1( - flash_connection: SerialNorFlashConnection, - dqs_pinmux_group: u32, - pinmux_group: u32, - status_override: u32, - dummy_cycles: u32, -) -> u32 { - ((flash_connection as u32) << 28) - | ((dqs_pinmux_group & 0xF) << 20) - | ((pinmux_group & 0xF) << 16) - | ((status_override & 0xFF) << 8) - | (dummy_cycles & 0xFF) -} - -#[repr(C)] -#[derive(Clone, Copy, Default)] -pub struct SerialNorConfigOption { - // Packed ROM ABI input for `flexspiNorDriver->get_config(...)`. - // - // Typical MCXA ROM examples: - // - Quad NOR, Quad SDR read @ 75 MHz: option0 = 0xC000_0004, option1 = 0 - // - Quad NOR, Quad DDR read @ 60 MHz: option0 = 0xC010_0003, option1 = 0 - // - // Build these words with `pack_serial_nor_option0(...)` and - // `pack_serial_nor_option1(...)`, keeping the transport struct itself raw. - // - // Example call pattern from the ROM docs: - // let mut option = SerialNorConfigOption { option0: 0xC000_0001, option1: 0 }; - // flexspi_nor().get_config(instance, &mut cfg, &mut option); - pub option0: u32, - pub option1: u32, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum FlexspiOperationType { - Command = 0, - Config = 1, - Write = 2, - Read = 3, -} - -impl FlexspiOperationType { - pub const END: Self = Self::Read; -} - -#[repr(C)] -#[derive(Clone, Copy)] -pub struct FlashRunContextFields { - pub por_mode: u8, - pub current_mode: u8, - pub exit_no_cmd_sequence: u8, - pub restore_sequence: u8, -} - -#[repr(C)] -#[derive(Clone, Copy)] -pub union FlashRunContext { - pub B: FlashRunContextFields, - pub U: u32, -} - -#[repr(C)] -#[derive(Clone, Copy)] -pub struct FlexspiLutSeq { - pub seq_num: u8, - pub seq_id: u8, - pub reserved: u16, -} - -#[repr(C)] -#[derive(Clone, Copy)] -pub struct FlexspiDllTime { - pub time_100ps: u8, - pub delay_cells: u8, -} - -#[repr(C)] -pub struct FlexspiMemConfig { - pub tag: u32, - pub version: u32, - pub reserved0: u32, - pub read_sample_clk_src: u8, - pub cs_hold_time: u8, - pub cs_setup_time: u8, - pub column_address_width: u8, - pub device_mode_cfg_enable: u8, - pub device_mode_type: u8, - pub wait_time_cfg_commands: u16, - pub device_mode_seq: FlexspiLutSeq, - pub device_mode_arg: u32, - pub config_cmd_enable: u8, - pub config_mode_type: [u8; 3], - pub config_cmd_seqs: [FlexspiLutSeq; 3], - pub reserved1: u32, - pub config_cmd_args: [u32; 3], - pub reserved2: u32, - pub controller_misc_option: u32, - pub device_type: u8, - pub sflash_pad_type: u8, - pub serial_clk_freq: u8, - pub lut_custom_seq_enable: u8, - pub reserved3: [u32; 2], - pub sflash_a1_size: u32, - pub sflash_a2_size: u32, - pub sflash_b1_size: u32, - pub sflash_b2_size: u32, - pub cs_pad_setting_override: u32, - pub sclk_pad_setting_override: u32, - pub data_pad_setting_override: u32, - pub dqs_pad_setting_override: u32, - pub timeout_in_ms: u32, - pub command_interval: u32, - pub data_valid_time: [FlexspiDllTime; 2], - pub busy_offset: u16, - pub busy_bit_polarity: u16, - pub lookup_table: [u32; 64], - pub lut_custom_seq: [FlexspiLutSeq; 12], - pub dll0_cr_val: u32, - pub dll1_cr_val: u32, - pub reserved4: [u32; 2], -} - -#[repr(C)] -pub struct FlexspiNorConfig { - pub mem_config: FlexspiMemConfig, - pub page_size: u32, - pub sector_size: u32, - pub ipcmd_serial_clk_freq: u8, - pub is_uniform_block_size: u8, - pub is_data_order_swapped: u8, - pub reserved0: [u8; 1], - pub serial_nor_type: u8, - pub need_exit_no_cmd_mode: u8, - pub half_clk_for_non_read_cmd: u8, - pub need_restore_no_cmd_mode: u8, - pub block_size: u32, - pub flash_state_ctx: FlashRunContext, - pub reserved2: [u32; 10], -} - -#[repr(C)] -pub struct FlexspiXfer { - pub operation: FlexspiOperationType, - pub base_address: u32, - pub seq_id: u32, - pub seq_num: u32, - pub is_parallel_mode_enable: bool, - pub tx_buffer: *const u32, - pub tx_size: u32, - pub rx_buffer: *mut u32, - pub rx_size: u32, -} - -#[repr(C)] -pub(super) struct FlexspiNorFlashDriverRaw { - pub version: u32, - pub init: unsafe extern "C" fn(instance: u32, cfg: *mut FlexspiNorConfig) -> Status, - pub page_program: - unsafe extern "C" fn(instance: u32, cfg: *mut FlexspiNorConfig, dst: u32, src: *const u32) -> Status, - pub erase_all: unsafe extern "C" fn(instance: u32, cfg: *mut FlexspiNorConfig) -> Status, - pub erase: unsafe extern "C" fn(instance: u32, cfg: *mut FlexspiNorConfig, start: u32, len: u32) -> Status, - pub erase_sector: unsafe extern "C" fn(instance: u32, cfg: *mut FlexspiNorConfig, addr: u32) -> Status, - pub erase_block: unsafe extern "C" fn(instance: u32, cfg: *mut FlexspiNorConfig, addr: u32) -> Status, - pub get_config: - unsafe extern "C" fn(instance: u32, cfg: *mut FlexspiNorConfig, opt: *mut SerialNorConfigOption) -> Status, - pub read: unsafe extern "C" fn( - instance: u32, - cfg: *mut FlexspiNorConfig, - dst: *mut u32, - start: u32, - bytes: u32, - ) -> Status, - pub xfer: unsafe extern "C" fn(instance: u32, xfer: *mut FlexspiXfer) -> Status, - pub update_lut: unsafe extern "C" fn(instance: u32, seq_index: u32, lut_base: *const u32, num_seq: u32) -> Status, - pub set_clock_source: unsafe extern "C" fn(clock_src: u32) -> Status, - pub config_clock: unsafe extern "C" fn(instance: u32, freq_option: u32, sample_clk_mode: u32), - pub partial_program: - unsafe extern "C" fn(instance: u32, cfg: *mut FlexspiNorConfig, dst: u32, src: *const u32, len: u32) -> Status, -} - -#[derive(Clone, Copy)] -pub struct FlexspiNorFlashDriver { - raw: &'static FlexspiNorFlashDriverRaw, -} - -impl FlexspiNorFlashDriver { - pub(super) const fn from_raw(raw: &'static FlexspiNorFlashDriverRaw) -> Self { - Self { raw } - } - - pub fn version(&self) -> u32 { - self.raw.version - } - - pub fn init(&self, instance: u32, cfg: *mut FlexspiNorConfig) -> FlexspiStatus { - unsafe { FlexspiStatus::from((self.raw.init)(instance, cfg)) } - } - - pub fn page_program(&self, instance: u32, cfg: *mut FlexspiNorConfig, dst: u32, src: *const u32) -> FlexspiStatus { - unsafe { FlexspiStatus::from((self.raw.page_program)(instance, cfg, dst, src)) } - } - - pub fn erase_all(&self, instance: u32, cfg: *mut FlexspiNorConfig) -> FlexspiStatus { - unsafe { FlexspiStatus::from((self.raw.erase_all)(instance, cfg)) } - } - - pub fn erase(&self, instance: u32, cfg: *mut FlexspiNorConfig, start: u32, len: u32) -> FlexspiStatus { - unsafe { FlexspiStatus::from((self.raw.erase)(instance, cfg, start, len)) } - } - - pub fn erase_sector(&self, instance: u32, cfg: *mut FlexspiNorConfig, addr: u32) -> FlexspiStatus { - unsafe { FlexspiStatus::from((self.raw.erase_sector)(instance, cfg, addr)) } - } - - pub fn erase_block(&self, instance: u32, cfg: *mut FlexspiNorConfig, addr: u32) -> FlexspiStatus { - unsafe { FlexspiStatus::from((self.raw.erase_block)(instance, cfg, addr)) } - } - - pub fn get_config( - &self, - instance: u32, - cfg: *mut FlexspiNorConfig, - opt: *mut SerialNorConfigOption, - ) -> FlexspiStatus { - unsafe { FlexspiStatus::from((self.raw.get_config)(instance, cfg, opt)) } - } - - pub fn read( - &self, - instance: u32, - cfg: *mut FlexspiNorConfig, - dst: *mut u32, - start: u32, - bytes: u32, - ) -> FlexspiStatus { - unsafe { FlexspiStatus::from((self.raw.read)(instance, cfg, dst, start, bytes)) } - } - - pub fn xfer(&self, instance: u32, xfer: *mut FlexspiXfer) -> FlexspiStatus { - unsafe { FlexspiStatus::from((self.raw.xfer)(instance, xfer)) } - } - - pub fn update_lut(&self, instance: u32, seq_index: u32, lut_base: *const u32, num_seq: u32) -> FlexspiStatus { - unsafe { FlexspiStatus::from((self.raw.update_lut)(instance, seq_index, lut_base, num_seq)) } - } - - pub fn set_clock_source(&self, clock_src: FlexspiClockSource) -> FlexspiStatus { - unsafe { FlexspiStatus::from((self.raw.set_clock_source)(clock_src as u32)) } - } - - pub fn config_clock( - &self, - instance: u32, - freq_option: FlexspiClockConfigFrequency, - sample_clk_mode: FlexspiClockConfigMode, - ) { - unsafe { (self.raw.config_clock)(instance, freq_option as u32, sample_clk_mode as u32) } - } - - pub fn partial_program( - &self, - instance: u32, - cfg: *mut FlexspiNorConfig, - dst: u32, - src: *const u32, - len: u32, - ) -> FlexspiStatus { - unsafe { FlexspiStatus::from((self.raw.partial_program)(instance, cfg, dst, src, len)) } - } -} diff --git a/libs/ec-slimloader-mcxa/src/rom_api/kb.rs b/libs/ec-slimloader-mcxa/src/rom_api/kb.rs deleted file mode 100644 index 16c79814..00000000 --- a/libs/ec-slimloader-mcxa/src/rom_api/kb.rs +++ /dev/null @@ -1,130 +0,0 @@ -#![allow(clippy::not_unsafe_ptr_arg_deref)] -// Safety: null, misaligned, invalid inputs or out of bounds references will cause ROM API to return an error code, which is handled by the caller. -use core::ffi::c_void; - -use super::Status; -use crate::error::KbStatus; - -// KBoot (KB) ROM API - -#[repr(C)] -pub struct KbRegion { - // Region base address. - pub address: u32, - // Region length in bytes. - pub length: u32, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum KbOperation { - // Verify/authenticate image. - AuthenticateImage = 1, - // Load image. - LoadImage = 2, - // Number of KB operations. - OperationCount = 3, -} - -#[repr(C)] -#[derive(Clone, Copy)] -pub struct KbLoadSb { - // Profile selector (meaning per ROM header / implementation). - pub profile: u32, - // Minimum build number. - pub minBuildNumber: u32, - // Override SB boot section ID. - pub overrideSBBootSectionID: u32, - // User SB KEK pointer. - pub userSBKEK: *mut u32, - // Number of region descriptors. - pub regionCount: u32, - // Pointer to regions array. - pub regions: *const KbRegion, -} - -#[repr(C)] -#[derive(Clone, Copy)] -pub struct KbAuthenticate { - // Profile selector (meaning per ROM header / implementation). - pub profile: u32, - // Minimum build number. - pub minBuildNumber: u32, - // Maximum image length. - pub maxImageLength: u32, - // User RHK pointer. - pub userRHK: *mut u32, -} - -#[repr(C)] -pub union KbOptionsParams { - pub authenticate: KbAuthenticate, - pub loadSB: KbLoadSb, -} - -#[repr(C)] -pub struct KbOptions { - // Must be KB_API_VERSION. - pub version: u32, - // Caller-provided buffer used by ROM. - pub buffer: *mut u8, - // Length of buffer in bytes. - pub bufferLength: u32, - // Requested operation. - pub op: KbOperation, - // Operation-specific parameters. - pub params: KbOptionsParams, -} - -#[repr(C)] -pub struct KbBufferDesc { - // Buffer pointer. - pub buf: *mut u8, - // Buffer length in bytes. - pub len: u32, - // Allocated size. - pub allocated: u32, -} - -#[repr(C)] -pub struct KbSessionRef { - // Options used to create the session. - pub options: KbOptions, - // Internal buffer descriptor. - pub buffer_desc: KbBufferDesc, - // Opaque operation context. - pub op_context: *mut c_void, -} - -#[repr(C)] -pub(super) struct KBApiDriverRaw { - // Initialize KB session. - pub kb_init: unsafe extern "C" fn(session: *mut *mut KbSessionRef, options: *const KbOptions) -> Status, - // Deinitialize KB session. - pub kb_deinit: unsafe extern "C" fn(session: *mut KbSessionRef) -> Status, - // Execute KB operation over a data buffer. - pub kb_execute: unsafe extern "C" fn(session: *mut KbSessionRef, data: *const u8, dataLength: u32) -> Status, -} - -#[derive(Clone, Copy)] -pub struct KBApiDriver { - raw: &'static KBApiDriverRaw, -} - -impl KBApiDriver { - pub(super) const fn from_raw(raw: &'static KBApiDriverRaw) -> Self { - Self { raw } - } - - pub fn kb_init(&self, session: *mut *mut KbSessionRef, options: *const KbOptions) -> KbStatus { - unsafe { KbStatus::from((self.raw.kb_init)(session, options)) } - } - - pub fn kb_deinit(&self, session: *mut KbSessionRef) -> KbStatus { - unsafe { KbStatus::from((self.raw.kb_deinit)(session)) } - } - - pub fn kb_execute(&self, session: *mut KbSessionRef, data: *const u8, dataLength: u32) -> KbStatus { - unsafe { KbStatus::from((self.raw.kb_execute)(session, data, dataLength)) } - } -} diff --git a/libs/ec-slimloader-mcxa/src/rom_api/nboot.rs b/libs/ec-slimloader-mcxa/src/rom_api/nboot.rs deleted file mode 100644 index ba90fdf5..00000000 --- a/libs/ec-slimloader-mcxa/src/rom_api/nboot.rs +++ /dev/null @@ -1,537 +0,0 @@ -#![allow(clippy::not_unsafe_ptr_arg_deref)] -// Safety: null, misaligned, invalid inputs or out of bounds references will cause ROM API to return an error code, which is handled by the caller. -use super::{NbootBool, NbootStatusProtected}; -use crate::error::*; - -// Boolean/result markers returned via nboot_bool_t out-parameters. -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum NbootBoolValue { - True = 0x3C5A_C33C, - True256 = 0x3C5A_C35A, - True384 = 0x3C5A_C3A5, - False = 0x5AA5_5AA5, -} - -impl NbootBoolValue { - #[inline(always)] - pub const fn from_raw(raw: NbootBool) -> Option { - match raw { - 0x3C5A_C33C => Some(Self::True), - 0x3C5A_C35A => Some(Self::True256), - 0x3C5A_C3A5 => Some(Self::True384), - 0x5AA5_5AA5 => Some(Self::False), - _ => None, - } - } -} - -#[repr(C)] -pub struct NbootCtx { - // Opaque context buffer. Size must match NBOOT_CONTEXT_SIZE from the ROM header. - pub opaque: [u8; 0xA94], -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum NbootMemCryptRegion { - Region0 = 0, - Region1 = 1, - Region2 = 2, - Region3 = 3, - Region4 = 4, - Region5 = 5, - Region6 = 6, - Region7 = 7, -} - -pub type NbootMemCryptOperation = u32; // Need to confirm exact typed values. - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum NbootMemCryptIpedModeSelect { - Rounds12 = 0x3C5A_C33C, - Rounds22 = 0x5AA5_5AA5, - FullyPipelined = 0x5A5A_5A5A, - NotFullyPipelined = 0xA5A5_A5A5, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum NbootMemCryptEngineType { - Npx = 0x5959_5959, - Iped = 0x9595_9595, -} - -#[repr(C)] -#[derive(Clone, Copy)] -pub struct NbootNpxRegionConfig { - // Must be NbootMemCryptEngineType::Npx. - pub configId: NbootMemCryptEngineType, - // Start address (inclusive). - pub startAddress: u32, - // End address (inclusive). - pub endAddress: u32, - // Subregion bitmap. - pub subregion: u64, - // IV erase counter. - pub ivEraseCounter: u32, - // Region lock flag. - pub regionLock: u8, -} - -#[repr(C)] -#[derive(Clone, Copy)] -pub struct NbootIpedRegionConfig { - // Must be NbootMemCryptEngineType::Iped. - pub configId: NbootMemCryptEngineType, - // Start address (inclusive). - pub startAddress: u32, - // End address (inclusive). - pub endAddress: u32, - // IV erase counter. - pub ivEraseCounter: u32, - // Region flags. - pub regionFlags: u8, - // Additional authenticated data. - pub aad: u32, -} - -#[repr(C)] -pub union NbootMemCryptRegionConfig { - pub npxConfig: NbootNpxRegionConfig, - pub ipedConfig: NbootIpedRegionConfig, -} - -#[repr(C)] -pub struct NbootRotAuthParms { - pub soc_rootKeyRevocation: [u32; 4], - pub soc_imageKeyRevocation: u32, - pub soc_rkh: [u32; 12], - pub soc_rkh_1: [u32; 12], // PQC_ROTKH (hash of hashes) - pub soc_numberOfRootKeys: u32, - pub soc_rootKeyUsage: [u32; 4], - pub soc_rootKeyTypeAndLength: u32, - pub soc_lifecycle: u32, -} - -#[repr(C)] -pub struct NbootImgAuthParms { - pub soc_RoTNVM: NbootRotAuthParms, - pub soc_trustedFirmwareVersion: u32, -} - -#[repr(C)] -pub struct NbootImgAuthenticateCmacParms { - pub expectedMAC: [u32; 4], -} - -#[repr(C)] -pub struct NbootSb4LoadManifestParms { - // Returned RoTNVM/auth parameters. - pub soc_RoTNVM: NbootRotAuthParms, - // Returned trusted firmware version. - pub soc_trustedFirmwareVersion: u32, - // Returned maximum SB block size. - pub maxBlockSize: u32, - // Returned PCK blob. - pub pckBlob: [u8; 48], -} - -// Root key configuration constants for NBOOT -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum NbootRootKeyRevocation { - Enabled = 0xAA, - Revoked = 0xBB, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum NbootRootKeyUsage { - All = 0x0, - DebugCa = 0x1, - ImageCaFwCa = 0x2, - DebugCaImageCaFwCa = 0x3, - ImageKeyFwKey = 0x4, - ImageKey = 0x5, - FwKey = 0x6, - Unused = 0x7, -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum NbootRootKeyType { - EcdsaP384Mldsa87 = 0x0000_FD04, // Hybrid root key type: ECDSA P-384 + ML-DSA-87 -} - -// Lifecycle state codes (low-byte discriminators) and full CFPA LC_STATE values. -// Per Table 18 (Life Cycle States): LC_STATE is a u32 like 0x9635_FC03. -// Some call sites only carry the low-byte discriminator (e.g. 0x03 for Develop), -// so we keep both representations. -#[repr(u8)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum NbootLifecycleDiscriminator { - Develop = 0x03, - Develop2 = 0x07, - InField = 0x0F, - InFieldLocked = 0xCF, - OemFieldReturn = 0x1F, - FailureAnalysis = 0x3F, - Bricked = 0x5A, -} - -impl NbootLifecycleDiscriminator { - #[inline(always)] - pub const fn from_raw(raw: u8) -> Option { - match raw { - 0x03 => Some(Self::Develop), - 0x07 => Some(Self::Develop2), - 0x0F => Some(Self::InField), - 0xCF => Some(Self::InFieldLocked), - 0x1F => Some(Self::OemFieldReturn), - 0x3F => Some(Self::FailureAnalysis), - 0x5A => Some(Self::Bricked), - _ => None, - } - } - - #[inline(always)] - pub const fn state(self) -> NbootLifecycleState { - match self { - Self::Develop => NbootLifecycleState::Develop, - Self::Develop2 => NbootLifecycleState::Develop2, - Self::InField => NbootLifecycleState::InField, - Self::InFieldLocked => NbootLifecycleState::InFieldLocked, - Self::OemFieldReturn => NbootLifecycleState::OemFieldReturn, - Self::FailureAnalysis => NbootLifecycleState::FailureAnalysis, - Self::Bricked => NbootLifecycleState::Bricked, - } - } -} - -#[repr(u32)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum NbootLifecycleState { - Develop = 0x9635_FC03, - Develop2 = 0x9635_F807, - InField = 0x9635_F00F, - InFieldLocked = 0x9635_30CF, - OemFieldReturn = 0x9635_E01F, - FailureAnalysis = 0x9635_C03F, - Bricked = 0x9635_A55A, -} - -impl NbootLifecycleState { - #[inline(always)] - pub const fn from_raw(raw: u32) -> Option { - match raw { - 0x9635_FC03 => Some(Self::Develop), - 0x9635_F807 => Some(Self::Develop2), - 0x9635_F00F => Some(Self::InField), - 0x9635_30CF => Some(Self::InFieldLocked), - 0x9635_E01F => Some(Self::OemFieldReturn), - 0x9635_C03F => Some(Self::FailureAnalysis), - 0x9635_A55A => Some(Self::Bricked), - _ => None, - } - } - - #[inline(always)] - pub const fn discriminator(self) -> NbootLifecycleDiscriminator { - match self { - Self::Develop => NbootLifecycleDiscriminator::Develop, - Self::Develop2 => NbootLifecycleDiscriminator::Develop2, - Self::InField => NbootLifecycleDiscriminator::InField, - Self::InFieldLocked => NbootLifecycleDiscriminator::InFieldLocked, - Self::OemFieldReturn => NbootLifecycleDiscriminator::OemFieldReturn, - Self::FailureAnalysis => NbootLifecycleDiscriminator::FailureAnalysis, - Self::Bricked => NbootLifecycleDiscriminator::Bricked, - } - } - - #[inline(always)] - pub const fn nboot_soc_lifecycle(self) -> u32 { - let discriminator = self.discriminator() as u16; - (((!discriminator) as u32) << 16) | (discriminator as u32) - } - - #[inline(always)] - pub const fn from_any_raw(raw: u32) -> Option { - if let Some(state) = Self::from_raw(raw) { - return Some(state); - } - // Short-form input: bare discriminator byte only. A long-form value that - // failed the full-word match above is corrupt; do not guess from its low byte. - if raw <= 0xFF { - if let Some(d) = NbootLifecycleDiscriminator::from_raw(raw as u8) { - return Some(d.state()); - } - } - None - } - - /// Returns a monotonic rank for forward-only progression checks. - /// Higher rank = further along the lifecycle. - #[inline(always)] - pub const fn rank(self) -> u8 { - match self { - Self::Develop => 0, - Self::Develop2 => 1, - Self::InField => 2, - Self::InFieldLocked => 2, // Same rank as InField since locking is not a lifecycle progression. - Self::OemFieldReturn => 3, - Self::FailureAnalysis => 4, - Self::Bricked => 5, - } - } - - /// Returns true if advancing to `next` is a valid forward progression (no regressions, no same state). - #[inline(always)] - pub const fn can_advance_to(self, next: Self) -> bool { - next.rank() >= self.rank() && (self as u32 != next as u32) - } -} - -// Sealed trait: CanAdvanceTo - -// Only the combinations listed below exist. Attempting to call -// `cfpa_stage_lifecycle_advance_and_reset` with any other (From, To) pair -// is a *compile* error. - -mod sealed { - pub trait Sealed {} - impl Sealed for super::Develop {} - impl Sealed for super::Develop2 {} - impl Sealed for super::InField {} - impl Sealed for super::InFieldLocked {} - impl Sealed for super::OemFieldReturn {} - impl Sealed for super::FailureAnalysis {} - impl Sealed for super::Bricked {} -} - -// Zero-sized types, one per lifecycle state, used as type parameters to enforce valid lifecycle transitions at compile time. -pub struct Develop; -pub struct Develop2; -pub struct InField; -pub struct InFieldLocked; -pub struct OemFieldReturn; -pub struct FailureAnalysis; -pub struct Bricked; - -/// Compile-time proof that advancing from `Self` to `Next` is a valid transition. -/// Only the explicit `impl` blocks below are permitted. -pub trait CanAdvanceTo: sealed::Sealed {} - -impl CanAdvanceTo for Develop {} -impl CanAdvanceTo for Develop {} -impl CanAdvanceTo for Develop2 {} -impl CanAdvanceTo for Develop2 {} -impl CanAdvanceTo for InField {} -impl CanAdvanceTo for InFieldLocked {} -impl CanAdvanceTo for InField {} -impl CanAdvanceTo for InFieldLocked {} -impl CanAdvanceTo for OemFieldReturn {} -impl CanAdvanceTo for Develop2 {} -impl CanAdvanceTo for InFieldLocked {} -impl CanAdvanceTo for InField {} -impl CanAdvanceTo for OemFieldReturn {} -impl CanAdvanceTo for FailureAnalysis {} - -/// Maps a zero-sized lifecycle type to its runtime `NbootLifecycleState` value. -/// Used by `verify_lifecycle_transition` to assert the device is actually in -/// the expected `From` state before committing a transition. -pub trait ActualLifecycleState: sealed::Sealed { - const STATE: NbootLifecycleState; -} - -impl ActualLifecycleState for Develop { - const STATE: NbootLifecycleState = NbootLifecycleState::Develop; -} -impl ActualLifecycleState for Develop2 { - const STATE: NbootLifecycleState = NbootLifecycleState::Develop2; -} -impl ActualLifecycleState for InField { - const STATE: NbootLifecycleState = NbootLifecycleState::InField; -} -impl ActualLifecycleState for InFieldLocked { - const STATE: NbootLifecycleState = NbootLifecycleState::InFieldLocked; -} -impl ActualLifecycleState for OemFieldReturn { - const STATE: NbootLifecycleState = NbootLifecycleState::OemFieldReturn; -} -impl ActualLifecycleState for FailureAnalysis { - const STATE: NbootLifecycleState = NbootLifecycleState::FailureAnalysis; -} -impl ActualLifecycleState for Bricked { - const STATE: NbootLifecycleState = NbootLifecycleState::Bricked; -} - -// Forward declarations of subtables. -#[repr(C)] -pub(super) struct NbootDriverRaw { - // Initialize NBOOT context (must be called before other NBOOT APIs). - pub nboot_context_init: unsafe extern "C" fn(ctx: *mut NbootCtx) -> NbootStatusProtected, - // Deinitialize NBOOT context. - pub nboot_context_deinit: unsafe extern "C" fn(ctx: *mut NbootCtx) -> NbootStatusProtected, - // Set context UUID (bytes; see NXP header for exact semantics). - pub nboot_context_set_uuid: unsafe extern "C" fn(ctx: *mut NbootCtx, uuid: *const u8) -> NbootStatusProtected, - // SB4: load/parse manifest. - pub nboot_sb4_load_manifest: unsafe extern "C" fn( - ctx: *mut NbootCtx, - manifest: *const u32, - parms: *mut NbootSb4LoadManifestParms, - ) -> NbootStatusProtected, - // SB4: load next block. - pub nboot_sb4_load_block: unsafe extern "C" fn(ctx: *mut NbootCtx, block: *mut u32) -> NbootStatusProtected, - // SB4: authenticate & complete check (ROMAPI entry). - pub nboot_sb4_check_authenticity_and_completeness_romapi: unsafe extern "C" fn( - ctx: *mut NbootCtx, - address: *const u32, - parms: *mut NbootSb4LoadManifestParms, - ) -> NbootStatusProtected, - // Authenticate image (signature verification result returned via is_signature_verified). - pub nboot_img_authenticate_romapi: unsafe extern "C" fn( - ctx: *mut NbootCtx, - image_start: *const u8, - is_signature_verified: *mut NbootBool, - parms: *mut NbootImgAuthParms, - ) -> NbootStatusProtected, - - // Enable/Configure in-memory encryption for a given address range. - pub nboot_mem_crypt_enable_encrypt_for_address_range: unsafe extern "C" fn( - ctx: *mut NbootCtx, - region_number: NbootMemCryptRegion, - region_config: *mut NbootMemCryptRegionConfig, - iped_mode_select: NbootMemCryptIpedModeSelect, - ) -> NbootStatusProtected, - // Check whether an operation is allowed for an address range and return flags/IV counters. - pub nboot_mem_crypt_range_checker: unsafe extern "C" fn( - ctx: *mut NbootCtx, - operation: NbootMemCryptOperation, - address: u32, - length: u32, - flags: *mut u8, - npx_iv_erase_cntr: *mut u32, - iped_iv_erase_cntr: *mut u32, - npx_erase_check_en: u32, - ) -> NbootStatusProtected, - // Enable background hashing (ROM-managed hash engine / DMA channel selection). - pub nboot_background_hash_enable: - unsafe extern "C" fn(ctx: *mut NbootCtx, hash_dma_channel: u32) -> NbootStatusProtected, -} - -#[derive(Clone, Copy)] -pub struct NbootDriver { - raw: &'static NbootDriverRaw, -} - -impl NbootDriver { - pub(super) const fn from_raw(raw: &'static NbootDriverRaw) -> Self { - Self { raw } - } - - pub fn nboot_context_init(&self, ctx: *mut NbootCtx) -> NbootStatus { - unsafe { NbootStatus::from((self.raw.nboot_context_init)(ctx)) } - } - - pub fn nboot_context_deinit(&self, ctx: *mut NbootCtx) -> NbootStatus { - unsafe { NbootStatus::from((self.raw.nboot_context_deinit)(ctx)) } - } - - pub fn nboot_context_set_uuid(&self, ctx: *mut NbootCtx, uuid: *const u8) -> NbootStatus { - unsafe { NbootStatus::from((self.raw.nboot_context_set_uuid)(ctx, uuid)) } - } - - pub fn nboot_sb4_load_manifest( - &self, - ctx: *mut NbootCtx, - manifest: *const u32, - parms: *mut NbootSb4LoadManifestParms, - ) -> NbootStatus { - unsafe { NbootStatus::from((self.raw.nboot_sb4_load_manifest)(ctx, manifest, parms)) } - } - - pub fn nboot_sb4_load_block(&self, ctx: *mut NbootCtx, block: *mut u32) -> NbootStatus { - unsafe { NbootStatus::from((self.raw.nboot_sb4_load_block)(ctx, block)) } - } - - pub fn nboot_sb4_check_authenticity_and_completeness_romapi( - &self, - ctx: *mut NbootCtx, - address: *const u32, - parms: *mut NbootSb4LoadManifestParms, - ) -> NbootStatus { - unsafe { - NbootStatus::from((self.raw.nboot_sb4_check_authenticity_and_completeness_romapi)( - ctx, address, parms, - )) - } - } - - pub fn nboot_img_authenticate_romapi( - &self, - ctx: *mut NbootCtx, - image_start: *const u8, - is_signature_verified: *mut NbootBool, - parms: *mut NbootImgAuthParms, - ) -> NbootStatus { - unsafe { - NbootStatus::from((self.raw.nboot_img_authenticate_romapi)( - ctx, - image_start, - is_signature_verified, - parms, - )) - } - } - - pub fn nboot_mem_crypt_enable_encrypt_for_address_range( - &self, - ctx: *mut NbootCtx, - region_number: NbootMemCryptRegion, - region_config: *mut NbootMemCryptRegionConfig, - iped_mode_select: NbootMemCryptIpedModeSelect, - ) -> NbootStatus { - unsafe { - NbootStatus::from((self.raw.nboot_mem_crypt_enable_encrypt_for_address_range)( - ctx, - region_number, - region_config, - iped_mode_select, - )) - } - } - - #[allow(clippy::too_many_arguments)] - pub fn nboot_mem_crypt_range_checker( - &self, - ctx: *mut NbootCtx, - operation: NbootMemCryptOperation, - address: u32, - length: u32, - flags: *mut u8, - npx_iv_erase_cntr: *mut u32, - iped_iv_erase_cntr: *mut u32, - npx_erase_check_en: u32, - ) -> NbootStatus { - unsafe { - NbootStatus::from((self.raw.nboot_mem_crypt_range_checker)( - ctx, - operation, - address, - length, - flags, - npx_iv_erase_cntr, - iped_iv_erase_cntr, - npx_erase_check_en, - )) - } - } - - pub fn nboot_background_hash_enable(&self, ctx: *mut NbootCtx, hash_dma_channel: u32) -> NbootStatus { - // should enum for DMA channel selection be added? (Answer is yes but which channels??) For now just pass 0 for default channel. By doing an enum, - // we can impose limitations on valid values (e.g. if only 2 channels are supported, etc.) - unsafe { NbootStatus::from((self.raw.nboot_background_hash_enable)(ctx, hash_dma_channel)) } - } -} diff --git a/libs/ec-slimloader-mcxa/src/rom_api/spi_flash.rs b/libs/ec-slimloader-mcxa/src/rom_api/spi_flash.rs deleted file mode 100644 index 63aca4c7..00000000 --- a/libs/ec-slimloader-mcxa/src/rom_api/spi_flash.rs +++ /dev/null @@ -1,66 +0,0 @@ -#![allow(clippy::not_unsafe_ptr_arg_deref)] -// Safety: null, misaligned, invalid inputs or out of bounds references will cause ROM API to return an error code, which is handled by the caller. -use core::ffi::c_void; - -use super::Status; -use crate::error::SpiFlashStatus; - -// LPSPI external flash (SPI NOR/EEPROM) ROM API - -#[repr(C)] -#[derive(Clone, Copy, Default)] -pub struct SpiMemConfigOption { - pub option0: u32, - pub option1: u32, -} - -#[repr(C)] -pub(super) struct SpiFlashDriverRaw { - pub spi_eeprom_init: unsafe extern "C" fn() -> Status, - pub spi_eeprom_read: unsafe extern "C" fn(address: u32, NoOfBytes: u32, buffer: *mut u8) -> Status, - pub spi_eeprom_write: unsafe extern "C" fn(address: u32, NoOfBytes: u32, buffer: *const u8) -> Status, - pub spi_eeprom_erase: unsafe extern "C" fn(address: u32, length: u32) -> Status, - pub spi_eeprom_config: unsafe extern "C" fn(config: *mut u32) -> Status, - pub spi_eeprom_flush: unsafe extern "C" fn() -> Status, - pub reserved0: *mut c_void, - pub spi_eeprom_erase_all: unsafe extern "C" fn() -> Status, -} - -#[derive(Clone, Copy)] -pub struct SpiFlashDriver { - raw: &'static SpiFlashDriverRaw, -} - -impl SpiFlashDriver { - pub(super) const fn from_raw(raw: &'static SpiFlashDriverRaw) -> Self { - Self { raw } - } - - pub fn spi_eeprom_init(&self) -> SpiFlashStatus { - unsafe { SpiFlashStatus::from((self.raw.spi_eeprom_init)()) } - } - - pub fn spi_eeprom_read(&self, address: u32, no_of_bytes: u32, buffer: *mut u8) -> SpiFlashStatus { - unsafe { SpiFlashStatus::from((self.raw.spi_eeprom_read)(address, no_of_bytes, buffer)) } - } - - pub fn spi_eeprom_write(&self, address: u32, no_of_bytes: u32, buffer: *const u8) -> SpiFlashStatus { - unsafe { SpiFlashStatus::from((self.raw.spi_eeprom_write)(address, no_of_bytes, buffer)) } - } - - pub fn spi_eeprom_erase(&self, address: u32, length: u32) -> SpiFlashStatus { - unsafe { SpiFlashStatus::from((self.raw.spi_eeprom_erase)(address, length)) } - } - - pub fn spi_eeprom_config(&self, config: *mut u32) -> SpiFlashStatus { - unsafe { SpiFlashStatus::from((self.raw.spi_eeprom_config)(config)) } - } - - pub fn spi_eeprom_flush(&self) -> SpiFlashStatus { - unsafe { SpiFlashStatus::from((self.raw.spi_eeprom_flush)()) } - } - - pub fn spi_eeprom_erase_all(&self) -> SpiFlashStatus { - unsafe { SpiFlashStatus::from((self.raw.spi_eeprom_erase_all)()) } - } -} diff --git a/libs/ec-slimloader-mcxa/src/verification.rs b/libs/ec-slimloader-mcxa/src/verification.rs index 03339591..a1656ac5 100644 --- a/libs/ec-slimloader-mcxa/src/verification.rs +++ b/libs/ec-slimloader-mcxa/src/verification.rs @@ -1,18 +1,19 @@ #![allow(clippy::not_unsafe_ptr_arg_deref)] +use ec_slimloader::BootError; +use embassy_mcxa::rom::{ + NbootBoolValue, NbootImgAuthParms, NbootRootKeyRevocation, NbootRootKeyType, NbootRootKeyUsage, NbootRotAuthParms, +}; use embassy_mcxa::{peripherals, Peri}; use crate::certificate::derive_image_rkth_pair; +use crate::error::map_nboot_status_to_boot_error; use crate::lifecycle::{ cnsa_enforced, dev_config_deviation, fast_boot_enabled, load_firmware_version_from_cfpa, load_image_key_revocation_from_cfpa, load_lifecycle_from_cfpa, load_pqc_rotkh_from_cmpa, load_root_key_revocation_from_cfpa, load_rotk_usage_from_cmpa, load_rotkh_from_cmpa, low_power_authentication_enforced, secure_boot_state, SecureBootState, }; -use crate::rom_api::{ - nboot, NbootBool, NbootBoolValue, NbootCtx, NbootImgAuthParms, NbootLifecycleState, NbootRootKeyRevocation, - NbootRootKeyType, NbootRootKeyUsage, NbootRotAuthParms, -}; macro_rules! verify_info { ($($arg:tt)*) => { @@ -86,19 +87,19 @@ impl DevMode { const DEV: u32 = 0x3CA5_5AC3; const PROD: u32 = 0xC35A_A53C; // bitwise complement of DEV - fn compute() -> Result { + fn compute() -> Result { // the two calls ultimately end in volatile IFR reads, so both // evaluations are performed and their results cannot be assumed equal. let first = dev_config_deviation(); // This function measures the deviation of DEV mode config. from the expected configuration. - //If the deviation is non-zero, then we are in production mode. If the deviation is zero, then we are in dev mode. This is a constant-time check that does not materialize any bools, and does not use any branches. + // If the deviation is non-zero, then we are in production mode. If the deviation is zero, then we are in dev mode. This is a constant-time check that does not materialize any bools, and does not use any branches. let second = dev_config_deviation(); - if asm_opaque(first) != asm_opaque(second) { - return Err(ec_slimloader::BootError::Integrity); + if first != second { + return Err(BootError::Integrity); } let mut token = Self(0); // OR of both deviation words: is_dev is all-ones only if both full // derivations landed on exactly zero. No bool is ever materialized. - let is_dev = zero_mask(asm_opaque(first) | asm_opaque(second)); + let is_dev = zero_mask(first | second); unsafe { core::ptr::write_volatile(&mut token.0, (Self::DEV & is_dev) | (Self::PROD & !is_dev)); } @@ -116,83 +117,70 @@ impl DevMode { } const DEFAULT_NBOOT_PARMS: NbootImgAuthParms = NbootImgAuthParms { - soc_RoTNVM: NbootRotAuthParms { - soc_rootKeyRevocation: [ - NbootRootKeyRevocation::Revoked as u32, - NbootRootKeyRevocation::Revoked as u32, - NbootRootKeyRevocation::Revoked as u32, - NbootRootKeyRevocation::Revoked as u32, - //Start as revoked by default for safety; will be updated with real values from CFPA if read is successful. - // This way if CFPA read fails for some reason, we won't accidentally treat revoked keys as valid. - ], - soc_imageKeyRevocation: 0xFFFF_FFFF, //Image key revocation use case: None? Still set highest revocation value by default for safety; will be updated with real value from CFPA if read is successful. + soc_rot_nvm: NbootRotAuthParms { + // Start as revoked by default for safety; will be updated with real values from CFPA if read is successful. + // This way if CFPA read fails for some reason, we won't accidentally treat revoked keys as valid. + soc_root_key_revocation: [NbootRootKeyRevocation::Revoked; 4], + soc_image_key_revocation: 0xFFFF_FFFF, //Image key revocation use case: None? Still set highest revocation value by default for safety; will be updated with real value from CFPA if read is successful. soc_rkh: [0; 12], - soc_rkh_1: [0; 12], // PQC hash for hybrid keys - soc_numberOfRootKeys: 4, // TODO: Must equal 4 per NXP example code. - soc_rootKeyUsage: [ - NbootRootKeyUsage::Unused as u32, - NbootRootKeyUsage::Unused as u32, - NbootRootKeyUsage::Unused as u32, - NbootRootKeyUsage::Unused as u32, - // Start as unused by default for safety; will be updated with real values from CMPA if read is successful. - ], - soc_rootKeyTypeAndLength: NbootRootKeyType::EcdsaP384Mldsa87 as u32, //FIXED TO THIS because we are CNSA 2.0 compliant. - soc_lifecycle: NbootLifecycleState::InField.nboot_soc_lifecycle(), // default to INFIELD (strict start), gets updated with real one further below. + soc_rkh_1: [0; 12], // PQC hash for hybrid keys + soc_number_of_root_keys: 4, // TODO: Must equal 4 per NXP example code. + // Start as unused by default for safety; will be updated with real values from CMPA if read is successful. + soc_root_key_usage: [NbootRootKeyUsage::Unused; 4], + soc_root_key_type_and_length: NbootRootKeyType::EcdsaP384Mldsa87, //FIXED TO THIS because we are CNSA 2.0 compliant. + soc_lifecycle: 0, }, - soc_trustedFirmwareVersion: 0xFFFF_FFFF, // default to max version to be safe (any real version should be lower), gets updated with real one from CFPA further below + soc_trusted_firmware_version: 0xFFFF_FFFF, // default to max version to be safe (any real version should be lower), gets updated with real one from CFPA further below }; -fn load_nboot_auth_parms_from_ifr() -> Result { +fn load_nboot_auth_parms_from_ifr() -> Result { let mut parms = DEFAULT_NBOOT_PARMS; if let Some(cmpa_rotkh) = load_rotkh_from_cmpa() { - parms.soc_RoTNVM.soc_rkh = cmpa_rotkh; + parms.soc_rot_nvm.soc_rkh = cmpa_rotkh; verify_trace!("RKTH loaded from CMPA"); } else { verify_warn!("CMPA ROTKH read failed"); - return Err(ec_slimloader::BootError::RootOfTrust); + return Err(BootError::RootOfTrust); } // Load PQC ROTKH for hybrid keys if let Some(cmpa_pqc_rotkh) = load_pqc_rotkh_from_cmpa() { - parms.soc_RoTNVM.soc_rkh_1 = cmpa_pqc_rotkh; + parms.soc_rot_nvm.soc_rkh_1 = cmpa_pqc_rotkh; verify_trace!("PQC RKTH loaded from CMPA"); } else { verify_warn!("CMPA PQC ROTKH read failed"); - return Err(ec_slimloader::BootError::RootOfTrust); + return Err(BootError::RootOfTrust); } //Load additional lifecycle state from CFPA/CMPA if let Some(cfpa_img_key_revocation) = load_image_key_revocation_from_cfpa() { - parms.soc_RoTNVM.soc_imageKeyRevocation = cfpa_img_key_revocation; + parms.soc_rot_nvm.soc_image_key_revocation = cfpa_img_key_revocation; } if let Some(cfpa_root_key_revocation) = load_root_key_revocation_from_cfpa() { - parms.soc_RoTNVM.soc_rootKeyRevocation = cfpa_root_key_revocation.map(|r| r as u32); + parms.soc_rot_nvm.soc_root_key_revocation = cfpa_root_key_revocation; } if let Some(cfpa_fw_version) = load_firmware_version_from_cfpa() { - parms.soc_trustedFirmwareVersion = cfpa_fw_version; + parms.soc_trusted_firmware_version = cfpa_fw_version; } if let Some(cmpa_root_key_usage) = load_rotk_usage_from_cmpa() { - parms.soc_RoTNVM.soc_rootKeyUsage = cmpa_root_key_usage.map(|u| u as u32); + parms.soc_rot_nvm.soc_root_key_usage = cmpa_root_key_usage; } if let Some(cfpa_lifecycle) = load_lifecycle_from_cfpa() { - parms.soc_RoTNVM.soc_lifecycle = cfpa_lifecycle.nboot_soc_lifecycle(); + parms.soc_rot_nvm.soc_lifecycle = cfpa_lifecycle.nboot_soc_lifecycle(); } Ok(parms) } -fn verify_secure_boot_policies( - dev_mode: &DevMode, - secure_boot_state: SecureBootState, -) -> Result<(), ec_slimloader::BootError> { +fn verify_secure_boot_policies(dev_mode: &DevMode, secure_boot_state: SecureBootState) -> Result<(), BootError> { if matches!(secure_boot_state, SecureBootState::Unknown) { verify_error!("Secure boot state could not be validated"); - return Err(ec_slimloader::BootError::Integrity); + return Err(BootError::Integrity); } // If we are NOT in development mode, make sure secure boot policies are compliant. let policy_violation = !matches!(secure_boot_state, SecureBootState::HybridEnforced) @@ -207,7 +195,7 @@ fn verify_secure_boot_policies( fast_boot_enabled(), low_power_authentication_enforced() ); - return Err(ec_slimloader::BootError::Integrity); + return Err(BootError::Integrity); } Ok(()) } @@ -220,7 +208,7 @@ fn verify_secure_boot_policies( pub fn verify_authenticity<'d>( mut peri: Peri<'d, peripherals::SGI0>, image_base: *const u8, -) -> Result { +) -> Result { let mut parms = load_nboot_auth_parms_from_ifr()?; let secure_boot_state = secure_boot_state(); @@ -229,19 +217,12 @@ pub fn verify_authenticity<'d>( verify_secure_boot_policies(&dev_mode, secure_boot_state)?; - let n_boot_api = nboot(); - let mut ctx: NbootCtx = unsafe { core::mem::zeroed() }; - let mut sig_ok: NbootBool = NbootBoolValue::False as u32; - verify_trace!("Initializing NBOOT context"); - let context_init_status = n_boot_api.nboot_context_init(&mut ctx); - if context_init_status != crate::error::NbootStatus::Success { - return Err(ec_slimloader::BootError::Authenticate); - } + let mut n_boot_api = embassy_mcxa::rom::get().nboot().map_err(|_| BootError::Authenticate)?; const MAX_FLASH_SLOT_SIZE: u32 = 2 * 1024 * 1024; // 2MB, TODO: make this configurable or derive from flash size let image_header = unsafe { crate::header::ImageHeader::from_ptr(image_base, MAX_FLASH_SLOT_SIZE) } - .map_err(|_| ec_slimloader::BootError::Integrity)?; + .map_err(|_| BootError::Integrity)?; // Parse AHAB container once and derive both RKTH values let (image_rkth, pqc_rkth) = derive_image_rkth_pair( peri.reborrow(), @@ -255,23 +236,21 @@ pub fn verify_authenticity<'d>( let image_rkth_words = image_rkth.as_le_words(); verify_info!("Derived image RKTH: {:?}", image_rkth_words); - if image_rkth_words != parms.soc_RoTNVM.soc_rkh { + if image_rkth_words != parms.soc_rot_nvm.soc_rkh { // non-const time is okay, these are public key hashes. if dev_mode.dev_token() == DevMode::DEV { verify_warn!("Dev mode: copying from image RKTH"); - parms.soc_RoTNVM.soc_rkh.copy_from_slice(&image_rkth_words); + parms.soc_rot_nvm.soc_rkh.copy_from_slice(&image_rkth_words); } else { verify_warn!("Production: image RKTH differs; not copying, will not call verify "); - n_boot_api.nboot_context_deinit(&mut ctx); - return Err(ec_slimloader::BootError::RootOfTrust); + return Err(BootError::RootOfTrust); } } else { verify_trace!("RKTH match"); } } else { verify_warn!("Failed to derive image RKTH"); - n_boot_api.nboot_context_deinit(&mut ctx); - return Err(ec_slimloader::BootError::RootOfTrust); + return Err(BootError::RootOfTrust); } // Process PQC RKTH (ML-DSA) for hybrid keys @@ -279,62 +258,42 @@ pub fn verify_authenticity<'d>( let pqc_rkth_words = pqc_rkth.as_le_words(); verify_info!("Derived image PQC RKTH: {:?}", pqc_rkth_words); - if pqc_rkth_words != parms.soc_RoTNVM.soc_rkh_1 { + if pqc_rkth_words != parms.soc_rot_nvm.soc_rkh_1 { //non-const time comparison is okay, these are public key hashes if dev_mode.dev_token() == DevMode::DEV { verify_warn!("Dev mode: copying from image PQC RKTH"); - parms.soc_RoTNVM.soc_rkh_1.copy_from_slice(&pqc_rkth_words); + parms.soc_rot_nvm.soc_rkh_1.copy_from_slice(&pqc_rkth_words); } else { verify_warn!("Production: image PQC RKTH differs; not copying, will not call verify"); - //TODO: just return Err() here? - n_boot_api.nboot_context_deinit(&mut ctx); - return Err(ec_slimloader::BootError::RootOfTrust); + return Err(BootError::RootOfTrust); } } else { verify_trace!("PQC RKTH match"); } } else { verify_warn!("Failed to derive image PQC RKTH (ML-DSA not found or error)"); - n_boot_api.nboot_context_deinit(&mut ctx); - return Err(ec_slimloader::BootError::RootOfTrust); + return Err(BootError::RootOfTrust); } // Last check to make sure that at this point, if PRODUCTION, i.e. NOT dev mode, we are handing over the correct IFR hashes to ROM. if dev_mode.dev_token() != DevMode::DEV { - let rkh_ok = load_rotkh_from_cmpa().is_some_and(|h| parms.soc_RoTNVM.soc_rkh == h); - let pqc_ok = load_pqc_rotkh_from_cmpa().is_some_and(|h| parms.soc_RoTNVM.soc_rkh_1 == h); + let rkh_ok = load_rotkh_from_cmpa().is_some_and(|h| parms.soc_rot_nvm.soc_rkh == h); + let pqc_ok = load_pqc_rotkh_from_cmpa().is_some_and(|h| parms.soc_rot_nvm.soc_rkh_1 == h); if !(rkh_ok && pqc_ok) { - n_boot_api.nboot_context_deinit(&mut ctx); - return Err(ec_slimloader::BootError::Integrity); + return Err(BootError::Integrity); } } verify_trace!("begin auth"); - let status = n_boot_api.nboot_img_authenticate_romapi(&mut ctx, image_base, &mut sig_ok, &mut parms); + let status = n_boot_api + .nboot_img_authenticate_romapi(image_base as u32, &mut parms) + .map_err(map_nboot_status_to_boot_error)?; - for w in parms.soc_RoTNVM.soc_rkh.iter_mut() { - *w = 0; - } - for w in parms.soc_RoTNVM.soc_rkh_1.iter_mut() { - *w = 0; - } - for w in parms.soc_RoTNVM.soc_rootKeyRevocation.iter_mut() { - *w = 0; - } - - n_boot_api.nboot_context_deinit(&mut ctx); - //TODO: does de-init zeroize the context or do we need to do that manually for security? - - match (status, sig_ok) { - (crate::error::NbootStatus::Success, s) if s == NbootBoolValue::True as u32 => { + match status { + NbootBoolValue::True => { verify_info!("Hybrid Auth OK"); - Ok(asm_opaque(s)) - } - (status, _) => { - let boot_error = crate::error::map_nboot_status_to_boot_error(status); - - verify_error!("Auth failed with status {:?}: {:?}", status, boot_error); - Err(boot_error) + Ok(true) } + _ => Ok(false), } } diff --git a/mcxa-security-provisioning/Cargo.lock b/libs/mcxa-security-provisioning/Cargo.lock similarity index 71% rename from mcxa-security-provisioning/Cargo.lock rename to libs/mcxa-security-provisioning/Cargo.lock index 40378aca..50bcd54b 100644 --- a/mcxa-security-provisioning/Cargo.lock +++ b/libs/mcxa-security-provisioning/Cargo.lock @@ -2,18 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.5" @@ -29,49 +17,6 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" -[[package]] -name = "arraydeque" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" - -[[package]] -name = "askama" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4" -dependencies = [ - "askama_derive", - "itoa", - "percent-encoding", - "serde", - "serde_json", -] - -[[package]] -name = "askama_derive" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f" -dependencies = [ - "askama_parser", - "memchr", - "proc-macro2", - "quote", - "rustc-hash", - "syn 2.0.119", -] - -[[package]] -name = "askama_parser" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358" -dependencies = [ - "memchr", - "winnow", -] - [[package]] name = "autocfg" version = "1.5.1" @@ -110,18 +55,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitvec" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddcec3d12c579d40898fe0a9a358a803c23e9c52ca3c425707f81c9436211837" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "byteorder" version = "1.5.0" @@ -130,9 +63,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.4.4" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad534f4357a5264cce5019c989cf66a4f0dc4e0d1b1d15f8aacec0ff7360273" +checksum = "005ec2760ca554fae18df7a11195552ec576cd665632a881bc011d5bb2fd4d80" dependencies = [ "find-msvc-tools", "shlex", @@ -156,15 +89,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bd422bfb4f24a97243f60b6a4443e63d810c925d8da4bb2d8fde26a7c1d57ec" -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "convert_case" version = "0.11.0" @@ -230,21 +154,6 @@ dependencies = [ "syn 2.0.119", ] -[[package]] -name = "crc" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d" -dependencies = [ - "crc-catalog", -] - -[[package]] -name = "crc-catalog" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "217698eaf96b4a3f0bc4f3662aaa55bdf913cd54d7204591faa790070c6d0853" - [[package]] name = "critical-section" version = "1.2.0" @@ -286,17 +195,6 @@ dependencies = [ "syn 2.0.119", ] -[[package]] -name = "dd-manifest-tree" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5793572036e0a6638977c7370c6afc423eac848ee8495f079b8fd3964de7b9f9" -dependencies = [ - "serde_json", - "toml", - "yaml-rust2", -] - [[package]] name = "defmt" version = "0.3.100" @@ -334,9 +232,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be59789d306cc1a082f53bb7c24c270d7e6078c00b7550a718219a7090156d97" dependencies = [ - "defmt 1.1.1", "defmt-or-log-macros", - "log", ] [[package]] @@ -359,46 +255,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "device-driver" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e4547bd66511372d2a38ac3c1b2892c7ebf83cf0d5411c3406e496c85a1d96" -dependencies = [ - "device-driver-macros", - "embedded-io 0.6.1", - "embedded-io-async 0.6.1", -] - -[[package]] -name = "device-driver-generation" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f0170a2ef7fb5a74029c3edcaff07a0d44dbfac3d9dcfbb06fc696f890bb877" -dependencies = [ - "anyhow", - "askama", - "bitvec", - "convert_case 0.6.0", - "dd-manifest-tree", - "itertools", - "prettyplease", - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "device-driver-macros" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176dbf719ece32afb641bf50d2d1881411ad1677aec6c8bf42011a7c279d97ff" -dependencies = [ - "device-driver-generation", - "proc-macro2", - "syn 2.0.119", -] - [[package]] name = "document-features" version = "0.2.12" @@ -408,63 +264,14 @@ dependencies = [ "litrs", ] -[[package]] -name = "ec-slimloader" -version = "0.2.0" -dependencies = [ - "defmt 0.3.100", - "defmt-or-log", - "ec-slimloader-state", - "embedded-storage-async", - "log", -] - -[[package]] -name = "ec-slimloader-mcxa" -version = "0.2.0" -dependencies = [ - "cortex-m", - "defmt 0.3.100", - "defmt-or-log", - "device-driver", - "ec-slimloader", - "ec-slimloader-state", - "embassy-mcxa", - "embassy-sync", - "embassy-time", - "embedded-storage-async", - "heapless 0.8.0", - "log", - "partition-manager", - "partition-manager-macros", - "static_cell", -] - -[[package]] -name = "ec-slimloader-state" -version = "0.2.0" -dependencies = [ - "crc", - "defmt 0.3.100", - "defmt-or-log", - "embedded-storage-async", - "num_enum", -] - -[[package]] -name = "either" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34" - [[package]] name = "embassy-embedded-hal" version = "0.6.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41#a568760201d152e70a2c8e82dfa9783935e7da41" dependencies = [ - "embassy-futures", + "embassy-futures 0.1.2 (git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41)", "embassy-hal-internal", - "embassy-sync", + "embassy-sync 0.8.0 (git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41)", "embedded-hal 0.2.7", "embedded-hal 1.0.0", "embedded-hal-async", @@ -476,19 +283,20 @@ dependencies = [ [[package]] name = "embassy-executor" version = "0.10.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41#a568760201d152e70a2c8e82dfa9783935e7da41" dependencies = [ "cordyceps", "critical-section", "document-features", "embassy-executor-macros", "embassy-executor-timer-queue", + "unitrait", ] [[package]] name = "embassy-executor-macros" version = "0.8.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41#a568760201d152e70a2c8e82dfa9783935e7da41" dependencies = [ "darling", "proc-macro2", @@ -498,18 +306,27 @@ dependencies = [ [[package]] name = "embassy-executor-timer-queue" -version = "0.1.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +version = "0.1.1" +source = "git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41#a568760201d152e70a2c8e82dfa9783935e7da41" +dependencies = [ + "unitrait", +] [[package]] name = "embassy-futures" version = "0.1.2" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc2d050bdc5c21e0862a89256ed8029ae6c290a93aecefc73084b3002cdebb01" + +[[package]] +name = "embassy-futures" +version = "0.1.2" +source = "git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41#a568760201d152e70a2c8e82dfa9783935e7da41" [[package]] name = "embassy-hal-internal" version = "0.5.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41#a568760201d152e70a2c8e82dfa9783935e7da41" dependencies = [ "cortex-m", "critical-section", @@ -519,18 +336,18 @@ dependencies = [ [[package]] name = "embassy-mcxa" version = "0.1.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41#a568760201d152e70a2c8e82dfa9783935e7da41" dependencies = [ "bbqueue", - "convert_case 0.11.0", + "convert_case", "cortex-m", "cortex-m-rt", "critical-section", "embassy-embedded-hal", "embassy-executor", - "embassy-futures", + "embassy-futures 0.1.2 (git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41)", "embassy-hal-internal", - "embassy-sync", + "embassy-sync 0.8.0 (git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41)", "embassy-time", "embassy-time-driver", "embassy-time-queue-utils", @@ -539,11 +356,11 @@ dependencies = [ "embedded-hal 1.0.0", "embedded-hal-async", "embedded-hal-nb", - "embedded-io 0.7.1", - "embedded-io-async 0.7.0", + "embedded-io", + "embedded-io-async", "embedded-storage", "grounded", - "heapless 0.9.3", + "heapless", "indexmap", "maitake-sync", "nb 1.1.0", @@ -561,20 +378,34 @@ dependencies = [ [[package]] name = "embassy-sync" version = "0.8.0" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bbd85cf5a5ae56bdf26f618364af642d1d0a4e245cdd75cd9aabda382f65a81" dependencies = [ "cfg-if", "critical-section", - "embedded-io-async 0.7.0", + "embedded-io-async", "futures-core", "futures-sink", - "heapless 0.9.3", + "heapless", +] + +[[package]] +name = "embassy-sync" +version = "0.8.0" +source = "git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41#a568760201d152e70a2c8e82dfa9783935e7da41" +dependencies = [ + "cfg-if", + "critical-section", + "embedded-io-async", + "futures-core", + "futures-sink", + "heapless", ] [[package]] name = "embassy-time" version = "0.5.1" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41#a568760201d152e70a2c8e82dfa9783935e7da41" dependencies = [ "cfg-if", "critical-section", @@ -589,7 +420,7 @@ dependencies = [ [[package]] name = "embassy-time-driver" version = "0.2.2" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41#a568760201d152e70a2c8e82dfa9783935e7da41" dependencies = [ "document-features", ] @@ -597,10 +428,10 @@ dependencies = [ [[package]] name = "embassy-time-queue-utils" version = "0.3.2" -source = "git+https://github.com/embassy-rs/embassy?rev=f21d63db2d104a3b4c070408e529c109a64e65b0#f21d63db2d104a3b4c070408e529c109a64e65b0" +source = "git+https://github.com/embassy-rs/embassy?rev=a568760201d152e70a2c8e82dfa9783935e7da41#a568760201d152e70a2c8e82dfa9783935e7da41" dependencies = [ "embassy-executor-timer-queue", - "heapless 0.9.3", + "heapless", ] [[package]] @@ -647,34 +478,19 @@ dependencies = [ "nb 1.1.0", ] -[[package]] -name = "embedded-io" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" - [[package]] name = "embedded-io" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9eb1aa714776b75c7e67e1da744b81a129b3ff919c8712b5e1b32252c1f07cc7" -[[package]] -name = "embedded-io-async" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff09972d4073aa8c299395be75161d582e7629cd663171d62af73c8d50dba3f" -dependencies = [ - "embedded-io 0.6.1", -] - [[package]] name = "embedded-io-async" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2564b9f813c544241430e147d8bc454815ef9ac998878d30cc3055449f7fd4c0" dependencies = [ - "embedded-io 0.7.1", + "embedded-io", ] [[package]] @@ -692,15 +508,6 @@ dependencies = [ "embedded-storage", ] -[[package]] -name = "encoding_rs" -version = "0.8.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" -dependencies = [ - "cfg-if", -] - [[package]] name = "equivalent" version = "1.0.2" @@ -709,9 +516,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "find-msvc-tools" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890" +checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d" [[package]] name = "fnv" @@ -719,12 +526,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "futures-core" version = "0.3.34" @@ -770,40 +571,12 @@ dependencies = [ "byteorder", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", -] - [[package]] name = "hashbrown" version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" -[[package]] -name = "hashlink" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" -dependencies = [ - "hashbrown 0.14.5", -] - -[[package]] -name = "heapless" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" -dependencies = [ - "hash32", - "stable_deref_trait", -] - [[package]] name = "heapless" version = "0.9.3" @@ -822,29 +595,14 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "2.14.0" +version = "2.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" dependencies = [ "equivalent", - "hashbrown 0.17.1", + "hashbrown", ] -[[package]] -name = "itertools" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" - [[package]] name = "lazy_static" version = "1.5.0" @@ -914,11 +672,9 @@ dependencies = [ "cortex-m", "defmt 0.3.100", "defmt-or-log", - "ec-slimloader-mcxa", - "embassy-futures", + "embassy-futures 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "embassy-mcxa", - "embassy-sync", - "embassy-time", + "embassy-sync 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-storage-async", "log", "partition-manager", @@ -977,27 +733,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_enum" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0bca838442ec211fa11de3a8b0e0e8f3a4522575b5c4c06ed722e005036f26" -dependencies = [ - "num_enum_derive", - "rustversion", -] - -[[package]] -name = "num_enum_derive" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "680998035259dcfcafe653688bf2aa6d3e2dc05e98be6ab46afb089dc84f1df8" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - [[package]] name = "nxp-pac" version = "0.1.0" @@ -1019,8 +754,7 @@ name = "partition-manager" version = "0.1.0" source = "git+https://github.com/OpenDevicePartnership/embedded-services?tag=v0.1.0#6034c6bf3d2d7bfe50821370be7c1275fbf8520a" dependencies = [ - "embassy-sync", - "embedded-storage-async", + "embassy-sync 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1052,12 +786,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" -[[package]] -name = "percent-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" - [[package]] name = "pin-project" version = "1.1.13" @@ -1093,16 +821,6 @@ dependencies = [ "critical-section", ] -[[package]] -name = "prettyplease" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" -dependencies = [ - "proc-macro2", - "syn 2.0.119", -] - [[package]] name = "proc-macro2" version = "1.0.107" @@ -1121,12 +839,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand_core" version = "0.6.4" @@ -1174,15 +886,14 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" -[[package]] -name = "rustc-hash" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" - [[package]] name = "rustc_version" version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] [[package]] name = "rustversion" @@ -1196,6 +907,21 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + [[package]] name = "serde" version = "1.0.229" @@ -1223,21 +949,7 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn 3.0.4", -] - -[[package]] -name = "serde_json" -version = "1.0.151" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" -dependencies = [ - "indexmap", - "itoa", - "memchr", - "serde", - "serde_core", - "zmij", + "syn 3.0.5", ] [[package]] @@ -1266,9 +978,9 @@ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" [[package]] name = "smallvec" -version = "1.15.2" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" +checksum = "b9be42f50aa861c555654aa3a37f52f4b1074bacf4e48fe0ef7fa584e80f1f0f" [[package]] name = "stable_deref_trait" @@ -1304,21 +1016,15 @@ dependencies = [ [[package]] name = "syn" -version = "3.0.4" +version = "3.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6275cddf4610d1775e6d1fe9469b2e77d0f39fd98fb7450901b821e0c53649f" +checksum = "12df2e0110f65b775f769bb17ef989067a1d931b2eb822bd4346631eeada89f9" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "thiserror" version = "2.0.20" @@ -1336,7 +1042,7 @@ checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" dependencies = [ "proc-macro2", "quote", - "syn 3.0.4", + "syn 3.0.5", ] [[package]] @@ -1380,16 +1086,9 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_write", "winnow", ] -[[package]] -name = "toml_write" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" - [[package]] name = "tracing" version = "0.1.44" @@ -1463,6 +1162,24 @@ version = "1.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" +[[package]] +name = "unitrait" +version = "2.0.0" +source = "git+https://github.com/embassy-rs/unitrait?rev=b98d69bbf6fa7872c0cc107e5b52f0bc1df03777#b98d69bbf6fa7872c0cc107e5b52f0bc1df03777" +dependencies = [ + "unitrait-macros", +] + +[[package]] +name = "unitrait-macros" +version = "2.0.0" +source = "git+https://github.com/embassy-rs/unitrait?rev=b98d69bbf6fa7872c0cc107e5b52f0bc1df03777#b98d69bbf6fa7872c0cc107e5b52f0bc1df03777" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "valuable" version = "0.1.1" @@ -1475,12 +1192,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "void" version = "1.0.2" @@ -1528,49 +1239,3 @@ checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" dependencies = [ "memchr", ] - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "yaml-rust2" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1a1c0bc9823338a3bdf8c61f994f23ac004c6fa32c08cd152984499b445e8d" -dependencies = [ - "arraydeque", - "encoding_rs", - "hashlink", -] - -[[package]] -name = "zerocopy" -version = "0.8.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556764e583adb45a9f8d413c2a147fa7e8d821e48e12b14fd560b607998b75eb" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.8.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ab42fc20575779bd240faa45f94a74256f755c0fa9e89f0ede20d91d0cdfc1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "zmij" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/libs/mcxa-security-provisioning/Cargo.toml b/libs/mcxa-security-provisioning/Cargo.toml new file mode 100644 index 00000000..b354dc4b --- /dev/null +++ b/libs/mcxa-security-provisioning/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "mcxa-security-provisioning" +version = "0.2.0" +edition = "2021" +license = "MIT OR Apache-2.0" +repository = "https://github.com/OpenDevicePartnership/ec-slimloader" + +[dependencies] +cortex-m = { version = "0.7.7" } +defmt = { version = "0.3", optional = true } +defmt-or-log = { version = "0.2.3" } +log = { version = "0.4", optional = true } +embedded-storage-async = "0.4.1" +embassy-futures = "0.1.2" +embassy-mcxa = { workspace = true, features = ["mcxa5xx"] } +embassy-sync = "0.8.0" +partition-manager = { git = "https://github.com/OpenDevicePartnership/embedded-services", tag = "v0.1.0", default-features = false } +partition-manager-macros = { git = "https://github.com/OpenDevicePartnership/embedded-services", tag = "v0.1.0" } +static_cell = "2.1" + +# Re-uses the MCXA lifecycle/IFR types defined in ec-slimloader-mcxa +ec-slimloader-mcxa = { path = "../ec-slimloader-mcxa", default-features = false, features = ["mcxa5xx"] } + +[features] +defmt = ["dep:defmt", "defmt-or-log/defmt", "ec-slimloader-mcxa/defmt", "embassy-mcxa/defmt"] +log = ["dep:log", "defmt-or-log/log", "ec-slimloader-mcxa/log"] +mcxa5xx = ["embassy-mcxa/mcxa5xx", "ec-slimloader-mcxa/mcxa5xx"] +mcxa5xxevk = ["ec-slimloader-mcxa/mcxa5xxevk"] diff --git a/libs/mcxa-security-provisioning/src/lib.rs b/libs/mcxa-security-provisioning/src/lib.rs new file mode 100644 index 00000000..6c664c45 --- /dev/null +++ b/libs/mcxa-security-provisioning/src/lib.rs @@ -0,0 +1,70 @@ +#![no_std] + +pub mod lifecycle_provisioning; + +use ec_slimloader_mcxa::lifecycle::NbootLifecycleState; +pub use lifecycle_provisioning::*; + +mod sealed { + pub trait Sealed {} + impl Sealed for super::Develop {} + impl Sealed for super::Develop2 {} + impl Sealed for super::InField {} + impl Sealed for super::InFieldLocked {} + impl Sealed for super::OemFieldReturn {} + impl Sealed for super::FailureAnalysis {} + impl Sealed for super::Bricked {} +} + +pub struct Develop; +pub struct Develop2; +pub struct InField; +pub struct InFieldLocked; +pub struct OemFieldReturn; +pub struct FailureAnalysis; +pub struct Bricked; + +/// Compile-time proof that advancing from `Self` to `Next` is a valid transition. +/// Only the explicit `impl` blocks below are permitted. +pub trait CanAdvanceTo: sealed::Sealed {} + +impl CanAdvanceTo for Develop {} +impl CanAdvanceTo for Develop {} +impl CanAdvanceTo for Develop2 {} +impl CanAdvanceTo for Develop2 {} +impl CanAdvanceTo for InField {} +impl CanAdvanceTo for InFieldLocked {} +impl CanAdvanceTo for InField {} +impl CanAdvanceTo for InFieldLocked {} +impl CanAdvanceTo for OemFieldReturn {} +impl CanAdvanceTo for Develop2 {} +impl CanAdvanceTo for InFieldLocked {} +impl CanAdvanceTo for InField {} +impl CanAdvanceTo for OemFieldReturn {} +impl CanAdvanceTo for FailureAnalysis {} + +pub trait LifecycleState: sealed::Sealed { + const RUNTIME_VALUE: NbootLifecycleState; +} + +impl LifecycleState for Develop { + const RUNTIME_VALUE: NbootLifecycleState = NbootLifecycleState::Develop; +} +impl LifecycleState for Develop2 { + const RUNTIME_VALUE: NbootLifecycleState = NbootLifecycleState::Develop2; +} +impl LifecycleState for InField { + const RUNTIME_VALUE: NbootLifecycleState = NbootLifecycleState::InField; +} +impl LifecycleState for InFieldLocked { + const RUNTIME_VALUE: NbootLifecycleState = NbootLifecycleState::InFieldLocked; +} +impl LifecycleState for OemFieldReturn { + const RUNTIME_VALUE: NbootLifecycleState = NbootLifecycleState::OemFieldReturn; +} +impl LifecycleState for FailureAnalysis { + const RUNTIME_VALUE: NbootLifecycleState = NbootLifecycleState::FailureAnalysis; +} +impl LifecycleState for Bricked { + const RUNTIME_VALUE: NbootLifecycleState = NbootLifecycleState::Bricked; +} diff --git a/mcxa-security-provisioning/src/lifecycle_provisioning.rs b/libs/mcxa-security-provisioning/src/lifecycle_provisioning.rs similarity index 85% rename from mcxa-security-provisioning/src/lifecycle_provisioning.rs rename to libs/mcxa-security-provisioning/src/lifecycle_provisioning.rs index 4d1c5283..36214031 100644 --- a/mcxa-security-provisioning/src/lifecycle_provisioning.rs +++ b/libs/mcxa-security-provisioning/src/lifecycle_provisioning.rs @@ -3,21 +3,19 @@ use core::{mem, ptr}; use defmt_or_log::error; use ec_slimloader_mcxa::certificate::derive_image_rkth_pair; -pub use ec_slimloader_mcxa::error::FlashStatus; use ec_slimloader_mcxa::header::ImageHeader; +use ec_slimloader_mcxa::lifecycle::NbootLifecycleState; pub use ec_slimloader_mcxa::lifecycle::{ cmpa_header_marker_is_valid, cnsa_enforced, fast_boot_enabled, hybrid_secure_boot_enforced, is_cfpa_erased, is_cmpa_erased, load_cfpa_header_word, load_lifecycle_from_cfpa, load_pqc_rotkh_from_cmpa, load_rotkh_from_cmpa, low_power_authentication_enforced, CmpaUpdateConfigData, CnsaLevel, IFRConfigAreaBase, IFRPage, LpWakePolicy, SecureBootLevel, XipImageProtect, }; -pub use ec_slimloader_mcxa::rom_api::{ - flash_cfg_for_rom_api, flash_driver, ActualLifecycleState, Bricked, CanAdvanceTo, Develop, Develop2, - FailureAnalysis, FlashConfig, InField, InFieldLocked, NbootLifecycleState, NbootRootKeyUsage, OemFieldReturn, - FLASH_API_ERASE_KEY, -}; +use embassy_mcxa::rom::{FlashError, NbootRootKeyUsage}; use embassy_mcxa::{peripherals, Peri}; +use crate::{CanAdvanceTo, LifecycleState}; + /// Token produced by `verify_lifecycle_transition()'. Carries the verified target /// `NbootLifecycleState` at runtime. The type parameter `Next` is compile-time /// proof that the transition was constructed via a valid `CanAdvanceTo` impl. @@ -504,14 +502,20 @@ pub enum CmpaWriteError { HashError, InvalidInput, InvalidImageSlot, - FlashError(FlashStatus), + FlashError(FlashError), FlashVerify { - status: FlashStatus, + status: FlashError, failed_address: u32, failed_data: u32, }, } +impl From for CmpaWriteError { + fn from(v: FlashError) -> Self { + Self::FlashError(v) + } +} + pub fn log_cmpa_write_error(e: CmpaWriteError) { match e { CmpaWriteError::LCStateInvalid => error!("CmpaWriteError: LCStateInvalid"), @@ -547,14 +551,20 @@ pub enum CfpaWriteError { LifecycleRegression, /// The device's actual lifecycle state in CFPA does not match the expected `From` state. LifecycleStateMismatch, - FlashError(FlashStatus), + FlashError(FlashError), FlashVerify { - status: FlashStatus, + status: FlashError, failed_address: u32, failed_data: u32, }, } +impl From for CfpaWriteError { + fn from(v: FlashError) -> Self { + Self::FlashError(v) + } +} + fn read_cfpa_page_for_update() -> Result<[u8; IFRPage::Cfpa.byte_len()], CfpaWriteError> { if !IFRPage::Cfpa .byte_len() @@ -601,82 +611,21 @@ fn read_cfpa_page_for_update() -> Result<[u8; IFRPage::Cfpa.byte_len()], CfpaWri } fn write_cfpa_page_to_scratch(page: &[u8; IFRPage::Cfpa.byte_len()]) -> Result<(), CfpaWriteError> { - let drv = flash_driver(); - let mut cfg = flash_cfg_for_rom_api(); - - let s = drv.flash_init(&mut cfg); - if s != FlashStatus::Success { - error!("cfpa: flash_init failed"); - return Err(CfpaWriteError::FlashError(s)); - } + let mut drv = embassy_mcxa::rom::get().flash()?; // flash_erase_sector supports "flash or User IFR(IFR0)" per ROM API docs. // Start only needs to be phrase-aligned (16-byte); 0x11002000 qualifies. // 0x11002000 + 0x2000 - 1 = 0x110037FF, which is the last byte before NMPA at 0x11003800. - let s = drv.flash_erase_sector( - &mut cfg, + drv.erase_sector( IFRScratchAreaBase::Cfpa as u32, IFRWriteGeometry::ScratchSectorBytes.as_u32(), - FLASH_API_ERASE_KEY, - ); - if s != FlashStatus::Success { - error!( - "cfpa: flash_erase_sector(scratch=0x{:08x}, len=0x{:x}) failed", - IFRScratchAreaBase::Cfpa as u32, - IFRWriteGeometry::ScratchSectorBytes.as_u32() - ); - return Err(CfpaWriteError::FlashError(s)); - } - let s = drv.ifr_verify_erase_sector( - &mut cfg, + )?; + drv.ifr_verify_erase_sector( IFRScratchAreaBase::Cfpa as u32, IFRWriteGeometry::ScratchSectorBytes.as_u32(), - ); - if s != FlashStatus::Success { - error!( - "cfpa: ifr_verify_erase_sector(scratch=0x{:08x}, len=0x{:x}) failed", - IFRScratchAreaBase::Cfpa as u32, - IFRWriteGeometry::ScratchSectorBytes.as_u32() - ); - return Err(CfpaWriteError::FlashError(s)); - } - - let s = drv.flash_program_phrase( - &mut cfg, - IFRScratchAreaBase::Cfpa as u32, - page.as_ptr(), - page.len() as u32, - ); - if s != FlashStatus::Success { - error!( - "cfpa: flash_program_phrase(addr=0x{:08x}, len=0x{:x}) failed", - IFRScratchAreaBase::Cfpa as u32, - page.len() as u32 - ); - return Err(CfpaWriteError::FlashError(s)); - } - - let mut failed_address = 0u32; - let mut failed_data = 0u32; - let s = drv.flash_verify_program( - &mut cfg, - IFRScratchAreaBase::Cfpa as u32, - page.len() as u32, - page.as_ptr(), - &mut failed_address, - &mut failed_data, - ); - if s != FlashStatus::Success { - error!( - "cfpa: flash_verify_program failed @ 0x{:08x} (data=0x{:08x})", - failed_address, failed_data - ); - return Err(CfpaWriteError::FlashVerify { - status: s, - failed_address, - failed_data, - }); - } + )?; + drv.program_phrase(IFRScratchAreaBase::Cfpa as u32, page)?; + drv.verify_program(IFRScratchAreaBase::Cfpa as u32, page)?; Ok(()) } @@ -832,10 +781,10 @@ pub fn verify_lifecycle_transition( next: NbootLifecycleState, ) -> Result, CfpaWriteError> where - From: CanAdvanceTo + ActualLifecycleState, + From: CanAdvanceTo + LifecycleState, { if let Some(current) = load_lifecycle_from_cfpa() { - if current != From::STATE { + if current != From::RUNTIME_VALUE { return Err(CfpaWriteError::LifecycleStateMismatch); } if !current.can_advance_to(next) { @@ -845,21 +794,11 @@ where if next == NbootLifecycleState::Bricked { // Bricking the device is a special case that doesn't require CMPA policy to be valid, since the device will be unusable after this action regardless. //erase all internal (todo: external) flash except the sticky locked SBL region. - let drv = flash_driver(); - let mut cfg = flash_cfg_for_rom_api(); - let s = drv.flash_init(&mut cfg); - - if s != FlashStatus::Success { - return Err(CfpaWriteError::FlashError(s)); - } + let mut drv = embassy_mcxa::rom::get().flash()?; const APP_START: u32 = 0x10000; // BL ends just before 0x10000, so this is the first address of the app region. const ERASE_SIZE: u32 = 0x0020_0000 - APP_START; // Erase from 0x10000 to 0x200000 (2MB flash size) to cover the app region. - let s = drv.flash_erase_sector(&mut cfg, APP_START, ERASE_SIZE, FLASH_API_ERASE_KEY); - - if s != FlashStatus::Success { - return Err(CfpaWriteError::FlashError(s)); - } + drv.erase_sector(APP_START, ERASE_SIZE)?; return Ok(LifecycleAdvanceToken::new(next)); } @@ -976,117 +915,23 @@ pub fn write_cmpa_page_to_scratch(cmpa_page: &[u8; IFRPage::CmpaAll.byte_len()]) let cfpa_page = build_cfpa_page_for_cmpa_update()?; - let drv = flash_driver(); - let mut cfg = flash_cfg_for_rom_api(); - - let status = drv.flash_init(&mut cfg); - if status != FlashStatus::Success { - error!("cmpa: flash_init failed"); - return Err(CmpaWriteError::FlashError(status)); - } + let mut drv = embassy_mcxa::rom::get().flash()?; // Erase the full 8 KB IFR scratch sector, then verify it is blank. // Start only needs to be phrase-aligned (16-byte); 0x11002000 qualifies. // 0x11002000 + 0x2000 - 1 = 0x110037FF, which is the last byte before NMPA at 0x11003800. - let status = drv.flash_erase_sector( - &mut cfg, + drv.erase_sector( IFRScratchAreaBase::Cfpa as u32, IFRWriteGeometry::ScratchSectorBytes.as_u32(), - FLASH_API_ERASE_KEY, - ); - if status != FlashStatus::Success { - error!( - "cmpa: flash_erase_sector(scratch=0x{:08x}, len=0x{:x}) failed", - IFRScratchAreaBase::Cfpa as u32, - IFRWriteGeometry::ScratchSectorBytes.as_u32() - ); - return Err(CmpaWriteError::FlashError(status)); - } - let status = drv.ifr_verify_erase_sector( - &mut cfg, + )?; + drv.ifr_verify_erase_sector( IFRScratchAreaBase::Cfpa as u32, IFRWriteGeometry::ScratchSectorBytes.as_u32(), - ); - if status != FlashStatus::Success { - error!( - "cmpa: ifr_verify_erase_sector(scratch=0x{:08x}, len=0x{:x}) failed", - IFRScratchAreaBase::Cfpa as u32, - IFRWriteGeometry::ScratchSectorBytes.as_u32() - ); - return Err(CmpaWriteError::FlashError(status)); - } - - let status = drv.flash_program_phrase( - &mut cfg, - IFRScratchAreaBase::Cfpa as u32, - cfpa_page.as_ptr(), - cfpa_page.len() as u32, - ); - if status != FlashStatus::Success { - error!( - "cmpa: flash_program_phrase(cfpa_scratch=0x{:08x}, len=0x{:x}) failed", - IFRScratchAreaBase::Cfpa as u32, - cfpa_page.len() as u32 - ); - return Err(CmpaWriteError::FlashError(status)); - } - - let status = drv.flash_program_phrase( - &mut cfg, - IFRScratchAreaBase::Cmpa as u32, - cmpa_page.as_ptr(), - cmpa_page.len() as u32, - ); - if status != FlashStatus::Success { - error!( - "cmpa: flash_program_phrase(cmpa_scratch=0x{:08x}, len=0x{:x}) failed", - IFRScratchAreaBase::Cmpa as u32, - cmpa_page.len() as u32 - ); - return Err(CmpaWriteError::FlashError(status)); - } - - let mut failed_address = 0u32; - let mut failed_data = 0u32; - let status = drv.flash_verify_program( - &mut cfg, - IFRScratchAreaBase::Cfpa as u32, - cfpa_page.len() as u32, - cfpa_page.as_ptr(), - &mut failed_address, - &mut failed_data, - ); - if status != FlashStatus::Success { - error!( - "cmpa: flash_verify_program(cfpa_scratch) failed @ 0x{:08x} (data=0x{:08x})", - failed_address, failed_data - ); - return Err(CmpaWriteError::FlashVerify { - status, - failed_address, - failed_data, - }); - } - - let status = drv.flash_verify_program( - &mut cfg, - IFRScratchAreaBase::Cmpa as u32, - cmpa_page.len() as u32, - cmpa_page.as_ptr(), - &mut failed_address, - &mut failed_data, - ); - if status != FlashStatus::Success { - error!( - "cmpa: flash_verify_program(cmpa_scratch) failed @ 0x{:08x} (data=0x{:08x})", - failed_address, failed_data - ); - return Err(CmpaWriteError::FlashVerify { - status, - failed_address, - failed_data, - }); - } + )?; + drv.program_phrase(IFRScratchAreaBase::Cfpa as u32, &cfpa_page)?; + drv.program_phrase(IFRScratchAreaBase::Cmpa as u32, cmpa_page)?; + drv.verify_program(IFRScratchAreaBase::Cfpa as u32, &cfpa_page)?; + drv.verify_program(IFRScratchAreaBase::Cmpa as u32, cmpa_page)?; Ok(()) } @@ -1135,114 +980,20 @@ pub fn write_cmpa_core_page_to_scratch(cmpa_page: &[u8; IFRPage::Cmpa.byte_len() let cfpa_page = build_cfpa_page_for_cmpa_update()?; - let drv = flash_driver(); - let mut cfg = flash_cfg_for_rom_api(); - - let status = drv.flash_init(&mut cfg); - if status != FlashStatus::Success { - error!("cmpa: flash_init failed"); - return Err(CmpaWriteError::FlashError(status)); - } + let mut drv = embassy_mcxa::rom::get().flash()?; - let status = drv.flash_erase_sector( - &mut cfg, + drv.erase_sector( IFRScratchAreaBase::Cfpa as u32, IFRWriteGeometry::ScratchSectorBytes.as_u32(), - FLASH_API_ERASE_KEY, - ); - if status != FlashStatus::Success { - error!( - "cmpa: flash_erase_sector(scratch=0x{:08x}, len=0x{:x}) failed", - IFRScratchAreaBase::Cfpa as u32, - IFRWriteGeometry::ScratchSectorBytes.as_u32() - ); - return Err(CmpaWriteError::FlashError(status)); - } - let status = drv.ifr_verify_erase_sector( - &mut cfg, + )?; + drv.ifr_verify_erase_sector( IFRScratchAreaBase::Cfpa as u32, IFRWriteGeometry::ScratchSectorBytes.as_u32(), - ); - if status != FlashStatus::Success { - error!( - "cmpa: ifr_verify_erase_sector(scratch=0x{:08x}, len=0x{:x}) failed", - IFRScratchAreaBase::Cfpa as u32, - IFRWriteGeometry::ScratchSectorBytes.as_u32() - ); - return Err(CmpaWriteError::FlashError(status)); - } - - let status = drv.flash_program_phrase( - &mut cfg, - IFRScratchAreaBase::Cfpa as u32, - cfpa_page.as_ptr(), - cfpa_page.len() as u32, - ); - if status != FlashStatus::Success { - error!( - "cmpa: flash_program_phrase(cfpa_scratch=0x{:08x}, len=0x{:x}) failed", - IFRScratchAreaBase::Cfpa as u32, - cfpa_page.len() as u32 - ); - return Err(CmpaWriteError::FlashError(status)); - } - - let status = drv.flash_program_phrase( - &mut cfg, - IFRScratchAreaBase::Cmpa as u32, - cmpa_page.as_ptr(), - cmpa_page.len() as u32, - ); - if status != FlashStatus::Success { - error!( - "cmpa: flash_program_phrase(cmpa_scratch=0x{:08x}, len=0x{:x}) failed", - IFRScratchAreaBase::Cmpa as u32, - cmpa_page.len() as u32 - ); - return Err(CmpaWriteError::FlashError(status)); - } - - let mut failed_address = 0u32; - let mut failed_data = 0u32; - let status = drv.flash_verify_program( - &mut cfg, - IFRScratchAreaBase::Cfpa as u32, - cfpa_page.len() as u32, - cfpa_page.as_ptr(), - &mut failed_address, - &mut failed_data, - ); - if status != FlashStatus::Success { - error!( - "cmpa: flash_verify_program(cfpa_scratch) failed @ 0x{:08x} (data=0x{:08x})", - failed_address, failed_data - ); - return Err(CmpaWriteError::FlashVerify { - status, - failed_address, - failed_data, - }); - } - - let status = drv.flash_verify_program( - &mut cfg, - IFRScratchAreaBase::Cmpa as u32, - cmpa_page.len() as u32, - cmpa_page.as_ptr(), - &mut failed_address, - &mut failed_data, - ); - if status != FlashStatus::Success { - error!( - "cmpa: flash_verify_program(cmpa_scratch) failed @ 0x{:08x} (data=0x{:08x})", - failed_address, failed_data - ); - return Err(CmpaWriteError::FlashVerify { - status, - failed_address, - failed_data, - }); - } + )?; + drv.program_phrase(IFRScratchAreaBase::Cfpa as u32, &cfpa_page)?; + drv.program_phrase(IFRScratchAreaBase::Cmpa as u32, cmpa_page)?; + drv.verify_program(IFRScratchAreaBase::Cfpa as u32, &cfpa_page)?; + drv.verify_program(IFRScratchAreaBase::Cmpa as u32, cmpa_page)?; Ok(()) } @@ -1553,7 +1304,7 @@ pub fn configure_rotkh_and_enable_secure_boot_policies_and_reset( /// The `From` and `Next` type parameters enforce compile-time validation of allowed transitions. pub fn advance_lifecycle_and_reset(next: NbootLifecycleState) -> Result where - From: CanAdvanceTo + ActualLifecycleState, + From: CanAdvanceTo + LifecycleState, { let token = verify_lifecycle_transition::(next)?; cfpa_stage_lifecycle_advance_and_reset(token) diff --git a/mcxa-security-provisioning/Cargo.toml b/mcxa-security-provisioning/Cargo.toml deleted file mode 100644 index 556ab839..00000000 --- a/mcxa-security-provisioning/Cargo.toml +++ /dev/null @@ -1,44 +0,0 @@ -[package] -name = "mcxa-security-provisioning" -version = "0.2.0" -edition = "2021" -license = "MIT OR Apache-2.0" -repository = "https://github.com/OpenDevicePartnership/ec-slimloader" - -[dependencies] -cortex-m = { version = "0.7.7" } -defmt = { version = "0.3", optional = true } -defmt-or-log = { version = "0.2.3" } -log = { version = "0.4", optional = true } -embedded-storage-async = "0.4.1" -embassy-futures = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-mcxa = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0", default-features = false } -embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -partition-manager = { git = "https://github.com/OpenDevicePartnership/embedded-services", tag = "v0.1.0", default-features = false } -partition-manager-macros = { git = "https://github.com/OpenDevicePartnership/embedded-services", tag = "v0.1.0" } -static_cell = "2.1" - -# Re-uses the MCXA lifecycle/IFR types defined in ec-slimloader-mcxa -ec-slimloader-mcxa = { path = "../libs/ec-slimloader-mcxa", default-features = false } - - -[features] -default = ["mcxa5xx", "defmt"] -defmt = ["dep:defmt", "defmt-or-log/defmt", "ec-slimloader-mcxa/defmt"] -log = ["dep:log", "defmt-or-log/log", "ec-slimloader-mcxa/log"] -mcxa2xx = ["embassy-mcxa/mcxa2xx", "ec-slimloader-mcxa/mcxa2xx"] -mcxa5xx = ["embassy-mcxa/mcxa5xx", "ec-slimloader-mcxa/mcxa5xx"] -mcxa5xxevk = ["ec-slimloader-mcxa/mcxa5xxevk"] - -[patch.crates-io] -embassy-embedded-hal = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-executor-macros = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-futures = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-hal-internal = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-time-driver = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -embassy-time-queue-utils = { git = "https://github.com/embassy-rs/embassy", rev = "f21d63db2d104a3b4c070408e529c109a64e65b0" } -rustc_version = { path = "../examples/mcxa-577app/patches/rustc_version" } diff --git a/mcxa-security-provisioning/src/lib.rs b/mcxa-security-provisioning/src/lib.rs deleted file mode 100644 index c9b813e6..00000000 --- a/mcxa-security-provisioning/src/lib.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![no_std] - -pub mod lifecycle_provisioning; - -pub use lifecycle_provisioning::*;