From 84b3d9ecc604e3fd30c3b2095b6f336eef3d11c2 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 23 Jun 2018 11:28:12 +0800 Subject: [PATCH] bootloader: also check firmware CRC in SDRAM (#1065) --- artiq/firmware/bootloader/main.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/artiq/firmware/bootloader/main.rs b/artiq/firmware/bootloader/main.rs index 4498140b4..e5515fb20 100644 --- a/artiq/firmware/bootloader/main.rs +++ b/artiq/firmware/bootloader/main.rs @@ -129,17 +129,23 @@ fn flash_boot() { } let firmware_in_flash = unsafe { slice::from_raw_parts(FIRMWARE.offset(8), length) }; - let actual_crc = crc32::checksum_ieee(firmware_in_flash); + let actual_crc_flash = crc32::checksum_ieee(firmware_in_flash); - if actual_crc == expected_crc { + if actual_crc_flash == expected_crc { let firmware_in_sdram = unsafe { slice::from_raw_parts_mut(MAIN_RAM, length) }; firmware_in_sdram.copy_from_slice(firmware_in_flash); - println!("Starting firmware."); - unsafe { boot::jump(MAIN_RAM as usize) } + let actual_crc_sdram = crc32::checksum_ieee(firmware_in_sdram); + if actual_crc_sdram == expected_crc { + println!("Starting firmware."); + unsafe { boot::jump(MAIN_RAM as usize) } + } else { + println!("Firmware CRC failed in SDRAM (actual {:08x}, expected {:08x})", + actual_crc_sdram, expected_crc); + } } else { - println!("Firmware CRC failed (actual {:08x}, expected {:08x})", - actual_crc, expected_crc); + println!("Firmware CRC failed in flash (actual {:08x}, expected {:08x})", + actual_crc_flash, expected_crc); } }