Message ID | 20211009173346.7859-10-kabel@kernel.org |
---|---|
State | Accepted |
Commit | 1335e31ecc2cd7e4e51b730499198c7548ac0a3f |
Delegated to: | Stefan Roese |
Headers | show |
Series | Small Turris MOX and Omnia changes | expand |
On 09.10.21 19:33, Marek Behún wrote: > From: Marek Behún <marek.behun@nic.cz> > > Currently we always overwrite ethaddrs with those from EEPROM. > > In order to allow user to use a cloned MAC address in U-Boot, change the > code so that it sets ethaddr variables only if they aren't set or are > invalid. > > Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de> Thanks, Stefan > --- > board/CZ.NIC/turris_omnia/turris_omnia.c | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) > > diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c > index a48e1f5c30..7a86111890 100644 > --- a/board/CZ.NIC/turris_omnia/turris_omnia.c > +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c > @@ -518,6 +518,15 @@ static void increment_mac(u8 *mac) > } > } > > +static void set_mac_if_invalid(int i, u8 *mac) > +{ > + u8 oldmac[6]; > + > + if (is_valid_ethaddr(mac) && > + !eth_env_get_enetaddr_by_index("eth", i, oldmac)) > + eth_env_set_enetaddr_by_index("eth", i, mac); > +} > + > int misc_init_r(void) > { > int err; > @@ -550,18 +559,11 @@ int misc_init_r(void) > mac[4] = mac1[2]; > mac[5] = mac1[3]; > > - if (is_valid_ethaddr(mac)) > - eth_env_set_enetaddr("eth1addr", mac); > - > + set_mac_if_invalid(1, mac); > increment_mac(mac); > - > - if (is_valid_ethaddr(mac)) > - eth_env_set_enetaddr("eth2addr", mac); > - > + set_mac_if_invalid(2, mac); > increment_mac(mac); > - > - if (is_valid_ethaddr(mac)) > - eth_env_set_enetaddr("ethaddr", mac); > + set_mac_if_invalid(0, mac); > > out: > return 0; > Viele Grüße, Stefan
diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c index a48e1f5c30..7a86111890 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -518,6 +518,15 @@ static void increment_mac(u8 *mac) } } +static void set_mac_if_invalid(int i, u8 *mac) +{ + u8 oldmac[6]; + + if (is_valid_ethaddr(mac) && + !eth_env_get_enetaddr_by_index("eth", i, oldmac)) + eth_env_set_enetaddr_by_index("eth", i, mac); +} + int misc_init_r(void) { int err; @@ -550,18 +559,11 @@ int misc_init_r(void) mac[4] = mac1[2]; mac[5] = mac1[3]; - if (is_valid_ethaddr(mac)) - eth_env_set_enetaddr("eth1addr", mac); - + set_mac_if_invalid(1, mac); increment_mac(mac); - - if (is_valid_ethaddr(mac)) - eth_env_set_enetaddr("eth2addr", mac); - + set_mac_if_invalid(2, mac); increment_mac(mac); - - if (is_valid_ethaddr(mac)) - eth_env_set_enetaddr("ethaddr", mac); + set_mac_if_invalid(0, mac); out: return 0;