From c7104db5254281853490ed36378bedcf8d0f9953 Mon Sep 17 00:00:00 2001
From: Natalia Kovalenko <waykovalenko@gmail.com>
Date: Wed, 19 Oct 2022 09:03:22 +0200
Subject: [PATCH] Wrap common GRUB and RAUC configuration metadata in variables
 and share them using the common include file.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

    rauc: Move machines specific configurations into
    dedicated include file (rauc-conf.inc) for metadata sharing.

    grub/oniro-grub-bootconf.bb: Include rauc-conf.inc. Retrieve the
    values ​​of SERIAL_CONSOLES, RAUC_SLOT_A, RAUC_SLOT_B to pass them to
    grub.cfg file.

    grub/files/grub.cfg: Use SERIAL_CONSOLES, RAUC_SLOT_A, RAUC_SLOT_B
    variables instead of hard-coding their values, to be suitable for
    different target machines.

Signed-off-by: Natalia Kovalenko <waykovalenko@gmail.com>
---
 .../recipes-bsp/grub/files/grub.cfg           | 10 ++++--
 .../recipes-bsp/grub/oniro-grub-bootconf.bb   |  7 +++-
 .../recipes-core/rauc/rauc-conf.inc           | 34 +++++++++++++++++++
 .../recipes-core/rauc/rauc_%.bbappend         | 31 +----------------
 4 files changed, 48 insertions(+), 34 deletions(-)
 create mode 100644 meta-oniro-core/recipes-core/rauc/rauc-conf.inc

diff --git a/meta-oniro-core/recipes-bsp/grub/files/grub.cfg b/meta-oniro-core/recipes-bsp/grub/files/grub.cfg
index 2dec6f31..6c6cfb7a 100644
--- a/meta-oniro-core/recipes-bsp/grub/files/grub.cfg
+++ b/meta-oniro-core/recipes-bsp/grub/files/grub.cfg
@@ -7,7 +7,7 @@
 
 serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
 
-set CMDLINE="console=ttyS0,115200 panic=60 rootwait quiet"
+set CMDLINE="console=@SERIAL_CONSOLES@ panic=60 rootwait quiet"
 
 # Find the boot partition. We need to know where to load from and save the
 # environment to. The boot partition is saved into the ONIRO_GRUB_BOOT
@@ -81,9 +81,13 @@ fi
 # https://gitlab.eclipse.org/eclipse/oniro-core/sysota/-/wikis/Boot%20Assets%20Specification#efigrub
 if [ "$SLOT" == "A" ]; then
     # TODO pass root partition by partuuid.
-    linux "(hd0,gpt2)/boot/@KERNEL_IMAGETYPE@" root=/dev/sda2 rauc.slot=A $CMDLINE
+menuentry 'boot' {
+    linux "(hd0,gpt2)/boot/@KERNEL_IMAGETYPE@" root=@RAUC_SLOT_A@ rauc.slot=A $CMDLINE
+}
 elif [ "$SLOT" == "B" ]; then
-    linux "(hd0,gpt3)/boot/@KERNEL_IMAGETYPE@" root=/dev/sda3 rauc.slot=B $CMDLINE
+menuentry 'boot' {
+    linux "(hd0,gpt3)/boot/@KERNEL_IMAGETYPE@" root=@RAUC_SLOT_B@ rauc.slot=B $CMDLINE
+}
 else
     echo "error: cannot select slot to boot from, halting"
     halt
diff --git a/meta-oniro-core/recipes-bsp/grub/oniro-grub-bootconf.bb b/meta-oniro-core/recipes-bsp/grub/oniro-grub-bootconf.bb
index 5ce781a3..2c4de3f8 100644
--- a/meta-oniro-core/recipes-bsp/grub/oniro-grub-bootconf.bb
+++ b/meta-oniro-core/recipes-bsp/grub/oniro-grub-bootconf.bb
@@ -15,7 +15,7 @@ SRC_URI = " \
 	file://grub.cfg \
 	file://grubenv \
 "
-
+require recipes-core/rauc/rauc-conf.inc
 inherit deploy
 
 RPROVIDES:${PN} += "virtual-grub-bootconf"
@@ -33,6 +33,11 @@ do_install() {
 	install -d ${D}${EFI_FILES_PATH}
 	install -m 644 grub.cfg ${D}${EFI_FILES_PATH}/grub.cfg
 	sed -i "s/@KERNEL_IMAGETYPE@/${KERNEL_IMAGETYPE}/g" ${D}${EFI_FILES_PATH}/grub.cfg
+	baudrate=`echo "${SERIAL_CONSOLES}" | sed 's/\;.*//'`
+	ttydev=`echo "${SERIAL_CONSOLES}" | sed -e 's/^[0-9]*\;//' -e 's/ .*//'`
+	sed -i "s/@SERIAL_CONSOLES@/${ttydev},${baudrate}/g" ${D}${EFI_FILES_PATH}/grub.cfg
+	sed -i "s,@RAUC_SLOT_A@,${RAUC_SLOT_A},g" ${D}${EFI_FILES_PATH}/grub.cfg
+	sed -i "s,@RAUC_SLOT_B@,${RAUC_SLOT_B},g" ${D}${EFI_FILES_PATH}/grub.cfg
 	install -m 644 grubenv ${D}${EFI_FILES_PATH}/grubenv
 }
 
