summaryrefslogtreecommitdiff
path: root/PKGBUILD
blob: 21bc3ca53a0dc94f021ba238f5744f621250006e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# Maintainer: jc_gargma <jc_gargma@iserlohn-fortress.net>
# Maintainer (Manjaro): Dan Johansen <strit@manjaro.org>
# Contributor (ArchArm): Kevin Mihelich <kevin@archlinuxarm.org>

# # I maintain this because:
# Manjaro version patch script does not apply consistently
# Manjaro version lacks ath9k regdom patches
# Manjaro version is 100 Hz
# Manjaro version uses git
# Manjaro version lacks cake modules

pkgbase=linux-pinebookpro
_supver=5
_majver=6
_minver=0
  if [ "$_minver" == "0" ]; then
    pkgver=${_supver}.${_majver}
  else
    pkgver=${_supver}.${_majver}.${_minver}
  fi
pkgrel=2
pkgdesc='Linux-PineBookPro'
url='https://kernel.org'
#url='https://gitlab.manjaro.org/tsys/linux-pinebook-pro'
arch=(aarch64)
#arch=(x86_64)
license=(GPL2)
makedepends=(
  bc kmod libelf
  dtc uboot-tools
)
provides=('linux')
conflicts=('linux')
options=('!strip')
_srcname=linux-${pkgver}
_commit=93293259039d6fc3a725961d42b4f11bfc3f5127
# https://gitlab.manjaro.org/tsys/linux-pinebook-pro/-/archive/93293259039d6fc3a725961d42b4f11bfc3f5127/linux-pinebook-pro-93293259039d6fc3a725961d42b4f11bfc3f5127.tar.gz
source=(
  https://www.kernel.org/pub/linux/kernel/v${_supver}.x/${_srcname}.tar.{xz,sign}
  pinebookpro-$_commit.patch
  0001-net-smsc95xx-Allow-mac-address-to-be-set-as-a-parame.patch
  0002-raid6-add-Kconfig-option-to-skip-raid6-benchmarking.patch
  0008-board-rockpi4-dts-upper-port-host.patch
  0001-ZEN-Add-sysctl-and-CONFIG-to-disallow-unprivileged-CLONE_NEWUSER.patch
  ath9k-regdom-hack.patch
  config         # the main kernel config file
  linux.preset
  60-linux.hook
  90-linux.hook
)
validpgpkeys=(
  'ABAF11C65A2970B130ABE3C479BE3E4300411886'  # Linus Torvalds
  '647F28654894E3BD457199BE38DBBDC86092693E'  # Greg Kroah-Hartman
)
# https://www.kernel.org/pub/linux/kernel/v5.x/sha256sums.asc
b2sums=('8dbe02a8ca7fd3dcf512a15c5d8098c1e7f94257e65173fed43fcc45480e4ab790df8cd39bbbb4e2a21dc9a00385bc9bbe98215a31e7f7e1d9c8f21cd8ace69e'
        'SKIP'
        '52e5e6ecf30996340136e9e7299bca2888f511a6bbf8784cd12dfba1c058cb89e214ae41eb72b9dd213a6b25501fa3c9212e8c50293d6ff4df0a6f8aad81221f'
        '62b160245a0bca5a27ef7afe83d860a48c220645f4fc6e075b7b39a45d668932b21ee86594747fab7a4d4e7a3006284e6683ecb741a0c88e92aa89ed73399f96'
        '1491b6281ec7b08b37bd543b25c41a2717efc6762dcd65fbc99882177a8b764cfc0bbc0129680bd9da3ec9b96d0b27651bd99155f0f66fa4314edcd7e4718234'
        'f8919ab803c7b4b4b5002547895ffa17492af405bc35d95746d2e9453061fe90cdf367cd9c461694c27660f1e174aaf5745aadb592c28f18beefef09588f2d1d'
        '464e0aa46dc59c59ad322b4e5770c316c5ff2efc95a6ca53bd973d4c872a6397222daa27d803f4d21be717ea974c2b66ad38faa0a77713e1167e3fb16170572b'
        '2e58bb89b247b1678355368956e67c1de51fcde97a227b2162f6771e30f17fa5520faafe7be4b6816a542e7ae10d05f64c6b6354f352c12746d4b8da632936dd'
        '1e899c2902325c8b826ff31d451bf24e74ce91fcf09058a3a9b41469ced872cda1290e1bbd29997520a1a9bc52111ff0679f5281475f46d66539aebe24636573'
        'f0cb39a8e448dc93cd830f1680303ecfcda6c729030ecf0bbf6dd8c57777a12ab33bbd991da4f735ba5869afb59d39f5cf5c7c725cc9ba6a78c235c2fd00251a'
        '40e2e0ac9eec9f9c08593875ca5bb8a26f835e33ae42e3718b98e83d76bbbc51a68395215c707fe58269954127261f7f8d12ec47341d28c672de973f3c4e71e8'
        'f39994fda3d76407b0af192534ca9931782b3e9de4e438a3adbc7640fc794c261102e5c7bfa1523c291ef8c7256c1106e6dbd40814006329c48d90f51c569e82')

