firmware: fix not(has_spiflash) build

This commit is contained in:
Sebastien Bourdeauducq 2019-01-05 23:40:03 +08:00
parent d6fea22174
commit 2c3510497b
1 changed files with 42 additions and 37 deletions

View File

@ -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,11 +25,23 @@ 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"),
}
}
}
#[cfg(has_spiflash)]
mod imp {
use core::str;
use byteorder::{ByteOrder, BigEndian};
use cache;
use spiflash;
use super::Error;
use core::fmt;
use core::fmt::Write;
struct FmtWrapper<'a> {
buf: &'a mut [u8],
offset: usize,
@ -58,16 +71,6 @@ impl<'a> fmt::Write for FmtWrapper<'a> {
}
}
#[cfg(has_spiflash)]
mod imp {
use core::str;
use byteorder::{ByteOrder, BigEndian};
use cache;
use spiflash;
use super::Error;
use core::fmt::Write;
use super::FmtWrapper;
// One flash sector immediately before the firmware.
const ADDR: usize = ::mem::FLASH_BOOT_ADDRESS - spiflash::SECTOR_SIZE;
const SIZE: usize = spiflash::SECTOR_SIZE;
@ -284,24 +287,26 @@ mod imp {
#[cfg(not(has_spiflash))]
mod imp {
use super::Error;
pub fn read<F: FnOnce(Result<&[u8], Error>) -> R, R>(_key: &str, f: F) -> R {
f(Err(()))
f(Err(Error::NoFlash))
}
pub fn read_str<F: FnOnce(Result<&str, Error>) -> 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)
}
}