diff --git a/build.sh b/build.sh index 09547f2d..ffdcd317 100755 --- a/build.sh +++ b/build.sh @@ -13,6 +13,10 @@ fi USER_TARGET=${ARCH}-unknown-yggdrasil USER_CARGO_OPTS="--target=${USER_TARGET}" +if [ "${PROFILE}" = "release" ]; then + USER_CARGO_OPTS="${USER_CARGO_OPTS} --release" +fi + pstatus() { echo -e "[BUILD] \033[32;1m$@\033[0m" } diff --git a/init/src/main.rs b/init/src/main.rs index c9e9c27b..22ddccf0 100644 --- a/init/src/main.rs +++ b/init/src/main.rs @@ -1,12 +1,9 @@ #![feature(rustc_private)] use std::fs::File; -use std::io::Read; -use std::os::yggdrasil::{mount, unmount, MountOptions, UnmountOptions}; +use std::os::yggdrasil::{mount, open, OpenOptions, FileMode, unmount, MountOptions, UnmountOptions}; fn main() { - println!("Hello!"); - unsafe { mount(MountOptions { source: None, @@ -14,26 +11,24 @@ fn main() { target: "/dev", }) .unwrap(); + + // Open stdin/stdout/stderr + open("/dev/ttyS0", OpenOptions::READ, FileMode::empty()).unwrap(); + open("/dev/ttyS0", OpenOptions::WRITE, FileMode::empty()).unwrap(); + open("/dev/ttyS0", OpenOptions::WRITE, FileMode::empty()).unwrap(); } - let mut file = File::open("/dev/ttyS0").unwrap(); - let mut buf = [0; 1]; + let mut stdin = std::io::stdin(); + let mut buffer = String::new(); - while let Ok(count) = file.read(&mut buf) { - if count != 1 { + while let Ok(len) = stdin.read_line(&mut buffer) { + if len == 0 { + println!("End of file reached"); break; } - - if buf[0] == 0x3 { - break; - } - - println!("Got {:#x}", buf[0]); + println!("{:?}", buffer.trim()); + buffer.clear(); } - unsafe { - unmount(UnmountOptions { - mountpoint: "/dev" - }).unwrap(); - } + loop {} }