blob: 1767e243951873548b4b629856534a66c8102d66 [file] [log] [blame]
// Copyright 2022, The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! pVM firmware.
#![no_main]
#![no_std]
#![feature(default_alloc_error_handler)]
#![feature(ptr_const_cast)] // Stabilized in 1.65.0
mod avb;
mod config;
mod entry;
mod exceptions;
mod fdt;
mod heap;
mod helpers;
mod memory;
mod mmio_guard;
mod mmu;
mod pci;
mod smccc;
use crate::{avb::PUBLIC_KEY, entry::RebootReason, memory::MemoryTracker, pci::PciInfo};
use ::avb::verify_image;
use dice::bcc;
use libfdt::Fdt;
use log::{debug, error, info, trace};
fn main(
fdt: &Fdt,
signed_kernel: &[u8],
ramdisk: Option<&[u8]>,
bcc: &bcc::Handover,
memory: &mut MemoryTracker,
) -> Result<(), RebootReason> {
info!("pVM firmware");
debug!("FDT: {:?}", fdt as *const libfdt::Fdt);
debug!("Signed kernel: {:?} ({:#x} bytes)", signed_kernel.as_ptr(), signed_kernel.len());
if let Some(rd) = ramdisk {
debug!("Ramdisk: {:?} ({:#x} bytes)", rd.as_ptr(), rd.len());
} else {
debug!("Ramdisk: None");
}
trace!("BCC: {bcc:x?}");
// Set up PCI bus for VirtIO devices.
let pci_info = PciInfo::from_fdt(fdt)?;
info!("PCI: {:#x?}", pci_info);
pci_info.map(memory)?;
verify_image(signed_kernel, PUBLIC_KEY).map_err(|e| {
error!("Failed to verify the payload: {e}");
RebootReason::PayloadVerificationError
})?;
info!("Starting payload...");
Ok(())
}