From ed49da8a8cc348755369113526aad03e8622dd5b Mon Sep 17 00:00:00 2001 From: Zygmunt Krynicki <zygmunt.krynicki@huawei.com> Date: Tue, 22 Feb 2022 13:18:51 +0000 Subject: [PATCH] meta-oniro-core: add and enable oniro-grub-bootconf The oniro-grub-bootconf recipe provides the virtual-grub-bootconf package which in turn contains a stub grub.cfg and empty grubenv file. The change is spread around a considerable number of areas. Specifically the kick-start file needs to explicitly reference the grub.cfg file which must be placed in the wic/ directory. Since we need the same file in grub/files directory, so that it can be installed into the image, a symbolic link is employed. The distribution configuration file, oniro-linux.conf sets IMAGE_EFI_BOOT_FILES so that the grubenv file is installed into the boot partition. This is required since grub cannot create the file by itself, it can only edit the file, in-place, if it is present there already. The actual configuration file for GRUB is a stub. Appropriate file with some non-trivial logic will be proposed separately. The stub file boots the first slot all the time. The kernel is loaded from the rootfs. This test-boots fine in x86 and x86-64 qemu builds. Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@huawei.com> --- .../conf/distro/include/oniro-wic.inc | 6 +++ meta-oniro-core/conf/distro/oniro-linux.conf | 7 +++ .../recipes-bsp/grub/files/grub.cfg | 12 +++++ .../recipes-bsp/grub/files/grubenv | 2 + .../recipes-bsp/grub/oniro-grub-bootconf.bb | 54 +++++++++++++++++++ meta-oniro-core/wic/grub.cfg | 1 + meta-oniro-core/wic/x-gpt-efi-disk.wks.in | 10 +++- 7 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 meta-oniro-core/recipes-bsp/grub/files/grub.cfg create mode 100644 meta-oniro-core/recipes-bsp/grub/files/grubenv create mode 100644 meta-oniro-core/recipes-bsp/grub/oniro-grub-bootconf.bb create mode 120000 meta-oniro-core/wic/grub.cfg diff --git a/meta-oniro-core/conf/distro/include/oniro-wic.inc b/meta-oniro-core/conf/distro/include/oniro-wic.inc index cd29d305..094bebab 100644 --- a/meta-oniro-core/conf/distro/include/oniro-wic.inc +++ b/meta-oniro-core/conf/distro/include/oniro-wic.inc @@ -55,3 +55,9 @@ WIC_ROOTB_PARTITION ?= "part / --source rootfs --use-uuid --fstype=${ROOT_FSTYPE WIC_DEVDATA_PARTITION ?= "part --fstype=ext4 --label ${DEVDATA_PARTITION_LABEL} --mkfs-extraopts '-T default' --align 4096 --fixed-size ${DEVDATA_PARTITION_SIZE} ${WIC_DEVDATA_PARTITION_EXTRA_ARGS}" WIC_SYSDATA_PARTITION ?= "part --fstype=ext4 --label ${SYSDATA_PARTITION_LABEL} --mkfs-extraopts '-T default' --align 4096 --fixed-size ${SYSDATA_PARTITION_SIZE} ${WIC_SYSDATA_PARTITION_EXTRA_ARGS}" WIC_APPDATA_PARTITION ?= "part --fstype=ext4 --label ${APPDATA_PARTITION_LABEL} --mkfs-extraopts '-T default' --align 4096 --fixed-size ${APPDATA_PARTITION_SIZE} ${WIC_APPDATA_PARTITION_EXTRA_ARGS}" + +# The construction of the image depends on the files deployed by the +# oniro-grub-bootconf package, namely the empty grubenv file. +do_image_wic[depends] += " \ + oniro-grub-bootconf:do_deploy \ +" diff --git a/meta-oniro-core/conf/distro/oniro-linux.conf b/meta-oniro-core/conf/distro/oniro-linux.conf index 710f7ea5..f91977a9 100644 --- a/meta-oniro-core/conf/distro/oniro-linux.conf +++ b/meta-oniro-core/conf/distro/oniro-linux.conf @@ -94,6 +94,13 @@ EFI_PROVIDER = "grub-efi" MACHINE_FEATURES:qemux86-64 += "efi" MACHINE_FEATURES:qemux86 += "efi" +# Install the grubenv file deployed by oniro-grub-bootconf package into the EFI partition. +IMAGE_EFI_BOOT_FILES += "grubenv;EFI/BOOT/grubenv" + +# Prefer Oniro-specific GRUB configuration file. +# (note r-provider is used below) +PREFERRED_RPROVIDER_virtual-grub-bootconf = "oniro-grub-bootconf" + # qemu-generic-arm64 specific requirements PREFERRED_VERSION_optee-os:qemu-generic-arm64 = "3.14.0" diff --git a/meta-oniro-core/recipes-bsp/grub/files/grub.cfg b/meta-oniro-core/recipes-bsp/grub/files/grub.cfg new file mode 100644 index 00000000..3d290145 --- /dev/null +++ b/meta-oniro-core/recipes-bsp/grub/files/grub.cfg @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: Huawei Inc. +# +# SPDX-License-Identifier: Apache-2.0 + +# NOTE: This file is referenced from x-gpt-efi-disk.wks.in +# Please be careful when moving it around the tree. + +serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 + +# Boot the "A" slot all the time. This file is a stub. +linux "(hd0,gpt2)/boot/bzImage" root=/dev/sda2 rauc.slot=A $CMDLINE +boot diff --git a/meta-oniro-core/recipes-bsp/grub/files/grubenv b/meta-oniro-core/recipes-bsp/grub/files/grubenv new file mode 100644 index 00000000..f93ccbff --- /dev/null +++ b/meta-oniro-core/recipes-bsp/grub/files/grubenv @@ -0,0 +1,2 @@ +# GRUB Environment Block +####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################### \ No newline at end of file diff --git a/meta-oniro-core/recipes-bsp/grub/oniro-grub-bootconf.bb b/meta-oniro-core/recipes-bsp/grub/oniro-grub-bootconf.bb new file mode 100644 index 00000000..856c0aa2 --- /dev/null +++ b/meta-oniro-core/recipes-bsp/grub/oniro-grub-bootconf.bb @@ -0,0 +1,54 @@ +# SPDX-FileCopyrightText: Huawei Inc. +# +# SPDX-License-Identifier: Apache-2.0 + +SUMMARY = "GRUB configuration file specialized for Oniro reference images" +DESCRIPTION = "This GRUB configuration file has the following features: \ +- Support for A/B immutable system image \ +- Support for try-mode booting compatible with RAUC \ +- Kernel is loaded from the system image \ +" +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10" + +SRC_URI = " \ + file://grub.cfg \ + file://grubenv \ +" + +inherit allarch deploy + +RPROVIDES:${PN} += "virtual-grub-bootconf" + +# Get definitions of the EFI_ variables. +require conf/image-uefi.conf + +S = "${WORKDIR}" + +do_install() { + # Install the boot assets into the rootfs. Those can be used to handle boot + # asset updates by SysOTA later on. Note that external grub.cfg is + # temporary. It must be merged into the grub binary after a period of + # testing. + install -d ${D}${EFI_FILES_PATH} + install -m 644 grub.cfg ${D}${EFI_FILES_PATH}/grub.cfg + install -m 644 grubenv ${D}${EFI_FILES_PATH}/grubenv +} + +do_deploy() { + # Install the boot assets into DEPLOYDIR. The deploy bbclass + # eventually copies those into the boot partition. + install -m 644 ${WORKDIR}/grub.cfg ${DEPLOYDIR} + # Unlike grub.cfg, nothing installs this file to the boot partition + # automatically. It is handled by extending IMAGE_EFI_BOOT_FILES from + # conf/distro/oniro-linux.conf. + install -m 644 ${WORKDIR}/grubenv ${DEPLOYDIR} +} + +# Cargo-cult from a similar recipe. +addtask deploy after do_install before do_build + +FILES:${PN} = "\ + ${EFI_FILES_PATH}/grub.cfg \ + ${EFI_FILES_PATH}/grubenv \ +" diff --git a/meta-oniro-core/wic/grub.cfg b/meta-oniro-core/wic/grub.cfg new file mode 120000 index 00000000..b736aef5 --- /dev/null +++ b/meta-oniro-core/wic/grub.cfg @@ -0,0 +1 @@ +../recipes-bsp/grub/files/grub.cfg \ No newline at end of file diff --git a/meta-oniro-core/wic/x-gpt-efi-disk.wks.in b/meta-oniro-core/wic/x-gpt-efi-disk.wks.in index 72e017ae..7bdb8e9b 100644 --- a/meta-oniro-core/wic/x-gpt-efi-disk.wks.in +++ b/meta-oniro-core/wic/x-gpt-efi-disk.wks.in @@ -15,7 +15,15 @@ # | | # 0 4096KiB -bootloader --ptable gpt --timeout=${WIC_BOOTLOADER_TIMEOUT} --append=" rootfstype=${ROOT_FSTYPE} " +# The bootloader plugin either generates a file or gets a canned file that +# needs to be placed in the wic directory. At the same time there's a virtual +# provider for the GRUB configuration file which installs a file to /boot in +# the (rootfs). Ideally the file that is installed would be used but this is +# apparently not supported. +# +# We don't want to have a duplicate file but there's no support for relative +# paths so use a symbolic link instead. +bootloader --configfile=grub.cfg --ptable gpt --timeout=${WIC_BOOTLOADER_TIMEOUT} --append=" rootfstype=${ROOT_FSTYPE} " part --source bootimg-efi --sourceparams="loader=${EFI_PROVIDER}" --label ${BOOT_PARTITION_LABEL} --active --align 4096 --offset 4096 --fixed-size ${BOOT_PARTITION_SIZE} ${WIC_ROOTA_PARTITION} -- GitLab