meta-ampere: mtjade: network: use sync-mac for MAC from FRU

Switch to use phosphor-networkd's sync-mac feature to get and use MAC
address from FRU, replacing Ampere approach.

Tested:
1. Boot the BMC to Linux and login to console
2. Get BMC MAC address in FRU
$ ipmitool fru print 0 | grep "Board Extra"
 Board Extra           : 70:E2:84:8F:E3:56
3. Check eth0 HWaddr with MAC in FRU
$ ifconfig eth1 | grep HWaddr
eth1      Link encap:Ethernet  HWaddr 70:E2:84:8F:E3:56

Signed-off-by: Thang Q. Nguyen <thang@os.amperecomputing.com>
Signed-off-by: Khang Nguyen <khangng@amperecomputing.com>
Change-Id: I7121fde2f7b8d673e3ae0b1e5a03f175a10ea578
diff --git a/meta-ampere/meta-common/recipes-ampere/network/ampere-usbnet/ampere_usbnet.sh b/meta-ampere/meta-common/recipes-ampere/network/ampere-usbnet/ampere_usbnet.sh
index 42bd39c..ca9357f 100644
--- a/meta-ampere/meta-common/recipes-ampere/network/ampere-usbnet/ampere_usbnet.sh
+++ b/meta-ampere/meta-common/recipes-ampere/network/ampere-usbnet/ampere_usbnet.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-ENV_MAC_ADDR=$(fw_printenv bmc_macaddr)
+ENV_MAC_ADDR=$(fw_printenv ethaddr eth1addr)
 
 MAC_ADDR=$(echo "$ENV_MAC_ADDR" | cut -d "=" -f 2)
 
diff --git a/meta-ampere/meta-common/recipes-ampere/platform/ampere-utils.bb b/meta-ampere/meta-common/recipes-ampere/platform/ampere-utils.bb
index 7c71b95..4f83acf 100644
--- a/meta-ampere/meta-common/recipes-ampere/platform/ampere-utils.bb
+++ b/meta-ampere/meta-common/recipes-ampere/platform/ampere-utils.bb
@@ -6,7 +6,6 @@
 
 SRC_URI = " \
            file://ampere_add_redfishevent.sh \
-           file://ampere_update_mac.sh \
            file://ampere_spi_util.sh \
            file://ampere_power_control_lock.sh \
           "
@@ -16,7 +15,6 @@
 do_install() {
     install -d ${D}/usr/sbin
     install -m 0755 ${WORKDIR}/ampere_add_redfishevent.sh ${D}/${sbindir}/
-    install -m 0755 ${WORKDIR}/ampere_update_mac.sh ${D}/${sbindir}/
     install -m 0755 ${WORKDIR}/ampere_spi_util.sh ${D}/${sbindir}/
     install -m 0755 ${WORKDIR}/ampere_power_control_lock.sh ${D}/${sbindir}/
 }
