build-linux-surface.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env python3
  2. import subprocess
  3. import sys
  4. from pathlib import Path
  5. #####################################################################
  6. ##
  7. ## The name of the modified kernel package.
  8. ##
  9. PACKAGE_NAME = "surface"
  10. ##
  11. ## https://gitlab.com/cki-project/kernel-ark/-/tags
  12. ##
  13. ## Fedora tags: kernel-X.Y.Z
  14. ## Upstream tags: vX.Y.Z
  15. ##
  16. PACKAGE_TAG = "kernel-6.3.6-0"
  17. ##
  18. ## The release number of the modified kernel package.
  19. ## e.g. 300 for kernel-6.3.1-300.fc38.foo
  20. ##
  21. PACKAGE_RELEASE = "1"
  22. ##
  23. ## Build options for configuring which parts of the kernel package are enabled.
  24. ##
  25. ## We disable all userspace components because we only want the kernel + modules.
  26. ## We also don't care too much about debug info or UKI.
  27. ##
  28. ## To list the available options, run make dist-full-help in the kernel-ark tree.
  29. ##
  30. KERNEL_BUILDOPTS = "+up +baseonly -debuginfo -doc -headers -efiuki"
  31. #####################################################################
  32. # The directory where this script is saved.
  33. script = Path(sys.argv[0]).resolve().parent
  34. # The root of the linux-surface repository.
  35. linux_surface = script / ".." / ".." / ".."
  36. # Determine the major version of the kernel.
  37. kernel_version = PACKAGE_TAG.split("-")[1]
  38. kernel_major = ".".join(kernel_version.split(".")[:2])
  39. # Determine the patches directory and config file.
  40. patches = linux_surface / "patches" / kernel_major
  41. config = linux_surface / "configs" / ("surface-%s.config" % kernel_major)
  42. sb_cert = script / "secureboot" / "MOK.crt"
  43. sb_key = script / "secureboot" / "MOK.key"
  44. # Check if the major version is supported.
  45. if not patches.exists() or not config.exists():
  46. print("ERROR: Could not find patches / configs for kernel %s!" % kernel_major)
  47. sys.exit(1)
  48. # Check if Secure Boot keys are available.
  49. sb_avail = sb_cert.exists() and sb_key.exists()
  50. # If we are building without secureboot, require user input to continue.
  51. if not sb_avail:
  52. print("")
  53. print("Secure Boot keys were not configured! Using Red Hat testkeys.")
  54. print("The compiled kernel will not boot with Secure Boot enabled!")
  55. print("")
  56. input("Press any key to continue")
  57. # Expand globs
  58. surface_patches = sorted(patches.glob("*.patch"))
  59. cmd = []
  60. cmd += [script / "build-ark.py"]
  61. cmd += ["--package-name", PACKAGE_NAME]
  62. cmd += ["--package-tag", PACKAGE_TAG]
  63. cmd += ["--package-release", PACKAGE_RELEASE]
  64. cmd += ["--patch"] + surface_patches
  65. cmd += ["--config", config]
  66. cmd += ["--buildopts", KERNEL_BUILDOPTS]
  67. local_patches = sorted((script / "patches").glob("*.patch"))
  68. local_configs = sorted((script / "configs").glob("*.config"))
  69. local_files = sorted((script / "files").glob("*"))
  70. if len(local_patches) > 0:
  71. cmd += ["--patch"] + local_patches
  72. if len(local_configs) > 0:
  73. cmd += ["--config"] + local_configs
  74. if len(local_files) > 0:
  75. cmd += ["--file"] + local_files
  76. if sb_avail:
  77. sb_patches = sorted((script / "secureboot").glob("*.patch"))
  78. sb_configs = sorted((script / "secureboot").glob("*.config"))
  79. if len(sb_patches) > 0:
  80. cmd += ["--patch"] + sb_patches
  81. if len(sb_configs) > 0:
  82. cmd += ["--config"] + sb_configs
  83. cmd += ["--file", sb_cert, sb_key]
  84. subprocess.run(cmd, check=True)