diff --git a/Makefile b/Makefile index 76b2349..91230c8 100644 --- a/Makefile +++ b/Makefile @@ -47,3 +47,6 @@ build: clean defconfig all qemu-run: qemu-system-riscv64 -m 128M -serial mon:stdio -bios $(SBI) -nographic -machine virt -nographic -machine virt -device virtio-blk-pci,drive=disk0 -drive id=disk0,if=none,format=raw,file=$(DISK) + +qemu-run-ramdisknotload: + qemu-system-riscv64 -m 128M -serial mon:stdio -bios $(SBI) -nographic -machine virt -nographic -machine virt -device virtio-blk-pci,drive=disk0 -drive id=disk0,if=none,format=raw,file=$(DISK) -device loader,file=$(RAMDISK_CPIO),addr=0x84000000 diff --git a/configs/platforms/riscv64-qemu-virt.toml b/configs/platforms/riscv64-qemu-virt.toml index f272f51..6697ac6 100644 --- a/configs/platforms/riscv64-qemu-virt.toml +++ b/configs/platforms/riscv64-qemu-virt.toml @@ -75,3 +75,22 @@ timer-frequency = 10_000_000 # uint # }; # RTC (goldfish) Address rtc-paddr = 0x10_1000 # uint + +# +# Boot configs +# +[boot] +# Whether to use ramdisk +# If ramdisk has already been configured in dtb and no assistance from ArceBoot is needed, please set it to false +# If ArceBoot needs to boot from ramdisk, please set it to true if the next stage boot file that complies with the UEFI standard is saved in ramdisk +use-ramdisk = true +# Does this program need to load the ramdisk +# If the ramdisk file is located in the storage medium and needs to be loaded into memory by Arceboot, set it to true +load-ramdisk = true +# Ramdisk file path, If 'use-ramdisk & load-ramdisk' is false, this item will not be enabled +ramdisk-file = "/ramdisk.cpio" +# Ramdisk location +# If 'use-ramdisk & load-ramdisk' is true, Arceboot will load ramdisk to memory(The address of load is random) +# If 'load-ramdisk' is false, Arceboot will read ramdisk from [ramdisk-start, ramdisk-start + ramdisk-size] +ramdisk-start = 0x84000000 +ramdisk-size = 0x400 diff --git a/scripts/test/disk.sh b/scripts/test/disk.sh index ac119fa..0291141 100755 --- a/scripts/test/disk.sh +++ b/scripts/test/disk.sh @@ -7,6 +7,9 @@ print_info() { printf "\033[36m%s\033[0m\n" "$1" } +print_info "开始创建 ramdisk 文件" +bash scripts/test/ramdisk_cpio.sh + print_info "开始执行 virtio-block 类型的 disk 创建脚本" print_info "此为 FAT32 文件系统镜像, 只含有一个 arceboot.txt 文件, 用于测试 Arceboot" print_info "即将在当前目录执行创建 -------->" @@ -18,6 +21,7 @@ mkdir temp sudo mount -o loop disk.img temp sudo mkdir -p temp/test sudo touch temp/test/arceboot.txt +sudo cp ramdisk.cpio temp echo "This is a test file for Arceboot." | sudo tee temp/test/arceboot.txt > /dev/null sudo umount temp rm -rf temp diff --git a/src/dtb.rs b/src/dtb.rs index 2dc4249..244e5d5 100644 --- a/src/dtb.rs +++ b/src/dtb.rs @@ -1,41 +1,6 @@ -// DTB -/* Examples -1. Parse and print the initial DTB structure -parser.dump_all(); - -// 2. Modify "bootargs" with a SHORTER value (in-place modification) -let truly_shorter_bootargs = "test"; // Length 4. Old allocated was 12 bytes. -if parser.modify_property("/chosen", "bootargs", truly_shorter_bootargs) { - parser.dump_all(); -} else { - error!("Failed to modify bootargs."); -} - -// 3. Modify "bootargs" with a LONGER value (triggers reallocation) -let longer_bootargs = "console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootwait custom_arg=hello_world_long_string"; -if parser.modify_property("/chosen", "bootargs", longer_bootargs) { - parser.dump_all(); -} else { - error!("Failed to modify bootargs."); -} - -// 4. Try to modify a non-existent property -if !parser.modify_property("/chosen", "non-existent-prop", "test") { - error!("Correctly failed to modify non-existent-prop."); -} - -// 5. Try to modify a property in a non-existent node -if !parser.modify_property("/nonexistent/node", "prop", "value") { - error!("Correctly failed to modify property in non-existent node."); -} -*/ - -extern crate alloc; - use alloc::string::String; use alloc::vec; use alloc::vec::Vec; -use core::fmt::{self, Write}; use core::mem; use core::ptr; use core::str; @@ -49,14 +14,6 @@ const FDT_MAGIC: u32 = 0xd00dfeed; pub static mut GLOBAL_NOW_DTB_ADDRESS: usize = 0; -struct Printer; -impl Write for Printer { - fn write_str(&mut self, s: &str) -> fmt::Result { - axlog::ax_print!("{}", s); - Ok(()) - } -} - struct DtbMemory<'a> { data: &'a mut [u8], } @@ -75,7 +32,7 @@ impl<'a> DtbMemory<'a> { fn read_u32(&self, offset: usize) -> Option { if !self.check_bounds(offset, 4) { error!( - "read_u32 out of bounds: offset={}, len=4, size={}", + "read_u32 out of bounds: offset={}, len=4, size={} (It won't panic. Try adjusting and then retry)", offset, self.data.len() ); @@ -88,7 +45,7 @@ impl<'a> DtbMemory<'a> { fn write_u32(&mut self, offset: usize, value: u32) -> bool { if !self.check_bounds(offset, 4) { error!( - "write_u32 out of bounds: offset={}, len=4, size={}", + "write_u32 out of bounds: offset={}, len=4, size={} (It won't panic. Try adjusting and then retry)", offset, self.data.len() ); @@ -101,7 +58,7 @@ impl<'a> DtbMemory<'a> { fn read_bytes(&self, offset: usize, len: usize) -> Option<&[u8]> { if !self.check_bounds(offset, len) { error!( - "read_bytes out of bounds: offset={}, len={}, size={}", + "read_bytes out of bounds: offset={}, len={}, size={} (It won't panic. Try adjusting and then retry)", offset, len, self.data.len() @@ -114,7 +71,7 @@ impl<'a> DtbMemory<'a> { fn write_bytes(&mut self, offset: usize, data: &[u8]) -> bool { if !self.check_bounds(offset, data.len()) { error!( - "write_bytes out of bounds: offset={}, len={}, size={}", + "write_bytes out of bounds: offset={}, len={}, size={} (It won't panic. Try adjusting and then retry)", offset, data.len(), self.data.len() @@ -130,7 +87,7 @@ impl<'a> DtbMemory<'a> { while len < 256 { if !self.check_bounds(offset + len, 1) { error!( - "read_str out of bounds while searching for null terminator: offset={}, len=1, size={}", + "read_str out of bounds while searching for null terminator: offset={}, len=1, size={} (It won't panic. Try adjusting and then retry)", offset + len, self.data.len() ); @@ -409,7 +366,7 @@ impl DtbParser { let mut current_path_segments: Vec = Vec::new(); let mut depth = 0; - let mut _node_start_offset: Option = None;// will get warning if without '_' + let mut _node_start_offset: Option = None; // will get warning if without '_' while let Some(token) = unsafe { self.next_token() } { match token { @@ -494,6 +451,289 @@ impl DtbParser { None } + /// Finds the insertion point for new data within a node. + fn find_insertion_point_in_node(&mut self, node_path: &str) -> Option { + let Some(location) = self.find_node(node_path) else { + error!("Parent node '{}' not found for insertion.", node_path); + return None; + }; + + let insertion_point_word_offset = location.end_offset - 1; + let insertion_point_byte_offset = + self.header.off_dt_struct() as usize + insertion_point_word_offset * 4; + + Some(insertion_point_byte_offset) + } + + /// Finds or adds a string to the string table and returns its offset. + fn get_string_offset(&mut self, s: &str) -> Option { + let current_strings_offset = self.header.off_dt_strings() as usize; + let current_strings_size = self.header.size_dt_strings() as usize; + + let mem_view_ro = self.get_memory_view_read_only(); + + // Search for existing string + let mut offset = 0; + while offset < current_strings_size { + if let Some(existing_str) = mem_view_ro.read_str(current_strings_offset + offset) { + if existing_str == s { + return Some(offset as u32); + } + offset += existing_str.len() + 1; // Include null terminator + } else { + error!("get_string_offset: Malformed string table."); + return None; + } + } + + // String not found, append it + let string_to_add = s.as_bytes(); + let string_len_with_null = string_to_add.len() + 1; + let aligned_string_len = (string_len_with_null + 3) & !3; + + let new_strings_size = current_strings_size + aligned_string_len; + let total_size_increase = aligned_string_len; + + // Reallocate DTB to accommodate new string + let old_total_size = self.header.totalsize() as usize; + let new_total_size = old_total_size + total_size_increase; + + let mut new_dtb_data = vec![0u8; new_total_size]; + let mut new_mem_view = DtbMemory::new(&mut new_dtb_data[..]); + + // Copy everything before the string table + new_mem_view.write_bytes(0, &self.dtb_data[0..current_strings_offset]); + + // Copy the old string table to its new offset + let new_strings_start_byte_offset = current_strings_offset; + new_mem_view.write_bytes( + new_strings_start_byte_offset, + &self.dtb_data[current_strings_offset..current_strings_offset + current_strings_size], + ); + + // Add the new string + let new_string_offset_in_table = current_strings_size; + new_mem_view.write_bytes( + new_strings_start_byte_offset + new_string_offset_in_table, + string_to_add, + ); + new_mem_view.write_u32( + new_strings_start_byte_offset + new_string_offset_in_table + string_to_add.len(), + 0, + ); + + // Update header + let mut new_header = FdtHeader::read(&new_mem_view).unwrap(); + new_header.set_totalsize(new_total_size as u32); + new_header.set_size_dt_strings(new_strings_size as u32); + new_header.write(&mut new_mem_view); + + self.dtb_data = new_dtb_data; + self.header = new_header; + + debug!( + "Added string '{}' to string table. New string table size: {} bytes", + s, + self.header.size_dt_strings() + ); + + Some(new_string_offset_in_table as u32) + } + + /// Adds a new node under a specified parent node. + /// + /// # Arguments + /// * `parent_path` - The full path to the parent node (e.g., "/chosen"). + /// * `new_node_name` - The name of the new node (e.g., "my-new-device"). + /// + /// Returns `true` on success, `false` on failure. + pub fn add_node(&mut self, parent_path: &str, new_node_name: &str) -> bool { + let Some(insertion_byte_offset) = self.find_insertion_point_in_node(parent_path) else { + error!( + "Could not find insertion point for node '{}' under parent '{}'.", + new_node_name, parent_path + ); + return false; + }; + + // Add node name to string table + let Some(_nameoff) = self.get_string_offset(new_node_name) else { + error!( + "Failed to add node name '{}' to string table.", + new_node_name + ); + return false; + }; + + // Construct the new node data + let node_name_bytes = new_node_name.as_bytes(); + let node_name_len_with_null = node_name_bytes.len() + 1; + let aligned_node_name_len = (node_name_len_with_null + 3) & !3; + + let node_data_len = 4 + aligned_node_name_len + 4; + + let mut new_node_bytes = Vec::with_capacity(node_data_len); + new_node_bytes.extend_from_slice(&FDT_BEGIN_NODE.to_be_bytes()); + new_node_bytes.extend_from_slice(node_name_bytes); + new_node_bytes.push(0); + while new_node_bytes.len() % 4 != 0 { + new_node_bytes.push(0); + } + new_node_bytes.extend_from_slice(&FDT_END_NODE.to_be_bytes()); + + let total_size_increase = new_node_bytes.len(); + let old_total_size = self.header.totalsize() as usize; + let new_total_size = old_total_size + total_size_increase; + + let mut new_dtb_data = vec![0u8; new_total_size]; + let mut new_mem_view = DtbMemory::new(&mut new_dtb_data[..]); + + let old_off_dt_struct = self.header.off_dt_struct() as usize; + let old_size_dt_struct = self.header.size_dt_struct() as usize; + let old_off_dt_strings = self.header.off_dt_strings() as usize; + let old_size_dt_strings = self.header.size_dt_strings() as usize; + + // 1. Copy data BEFORE insertion point (header, rsvmap, struct block up to insertion) + new_mem_view.write_bytes(0, &self.dtb_data[0..insertion_byte_offset]); + + // 2. Insert new node data + new_mem_view.write_bytes(insertion_byte_offset, &new_node_bytes); + + // 3. Copy data AFTER insertion point, adjusting offsets + let old_struct_end_byte_offset = old_off_dt_struct + old_size_dt_struct; + + new_mem_view.write_bytes( + insertion_byte_offset + total_size_increase, + &self.dtb_data[insertion_byte_offset..old_struct_end_byte_offset], + ); + + // 4. Copy string table, adjusting its offset + let new_strings_start_byte_offset = old_off_dt_strings + total_size_increase; + new_mem_view.write_bytes( + new_strings_start_byte_offset, + &self.dtb_data[old_off_dt_strings..old_off_dt_strings + old_size_dt_strings], + ); + + // 5. Update the header in the new DTB data + let mut new_header = FdtHeader::read(&new_mem_view).unwrap(); + new_header.set_totalsize(new_total_size as u32); + new_header.set_size_dt_struct(old_size_dt_struct as u32 + total_size_increase as u32); + new_header.set_off_dt_strings(new_strings_start_byte_offset as u32); + new_header.write(&mut new_mem_view); + + // 6. Replace the old dtb_data with the new one + self.dtb_data = new_dtb_data; + self.header = new_header; + + debug!( + "Added node '{}' under '{}'. New total size: {} bytes", + new_node_name, + parent_path, + self.dtb_data.len() + ); + + true + } + + /// Adds a new property to a specified node. + /// + /// # Arguments + /// * `node_path` - The full path to the node where the property will be added. + /// * `prop_name` - The name of the new property. + /// * `prop_value` - The value of the new property (as a byte slice). + /// + /// Returns `true` on success, `false` on failure. + pub fn add_property(&mut self, node_path: &str, prop_name: &str, prop_value: &[u8]) -> bool { + let Some(node_location) = self.find_node(node_path) else { + error!( + "Node '{}' not found for adding property '{}'.", + node_path, prop_name + ); + return false; + }; + + let insertion_point_word_offset = node_location.end_offset - 1; + let insertion_byte_offset = + self.header.off_dt_struct() as usize + insertion_point_word_offset * 4; + + // Add property name to string table + let Some(nameoff) = self.get_string_offset(prop_name) else { + error!( + "Failed to add property name '{}' to string table.", + prop_name + ); + return false; + }; + + // Construct the new property data + let prop_value_len = prop_value.len(); + let aligned_prop_value_len = (prop_value_len + 3) & !3; + + let prop_data_len = 4 + 4 + 4 + aligned_prop_value_len; + + let mut new_prop_bytes = Vec::with_capacity(prop_data_len); + new_prop_bytes.extend_from_slice(&FDT_PROP.to_be_bytes()); + new_prop_bytes.extend_from_slice(&(prop_value_len as u32).to_be_bytes()); + new_prop_bytes.extend_from_slice(&nameoff.to_be_bytes()); + new_prop_bytes.extend_from_slice(prop_value); + while new_prop_bytes.len() % 4 != 0 { + new_prop_bytes.push(0); + } + + let total_size_increase = new_prop_bytes.len(); + let old_total_size = self.header.totalsize() as usize; + let new_total_size = old_total_size + total_size_increase; + + let mut new_dtb_data = vec![0u8; new_total_size]; + let mut new_mem_view = DtbMemory::new(&mut new_dtb_data[..]); + + let old_off_dt_struct = self.header.off_dt_struct() as usize; + let old_size_dt_struct = self.header.size_dt_struct() as usize; + let old_off_dt_strings = self.header.off_dt_strings() as usize; + let old_size_dt_strings = self.header.size_dt_strings() as usize; + + // 1. Copy data BEFORE insertion point (header, rsvmap, struct block up to insertion) + new_mem_view.write_bytes(0, &self.dtb_data[0..insertion_byte_offset]); + + // 2. Insert new property data + new_mem_view.write_bytes(insertion_byte_offset, &new_prop_bytes); + + // 3. Copy data AFTER insertion point, adjusting offsets + let old_struct_end_byte_offset = old_off_dt_struct + old_size_dt_struct; + + new_mem_view.write_bytes( + insertion_byte_offset + total_size_increase, + &self.dtb_data[insertion_byte_offset..old_struct_end_byte_offset], + ); + + // 4. Copy string table, adjusting its offset + let new_strings_start_byte_offset = old_off_dt_strings + total_size_increase; + new_mem_view.write_bytes( + new_strings_start_byte_offset, + &self.dtb_data[old_off_dt_strings..old_off_dt_strings + old_size_dt_strings], + ); + + // 5. Update the header in the new DTB data + let mut new_header = FdtHeader::read(&new_mem_view).unwrap(); + new_header.set_totalsize(new_total_size as u32); + new_header.set_size_dt_struct(old_size_dt_struct as u32 + total_size_increase as u32); + new_header.set_off_dt_strings(new_strings_start_byte_offset as u32); + new_header.write(&mut new_mem_view); + + // 6. Replace the old dtb_data with the new one + self.dtb_data = new_dtb_data; + self.header = new_header; + + debug!( + "Added property '{}' to node '{}'. New total size: {} bytes", + prop_name, + node_path, + self.dtb_data.len() + ); + + true + } + /// Modifies the value of a property within a specified node. /// If the new value is longer than the existing allocated space, /// the entire DTB is reallocated and rebuilt in memory. diff --git a/src/main.rs b/src/main.rs index c860eb3..fd6253b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ #[macro_use] extern crate axlog; +extern crate alloc; use axhal::mem::{MemRegionFlags, PhysAddr, memory_regions, phys_to_virt}; @@ -60,22 +61,8 @@ pub extern "C" fn rust_main(_cpu_id: usize, dtb: usize) -> ! { dtb::GLOBAL_NOW_DTB_ADDRESS = phys_to_virt(PhysAddr::from_usize(dtb)).as_usize(); } - // if dtb is needed to next stage - /* - unsafe { - let mut parser = dtb::DtbParser::new(phys_to_virt(PhysAddr::from_usize(dtb)).as_usize()).unwrap(); - parser.dump_all(); - if parser.modify_property( - "/chosen", - "bootargs", - "console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootwait", - ) { - error!("modify error!"); - } - let new_dtb: usize = parser.save_to_mem(); - // Send 'new_dtb' to next stage - } - */ + // ramdisk check + crate::medium::ramdisk_cpio::check_ramdisk(); crate::shell::shell_main(); diff --git a/src/medium/mod.rs b/src/medium/mod.rs index 2bc368a..5a24f19 100644 --- a/src/medium/mod.rs +++ b/src/medium/mod.rs @@ -1,11 +1,2 @@ -cfg_if::cfg_if! { - if #[cfg(feature = "ramdisk_cpio")] { - mod ramdisk_cpio; - pub use ramdisk_cpio::*; - } else if #[cfg(feature = "virtiodisk")] { - mod virtio_disk; - pub use virtio_disk::*; - } else { - info!("Boot media feature is not enabled."); - } -} +pub mod ramdisk_cpio; +pub mod virtio_disk; \ No newline at end of file diff --git a/src/medium/ramdisk_cpio.rs b/src/medium/ramdisk_cpio.rs index e92cf4a..17bbbee 100644 --- a/src/medium/ramdisk_cpio.rs +++ b/src/medium/ramdisk_cpio.rs @@ -1,12 +1,10 @@ -extern crate alloc; - -use core::{ptr, str}; -use axhal::mem::phys_to_virt; -use axio::{self as io, prelude::*}; -use alloc::{string::String, vec::Vec, string::ToString}; +use alloc::{string::String, string::ToString, vec::Vec}; +use axhal::mem::{PhysAddr, VirtAddr, phys_to_virt, virt_to_phys}; +use axio::{self as io}; +use core::str; const CPIO_MAGIC: &[u8; 6] = b"070701"; -const CPIO_BASE: usize = 0x8400_0000; +pub static mut CPIO_BASE: usize = 0x0; #[repr(C)] #[derive(Debug)] @@ -44,7 +42,12 @@ pub fn current_dir() -> io::Result { /// Read the entire contents of a file into a bytes vector. pub fn read(path: &str) -> io::Result> { - let mut ptr = phys_to_virt(CPIO_BASE.into()).as_usize(); + if unsafe { CPIO_BASE } == 0 { + error!("Ramdisk is not enabled!"); + return core::prelude::v1::Err(io::Error::Unsupported); + } + + let mut ptr = phys_to_virt(unsafe { CPIO_BASE.into() }).as_usize(); loop { let hdr = unsafe { &*(ptr as *const CpioNewcHeader) }; @@ -76,9 +79,7 @@ pub fn read(path: &str) -> io::Result> { }; if is_match { - let data = unsafe { - core::slice::from_raw_parts(file_start as *const u8, filesize) - }; + let data = unsafe { core::slice::from_raw_parts(file_start as *const u8, filesize) }; let mut bytes = Vec::with_capacity(filesize as usize); bytes.extend_from_slice(data); return Ok(bytes); @@ -92,7 +93,12 @@ pub fn read(path: &str) -> io::Result> { /// Read the entire contents of a file into a string. pub fn read_to_string(path: &str) -> io::Result { - let mut ptr = phys_to_virt(CPIO_BASE.into()).as_usize(); + if unsafe { CPIO_BASE } == 0 { + error!("Ramdisk is not enabled!"); + return core::prelude::v1::Err(io::Error::Unsupported); + } + + let mut ptr = phys_to_virt(unsafe { CPIO_BASE.into() }).as_usize(); loop { let hdr = unsafe { &*(ptr as *const CpioNewcHeader) }; @@ -136,3 +142,92 @@ pub fn read_to_string(path: &str) -> io::Result { core::prelude::v1::Err(io::Error::NotFound) } + +fn set_ramdisk_addr(addr: usize) { + unsafe { + CPIO_BASE = addr; + } +} + +fn ramdisk_enabled() -> bool { + axconfig::boot::USE_RAMDISK +} + +fn ramdisk_load_enabled() -> bool { + axconfig::boot::LOAD_RAMDISK +} + +fn do_load_ramdisk() -> Option<(usize, usize)> { + let file_data = crate::medium::virtio_disk::read(axconfig::boot::RAMDISK_FILE).unwrap(); + let file_size = file_data.len(); + + let start_addr = axalloc::global_allocator() + .alloc_pages(file_size / 4096 + 1, 4096) + .unwrap(); + unsafe { + core::ptr::copy_nonoverlapping(file_data.as_ptr(), start_addr as *mut u8, file_size); + } + debug!( + "Ramdisk will be load to {:#x}, size is {:#x}", + start_addr, file_size + ); + Some((start_addr, file_size)) +} + +fn enable_dtb_ramdisk(addr: usize, size: usize) { + unsafe { + let mut parser = crate::dtb::DtbParser::new(crate::dtb::GLOBAL_NOW_DTB_ADDRESS).unwrap(); + + // linux initrd + if !parser.add_property("/chosen", "linux,initrd-start", &addr.to_ne_bytes()) { + error!("Change linux,initrd-start failed!"); + } + if !parser.add_property( + "/chosen", + "linux,initrd-end", + &((addr + size).to_ne_bytes()), + ) { + error!("Change linux,initrd-end failed!"); + } + + // Save new dtb + crate::dtb::GLOBAL_NOW_DTB_ADDRESS = parser.save_to_mem(); + } +} + +pub fn check_ramdisk() { + info!("Checking ramdisk....."); + // Check the detailed annotations and explanations in configs/platforms/riscv64-qemu-virt.toml + if crate::medium::ramdisk_cpio::ramdisk_enabled() { + let mut start_addr_phys: usize = 0; + let mut _start_addr_virt: usize = 0; + let mut size: usize = 0; + if crate::medium::ramdisk_cpio::ramdisk_load_enabled() { + if let Some((addr, si)) = crate::medium::ramdisk_cpio::do_load_ramdisk() { + _start_addr_virt = addr; + start_addr_phys = virt_to_phys(VirtAddr::from_usize(addr)).as_usize(); + size = si; + } else { + error!("Load ramdisk failed!"); + } + crate::medium::ramdisk_cpio::set_ramdisk_addr(start_addr_phys); + crate::medium::ramdisk_cpio::enable_dtb_ramdisk(start_addr_phys, size); + info!( + "read test file context: {}", + crate::medium::ramdisk_cpio::read_to_string("/test/arceboot.txt").unwrap() + ); + } else { + start_addr_phys = axconfig::boot::RAMDISK_START; + _start_addr_virt = phys_to_virt(PhysAddr::from_usize(start_addr_phys)).as_usize(); + size = axconfig::boot::RAMDISK_SIZE; + + crate::medium::ramdisk_cpio::set_ramdisk_addr(start_addr_phys); + crate::medium::ramdisk_cpio::enable_dtb_ramdisk(start_addr_phys, size); + info!( + "read test file context: {}", + crate::medium::ramdisk_cpio::read_to_string("/test/arceboot.txt").unwrap() + ); + } + } + info!("Checking for ramdisk is done!"); +} diff --git a/src/medium/virtio_disk.rs b/src/medium/virtio_disk.rs index c1ebae6..2a4f564 100644 --- a/src/medium/virtio_disk.rs +++ b/src/medium/virtio_disk.rs @@ -1,5 +1,3 @@ -extern crate alloc; - use axio::{self as io}; use alloc::{string::String, vec::Vec}; diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs index 6534ada..1d8bddc 100644 --- a/src/runtime/mod.rs +++ b/src/runtime/mod.rs @@ -12,8 +12,6 @@ use object::Object; use object::ObjectSection; use uefi_raw::table::system::SystemTable; -extern crate alloc; - use crate::runtime::table::{get_system_table_raw, init_system_table}; mod protocol; diff --git a/src/runtime/protocol/handle.rs b/src/runtime/protocol/handle.rs index 9074789..1a77452 100644 --- a/src/runtime/protocol/handle.rs +++ b/src/runtime/protocol/handle.rs @@ -2,7 +2,6 @@ use axsync::Mutex; use lazyinit::LazyInit; use uefi_raw::{Guid, Handle}; -extern crate alloc; use alloc::collections::BTreeMap; use alloc::vec::Vec; diff --git a/src/runtime/protocol/simple_text_output.rs b/src/runtime/protocol/simple_text_output.rs index f7cb7fe..4b7d719 100644 --- a/src/runtime/protocol/simple_text_output.rs +++ b/src/runtime/protocol/simple_text_output.rs @@ -5,7 +5,6 @@ use uefi_raw::{ protocol::console::{SimpleTextOutputMode, SimpleTextOutputProtocol}, }; -extern crate alloc; use alloc::boxed::Box; static TEXT_OUTPUT: LazyInit> = LazyInit::new(); diff --git a/src/runtime/table.rs b/src/runtime/table.rs index 35b9f77..4c64a78 100644 --- a/src/runtime/table.rs +++ b/src/runtime/table.rs @@ -8,7 +8,6 @@ use crate::runtime::protocol::simple_text_output::{ get_simple_text_output, init_simple_text_output, }; -extern crate alloc; use alloc::boxed::Box; #[derive(Debug)] diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 8a907b4..f9ff323 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -12,7 +12,7 @@ const SPACE: u8 = b' '; const MAX_CMD_LEN: usize = 256; fn print_prompt() { - axlog::ax_print!("[Arceboot]: {}$ ", &crate::medium::current_dir().unwrap()); + axlog::ax_print!("[Arceboot]: {}$ ", &crate::medium::virtio_disk::current_dir().unwrap()); } pub fn shell_main() { diff --git a/src/shell/stdio.rs b/src/shell/stdio.rs index f1a0568..7f95ec5 100644 --- a/src/shell/stdio.rs +++ b/src/shell/stdio.rs @@ -1,5 +1,3 @@ -extern crate alloc; - use alloc::{string::String, vec::Vec}; pub use axio::{BufRead, BufReader, Read, Write}; use axsync::{Mutex, MutexGuard};