xref: /openbmc/openbmc/poky/meta/lib/oeqa/selftest/cases/uki.py (revision 8460358c3d24c71d9d38fd126c745854a6301564)
1# Based on runqemu.py test file
2#
3# Copyright (c) 2017 Wind River Systems, Inc.
4#
5# SPDX-License-Identifier: MIT
6#
7
8from oeqa.selftest.case import OESelftestTestCase
9from oeqa.utils.commands import bitbake, runqemu, get_bb_var
10from oeqa.core.decorator.data import skipIfNotArch
11from oeqa.core.decorator import OETestTag
12import oe.types
13
14class UkiTest(OESelftestTestCase):
15    """Boot Unified Kernel Image (UKI) generated with uki.bbclass on UEFI firmware (omvf/edk2)"""
16
17    @skipIfNotArch(['i586', 'i686', 'x86_64'])
18    @OETestTag("runqemu")
19    def test_uki_boot_systemd(self):
20        """Build and boot into UEFI firmware (omvf/edk2), systemd-boot, initrd without systemd, rootfs with systemd"""
21        image = "core-image-minimal"
22        runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', image) or ""
23        cmd = "runqemu %s nographic serial wic ovmf" % (runqemu_params)
24        if oe.types.qemu_use_kvm(self.td.get('QEMU_USE_KVM', 0), self.td["TARGET_ARCH"]):
25            cmd += " kvm"
26
27        self.write_config("""
28# efi firmware must load systemd-boot, not grub
29EFI_PROVIDER = "systemd-boot"
30
31# image format must be wic, needs esp partition for firmware etc
32IMAGE_FSTYPES:pn-%s:append = " wic"
33WKS_FILE = "efi-uki-bootdisk.wks.in"
34
35# efi, uki and systemd features must be enabled
36INIT_MANAGER = "systemd"
37MACHINE_FEATURES:append = " efi"
38IMAGE_CLASSES:append:pn-core-image-minimal = " uki"
39
40# uki embeds also an initrd
41INITRAMFS_IMAGE = "core-image-minimal-initramfs"
42
43# runqemu must not load kernel separately, it's in the uki
44QB_KERNEL_ROOT = ""
45QB_DEFAULT_KERNEL = "none"
46
47# boot command line provided via uki, not via bootloader
48UKI_CMDLINE = "rootwait root=LABEL=root console=${KERNEL_CONSOLE}"
49
50# disable kvm, breaks boot
51QEMU_USE_KVM = ""
52
53IMAGE_CLASSES:remove = 'testimage'
54""" % (image))
55
56        uki_filename = get_bb_var('UKI_FILENAME', image)
57
58        bitbake(image + " ovmf")
59        with runqemu(image, ssh=False, launch_cmd=cmd) as qemu:
60            self.assertTrue(qemu.runner.logged, "Failed: %s" % cmd)
61
62            # Verify from efivars that firmware was:
63            # x86_64, qemux86_64, ovmf = edk2
64            cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderFirmwareInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep 'EDK II'"
65            status, output = qemu.run_serial(cmd)
66            self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
67
68            # Check that systemd-boot was the loader
69            cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep systemd-boot"
70            status, output = qemu.run_serial(cmd)
71            self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
72
73            # Check that systemd-stub was used
74            cmd = "echo $( cat /sys/firmware/efi/efivars/StubInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep systemd-stub"
75            status, output = qemu.run_serial(cmd)
76            self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
77
78            # Check that the compiled uki file was booted into
79            cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep '%s'" % (uki_filename)
80            status, output = qemu.run_serial(cmd)
81            self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
82
83    @skipIfNotArch(['i586', 'i686', 'x86_64'])
84    @OETestTag("runqemu")
85    def test_uki_sysvinit(self):
86        """Build and boot into UEFI firmware (omvf/edk2), systemd-boot, initrd with sysvinit, rootfs with sysvinit"""
87        config = """
88# efi firmware must load systemd-boot, not grub
89EFI_PROVIDER = "systemd-boot"
90
91# image format must be wic, needs esp partition for firmware etc
92IMAGE_FSTYPES:pn-core-image-base:append = " wic"
93WKS_FILE = "efi-uki-bootdisk.wks.in"
94
95# efi, uki and systemd features must be enabled
96MACHINE_FEATURES:append = " efi"
97DISTRO_FEATURES_NATIVE:append = " systemd"
98IMAGE_CLASSES:append:pn-core-image-base = " uki"
99
100# uki embeds also an initrd, no systemd or udev
101INITRAMFS_IMAGE = "core-image-initramfs-boot"
102
103# runqemu must not load kernel separately, it's in the uki
104QB_KERNEL_ROOT = ""
105QB_DEFAULT_KERNEL = "none"
106
107# boot command line provided via uki, not via bootloader
108UKI_CMDLINE = "rootwait root=LABEL=root console=${KERNEL_CONSOLE}"
109
110# disable kvm, breaks boot
111QEMU_USE_KVM = ""
112
113IMAGE_CLASSES:remove = 'testimage'
114"""
115        self.append_config(config)
116        bitbake('core-image-base ovmf')
117        runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', 'core-image-base') or ""
118        uki_filename = get_bb_var('UKI_FILENAME', 'core-image-base')
119        self.remove_config(config)
120
121        with runqemu('core-image-base', ssh=False,
122                     runqemuparams='%s slirp nographic ovmf' % (runqemu_params), image_fstype='wic') as qemu:
123            # Verify from efivars that firmware was:
124            # x86_64, qemux86_64, ovmf = edk2
125            cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderFirmwareInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep 'EDK II'"
126            status, output = qemu.run_serial(cmd)
127            self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
128
129            # Check that systemd-boot was the loader
130            cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep systemd-boot"
131            status, output = qemu.run_serial(cmd)
132            self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
133
134            # Check that systemd-stub was used
135            cmd = "echo $( cat /sys/firmware/efi/efivars/StubInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep systemd-stub"
136            status, output = qemu.run_serial(cmd)
137            self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
138
139            # Check that the compiled uki file was booted into
140            cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep '%s'" % (uki_filename)
141            status, output = qemu.run_serial(cmd)
142            self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
143