forked from koniifer/ableos
load the modules programmatically instead of manually
This commit is contained in:
parent
b96927d61a
commit
a5cab167c5
|
@ -124,6 +124,18 @@ fn assemble() -> Result<(), Error> {
|
||||||
fn get_fs() -> Result<FileSystem<impl ReadWriteSeek>, io::Error> {
|
fn get_fs() -> Result<FileSystem<impl ReadWriteSeek>, io::Error> {
|
||||||
let filename = "sysdata/system_config.toml";
|
let filename = "sysdata/system_config.toml";
|
||||||
|
|
||||||
|
let mut img = File::options()
|
||||||
|
.read(true)
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.open(Path::new("target/disk.img"))?;
|
||||||
|
|
||||||
|
img.set_len(1024 * 1024 * 64)?;
|
||||||
|
|
||||||
|
fatfs::format_volume(&mut img, FormatVolumeOptions::new())?;
|
||||||
|
|
||||||
|
let fs = FileSystem::new(img, FsOptions::new())?;
|
||||||
|
|
||||||
// Read the contents of the file using a `match` block
|
// Read the contents of the file using a `match` block
|
||||||
// to return the `data: Ok(c)` as a `String`
|
// to return the `data: Ok(c)` as a `String`
|
||||||
// or handle any `errors: Err(_)`.
|
// or handle any `errors: Err(_)`.
|
||||||
|
@ -175,6 +187,16 @@ TERM_BACKDROP={}
|
||||||
term_wallpaper.as_str().unwrap(),
|
term_wallpaper.as_str().unwrap(),
|
||||||
term_background
|
term_background
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Copy the term_wallpaper to the image
|
||||||
|
let term_wallpaper_path = term_wallpaper
|
||||||
|
.as_str()
|
||||||
|
.unwrap()
|
||||||
|
.split("boot:///")
|
||||||
|
.last()
|
||||||
|
.unwrap();
|
||||||
|
copy_file_to_img(&format!("sysdata/{}", term_wallpaper_path), &fs);
|
||||||
|
|
||||||
limine_str.push_str(&base);
|
limine_str.push_str(&base);
|
||||||
|
|
||||||
let boot_entries = limine_table.as_table_mut().unwrap();
|
let boot_entries = limine_table.as_table_mut().unwrap();
|
||||||
|
@ -230,18 +252,23 @@ TERM_BACKDROP={}
|
||||||
limine_str.push_str(&a);
|
limine_str.push_str(&a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy modules into the test_programs directory
|
||||||
|
modules.into_iter().for_each(|(key, value)| {
|
||||||
|
if value.is_table() {
|
||||||
|
let path = value
|
||||||
|
.get("path")
|
||||||
|
.expect("You must have a `path` as a value")
|
||||||
|
.as_str()
|
||||||
|
.unwrap()
|
||||||
|
.split("boot:///")
|
||||||
|
.last()
|
||||||
|
.unwrap();
|
||||||
|
let fpath = format!("target/test-programs/{}", path);
|
||||||
|
copy_file_to_img(&fpath, &fs);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
let mut img = File::options()
|
|
||||||
.read(true)
|
|
||||||
.write(true)
|
|
||||||
.create(true)
|
|
||||||
.open(Path::new("target/disk.img"))?;
|
|
||||||
|
|
||||||
img.set_len(1024 * 1024 * 64)?;
|
|
||||||
|
|
||||||
fatfs::format_volume(&mut img, FormatVolumeOptions::new())?;
|
|
||||||
|
|
||||||
let fs = FileSystem::new(img, FsOptions::new())?;
|
|
||||||
|
|
||||||
let bootdir = fs.root_dir().create_dir("efi")?.create_dir("boot")?;
|
let bootdir = fs.root_dir().create_dir("efi")?.create_dir("boot")?;
|
||||||
|
|
||||||
|
@ -262,31 +289,23 @@ TERM_BACKDROP={}
|
||||||
.attach_printable("Copying Limine (ARM): have you pulled the submodule?")?,
|
.attach_printable("Copying Limine (ARM): have you pulled the submodule?")?,
|
||||||
&mut bootdir.create_file("bootaa64.efi")?,
|
&mut bootdir.create_file("bootaa64.efi")?,
|
||||||
)?;
|
)?;
|
||||||
// TODO: Remove this and replace it with pulling executables from the system_config
|
|
||||||
for fpath in [
|
|
||||||
"sysdata/background.bmp",
|
|
||||||
"target/test-programs/failure.hbf",
|
|
||||||
"target/test-programs/ecall.hbf",
|
|
||||||
"target/test-programs/main.hbf",
|
|
||||||
"target/test-programs/serial_driver.hbf",
|
|
||||||
"target/test-programs/vfs_test.hbf",
|
|
||||||
"target/test-programs/sds_test.hbf",
|
|
||||||
"target/test-programs/limine_framebuffer_driver.hbf",
|
|
||||||
"target/test-programs/keyboard_driver.hbf",
|
|
||||||
] {
|
|
||||||
let path = Path::new(fpath);
|
|
||||||
io::copy(
|
|
||||||
&mut File::open(path)?,
|
|
||||||
&mut fs
|
|
||||||
.root_dir()
|
|
||||||
.create_file(&path.file_name().unwrap().to_string_lossy())?,
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
drop(bootdir);
|
drop(bootdir);
|
||||||
Ok(fs)
|
Ok(fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn copy_file_to_img(fpath: &str, fs: &FileSystem<File>) {
|
||||||
|
let path = Path::new(fpath);
|
||||||
|
io::copy(
|
||||||
|
&mut File::open(path).expect(&format!("Could not open file {fpath}")),
|
||||||
|
&mut fs
|
||||||
|
.root_dir()
|
||||||
|
.create_file(&path.file_name().unwrap().to_string_lossy())
|
||||||
|
.expect("Unable to create file"),
|
||||||
|
)
|
||||||
|
.expect("Copy failed");
|
||||||
|
}
|
||||||
|
|
||||||
fn build(release: bool, target: Target) -> Result<(), Error> {
|
fn build(release: bool, target: Target) -> Result<(), Error> {
|
||||||
let fs = get_fs().change_context(Error::Io)?;
|
let fs = get_fs().change_context(Error::Io)?;
|
||||||
let mut com = Command::new("cargo");
|
let mut com = Command::new("cargo");
|
||||||
|
|
Loading…
Reference in a new issue