diff --git a/artiq/firmware/libboard_misoc/config.rs b/artiq/firmware/libboard_misoc/config.rs index 9a737e303..51f71ac33 100644 --- a/artiq/firmware/libboard_misoc/config.rs +++ b/artiq/firmware/libboard_misoc/config.rs @@ -9,6 +9,7 @@ pub enum Error { MissingSeparator { offset: usize }, Utf8Error(str::Utf8Error), NoFlash, + KeyNotFound } impl fmt::Display for Error { @@ -28,6 +29,8 @@ impl fmt::Display for Error { write!(f, "{}", err), &Error::NoFlash => write!(f, "flash memory is not present"), + &Error::KeyNotFound => + write!(f, "key not found") } } } @@ -156,14 +159,16 @@ mod imp { f(Lock::take().and_then(|lock| { let mut iter = Iter::new(lock.data()); let mut value = &[][..]; + let mut found = false; while let Some(result) = iter.next() { let (record_key, record_value) = result?; if key.as_bytes() == record_key { + found = true; // last write wins value = record_value } } - Ok(value) + if found { Ok(value) } else { Err(Error::KeyNotFound) } })) } diff --git a/artiq/firmware/runtime/session.rs b/artiq/firmware/runtime/session.rs index bd1562269..c6d745545 100644 --- a/artiq/firmware/runtime/session.rs +++ b/artiq/firmware/runtime/session.rs @@ -529,7 +529,7 @@ fn flash_kernel_worker(io: &Io, aux_mutex: &Mutex, config::read(config_key, |result| { match result { - Ok(kernel) if kernel.len() > 0 => unsafe { + Ok(kernel) => unsafe { // kernel CPU cannot access the SPI flash address space directly, // so make a copy. kern_load(io, &mut session, Vec::from(kernel).as_ref())