summaryrefslogtreecommitdiff
path: root/meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.sh
blob: 8182b4c8d211ad1daaab83e295228f785fef3846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#
# This script is used to get the MAC Address from FRU Inventory information

ETHERNET_INTERFACE="eth1"
ETHERNET_NCSI="eth0"
ENV_ETH="eth1addr"
ENV_MAC_ADDR=$(fw_printenv | grep $ENV_ETH)

# Workaround to dhcp NC-SI eth0 interface when BMC boot up
ifconfig ${ETHERNET_NCSI} down
ifconfig ${ETHERNET_NCSI} up

# Read FRU Board Custom Field 1 to get the MAC address
CUSTOM_FIELD_1=$(busctl get-property xyz.openbmc_project.FruDevice /xyz/openbmc_project/FruDevice/Mt_Jade_Motherboard xyz.openbmc_project.FruDevice BOARD_INFO_AM1)
MAC_ADDR=$(echo "$CUSTOM_FIELD_1" | cut -d "\"" -f 2)

# Check if BMC MAC address is exported
if [ -z "${MAC_ADDR}" ]; then
	echo "ERROR: No BMC MAC address is detected from FRU Inventory information!"
	# Return 1 so that systemd knows the service failed to start
	exit 1
fi

# Check if BMC MAC address is exported
if [[ $ENV_MAC_ADDR =~ $MAC_ADDR ]]; then
	echo "WARNING: BMC MAC address already exist!"
	exit 0
fi

# Request to update the MAC address
fw_setenv ${ENV_ETH} "${MAC_ADDR}"

if fw_setenv ${ENV_ETH} "${MAC_ADDR}";
then
	echo "ERROR: Fail to set MAC address to ${ENV_ETH}"
	exit 1
fi

# Request to restart the service
ifconfig ${ETHERNET_INTERFACE} down
if ! ifconfig ${ETHERNET_INTERFACE} hw ether "${MAC_ADDR}";
then
	echo "ERROR: Can not update MAC ADDR to ${ETHERNET_INTERFACE}"
	exit 1
fi
ifconfig ${ETHERNET_INTERFACE} up

echo "Successfully update the MAC address ${MAC_ADDR} to ${ENV_ETH} and ${ETHERNET_INTERFACE}"