kernel-surface.spec 12 KB

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