PKGBUILD 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. # Maintainer: David P. <megver83@parabola.nu>
  2. # Contributor: André Silva <emulatorman@hyperbola.info>
  3. # Contributor: Márcio Silva <coadde@hyperbola.info>
  4. # Based on linux-hardened package
  5. _replacesarchkernel=('linux%') # '%' gets replaced with kernel suffix
  6. _replacesoldkernels=() # '%' gets replaced with kernel suffix
  7. _replacesoldmodules=() # '%' gets replaced with kernel suffix
  8. pkgbase=linux-libre-hardened
  9. pkgver=6.7.3.hardened1
  10. pkgrel=3
  11. pkgdesc='Security-Hardened Linux-libre'
  12. url='https://linux-libre.fsfla.org/'
  13. arch=(x86_64)
  14. license=(GPL2)
  15. makedepends=(
  16. bc
  17. cpio
  18. gettext
  19. libelf
  20. pahole
  21. perl
  22. python
  23. tar
  24. xz
  25. # htmldocs
  26. graphviz
  27. imagemagick
  28. python-sphinx
  29. texlive-latexextra
  30. )
  31. options=('!strip')
  32. _srcname=linux-6.7
  33. _srctag=${pkgver%.*}-${pkgver##*.}
  34. source=(
  35. "https://linux-libre.fsfla.org/pub/linux-libre/releases/${_srcname##*-}-gnu/linux-libre-${_srcname##*-}-gnu.tar.xz"{,.sign}
  36. "https://linux-libre.fsfla.org/pub/linux-libre/releases/${pkgver%.*}-gnu/patch-${_srcname##*-}-gnu-${pkgver%.*}-gnu.xz"{,.sign}
  37. "https://github.com/anthraxx/linux-hardened/releases/download/${_srctag}/linux-hardened-${_srctag}.patch"{,.sig}
  38. "https://repo.parabola.nu/other/linux-libre/logos/logo_linux_"{clut224.ppm,vga16.ppm,mono.pbm}{,.sig}
  39. config # the main kernel config file
  40. # maintain the TTY over USB disconnects
  41. # http://www.coreboot.org/EHCI_Gadget_Debug
  42. 0001-usb-serial-gadget-no-TTY-hangup-on-USB-disconnect-WI.patch
  43. # fix Atmel maXTouch touchscreen support
  44. # https://labs.parabola.nu/issues/877
  45. # http://www.fsfla.org/pipermail/linux-libre/2015-November/003202.html
  46. 0002-fix-Atmel-maXTouch-touchscreen-support.patch
  47. # Arch Linux patches
  48. # https://gitlab.archlinux.org/archlinux/packaging/packages/linux-hardened
  49. 0001-Revert-mm-sparsemem-fix-race-in-accessing-memory_sec.patch
  50. )
  51. validpgpkeys=(
  52. 474402C8C582DAFBE389C427BCB7CF877E7D47A7 # Alexandre Oliva
  53. 65EEFE022108E2B708CBFCF7F9E712E59AF5F22A # Daniel Micay
  54. 6DB9C4B4F0D8C0DC432CF6E4227CA7C556B2BA78 # David P.
  55. E240B57E2C4630BA768E2F26FC1B547C8D8172C8 # Levente Polyak
  56. )
  57. sha256sums=('eb43c7dfe646d607ce7f010fa77789260db46fad1086dcd5c7f8df0bee9c14b0'
  58. 'SKIP'
  59. '2b28165b2bd4fb1c833d79cab429d5a282dd41d94cee54370f21ff2261f36cf8'
  60. 'SKIP'
  61. 'a427d149a67eec747cf070cd176033663b2bfd972b4ba114049e9aee0a644d0e'
  62. 'SKIP'
  63. 'bfd4a7f61febe63c880534dcb7c31c5b932dde6acf991810b41a939a93535494'
  64. 'SKIP'
  65. '6de8a8319271809ffdb072b68d53d155eef12438e6d04ff06a5a4db82c34fa8a'
  66. 'SKIP'
  67. '13bd7a8d9ed6b6bc971e4cd162262c5a20448a83796af39ce394d827b0e5de74'
  68. 'SKIP'
  69. '133c9b3908b52912ad04fcad1de76c1af61e2fe81984c979057f8e58f8aabf74'
  70. '0376bd5efa31d4e2a9d52558777cebd9f0941df8e1adab916c868bf0c05f2fc3'
  71. '351fd96be8cd5ebd0435c0a8a978673fc023e3b1026085e67f86d815b2285e25'
  72. '88c88d845998b88cb9fa617b2f30e35f05b168c2bdd52537cd6a8b6aac173641')
  73. b2sums=('45471cdf9e8fc37e384bdcfc2d22b113850daf62a5bea70a1dc6ea402fd2f924bc21cb0275f7e22532092e20af6de7fc2bc7f2056321d29fd29e5cb0e7e80f87'
  74. 'SKIP'
  75. 'eb0ad58e4bc9603c59fa41181b18b189325a2576a28de57e933d147d946b814ec8c95b813b7a3e01742e340951d0f9dd68fb1b209e4e25fdfed8ed15166e30a4'
  76. 'SKIP'
  77. '64b7a697d32582e725125d32303983d2d32bfb8591848be8e1ce7971ce0118d464264c2d3e154cb088bf4f0c614facb07c368aade40f22886d7351cec5c929b1'
  78. 'SKIP'
  79. '73fee2ae5cb1ffd3e6584e56da86a8b1ff6c713aae54d77c0dab113890fc673dc5f300eb9ed93fb367b045ece8fa80304ff277fe61665eccf7b7ce24f0c045eb'
  80. 'SKIP'
  81. 'd02a1153a4285b32c774dca4560fe37907ccf30b8e487a681b717ed95ae9bed5988875c0a118938e5885ae9d2857e53a6f216b732b6fa3368e3c5fe08c86382c'
  82. 'SKIP'
  83. '580911af9431c066bbc072fd22d5e2ef65f12d8358cec5ff5a4f1b7deebb86cef6b5c1ad631f42350af72c51d44d2093c71f761234fb224a8b9dbb3b64b8201d'
  84. 'SKIP'
  85. '6b04c78215f9c0c582d301b3cc6d30d1ec7ffb0d13db821d60a02a37c649a1f12b50cd4337baa22adf8983d6a98f04eb4d626ddd3a21b648b22be3fc695932df'
  86. 'c2214154c36900e311531bfe68184f31639f5c50fed23bc3803a7f18439b7ff258552a39f02fed0ea92f10744e17a6c55cef0ef1a98187f978fe480fb3dddc14'
  87. '0c7ceba7cd90087db3296610a07886f337910bad265a32c052d3a703e6eb8e53f355ab9948d72d366408d968d8ee7435084dd89bef5ed0b69355fd884c2cd468'
  88. '687419d6145974e147419d658eec47efa019064f26378081a12ff145f62a141deec42cabfbdedfe5bc27333e1e610a059d3d5584d0d1afd545d8542f9c6d44d7')
  89. _replacesarchkernel=("${_replacesarchkernel[@]/\%/${pkgbase#linux-libre}}")
  90. _replacesoldkernels=("${_replacesoldkernels[@]/\%/${pkgbase#linux-libre}}")
  91. _replacesoldmodules=("${_replacesoldmodules[@]/\%/${pkgbase#linux-libre}}")
  92. export KBUILD_BUILD_HOST=parabola
  93. export KBUILD_BUILD_USER=$pkgbase
  94. export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
  95. prepare() {
  96. cd $_srcname
  97. if [ "${_srcname##*-}" != "${pkgver%.*}" ]; then
  98. echo "Applying upstream patch..."
  99. patch -Np1 < "../patch-${_srcname##*-}-gnu-${pkgver%.*}-gnu"
  100. fi
  101. echo "Adding freedo as boot logo..."
  102. install -m644 -t drivers/video/logo \
  103. ../logo_linux_{clut224.ppm,vga16.ppm,mono.pbm}
  104. echo "Setting version..."
  105. sed -e "/^[-+]EXTRAVERSION =/s/= */= -gnu/" \
  106. -i "../linux-hardened-$_srctag.patch"
  107. echo "-$pkgrel" > localversion.10-pkgrel
  108. echo "${pkgbase#linux-libre}" > localversion.20-pkgname
  109. local src
  110. for src in "${source[@]}"; do
  111. src="${src%%::*}"
  112. src="${src##*/}"
  113. src="${src%.zst}"
  114. [[ $src = *.patch ]] || continue
  115. echo "Applying patch $src..."
  116. patch -Np1 < "../$src"
  117. done
  118. echo "Setting config..."
  119. cp ../config .config
  120. make olddefconfig
  121. diff -u ../config .config || :
  122. make -s kernelrelease > version
  123. echo "Prepared $pkgbase version $(<version)"
  124. }
  125. build() {
  126. cd $_srcname
  127. make htmldocs &
  128. local pid_docs=$!
  129. make all
  130. wait "${pid_docs}"
  131. }
  132. _package() {
  133. pkgdesc="The $pkgdesc kernel and modules"
  134. depends=(
  135. coreutils
  136. initramfs
  137. kmod
  138. )
  139. optdepends=(
  140. 'wireless-regdb: to set the correct wireless channels of your country'
  141. 'linux-libre-firmware: firmware images needed for some devices'
  142. 'usbctl: deny_new_usb control'
  143. )
  144. provides=(
  145. KSMBD-MODULE
  146. VIRTUALBOX-GUEST-MODULES
  147. WIREGUARD-MODULE
  148. )
  149. replaces=(
  150. )
  151. provides+=("${_replacesarchkernel[@]/%/=${pkgver%.*}}" "LINUX-ABI_VERSION=${pkgver%.*}")
  152. conflicts=("${_replacesarchkernel[@]}" "${_replacesoldkernels[@]}" "${_replacesoldmodules[@]}")
  153. replaces=("${_replacesarchkernel[@]}" "${_replacesoldkernels[@]}" "${_replacesoldmodules[@]}")
  154. cd $_srcname
  155. local modulesdir="$pkgdir/usr/lib/modules/$(<version)"
  156. echo "Installing boot image..."
  157. # systemd expects to find the kernel here to allow hibernation
  158. # https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
  159. install -Dm644 "$(make -s image_name)" "$modulesdir/vmlinuz"
  160. # Used by mkinitcpio to name the kernel
  161. echo "$pkgbase" | install -Dm644 /dev/stdin "$modulesdir/pkgbase"
  162. echo "Installing modules..."
  163. ZSTD_CLEVEL=19 make INSTALL_MOD_PATH="$pkgdir/usr" INSTALL_MOD_STRIP=1 \
  164. DEPMOD=/doesnt/exist modules_install # Suppress depmod
  165. # remove build link
  166. rm "$modulesdir"/build
  167. }
  168. _package-headers() {
  169. pkgdesc="Headers and scripts for building modules for the $pkgdesc kernel"
  170. depends=(pahole)
  171. provides=("${_replacesarchkernel[@]/%/-headers=${pkgver%.*}}")
  172. conflicts=("${_replacesarchkernel[@]/%/-headers}" "${_replacesoldkernels[@]/%/-headers}")
  173. replaces=("${_replacesarchkernel[@]/%/-headers}" "${_replacesoldkernels[@]/%/-headers}")
  174. cd $_srcname
  175. local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
  176. echo "Installing build files..."
  177. install -Dt "$builddir" -m644 .config Makefile Module.symvers System.map \
  178. localversion.* version vmlinux
  179. install -Dt "$builddir/kernel" -m644 kernel/Makefile
  180. install -Dt "$builddir/arch/x86" -m644 arch/x86/Makefile
  181. cp -t "$builddir" -a scripts
  182. # required when STACK_VALIDATION is enabled
  183. install -Dt "$builddir/tools/objtool" tools/objtool/objtool
  184. # required when DEBUG_INFO_BTF_MODULES is enabled
  185. # install -Dt "$builddir/tools/bpf/resolve_btfids" tools/bpf/resolve_btfids/resolve_btfids
  186. echo "Installing headers..."
  187. cp -t "$builddir" -a include
  188. cp -t "$builddir/arch/x86" -a arch/x86/include
  189. install -Dt "$builddir/arch/x86/kernel" -m644 arch/x86/kernel/asm-offsets.s
  190. install -Dt "$builddir/drivers/md" -m644 drivers/md/*.h
  191. install -Dt "$builddir/net/mac80211" -m644 net/mac80211/*.h
  192. # https://bugs.archlinux.org/task/13146
  193. install -Dt "$builddir/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h
  194. # https://bugs.archlinux.org/task/20402
  195. install -Dt "$builddir/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
  196. install -Dt "$builddir/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
  197. install -Dt "$builddir/drivers/media/tuners" -m644 drivers/media/tuners/*.h
  198. # https://bugs.archlinux.org/task/71392
  199. install -Dt "$builddir/drivers/iio/common/hid-sensors" -m644 drivers/iio/common/hid-sensors/*.h
  200. echo "Installing KConfig files..."
  201. find . -name 'Kconfig*' -exec install -Dm644 {} "$builddir/{}" \;
  202. echo "Removing unneeded architectures..."
  203. local arch
  204. for arch in "$builddir"/arch/*/; do
  205. [[ $arch = */x86/ ]] && continue
  206. echo "Removing $(basename "$arch")"
  207. rm -r "$arch"
  208. done
  209. echo "Removing documentation..."
  210. rm -r "$builddir/Documentation"
  211. echo "Removing broken symlinks..."
  212. find -L "$builddir" -type l -printf 'Removing %P\n' -delete
  213. echo "Removing loose objects..."
  214. find "$builddir" -type f -name '*.o' -printf 'Removing %P\n' -delete
  215. echo "Stripping build tools..."
  216. local file
  217. while read -rd '' file; do
  218. case "$(file -Sib "$file")" in
  219. application/x-sharedlib\;*) # Libraries (.so)
  220. strip -v $STRIP_SHARED "$file" ;;
  221. application/x-archive\;*) # Libraries (.a)
  222. strip -v $STRIP_STATIC "$file" ;;
  223. application/x-executable\;*) # Binaries
  224. strip -v $STRIP_BINARIES "$file" ;;
  225. application/x-pie-executable\;*) # Relocatable binaries
  226. strip -v $STRIP_SHARED "$file" ;;
  227. esac
  228. done < <(find "$builddir" -type f -perm -u+x ! -name vmlinux -print0)
  229. echo "Stripping vmlinux..."
  230. strip -v $STRIP_STATIC "$builddir/vmlinux"
  231. echo "Adding symlink..."
  232. mkdir -p "$pkgdir/usr/src"
  233. ln -sr "$builddir" "$pkgdir/usr/src/$pkgbase"
  234. }
  235. _package-docs() {
  236. pkgdesc="Documentation for the $pkgdesc kernel"
  237. provides=("${_replacesarchkernel[@]/%/-docs=${pkgver%.*}}")
  238. conflicts=("${_replacesarchkernel[@]/%/-docs}" "${_replacesoldkernels[@]/%/-docs}")
  239. replaces=("${_replacesarchkernel[@]/%/-docs}" "${_replacesoldkernels[@]/%/-docs}")
  240. cd $_srcname
  241. local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
  242. echo "Installing documentation..."
  243. local src dst
  244. while read -rd '' src; do
  245. dst="${src#Documentation/}"
  246. dst="$builddir/Documentation/${dst#output/}"
  247. install -Dm644 "$src" "$dst"
  248. done < <(find Documentation -name '.*' -prune -o ! -type d -print0)
  249. echo "Adding symlink..."
  250. mkdir -p "$pkgdir/usr/share/doc"
  251. ln -sr "$builddir/Documentation" "$pkgdir/usr/share/doc/$pkgbase"
  252. }
  253. pkgname=(
  254. "$pkgbase"
  255. "$pkgbase-headers"
  256. "$pkgbase-docs"
  257. )
  258. for _p in "${pkgname[@]}"; do
  259. eval "package_$_p() {
  260. $(declare -f "_package${_p#$pkgbase}")
  261. _package${_p#$pkgbase}
  262. }"
  263. done
  264. # vim:set ts=8 sts=2 sw=2 et: