kernel-surface.spec 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. #
  2. # Definitions to configure the kernel we want to build
  3. #
  4. %global kernel_tag_fc36 kernel-5.18.18-200.fc36
  5. %global kernel_tag_fc35 kernel-5.18.18-100.fc35
  6. %global kernel_release_fc36 1
  7. %global kernel_release_fc35 1
  8. # This is what is printed in the GRUB menu. These cannot be fetched from the
  9. # buildhost, because in a container this will also say container. To get the
  10. # same text as the default kernels, just hardcode it. Hey, this is important!
  11. %global fedora_title_fc36 36 (Thirty Six)
  12. %global fedora_title_fc35 35 (Thirty Five)
  13. %global ls_patches_commit ef12afe2065b466c66a62971983b07928b8ebeb3
  14. %global sb_crt surface.crt
  15. %global sb_key surface.key
  16. #
  17. # Definitions that get automatically generated from the ones above
  18. #
  19. %global kernel_tag %{kernel_tag_fc%{fedora}}
  20. %global kernel_release %{kernel_release_fc%{fedora}}
  21. %global fedora_title %{fedora_title_fc%{fedora}}
  22. %global kernel_version %(echo %{kernel_tag} | cut -d'-' -f2)
  23. %global kernel_majorver %(echo %{kernel_version} | cut -d'.' -f1-2)
  24. %global kernel_patches patches/%{kernel_majorver}
  25. %global kernel_localversion %{kernel_release}.surface%{?dist}.%{_target_cpu}
  26. %global kernel_config kernel-%{kernel_version}-%{_target_cpu}.config
  27. %global kernel_name %{kernel_version}-%{kernel_localversion}
  28. %global fedora_source https://github.com/StollD/linux-fedora
  29. %global surface_source https://raw.githubusercontent.com/linux-surface/linux-surface/%{ls_patches_commit}
  30. %global kernel_modpath %{buildroot}/lib/modules/%{kernel_name}
  31. #
  32. # Actual specfile starts here
  33. #
  34. %bcond_with signkernel
  35. Name: kernel-surface
  36. Summary: The Linux Kernel with patches for Microsoft Surface
  37. Version: %{kernel_version}
  38. Release: %{kernel_release}%{?dist}
  39. License: GPLv2
  40. URL: https://github.com/linux-surface/linux-surface
  41. Provides: installonlypkg(kernel-surface)
  42. Provides: kernel-uname-r = %{kernel_name}
  43. Provides: kernel-core-uname-r = %{kernel_name}
  44. Provides: kernel-modules-uname-r = %{kernel_name}
  45. Recommends: iptsd
  46. Requires(pre): coreutils, systemd >= 203-2, /usr/bin/kernel-install
  47. Requires(pre): dracut >= 027
  48. Requires(pre): linux-firmware >= 20150904-56.git6ebf5d57
  49. Requires(preun): systemd >= 200
  50. BuildRequires: openssl openssl-devel
  51. BuildRequires: kmod, patch, bash, tar, git-core, sbsigntools
  52. BuildRequires: bzip2, xz, findutils, gzip, m4, perl-interpreter,
  53. BuildRequires: perl-Carp, perl-devel, perl-generators, make, diffutils,
  54. BuildRequires: gawk, gcc, binutils, redhat-rpm-config, hmaccalc, bison
  55. BuildRequires: flex, net-tools, hostname, bc, elfutils-devel
  56. BuildRequires: gcc-plugin-devel dwarves
  57. # Used to mangle unversioned shebangs to be Python 3
  58. BuildRequires: python3-devel
  59. Conflicts: xfsprogs < 4.3.0-1
  60. Conflicts: xorg-x11-drv-vmmouse < 13.0.99
  61. BuildConflicts: rhbuildsys(DiskFree) < 500Mb
  62. BuildConflicts: rpm < 4.13.0.1-19
  63. BuildConflicts: dwarves < 1.13
  64. Source0: %{fedora_source}/archive/%{kernel_tag}.tar.gz
  65. Source1: %{surface_source}/configs/surface-%{kernel_majorver}.config
  66. Source2: fedora.config
  67. %if %{with signkernel}
  68. Source20: %{sb_crt}
  69. Source21: %{sb_key}
  70. %endif
  71. Source100: mod-sign.sh
  72. Source101: parallel_xz.sh
  73. Patch0: %{surface_source}/%{kernel_patches}/0001-surface3-oemb.patch
  74. Patch1: %{surface_source}/%{kernel_patches}/0002-mwifiex.patch
  75. Patch2: %{surface_source}/%{kernel_patches}/0003-ath10k.patch
  76. Patch3: %{surface_source}/%{kernel_patches}/0004-ipts.patch
  77. Patch4: %{surface_source}/%{kernel_patches}/0005-surface-sam.patch
  78. Patch5: %{surface_source}/%{kernel_patches}/0006-surface-sam-over-hid.patch
  79. Patch6: %{surface_source}/%{kernel_patches}/0007-surface-button.patch
  80. Patch7: %{surface_source}/%{kernel_patches}/0008-surface-typecover.patch
  81. Patch8: %{surface_source}/%{kernel_patches}/0009-surface-battery.patch
  82. Patch9: %{surface_source}/%{kernel_patches}/0010-surface-gpe.patch
  83. Patch10: %{surface_source}/%{kernel_patches}/0011-cameras.patch
  84. Patch11: %{surface_source}/%{kernel_patches}/0012-amd-gpio.patch
  85. Patch100: 0001-Add-secureboot-pre-signing-to-the-kernel.patch
  86. ExclusiveArch: x86_64
  87. %global debug_package %{nil}
  88. %global _build_id_links alldebug
  89. %description
  90. The Linux Kernel, the operating system core itself, with support for
  91. Microsoft Surface.
  92. %package devel
  93. Summary: Development package for building kernel modules for kernel-surface
  94. AutoReqProv: no
  95. Provides: installonlypkg(kernel-surface)
  96. Provides: kernel-devel-uname-r = %{kernel_name}
  97. %description devel
  98. This package provides kernel headers and makefiles sufficient to build modules
  99. against the kernel-surface package.
  100. %prep
  101. %autosetup -S git -n linux-fedora-%{kernel_tag}
  102. # Fix missing Makefile.rhelver
  103. touch Makefile.rhelver
  104. scripts/kconfig/merge_config.sh \
  105. fedora/configs/%{kernel_config} \
  106. %{SOURCE1} \
  107. %{SOURCE2}
  108. echo $((%{kernel_release} - 1)) > .version
  109. # Copy secureboot certificates if they are available
  110. %if %{with signkernel}
  111. mkdir -p keys
  112. cp %{SOURCE20} keys/MOK.crt
  113. cp %{SOURCE21} keys/MOK.key
  114. %endif
  115. # This Prevents scripts/setlocalversion from mucking with our version numbers.
  116. touch .scmversion
  117. # Mangle /usr/bin/python shebangs to /usr/bin/python3
  118. # Mangle all Python shebangs to be Python 3 explicitly
  119. # -p preserves timestamps
  120. # -n prevents creating ~backup files
  121. # -i specifies the interpreter for the shebang
  122. # This fixes errors such as
  123. # *** ERROR: ambiguous python shebang in /usr/bin/kvm_stat: #!/usr/bin/python. Change it to python3 (or python2) explicitly.
  124. # We patch all sources below for which we got a report/error.
  125. pathfix.py -i "%{__python3} %{py3_shbang_opts}" -p -n \
  126. tools/kvm/kvm_stat/kvm_stat \
  127. scripts/show_delta \
  128. scripts/diffconfig \
  129. scripts/bloat-o-meter \
  130. scripts/jobserver-exec \
  131. tools \
  132. Documentation \
  133. scripts/clang-tools
  134. %build
  135. # This ensures build-ids are unique to allow parallel debuginfo
  136. perl -p -i -e "s/^CONFIG_BUILD_SALT.*/CONFIG_BUILD_SALT=\"%{kernel_name}\"/" .config
  137. make %{?_smp_mflags} all LOCALVERSION=-%{kernel_localversion} ARCH=%{_target_cpu}
  138. %define __modsign_install_post \
  139. %{SOURCE100} certs/signing_key.pem certs/signing_key.x509 %{kernel_modpath} \
  140. find %{kernel_modpath} -type f -name '*.ko' | %{SOURCE101} %{?_smp_mflags}; \
  141. %{nil}
  142. #
  143. # Disgusting hack alert! We need to ensure we sign modules *after* all
  144. # invocations of strip occur.
  145. #
  146. %define __spec_install_post \
  147. %{?__debug_package:%{__debug_install_post}}\
  148. %{__arch_install_post}\
  149. %{__os_install_post}\
  150. %{__modsign_install_post}
  151. %install
  152. mkdir -p %{buildroot}/boot
  153. # Install modules
  154. make %{?_smp_mflags} INSTALL_MOD_PATH=%{buildroot} modules_install KERNELRELEASE=%{kernel_name}
  155. # Install vmlinuz
  156. image_name=$(make -s image_name)
  157. install -m 755 $image_name %{buildroot}/boot/vmlinuz-%{kernel_name}
  158. install -m 755 $image_name %{kernel_modpath}/vmlinuz
  159. # Install System.map and .config
  160. install -m 644 System.map %{kernel_modpath}/System.map
  161. install -m 644 System.map %{buildroot}/boot/System.map-%{kernel_name}
  162. install -m 644 .config %{kernel_modpath}/config
  163. install -m 644 .config %{buildroot}/boot/config-%{kernel_name}
  164. # hmac sign the kernel for FIPS
  165. sha512hmac %{buildroot}/boot/vmlinuz-%{kernel_name} | sed -e "s,%{buildroot},," > %{kernel_modpath}/.vmlinuz.hmac
  166. cp %{kernel_modpath}/.vmlinuz.hmac %{buildroot}/boot/.vmlinuz-%{kernel_name}.hmac
  167. # mark modules executable so that strip-to-file can strip them
  168. find %{kernel_modpath} -name "*.ko" -type f | xargs --no-run-if-empty chmod u+x
  169. # Setup directories for -devel files
  170. rm -f %{kernel_modpath}/build
  171. rm -f %{kernel_modpath}/source
  172. mkdir -p %{kernel_modpath}/build
  173. pushd %{kernel_modpath}
  174. ln -s build source
  175. popd
  176. # first copy everything
  177. cp --parents $(find -type f -name "Makefile*" -o -name "Kconfig*") %{kernel_modpath}/build
  178. cp Module.symvers %{kernel_modpath}/build
  179. cp System.map %{kernel_modpath}/build
  180. if [ -s Module.markers ]; then
  181. cp Module.markers %{kernel_modpath}/build
  182. fi
  183. # then drop all but the needed Makefiles/Kconfig files
  184. rm -rf %{kernel_modpath}/build/scripts
  185. rm -rf %{kernel_modpath}/build/include
  186. cp .config %{kernel_modpath}/build
  187. cp -a scripts %{kernel_modpath}/build
  188. rm -rf %{kernel_modpath}/build/scripts/tracing
  189. rm -f %{kernel_modpath}/build/scripts/spdxcheck.py
  190. if [ -f tools/objtool/objtool ]; then
  191. cp -a tools/objtool/objtool %{kernel_modpath}/build/tools/objtool/ || :
  192. # these are a few files associated with objtool
  193. cp -a --parents tools/build/Build.include %{kernel_modpath}/build/
  194. cp -a --parents tools/build/Build %{kernel_modpath}/build/
  195. cp -a --parents tools/build/fixdep.c %{kernel_modpath}/build/
  196. cp -a --parents tools/scripts/utilities.mak %{kernel_modpath}/build/
  197. # also more than necessary but it's not that many more files
  198. cp -a --parents tools/objtool/* %{kernel_modpath}/build/
  199. cp -a --parents tools/lib/str_error_r.c %{kernel_modpath}/build/
  200. cp -a --parents tools/lib/string.c %{kernel_modpath}/build/
  201. cp -a --parents tools/lib/subcmd/* %{kernel_modpath}/build/
  202. fi
  203. if [ -d arch/x86/scripts ]; then
  204. cp -a arch/x86/scripts %{kernel_modpath}/build/arch/x86/ || :
  205. fi
  206. if [ -f arch/x86/*lds ]; then
  207. cp -a arch/x86/*lds %{kernel_modpath}/build/arch/x86/ || :
  208. fi
  209. if [ -f arch/x86/kernel/module.lds ]; then
  210. cp -a --parents arch/x86/kernel/module.lds %{kernel_modpath}/build/
  211. fi
  212. rm -f %{kernel_modpath}/build/scripts/*.o
  213. rm -f %{kernel_modpath}/build/scripts/*/*.o
  214. if [ -d arch/x86/include ]; then
  215. cp -a --parents arch/x86/include %{kernel_modpath}/build/
  216. fi
  217. cp -a include %{kernel_modpath}/build/include
  218. # files for 'make prepare' to succeed with kernel-devel
  219. cp -a --parents arch/x86/entry/syscalls/syscall_32.tbl %{kernel_modpath}/build/
  220. cp -a --parents arch/x86/entry/syscalls/syscall_64.tbl %{kernel_modpath}/build/
  221. cp -a --parents arch/x86/tools/relocs_32.c %{kernel_modpath}/build/
  222. cp -a --parents arch/x86/tools/relocs_64.c %{kernel_modpath}/build/
  223. cp -a --parents arch/x86/tools/relocs.c %{kernel_modpath}/build/
  224. cp -a --parents arch/x86/tools/relocs_common.c %{kernel_modpath}/build/
  225. cp -a --parents arch/x86/tools/relocs.h %{kernel_modpath}/build/
  226. cp -a --parents scripts/syscalltbl.sh %{kernel_modpath}/build/
  227. cp -a --parents scripts/syscallhdr.sh %{kernel_modpath}/build/
  228. # Yes this is more includes than we probably need. Feel free to sort out
  229. # dependencies if you so choose.
  230. cp -a --parents tools/include/* %{kernel_modpath}/build/
  231. cp -a --parents arch/x86/purgatory/purgatory.c %{kernel_modpath}/build/
  232. cp -a --parents arch/x86/purgatory/stack.S %{kernel_modpath}/build/
  233. cp -a --parents arch/x86/purgatory/setup-x86_64.S %{kernel_modpath}/build/
  234. cp -a --parents arch/x86/purgatory/entry64.S %{kernel_modpath}/build/
  235. cp -a --parents arch/x86/boot/string.h %{kernel_modpath}/build/
  236. cp -a --parents arch/x86/boot/string.c %{kernel_modpath}/build/
  237. cp -a --parents arch/x86/boot/ctype.h %{kernel_modpath}/build/
  238. # Make sure the Makefile, version.h, and auto.conf have a matching
  239. # timestamp so that external modules can be built
  240. touch -r %{kernel_modpath}/build/Makefile \
  241. %{kernel_modpath}/build/include/generated/uapi/linux/version.h \
  242. %{kernel_modpath}/build/include/config/auto.conf
  243. mkdir -p %{buildroot}/usr/src/kernels
  244. mv %{kernel_modpath}/build %{buildroot}/usr/src/kernels/%{kernel_name}
  245. # This is going to create a broken link during the build, but we don't use
  246. # it after this point. We need the link to actually point to something
  247. # when kernel-devel is installed, and a relative link doesn't work across
  248. # the F17 UsrMove feature.
  249. ln -sf /usr/src/kernels/%{kernel_name} %{kernel_modpath}/build
  250. # prune junk from kernel-devel
  251. find %{buildroot}/usr/src/kernels -name ".*.cmd" -delete
  252. # remove files that will be auto generated by depmod at rpm -i time
  253. pushd %{kernel_modpath}
  254. rm -f modules.{alias*,builtin.bin,dep*,*map,symbols*,devname,softdep}
  255. popd
  256. # build a BLS config for this kernel
  257. cat >%{kernel_modpath}/bls.conf <<EOF
  258. title Fedora (%{kernel_name}) %{fedora_title}
  259. version %{kernel_name}
  260. linux /vmlinuz-%{kernel_name}
  261. initrd /initramfs-%{kernel_name}.img
  262. options \$kernelopts
  263. grub_users \$grub_users
  264. grub_arg --unrestricted
  265. grub_class kernel
  266. EOF
  267. %clean
  268. rm -rf %{buildroot}
  269. %post
  270. /bin/kernel-install add %{kernel_name} /lib/modules/%{kernel_name}/vmlinuz || exit $?
  271. %preun
  272. /bin/kernel-install remove %{kernel_name} /lib/modules/%{kernel_name}/vmlinuz || exit $?
  273. %files
  274. %defattr (-, root, root)
  275. /lib/modules/%{kernel_name}
  276. %ghost /boot/vmlinuz-%{kernel_name}
  277. %ghost /boot/config-%{kernel_name}
  278. %ghost /boot/System.map-%{kernel_name}
  279. %ghost /boot/.vmlinuz-%{kernel_name}.hmac
  280. %files devel
  281. %defattr (-, root, root)
  282. /usr/src/kernels/%{kernel_name}
  283. %changelog
  284. * Thu Jan 09 2020 Dorian Stoll <dorian.stoll@tmsp.io>
  285. - Initial version