init: mount/unmount test

This commit is contained in:
Mark Poliakov 2023-07-20 12:00:41 +03:00
parent 0ca54f28e0
commit 36ac85cb80
5 changed files with 57 additions and 4 deletions

View File

@ -0,0 +1,7 @@
{
"rust-analyzer.cargo.target": "aarch64-unknown-yggdrasil",
"rust-analyzer.server.extraEnv": {
"RUSTUP_TOOLCHAIN": "ygg-stage1",
"RA_LOG": "debug"
}
}

View File

@ -1,4 +1,5 @@
[workspace]
resolver = "1"
members = [
"init"
]

View File

@ -13,8 +13,6 @@ fi
USER_TARGET=${ARCH}-unknown-yggdrasil
USER_CARGO_OPTS="--target=${USER_TARGET}"
USER_FILES=init
pstatus() {
echo -e "[BUILD] \033[32;1m$@\033[0m"
}
@ -32,8 +30,16 @@ check_toolchain() {
}
pack_initrd() {
cd "target/${USER_TARGET}/${PROFILE}"
tar --xform='s/^/\//' -cf initrd.tar ${USER_FILES}
local build_dir=target/${USER_TARGET}/${PROFILE}
local root_dir=${build_dir}/rootfs
mkdir -p "${root_dir}"
cp ${build_dir}/init ${root_dir}
cd "${root_dir}"
mkdir -p dev
tar cf ../initrd.tar `find . -printf "%P\n"`
cd -
}

View File

@ -1,3 +1,39 @@
#![feature(rustc_private)]
use std::fs::File;
use std::io::Read;
use std::os::yggdrasil::{mount, unmount, MountOptions, UnmountOptions};
fn main() {
println!("Hello!");
unsafe {
mount(MountOptions {
source: None,
filesystem: Some("devfs"),
target: "/dev",
})
.unwrap();
}
let mut file = File::open("/dev/ttyS0").unwrap();
let mut buf = [0; 1];
while let Ok(count) = file.read(&mut buf) {
if count != 1 {
break;
}
if buf[0] == 0x3 {
break;
}
println!("Got {:#x}", buf[0]);
}
unsafe {
unmount(UnmountOptions {
mountpoint: "/dev"
}).unwrap();
}
}

3
rust-toolchain.toml Normal file
View File

@ -0,0 +1,3 @@
[toolchain]
channel = "ygg-stage1"
targets = ["aarch64-unknown-yggdrasil"]