Compare commits

...

6 Commits

9 changed files with 101 additions and 51 deletions

View File

@ -15,7 +15,7 @@ let
version = "0.1.0"; version = "0.1.0";
src = ./src; src = ./src;
cargoSha256 = "1ybqf370xqcvs94zs542ydm5jszwrfqwlnr3xwn5yn2zp4cnv0vd"; cargoSha256 = "1vapk3xjaj4q3xz312nwwbdb7c9fr4439x2rchigh21d5yqfdpr7";
nativeBuildInputs = [ nativeBuildInputs = [
pkgs.gnumake pkgs.gnumake

View File

@ -5,7 +5,7 @@ set -e
impure=0 impure=0
load_bitstream=1 load_bitstream=1
while getopts "h:i:l" opt; do while getopts "h:il" opt; do
case "$opt" in case "$opt" in
\?) exit 1 \?) exit 1
;; ;;

10
src/Cargo.lock generated
View File

@ -200,7 +200,7 @@ dependencies = [
[[package]] [[package]]
name = "libasync" name = "libasync"
version = "0.0.0" version = "0.0.0"
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#9fcf9243f2dd2e9fcd61d17ddb1d6d495a68893f" source = "git+https://git.m-labs.hk/M-Labs/zc706.git#7082e07a1857d811bcf2f6982c655c411c5a1e4f"
dependencies = [ dependencies = [
"embedded-hal", "embedded-hal",
"libcortex_a9", "libcortex_a9",
@ -212,7 +212,7 @@ dependencies = [
[[package]] [[package]]
name = "libboard_zynq" name = "libboard_zynq"
version = "0.0.0" version = "0.0.0"
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#9fcf9243f2dd2e9fcd61d17ddb1d6d495a68893f" source = "git+https://git.m-labs.hk/M-Labs/zc706.git#7082e07a1857d811bcf2f6982c655c411c5a1e4f"
dependencies = [ dependencies = [
"bit_field", "bit_field",
"embedded-hal", "embedded-hal",
@ -236,7 +236,7 @@ dependencies = [
[[package]] [[package]]
name = "libcortex_a9" name = "libcortex_a9"
version = "0.0.0" version = "0.0.0"
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#9fcf9243f2dd2e9fcd61d17ddb1d6d495a68893f" source = "git+https://git.m-labs.hk/M-Labs/zc706.git#7082e07a1857d811bcf2f6982c655c411c5a1e4f"
dependencies = [ dependencies = [
"bit_field", "bit_field",
"libregister", "libregister",
@ -245,7 +245,7 @@ dependencies = [
[[package]] [[package]]
name = "libregister" name = "libregister"
version = "0.0.0" version = "0.0.0"
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#9fcf9243f2dd2e9fcd61d17ddb1d6d495a68893f" source = "git+https://git.m-labs.hk/M-Labs/zc706.git#7082e07a1857d811bcf2f6982c655c411c5a1e4f"
dependencies = [ dependencies = [
"bit_field", "bit_field",
"vcell", "vcell",
@ -255,7 +255,7 @@ dependencies = [
[[package]] [[package]]
name = "libsupport_zynq" name = "libsupport_zynq"
version = "0.0.0" version = "0.0.0"
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#9fcf9243f2dd2e9fcd61d17ddb1d6d495a68893f" source = "git+https://git.m-labs.hk/M-Labs/zc706.git#7082e07a1857d811bcf2f6982c655c411c5a1e4f"
dependencies = [ dependencies = [
"compiler_builtins", "compiler_builtins",
"libboard_zynq", "libboard_zynq",

View File

@ -13,14 +13,15 @@ use libboard_zynq::{
self as zynq, self as zynq,
smoltcp::{ smoltcp::{
self, self,
wire::{EthernetAddress, IpAddress, Ipv4Address, IpCidr}, wire::IpCidr,
iface::{NeighborCache, EthernetInterfaceBuilder, Routes}, iface::{NeighborCache, EthernetInterfaceBuilder},
time::Instant, time::Instant,
}, },
timer::GlobalTimer, timer::GlobalTimer,
}; };
use libasync::{smoltcp::{Sockets, TcpStream}, task}; use libasync::{smoltcp::{Sockets, TcpStream}, task};
use crate::net_settings;
use crate::proto_async::*; use crate::proto_async::*;
use crate::kernel; use crate::kernel;
use crate::rpc; use crate::rpc;
@ -252,12 +253,11 @@ async fn handle_connection(stream: &TcpStream, control: Rc<RefCell<kernel::Contr
} }
} }
const HWADDR: [u8; 6] = [0, 0x23, 0xab, 0xad, 0x1d, 0xea];
const IPADDR: IpAddress = IpAddress::Ipv4(Ipv4Address([192, 168, 1, 52]));
pub fn main(timer: GlobalTimer) { pub fn main(timer: GlobalTimer) {
let eth = zynq::eth::Eth::default(HWADDR.clone()); let net_addresses = net_settings::get_adresses();
info!("network addresses: {}", net_addresses);
let eth = zynq::eth::Eth::default(net_addresses.hardware_addr.0.clone());
const RX_LEN: usize = 8; const RX_LEN: usize = 8;
// Number of transmission buffers (minimum is two because with // Number of transmission buffers (minimum is two because with
// one, duplicate packet transmission occurs) // one, duplicate packet transmission occurs)
@ -265,18 +265,32 @@ pub fn main(timer: GlobalTimer) {
let eth = eth.start_rx(RX_LEN); let eth = eth.start_rx(RX_LEN);
let mut eth = eth.start_tx(TX_LEN); let mut eth = eth.start_tx(TX_LEN);
let ethernet_addr = EthernetAddress(HWADDR); let neighbor_cache = NeighborCache::new(alloc::collections::BTreeMap::new());
let mut ip_addrs = [IpCidr::new(IPADDR, 24)]; let mut iface = match net_addresses.ipv6_addr {
let mut routes_storage = vec![None; 4]; Some(addr) => {
let routes = Routes::new(&mut routes_storage[..]); let ip_addrs = [
let mut neighbor_storage = vec![None; 256]; IpCidr::new(net_addresses.ipv4_addr, 0),
let neighbor_cache = NeighborCache::new(&mut neighbor_storage[..]); IpCidr::new(net_addresses.ipv6_ll_addr, 0),
let mut iface = EthernetInterfaceBuilder::new(&mut eth) IpCidr::new(addr, 0)
.ethernet_addr(ethernet_addr) ];
.ip_addrs(&mut ip_addrs[..]) EthernetInterfaceBuilder::new(&mut eth)
.routes(routes) .ethernet_addr(net_addresses.hardware_addr)
.neighbor_cache(neighbor_cache) .ip_addrs(ip_addrs)
.finalize(); .neighbor_cache(neighbor_cache)
.finalize()
}
None => {
let ip_addrs = [
IpCidr::new(net_addresses.ipv4_addr, 0),
IpCidr::new(net_addresses.ipv6_ll_addr, 0)
];
EthernetInterfaceBuilder::new(&mut eth)
.ethernet_addr(net_addresses.hardware_addr)
.ip_addrs(ip_addrs)
.neighbor_cache(neighbor_cache)
.finalize()
}
};
Sockets::init(32); Sockets::init(32);

View File

@ -77,7 +77,7 @@ impl Config {
Ok(Config { fs }) Ok(Config { fs })
} }
fn read<'b>(&mut self, key: &'b str) -> Result<'b, Vec<u8>> { fn read<'b>(&self, key: &'b str) -> Result<'b, Vec<u8>> {
let root_dir = self.fs.root_dir(); let root_dir = self.fs.root_dir();
let mut buffer: Vec<u8> = Vec::new(); let mut buffer: Vec<u8> = Vec::new();
match root_dir.open_file(&["/CONFIG/", key, ".BIN"].concat()) { match root_dir.open_file(&["/CONFIG/", key, ".BIN"].concat()) {
@ -90,7 +90,7 @@ impl Config {
Ok(buffer) Ok(buffer)
} }
pub fn read_str<'b>(&mut self, key: &'b str) -> Result<'b, String> { pub fn read_str<'b>(&self, key: &'b str) -> Result<'b, String> {
Ok(String::from_utf8(self.read(key)?)?) Ok(String::from_utf8(self.read(key)?)?)
} }
} }

View File

@ -7,13 +7,14 @@
extern crate alloc; extern crate alloc;
use core::{cmp, str}; use core::{cmp, str};
use log::{info, error}; use log::info;
use libboard_zynq::{timer::GlobalTimer, logger, devc, slcr}; use libboard_zynq::{timer::GlobalTimer, logger, devc, slcr};
use libsupport_zynq::ram; use libsupport_zynq::ram;
mod sd_reader; mod sd_reader;
mod config; mod config;
mod net_settings;
mod proto_core_io; mod proto_core_io;
mod proto_async; mod proto_async;
mod comms; mod comms;
@ -49,24 +50,6 @@ pub fn main_core0() {
ram::init_alloc_linker(); ram::init_alloc_linker();
match config::Config::new() {
Ok(mut cfg) => {
match cfg.read_str("FOO") {
Ok(val) => info!("FOO = {}", val),
Err(error) => info!("failed to read config FOO: {}", error),
}
match cfg.read_str("BAR") {
Ok(val) => info!("BAR = {}", val),
Err(error) => info!("failed to read config BAR: {}", error),
}
match cfg.read_str("FOOBAR") {
Ok(val) => info!("read FOOBAR = {}", val),
Err(error) => info!("failed to read config FOOBAR: {}", error),
}
},
Err(error) => error!("config failed: {}", error)
}
if devc::DevC::new().is_done() { if devc::DevC::new().is_done() {
info!("gateware already loaded"); info!("gateware already loaded");
// Do not load again: assume that the gateware already present is // Do not load again: assume that the gateware already present is

View File

@ -0,0 +1,56 @@
use core::fmt;
use libboard_zynq::smoltcp::wire::{EthernetAddress, IpAddress};
use crate::config;
pub struct NetAddresses {
pub hardware_addr: EthernetAddress,
pub ipv4_addr: IpAddress,
pub ipv6_ll_addr: IpAddress,
pub ipv6_addr: Option<IpAddress>
}
impl fmt::Display for NetAddresses {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "MAC={} IPv4={} IPv6-LL={} IPv6=",
self.hardware_addr, self.ipv4_addr, self.ipv6_ll_addr)?;
match self.ipv6_addr {
Some(addr) => write!(f, "{}", addr)?,
None => write!(f, "no configured address")?
}
Ok(())
}
}
pub fn get_adresses() -> 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;
if let Ok(cfg) = config::Config::new() {
if let Ok(Ok(addr)) = cfg.read_str("mac").map(|s| s.parse()) {
hardware_addr = addr;
}
if let Ok(Ok(addr)) = cfg.read_str("ip").map(|s| s.parse()) {
ipv4_addr = addr;
}
if let Ok(Ok(addr)) = cfg.read_str("ip6").map(|s| s.parse()) {
ipv6_addr = Some(addr);
}
}
let ipv6_ll_addr = IpAddress::v6(
0xfe80, 0x0000, 0x0000, 0x0000,
(((hardware_addr.0[0] ^ 0x02) as u16) << 8) | (hardware_addr.0[1] as u16),
((hardware_addr.0[2] as u16) << 8) | 0x00ff,
0xfe00 | (hardware_addr.0[3] as u16),
((hardware_addr.0[4] as u16) << 8) | (hardware_addr.0[5] as u16));
NetAddresses {
hardware_addr: hardware_addr,
ipv4_addr: ipv4_addr,
ipv6_ll_addr: ipv6_ll_addr,
ipv6_addr: ipv6_addr
}
}

View File

@ -21,6 +21,6 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
println!("{:#08x}", ip - 2 * 4); println!("{:#08x}", ip - 2 * 4);
}); });
println!("End backtrace"); println!("End backtrace");
slcr::RegisterBlock::unlocked(|slcr| slcr.soft_reset());
loop {} loop {}
} }

View File

@ -11,7 +11,6 @@ use libcortex_a9::{enable_fpu, cache::dcci_slice};
use libboard_zynq::{ use libboard_zynq::{
self as zynq, clocks::Clocks, clocks::source::{ClockSource, ArmPll, IoPll}, self as zynq, clocks::Clocks, clocks::source::{ClockSource, ArmPll, IoPll},
logger, logger,
ps7_init,
timer::GlobalTimer, timer::GlobalTimer,
}; };
use libsupport_zynq as _; use libsupport_zynq as _;
@ -29,8 +28,6 @@ extern fn lzma_error(message: *const u8) {
#[no_mangle] #[no_mangle]
pub fn main_core0() { pub fn main_core0() {
ps7_init::apply();
GlobalTimer::start(); GlobalTimer::start();
logger::init().unwrap(); logger::init().unwrap();
log::set_max_level(log::LevelFilter::Debug); log::set_max_level(log::LevelFilter::Debug);