From 42f94487cfefa0b624d87bcef6c921b0eba8bbc7 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 1 Sep 2020 14:43:16 +0800 Subject: [PATCH] split config code into libconfig --- src/Cargo.lock | 12 +++++++++++- src/Cargo.toml | 1 + src/libconfig/Cargo.toml | 15 +++++++++++++++ .../src/config.rs => libconfig/src/lib.rs} | 9 +++++++-- src/{runtime => libconfig}/src/load_pl.rs | 2 +- src/{runtime => libconfig}/src/net_settings.rs | 5 ++--- src/{runtime => libconfig}/src/sd_reader.rs | 0 src/runtime/Cargo.toml | 2 +- src/runtime/src/comms.rs | 5 ++--- src/runtime/src/main.rs | 11 ++++------- 10 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 src/libconfig/Cargo.toml rename src/{runtime/src/config.rs => libconfig/src/lib.rs} (97%) rename src/{runtime => libconfig}/src/load_pl.rs (99%) rename src/{runtime => libconfig}/src/net_settings.rs (95%) rename src/{runtime => libconfig}/src/sd_reader.rs (100%) diff --git a/src/Cargo.lock b/src/Cargo.lock index 5dc6e40..4e3a97e 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -236,6 +236,16 @@ dependencies = [ "libboard_zynq", ] +[[package]] +name = "libconfig" +version = "0.1.0" +dependencies = [ + "core_io", + "fatfs", + "libboard_zynq", + "log", +] + [[package]] name = "libcortex_a9" version = "0.0.0" @@ -416,11 +426,11 @@ dependencies = [ "dwarf", "dyld", "embedded-hal", - "fatfs", "futures", "libasync", "libboard_zynq", "libc", + "libconfig", "libcortex_a9", "libm", "libregister", diff --git a/src/Cargo.toml b/src/Cargo.toml index d3378b1..ad26b6d 100644 --- a/src/Cargo.toml +++ b/src/Cargo.toml @@ -2,6 +2,7 @@ members = [ "libc", "libdyld", + "libconfig", "libcoreio", "libdwarf", "libunwind", diff --git a/src/libconfig/Cargo.toml b/src/libconfig/Cargo.toml new file mode 100644 index 0000000..993cdd6 --- /dev/null +++ b/src/libconfig/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "libconfig" +version = "0.1.0" +authors = ["M-Labs"] +edition = "2018" + +[dependencies] +libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" } +core_io = { version = "0.1", features = ["collections"] } +fatfs = { version = "0.3", features = ["core_io"], default-features = false } +log = "0.4" + +[features] +ipv6 = [] + diff --git a/src/runtime/src/config.rs b/src/libconfig/src/lib.rs similarity index 97% rename from src/runtime/src/config.rs rename to src/libconfig/src/lib.rs index b8e3672..bc1e579 100644 --- a/src/runtime/src/config.rs +++ b/src/libconfig/src/lib.rs @@ -1,10 +1,15 @@ -use crate::sd_reader; +#![no_std] +extern crate alloc; + use core::fmt; use alloc::{string::FromUtf8Error, string::String, vec::Vec}; use core_io::{self as io, BufRead, BufReader, Read}; - use libboard_zynq::sdio; +pub mod sd_reader; +pub mod net_settings; +pub mod load_pl; + #[derive(Debug)] pub enum Error<'a> { SdError(sdio::sd_card::CardInitializationError), diff --git a/src/runtime/src/load_pl.rs b/src/libconfig/src/load_pl.rs similarity index 99% rename from src/runtime/src/load_pl.rs rename to src/libconfig/src/load_pl.rs index f9cedf4..8eaceae 100644 --- a/src/runtime/src/load_pl.rs +++ b/src/libconfig/src/load_pl.rs @@ -1,4 +1,4 @@ -use crate::sd_reader; +use super::sd_reader; use core_io::{Error, Read, Seek, SeekFrom}; use libboard_zynq::{devc, sdio}; use log::{info, debug}; diff --git a/src/runtime/src/net_settings.rs b/src/libconfig/src/net_settings.rs similarity index 95% rename from src/runtime/src/net_settings.rs rename to src/libconfig/src/net_settings.rs index 9bef1ea..8c2a24e 100644 --- a/src/runtime/src/net_settings.rs +++ b/src/libconfig/src/net_settings.rs @@ -1,8 +1,7 @@ use core::fmt; use libboard_zynq::smoltcp::wire::{EthernetAddress, IpAddress}; - -use crate::config; +use super::Config; pub struct NetAddresses { pub hardware_addr: EthernetAddress, @@ -23,7 +22,7 @@ impl fmt::Display for NetAddresses { } } -pub fn get_adresses(cfg: &config::Config) -> NetAddresses { +pub fn get_adresses(cfg: &Config) -> NetAddresses { let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x52]); let mut ipv4_addr = IpAddress::v4(192, 168, 1, 52); let mut ipv6_addr = None; diff --git a/src/runtime/src/sd_reader.rs b/src/libconfig/src/sd_reader.rs similarity index 100% rename from src/runtime/src/sd_reader.rs rename to src/libconfig/src/sd_reader.rs diff --git a/src/runtime/Cargo.toml b/src/runtime/Cargo.toml index 0137b05..6385fe0 100644 --- a/src/runtime/Cargo.toml +++ b/src/runtime/Cargo.toml @@ -21,7 +21,6 @@ byteorder = { version = "1.3", default-features = false } void = { version = "1", default-features = false } futures = { version = "0.3", default-features = false, features = ["async-await"] } async-recursion = "0.3" -fatfs = { version = "0.3", features = ["core_io"], default-features = false } log_buffer = { version = "1.2" } libm = { version = "0.2", features = ["unstable"] } vcell = "0.1" @@ -36,3 +35,4 @@ dyld = { path = "../libdyld" } dwarf = { path = "../libdwarf" } unwind = { path = "../libunwind" } libc = { path = "../libc" } +libconfig = { path = "../libconfig" } diff --git a/src/runtime/src/comms.rs b/src/runtime/src/comms.rs index b8a71fc..5e42314 100644 --- a/src/runtime/src/comms.rs +++ b/src/runtime/src/comms.rs @@ -20,9 +20,8 @@ use libboard_zynq::{ use libcortex_a9::{semaphore::Semaphore, mutex::Mutex}; use futures::{select_biased, future::FutureExt}; use libasync::{smoltcp::{Sockets, TcpStream}, task}; +use libconfig::{Config, net_settings}; -use crate::config; -use crate::net_settings; use crate::proto_async::*; use crate::kernel; use crate::rpc; @@ -315,7 +314,7 @@ async fn handle_connection(stream: &TcpStream, control: Rc &str { } } -fn init_rtio(timer: &mut GlobalTimer, cfg: &config::Config) { +fn init_rtio(timer: &mut GlobalTimer, cfg: &Config) { let clock_sel = if let Ok(rtioclk) = cfg.read_str("rtioclk") { match rtioclk.as_ref() { @@ -197,11 +194,11 @@ pub fn main_core0() { init_gateware(); info!("detected gateware: {}", identifier_read(&mut [0; 64])); - let cfg = match config::Config::new() { + let cfg = match Config::new() { Ok(cfg) => cfg, Err(err) => { warn!("config initialization failed: {}", err); - config::Config::new_dummy() + Config::new_dummy() } };