Skip to content

Commit

Permalink
Update rust toolchain to 1.84
Browse files Browse the repository at this point in the history
This fixes all the warnings and erros that the newer rust toolchain
throws.

1.84 uses a bit more stack than 1.70.

Signed-off-by: Arthur Heymans <[email protected]>
  • Loading branch information
ArthurHeymans committed Feb 13, 2025
1 parent e992bd3 commit 1cb6526
Show file tree
Hide file tree
Showing 102 changed files with 531 additions and 625 deletions.
2 changes: 2 additions & 0 deletions .cargo/config → .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Licensed under the Apache-2.0 license

[target.riscv32imc-unknown-none-elf]
rustflags = [
"-C", "target-feature=+relax",
Expand Down
31 changes: 24 additions & 7 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions api/src/soc_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ pub trait SocManager {
.as_mut_bytes()
.split_at_mut(mem::size_of::<MailboxReqHeader>());

let mut header = MailboxReqHeader::mut_from_bytes(header_bytes as &mut [u8]).unwrap();
let header = MailboxReqHeader::mut_from_bytes(header_bytes as &mut [u8]).unwrap();
header.chksum = calc_checksum(R::ID.into(), payload_bytes);

let Some(data) = SocManager::mailbox_exec(self, R::ID.into(), req.as_bytes(), resp_bytes)? else {
return Err(CaliptraApiError::MailboxNoResponseData);
let Some(data) = SocManager::mailbox_exec(self, R::ID.into(), req.as_bytes(), resp_bytes)?
else {
return Err(CaliptraApiError::MailboxNoResponseData);
};

if data.len() < R::Resp::MIN_SIZE || data.len() > mem::size_of::<R::Resp>() {
Expand Down
22 changes: 12 additions & 10 deletions builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ pub fn elf2rom(elf_bytes: &[u8]) -> io::Result<Vec<u8>> {
let elf = elf::ElfBytes::<LittleEndian>::minimal_parse(elf_bytes).map_err(other_err)?;

let Some(segments) = elf.segments() else {
return Err(other_err("ELF file has no segments"))
return Err(other_err("ELF file has no segments"));
};
for segment in segments {
if segment.p_type != elf::abi::PT_LOAD {
Expand All @@ -398,15 +398,21 @@ pub fn elf2rom(elf_bytes: &[u8]) -> io::Result<Vec<u8>> {
let mem_offset = segment.p_paddr as usize;
let len = segment.p_filesz as usize;
let Some(src_bytes) = elf_bytes.get(file_offset..file_offset + len) else {
return Err(other_err(format!("segment at 0x{:x} out of file bounds", segment.p_offset)));
return Err(other_err(format!(
"segment at 0x{:x} out of file bounds",
segment.p_offset
)));
};
if len == 0 {
continue;
}
let Some(dest_bytes) = result.get_mut(mem_offset..mem_offset + len) else {
return Err(other_err(format!(
return Err(other_err(format!(
"segment at 0x{mem_offset:04x}..0x{:04x} exceeds the ROM region \
of 0x0000..0x{:04x}", mem_offset + len, result.len())));
of 0x0000..0x{:04x}",
mem_offset + len,
result.len()
)));
};
dest_bytes.copy_from_slice(src_bytes);
}
Expand Down Expand Up @@ -434,7 +440,7 @@ pub fn elf2rom(elf_bytes: &[u8]) -> io::Result<Vec<u8>> {
pub fn elf_size(elf_bytes: &[u8]) -> io::Result<u64> {
let elf = elf::ElfBytes::<LittleEndian>::minimal_parse(elf_bytes).map_err(other_err)?;
let Some(segments) = elf.segments() else {
return Err(other_err("ELF file has no segments"))
return Err(other_err("ELF file has no segments"));
};
let mut min_addr = u64::MAX;
let mut max_addr = u64::MIN;
Expand All @@ -445,11 +451,7 @@ pub fn elf_size(elf_bytes: &[u8]) -> io::Result<u64> {
min_addr = min_addr.min(segment.p_paddr);
max_addr = max_addr.max(segment.p_paddr + segment.p_filesz);
}
Ok(if max_addr >= min_addr {
max_addr - min_addr
} else {
0
})
Ok(max_addr.saturating_sub(min_addr))
}

#[derive(Clone)]
Expand Down
11 changes: 6 additions & 5 deletions cfi/lib/src/cfi_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ impl Default for CfiInt {
}

fn prng() -> &'static Xoshiro128 {
unsafe { &CFI_STATE.prng }
let cfi_state = &raw const CFI_STATE;
unsafe { &(*cfi_state).prng }
}

/// CFI counter
Expand Down Expand Up @@ -177,17 +178,17 @@ impl CfiCounter {
pub fn read() -> CfiInt {
unsafe {
CfiInt::from_raw(
core::ptr::read_volatile(&CFI_STATE.val as *const u32),
core::ptr::read_volatile(&CFI_STATE.mask as *const u32),
core::ptr::read_volatile(&raw const CFI_STATE.val),
core::ptr::read_volatile(&raw const CFI_STATE.mask),
)
}
}

/// Write counter value
fn write(val: CfiInt) {
unsafe {
core::ptr::write_volatile(&mut CFI_STATE.val as *mut u32, val.val);
core::ptr::write_volatile(&mut CFI_STATE.mask as *mut u32, val.masked_val);
core::ptr::write_volatile(&raw mut CFI_STATE.val, val.val);
core::ptr::write_volatile(&raw mut CFI_STATE.mask, val.masked_val);
}
}
}
2 changes: 1 addition & 1 deletion ci-tools/size-history/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl CommitInfo {
let mut title = expect_line_with_prefix(" ", lines.next())?.to_string();
'inner: loop {
let Some(line) = lines.next() else {
result.push(CommitInfo{
result.push(CommitInfo {
id: commit_id.into(),
author: author.into(),
title,
Expand Down
8 changes: 6 additions & 2 deletions ci-tools/size-history/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ fn real_main() -> io::Result<()> {

if !worktree.is_log_linear()? {
println!("git history is not linear; attempting to squash PR");
let (Ok(pull_request_title), Ok(base_ref)) = (env::var("PR_TITLE"), env::var("PR_BASE_COMMIT")) else {
return Err(other_err("non-linear history not supported outside of a PR"));
let (Ok(pull_request_title), Ok(base_ref)) =
(env::var("PR_TITLE"), env::var("PR_BASE_COMMIT"))
else {
return Err(other_err(
"non-linear history not supported outside of a PR",
));
};
let mut rebase_onto: String = base_ref;
for merge_parents in worktree.merge_log()? {
Expand Down
2 changes: 1 addition & 1 deletion common/src/keyids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub const KEY_ID_ROM_FMC_CDI: KeyId = KeyId::KeyId6;
pub const KEY_ID_FMC_ECDSA_PRIV_KEY: KeyId = KeyId::KeyId7;
#[cfg(feature = "rom")]
pub const KEY_ID_FMC_MLDSA_KEYPAIR_SEED: KeyId = KeyId::KeyId8;
#[cfg(any(feature = "rom"))]
#[cfg(feature = "rom")]
pub const KEY_ID_FW_KEY_LADDER: KeyId = KeyId::KeyId2;
#[cfg(feature = "fmc")]
pub const KEY_ID_RT_CDI: KeyId = KeyId::KeyId4;
Expand Down
2 changes: 1 addition & 1 deletion common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub use fuse::{FuseLogEntry, FuseLogEntryId};
pub use pcr::{PcrLogEntry, PcrLogEntryId, RT_FW_CURRENT_PCR, RT_FW_JOURNEY_PCR};

pub const FMC_ORG: u32 = 0x40000000;
pub const FMC_SIZE: u32 = 21 * 1024;
pub const FMC_SIZE: u32 = 22 * 1024;
pub const RUNTIME_ORG: u32 = FMC_ORG + FMC_SIZE;
pub const RUNTIME_SIZE: u32 = 128 * 1024;

Expand Down
2 changes: 1 addition & 1 deletion common/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct FirmwareImageVerificationEnv<'a, 'b> {
pub image: &'b [u8],
}

impl<'a, 'b> ImageVerificationEnv for &mut FirmwareImageVerificationEnv<'a, 'b> {
impl ImageVerificationEnv for &mut FirmwareImageVerificationEnv<'_, '_> {
/// Calculate 384 digest using SHA2 Engine
fn sha384_digest(&mut self, offset: u32, len: u32) -> CaliptraResult<ImageDigest384> {
let err = CaliptraError::IMAGE_VERIFIER_ERR_DIGEST_OUT_OF_BOUNDS;
Expand Down
1 change: 0 additions & 1 deletion common/src/x509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Abstract:
--*/
use caliptra_drivers::*;
use core::mem::size_of;
use core::usize;
use zerocopy::IntoBytes;

use crate::crypto::PubKey;
Expand Down
10 changes: 5 additions & 5 deletions coverage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn dump_emu_coverage_to_file(
bitmap: &BitVec,
) -> std::io::Result<()> {
let mut filename = format!("CovData{}", hex::encode(rand::random::<[u8; 16]>()));
filename.push_str(&'-'.to_string());
filename.push('-');
filename.push_str(&tag.to_string());
filename.push_str(".bitvec");

Expand Down Expand Up @@ -110,7 +110,7 @@ pub fn get_bitvec_paths(dir: &str) -> Result<Vec<PathBuf>, Box<dyn std::error::E
.map(|dir_entry| dir_entry.path())
// Filter out all paths with extensions other than `bitvec`
.filter_map(|path| {
if path.extension().map_or(false, |ext| ext == "bitvec") {
if path.extension().is_some_and(|ext| ext == "bitvec") {
Some(path)
} else {
None
Expand Down Expand Up @@ -164,7 +164,7 @@ pub fn collect_instr_pcs(id: &FwId<'static>) -> anyhow::Result<Vec<u32>> {
let instruction = u16::from_le_bytes([instruction[0], instruction[1]]);

match instruction & 0b11 {
0 | 1 | 2 => {
0..=2 => {
index += 2;
}
_ => {
Expand Down Expand Up @@ -263,7 +263,7 @@ pub mod calculator {
fn test_parse_trace_file() {
// Create a temporary trace file for testing
let temp_trace_file = "temp_trace.txt";
let trace_data = vec![
let trace_data = [
"SoC write4 *0x300300bc <- 0x0",
"SoC write4 *0x30030110 <- 0x2625a00",
"SoC write4 *0x30030114 <- 0x0",
Expand Down Expand Up @@ -312,5 +312,5 @@ fn test_coverage_map_creation_data_files() {
let paths = get_bitvec_paths("/tmp").unwrap();

let cv = CoverageMap::new(paths);
assert!(cv.map.get(&tag).is_some());
assert!(cv.map.contains_key(&tag));
}
1 change: 1 addition & 0 deletions cpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition = "2021"
# --profile=firmware \
# --features riscv
riscv = []
std = []

[lib]
test = false
Expand Down
3 changes: 2 additions & 1 deletion drivers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ caliptra-cfi-lib-git = { workspace = true, default-features = false, features =
caliptra-cfi-derive-git = { workspace = true, optional = true }

[features]
std = []
emu = []
riscv = []
runtime = ["dep:dpe", "dep:caliptra-cfi-lib-git", "dep:caliptra-cfi-derive-git"]
fmc = []
fpga_realtime = ["caliptra-hw-model/fpga_realtime"]
Expand All @@ -45,4 +47,3 @@ caliptra-hw-model-types.workspace = true
caliptra-hw-model.workspace = true
caliptra-test.workspace = true
openssl.workspace = true
caliptra_common.workspace = true
4 changes: 2 additions & 2 deletions drivers/src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl<'a> DmaMmio<'a> {
}
}

impl<'a> Mmio for &DmaMmio<'a> {
impl Mmio for &DmaMmio<'_> {
#[inline(always)]
unsafe fn read_volatile<T: ureg::Uint>(&self, src: *const T) -> T {
// we only support 32-bit reads
Expand All @@ -444,7 +444,7 @@ impl<'a> Mmio for &DmaMmio<'a> {
}
}

impl<'a> MmioMut for &DmaMmio<'a> {
impl MmioMut for &DmaMmio<'_> {
#[inline(always)]
unsafe fn write_volatile<T: ureg::Uint>(&self, dst: *mut T, src: T) {
// we only support 32-bit writes
Expand Down
16 changes: 2 additions & 14 deletions drivers/src/ecc384.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl From<KeyReadArgs> for Ecc384Seed<'_> {
}
}

/// ECC-384 Private Key output
/// ECC-384 Public Key output
#[derive(Debug)]
pub enum Ecc384PrivKeyOut<'a> {
/// Array
Expand All @@ -76,7 +76,7 @@ impl<'a> From<&'a mut Array4x12> for Ecc384PrivKeyOut<'a> {
}
}

impl<'a> From<KeyWriteArgs> for Ecc384PrivKeyOut<'a> {
impl From<KeyWriteArgs> for Ecc384PrivKeyOut<'_> {
/// Converts to this type from the input type.
fn from(value: KeyWriteArgs) -> Self {
Self::Key(value)
Expand Down Expand Up @@ -654,9 +654,6 @@ trait Ecc384KeyAccessErr {
/// Convert to read seed operation error
fn into_read_seed_err(self) -> CaliptraError;

/// Convert to read data operation error
fn into_read_data_err(self) -> CaliptraError;

/// Convert to read private key operation error
fn into_read_priv_key_err(self) -> CaliptraError;

Expand All @@ -674,15 +671,6 @@ impl Ecc384KeyAccessErr for KvAccessErr {
}
}

/// Convert to read data operation error
fn into_read_data_err(self) -> CaliptraError {
match self {
KvAccessErr::KeyRead => CaliptraError::DRIVER_ECC384_READ_DATA_KV_READ,
KvAccessErr::KeyWrite => CaliptraError::DRIVER_ECC384_READ_DATA_KV_WRITE,
KvAccessErr::Generic => CaliptraError::DRIVER_ECC384_READ_DATA_KV_UNKNOWN,
}
}

/// Convert to reads private key operation error
fn into_read_priv_key_err(self) -> CaliptraError {
match self {
Expand Down
Loading

0 comments on commit 1cb6526

Please sign in to comment.