From 43e0440911e13b58e88fbbdbac01a073841f4943 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Mon, 7 Mar 2022 18:01:44 +0800 Subject: [PATCH] Kasli-SoC: Get MAC address from EEPROM (#90) Co-authored-by: mwojcik Co-committed-by: mwojcik --- Cargo.toml | 2 +- libconfig/src/net_settings.rs | 16 ++++++++++++++-- szl/src/netboot.rs | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c23f4aa..8f18210 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ members = [ panic = "abort" debug = true codegen-units = 1 -opt-level = 'z' +opt-level = 's' lto = true debug-assertions = false overflow-checks = false diff --git a/libconfig/src/net_settings.rs b/libconfig/src/net_settings.rs index 453b247..fa3079f 100644 --- a/libconfig/src/net_settings.rs +++ b/libconfig/src/net_settings.rs @@ -30,7 +30,19 @@ impl fmt::Display for NetAddresses { } } -pub fn get_adresses(cfg: &Config) -> NetAddresses { +#[cfg(feature = "target_kasli_soc")] +fn get_address_from_eeprom() -> EthernetAddress { + use libboard_zynq::i2c::{I2c, eeprom}; + + let mut i2c = I2c::i2c0(); + i2c.init().unwrap(); + let mut eeprom = eeprom::EEPROM::new(&mut i2c, 16); + let address = eeprom.read_eui48().unwrap_or([0x02, 0x00, 0x00, 0x00, 0x00, 0x56]); + + EthernetAddress(address) +} + +pub fn get_addresses(cfg: &Config) -> NetAddresses { #[cfg(feature = "target_zc706")] let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x52]); #[cfg(feature = "target_zc706")] @@ -44,7 +56,7 @@ pub fn get_adresses(cfg: &Config) -> NetAddresses { #[cfg(feature = "target_redpitaya")] let mut ipv4_addr = IpAddress::v4(192, 168, 1, 55); #[cfg(feature = "target_kasli_soc")] - let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x56]); + let mut hardware_addr = get_address_from_eeprom(); #[cfg(feature = "target_kasli_soc")] let mut ipv4_addr = IpAddress::v4(192, 168, 1, 56); diff --git a/szl/src/netboot.rs b/szl/src/netboot.rs index 02ff235..8552a6e 100644 --- a/szl/src/netboot.rs +++ b/szl/src/netboot.rs @@ -316,7 +316,7 @@ pub fn netboot( runtime_max_len: usize, ) { log::info!("Preparing network for netboot"); - let net_addresses = net_settings::get_adresses(&cfg); + let net_addresses = net_settings::get_addresses(&cfg); log::info!("Network addresses: {}", net_addresses); let eth = Eth::eth0(net_addresses.hardware_addr.0.clone()); let eth = eth.start_rx(8);