implement CRC write
Some checks failed
Rust/va416xx-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
2024-09-11 17:26:31 +02:00
parent 1cc8645781
commit 1b313d21c4
5 changed files with 70 additions and 24 deletions

View File

@@ -18,7 +18,7 @@
#![no_std]
use cortex_m_rt::entry;
use crc::{Crc, CRC_16_IBM_3740};
use crc::{Crc, CRC_32_ISO_HDLC};
use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
use va416xx_hal::{
@@ -47,7 +47,7 @@ const FLASH_SELF: bool = false;
const BOOTLOADER_START_ADDR: u32 = 0x0;
const BOOTLOADER_END_ADDR: u32 = 0x4000;
const BOOTLOADER_CRC_ADDR: u32 = 0x3FFE;
const BOOTLOADER_CRC_ADDR: u32 = 0x3FFC;
const APP_A_START_ADDR: u32 = 0x4000;
pub const APP_A_END_ADDR: u32 = 0x22000;
// The actual size of the image which is relevant for CRC calculation.
@@ -64,7 +64,7 @@ pub const VECTOR_TABLE_OFFSET: u32 = 0x0;
pub const VECTOR_TABLE_LEN: u32 = 0x350;
pub const RESET_VECTOR_OFFSET: u32 = 0x4;
const CRC_ALGO: Crc<u16> = Crc::<u16>::new(&CRC_16_IBM_3740);
const CRC_ALGO: Crc<u32> = Crc::<u32>::new(&CRC_32_ISO_HDLC);
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
enum AppSel {
@@ -111,6 +111,7 @@ fn main() -> ! {
WDT_FREQ_MS,
));
}
let nvm = Nvm::new(&mut dp.sysconfig, dp.spi3, &clocks);
if FLASH_SELF {
@@ -172,7 +173,7 @@ fn main() -> ! {
}
fn check_own_crc(wdt: &OptWdt, nvm: &Nvm, cp: &cortex_m::Peripherals) {
let crc_exp = unsafe { *(BOOTLOADER_CRC_ADDR as *const u16) };
let crc_exp = unsafe { *(BOOTLOADER_CRC_ADDR as *const u32) };
wdt.feed();
// I'd prefer to use [core::slice::from_raw_parts], but that is problematic
// because the address of the bootloader is 0x0, so the NULL check fails and the functions
@@ -219,7 +220,7 @@ fn check_app_given_addr(
image_size_addr: u32,
wdt: &OptWdt,
) -> bool {
let crc_exp = unsafe { *(crc_addr as *const u16) };
let crc_exp = unsafe { *(crc_addr as *const u32) };
let image_size = unsafe { *(image_size_addr as *const u32) };
wdt.feed();
let crc_calc = CRC_ALGO.checksum(unsafe {