diff --git a/meta-oniro-core/recipes-core/rauc/rauc-conf.inc b/meta-oniro-core/recipes-core/rauc/rauc-conf.inc
new file mode 100644
index 00000000..80cad39e
--- /dev/null
+++ b/meta-oniro-core/recipes-core/rauc/rauc-conf.inc
@@ -0,0 +1,34 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: MIT
+
+# Define the slots and compatible strings for reference boards.
+# The values here must be synchronized with those in the bundle.
+# Look at meta-oniro-core/recipes-core/bundles/oniro-bundle-base.bb
+RAUC_COMPAT:raspberrypi-armv7 := "Raspberry Pi ARMv7"
+RAUC_SLOT_A:raspberrypi-armv7 := "/dev/mmcblk0p2"
+RAUC_SLOT_B:raspberrypi-armv7 := "/dev/mmcblk0p3"
+
+RAUC_COMPAT:raspberrypi4-64 := "Raspberry Pi 4"
+RAUC_SLOT_A:raspberrypi4-64 := "/dev/mmcblk0p2"
+RAUC_SLOT_B:raspberrypi4-64 := "/dev/mmcblk0p3"
+
+RAUC_COMPAT:seco-intel-b68 := "SECO Alvin"
+RAUC_SLOT_A:seco-intel-b68 := "/dev/sda2"
+RAUC_SLOT_B:seco-intel-b68 := "/dev/sda3"
+
+RAUC_COMPAT:qemux86 := "QEMU x86"
+RAUC_SLOT_A:qemux86 := "/dev/sda2"
+RAUC_SLOT_B:qemux86 := "/dev/sda3"
+
+RAUC_COMPAT:qemux86-64 := "QEMU x86-64"
+RAUC_SLOT_A:qemux86-64 := "/dev/sda2"
+RAUC_SLOT_B:qemux86-64 := "/dev/sda3"
+
+RAUC_COMPAT:qemuarm-efi:= "QEMU ARM (EFI)"
+RAUC_SLOT_A:qemuarm-efi := "/dev/sda2"
+RAUC_SLOT_B:qemuarm-efi := "/dev/sda3"
+
+RAUC_COMPAT:qemuarm64-efi:= "QEMU ARM64 (EFI)"
+RAUC_SLOT_A:qemuarm64-efi := "/dev/sda2"
+RAUC_SLOT_B:qemuarm64-efi := "/dev/sda3"
diff --git a/meta-oniro-core/recipes-core/rauc/rauc_%.bbappend b/meta-oniro-core/recipes-core/rauc/rauc_%.bbappend
index a970cef2..4ab08c3f 100644
--- a/meta-oniro-core/recipes-core/rauc/rauc_%.bbappend
+++ b/meta-oniro-core/recipes-core/rauc/rauc_%.bbappend
@@ -18,36 +18,7 @@ SRC_URI:append = " \
   file://system.conf.in \
   "
 
-# Define the slots and compatible strings for reference boards.
-# The values here must be synchronized with those in the bundle.
-# Look at meta-oniro-core/recipes-core/bundles/oniro-bundle-base.bb
-RAUC_COMPAT:raspberrypi-armv7 := "Raspberry Pi ARMv7"
-RAUC_SLOT_A:raspberrypi-armv7 := "/dev/mmcblk0p2"
-RAUC_SLOT_B:raspberrypi-armv7 := "/dev/mmcblk0p3"
-
-RAUC_COMPAT:raspberrypi4-64 := "Raspberry Pi 4"
-RAUC_SLOT_A:raspberrypi4-64 := "/dev/mmcblk0p2"
-RAUC_SLOT_B:raspberrypi4-64 := "/dev/mmcblk0p3"
-
-RAUC_COMPAT:seco-intel-b68 := "SECO Alvin"
-RAUC_SLOT_A:seco-intel-b68 := "/dev/sda2"
-RAUC_SLOT_B:seco-intel-b68 := "/dev/sda3"
-
-RAUC_COMPAT:qemux86 := "QEMU x86"
-RAUC_SLOT_A:qemux86 := "/dev/sda2"
-RAUC_SLOT_B:qemux86 := "/dev/sda3"
-
-RAUC_COMPAT:qemux86-64 := "QEMU x86-64"
-RAUC_SLOT_A:qemux86-64 := "/dev/sda2"
-RAUC_SLOT_B:qemux86-64 := "/dev/sda3"
-
-RAUC_COMPAT:qemuarm-efi:= "QEMU ARM (EFI)"
-RAUC_SLOT_A:qemuarm-efi := "/dev/sda2"
-RAUC_SLOT_B:qemuarm-efi := "/dev/sda3"
-
-RAUC_COMPAT:qemuarm64-efi:= "QEMU ARM64 (EFI)"
-RAUC_SLOT_A:qemuarm64-efi := "/dev/sda2"
-RAUC_SLOT_B:qemuarm64-efi := "/dev/sda3"
+include rauc-conf.inc
 
 do_install:prepend() {
     sed \
-- 
GitLab