eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 801354aab1d6642aeccd4378b95819eb3280ac4d
parent c12b7d5b5cc9556cf7090de622ec5f6779373d8b
Author: Florian Gebhardt <me@fgardt.dev>
Date:   Sat,  5 Jul 2025 22:01:39 +0200

chore: make clippy happy

Diffstat:
Msrc/crc32.rs | 6+++---
Msrc/helpers.rs | 2+-
Msrc/lib.rs | 31++++++++++---------------------
Msrc/mmu_hal.rs | 4+---
Msrc/mmu_ll/esp32.rs | 28+++++++++++++++++-----------
Msrc/mmu_ll/mod.rs | 4++--
6 files changed, 34 insertions(+), 41 deletions(-)

diff --git a/src/crc32.rs b/src/crc32.rs @@ -35,10 +35,10 @@ const CRC_32_TAB: [u32; 256] = [ pub fn calc_crc32(buf: &[u8], mut crc: u32) -> u32 { crc = !crc; - for i in 0..buf.len() { - let crc_idx = (crc ^ buf[i] as u32) & 0xFF; + for &elem in buf { + let crc_idx = (crc ^ elem as u32) & 0xFF; crc = CRC_32_TAB[crc_idx as usize] ^ (crc >> 8); } - (crc ^ 0xFFFFFFFF) & 0xFFFFFFFF + crc ^ 0xFFFFFFFF } diff --git a/src/helpers.rs b/src/helpers.rs @@ -9,7 +9,7 @@ pub const fn seq_to_part(seq: u32, partitions_count: usize) -> usize { /// Helper funcion! /// If crc of seq is correct it returns seq, otherwise default value is returned pub fn seq_or_default(seq: &[u8], crc: u32, default: u32) -> u32 { - let crc_calc = crate::crc32::calc_crc32(&seq, 0xFFFFFFFF); + let crc_calc = crate::crc32::calc_crc32(seq, 0xFFFFFFFF); if crc == crc_calc { return u32::from_le_bytes(seq.try_into().expect("Wrong size?")); } diff --git a/src/lib.rs b/src/lib.rs @@ -84,10 +84,7 @@ where /// Writes next firmware chunk pub fn ota_write_chunk(&mut self, chunk: &[u8]) -> Result<bool> { - let progress = self - .progress - .as_mut() - .ok_or_else(|| OtaError::OtaNotStarted)?; + let progress = self.progress.as_mut().ok_or(OtaError::OtaNotStarted)?; if progress.remaining == 0 { return Ok(true); @@ -115,18 +112,13 @@ where /// verify - should it read flash and check crc /// rollback - if rollbacks enable (will set ota_state to ESP_OTA_IMG_NEW) pub fn ota_flush(&mut self, verify: bool, rollback: bool) -> Result<()> { - if verify { - if !self.ota_verify()? { - error!("[OTA] Verify failed! Not flushing..."); + if verify && !self.ota_verify()? { + error!("[OTA] Verify failed! Not flushing..."); - return Err(OtaError::OtaVerifyError); - } + return Err(OtaError::OtaVerifyError); } - let progress = self - .progress - .clone() - .ok_or_else(|| OtaError::OtaNotStarted)?; + let progress = self.progress.clone().ok_or(OtaError::OtaNotStarted)?; if progress.target_crc != progress.last_crc { warn!("[OTA] Calculated crc: {}", progress.last_crc); @@ -147,10 +139,7 @@ where /// It reads written flash and checks crc pub fn ota_verify(&mut self) -> Result<bool> { - let progress = self - .progress - .clone() - .ok_or_else(|| OtaError::OtaNotStarted)?; + let progress = self.progress.clone().ok_or(OtaError::OtaNotStarted)?; let mut calc_crc = 0; let mut bytes = [0; OTA_VERIFY_READ_SIZE]; @@ -262,7 +251,7 @@ where let (slot1, slot2) = self.get_ota_boot_entries(); let current_partition = self .get_currently_booted_partition() - .ok_or_else(|| OtaError::CannotFindCurrentBootPartition)?; + .ok_or(OtaError::CannotFindCurrentBootPartition)?; let slot1_part = helpers::seq_to_part(slot1.seq, self.pinfo.ota_partitions_count); let slot2_part = helpers::seq_to_part(slot2.seq, self.pinfo.ota_partitions_count); @@ -279,7 +268,7 @@ where let (slot1, slot2) = self.get_ota_boot_entries(); let current_partition = self .get_currently_booted_partition() - .ok_or_else(|| OtaError::CannotFindCurrentBootPartition)?; + .ok_or(OtaError::CannotFindCurrentBootPartition)?; let slot1_part = helpers::seq_to_part(slot1.seq, self.pinfo.ota_partitions_count); let slot2_part = helpers::seq_to_part(slot2.seq, self.pinfo.ota_partitions_count); @@ -326,12 +315,12 @@ where let mut last_ota_part: i8 = -1; for read_offset in (0..PART_SIZE).step_by(32) { _ = flash.read(PART_OFFSET + read_offset, &mut bytes); - if &bytes == &[0xFF; 32] { + if bytes == [0xFF; 32] { break; } let magic = &bytes[0..2]; - if magic != &[0xAA, 0x50] { + if magic != [0xAA, 0x50] { continue; } diff --git a/src/mmu_hal.rs b/src/mmu_hal.rs @@ -40,9 +40,7 @@ pub fn esp_get_current_running_partition(partitions: &[(u32, u32)]) -> Option<us let paddr_base = crate::mmu_ll::mmu_ll_entry_id_to_paddr_base(mmu_id, entry_id); let paddr = paddr_base | offset; - for i in 0..partitions.len() { - let part = partitions[i]; - + for (i, part) in partitions.iter().enumerate() { if paddr >= part.0 && paddr < part.0 + part.1 { return Some(i); } diff --git a/src/mmu_ll/esp32.rs b/src/mmu_ll/esp32.rs @@ -76,20 +76,26 @@ const SOC_DPORT_WORKAROUND_DIS_INTERRUPT_LVL: u32 = 5; #[inline(always)] unsafe fn dport_interrupt_disable() -> u32 { let level: u32; - core::arch::asm!( - "rsil {0}, {1}", - out(reg) level, - const SOC_DPORT_WORKAROUND_DIS_INTERRUPT_LVL, - options(nomem, nostack) - ); + + unsafe { + core::arch::asm!( + "rsil {0}, {1}", + out(reg) level, + const SOC_DPORT_WORKAROUND_DIS_INTERRUPT_LVL, + options(nomem, nostack) + ); + } + level } #[inline(always)] unsafe fn dport_interrupt_restore(level: u32) { - core::arch::asm!( - "wsr.ps {0}; rsync", - in(reg) level, - options(nomem, nostack) - ); + unsafe { + core::arch::asm!( + "wsr.ps {0}; rsync", + in(reg) level, + options(nomem, nostack) + ); + } } diff --git a/src/mmu_ll/mod.rs b/src/mmu_ll/mod.rs @@ -1,8 +1,8 @@ #[cfg(any(feature = "esp32", feature = "esp32s2"))] macro_rules! soc_address_in_bus { ($bus_name:ident, $vaddr:ident) => {{ - $vaddr >= concat_idents!($bus_name, _ADDRESS_LOW) - && $vaddr < concat_idents!($bus_name, _ADDRESS_HIGH) + (concat_idents!($bus_name, _ADDRESS_LOW)..concat_idents!($bus_name, _ADDRESS_HIGH)) + .contains(&$vaddr) }}; }