From 84bbf001289a6b45aed8ad86bc638f17983cafa7 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Mon, 7 Mar 2022 15:28:22 +0800 Subject: [PATCH] net_settings: read mac from eeprom for kasli-soc --- libconfig/src/net_settings.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libconfig/src/net_settings.rs b/libconfig/src/net_settings.rs index 453b247..0e99e12 100644 --- a/libconfig/src/net_settings.rs +++ b/libconfig/src/net_settings.rs @@ -30,6 +30,18 @@ impl fmt::Display for 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_adresses(cfg: &Config) -> NetAddresses { #[cfg(feature = "target_zc706")] let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x52]); @@ -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);