From 8294d7fea560258cff04cea1192ee38900458bbb Mon Sep 17 00:00:00 2001 From: occheung Date: Thu, 15 Jul 2021 15:59:18 +0800 Subject: [PATCH] bootloader: swap endianness Signed-off-by: occheung --- artiq/firmware/bootloader/Makefile | 3 ++- artiq/firmware/bootloader/main.rs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/artiq/firmware/bootloader/Makefile b/artiq/firmware/bootloader/Makefile index ee70ff22f..d5a34f5ba 100644 --- a/artiq/firmware/bootloader/Makefile +++ b/artiq/firmware/bootloader/Makefile @@ -14,4 +14,5 @@ bootloader.elf: $(RUSTOUT)/libbootloader.a %.bin: %.elf $(objcopy) -O binary - $(MSCIMG) $@ + $(MSCIMG) $@ --little + objcopy -I binary -O binary --reverse-bytes=4 $@ diff --git a/artiq/firmware/bootloader/main.rs b/artiq/firmware/bootloader/main.rs index bb7030051..daa3a9be7 100644 --- a/artiq/firmware/bootloader/main.rs +++ b/artiq/firmware/bootloader/main.rs @@ -10,7 +10,7 @@ extern crate riscv; use core::{ptr, slice, convert::TryFrom}; use crc::crc32; -use byteorder::{ByteOrder, BigEndian}; +use byteorder::{ByteOrder, LittleEndian}; use board_misoc::{ident, cache, sdram, config, boot, mem as board_mem}; #[cfg(has_slave_fpga_cfg)] use board_misoc::slave_fpga; @@ -157,8 +157,8 @@ fn flash_boot() { println!("Booting from flash..."); let header = unsafe { slice::from_raw_parts(FIRMWARE, 8) }; - let length = BigEndian::read_u32(&header[0..]) as usize; - let expected_crc = BigEndian::read_u32(&header[4..]); + let length = LittleEndian::read_u32(&header[0..]) as usize; + let expected_crc = LittleEndian::read_u32(&header[4..]); if length == 0 || length == 0xffffffff { println!("No firmware present");