[sonic-cfg] [Marvell] read system mac address from eeprom (#3309)

* [sonic-cfg] [Marvell] get_system_mac() to fetch valid mac address from Eeprom else
get mac address from eth0

* [platform] Marvell mac address fetch for different platform based on board

Signed-off-by: Antony Rheneus <arheneus@marvell.com>
This commit is contained in:
arheneus@marvell.com 2019-08-08 23:34:07 +05:30 committed by lguohan
parent d16ece23bb
commit 17b5fd2b5f

View File

@ -65,16 +65,24 @@ def get_system_mac():
if valid_mac_address(mac):
return mac
get_mac_cmd = "sudo decode-syseeprom -m"
hw_mac_entry_cmds = [ "sudo decode-syseeprom -m" ]
elif (version_info['asic_type'] == 'marvell'):
# Try valid mac in eeprom, else fetch it from eth0
platform = get_platform_info(get_machine_info())
hwsku = get_machine_info()['onie_machine']
profile_cmd = 'cat /usr/share/sonic/device/' + platform +'/'+ hwsku +'/profile.ini | cut -f2 -d='
hw_mac_entry_cmds = [ profile_cmd, "sudo decode-syseeprom -m", "ip link show eth0 | grep ether | awk '{print $2}'" ]
else:
get_mac_cmd = "ip link show eth0 | grep ether | awk '{print $2}'"
hw_mac_entry_cmds = [ "ip link show eth0 | grep ether | awk '{print $2}'" ]
proc = subprocess.Popen(get_mac_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(mac, err) = proc.communicate()
if err:
return None
mac = mac.strip()
for get_mac_cmd in hw_mac_entry_cmds:
proc = subprocess.Popen(get_mac_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(mac, err) = proc.communicate()
if err:
continue
mac = mac.strip()
if valid_mac_address(mac):
break
if not valid_mac_address(mac):
return None