forked from M-Labs/artiq
1
0
Fork 0

bootloader: also check firmware CRC in SDRAM (#1065)

This commit is contained in:
Sebastien Bourdeauducq 2018-06-23 11:28:12 +08:00
parent 68530fde07
commit 84b3d9ecc6
1 changed files with 12 additions and 6 deletions

View File

@ -129,17 +129,23 @@ fn flash_boot() {
} }
let firmware_in_flash = unsafe { slice::from_raw_parts(FIRMWARE.offset(8), length) }; 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) }; let firmware_in_sdram = unsafe { slice::from_raw_parts_mut(MAIN_RAM, length) };
firmware_in_sdram.copy_from_slice(firmware_in_flash); firmware_in_sdram.copy_from_slice(firmware_in_flash);
println!("Starting firmware."); let actual_crc_sdram = crc32::checksum_ieee(firmware_in_sdram);
unsafe { boot::jump(MAIN_RAM as usize) } 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 { } else {
println!("Firmware CRC failed (actual {:08x}, expected {:08x})", println!("Firmware CRC failed in flash (actual {:08x}, expected {:08x})",
actual_crc, expected_crc); actual_crc_flash, expected_crc);
} }
} }