meta-gbmc-staging: gbmc-sysinit: Refactor for multi-platform support
This commit refactors the gbmc-sysinit recipe to support multiple
platforms (server2 and server3) from a common code base.
- A new `gbmc-sysinit.inc` file has been created to hold common
variables and tasks shared between the different platform recipes.
- The original `gbmc-sysinit.bb` has been renamed to
`gbmc-sysinit_server2.bb` and updated to `require` the new `.inc`
file. Its associated source files have been moved to a `server2/`
subdirectory.
- A new `gbmc-sysinit_server3.bb` recipe has been added to support the
server3 platform. This recipe also uses the common `.inc` file and
adds its own set of systemd services and helper scripts, which are
located in a new `server3/` subdirectory.
- The `transfer_bios_image_to_dram` function in the server3 helper
script is intentionally left as a stub, as it is designed to be
overridden by a machine-specific layer.
Tested: build and run on a Server3.0 machine and everything works as
expected.
Google-Bug-Id: 408930097
Change-Id: I18b867ae08b150d671c435563fd31f2bd356239f
Signed-off-by: Tom Tung <tomtung@google.com>
diff --git a/recipes-google/gbmc-sysinit/gbmc-sysinit.inc b/recipes-google/gbmc-sysinit/gbmc-sysinit.inc
new file mode 100644
index 0000000..f91141d
--- /dev/null
+++ b/recipes-google/gbmc-sysinit/gbmc-sysinit.inc
@@ -0,0 +1,10 @@
+S = "${WORKDIR}"
+
+inherit systemd
+
+DEPENDS = "systemd"
+RDEPENDS:${PN} += "bash"
+
+SRC_URI += "file://prodid-override.conf"
+
+SYSTEMD_PACKAGES = "${PN}"
diff --git a/recipes-google/gbmc-sysinit/gbmc-sysinit/prodid-override.conf b/recipes-google/gbmc-sysinit/gbmc-sysinit/prodid-override.conf
new file mode 100644
index 0000000..40daaf4
--- /dev/null
+++ b/recipes-google/gbmc-sysinit/gbmc-sysinit/prodid-override.conf
@@ -0,0 +1,3 @@
+[Unit]
+Requires=hothd.service
+After=hothd.service
diff --git a/recipes-google/gbmc-sysinit/gbmc-sysinit.bb b/recipes-google/gbmc-sysinit/gbmc-sysinit_server2.bb
similarity index 73%
rename from recipes-google/gbmc-sysinit/gbmc-sysinit.bb
rename to recipes-google/gbmc-sysinit/gbmc-sysinit_server2.bb
index b2172d0..2be113e 100644
--- a/recipes-google/gbmc-sysinit/gbmc-sysinit.bb
+++ b/recipes-google/gbmc-sysinit/gbmc-sysinit_server2.bb
@@ -1,24 +1,22 @@
-SUMMARY = "gBMC System Initialization Service"
+SUMMARY = "gBMC System Initialization Service for Server 2.0 platforms"
DESCRIPTION = "Verify the BIOS and release initalize the system"
PR = "r1"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
-S = "${WORKDIR}"
+require gbmc-sysinit.inc
-inherit systemd
+FILESEXTRAPATHS:prepend := "${THISDIR}/server2:"
-DEPENDS = "systemd"
-RDEPENDS:${PN} = " \
- bash \
- libsystemd \
+FILES:${PN}:append = " \
+ ${systemd_system_unitdir}/gbmc-sysinit.service.d/prodid-override.conf \
"
BIOS_PARTITION ?= "bios-primary"
BIOS_SIZE ?= "67108864"
BIOS_KEY ?= "/usr/share/google-bios-key/platforms_secure.pem"
-SRC_URI = " \
+SRC_URI += " \
file://gbmc_sysinit.sh.in \
file://gbmc_sysinit_helper.sh \
file://gbmc-host-ready.target \
@@ -47,4 +45,8 @@
install -d ${D}${datadir}/gbmc-sysinit
install -m 0755 ${WORKDIR}/gbmc_sysinit_helper.sh ${D}${datadir}/gbmc-sysinit/
+
+ install -d ${D}${systemd_system_unitdir}/gbmc-sysinit.service.d
+ install -m 0644 ${WORKDIR}/prodid-override.conf \
+ ${D}${systemd_system_unitdir}/gbmc-sysinit.service.d/
}
diff --git a/recipes-google/gbmc-sysinit/gbmc-sysinit_server3.bb b/recipes-google/gbmc-sysinit/gbmc-sysinit_server3.bb
new file mode 100644
index 0000000..cc2748a
--- /dev/null
+++ b/recipes-google/gbmc-sysinit/gbmc-sysinit_server3.bb
@@ -0,0 +1,59 @@
+SUMMARY = "gBMC System Initialization Service for Server 3.0"
+DESCRIPTION = "Verify the BIOS and release initalize the system"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+require gbmc-sysinit.inc
+
+FILESEXTRAPATHS:prepend := "${THISDIR}/server3:"
+
+SRC_URI += " \
+ file://gbmc_sysinit.sh \
+ file://gbmc_sysinit_helper.sh \
+ file://wait_emmc_available.sh \
+ file://gbmc-release-host@.service \
+ file://gbmc-sysinit@.service \
+ file://emmc-wait.service \
+"
+
+FILES:${PN}:append = " \
+ ${systemd_system_unitdir}/gbmc-sysinit@.service.d/prodid-override.conf \
+"
+
+SYSTEMD_SERVICE:${PN}:append = " \
+ gbmc-sysinit@.service \
+ gbmc-release-host@.service \
+ emmc-wait.service \
+"
+
+do_install:append () {
+ install -d ${D}${bindir}
+ install -m 0755 ${WORKDIR}/gbmc_sysinit.sh ${D}${bindir}/
+ install -m 0755 ${WORKDIR}/wait_emmc_available.sh ${D}${bindir}/
+
+ install -d ${D}${systemd_system_unitdir}
+ install -m 0644 ${WORKDIR}/gbmc-release-host@.service \
+ ${D}${systemd_system_unitdir}
+ install -m 0644 ${WORKDIR}/gbmc-sysinit@.service \
+ ${D}${systemd_system_unitdir}
+ install -m 0644 ${WORKDIR}/emmc-wait.service \
+ ${D}${systemd_system_unitdir}
+
+ install -d ${D}${datadir}/${PN}
+ install -m 0755 ${WORKDIR}/gbmc_sysinit_helper.sh ${D}${datadir}/${PN}
+
+ install -d ${D}${systemd_system_unitdir}/gbmc-sysinit@.service.d
+ install -m 0644 ${WORKDIR}/prodid-override.conf \
+ ${D}${systemd_system_unitdir}/gbmc-sysinit@.service.d/
+}
+
+HOST_NODES ??= "0 1"
+
+pkg_postinst:${PN} () {
+ for node in ${HOST_NODES};
+ do
+ systemctl --root=$D enable gbmc-sysinit@${node}.service
+ systemctl --root=$D enable gbmc-release-host@${node}.service
+ done
+}
diff --git a/recipes-google/gbmc-sysinit/gbmc-sysinit/gbmc-host-ready.target b/recipes-google/gbmc-sysinit/server2/gbmc-host-ready.target
similarity index 100%
rename from recipes-google/gbmc-sysinit/gbmc-sysinit/gbmc-host-ready.target
rename to recipes-google/gbmc-sysinit/server2/gbmc-host-ready.target
diff --git a/recipes-google/gbmc-sysinit/gbmc-sysinit/gbmc-sysinit.service b/recipes-google/gbmc-sysinit/server2/gbmc-sysinit.service
similarity index 84%
rename from recipes-google/gbmc-sysinit/gbmc-sysinit/gbmc-sysinit.service
rename to recipes-google/gbmc-sysinit/server2/gbmc-sysinit.service
index 64f5714..2ff71ea 100644
--- a/recipes-google/gbmc-sysinit/gbmc-sysinit/gbmc-sysinit.service
+++ b/recipes-google/gbmc-sysinit/server2/gbmc-sysinit.service
@@ -2,8 +2,6 @@
Description=gBMC System Initialization and release Host from reset
Requires=gbmc-host-ready.target
After=gbmc-host-ready.target
-Requires=hothd.service
-After=hothd.service
[Service]
Type=oneshot
diff --git a/recipes-google/gbmc-sysinit/gbmc-sysinit/gbmc_sysinit.sh.in b/recipes-google/gbmc-sysinit/server2/gbmc_sysinit.sh.in
similarity index 100%
rename from recipes-google/gbmc-sysinit/gbmc-sysinit/gbmc_sysinit.sh.in
rename to recipes-google/gbmc-sysinit/server2/gbmc_sysinit.sh.in
diff --git a/recipes-google/gbmc-sysinit/gbmc-sysinit/gbmc_sysinit_helper.sh b/recipes-google/gbmc-sysinit/server2/gbmc_sysinit_helper.sh
similarity index 100%
rename from recipes-google/gbmc-sysinit/gbmc-sysinit/gbmc_sysinit_helper.sh
rename to recipes-google/gbmc-sysinit/server2/gbmc_sysinit_helper.sh
diff --git a/recipes-google/gbmc-sysinit/server3/emmc-wait.service b/recipes-google/gbmc-sysinit/server3/emmc-wait.service
new file mode 100644
index 0000000..17fd1e2
--- /dev/null
+++ b/recipes-google/gbmc-sysinit/server3/emmc-wait.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Wait for eMMC to become available
+DefaultDependencies=no
+
+[Service]
+Type=oneshot
+TimeoutStartSec=330s
+ExecStart=/usr/bin/wait_emmc_available.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/recipes-google/gbmc-sysinit/server3/gbmc-release-host@.service b/recipes-google/gbmc-sysinit/server3/gbmc-release-host@.service
new file mode 100644
index 0000000..dd68c46
--- /dev/null
+++ b/recipes-google/gbmc-sysinit/server3/gbmc-release-host@.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=The HPM%i is ready to be powered on
+Requires=gbmc-sysinit@%i.service
+After=gbmc-sysinit@%i.service
+
+[Install]
+WantedBy=multi-user.target
diff --git a/recipes-google/gbmc-sysinit/server3/gbmc-sysinit@.service b/recipes-google/gbmc-sysinit/server3/gbmc-sysinit@.service
new file mode 100644
index 0000000..7074461
--- /dev/null
+++ b/recipes-google/gbmc-sysinit/server3/gbmc-sysinit@.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=gBMC System Initialization and release Host %i from reset
+Requires=emmc-wait.service
+After=emmc-wait.service
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/gbmc_sysinit.sh %i
+
+[Install]
+WantedBy=multi-user.target
+
diff --git a/recipes-google/gbmc-sysinit/server3/gbmc_sysinit.sh b/recipes-google/gbmc-sysinit/server3/gbmc_sysinit.sh
new file mode 100644
index 0000000..d769498
--- /dev/null
+++ b/recipes-google/gbmc-sysinit/server3/gbmc_sysinit.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+source /usr/share/gbmc-sysinit/gbmc_sysinit_helper.sh
+
+main() {
+ if [[ $# -ne 1 ]] || ! [[ "${1}" =~ ^[01]$ ]]; then
+ echo " Expecting one argument(host_index) only." >&2
+ echo " host_index: Must be 0 or 1." >&2
+ return 1
+ fi
+
+ local index="${1}"
+ transfer_bios_image_to_dram ${index}
+}
+
+# Exit without running main() if sourced
+return 0 2>/dev/null
+
+main "$@"
diff --git a/recipes-google/gbmc-sysinit/server3/gbmc_sysinit_helper.sh b/recipes-google/gbmc-sysinit/server3/gbmc_sysinit_helper.sh
new file mode 100644
index 0000000..950a9b7
--- /dev/null
+++ b/recipes-google/gbmc-sysinit/server3/gbmc_sysinit_helper.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+transfer_bios_image_to_dram() {
+ echo "transfer_bios_image_to_dram is not implemented" >&2
+ return 1
+}
diff --git a/recipes-google/gbmc-sysinit/server3/wait_emmc_available.sh b/recipes-google/gbmc-sysinit/server3/wait_emmc_available.sh
new file mode 100644
index 0000000..069fd1c
--- /dev/null
+++ b/recipes-google/gbmc-sysinit/server3/wait_emmc_available.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+# This script waits for the emmc-available.target to become active,
+# timing out after a specified duration.
+
+main() {
+ local -r timeout_seconds=300
+ local -r sleep_interval_seconds=30
+ local start_time
+ start_time=$SECONDS
+
+ while true; do
+ if systemctl is-active --quiet emmc-available.target; then
+ echo "emmc-available.target is active."
+ return 0
+ fi
+
+ local elapsed_time
+ elapsed_time=$(( SECONDS - start_time ))
+ if (( elapsed_time >= timeout_seconds )); then
+ echo "ERROR: Timed out after ${timeout_seconds} seconds waiting for emmc-available.target." >&2
+ return 1
+ fi
+
+ echo "Waiting for emmc-available.target..."
+ sleep "${sleep_interval_seconds}"
+ done
+}
+
+main "$@"