summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs7
3 files changed, 13 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e08dae3..a77c839 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,12 @@
version = 4
[[package]]
+name = "anyhow"
+version = "1.0.100"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61"
+
+[[package]]
name = "libc"
version = "0.2.176"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -21,5 +27,6 @@ dependencies = [
name = "trve"
version = "0.0.0"
dependencies = [
+ "anyhow",
"memmap2",
]
diff --git a/Cargo.toml b/Cargo.toml
index 59f1a2f..003b0b5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,4 +4,5 @@ version = "0.0.0"
edition = "2024"
[dependencies]
+anyhow = "1.0.100"
memmap2 = "0.9.8"
diff --git a/src/main.rs b/src/main.rs
index 67186bb..5e20b1a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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)?;