Repository: chipsalliance/caliptra-sw
Pull request #552 (2023-07-27 20:39:43)

Some ROM size optimizations (-700 bytes)


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 9c60d48e..c28ef351 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1717,8 +1717,7 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
 [[package]]
 name = "ufmt"
 version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a64846ec02b57e9108d6469d98d1648782ad6bb150a95a9baac26900bbeab9d"
+source = "git+https://github.com/korran/ufmt.git?rev=1d0743c1ffffc68bc05ca8eeb81c166192863f33#1d0743c1ffffc68bc05ca8eeb81c166192863f33"
 dependencies = [
  "ufmt-macros",
  "ufmt-write",
@@ -1727,8 +1726,7 @@ dependencies = [
 [[package]]
 name = "ufmt-macros"
 version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d337d3be617449165cb4633c8dece429afd83f84051024079f97ad32a9663716"
+source = "git+https://github.com/korran/ufmt.git?rev=1d0743c1ffffc68bc05ca8eeb81c166192863f33#1d0743c1ffffc68bc05ca8eeb81c166192863f33"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -1738,8 +1736,7 @@ dependencies = [
 [[package]]
 name = "ufmt-write"
 version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69"
+source = "git+https://github.com/korran/ufmt.git?rev=1d0743c1ffffc68bc05ca8eeb81c166192863f33#1d0743c1ffffc68bc05ca8eeb81c166192863f33"
 
 [[package]]
 name = "uio"
diff --git a/Cargo.toml b/Cargo.toml
index 0ce8694e..279c37b4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -62,6 +62,9 @@ members = [
   "test-harness/types",
 ]
 
+[workspace.dependencies]
+ufmt = { git = "https://github.com/korran/ufmt.git", rev = "1d0743c1ffffc68bc05ca8eeb81c166192863f33", features = ["inline"] }
+
 [profile.firmware]
 inherits = "release"
 panic = "abort"
diff --git a/common/Cargo.toml b/common/Cargo.toml
index 92e8532f..521e6313 100644
--- a/common/Cargo.toml
+++ b/common/Cargo.toml
@@ -7,7 +7,7 @@ edition = "2021"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-ufmt = "0.2.0"
+ufmt = { workspace = true }
 zerocopy = "0.6.1"
 caliptra-drivers = { path = "../drivers" }
 caliptra-registers = { path = "../registers" }
diff --git a/fmc/Cargo.toml b/fmc/Cargo.toml
index ac49dc70..747aeb17 100644
--- a/fmc/Cargo.toml
+++ b/fmc/Cargo.toml
@@ -13,7 +13,7 @@ caliptra-registers = { path = "../registers" }
 caliptra-x509 = { version = "0.1.0", path = "../x509" , default-features = false }
 caliptra_common = { path = "../common", default-features = false }
 caliptra-image-types = { path = "../image/types",  default-features = false  }
-ufmt = "0.2.0"
+ufmt = { workspace = true }
 zerocopy = "0.6.1"
 
 [build-dependencies]
diff --git a/image/verify/src/verifier.rs b/image/verify/src/verifier.rs
index 48160242..bcf925aa 100644
--- a/image/verify/src/verifier.rs
+++ b/image/verify/src/verifier.rs
@@ -389,6 +389,8 @@ impl<Env: ImageVerificationEnv> ImageVerifier<Env> {
     }
 
     /// Verify Owner Signature
+    // Inlined to reduce ROM size
+    #[inline(always)]
     fn verify_owner_ecc_sig(
         &mut self,
         digest: &ImageDigest,
@@ -688,6 +690,8 @@ impl<Env: ImageVerificationEnv> ImageVerifier<Env> {
     /// Calculates a digest of the vendor key that signed the image.
     ///
     /// TODO: include the LMS key in the digest.
+    // Inlined to reduce ROM size
+    #[inline(always)]
     fn make_vendor_key_digest(&mut self, info: &HeaderInfo) -> CaliptraResult<ImageDigest> {
         let range = ImageManifest::vendor_ecc_pub_key_range(info.vendor_ecc_pub_key_idx);
 
diff --git a/rom/dev/Cargo.toml b/rom/dev/Cargo.toml
index d808487c..a84df257 100644
--- a/rom/dev/Cargo.toml
+++ b/rom/dev/Cargo.toml
@@ -15,7 +15,7 @@ caliptra-image-types = { path = "../../image/types", default-features = false }
 caliptra-image-verify = { path = "../../image/verify", default-features = false }
 caliptra_common = { path = "../../common", default-features = false }
 caliptra-registers = { path = "../../registers" }
-ufmt = "0.2.0"
+ufmt = { workspace = true }
 zerocopy = "0.6.1"
 caliptra-error = { version = "0.1.0", path = "../../error", default_features = false }
 
diff --git a/rom/dev/src/flow/cold_reset/fw_processor.rs b/rom/dev/src/flow/cold_reset/fw_processor.rs
index 81127d9e..4c966359 100644
--- a/rom/dev/src/flow/cold_reset/fw_processor.rs
+++ b/rom/dev/src/flow/cold_reset/fw_processor.rs
@@ -281,6 +281,8 @@ impl FirmwareProcessor {
     /// * `env`      - ROM Environment
     /// * `manifest` - Manifest
     /// * `txn`      - Mailbox Receive Transaction
+    // Inlined to reduce ROM size
+    #[inline(always)]
     fn load_image(manifest: &ImageManifest, txn: &mut MailboxRecvTxn) -> CaliptraResult<()> {
         cprintln!(
             "[afmc] Loading FMC at address 0x{:08x} len {}",
diff --git a/rom/dev/src/flow/cold_reset/idev_id.rs b/rom/dev/src/flow/cold_reset/idev_id.rs
index cbadaa67..ca965a18 100644
--- a/rom/dev/src/flow/cold_reset/idev_id.rs
+++ b/rom/dev/src/flow/cold_reset/idev_id.rs
@@ -182,6 +182,8 @@ impl InitDevIdLayer {
     ///
     /// * `env`    - ROM Environment
     /// * `output` - DICE Output
+    // Inlined to reduce ROM size
+    #[inline(always)]
     fn generate_csr(env: &mut RomEnv, output: &DiceOutput) -> CaliptraResult<()> {
         //
         // Generate the CSR if requested via Manufacturing Service Register
diff --git a/rom/dev/src/kat.rs b/rom/dev/src/kat.rs
index dcb7a536..a8cf2127 100644
--- a/rom/dev/src/kat.rs
+++ b/rom/dev/src/kat.rs
@@ -25,25 +25,25 @@ use crate::{cprintln, rom_env::RomEnv};
 pub fn execute_kat(env: &mut RomEnv) -> CaliptraResult<()> {
     cprintln!("[kat] ++");
 
-    cprintln!("[kat] Executing SHA1 Engine KAT");
+    cprintln!("[kat] sha1");
     Sha1Kat::default().execute(&mut env.sha1)?;
 
-    cprintln!("[kat] Executing SHA2-256 Engine KAT");
+    cprintln!("[kat] SHA2-256");
     Sha256Kat::default().execute(&mut env.sha256)?;
 
-    cprintln!("[kat] Executing SHA2-384 Engine KAT");
+    cprintln!("[kat] SHA2-384");
     Sha384Kat::default().execute(&mut env.sha384)?;
 
-    cprintln!("[kat] Executing SHA2-384 Accelerator KAT");
+    cprintln!("[kat] SHA2-384-ACC");
     Sha384AccKat::default().execute(&mut env.sha384_acc)?;
 
-    cprintln!("[kat] Executing ECC-384 Engine KAT");
+    cprintln!("[kat] ECC-384");
     Ecc384Kat::default().execute(&mut env.ecc384, &mut env.trng)?;
 
-    cprintln!("[kat] Executing HMAC-384 Engine KAT");
+    cprintln!("[kat] HMAC-384");
     Hmac384Kat::default().execute(&mut env.hmac384, &mut env.trng)?;
 
-    cprintln!("[kat] Executing LMS Engine KAT");
+    cprintln!("[kat] LMS");
     LmsKat::default().execute(&mut env.sha256, &env.lms)?;
 
     cprintln!("[kat] --");
diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml
index 31f037da..48151fe1 100644
--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -12,7 +12,7 @@ caliptra-registers = { path = "../registers" }
 caliptra_common = { path = "../common", default-features = false }
 caliptra-x509 = { path = "../x509", default-features = false }
 caliptra-image-types = { path = "../image/types", default-features = false }
-ufmt = "0.2.0"
+ufmt = { workspace = true }
 zerocopy = "0.6.1"
 caliptra-kat = { version = "0.1.0", path = "../kat" }
 


Test patch:
diff --git a/fmc/test-fw/test-rt/Cargo.toml b/fmc/test-fw/test-rt/Cargo.toml
index d5a410bb..47952042 100644
--- a/fmc/test-fw/test-rt/Cargo.toml
+++ b/fmc/test-fw/test-rt/Cargo.toml
@@ -10,7 +10,7 @@ caliptra-cpu = { version = "0.1.0", path = "../../../cpu" }
 caliptra-drivers = { path = "../../../drivers" }
 caliptra-registers = { version = "0.1.0", path = "../../../registers" }
 caliptra_common = { path = "../../../common", default-features = false }
-ufmt = "0.2.0"
+ufmt = { workspace = true }
 zerocopy = "0.6.1"
 
 [build-dependencies]
diff --git a/rom/dev/tools/test-fmc/Cargo.toml b/rom/dev/tools/test-fmc/Cargo.toml
index edf66d5b..9ae52425 100644
--- a/rom/dev/tools/test-fmc/Cargo.toml
+++ b/rom/dev/tools/test-fmc/Cargo.toml
@@ -8,7 +8,7 @@ edition = "2021"
 [dependencies]
 caliptra-drivers = { path = "../../../../drivers" }
 caliptra_common = { path = "../../../../common", default-features = false }
-ufmt = "0.2.0"
+ufmt = { workspace = true }
 ureg = { path = "../../../../ureg" }
 zerocopy = "0.6.1"
 caliptra-x509 = { version = "0.1.0", path = "../../../../x509" , default-features = false }
diff --git a/rom/dev/tools/test-rt/Cargo.toml b/rom/dev/tools/test-rt/Cargo.toml
index 5012709d..a0d0366f 100644
--- a/rom/dev/tools/test-rt/Cargo.toml
+++ b/rom/dev/tools/test-rt/Cargo.toml
@@ -7,7 +7,7 @@ edition = "2021"
 
 [dependencies]
 caliptra-drivers = { path = "../../../../drivers" }
-ufmt = "0.2.0"
+ufmt = { workspace = true }
 caliptra-cpu = { version = "0.1.0", path = "../../../../cpu" }
 
 [build-dependencies]