kernel-surface.spec 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. #
  2. # Definitions to configure the kernel we want to build
  3. #
  4. %global kernel_tag_fc34 kernel-5.14.7-200.fc34
  5. %global kernel_tag_fc33 kernel-5.14.7-100.fc33
  6. %global kernel_release_fc34 1
  7. %global kernel_release_fc33 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_fc34 34 (Thirty Four)
  12. %global fedora_title_fc33 33 (Thirty Three)
  13. %global ls_patches_commit be7c1399cca2d3706492c397ad3c6d8d51d44e6e
  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-over-hid.patch
  78. Patch5: %{surface_source}/%{kernel_patches}/0006-surface-typecover.patch
  79. Patch6: %{surface_source}/%{kernel_patches}/0007-cameras.patch
  80. Patch7: %{surface_source}/%{kernel_patches}/0008-amd-gpio.patch
  81. Patch8: %{surface_source}/%{kernel_patches}/0009-amd-s0ix.patch
  82. Patch100: 0001-Add-secureboot-pre-signing-to-the-kernel.patch
  83. ExclusiveArch: x86_64
  84. %global debug_package %{nil}
  85. %global _build_id_links alldebug
  86. %description
  87. The Linux Kernel, the operating system core itself, with support for
  88. Microsoft Surface.
  89. %package devel
  90. Summary: Development package for building kernel modules for kernel-surface
  91. AutoReqProv: no
  92. Provides: installonlypkg(kernel-surface)
  93. Provides: kernel-devel-uname-r = %{kernel_name}
  94. %description devel
  95. This package provides kernel headers and makefiles sufficient to build modules
  96. against the kernel-surface package.
  97. %prep
  98. %autosetup -p1 -n linux-fedora-%{kernel_tag}
  99. scripts/kconfig/merge_config.sh \
  100. fedora/configs/%{kernel_config} \
  101. %{SOURCE1} \
  102. %{SOURCE2}
  103. echo $((%{kernel_release} - 1)) > .version
  104. # Copy secureboot certificates if they are available
  105. %if %{with signkernel}
  106. mkdir -p keys
  107. cp %{SOURCE20} keys/MOK.crt
  108. cp %{SOURCE21} keys/MOK.key
  109. %endif
  110. # This Prevents scripts/setlocalversion from mucking with our version numbers.
  111. touch .scmversion
  112. # Mangle /usr/bin/python shebangs to /usr/bin/python3
  113. # Mangle all Python shebangs to be Python 3 explicitly
  114. # -p preserves timestamps
  115. # -n prevents creating ~backup files
  116. # -i specifies the interpreter for the shebang
  117. # This fixes errors such as
  118. # *** ERROR: ambiguous python shebang in /usr/bin/kvm_stat: #!/usr/bin/python. Change it to python3 (or python2) explicitly.
  119. # We patch all sources below for which we got a report/error.
  120. pathfix.py -i "%{__python3} %{py3_shbang_opts}" -p -n \
  121. tools/kvm/kvm_stat/kvm_stat \
  122. scripts/show_delta \
  123. scripts/diffconfig \
  124. scripts/bloat-o-meter \
  125. scripts/jobserver-exec \
  126. tools \
  127. Documentation \
  128. scripts/clang-tools
  129. %build
  130. # This ensures build-ids are unique to allow parallel debuginfo
  131. perl -p -i -e "s/^CONFIG_BUILD_SALT.*/CONFIG_BUILD_SALT=\"%{kernel_name}\"/" .config
  132. make %{?_smp_mflags} all LOCALVERSION=-%{kernel_localversion} ARCH=%{_target_cpu}
  133. %define __modsign_install_post \
  134. %{SOURCE100} certs/signing_key.pem certs/signing_key.x509 %{kernel_modpath} \
  135. find %{kernel_modpath} -type f -name '*.ko' | %{SOURCE101} %{?_smp_mflags}; \
  136. %{nil}
  137. #
  138. # Disgusting hack alert! We need to ensure we sign modules *after* all
  139. # invocations of strip occur.
  140. #
  141. %define __spec_install_post \
  142. %{?__debug_package:%{__debug_install_post}}\
  143. %{__arch_install_post}\
  144. %{__os_install_post}\
  145. %{__modsign_install_post}
  146. %install
  147. mkdir -p %{buildroot}/boot
  148. # Install modules
  149. make %{?_smp_mflags} INSTALL_MOD_PATH=%{buildroot} modules_install KERNELRELEASE=%{kernel_name}
  150. # Install vmlinuz
  151. image_name=$(make -s image_name)
  152. install -m 755 $image_name %{buildroot}/boot/vmlinuz-%{kernel_name}
  153. install -m 755 $image_name %{kernel_modpath}/vmlinuz
  154. # Install System.map and .config
  155. install -m 644 System.map %{kernel_modpath}/System.map
  156. install -m 644 System.map %{buildroot}/boot/System.map-%{kernel_name}
  157. install -m 644 .config %{kernel_modpath}/config
  158. install -m 644 .config %{buildroot}/boot/config-%{kernel_name}
  159. # hmac sign the kernel for FIPS
  160. sha512hmac %{buildroot}/boot/vmlinuz-%{kernel_name} | sed -e "s,%{buildroot},," > %{kernel_modpath}/.vmlinuz.hmac
  161. cp %{kernel_modpath}/.vmlinuz.hmac %{buildroot}/boot/.vmlinuz-%{kernel_name}.hmac
  162. # mark modules executable so that strip-to-file can strip them
  163. find %{kernel_modpath} -name "*.ko" -type f | xargs --no-run-if-empty chmod u+x
  164. # Setup directories for -devel files
  165. rm -f %{kernel_modpath}/build
  166. rm -f %{kernel_modpath}/source
  167. mkdir -p %{kernel_modpath}/build
  168. pushd %{kernel_modpath}
  169. ln -s build source
  170. popd
  171. # first copy everything
  172. cp --parents $(find -type f -name "Makefile*" -o -name "Kconfig*") %{kernel_modpath}/build
  173. cp Module.symvers %{kernel_modpath}/build
  174. cp System.map %{kernel_modpath}/build
  175. if [ -s Module.markers ]; then
  176. cp Module.markers %{kernel_modpath}/build
  177. fi
  178. # then drop all but the needed Makefiles/Kconfig files
  179. rm -rf %{kernel_modpath}/build/scripts
  180. rm -rf %{kernel_modpath}/build/include
  181. cp .config %{kernel_modpath}/build
  182. cp -a scripts %{kernel_modpath}/build
  183. rm -rf %{kernel_modpath}/build/scripts/tracing
  184. rm -f %{kernel_modpath}/build/scripts/spdxcheck.py
  185. if [ -f tools/objtool/objtool ]; then
  186. cp -a tools/objtool/objtool %{kernel_modpath}/build/tools/objtool/ || :
  187. # these are a few files associated with objtool
  188. cp -a --parents tools/build/Build.include %{kernel_modpath}/build/
  189. cp -a --parents tools/build/Build %{kernel_modpath}/build/
  190. cp -a --parents tools/build/fixdep.c %{kernel_modpath}/build/
  191. cp -a --parents tools/scripts/utilities.mak %{kernel_modpath}/build/
  192. # also more than necessary but it's not that many more files
  193. cp -a --parents tools/objtool/* %{kernel_modpath}/build/
  194. cp -a --parents tools/lib/str_error_r.c %{kernel_modpath}/build/
  195. cp -a --parents tools/lib/string.c %{kernel_modpath}/build/
  196. cp -a --parents tools/lib/subcmd/* %{kernel_modpath}/build/
  197. fi
  198. if [ -d arch/x86/scripts ]; then
  199. cp -a arch/x86/scripts %{kernel_modpath}/build/arch/x86/ || :
  200. fi
  201. if [ -f arch/x86/*lds ]; then
  202. cp -a arch/x86/*lds %{kernel_modpath}/build/arch/x86/ || :
  203. fi
  204. if [ -f arch/x86/kernel/module.lds ]; then
  205. cp -a --parents arch/x86/kernel/module.lds %{kernel_modpath}/build/
  206. fi
  207. rm -f %{kernel_modpath}/build/scripts/*.o
  208. rm -f %{kernel_modpath}/build/scripts/*/*.o
  209. if [ -d arch/x86/include ]; then
  210. cp -a --parents arch/x86/include %{kernel_modpath}/build/
  211. fi
  212. cp -a include %{kernel_modpath}/build/include
  213. # files for 'make prepare' to succeed with kernel-devel
  214. cp -a --parents arch/x86/entry/syscalls/syscall_32.tbl %{kernel_modpath}/build/
  215. cp -a --parents arch/x86/entry/syscalls/syscalltbl.sh %{kernel_modpath}/build/
  216. cp -a --parents arch/x86/entry/syscalls/syscallhdr.sh %{kernel_modpath}/build/
  217. cp -a --parents arch/x86/entry/syscalls/syscall_64.tbl %{kernel_modpath}/build/
  218. cp -a --parents arch/x86/tools/relocs_32.c %{kernel_modpath}/build/
  219. cp -a --parents arch/x86/tools/relocs_64.c %{kernel_modpath}/build/
  220. cp -a --parents arch/x86/tools/relocs.c %{kernel_modpath}/build/
  221. cp -a --parents arch/x86/tools/relocs_common.c %{kernel_modpath}/build/
  222. cp -a --parents arch/x86/tools/relocs.h %{kernel_modpath}/build/
  223. # Yes this is more includes than we probably need. Feel free to sort out
  224. # dependencies if you so choose.
  225. cp -a --parents tools/include/* %{kernel_modpath}/build/
  226. cp -a --parents arch/x86/purgatory/purgatory.c %{kernel_modpath}/build/
  227. cp -a --parents arch/x86/purgatory/stack.S %{kernel_modpath}/build/
  228. cp -a --parents arch/x86/purgatory/setup-x86_64.S %{kernel_modpath}/build/
  229. cp -a --parents arch/x86/purgatory/entry64.S %{kernel_modpath}/build/
  230. cp -a --parents arch/x86/boot/string.h %{kernel_modpath}/build/
  231. cp -a --parents arch/x86/boot/string.c %{kernel_modpath}/build/
  232. cp -a --parents arch/x86/boot/ctype.h %{kernel_modpath}/build/
  233. # Make sure the Makefile and version.h have a matching timestamp so that
  234. # external modules can be built
  235. touch -r %{kernel_modpath}/build/Makefile %{kernel_modpath}/build/include/generated/uapi/linux/version.h
  236. # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
  237. cp %{kernel_modpath}/build/.config %{kernel_modpath}/build/include/config/auto.conf
  238. mkdir -p %{buildroot}/usr/src/kernels
  239. mv %{kernel_modpath}/build %{buildroot}/usr/src/kernels/%{kernel_name}
  240. # This is going to create a broken link during the build, but we don't use
  241. # it after this point. We need the link to actually point to something
  242. # when kernel-devel is installed, and a relative link doesn't work across
  243. # the F17 UsrMove feature.
  244. ln -sf /usr/src/kernels/%{kernel_name} %{kernel_modpath}/build
  245. # prune junk from kernel-devel
  246. find %{buildroot}/usr/src/kernels -name ".*.cmd" -delete
  247. # remove files that will be auto generated by depmod at rpm -i time
  248. pushd %{kernel_modpath}
  249. rm -f modules.{alias*,builtin.bin,dep*,*map,symbols*,devname,softdep}
  250. popd
  251. # build a BLS config for this kernel
  252. cat >%{kernel_modpath}/bls.conf <<EOF
  253. title Fedora (%{kernel_name}) %{fedora_title}
  254. version %{kernel_name}
  255. linux /vmlinuz-%{kernel_name}
  256. initrd /initramfs-%{kernel_name}.img
  257. options \$kernelopts
  258. grub_users \$grub_users
  259. grub_arg --unrestricted
  260. grub_class kernel
  261. EOF
  262. %clean
  263. rm -rf %{buildroot}
  264. %post
  265. /bin/kernel-install add %{kernel_name} /lib/modules/%{kernel_name}/vmlinuz || exit $?
  266. %preun
  267. /bin/kernel-install remove %{kernel_name} /lib/modules/%{kernel_name}/vmlinuz || exit $?
  268. %files
  269. %defattr (-, root, root)
  270. /lib/modules/%{kernel_name}
  271. %ghost /boot/vmlinuz-%{kernel_name}
  272. %ghost /boot/config-%{kernel_name}
  273. %ghost /boot/System.map-%{kernel_name}
  274. %ghost /boot/.vmlinuz-%{kernel_name}.hmac
  275. %files devel
  276. %defattr (-, root, root)
  277. /usr/src/kernels/%{kernel_name}
  278. %changelog
  279. * Thu Jan 09 2020 Dorian Stoll <dorian.stoll@tmsp.io>
  280. - Initial version