kernel-surface.spec 12 KB

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