diff --git a/meta-ampere/meta-common/recipes-ampere/platform/ampere-utils/ampere_update_mac.sh b/meta-ampere/meta-common/recipes-ampere/platform/ampere-utils/ampere_update_mac.sh
deleted file mode 100644
index 6be938a..0000000
--- a/meta-ampere/meta-common/recipes-ampere/platform/ampere-utils/ampere_update_mac.sh
+++ /dev/null
@@ -1,115 +0,0 @@
-#!/bin/bash
-#
-# This script is used to get the BMC MAC Address from FRU EEPROM at Board Extra.
-# and if the eth address is not exist on U-boot Enviroment, this script will update it.
-#
-
-function Usage () {
-	echo "Usage:"
-	echo "      ampere_update_mac.sh <ethX> <fru bus> <fru addr>"
-	echo "Example:"
-	echo "      ampere_update_mac.sh eth1 3 80"
-}
-
-function read_mac_address () {
-	fruBus=$1
-	fruAddr=$2
-
-	if FRU_OBJECT_PATH=$(busctl tree xyz.openbmc_project.FruDevice | grep "/xyz/openbmc_project/FruDevice/" | tr -s '\n' ' ' | tr -d "|-" | tr -d '`')
-	then
-		IFS=' ' read -r -a FRU_OBJ_PATH_ARR <<< "$FRU_OBJECT_PATH"
-
-		for fruObj in "${FRU_OBJ_PATH_ARR[@]}"
-		do
-			BUS_IDX_RW=$(busctl get-property xyz.openbmc_project.FruDevice "$fruObj" xyz.openbmc_project.FruDevice BUS)
-			BUS_ADDR_RW=$(busctl get-property xyz.openbmc_project.FruDevice "$fruObj" xyz.openbmc_project.FruDevice ADDRESS)
-
-			if [ -z "$BUS_IDX_RW" ] || [ -z "$BUS_IDX_RW" ]; then
-				continue
-			else
-				BUS_IDX_CV=$(echo "$BUS_IDX_RW" | cut -d " " -f 2)
-				BUS_ADDR_CV=$(echo "$BUS_ADDR_RW" | cut -d " " -f 2)
-				if [ "$BUS_IDX_CV" != "$fruBus" ] || [ "$BUS_ADDR_CV" != "$fruAddr" ]; then
-					continue
-				fi
-			fi
-
-			MAC_ADDR_RAW=$(busctl get-property xyz.openbmc_project.FruDevice "$fruObj" xyz.openbmc_project.FruDevice BOARD_INFO_AM1)
-			MAC_ADDR=$(echo "$MAC_ADDR_RAW" | cut -d "\"" -f 2)
-			break
-		done
-	fi
-	echo "$MAC_ADDR"
-}
-
-ETHERNET_INTERFACE=$1
-BMC_FRU_BUS=$2
-BMC_FRU_ADDR=$3
-
-if [ -z "$BMC_FRU_ADDR" ];
-then
-	Usage
-	exit
-fi
-
-# Check eth port
-case ${ETHERNET_INTERFACE} in
-	"eth0")
-		ENV_PORT="1"
-		;;
-	"eth1")
-		ENV_PORT="2"
-		;;
-	"eth2")
-		ENV_PORT="3"
-		;;
-	*)
-		Usage
-		exit
-		;;
-esac
-
-# Read FRU Board Custom Field 1 to get the MAC address
-for i in {1..10}; do
-	MAC_ADDR=$(read_mac_address "$BMC_FRU_BUS" "$BMC_FRU_ADDR")
-
-	# Check if BMC MAC address is exported
-	if [ -z "${MAC_ADDR}" ]; then
-		sleep 2
-		continue
-	fi
-
-	if echo "$MAC_ADDR" | grep -q -vE "^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$" ; then
-		echo "ERROR: No valid BMC MAC Address detected from BMC FRU! $MAC_ADDR"
-		exit 0
-	else
-		echo "mac-update: detect BMC MAC $MAC_ADDR at loop $i"
-		break
-	fi
-done
-
-# Check if the Ethernet port has correct MAC Address
-ETH_INCLUDE_MAC=$(ifconfig "${ETHERNET_INTERFACE}" | grep -i "$MAC_ADDR")
-if [ -n "$ETH_INCLUDE_MAC" ]; then
-	echo "BMC MAC Address is already configured"
-	exit 0
-fi
-
-# Request to restart the service
-ifconfig "${ETHERNET_INTERFACE}" down
-fw_setenv bmc_macaddr "${MAC_ADDR}"
-
-ifconfig "${ETHERNET_INTERFACE}" hw ether "${MAC_ADDR}"
-retval=$?
-if [[ $retval -ne 0 ]]; then
-	echo "ERROR: Can not update MAC ADDR to ${ETHERNET_INTERFACE}"
-	exit 1
-fi
-# Setting LAN MAC Address to xx:xx:xx:xx:xx:xx
-ipmitool lan set "${ENV_PORT}" macaddr "${ETHERNET_INTERFACE}"
-# Enableing BMC-generated ARP responses & Setting SNMP Community String to public
-ipmitool lan set "${ENV_PORT}" arp respond on
-ipmitool lan set "${ENV_PORT}" snmp public
-ifconfig "${ETHERNET_INTERFACE}" up
-
-echo "Successfully update the MAC address ${MAC_ADDR} to ${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
deleted file mode 100644
index 7deb05a..0000000
--- a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update.bb
+++ /dev/null
@@ -1,18 +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}:"
-
-SYSTEMD_SERVICE:${PN} = "ampere_update_mac.service"
-
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
deleted file mode 100644
index 98494b7..0000000
--- a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-mac-update/ampere_update_mac.service
+++ /dev/null
@@ -1,13 +0,0 @@
-[Unit]
-Description=Updating MAC Address Service From FRU inventory
-Requires=xyz.openbmc_project.EntityManager.service
-After=xyz.openbmc_project.EntityManager.service
-
-[Service]
-ExecStart=/usr/sbin/ampere_update_mac.sh eth1 3 80
-SyslogIdentifier=ampere_update_mac.sh
-Type=oneshot
-RemainAfterExit=yes
-
-[Install]
-WantedBy={SYSTEMD_DEFAULT_TARGET}
diff --git a/meta-ampere/meta-jade/recipes-phosphor/network/phosphor-network/config.json b/meta-ampere/meta-jade/recipes-phosphor/network/phosphor-network/config.json
new file mode 100644
index 0000000..14ef18c
--- /dev/null
+++ b/meta-ampere/meta-jade/recipes-phosphor/network/phosphor-network/config.json
@@ -0,0 +1,3 @@
+{
+    "eth1": ""
+}
diff --git a/meta-ampere/meta-jade/recipes-phosphor/network/phosphor-network_%.bbappend b/meta-ampere/meta-jade/recipes-phosphor/network/phosphor-network_%.bbappend
new file mode 100644
index 0000000..2f2ee59
--- /dev/null
+++ b/meta-ampere/meta-jade/recipes-phosphor/network/phosphor-network_%.bbappend
@@ -0,0 +1,11 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
+
+PACKAGECONFIG:append = " sync-mac "
+
+SRC_URI:append = " file://config.json "
+FILES:${PN} += "${datadir}/network/*.json"
+
+do_install:append() {
+    install -d ${D}${datadir}/network/
+    install -m 0644 ${WORKDIR}/config.json ${D}${datadir}/network/
+}