Switch the current binary to use anyhow errors and add a proper argument number check

This commit is contained in:
2025-12-21 19:06:23 +01:00
parent 2e1c0a7dce
commit 944ed573c6
3 changed files with 13 additions and 2 deletions

View File

@@ -19,6 +19,8 @@ use trve::{
mem::{DeviceEntry, MemAccessFault, MemConfig, MemDeviceInterface, PageNum, Ram},
};
use anyhow::{Result, bail};
use crate::basic_uart::BasicUart;
fn read_file_to_buffer(path: &str, buffer: &mut [u8]) -> io::Result<usize> {
@@ -41,14 +43,15 @@ fn read_file_to_buffer(path: &str, buffer: &mut [u8]) -> io::Result<usize> {
Ok(total_read)
}
fn main() -> Result<(), Box<dyn Error>> {
fn main() -> Result<()> {
let mut ram = Ram::try_new(16 * 1024 * 1024 / 4096)?;
let buf = ram.buf_mut();
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
eprintln!("USAGE: trve <ram_image>")
eprintln!("USAGE: trve <ram_image>");
bail!("Wrong number of arguments");
}
read_file_to_buffer(&args[1], buf)?;