From 9fce4dabf493ac18c225238bd34451c6f1b957ec Mon Sep 17 00:00:00 2001
From: Zygmunt Krynicki <zygmunt.krynicki@huawei.com>
Date: Thu, 30 Sep 2021 19:03:00 +0200
Subject: [PATCH] sysota: install machine-specific sysotad.conf

The systoa package now provides standard sysotad.conf configuration
file, which is safe to install on all systems. For the MACHINE
"raspberrypi4-64" a special sysotad.conf is provided, one that
enables the pi-boot specific boot loader logic.

The entire sysota package becomes MACHINE-specific to avoid populating
the cache with the wrong config settings across builds.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@huawei.com>
---
 .../sysota/files/raspberrypi4/sysotad.conf    |  6 ++++++
 .../recipes-ota/sysota/files/sysotad.conf     |  6 ++++++
 .../recipes-ota/sysota/sysota_git.bb          | 19 +++++++++++++++++++
 3 files changed, 31 insertions(+)
 create mode 100644 meta-ohos-core/recipes-ota/sysota/files/raspberrypi4/sysotad.conf
 create mode 100644 meta-ohos-core/recipes-ota/sysota/files/sysotad.conf

diff --git a/meta-ohos-core/recipes-ota/sysota/files/raspberrypi4/sysotad.conf b/meta-ohos-core/recipes-ota/sysota/files/raspberrypi4/sysotad.conf
new file mode 100644
index 00000000..ac2f3ba7
--- /dev/null
+++ b/meta-ohos-core/recipes-ota/sysota/files/raspberrypi4/sysotad.conf
@@ -0,0 +1,6 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+[OTA]
+BootLoaderType=pi-boot
diff --git a/meta-ohos-core/recipes-ota/sysota/files/sysotad.conf b/meta-ohos-core/recipes-ota/sysota/files/sysotad.conf
new file mode 100644
index 00000000..e76921bb
--- /dev/null
+++ b/meta-ohos-core/recipes-ota/sysota/files/sysotad.conf
@@ -0,0 +1,6 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+[OTA]
+BootLoaderType=inert
diff --git a/meta-ohos-core/recipes-ota/sysota/sysota_git.bb b/meta-ohos-core/recipes-ota/sysota/sysota_git.bb
index 9260c889..0b2d345b 100644
--- a/meta-ohos-core/recipes-ota/sysota/sysota_git.bb
+++ b/meta-ohos-core/recipes-ota/sysota/sysota_git.bb
@@ -7,6 +7,10 @@ LICENSE = "Apache-2.0"
 LIC_FILES_CHKSUM = "file://src/${GO_IMPORT}/LICENSES/Apache-2.0.txt;md5=c846ebb396f8b174b10ded4771514fcc"
 
 SRC_URI = "git://git.ostc-eu.org/OSTC/OHOS/components/sysota.git;protocol=https;branch=main"
+SRC_URI_append = " \
+  file://sysotad.conf \
+  "
+
 SRCREV = "8d2f4fce96a4cf880c329103b2640450857d6423"
 S = "${WORKDIR}/git"
 
@@ -76,6 +80,10 @@ do_compile_append() {
 
 do_install_append() {
     oe_runmake -C ${B}/make-build --warn-undefined-variables install DESTDIR=${D}
+
+    # Install the built-in configuration file.
+    # See below for machine-specific overrides.
+    install -D -m 0644 ${WORKDIR}/sysotad.conf ${D}${libdir}/sysota/sysotad.conf
 }
 
 # Include D-Bus configuration files in the primary package. Those contain bus
@@ -83,6 +91,9 @@ do_install_append() {
 # (not to be confused with the systemd service unit).
 FILES_${PN} += "${datadir}/dbus-1"
 
+# Include the built-in configuration file.
+FILES_${PN} += "${libdir}/sysota/sysotad.conf"
+
 # SystemOTA depends on RAUC and unsquashfs and mksquashfs (for tests).
 RDEPENDS_${PN} += "squashfs-tools rauc"
 
@@ -93,3 +104,11 @@ RDEPENDS_${PN}-dev += "bash"
 # systemd services.
 REQUIRED_DISTRO_FEATURES = "systemd"
 SYSTEMD_SERVICE_${PN} = "sysotad.service"
+
+# Specific MACHINE configurations have sysotad.conf which provides the right
+# settings, like the boot loader type.
+FILESEXTRAPATHS_prepend_raspberrypi4-64 := "${THISDIR}/files/raspberrypi4:"
+
+# Make the SystemOTA package machine-specific. This lets us put the specific
+# configuration file, which encodes boot loader type, into it safely.
+PACKAGE_ARCH = "${MACHINE_ARCH}"
-- 
GitLab