export KBUILD_BUILD_HOST=$pkgbase
export KBUILD_BUILD_USER=$pkgbase
export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"

prepare() {
  cd $_srcname

  # add upstream patch
#  if [ "$_minver" != "0" ]; then
#    msg2 "Applying upstream patch"
#    patch -Np1 < ../patch-${_supver}.${_majver}-${pkgver}
#  fi

  # Out of tree changes for pinebookpro to function
  msg2 "Applying pinebookpro patch"
  patch -p1 -i "${srcdir}/pinebookpro-$_commit.patch"

  # ALARM patches
  patch -Np1 -i "${srcdir}/0001-net-smsc95xx-Allow-mac-address-to-be-set-as-a-parame.patch"
  patch -Np1 -i "${srcdir}/0002-raid6-add-Kconfig-option-to-skip-raid6-benchmarking.patch"
  patch -Np1 -i "${srcdir}/0008-board-rockpi4-dts-upper-port-host.patch"

  # Hotfixes
  msg2 "Applying hotfixes"
  patch -p1 -i "${srcdir}/0001-ZEN-Add-sysctl-and-CONFIG-to-disallow-unprivileged-CLONE_NEWUSER.patch"


  # Ignore ath9k eeprom patch
  msg2 "Applying ath9k patch"
  patch -p1 -i "${srcdir}/ath9k-regdom-hack.patch"


  msg2 "Setting version..."
  scripts/setlocalversion --save-scmversion
  echo "-$pkgrel" > localversion.10-pkgrel
  echo "${pkgbase#linux}" > localversion.20-pkgname


  msg2 "Setting config..."
  # we are in src/linux-x.yy.zz, looking for a config next to the pkgbuild
#  if [ -f ${SRCDEST}/config.previous ]; then
#    cp ${SRCDEST}/config.previous .config
#  else
    cp ../config .config
#  fi

  make olddefconfig

#  make menuconfig

  # Remove sublevel when no sublevel exists
  if [ "$_minver" == "0" ]; then
    sed -i '/SUBLEVEL = 0/d' Makefile
  fi

  make -s kernelrelease > version

  # workaround for make -s kernelrelease not applying
  # localversion to version when changed using menuconfig
  grep -Po '(?<=CONFIG_LOCALVERSION=").*(?=")' .config > ../localversion
  echo "$pkgver" > ../version.temp
  cat "localversion.10-pkgrel" >> ../version.temp
  cat "localversion.20-pkgname" >> ../version.temp
  cat ../localversion >> ../version.temp
  cat ../version.temp | tr -d "\n" > version

  # back up the config
#  msg2 "Backing up config..."
#  cp .config ${SRCDEST}/config.previous

  msg2 "Prepared %s version %s" "$pkgbase" "$(<version)"

  # don't run depmod on 'make install'. We'll do this ourselves in packaging
  sed -i '2iexit 0' scripts/depmod.sh

}

build() {
  cd $_srcname
  make Image Image.gz modules
  # Generate device tree blobs with symbols to support applying device tree overlays in U-Boot
  make DTC_FLAGS="-@" dtbs
}

_package() {
  pkgdesc="The $pkgdesc kernel and modules"
  depends=(coreutils kmod initramfs)
  optdepends=('crda: to set the correct wireless channels of your country'
              'linux-firmware: firmware images needed for some devices')

  cd $_srcname
  local kernver="$(<version)"
  local modulesdir="$pkgdir/usr/lib/modules/$kernver"

  msg2 "Installing boot image..."
  # systemd expects to find the kernel here to allow hibernation
  # https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
  install -Dm644 "$(make -s image_name)" "$modulesdir/vmlinux"

  # Used by mkinitcpio to name the kernel
  echo "$pkgbase" | install -Dm644 /dev/stdin "$modulesdir/pkgbase"

  mkdir -p "${pkgdir}"/{boot,usr/lib/modules}

  msg2 "Installing modules..."
  make INSTALL_MOD_PATH="$pkgdir/usr" modules_install

  msg2 "Installing dtbs..."
  make INSTALL_DTBS_PATH="${pkgdir}/boot/dtbs" dtbs_install

  cp arch/arm64/boot/Image{,.gz} "${pkgdir}/boot"

  # make room for external modules
  local _extramodules="extramodules-${kernver}"
  ln -s "../${_extramodules}" "${pkgdir}/usr/lib/modules/${kernver}/extramodules"

  # add real version for building modules and running depmod from hook
  echo "${kernver}" |
    install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modules/${_extramodules}/version"

  # remove build and source links
  rm "$modulesdir"/{source,build}

  # now we call depmod...
  depmod -b "${pkgdir}/usr" -F System.map "${kernver}"

  # add vmlinux
  install -Dt "${pkgdir}/usr/lib/modules/${kernver}/build" -m644 vmlinux

  # sed expression for following substitutions
  local _subst="
    s|%PKGBASE%|${pkgbase}|g
    s|%KERNVER%|${kernver}|g
    s|%EXTRAMODULES%|${_extramodules}|g
  "

  # install mkinitcpio preset file
  sed "${_subst}" ../linux.preset |
    install -Dm644 /dev/stdin "${pkgdir}/etc/mkinitcpio.d/${pkgbase}.preset"

  # install pacman hooks
  sed "${_subst}" ../60-linux.hook |
    install -Dm644 /dev/stdin "${pkgdir}/usr/share/libalpm/hooks/60-${pkgbase}.hook"
  sed "${_subst}" ../90-linux.hook |
    install -Dm644 /dev/stdin "${pkgdir}/usr/share/libalpm/hooks/90-${pkgbase}.hook"


  msg2 "Fixing permissions..."
  chmod -Rc u=rwX,go=rX "$pkgdir"
}

