1import os 2 3import infra.basetest 4 5 6class TestGrubi386BIOS(infra.basetest.BRTest): 7 config = \ 8 """ 9 BR2_x86_core2=y 10 BR2_TOOLCHAIN_EXTERNAL=y 11 BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_UCLIBC_STABLE=y 12 BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh {}" 13 BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh" 14 BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/pc/genimage-bios.cfg" 15 BR2_LINUX_KERNEL=y 16 BR2_LINUX_KERNEL_CUSTOM_VERSION=y 17 BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.204" 18 BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y 19 BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/pc/linux.config" 20 BR2_LINUX_KERNEL_INSTALL_TARGET=y 21 BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y 22 BR2_TARGET_ROOTFS_EXT2=y 23 BR2_TARGET_GRUB2=y 24 BR2_TARGET_GRUB2_I386_PC=y 25 BR2_TARGET_GRUB2_INSTALL_TOOLS=y 26 BR2_PACKAGE_HOST_GENIMAGE=y 27 """.format(infra.filepath("tests/boot/test_grub/post-build.sh")) 28 29 def test_run(self): 30 hda = os.path.join(self.builddir, "images", "disk.img") 31 self.emulator.boot(arch="i386", options=["-hda", hda]) 32 self.emulator.login() 33 34 35class TestGrubi386EFI(infra.basetest.BRTest): 36 config = \ 37 """ 38 BR2_x86_core2=y 39 BR2_TOOLCHAIN_EXTERNAL=y 40 BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_UCLIBC_STABLE=y 41 BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh {}" 42 BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image-efi.sh" 43 BR2_LINUX_KERNEL=y 44 BR2_LINUX_KERNEL_CUSTOM_VERSION=y 45 BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.204" 46 BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y 47 BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/pc/linux.config" 48 BR2_LINUX_KERNEL_INSTALL_TARGET=y 49 BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y 50 BR2_PACKAGE_EFIVAR=y 51 BR2_TARGET_ROOTFS_EXT2=y 52 BR2_TARGET_EDK2=y 53 BR2_TARGET_GRUB2=y 54 BR2_TARGET_GRUB2_I386_EFI=y 55 BR2_TARGET_GRUB2_INSTALL_TOOLS=y 56 BR2_PACKAGE_HOST_GENIMAGE=y 57 BR2_PACKAGE_HOST_MTOOLS=y 58 BR2_PACKAGE_HOST_DOSFSTOOLS=y 59 """.format(infra.filepath("tests/boot/test_grub/post-build.sh")) 60 61 def test_run(self): 62 hda = os.path.join(self.builddir, "images", "disk.img") 63 bios = os.path.join(self.builddir, "images", "OVMF.fd") 64 # In QEMU v5.1.0 up to v7.2.0, the CPU hotplug register block misbehaves. 65 # EDK2 hang if the bug is detected in Qemu after printing errors to IO port 0x402 66 # (requires BR2_TARGET_EDK2_OVMF_DEBUG_ON_SERIAL to see them) 67 # The Docker image used by the Buildroot gitlab-ci uses Qemu 5.2.0, the workaround 68 # can be removed as soon as the Docker image is updated to provided Qemu >= 8.0.0. 69 # https://github.com/tianocore/edk2/commit/bf5678b5802685e07583e3c7ec56d883cbdd5da3 70 # http://lists.busybox.net/pipermail/buildroot/2023-July/670825.html 71 qemu_fw_cfg = "name=opt/org.tianocore/X-Cpuhp-Bugcheck-Override,string=yes" 72 self.emulator.boot(arch="i386", options=["-bios", bios, "-hda", hda, "-fw_cfg", qemu_fw_cfg]) 73 self.emulator.login() 74 75 cmd = "modprobe efivarfs" 76 self.assertRunOk(cmd) 77 78 cmd = "mount -t efivarfs none /sys/firmware/efi/efivars" 79 self.assertRunOk(cmd) 80 81 cmd = "efivar -l" 82 self.assertRunOk(cmd) 83 84 85class TestGrubX8664EFI(infra.basetest.BRTest): 86 config = \ 87 """ 88 BR2_x86_64=y 89 BR2_x86_corei7=y 90 BR2_TOOLCHAIN_EXTERNAL=y 91 BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_64_UCLIBC_STABLE=y 92 BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh {}" 93 BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image-efi.sh" 94 BR2_LINUX_KERNEL=y 95 BR2_LINUX_KERNEL_CUSTOM_VERSION=y 96 BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.204" 97 BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y 98 BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/pc/linux.config" 99 BR2_LINUX_KERNEL_INSTALL_TARGET=y 100 BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y 101 BR2_PACKAGE_EFIVAR=y 102 BR2_TARGET_ROOTFS_EXT2=y 103 BR2_TARGET_EDK2=y 104 BR2_TARGET_GRUB2=y 105 BR2_TARGET_GRUB2_X86_64_EFI=y 106 BR2_TARGET_GRUB2_INSTALL_TOOLS=y 107 BR2_PACKAGE_HOST_GENIMAGE=y 108 BR2_PACKAGE_HOST_MTOOLS=y 109 BR2_PACKAGE_HOST_DOSFSTOOLS=y 110 """.format(infra.filepath("tests/boot/test_grub/post-build.sh")) 111 112 def test_run(self): 113 hda = os.path.join(self.builddir, "images", "disk.img") 114 bios = os.path.join(self.builddir, "images", "OVMF.fd") 115 # In QEMU v5.1.0 up to v7.2.0, the CPU hotplug register block misbehaves. 116 # EDK2 hang if the bug is detected in Qemu after printing errors to IO port 0x402 117 # (requires BR2_TARGET_EDK2_OVMF_DEBUG_ON_SERIAL to see them) 118 # The Docker image used by the Buildroot gitlab-ci uses Qemu 5.2.0, the workaround 119 # can be removed as soon as the Docker image is updated to provided Qemu >= 8.0.0. 120 # https://github.com/tianocore/edk2/commit/bf5678b5802685e07583e3c7ec56d883cbdd5da3 121 # http://lists.busybox.net/pipermail/buildroot/2023-July/670825.html 122 qemu_fw_cfg = "name=opt/org.tianocore/X-Cpuhp-Bugcheck-Override,string=yes" 123 self.emulator.boot(arch="x86_64", options=["-bios", bios, "-cpu", "Nehalem", "-hda", hda, "-fw_cfg", qemu_fw_cfg]) 124 self.emulator.login() 125 126 cmd = "modprobe efivarfs" 127 self.assertRunOk(cmd) 128 129 cmd = "mount -t efivarfs none /sys/firmware/efi/efivars" 130 self.assertRunOk(cmd) 131 132 cmd = "efivar -l" 133 self.assertRunOk(cmd) 134 135 136class TestGrubAArch64EFI(infra.basetest.BRTest): 137 config = \ 138 """ 139 BR2_aarch64=y 140 BR2_TOOLCHAIN_EXTERNAL=y 141 BR2_ROOTFS_POST_IMAGE_SCRIPT="{post_image}" 142 BR2_LINUX_KERNEL=y 143 BR2_LINUX_KERNEL_CUSTOM_VERSION=y 144 BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.15.18" 145 BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y 146 BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config" 147 BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{linux_fragment}" 148 BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y 149 BR2_PACKAGE_EFIVAR=y 150 BR2_TARGET_ROOTFS_EXT2=y 151 BR2_TARGET_EDK2=y 152 BR2_TARGET_GRUB2=y 153 BR2_PACKAGE_HOST_GENIMAGE=y 154 BR2_PACKAGE_HOST_MTOOLS=y 155 BR2_PACKAGE_HOST_DOSFSTOOLS=y 156 """.format(post_image=infra.filepath("tests/boot/test_grub/post-image-aarch64-efi.sh"), 157 linux_fragment=infra.filepath("tests/boot/test_grub/linux-aarch64-efi.config")) 158 159 def test_run(self): 160 hda = os.path.join(self.builddir, "images", "disk.img") 161 bios = os.path.join(self.builddir, "images", "QEMU_EFI.fd") 162 self.emulator.boot(arch="aarch64", options=["-M", "virt", "-cpu", "cortex-a53", "-bios", bios, "-hda", hda]) 163 self.emulator.login() 164 165 cmd = "modprobe efivarfs" 166 self.assertRunOk(cmd) 167 168 cmd = "mount -t efivarfs none /sys/firmware/efi/efivars" 169 self.assertRunOk(cmd) 170 171 cmd = "efivar -l" 172 self.assertRunOk(cmd) 173