Browse Source

Read and parse JSON configuration file

master
Nick Rirush 5 years ago
parent
commit
36846125b0
Signed by: Rirush GPG Key ID: 8922C7BBF842AFF0
  1. 80
      Cargo.lock
  2. 5
      Cargo.toml
  3. 59
      src/main.rs

80
Cargo.lock

@ -18,6 +18,9 @@ name = "coonboot"
version = "0.1.0"
dependencies = [
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde-json-core 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"uefi 0.1.0 (git+https://github.com/GabrielMajeri/uefi-rs)",
"uefi-alloc 0.1.0 (git+https://github.com/GabrielMajeri/uefi-rs)",
"uefi-exts 0.1.0 (git+https://github.com/GabrielMajeri/uefi-rs)",
@ -26,6 +29,14 @@ dependencies = [
]
[[package]]
name = "heapless"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"untagged-option 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "log"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -39,11 +50,61 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proc-macro2"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rlibc"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde-json-core"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"heapless 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_derive"
version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "0.15.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ucs2"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -98,6 +159,16 @@ dependencies = [
]
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "untagged-option"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "usize_conversions"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@ -123,15 +194,24 @@ dependencies = [
"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
"checksum heapless 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "235aaa7f0c6d44d90018003f02983ae5cd73402343e11ff0e2cf247eb9efcb28"
"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f"
"checksum os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "66481dbeb5e773e7bd85b63cd6042c30786f834338288c5ec4f3742673db360a"
"checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee"
"checksum quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "63b5829244f52738cfee93b3a165c1911388675be000c888d2fae620dee8fa5b"
"checksum rlibc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe"
"checksum serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "15c141fc7027dd265a47c090bf864cf62b42c4d228bbcf4e51a0c9e2b0d3f7ef"
"checksum serde-json-core 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e287e0980922159edd41f9a52e0529e0d39136541dda105961f5c9da93bff6ec"
"checksum serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "225de307c6302bec3898c51ca302fc94a7a1697ef0845fcee6448f33c032249c"
"checksum syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)" = "90c39a061e2f412a9f869540471ab679e85e50c6b05604daf28bc3060f75c430"
"checksum ucs2 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e583483194b07714e09e7f72ae3ed447d17fe6855f66a2ccbf6751e52df82e0"
"checksum uefi 0.1.0 (git+https://github.com/GabrielMajeri/uefi-rs)" = "<none>"
"checksum uefi-alloc 0.1.0 (git+https://github.com/GabrielMajeri/uefi-rs)" = "<none>"
"checksum uefi-exts 0.1.0 (git+https://github.com/GabrielMajeri/uefi-rs)" = "<none>"
"checksum uefi-logger 0.1.0 (git+https://github.com/GabrielMajeri/uefi-rs)" = "<none>"
"checksum uefi-services 0.1.0 (git+https://github.com/GabrielMajeri/uefi-rs)" = "<none>"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum untagged-option 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89553f60895e868761e18120e72077da22920614562d2f4fe98fa707fbb12fe6"
"checksum usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f70329e2cbe45d6c97a5112daad40c34cd9a4e18edb5a2a18fefeb584d8d25e5"
"checksum ux 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53d8df5dd8d07fedccd202de1887d94481fadaea3db70479f459e8163a1fab41"
"checksum x86_64 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd647af1614659e1febec1d681231aea4ebda4818bf55a578aff02f3e4db4b4"

5
Cargo.toml

@ -9,4 +9,7 @@ uefi-alloc = { git = "https://github.com/GabrielMajeri/uefi-rs" }
uefi-exts = { git = "https://github.com/GabrielMajeri/uefi-rs" }
uefi-logger = { git = "https://github.com/GabrielMajeri/uefi-rs" }
uefi-services = { git = "https://github.com/GabrielMajeri/uefi-rs" }
log = { version = "0.4", default-features = false }
log = { version = "0.4", default-features = false }
serde = { version = "1.0", default-features = false, features = ["alloc"] }
serde_derive = "1.0"
serde-json-core = "0.0.1"

59
src/main.rs

@ -10,39 +10,76 @@ extern crate uefi_services;
#[macro_use]
extern crate log;
extern crate alloc;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json_core;
use serde_json_core::de::from_slice;
use uefi::prelude::*;
use uefi::proto::media::file::{FileAttribute, FileMode};
use uefi::proto::media::fs::SimpleFileSystem;
use uefi_exts::BootServicesExt;
#[derive(Deserialize, Serialize)]
struct Configuration<'a> {
pub kernel_location: &'a str,
pub load_modules: bool,
}
impl<'a> Default for Configuration<'a> {
fn default() -> Configuration<'a> {
Configuration {
kernel_location: "\\EFI\\COONBOOT\\CoonKRNL",
load_modules: false,
}
}
}
#[no_mangle]
pub extern "win64" fn uefi_start(_image: uefi::Handle, table: SystemTable<Boot>) -> Status {
let mut buf: [u8; 8000] = [0; 8000];
uefi_services::init(&table).expect_success("Failed to initialize utilities");
table
.stdout()
.reset(false)
.expect_success("Failed to reset stdout");
let mut config: Configuration = Default::default();
let fs = table
.boot_services()
.find_protocol::<SimpleFileSystem>()
.expect("Failed to resolve filesystem")
.get();
unsafe {
let mut file = (*fs).open_volume().expect("Failed to open root").unwrap();
let mut file = file
.open(
"\\EFI\\coonboot.efi",
FileMode::READ,
FileAttribute::empty(),
)
.unwrap()
.unwrap();
let mut buf: [u8; 3] = [0, 0, 0];
file.read(&mut buf).unwrap().unwrap();
info!("First three bytes of coonboot.efi: {:?}", buf);
let result = file.open(
"\\EFI\\COONBOOT\\boot.json",
FileMode::READ,
FileAttribute::empty(),
);
match result {
Ok(file) => {
let mut file = file.unwrap();
// TODO: Don't panic here
let size = file.read(&mut buf).unwrap().unwrap();
// TODO: Don't panic here too
config = from_slice(&buf[..size]).unwrap();
}
Err(_) => {
warn!("\\EFI\\COONBOOT\\boot.json not found, using default configuration");
}
}
}
if config.load_modules {
error!("Can't load kernel modules, not supported yet");
}
info!("Loading kernel from {}", config.kernel_location);
Status::SUCCESS
}

Loading…
Cancel
Save