diff --git a/docs/raspberry_pi4.md b/docs/raspberry_pi4.md new file mode 100644 index 0000000..57eb440 --- /dev/null +++ b/docs/raspberry_pi4.md @@ -0,0 +1,64 @@ +# Raspberry Pi4 Support +MilvusVisor has support for Raspberry Pi 4 environments. +We tested "Raspberry Pi 4 Computer Model B" + +## Restricts +We currently support Only single core boot. Please add "nosmp" boot option, Otherwise Linux can boot, but MilvusVisor will not work fine. + +## How to build +To enable Raspberry Pi 4 support, you need to add `edit_dtb_memory` feature flag on building binaries of hypervisor and bootloader. + +```shell +make custom_all FEATURES=edit_dtb_memory +``` + +## How to boot +### Build U-boot +(This step assumed that your environment is Ubuntu. Otherwise, please replace the package names to suitable.) + +1. Install `gcc-aarch64-linux-gnu` and `libssl-dev` +2. Clone u-boot and move into the directory +3. `export CROSS_COMPILE=aarch64-linux-gnu-` +4. Set configuration for Raspberry Pi 4: `make rpi_4_defconfig` +5. Build: `make` +6. Copy u-boot.bin + +You can build in the docker with the below shell script(When run docker, don't forget bind directory to get the output binary :) ) + +```shell +#!/bin/sh +apt-get update +apt-get install -y build-essential bison flex gcc-aarch64-linux-gnu libssl-dev git make +git clone --depth=1 https://source.denx.de/u-boot/u-boot.git +cd u-boot +export CROSS_COMPILE=aarch64-linux-gnu- +make rpi_4_defconfig +make -j`nproc` +cp u-boot.bin /path/to/bound/ +``` + +### Download "Raspberry Pi OS (64-bit)" +Go to https://www.raspberrypi.com/software/operating-systems/ , find "Raspberry Pi OS (64-bit)" section, and download "Raspberry Pi OS with desktop" or "Raspberry Pi OS Lite". (We tested with "Raspberry Pi OS Lite") + + +### Write image and binaries + +1. Write the OS image to SD: (For example: `unxz 20XX-XX-XX-raspios-version-arm64-lite.img.xz && sudo dd if=20XX-XX-XX-raspios-version-arm64-lite.img of=/dev/mmcblk0 bs=10M status=progress`) +2. Mount SD Card: `sudo mount /dev/mmcblk0p1 /mnt` +3. Copy u-boot.bin: `sudo cp u-boot.bin /mnt/` +4. Copy MilvusVisor: `sudo cp -r /path/to/MlivusVisor/bin/EFI /mnt` +5. Modify config.txt: `sudo sed -i '/arm_64bit=1/akernel=u-boot.bin' /mnt/config.txt` +6. Modify config.txt: `sudo sed -i -e 's/console=serial0,115200 console=tty1//g' /mnt/cmdline.txt` +7. Enable UART(Optional): `sudo sed -i '/arm_64bit=1/adtoverlay=miniuart-bt\ncore_freq=250' /mnt/config.txt && sudo sed -i -e 's/quiet/console=ttyAMA0/g' /mnt/cmdline.txt` +8. Unmount: `sudo umount /mnt` + +### How to Run +1. insert SD Card into Raspberry Pi 4 +2. Connect UART(Optional) +3. Connect USB Power +4. Check DTB_ADDRESS which will printed by bootloader like `DTB_ADDRESS: 0x39EF7000` +5. Wait unti u-boot shows shell like `U-Boot>` +6. Load kernel8.img: `fatload mmc 0:1 ${kernel_addr_r} kernel8.img` +7. Set kernel_comp_size: `setenv kernel_comp_size ${filesize}` +8. Set kernel_comp_addr_r: `setenv kernel_comp_addr_r 0x3800000` +9. Boot Linux(`0x39EF7000` is DTB_ADDRESS, please change the value if different from checked value): `booti ${kernel_addr_r} - 0x39EF7000` diff --git a/src/common/src/lib.rs b/src/common/src/lib.rs index 1774ea8..5e14951 100644 --- a/src/common/src/lib.rs +++ b/src/common/src/lib.rs @@ -47,7 +47,6 @@ pub const HYPERVISOR_VIRTUAL_BASE_ADDRESS: usize = 0x7FC0000000; pub const HYPERVISOR_SERIAL_BASE_ADDRESS: usize = 0x7FD0000000; /// The memory size to allocate pub const ALLOC_SIZE: usize = 256 * 1024 * 1024; /* 256 MB */ -pub const ALLOC_SIZE_SUB: usize = 32 * 1024 * 1024; /* 32 MB */ pub const MAX_PHYSICAL_ADDRESS: usize = (1 << (52 + 1)) - 1; /* Armv8.2-A */ //pub const MAX_PHYSICAL_ADDRESS: usize = (1 << (48 + 1)) - 1;/* Armv8.0 */ pub const PAGE_SHIFT: usize = 12; diff --git a/src/hypervisor_bootloader/.cargo/config b/src/hypervisor_bootloader/.cargo/config index 387643f..e37f508 100644 --- a/src/hypervisor_bootloader/.cargo/config +++ b/src/hypervisor_bootloader/.cargo/config @@ -1,6 +1,5 @@ [build] target = "aarch64-unknown-uefi" -rustflags = ["-C", "target-feature=+v8.1a"] [unstable] build-std-features = ["compiler-builtins-mem"] diff --git a/src/hypervisor_bootloader/Cargo.toml b/src/hypervisor_bootloader/Cargo.toml index c9462f7..fd1fef6 100644 --- a/src/hypervisor_bootloader/Cargo.toml +++ b/src/hypervisor_bootloader/Cargo.toml @@ -22,8 +22,8 @@ mrs_msr_emulation = [] a64fx = ["mrs_msr_emulation"] advanced_memory_manager = [] # Bootloader uses stack style allocator tftp = [] -u_boot = [] -raspberrypi = ["u_boot"] +edit_dtb_memory = [] +u_boot = ["edit_dtb_memory"] [dependencies] common = { path = "../common" } diff --git a/src/hypervisor_bootloader/src/dtb.rs b/src/hypervisor_bootloader/src/dtb.rs index e5da827..27c8b8b 100644 --- a/src/hypervisor_bootloader/src/dtb.rs +++ b/src/hypervisor_bootloader/src/dtb.rs @@ -12,8 +12,6 @@ const FDT_NOP: u32 = 0x00000004u32.to_be(); const FDT_END: u32 = 0x00000009u32.to_be(); const TOKEN_SIZE: usize = 4; -//const NODE_NAME_SERIAL: &[u8] = "serial".as_bytes(); - const PROP_STATUS: &[u8] = "status".as_bytes(); const PROP_STATUS_OKAY: &[u8] = "okay".as_bytes(); const PROP_COMPATIBLE: &[u8] = "compatible".as_bytes(); @@ -165,7 +163,7 @@ impl DtbNode { &mut self, target_prop_name: &[u8], dtb: &DtbAnalyser, - ) -> Result, ()> { + ) -> Result, ()> { let mut pointer = self.base_pointer; Self::skip_nop(&mut pointer); if unsafe { *(pointer as *const u32) } != FDT_BEGIN_NODE { @@ -198,7 +196,7 @@ impl DtbNode { } else if Self::match_string(prop_name, PROP_SIZE_CELLS) { self.size_cells = u32::from_be(unsafe { *(pointer as *const u32) }); } else if Self::match_string(prop_name, target_prop_name) { - return Ok(Some(pointer)); + return Ok(Some((pointer, property_len))); } pointer += property_len as usize; @@ -456,25 +454,73 @@ impl DtbNode { pub fn is_status_okay(&self, dtb: &DtbAnalyser) -> Result, ()> { let mut s = self.clone(); - if let Some(p) = s.search_pointer_to_property(PROP_STATUS, dtb)? { + if let Some((p, _)) = s.search_pointer_to_property(PROP_STATUS, dtb)? { Ok(Some(Self::match_string(p, PROP_STATUS_OKAY))) } else { Ok(None) } } + pub fn get_offset(&self) -> usize { + self.address_offset + } + #[allow(dead_code)] - pub fn get_reg(&self, dtb: &DtbAnalyser) -> Result, ()> { + pub fn get_reg(&self, dtb: &DtbAnalyser, index: usize) -> Result<(usize, usize), ()> { let mut s = self.clone(); - if let Some(mut _p) = s.search_pointer_to_property(PROP_REG, dtb)? { - unimplemented!() + if let Some((mut p, property_len)) = s.search_pointer_to_property(PROP_REG, dtb)? { + let offset = index * ((self.address_cells + self.size_cells) as usize) * TOKEN_SIZE; + if offset >= property_len as usize { + return Err(()); + } + p += offset; + let mut address = 0usize; + let mut size = 0usize; + for _ in 0..self.address_cells { + address <<= u32::BITS; + address |= u32::from_be(unsafe { *(p as *const u32) }) as usize; + p += TOKEN_SIZE; + } + for _ in 0..self.size_cells { + size <<= u32::BITS; + size |= u32::from_be(unsafe { *(p as *const u32) }) as usize; + p += TOKEN_SIZE; + } + return Ok((address, size)); } else { - Ok(None) + Err(()) } } - pub fn get_offset(&self) -> usize { - self.address_offset + #[allow(dead_code)] + pub fn edit_reg( + &self, + dtb: &DtbAnalyser, + index: usize, + address: usize, + size: usize, + ) -> Result<(), ()> { + let mut s = self.clone(); + if let Some((mut p, property_len)) = s.search_pointer_to_property(PROP_REG, dtb)? { + let offset = index * ((self.address_cells + self.size_cells) as usize) * TOKEN_SIZE; + if offset >= property_len as usize { + return Err(()); + } + p += offset; + for i in (0..(self.address_cells as usize)).rev() { + let a = ((address >> (u32::BITS as usize * i)) & (u32::MAX as usize)) as u32; + unsafe { core::ptr::write_volatile(p as *mut u32, a.to_be()) }; + p += TOKEN_SIZE; + } + for i in (0..(self.size_cells as usize)).rev() { + let a = ((size >> (u32::BITS as usize * i)) & (u32::MAX as usize)) as u32; + unsafe { core::ptr::write_volatile(p as *mut u32, a.to_be()) }; + p += TOKEN_SIZE; + } + Ok(()) + } else { + Err(()) + } } } @@ -567,118 +613,3 @@ impl DtbAnalyser { self.struct_block_size + self.struct_block_address } } - -#[cfg(feature = "raspberrypi")] -pub fn add_new_memory_reservation_entry_to_dtb( - original_base_address: usize, - new_base_address: usize, - new_size: usize, - reserved_address: usize, - reserved_size: usize, -) -> Result<(), ()> { - let mut total_new_size = 0; - let original_dtb_header = unsafe { &*(original_base_address as *const DtbHeader) }; - - let new_dtb_header = unsafe { &mut *(new_base_address as *mut DtbHeader) }; - total_new_size += core::mem::size_of::(); - if new_size < total_new_size { - return Err(()); - } - - new_dtb_header.magic = original_dtb_header.magic; - new_dtb_header.version = original_dtb_header.version; - new_dtb_header.last_comp_version = original_dtb_header.last_comp_version; - new_dtb_header.boot_cpuid_phys = original_dtb_header.boot_cpuid_phys; - new_dtb_header.size_dt_struct = original_dtb_header.size_dt_struct; - new_dtb_header.size_dt_strings = original_dtb_header.size_dt_strings; - - // copy memory reservation block and add new reservation entry - let original_reservation_block_address = - original_base_address + u32::from_be(original_dtb_header.off_mem_rsv_map) as usize; - let new_reservation_block_address = new_base_address + total_new_size; - let mut pointer = original_reservation_block_address; - loop { - let address = unsafe { *(pointer as *const u64) }; - pointer += core::mem::size_of::(); - let size = unsafe { *(pointer as *const u64) }; - pointer += core::mem::size_of::(); - if address == 0 && size == 0 { - break; - } - } - // original reservation block size without terminal entry - let reservation_block_section_size = - pointer - original_reservation_block_address - core::mem::size_of::() * 2; - // new total size will be the size of original reservation block + new entry + terminal entry - total_new_size += reservation_block_section_size + core::mem::size_of::() * 4; - if new_size < total_new_size { - return Err(()); - } - unsafe { - // copy original mrb to new mrb - core::ptr::copy_nonoverlapping( - original_reservation_block_address as *const u8, - new_reservation_block_address as *mut u8, - reservation_block_section_size, - ); - } - unsafe { - // write new entries - let new_reservation_entry_address_filed_address = - new_reservation_block_address + reservation_block_section_size; - let new_reservation_entry_size_field_address = new_reservation_block_address - + reservation_block_section_size - + core::mem::size_of::(); - *(new_reservation_entry_address_filed_address as *mut usize) = reserved_address.to_be(); - *(new_reservation_entry_size_field_address as *mut usize) = reserved_size.to_be(); - let new_termianal_entry_address = new_reservation_block_address - + reservation_block_section_size - + core::mem::size_of::() * 2; - *(new_termianal_entry_address as *mut usize) = 0; - *((new_termianal_entry_address + core::mem::size_of::()) as *mut usize) = 0; - } - - // copy struct section - let new_struct_base_address = new_base_address + total_new_size; - let original_struct_base_address = - original_base_address + u32::from_be(original_dtb_header.off_dt_struct) as usize; - let struct_section_size = u32::from_be(original_dtb_header.size_dt_struct) as usize; - total_new_size += struct_section_size; - if total_new_size > new_size { - return Err(()); - } - unsafe { - core::ptr::copy_nonoverlapping( - original_struct_base_address as *const u8, - new_struct_base_address as *mut u8, - struct_section_size, - ); - } - - // copy string section - let new_string_section_address = new_base_address + total_new_size; - let original_string_section_address = - original_base_address + u32::from_be(original_dtb_header.off_dt_strings) as usize; - let string_section_size = u32::from_be(original_dtb_header.size_dt_strings) as usize; - total_new_size += string_section_size; - if total_new_size > new_size { - return Err(()); - } - unsafe { - core::ptr::copy_nonoverlapping( - original_string_section_address as *const u8, - new_string_section_address as *mut u8, - u32::from_be(original_dtb_header.size_dt_strings) as usize, - ); - } - - // edit header - new_dtb_header.off_mem_rsv_map = - ((new_reservation_block_address - new_base_address) as u32).to_be(); - new_dtb_header.off_dt_struct = ((new_struct_base_address - new_base_address) as u32).to_be(); - new_dtb_header.off_dt_strings = - ((new_string_section_address - new_base_address) as u32).to_be(); - new_dtb_header.total_size = (total_new_size as u32).to_be(); - - Ok(()) -} diff --git a/src/hypervisor_bootloader/src/main.rs b/src/hypervisor_bootloader/src/main.rs index a79bdd7..3c2afd9 100644 --- a/src/hypervisor_bootloader/src/main.rs +++ b/src/hypervisor_bootloader/src/main.rs @@ -25,15 +25,13 @@ use common::*; #[cfg(not(feature = "tftp"))] use uefi::file; -#[cfg(feature = "tftp")] -use uefi::pxe; use uefi::{ - boot_service, EfiConfigurationTable, EfiHandle, EfiStatus, EfiSystemTable, - EFI_ACPI_20_TABLE_GUID, EFI_DTB_TABLE_GUID, + boot_service, EfiConfigurationTable, EfiHandle, EfiSystemTable, EFI_ACPI_20_TABLE_GUID, + EFI_DTB_TABLE_GUID, }; +#[cfg(feature = "tftp")] +use uefi::{pxe, EfiStatus}; -#[cfg(feature = "raspberrypi")] -use crate::dtb::add_new_memory_reservation_entry_to_dtb; use core::arch::asm; use core::mem::{transmute, MaybeUninit}; @@ -48,8 +46,6 @@ static mut ACPI_20_TABLE_ADDRESS: Option = None; static mut DTB_ADDRESS: Option = None; static mut MEMORY_ALLOCATOR: MaybeUninit = MaybeUninit::uninit(); #[cfg(feature = "u_boot")] -static mut MEMORY_ALLOCATOR_SUB: MaybeUninit = MaybeUninit::uninit(); -#[cfg(feature = "u_boot")] static mut U_BOOT_ADDR: usize = 0x0; #[cfg(feature = "tftp")] static mut PXE_PROTOCOL: *const pxe::EfiPxeBaseCodeProtocol = core::ptr::null(); @@ -82,8 +78,6 @@ extern "C" fn efi_main(image_handle: EfiHandle, system_table: *mut EfiSystemTabl assert_eq!(get_current_el() >> 2, 2, "Expected CurrentEL is EL2"); let allocated_memory_address = init_memory_pool(); - #[cfg(feature = "u_boot")] - let allocated_memory_address_sub = init_sub_memory_pool(); #[cfg(debug_assertions)] dump_memory_map(); @@ -94,15 +88,7 @@ extern "C" fn efi_main(image_handle: EfiHandle, system_table: *mut EfiSystemTabl paging::dump_page_table(); paging::setup_stage_2_translation().expect("Failed to setup Stage2 Paging"); - map_memory_pool(allocated_memory_address, ALLOC_SIZE, false); - #[cfg(feature = "u_boot")] - { - map_memory_pool(allocated_memory_address_sub, ALLOC_SIZE_SUB, true); - let u_boot_addr = load_u_boot(); - unsafe { - U_BOOT_ADDR = u_boot_addr; - } - } + map_memory_pool(allocated_memory_address, ALLOC_SIZE); detect_acpi_and_dtb(); @@ -142,6 +128,19 @@ extern "C" fn efi_main(image_handle: EfiHandle, system_table: *mut EfiSystemTabl + (STACK_PAGES << PAGE_SHIFT); let memory_save_list = create_memory_save_list(); + #[cfg(feature = "u_boot")] + { + /* Load U-BOOT for EL1 (This process must be called after `create_memory_save_list`) */ + let u_boot_address = load_u_boot(); + unsafe { U_BOOT_ADDR = u_boot_address }; + } + #[cfg(feature = "edit_dtb_memory")] + if let Some(dtb_address) = unsafe { DTB_ADDRESS } { + /* Edit DTB's memory region */ + edit_dtb_memory_size(dtb_address, allocated_memory_address); + println!("DTB_ADDRESS: {:#X}", dtb_address); + } + println!("Call the hypervisor(Entry Point: {:#X})", entry_point); let mut system_info = SystemInformation { @@ -158,24 +157,6 @@ extern "C" fn efi_main(image_handle: EfiHandle, system_table: *mut EfiSystemTabl }; unsafe { (transmute::(entry_point))(&mut system_info) }; - #[cfg(feature = "raspberrypi")] - { - let dtb_buffer_size = (4 * 1024) << PAGE_SHIFT; - let new_dtb_addr = allocate_sub_memory(dtb_buffer_size >> PAGE_SHIFT, None) - .expect("Failed to alloc new dtb area"); - add_new_memory_reservation_entry_to_dtb( - unsafe { DTB_ADDRESS.expect("No DTB found") }, - new_dtb_addr, - dtb_buffer_size, - allocated_memory_address, - ALLOC_SIZE, - ) - .expect("failed to edit dtb"); - unsafe { - DTB_ADDRESS = Some(new_dtb_addr); - } - } - /* Do not call allocate_memory/free_memory from here */ println!("Setup EL1"); @@ -251,39 +232,6 @@ fn init_memory_pool() -> usize { return allocated_address; } -/// Allocate memory and setup [`MEMORY_ALLOCATOR_SUB`] -/// -/// This function allocates [`ALLOC_SIZE_SUB`] and then, set it into [`MEMORY_ALLOCATOR_SUB`] -/// The attribute of allocated memory area will be changed to EfiUnusableMemory -/// -/// # Panics -/// If the allocation is failed, this function will panic. -/// -/// # Result -/// Returns the start_address allocated -#[cfg(feature = "u_boot")] -fn init_sub_memory_pool() -> usize { - let allocate_pages = ALLOC_SIZE_SUB >> PAGE_SHIFT; - let allocated_address = boot_service::alloc_highest_memory( - unsafe { (*SYSTEM_TABLE).efi_boot_services }, - allocate_pages, - MAX_PHYSICAL_ADDRESS, - ) - .expect("Failed to init memory pool"); - println!( - "Allocated {:#X} ~ {:#X} for sub", - allocated_address, - allocated_address + ALLOC_SIZE_SUB - ); - //unsafe { MEMORY_ALLOCATOR.write(MemoryAllocator::create(allocated_address, ALLOC_SIZE)) }; - unsafe { - MEMORY_ALLOCATOR_SUB - .assume_init_mut() - .init(allocated_address, ALLOC_SIZE_SUB) - }; - return allocated_address; -} - /// Map allocated memory area into TTBR0_EL2 and set up not to be accessible from EL1/EL0 /// /// This function map memory allocated by [`init_memory_pool`] into new TTBR0_EL2. @@ -293,11 +241,11 @@ fn init_sub_memory_pool() -> usize { /// /// # Arguments /// * `allocated_memory_address` - base address of allocated memory by [`init_memory_pool`] -/// * `el01_accessible` - allow EL1/EL0 to access this area +/// * `alloc_size` - allocated memory size /// /// # Panics /// If the mapping into new TTBR0_EL2 or VTTBR_EL2 is failed, this function will panic. -fn map_memory_pool(allocated_memory_address: usize, alloc_size: usize, el01_accessible: bool) { +fn map_memory_pool(allocated_memory_address: usize, alloc_size: usize) { paging::map_address( allocated_memory_address, allocated_memory_address, @@ -310,11 +258,9 @@ fn map_memory_pool(allocated_memory_address: usize, alloc_size: usize, el01_acce .expect("Failed to map allocated memory"); /*paging::unmap_address_from_vttbr_el2(b_s, allocated_memory_address, ALLOC_SIZE) .expect("Failed to unmap allocated address.");*/ - if !el01_accessible { - let dummy_page = allocate_memory(1, None).expect("Failed to alloc dummy page"); - paging::map_dummy_page_into_vttbr_el2(allocated_memory_address, alloc_size, dummy_page) - .expect("Failed to map dummy page"); - } + let dummy_page = allocate_memory(1, None).expect("Failed to alloc dummy page"); + paging::map_dummy_page_into_vttbr_el2(allocated_memory_address, alloc_size, dummy_page) + .expect("Failed to map dummy page"); } /// Allocate memory from memory pool @@ -333,18 +279,6 @@ pub fn allocate_memory(pages: usize, align: Option) -> Result, -) -> Result { - unsafe { - MEMORY_ALLOCATOR_SUB - .assume_init_mut() - .allocate(pages << PAGE_SHIFT, align.unwrap_or(PAGE_SHIFT)) - } -} - /// Free memory to memory pool /// /// # Arguments @@ -384,24 +318,23 @@ fn load_u_boot() -> usize { let u_boot_info = file::get_file_info(u_boot_protocol).expect("Failed to get u-boot file information"); let pages = (((u_boot_info.file_size - 1) & PAGE_MASK) >> PAGE_SHIFT) + 1; - println!( - "u_boot info: {:#X} {:#X} {:#X} {:#X}", - u_boot_info.size, u_boot_info.file_size, u_boot_info.physical_size, pages - ); - // U-Boot must be loaded at a 4K aligned address let physical_base_address = - allocate_sub_memory(pages, Some(12)).expect("Failed to allocate memory for hypervisor"); + boot_service::alloc_highest_memory(b_s, pages, MAX_PHYSICAL_ADDRESS) + .expect("Failed to allocate memory for u-boot"); let read_size = file::read( u_boot_protocol, physical_base_address as *mut u8, u_boot_info.file_size, ) - .expect("Failed to read hypervisor segments"); + .expect("Failed to read u-boot"); if read_size != u_boot_info.file_size { - panic!("read failure? {}, {}", read_size, u_boot_info.file_size); + panic!( + "Failed to read u-boot: Expected {:#X} bytes, but actually {:#X} bytes", + u_boot_info.file_size, read_size + ); } if let Err(e) = file::close_file(u_boot_protocol) { @@ -791,6 +724,39 @@ fn create_memory_save_list() -> &'static mut [MemorySaveListEntry] { return list; } +#[cfg(feature = "edit_dtb_memory")] +fn edit_dtb_memory_size(dtb_address: usize, allocated_memory_address: usize) { + let dtb_analyser = dtb::DtbAnalyser::new(dtb_address).expect("Invalid DTB"); + let mut dtb_search_holder = dtb_analyser.get_root_node().get_search_holder().unwrap(); + let Ok(Some(memory_node)) = + dtb_search_holder.search_next_device_by_node_name(b"memory", &dtb_analyser) + else { + println!("Memory region is not found."); + return; + }; + for i in 0.. { + let Ok((address, size)) = memory_node.get_reg(&dtb_analyser, i) else { + println!("Failed to find memory region which contaions allocated memory."); + return; + }; + if address <= allocated_memory_address && allocated_memory_address <= (address + size) { + /* Found region */ + println!( + "Shrink memory region {:#X} ~ {:#X} to {:#X} ~ {:#X}", + address, + address + size, + address, + allocated_memory_address + ); + let new_size = allocated_memory_address - address; + memory_node + .edit_reg(&dtb_analyser, i, address, new_size) + .expect("Failed to edit reg"); + break; + } + } +} + #[allow(dead_code)] fn dump_memory_map() { let b_s = unsafe { (*SYSTEM_TABLE).efi_boot_services }; @@ -1092,9 +1058,6 @@ fn exit_bootloader() -> ! { asm!("br {x}", x = in(reg) U_BOOT_ADDR, in("x0") DTB_ADDRESS.unwrap_or(0), - in("x1") 0, - in("x2") 0, - in("x3") 0, options(noreturn) ) }; @@ -1118,7 +1081,7 @@ fn exit_bootloader() -> ! { unsafe { ((*(*SYSTEM_TABLE).efi_boot_services).exit)( IMAGE_HANDLE, - EfiStatus::EfiSuccess, + uefi::EfiStatus::EfiSuccess, 0, core::ptr::null(), ); diff --git a/src/hypervisor_bootloader/src/serial_port.rs b/src/hypervisor_bootloader/src/serial_port.rs index c979285..654abc5 100644 --- a/src/hypervisor_bootloader/src/serial_port.rs +++ b/src/hypervisor_bootloader/src/serial_port.rs @@ -63,7 +63,6 @@ fn try_to_get_serial_info_from_dtb(dtb_address: usize) -> Option println!("Device is not okay."); continue; } - let address = node.get_offset(); return Some(SerialPortInfo { physical_address: address, diff --git a/src/hypervisor_bootloader/src/smmu.rs b/src/hypervisor_bootloader/src/smmu.rs index 79637f4..1950013 100644 --- a/src/hypervisor_bootloader/src/smmu.rs +++ b/src/hypervisor_bootloader/src/smmu.rs @@ -49,7 +49,10 @@ pub fn detect_smmu(acpi_address: usize) -> Option { return None; } }; - let Some(smmu_v3) = iort.get_smmu_v3_information() else { println!("SMMUv3 is not found"); return None;}; + let Some(smmu_v3) = iort.get_smmu_v3_information() else { + println!("SMMUv3 is not found"); + return None; + }; let base_address = smmu_v3.base_address as usize; println!("SMMUv3 BaseAddress: {:#X}", base_address); diff --git a/src/hypervisor_kernel/.cargo/config b/src/hypervisor_kernel/.cargo/config index 99bd7c9..fde2e9d 100644 --- a/src/hypervisor_kernel/.cargo/config +++ b/src/hypervisor_kernel/.cargo/config @@ -1,6 +1,6 @@ [build] target = "aarch64-unknown-none" -rustflags = ["-C", "target-feature=+v8.1a", "-C", "link-arg=-Thypervisor_kernel/config/linkerscript.ld"] +rustflags = ["-C", "link-arg=-Thypervisor_kernel/config/linkerscript.ld"] [unstable] build-std = ["core", "compiler_builtins"] diff --git a/src/hypervisor_kernel/Cargo.toml b/src/hypervisor_kernel/Cargo.toml index fc2aa9b..4bdebd4 100644 --- a/src/hypervisor_kernel/Cargo.toml +++ b/src/hypervisor_kernel/Cargo.toml @@ -23,8 +23,8 @@ mrs_msr_emulation = [] a64fx = ["mrs_msr_emulation"] advanced_memory_manager = ["common/advanced_memory_manager"] tftp = [] -u_boot = [] -raspberrypi = ["u_boot"] +edit_dtb_memory = [] +u_boot = ["edit_dtb_memory"] [dependencies] common = { path = "../common" }