_package-headers() {
  pkgdesc="Header files and scripts for building modules for $pkgdesc kernel"

  cd $_srcname
  local builddir="$pkgdir/usr/lib/modules/$(<version)/build"

  msg2 "Installing build files..."
  install -Dt "$builddir" -m644 .config Makefile Module.symvers System.map \
    localversion.* version vmlinux
  install -Dt "$builddir/kernel" -m644 kernel/Makefile
  install -Dt "$builddir/arch/arm64" -m644 arch/arm64/Makefile
  cp -t "$builddir" -a scripts

  # add objtool for external module building and enabled VALIDATION_STACK option
  if [[ -e tools/objtool/objtool ]]; then
    install -Dt "$builddir/tools/objtool" tools/objtool/objtool
  fi

  # add xfs and shmem for aufs building
  mkdir -p "$builddir"/{fs/xfs,mm}

  msg2 "Installing headers..."
  cp -t "$builddir" -a include
  cp -t "$builddir/arch/arm64" -a arch/arm64/include
  mkdir -p "$builddir/arch/arm"
  cp -t "$builddir/arch/arm" -a arch/arm/include
  install -Dt "$builddir/arch/arm64/kernel" -m644 arch/arm64/kernel/asm-offsets.s arch/arm64/kernel/module.lds

  install -Dt "$builddir/drivers/md" -m644 drivers/md/*.h
  install -Dt "$builddir/net/mac80211" -m644 net/mac80211/*.h

  # http://bugs.archlinux.org/task/13146
  install -Dt "$builddir/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h

  # http://bugs.archlinux.org/task/20402
  install -Dt "$builddir/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
  install -Dt "$builddir/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
  install -Dt "$builddir/drivers/media/tuners" -m644 drivers/media/tuners/*.h

  msg2 "Installing KConfig files..."
  find . -name 'Kconfig*' -exec install -Dm644 {} "$builddir/{}" \;

  msg2 "Removing unneeded architectures..."
  local arch
  for arch in "$builddir"/arch/*/; do
    [[ $arch = */arm64/ || ${_arch} == */arm/ ]] && continue
    echo "Removing $(basename "$arch")"
    rm -r "$arch"
  done

  msg2 "Removing documentation..."
  rm -r "$builddir/Documentation"

  msg2 "Removing broken symlinks..."
  find -L "$builddir" -type l -printf 'Removing %P\n' -delete

  msg2 "Removing loose objects..."
  find "$builddir" -type f -name '*.o' -printf 'Removing %P\n' -delete

  msg2 "Stripping build tools..."
  local file
  while read -rd '' file; do
    case "$(file -bi "$file")" in
      application/x-sharedlib\;*)      # Libraries (.so)
        strip -v $STRIP_SHARED "$file" ;;
      application/x-archive\;*)        # Libraries (.a)
        strip -v $STRIP_STATIC "$file" ;;
      application/x-executable\;*)     # Binaries
        strip -v $STRIP_BINARIES "$file" ;;
      application/x-pie-executable\;*) # Relocatable binaries
        strip -v $STRIP_SHARED "$file" ;;
    esac
  done < <(find "$builddir" -type f -perm -u+x ! -name vmlinux -print0)

  msg2 "Adding symlink..."
  mkdir -p "$pkgdir/usr/src"
  ln -sr "$builddir" "$pkgdir/usr/src/$pkgbase"

  msg2 "Fixing permissions..."
  chmod -Rc u=rwX,go=rX "$pkgdir"
}

pkgname=("$pkgbase" "$pkgbase-headers")
for _p in "${pkgname[@]}"; do
  eval "package_$_p() {
    $(declare -f "_package${_p#$pkgbase}")
    _package${_p#$pkgbase}
  }"
done