From 2c3510497b4ff4b7d6757ca89853c1494ea10c63 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 5 Jan 2019 23:40:03 +0800 Subject: [PATCH] firmware: fix not(has_spiflash) build --- artiq/firmware/libboard_misoc/config.rs | 79 +++++++++++++------------ 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/artiq/firmware/libboard_misoc/config.rs b/artiq/firmware/libboard_misoc/config.rs index c44ee36bb..7ed368efd 100644 --- a/artiq/firmware/libboard_misoc/config.rs +++ b/artiq/firmware/libboard_misoc/config.rs @@ -7,7 +7,8 @@ pub enum Error { Truncated { offset: usize }, InvalidSize { offset: usize, size: usize }, MissingSeparator { offset: usize }, - Utf8Error(str::Utf8Error) + Utf8Error(str::Utf8Error), + NoFlash, } impl fmt::Display for Error { @@ -24,40 +25,13 @@ impl fmt::Display for Error { &Error::MissingSeparator { offset } => write!(f, "missing separator at offset {}", offset), &Error::Utf8Error(err) => - write!(f, "{}", err) + write!(f, "{}", err), + &Error::NoFlash => + write!(f, "flash memory is not present"), } } } -struct FmtWrapper<'a> { - buf: &'a mut [u8], - offset: usize, -} - -impl<'a> FmtWrapper<'a> { - fn new(buf: &'a mut [u8]) -> Self { - FmtWrapper { - buf: buf, - offset: 0, - } - } - - fn contents(&self) -> &[u8] { - &self.buf[..self.offset] - } -} - -impl<'a> fmt::Write for FmtWrapper<'a> { - fn write_str(&mut self, s: &str) -> fmt::Result { - let bytes = s.as_bytes(); - let remainder = &mut self.buf[self.offset..]; - let remainder = &mut remainder[..bytes.len()]; - remainder.copy_from_slice(bytes); - self.offset += bytes.len(); - Ok(()) - } -} - #[cfg(has_spiflash)] mod imp { use core::str; @@ -65,8 +39,37 @@ mod imp { use cache; use spiflash; use super::Error; + use core::fmt; use core::fmt::Write; - use super::FmtWrapper; + + struct FmtWrapper<'a> { + buf: &'a mut [u8], + offset: usize, + } + + impl<'a> FmtWrapper<'a> { + fn new(buf: &'a mut [u8]) -> Self { + FmtWrapper { + buf: buf, + offset: 0, + } + } + + fn contents(&self) -> &[u8] { + &self.buf[..self.offset] + } + } + + impl<'a> fmt::Write for FmtWrapper<'a> { + fn write_str(&mut self, s: &str) -> fmt::Result { + let bytes = s.as_bytes(); + let remainder = &mut self.buf[self.offset..]; + let remainder = &mut remainder[..bytes.len()]; + remainder.copy_from_slice(bytes); + self.offset += bytes.len(); + Ok(()) + } + } // One flash sector immediately before the firmware. const ADDR: usize = ::mem::FLASH_BOOT_ADDRESS - spiflash::SECTOR_SIZE; @@ -284,24 +287,26 @@ mod imp { #[cfg(not(has_spiflash))] mod imp { + use super::Error; + pub fn read) -> R, R>(_key: &str, f: F) -> R { - f(Err(())) + f(Err(Error::NoFlash)) } pub fn read_str) -> R, R>(_key: &str, f: F) -> R { - f(Err(())) + f(Err(Error::NoFlash)) } pub fn write(_key: &str, _value: &[u8]) -> Result<(), Error> { - Err(()) + Err(Error::NoFlash) } pub fn remove(_key: &str) -> Result<(), Error> { - Err(()) + Err(Error::NoFlash) } pub fn erase() -> Result<(), Error> { - Err(()) + Err(Error::NoFlash) } }