eculocate

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

commit 82545ae04b23b5f207347cd28f2dc3747b853ef1
parent 7b111fab774e18407da3bc68527e88394d7f2cba
Author: filipton <filipton12@gmail.com>
Date:   Fri,  5 Jul 2024 10:50:59 +0200

feat: simplify crc calculations

Diffstat:
Msimple-ota-server/src/main.rs | 6+-----
Msrc/lib.rs | 10+++-------
2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/simple-ota-server/src/main.rs b/simple-ota-server/src/main.rs @@ -5,11 +5,7 @@ use std::{ fn main() { let binary = std::fs::read("./firmware.bin").unwrap(); - let mut binary_bytes = Vec::with_capacity(binary.len() + 4); - binary_bytes.extend_from_slice(&[255, 255, 255, 255]); // to calc crc32 from binary, append - // 4 x 255's at the beggining - binary_bytes.extend_from_slice(&binary); - let binary_crc = crc32fast::hash(&binary_bytes); + let binary_crc = crc32fast::hash(&binary); println!("BINARY_SIZE: {}", binary.len()); println!("BINARY CRC32: {}", binary_crc); diff --git a/src/lib.rs b/src/lib.rs @@ -25,7 +25,7 @@ where { flash: S, - last_crc: Option<u32>, + last_crc: u32, ota_offset: Option<u32>, target_partition: Option<usize>, flash_size: u32, @@ -42,7 +42,7 @@ where Ota { flash, - last_crc: None, + last_crc: 0, ota_offset: None, target_partition: None, ota_remaining: 0, @@ -98,11 +98,7 @@ where ota_offset ); - self.last_crc = if let Some(last_crc) = self.last_crc { - Some(crc32::calc_crc32(&chunk[..write_size], last_crc)) - } else { - Some(crc32::calc_crc32(&chunk[..write_size], 0xFFFFFFFF)) - }; + self.last_crc = crc32::calc_crc32(&chunk[..write_size], self.last_crc); *ota_offset += write_size as u32; self.ota_remaining -= write_size as u32;