test_grub.py 7.0 KB

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