summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDov Shlachter <dovs@google.com>2024-02-29 22:07:36 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-02-29 22:07:36 +0000
commitc9aec88886bce5bf9c35f4181598e98bc8b590e9 (patch)
tree8fb9b0424a78a27dec709a48ac424fb8e23f85ad
parent93cb33381b8476d212990c757ce082cf0eaca91c (diff)
parenta9a6cde38c89dbea443226e50dbbe7b64f6055c7 (diff)
downloadlibbootloader-c9aec88886bce5bf9c35f4181598e98bc8b590e9.tar.gz
Merge "Minor cleanups for slots" into main am: a9a6cde38c
Original change: https://android-review.googlesource.com/c/platform/bootable/libbootloader/+/2973876 Change-Id: I455e773466a1d552c6ad47d026dfb32ef5ecb9d0 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--gbl/libgbl/src/slots.rs9
-rw-r--r--gbl/libgbl/src/slots/fuchsia.rs16
2 files changed, 15 insertions, 10 deletions
diff --git a/gbl/libgbl/src/slots.rs b/gbl/libgbl/src/slots.rs
index 10d1475..5269e51 100644
--- a/gbl/libgbl/src/slots.rs
+++ b/gbl/libgbl/src/slots.rs
@@ -62,6 +62,14 @@ impl From<char> for Suffix {
}
}
+impl TryFrom<usize> for Suffix {
+ type Error = Error;
+
+ fn try_from(value: usize) -> Result<Self, Self::Error> {
+ u32::try_from(value).ok().and_then(char::from_u32).ok_or(Error::Other).map(Self)
+ }
+}
+
// Includes a null terminator
const SUFFIX_CSTR_MAX_BYTES: usize = size_of::<Suffix>() + 1;
@@ -224,6 +232,7 @@ impl BootTarget {
#[doc(hidden)]
pub mod private {
use super::*;
+
#[doc(hidden)]
pub trait SlotGet {
/// Given an index, returns the Slot that corresponds to that index,
diff --git a/gbl/libgbl/src/slots/fuchsia.rs b/gbl/libgbl/src/slots/fuchsia.rs
index ce25ef9..7aead36 100644
--- a/gbl/libgbl/src/slots/fuchsia.rs
+++ b/gbl/libgbl/src/slots/fuchsia.rs
@@ -222,13 +222,11 @@ impl Default for SlotBlock {
impl super::private::SlotGet for SlotBlock {
fn get_slot_by_number(&self, number: usize) -> Result<Slot, Error> {
- let abr_slot = self.abr_data.slot_data.get(number).ok_or(Error::Other)?;
-
- let suffix = match number {
- 0 => 'a'.into(),
- 1 => 'b'.into(),
- _ => Err(Error::Other)?,
- };
+ let lower_ascii = 'a'..='z';
+ let (suffix, &abr_slot) = core::iter::zip(lower_ascii, self.get_data().slot_data.iter())
+ .nth(number)
+ .map(|(c, s)| (Suffix(c), s))
+ .ok_or_else(|| Suffix::try_from(number).map_or(Error::Other, Error::NoSuchSlot))?;
let bootability = match (abr_slot.successful, abr_slot.tries) {
(s, _) if s != 0 => Bootability::Successful,
@@ -321,7 +319,7 @@ impl Manager for SlotBlock {
fn set_active_slot(&mut self, slot_suffix: Suffix) -> Result<(), Error> {
let (idx, _) = self.get_index_and_slot_with_suffix(slot_suffix)?;
- let abr_data = &mut self.get_mut_data();
+ let abr_data = self.get_mut_data();
for (i, slot) in abr_data.slot_data.iter_mut().enumerate() {
if i == idx {
*slot = Default::default();
@@ -337,8 +335,6 @@ impl Manager for SlotBlock {
}
fn set_oneshot_status(&mut self, oneshot: OneShot) -> Result<(), Error> {
- // TODO(dovs): gate behind avb unlock status
-
if Some(oneshot) == self.get_oneshot_status() {
return Ok(());
}