summaryrefslogtreecommitdiff
path: root/meta-openpower
diff options
context:
space:
mode:
Diffstat (limited to 'meta-openpower')
-rwxr-xr-xmeta-openpower/recipes-phosphor/network/first-boot-set-mac/first-boot-set-mac.sh57
-rw-r--r--meta-openpower/recipes-phosphor/network/first-boot-set-mac/first-boot-set-mac@.service14
-rw-r--r--meta-openpower/recipes-phosphor/network/first-boot-set-mac_1.0.bb20
3 files changed, 91 insertions, 0 deletions
diff --git a/meta-openpower/recipes-phosphor/network/first-boot-set-mac/first-boot-set-mac.sh b/meta-openpower/recipes-phosphor/network/first-boot-set-mac/first-boot-set-mac.sh
new file mode 100755
index 0000000000..9f751a6c3c
--- /dev/null
+++ b/meta-openpower/recipes-phosphor/network/first-boot-set-mac/first-boot-set-mac.sh
@@ -0,0 +1,57 @@
+#!/bin/sh -eu
+
+show_error() {
+ logger -p user.error -t bmc-first-init $@
+}
+
+sync_mac() {
+
+ MAPPER_IFACE='xyz.openbmc_project.ObjectMapper'
+ MAPPER_PATH='/xyz/openbmc_project/object_mapper'
+ INVENTORY_PATH='/xyz/openbmc_project/inventory'
+ NETWORK_ITEM_IFACE='xyz.openbmc_project.Inventory.Item.NetworkInterface'
+
+ NETWORK_ITEM_PATH=$(busctl --no-pager --verbose call \
+ ${MAPPER_IFACE} \
+ ${MAPPER_PATH} \
+ ${MAPPER_IFACE} \
+ GetSubTree sias \
+ ${INVENTORY_PATH} 0 1 ${NETWORK_ITEM_IFACE} \
+ 2>/dev/null | grep ${INVENTORY_PATH} || true)
+
+ # ' STRING "/xyz/openbmc_project/inventory/system/chassis/ethernet";'
+ NETWORK_ITEM_PATH=${NETWORK_ITEM_PATH#*\"}
+ NETWORK_ITEM_PATH=${NETWORK_ITEM_PATH%\"*}
+
+ NETWORK_ITEM_SERVICE=$(mapper get-service \
+ ${NETWORK_ITEM_PATH} 2>/dev/null || true)
+
+ if [[ -z "${NETWORK_ITEM_SERVICE}" ]]; then
+ show_error 'No Ethernet interface found in the Inventory. Is VPD EEPROM empty?'
+ return
+ fi
+
+ MAC_ADDR=$(busctl get-property ${NETWORK_ITEM_SERVICE} \
+ ${NETWORK_ITEM_PATH} \
+ ${NETWORK_ITEM_IFACE} MACAddress)
+
+ # 's "54:52:01:02:03:04"'
+ MAC_ADDR=${MAC_ADDR#*\"}
+ MAC_ADDR=${MAC_ADDR%\"*}
+
+ if [[ -n "${MAC_ADDR}" ]]; then
+ busctl set-property xyz.openbmc_project.Network \
+ /xyz/openbmc_project/network/$1 \
+ xyz.openbmc_project.Network.MACAddress \
+ MACAddress s ${MAC_ADDR}
+ fi
+}
+
+if [ $# -eq 0 ]
+ then echo 'No Ethernet interface name is given'
+ exit 1
+fi
+
+sync_mac $1
+
+systemctl disable first-boot-set-mac@${1}.service
diff --git a/meta-openpower/recipes-phosphor/network/first-boot-set-mac/first-boot-set-mac@.service b/meta-openpower/recipes-phosphor/network/first-boot-set-mac/first-boot-set-mac@.service
new file mode 100644
index 0000000000..a7c913eb62
--- /dev/null
+++ b/meta-openpower/recipes-phosphor/network/first-boot-set-mac/first-boot-set-mac@.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Init BMC MAC address for NIC %I
+Wants=mapper-wait@-xyz-openbmc_project-inventory.service
+After=mapper-wait@-xyz-openbmc_project-inventory.service
+Wants=mapper-wait@-xyz-openbmc_project-network-%i.service
+After=mapper-wait@-xyz-openbmc_project-network-%i.service
+
+[Service]
+ExecStart=/usr/bin/first-boot-set-mac.sh %i
+Type=oneshot
+RemainAfterExit=Yes
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-openpower/recipes-phosphor/network/first-boot-set-mac_1.0.bb b/meta-openpower/recipes-phosphor/network/first-boot-set-mac_1.0.bb
new file mode 100644
index 0000000000..0fd040d418
--- /dev/null
+++ b/meta-openpower/recipes-phosphor/network/first-boot-set-mac_1.0.bb
@@ -0,0 +1,20 @@
+SUMMARY = "Init BMC MAC address"
+DESCRIPTION = "Setup BMC MAC address read from VPD"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${OPENPOWERBASE}/COPYING.apache-2.0;md5=34400b68072d710fecd0a2940a0d1658"
+
+inherit allarch systemd
+
+RDEPENDS_${PN} = "${VIRTUAL-RUNTIME_base-utils}"
+
+SYSTEMD_SERVICE_${PN} = "first-boot-set-mac@.service"
+
+SRC_URI = "file://${PN}.sh file://${PN}@.service"
+
+S = "${WORKDIR}"
+do_install() {
+ install -d ${D}${bindir} ${D}${systemd_system_unitdir}
+ install ${PN}.sh ${D}${bindir}/
+ install -m 644 ${PN}@.service ${D}${systemd_system_unitdir}/
+}