diff options
author | Thang Q. Nguyen <thang@os.amperecomputing.com> | 2021-02-06 04:22:45 +0300 |
---|---|---|
committer | Thang Q. Nguyen <thang@os.amperecomputing.com> | 2021-02-09 01:44:37 +0300 |
commit | 72eb151aeec4b22bba618db928eed6c401e021af (patch) | |
tree | 7a818596b14556df34147e71296c9a9b74f328cc /meta-ampere | |
parent | 38e84136d5ea0f52126d7c2a1c629e0eb3653039 (diff) | |
download | openbmc-72eb151aeec4b22bba618db928eed6c401e021af.tar.xz |
meta-ampere: Set BMC MAC Address from FRU inventory
Support to get BMC MAC address from FRU over the FRU inventory
information (/xyz/openbmc_project/inventory/system/chassis/motherboard)
and update to the eth0 Ethernet interface and set the eth1addr u-boot
variable.
Tested:
1. Boot to u-boot, clear the eth1addr variable, save and reboot.
2. Boot to Linux:
- Check if the eth0 interface uses the MAC address in FRU.
root@mtjade:~# ip addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 70:e2:84:86:76:ba brd ff:ff:ff:ff:ff:ff
- Check if the eth1addr u-boot variable uses the MAC address in FRU
root@mtjade:~# fw_printenv eth1addr
eth1addr=70:E2:84:86:76:BA
Signed-off-by: Chanh Nguyen <chanh@os.amperecomputing.com>
Signed-off-by: Thang Q. Nguyen <thang@os.amperecomputing.com>
Change-Id: Ifb7eefbb17257545d026005f859d37ef562289b7
Diffstat (limited to 'meta-ampere')
4 files changed, 82 insertions, 0 deletions
diff --git a/meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update.bb b/meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update.bb new file mode 100644 index 000000000..3e18ad71e --- /dev/null +++ b/meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update.bb @@ -0,0 +1,26 @@ +SUMMARY = "Ampere Computing LLC Update MAC Address from FRU Inventory Information" +DESCRIPTION = "Update MAC Address from FRU Inventory Information for Ampere systems" +PR = "r1" + +LICENSE = "Apache-2.0" + +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10" + +inherit systemd +inherit obmc-phosphor-systemd + +DEPENDS = "systemd" +RDEPENDS_${PN} = "bash" + +FILESEXTRAPATHS_append := "${THISDIR}/${PN}:" + +SRC_URI += " \ + file://ampere_update_mac.sh \ + " + +SYSTEMD_SERVICE_${PN} = "ampere_update_mac.service" + +do_install_append() { + install -d ${D}/${sbindir} + install -m 755 ${WORKDIR}/ampere_update_mac.sh ${D}/${sbindir} +} diff --git a/meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update/ampere_update_mac.service b/meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update/ampere_update_mac.service new file mode 100644 index 000000000..86f7a0346 --- /dev/null +++ b/meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update/ampere_update_mac.service @@ -0,0 +1,12 @@ +[Unit] +Description=Updating MAC Address Service From FRU inventory +After=xyz.openbmc_project.Inventory.Manager.service + +[Service] +ExecStart=/usr/sbin/ampere_update_mac.sh +SyslogIdentifier=ampere_update_mac.sh +Type=oneshot +RemainAfterExit=yes + +[Install] +WantedBy={SYSTEMD_DEFAULT_TARGET} diff --git a/meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update/ampere_update_mac.sh b/meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update/ampere_update_mac.sh new file mode 100644 index 000000000..5dbdde771 --- /dev/null +++ b/meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update/ampere_update_mac.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# +# This script is used to get the MAC Address from FRU Inventory information + +ETHERNET_INTERFACE="eth0" +ENV_ETH="eth1addr" +ENV_MAC_ADDR=`fw_printenv` + +# Check if BMC MAC address is exported +if [[ $ENV_MAC_ADDR =~ $ENV_ETH ]]; then + echo "WARNING: BMC MAC address already exist!" + exit 0 +fi + +# Read FRU Board Custom Field 1 to get the MAC address +CUSTOM_FIELD_1=`busctl get-property xyz.openbmc_project.Inventory.Manager /xyz/openbmc_project/inventory/system/chassis/motherboard xyz.openbmc_project.Inventory.Item.NetworkInterface MACAddress` +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 + +# Request to update the MAC address +fw_setenv ${ENV_ETH} ${MAC_ADDR} + +if [[ $? -ne 0 ]]; then + echo "ERROR: Fail to set MAC address to ${ENV_ETH}" + exit 1 +fi + +# Request to restart the service +ifconfig ${ETHERNET_INTERFACE} down +ifconfig ${ETHERNET_INTERFACE} hw ether ${MAC_ADDR} +if [[ $? -ne 0 ]]; 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}" diff --git a/meta-ampere/meta-jade/conf/machine/mtjade.conf b/meta-ampere/meta-jade/conf/machine/mtjade.conf index 218018953..ec6e27f17 100644 --- a/meta-ampere/meta-jade/conf/machine/mtjade.conf +++ b/meta-ampere/meta-jade/conf/machine/mtjade.conf @@ -18,6 +18,7 @@ VOLATILE_LOG_DIR = "no" OBMC_IMAGE_EXTRA_INSTALL_append = "\ ampere-usbnet \ ampere-flash-utils \ + ampere-mac-update \ " PREFERRED_PROVIDER_virtual/obmc-chassis-mgmt = "packagegroup-ampere-apps" |