forked from M-Labs/artiq
1
0
Fork 0

firmware: read MAC/IP address configuration from flash.

This commit is contained in:
whitequark 2017-01-26 17:35:42 +00:00
parent 6c637537f0
commit 31e5f9a810
4 changed files with 36 additions and 8 deletions

View File

@ -97,7 +97,7 @@ dependencies = [
"fringe 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "fringe 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"logger_artiq 0.0.0", "logger_artiq 0.0.0",
"smoltcp 0.2.0 (git+https://github.com/m-labs/smoltcp?rev=a20f89f)", "smoltcp 0.2.1 (git+https://github.com/m-labs/smoltcp?rev=ebee5b7)",
"std_artiq 0.0.0", "std_artiq 0.0.0",
] ]
@ -115,8 +115,8 @@ dependencies = [
[[package]] [[package]]
name = "smoltcp" name = "smoltcp"
version = "0.2.0" version = "0.2.1"
source = "git+https://github.com/m-labs/smoltcp?rev=a20f89f#a20f89f5eed8ed7519c7be4c66b2f51e3fa5f6fa" source = "git+https://github.com/m-labs/smoltcp?rev=ebee5b7#ebee5b7b584399ddae91320818f116c6173fc6b4"
dependencies = [ dependencies = [
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -150,7 +150,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054" "checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
"checksum log_buffer 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ec57723b84bbe7bdf76aa93169c9b59e67473317c6de3a83cb2a0f8ccb2aa493" "checksum log_buffer 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ec57723b84bbe7bdf76aa93169c9b59e67473317c6de3a83cb2a0f8ccb2aa493"
"checksum managed 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5981b4c6de5ce272aaf2caaa56adb8f6fd24a73206b38302db572ab9374aab10" "checksum managed 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5981b4c6de5ce272aaf2caaa56adb8f6fd24a73206b38302db572ab9374aab10"
"checksum smoltcp 0.2.0 (git+https://github.com/m-labs/smoltcp?rev=a20f89f)" = "<none>" "checksum smoltcp 0.2.1 (git+https://github.com/m-labs/smoltcp?rev=ebee5b7)" = "<none>"
"checksum walkdir 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "dd7c16466ecc507c7cb5988db03e6eab4aaeab89a5c37a29251fcfd3ac9b7afe" "checksum walkdir 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "dd7c16466ecc507c7cb5988db03e6eab4aaeab89a5c37a29251fcfd3ac9b7afe"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"

View File

@ -23,6 +23,6 @@ byteorder = { version = "1.0", default-features = false }
[dependencies.smoltcp] [dependencies.smoltcp]
git = "https://github.com/m-labs/smoltcp" git = "https://github.com/m-labs/smoltcp"
rev = "a20f89f" rev = "ebee5b7"
default-features = false default-features = false
features = ["use_alloc", "use_collections", "use_log"]#, "verbose"] features = ["use_alloc", "use_collections", "use_log"]#, "verbose"]

View File

@ -1,5 +1,6 @@
use std::cmp; use std::cmp;
use std::vec::Vec; use std::vec::Vec;
use std::string::String;
use libc::{c_void, c_char, c_int, c_uint}; use libc::{c_void, c_char, c_int, c_uint};
extern { extern {
@ -44,6 +45,10 @@ pub fn read_to_end(key: &str) -> Vec<u8> {
value value
} }
pub fn read_string(key: &str) -> String {
String::from_utf8(read_to_end(key)).unwrap()
}
pub fn write(key: &str, buf: &[u8]) -> Result<(), ()> { pub fn write(key: &str, buf: &[u8]) -> Result<(), ()> {
let key_c = c_str!(key); let key_c = c_str!(key);
let result = unsafe { let result = unsafe {

View File

@ -15,6 +15,7 @@ extern crate smoltcp;
extern crate board; extern crate board;
use std::boxed::Box; use std::boxed::Box;
use smoltcp::wire::{EthernetAddress, IpAddress};
extern { extern {
fn readchar() -> libc::c_char; fn readchar() -> libc::c_char;
@ -81,6 +82,30 @@ fn startup() {
#[cfg(has_converter_spi)] #[cfg(has_converter_spi)]
board::ad9154::init().expect("cannot initialize ad9154"); board::ad9154::init().expect("cannot initialize ad9154");
let hardware_addr;
match EthernetAddress::parse(&config::read_string("mac")) {
Err(()) => {
hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]);
warn!("using default MAC address {}; consider changing it", hardware_addr);
}
Ok(addr) => {
hardware_addr = addr;
info!("using MAC address {}", hardware_addr);
}
}
let protocol_addr;
match IpAddress::parse(&config::read_string("ip")) {
Err(()) | Ok(IpAddress::Unspecified) => {
protocol_addr = IpAddress::v4(192, 168, 1, 50);
info!("using default IP address {}", protocol_addr);
}
Ok(addr) => {
protocol_addr = addr;
info!("using IP address {}", protocol_addr);
}
}
fn _net_trace_writer<U>(printer: smoltcp::wire::PrettyPrinter<U>) fn _net_trace_writer<U>(printer: smoltcp::wire::PrettyPrinter<U>)
where U: smoltcp::wire::pretty_print::PrettyPrint { where U: smoltcp::wire::pretty_print::PrettyPrint {
print!("\x1b[37m{}\x1b[0m", printer) print!("\x1b[37m{}\x1b[0m", printer)
@ -90,11 +115,9 @@ fn startup() {
// let net_device = smoltcp::phy::Tracer::<_, smoltcp::wire::EthernetFrame<&[u8]>> // let net_device = smoltcp::phy::Tracer::<_, smoltcp::wire::EthernetFrame<&[u8]>>
// ::new(net_device, _net_trace_writer); // ::new(net_device, _net_trace_writer);
let arp_cache = smoltcp::iface::SliceArpCache::new([Default::default(); 8]); let arp_cache = smoltcp::iface::SliceArpCache::new([Default::default(); 8]);
let hardware_addr = smoltcp::wire::EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]);
let protocol_addrs = [smoltcp::wire::IpAddress::v4(192, 168, 1, 50)];
let mut interface = smoltcp::iface::EthernetInterface::new( let mut interface = smoltcp::iface::EthernetInterface::new(
Box::new(net_device), Box::new(arp_cache) as Box<smoltcp::iface::ArpCache>, Box::new(net_device), Box::new(arp_cache) as Box<smoltcp::iface::ArpCache>,
hardware_addr, protocol_addrs); hardware_addr, [protocol_addr]);
let mut scheduler = sched::Scheduler::new(); let mut scheduler = sched::Scheduler::new();
let io = scheduler.io(); let io = scheduler.io();