From 3c212f087b0b50c49a59d60200259b1adced25dd Mon Sep 17 00:00:00 2001 From: "Thang Q. Nguyen" Date: Mon, 20 Sep 2021 10:47:54 +0000 Subject: meta-ampere: mtjade: set MAC Address from FruDevice FruDevice service is always running no matter if entity-manager is used or not. It scans for all FRU EEPROMs, parse and store information into dbus. This commit changes to get BMC MAC Address from FruDevice data instead of ipmi-fru-parser. Tested: 1. Clear environment in u-boot, boot BMC to Linux and check if the eth1addr variable is set with value from FRU. 2. Change BMC MAC address from FRU's Board Extra. Reboot BMC and check if the eth1addr variable is set with new BMC MAC Address Signed-off-by: Thang Q. Nguyen Change-Id: I99b5d46c8a22b98402f749cdebd1c0aad3d6daf0 --- .../recipes-ac01/mac/ampere-mac-update.bb | 26 ------------ .../ampere-mac-update/ampere_update_mac.service | 12 ------ .../mac/ampere-mac-update/ampere_update_mac.sh | 43 ------------------- .../recipes-ampere/platform/ampere-mac-update.bb | 26 ++++++++++++ .../ampere-mac-update/ampere_update_mac.service | 12 ++++++ .../ampere-mac-update/ampere_update_mac.sh | 48 ++++++++++++++++++++++ 6 files changed, 86 insertions(+), 81 deletions(-) delete mode 100644 meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update.bb delete mode 100644 meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update/ampere_update_mac.service delete mode 100644 meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update/ampere_update_mac.sh create mode 100644 meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update.bb create mode 100644 meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.service create mode 100644 meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.sh 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 deleted file mode 100644 index b6ddfad80..000000000 --- a/meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update.bb +++ /dev/null @@ -1,26 +0,0 @@ -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 deleted file mode 100644 index 86f7a0346..000000000 --- a/meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update/ampere_update_mac.service +++ /dev/null @@ -1,12 +0,0 @@ -[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 deleted file mode 100644 index 5dbdde771..000000000 --- a/meta-ampere/meta-common/recipes-ac01/mac/ampere-mac-update/ampere_update_mac.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/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/recipes-ampere/platform/ampere-mac-update.bb b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update.bb new file mode 100644 index 000000000..b6ddfad80 --- /dev/null +++ b/meta-ampere/meta-jade/recipes-ampere/platform/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-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.service b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.service new file mode 100644 index 000000000..86f7a0346 --- /dev/null +++ b/meta-ampere/meta-jade/recipes-ampere/platform/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-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.sh b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.sh new file mode 100644 index 000000000..4e4d6f3e7 --- /dev/null +++ b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.sh @@ -0,0 +1,48 @@ +#!/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 [[ $? -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}" -- cgit v1.2.3