summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 56af639833e8ab16a1147042c56f5cdf5fa078f0 (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
# AArch64 multi-platform
# PKGBUILD Maintainer: Raanu <Gero3977@gmail.com>
# Kernel maintainer: Ayufan <ayufan@ayufan.eu> 

# The below variables get updated from external script when new builds are released
_kernver=4.4.138-1094-rockchip-ayufan-gf13a8a9a4eee
_imagename=linux-image-4.4.138-1094-rockchip-ayufan-gf13a8a9a4eee_4.4.138-1094-rockchip-ayufan_arm64.deb
_headersname=linux-headers-4.4.138-1094-rockchip-ayufan-gf13a8a9a4eee_4.4.138-1094-rockchip-ayufan_arm64.deb
_releasetag=4.4.138-1094-rockchip-ayufan
_pkgver=4.4.138_1094



_desc="AArch64 for Rock64. This package will fetch a Debian built kernel as a temporary workaround for USB 3.0 fixes."
pkgbase=linux-aarch64-rock64-bin
pkgname=('linux-aarch64-rock64-bin' 'linux-aarch64-rock64-bin-headers')
pkgver="${_pkgver}"
pkgrel=2
arch=('aarch64')
url="https://github.com/ayufan-rock64/linux-kernel"
license=('GPL2')
options=('!strip')
depends=('coreutils' 'linux-firmware' 'kmod' 'mkinitcpio>=0.7')
provides=("linux=${pkgver}" "linux-aarch64=${pkgver}")
conflicts=('linux' 'linux-aarch64' 'linux-arch64-rc')
source=("https://github.com/ayufan-rock64/linux-kernel/releases/download/${_releasetag}/${_imagename}"
"https://github.com/ayufan-rock64/linux-kernel/releases/download/${_releasetag}/${_headersname}"
        'linux.preset'
        '99-linux.hook'
        'linux-aarch64-rock64-bin.install')
sha256sums=('f61a9c611043e1f914ddd9df2c0d71cfab6eebe647e153b8ee24f9734ad576bc'
            'e7a28757bf5242ed3e0f7d46542e9b1c1b65604ae6cc7fef8c1f21bbb339d2e7'
            '9757ea513c67c9fb14e9ba9b681069f091e60bc5f892c9a2c4fe3cd57ca3fbe4'
            'be679ded489c484ec6a9eeed78c6383f9c5a7fab20d2b1f00be67ac6c7185fe6'
            'c87f3c6d4fa19319d5f81b65a45d62ab71e570bdf549c7e6c0f89292dcb5174f')
noextract=("${_imagename}"
           "${_headersname}")


prepare() {
  cd "${srcdir}"

  # extract the prebuilt kernel files
  mkdir -p linux-image/
  cp "${_imagename}" linux-image/
  cd linux-image/
  ar xf "${_imagename}"
  tar -xf data.tar.xz
  
  cd "${srcdir}"

  # extract the related linux headers
  mkdir -p linux-headers/
  cp "${_headersname}" linux-headers/
  cd linux-headers/
  ar xf "${_headersname}" 
  tar -xf data.tar.xz 
}

package_linux-aarch64-rock64-bin() {
  pkgdesc="The Linux Kernel and modules - ${_desc}"
  depends=('coreutils' 'linux-firmware' 'kmod' 'mkinitcpio>=0.7')
  optdepends=('crda: to set the correct wireless channels of your country' 'linux-aarch64-rock64-bin-headers')
  provides=("linux=${pkgver}" "linux-aarch64=${pkgver}")
  conflicts=('linux' 'linux-aarch64' 'linux-arch64-rc')  provides=('kernel26' "linux=${pkgver}")
  replaces=('linux-armv8')
  backup=("etc/mkinitcpio.d/${pkgbase}.preset")
  install=${pkgname}.install

  cd "${srcdir}/linux-image"

  # copy boot files  
  cp -r boot "${pkgdir}/boot"
  cp "boot/vmlinuz-${_kernver}" "${pkgdir}/boot/Image"
  mkdir -p "${pkgdir}/boot/dtbs/rockchip"
  mv "usr/lib/linux-image-${_kernver}/rockchip" "${pkgdir}/boot/dtbs/"

  # copy kernel files
  mkdir -p "${pkgdir}/usr"
  mkdir -p "${pkgdir}/lib"
  cp -r usr "${pkgdir}/"
  cp -r lib "${pkgdir}/"
  
  # set correct depmod command for install
  sed \
    -e  "s/KERNEL_NAME=.*/KERNEL_NAME=${_kernelname}/g" \
    -e  "s/KERNEL_VERSION=.*/KERNEL_VERSION=${_kernver}/g" \
    -i "${startdir}/${pkgname}.install"

  # install mkinitcpio preset file for kernel
  install -D -m644 "${srcdir}/linux.preset" "${pkgdir}/etc/mkinitcpio.d/${pkgbase}.preset"
  sed \
    -e "1s|'linux.*'|'${pkgbase}'|" \
    -e "s|ALL_kver=.*|ALL_kver=\"${_kernver}\"|" \
    -i "${pkgdir}/etc/mkinitcpio.d/${pkgbase}.preset"

  # install pacman hook for initramfs regeneration
  sed "s|%PKGBASE%|${pkgbase}|g" "${srcdir}/99-linux.hook" |
    install -D -m644 /dev/stdin "${pkgdir}/usr/share/libalpm/hooks/99-${pkgbase}.hook"

  # Now we call depmod...
  depmod -b "$pkgdir" -F "boot/System.map-${_kernver}" "$_kernver"

  # move module tree /lib -> /usr/lib
  mkdir -p "${pkgdir}/usr"
  cp -r "$pkgdir/lib" "$pkgdir/usr"
  rm -rf "$pkgdir/lib"

}

package_linux-aarch64-rock64-bin-headers() {
  pkgdesc="Header files and scripts for building modules for linux kernel - ${_desc}"
  provides=("linux-headers=${pkgver}")
  replaces=('linux-armv8-headers')
  conflicts=('linux-headers')
  optdepends=('linux-aarch64-rock64-bin')

  KARCH=arm64
  
  mkdir -p "${pkgdir}/usr/lib/modules/${_kernver}/build"
  cp -rT "${srcdir}/linux-headers/usr/src/linux-headers-${_kernver}/" "${pkgdir}/usr/lib/modules/${_kernver}/build"

  install -dm755 "${pkgdir}/usr/lib/modules/${_kernver}"
  
  cd "${srcdir}/linux-headers/usr/src/linux-headers-${_kernver}"
  install -D -m644 Makefile \
    "${pkgdir}/usr/lib/modules/${_kernver}/build/Makefile"
  install -D -m644 kernel/Makefile \
    "${pkgdir}/usr/lib/modules/${_kernver}/build/kernel/Makefile"
  install -D -m644 .config \
    "${pkgdir}/usr/lib/modules/${_kernver}/build/.config"

  mkdir -p "${pkgdir}/usr/lib/modules/${_kernver}/build/include"
  
  # fix permissions on scripts dir
  chmod og-w -R "${pkgdir}/usr/lib/modules/${_kernver}/build/scripts"
  mkdir -p "${pkgdir}/usr/lib/modules/${_kernver}/build/.tmp_versions"

  chown -R root.root "${pkgdir}/usr/lib/modules/${_kernver}/build"
  find "${pkgdir}/usr/lib/modules/${_kernver}/build" -type d -exec chmod 755 {} \;

  # strip scripts directory
  echo "Runing strip on some files found in headers 'script' directory, it's safe to ignore errors after this point"
  find "${pkgdir}/usr/lib/modules/${_kernver}/build/scripts" -type f -perm -u+w 2>/dev/null | while read binary ; do
    case "$(file -bi "${binary}")" in
      *application/x-sharedlib*) # Libraries (.so)
        /usr/bin/strip ${STRIP_SHARED} "${binary}" || true;;
      *application/x-archive*) # Libraries (.a)
        /usr/bin/strip ${STRIP_STATIC} "${binary}" || true;;
      *application/x-executable*) # Binaries
        /usr/bin/strip ${STRIP_BINARIES} "${binary}" || true;;
    esac
  done

  # remove unneeded architectures
  rm -rf "${pkgdir}"/usr/lib/modules/${_kernver}/build/arch/{alpha,arc,arm,arm26,avr32,blackfin,c6x,cris,frv,h8300,hexagon,ia64,m32r,m68k,m68knommu,metag,mips,microblaze,mn10300,openrisc,parisc,powerpc,ppc,s390,score,sh,sh64,sparc,sparc64,tile,unicore32,um,v850,x86,xtensa}
}