summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-03-04 21:55:12 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-03-04 21:55:12 +0000
commit7c4db9852a3d7c32ad46dce1c6c1e7051e453696 (patch)
tree342b68a9b565f115a456a1e8fd2e2925d9ae121a
parent2d7d31896ab372d8698553f03a97b5a7371ab5ab (diff)
parent5eb69cfb3d3412054ce4a6fe48af10971f5966fe (diff)
downloadlibbootloader-simpleperf-release.tar.gz
Snap for 11526323 from 5eb69cfb3d3412054ce4a6fe48af10971f5966fe to simpleperf-releasesimpleperf-release
Change-Id: I01a2c6d26b3c585c4886d7dd5dfffacf368ad8eb
-rw-r--r--gbl/build.config.constants2
-rw-r--r--gbl/efi/src/android_boot.rs34
-rw-r--r--gbl/efi/src/fuchsia_boot.rs4
-rw-r--r--gbl/efi/src/main.rs8
-rw-r--r--gbl/efi/src/utils.rs4
-rw-r--r--gbl/libavb/BUILD.avb.bazel6
-rw-r--r--gbl/libbootimg/BUILD1
-rw-r--r--gbl/libefi/BUILD5
-rw-r--r--gbl/libefi/src/lib.rs12
-rw-r--r--gbl/libfdt/BUILD5
-rw-r--r--gbl/libgbl/src/slots.rs9
-rw-r--r--gbl/libgbl/src/slots/fuchsia.rs16
-rw-r--r--gbl/libstorage/src/gpt.rs4
13 files changed, 69 insertions, 41 deletions
diff --git a/gbl/build.config.constants b/gbl/build.config.constants
index 370ff7d..0a9f1f5 100644
--- a/gbl/build.config.constants
+++ b/gbl/build.config.constants
@@ -1,2 +1,2 @@
BRANCH=u-boot-mainline
-CLANG_VERSION=r475365b
+CLANG_VERSION=r510928
diff --git a/gbl/efi/src/android_boot.rs b/gbl/efi/src/android_boot.rs
index 02f54c6..b41b808 100644
--- a/gbl/efi/src/android_boot.rs
+++ b/gbl/efi/src/android_boot.rs
@@ -18,7 +18,7 @@ use core::str::from_utf8;
use bootconfig::{BootConfigBuilder, BootConfigError};
use bootimg::{BootImage, VendorImageHeader};
-use efi::{efi_print, exit_boot_services, EfiEntry};
+use efi::{efi_print, efi_println, exit_boot_services, EfiEntry};
use fdt::Fdt;
use crate::error::{EfiAppError, GblEfiError, Result};
@@ -108,12 +108,12 @@ pub fn load_android_simple<'a>(
(hdr._base.kernel_size as usize, &hdr._base.cmdline[..], PAGE_SIZE)
}
_ => {
- efi_print!(efi_entry, "V0/V1/V2 images are not supported\n");
+ efi_println!(efi_entry, "V0/V1/V2 images are not supported");
return Err(GblEfiError::EfiAppError(EfiAppError::Unsupported));
}
};
- efi_print!(efi_entry, "boot image size: {}\n", kernel_size);
- efi_print!(efi_entry, "boot image cmdline: \"{}\"\n", from_utf8(cmdline).unwrap());
+ efi_println!(efi_entry, "boot image size: {}", kernel_size);
+ efi_println!(efi_entry, "boot image cmdline: \"{}\"", from_utf8(cmdline).unwrap());
// Parse vendor boot header.
let (vendor_boot_header_buffer, load) = load.split_at_mut(PAGE_SIZE);
@@ -131,8 +131,8 @@ pub fn load_android_simple<'a>(
&hdr._base.cmdline[..],
),
};
- efi_print!(efi_entry, "vendor ramdisk size: {}\n", vendor_ramdisk_size);
- efi_print!(efi_entry, "vendor cmdline: \"{}\"\n", from_utf8(vendor_cmdline).unwrap());
+ efi_println!(efi_entry, "vendor ramdisk size: {}", vendor_ramdisk_size);
+ efi_println!(efi_entry, "vendor cmdline: \"{}\"", from_utf8(vendor_cmdline).unwrap());
// Parse init_boot header
let init_boot_header_buffer = &mut load[..PAGE_SIZE];
@@ -142,11 +142,11 @@ pub fn load_android_simple<'a>(
BootImage::V3(ref hdr) => (hdr.ramdisk_size as usize, PAGE_SIZE),
BootImage::V4(ref hdr) => (hdr._base.ramdisk_size as usize, PAGE_SIZE),
_ => {
- efi_print!(efi_entry, "V0/V1/V2 images are not supported\n");
+ efi_println!(efi_entry, "V0/V1/V2 images are not supported");
return Err(GblEfiError::EfiAppError(EfiAppError::Unsupported));
}
};
- efi_print!(efi_entry, "init_boot image size: {}\n", generic_ramdisk_size);
+ efi_println!(efi_entry, "init_boot image size: {}", generic_ramdisk_size);
// Load and prepare various images.
let images_buffer = aligned_subslice(load, KERNEL_ALIGNMENT)?;
@@ -247,7 +247,7 @@ pub fn load_android_simple<'a>(
}
_ => {}
}
- efi_print!(efi_entry, "final bootconfig: \"{}\"\n", bootconfig_builder);
+ efi_println!(efi_entry, "final bootconfig: \"{}\"", bootconfig_builder);
ramdisk_load_curr = usize_add(ramdisk_load_curr, bootconfig_builder.config_bytes().len())?;
// Prepare FDT.
@@ -275,8 +275,8 @@ pub fn load_android_simple<'a>(
CStr::from_bytes_with_nul(b"linux,initrd-end\0").unwrap(),
&ramdisk_end.to_be_bytes(),
)?;
- efi_print!(&efi_entry, "linux,initrd-start: {:#x}\n", ramdisk_addr);
- efi_print!(&efi_entry, "linux,initrd-end: {:#x}\n", ramdisk_end);
+ efi_println!(&efi_entry, "linux,initrd-start: {:#x}", ramdisk_addr);
+ efi_println!(&efi_entry, "linux,initrd-end: {:#x}", ramdisk_end);
// Concatenate kernel commandline and add it to FDT.
let bootargs_prop = CStr::from_bytes_with_nul(b"bootargs\0").unwrap();
@@ -296,7 +296,7 @@ pub fn load_android_simple<'a>(
cmdline_payload[cmdline_payload_off..][..ele.len()].clone_from_slice(ele.as_bytes());
cmdline_payload_off += ele.len();
}
- efi_print!(&efi_entry, "final cmdline: \"{}\"\n", from_utf8(cmdline_payload).unwrap());
+ efi_println!(&efi_entry, "final cmdline: \"{}\"", from_utf8(cmdline_payload).unwrap());
// Finalize FDT to actual used size.
fdt.shrink_to_fit()?;
@@ -334,20 +334,22 @@ pub fn load_android_simple<'a>(
// flow in libgbl, which will eventually replace this demo. The demo is currently used as an
// end-to-end test for libraries developed so far.
pub fn android_boot_demo(entry: EfiEntry) -> Result<()> {
- efi_print!(entry, "Try booting as Android\n");
+ efi_println!(entry, "Try booting as Android");
// Allocate buffer for load.
let mut load_buffer = vec![0u8; 128 * 1024 * 1024]; // 128MB
let (ramdisk, fdt, kernel, remains) = load_android_simple(&entry, &mut load_buffer[..])?;
- efi_print!(
+ efi_println!(&entry, "");
+ efi_println!(
&entry,
- "\nBooting kernel @ {:#x}, ramdisk @ {:#x}, fdt @ {:#x}\n\n",
+ "Booting kernel @ {:#x}, ramdisk @ {:#x}, fdt @ {:#x}",
kernel.as_ptr() as usize,
ramdisk.as_ptr() as usize,
fdt.as_ptr() as usize
);
+ efi_println!(&entry, "");
#[cfg(target_arch = "aarch64")]
{
@@ -397,7 +399,7 @@ pub fn android_boot_demo(entry: EfiEntry) -> Result<()> {
.boot_services()
.find_first_and_open::<efi::RiscvBootProtocol>()?
.get_boot_hartid()?;
- efi_print!(entry, "riscv boot_hart_id: {}\n", boot_hart_id);
+ efi_println!(entry, "riscv boot_hart_id: {}", boot_hart_id);
let _ = exit_boot_services(entry, remains)?;
// SAFETY: We currently target at Cuttlefish emulator where images are provided valid.
unsafe { boot::riscv64::jump_linux(kernel, boot_hart_id, fdt) };
diff --git a/gbl/efi/src/fuchsia_boot.rs b/gbl/efi/src/fuchsia_boot.rs
index 6c5c37a..1faa52b 100644
--- a/gbl/efi/src/fuchsia_boot.rs
+++ b/gbl/efi/src/fuchsia_boot.rs
@@ -16,7 +16,7 @@ use crate::error::{EfiAppError, Result};
use crate::utils::{aligned_subslice, find_gpt_devices, get_efi_fdt, usize_add};
use core::fmt::Write;
use core::mem::size_of;
-use efi::{efi_print, EfiEntry};
+use efi::{efi_print, efi_println, EfiEntry};
use fdt::Fdt;
use zbi::{ZbiContainer, ZbiFlags, ZbiHeader, ZbiType, ZBI_ALIGNMENT_USIZE};
use zerocopy::{AsBytes, FromBytes, FromZeroes, Ref};
@@ -182,7 +182,7 @@ pub fn is_fuchsia_gpt(efi_entry: &EfiEntry) -> Result<()> {
// flow in libgbl, which will eventually replace this demo. The demo is currently used as an
// end-to-end test for libraries developed so far.
pub fn fuchsia_boot_demo(efi_entry: EfiEntry) -> Result<()> {
- efi_print!(efi_entry, "Try booting as Fuchsia/Zircon\n");
+ efi_println!(efi_entry, "Try booting as Fuchsia/Zircon");
// Allocate buffer for load.
let mut load_buffer = vec![0u8; 128 * 1024 * 1024]; // 128MB
diff --git a/gbl/efi/src/main.rs b/gbl/efi/src/main.rs
index 4d29141..fc34f5b 100644
--- a/gbl/efi/src/main.rs
+++ b/gbl/efi/src/main.rs
@@ -26,7 +26,7 @@ extern crate alloc;
use core::fmt::Write;
use efi::defs::EfiSystemTable;
-use efi::{efi_print, initialize};
+use efi::{efi_print, efi_println, initialize};
#[macro_use]
mod utils;
@@ -45,8 +45,10 @@ fn main(image_handle: *mut core::ffi::c_void, systab_ptr: *mut EfiSystemTable) -
// SAFETY: Called only once here upon EFI app entry.
let entry = unsafe { initialize(image_handle, systab_ptr)? };
- efi_print!(entry, "\n\n****Rust EFI Application****\n\n");
- efi_print!(entry, "Image path: {}\n", loaded_image_path(&entry)?);
+ efi_println!(entry, "****Rust EFI Application****");
+ if let Ok(v) = loaded_image_path(&entry) {
+ efi_println!(entry, "Image path: {}", v);
+ }
// For simplicity, we pick bootflow based on GPT layout.
if fuchsia_boot::is_fuchsia_gpt(&entry).is_ok() {
diff --git a/gbl/efi/src/utils.rs b/gbl/efi/src/utils.rs
index c4f0be9..490e827 100644
--- a/gbl/efi/src/utils.rs
+++ b/gbl/efi/src/utils.rs
@@ -170,8 +170,8 @@ pub fn get_device_path<'a>(
handle: DeviceHandle,
) -> Result<DevicePathText<'a>> {
let bs = entry.system_table().boot_services();
- let path = bs.open_protocol::<DevicePathProtocol>(handle).unwrap();
- let path_to_text = bs.find_first_and_open::<DevicePathToTextProtocol>().unwrap();
+ let path = bs.open_protocol::<DevicePathProtocol>(handle)?;
+ let path_to_text = bs.find_first_and_open::<DevicePathToTextProtocol>()?;
Ok(path_to_text.convert_device_path_to_text(&path, false, false)?)
}
diff --git a/gbl/libavb/BUILD.avb.bazel b/gbl/libavb/BUILD.avb.bazel
index 0e8117b..bc709a6 100644
--- a/gbl/libavb/BUILD.avb.bazel
+++ b/gbl/libavb/BUILD.avb.bazel
@@ -60,6 +60,7 @@ cc_library(
".",
"libavb/sha/",
],
+ deps = ["@gbl//libavb:gbl_deps"],
)
cc_library(
@@ -158,7 +159,10 @@ use zerocopy::{FromBytes, FromZeroes};
clang_flags = select({
"@gbl//toolchain:gbl_rust_uefi_x86_32": ["-m32"],
"//conditions:default": ["-m64"],
- }) + ["-I{}".format(LLVM_PREBUILTS_C_INCLUDE)],
+ }) + [
+ "-I{}".format(LLVM_PREBUILTS_C_INCLUDE),
+ "-nostdinc",
+ ],
header = "libavb/libavb.h",
)
diff --git a/gbl/libbootimg/BUILD b/gbl/libbootimg/BUILD
index 2a6dc85..7299022 100644
--- a/gbl/libbootimg/BUILD
+++ b/gbl/libbootimg/BUILD
@@ -71,6 +71,7 @@ use zerocopy::{AsBytes, FromBytes, FromZeroes};""",
}) + [
"-x",
"c++",
+ "-nostdinc",
],
header = "@mkbootimg//:include/bootimg/bootimg.h",
)
diff --git a/gbl/libefi/BUILD b/gbl/libefi/BUILD
index ee4ae1e..0c75174 100644
--- a/gbl/libefi/BUILD
+++ b/gbl/libefi/BUILD
@@ -76,7 +76,10 @@ use zerocopy::{AsBytes, FromBytes, FromZeroes};""",
clang_flags = select({
"@gbl//toolchain:gbl_rust_uefi_x86_32": ["-m32"],
"//conditions:default": ["-m64"],
- }) + ["-I{}".format(LLVM_PREBUILTS_C_INCLUDE)],
+ }) + [
+ "-I{}".format(LLVM_PREBUILTS_C_INCLUDE),
+ "-nostdinc",
+ ],
header = "defs/efi.h",
)
diff --git a/gbl/libefi/src/lib.rs b/gbl/libefi/src/lib.rs
index 3cf615e..874babb 100644
--- a/gbl/libefi/src/lib.rs
+++ b/gbl/libefi/src/lib.rs
@@ -644,11 +644,19 @@ impl Drop for LocatedHandles<'_> {
/// `EFI_SYSTEM_TABLE.ConOut`.
#[macro_export]
macro_rules! efi_print {
- ( $efi_entry:expr, $( $x:expr ),* ) => {
+ ( $efi_entry:expr, $( $x:expr ),* $(,)? ) => {
write!($efi_entry.system_table().con_out().unwrap(), $($x,)*).unwrap()
};
}
+#[macro_export]
+macro_rules! efi_println {
+ ( $efi_entry:expr, $( $x:expr ),* ) => {
+ efi_print!($efi_entry, $($x,)*);
+ efi_print!($efi_entry, "\r\n");
+ };
+}
+
/// Provides a builtin panic handler.
/// In the long term, to improve flexibility, consider allowing application to install a custom
/// handler into `EfiEntry` to be called here.
@@ -660,7 +668,7 @@ fn panic(panic: &PanicInfo) -> ! {
if let Some(e) = entry {
match e.system_table().con_out() {
Ok(mut con_out) => {
- let _ = write!(con_out, "Panics! {}\n", panic);
+ let _ = write!(con_out, "Panics! {}\r\n", panic);
}
_ => {}
}
diff --git a/gbl/libfdt/BUILD b/gbl/libfdt/BUILD
index e5de3cb..a2b1814 100644
--- a/gbl/libfdt/BUILD
+++ b/gbl/libfdt/BUILD
@@ -48,7 +48,10 @@ use zerocopy::{AsBytes, FromBytes, FromZeroes};
clang_flags = select({
"@gbl//toolchain:gbl_rust_uefi_x86_32": ["-m32"],
"//conditions:default": ["-m64"],
- }) + ["-I{}".format(LLVM_PREBUILTS_C_INCLUDE)],
+ }) + [
+ "-I{}".format(LLVM_PREBUILTS_C_INCLUDE),
+ "-nostdinc",
+ ],
header = "@libfdt_c//:libfdt.h",
)
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(());
}
diff --git a/gbl/libstorage/src/gpt.rs b/gbl/libstorage/src/gpt.rs
index 9767231..05b9fd2 100644
--- a/gbl/libstorage/src/gpt.rs
+++ b/gbl/libstorage/src/gpt.rs
@@ -167,12 +167,12 @@ impl<'a> Gpt<'a> {
/// * `buffer`: Buffer for creating the object. Must have a size at least
/// `Gpt::required_buffer_size(max_entries)`.
pub(crate) fn new_from_buffer(max_entries: u64, buffer: &'a mut [u8]) -> Result<Gpt<'a>> {
- let buffer = aligned_subslice(buffer, GPT_ENTRY_ALIGNMENT)?;
if max_entries > GPT_MAX_NUM_ENTRIES
|| buffer.len() < Self::required_buffer_size(max_entries)?
{
return Err(StorageError::InvalidInput);
}
+ let buffer = aligned_subslice(buffer, GPT_ENTRY_ALIGNMENT)?;
*GptInfo::from_bytes(buffer) =
GptInfo { num_valid_entries: None, max_entries: max_entries };
Self::from_existing(buffer)
@@ -431,7 +431,7 @@ mod test {
use crate::AsBlockDevice;
fn gpt_block_device(max_entries: u64, data: &[u8]) -> TestBlockDevice {
- TestBlockDevice::new_with_data(1, 512, max_entries, data)
+ TestBlockDevice::new_with_data(512, 512, max_entries, data)
}
#[test]