-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPKGBUILD
476 lines (405 loc) · 17.3 KB
/
PKGBUILD
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# forked from https://github.com/archlinuxarm/PKGBUILDs/tree/master/core/linux-armv7
pkgbase=linux-xe303c12
pkgname=$pkgbase
_kernelname=${pkgbase#linux}
_desc="ARMv7 XE303C12-platform"
pkgver=5.15.79
_srcname=linux-${pkgver}
pkgrel=1
rcnver=5.15.0
rcnrel=rc7-armv7-x7
arch=('armv7h')
url="http://www.kernel.org/"
license=('GPL2')
makedepends=('xmlto' 'docbook-xsl' 'kmod' 'inetutils' 'bc' 'git' 'uboot-tools' 'vboot-utils' 'dtc' 'flex' 'make' 'gcc' 'fakeroot' 'bison')
options=('!strip')
MAKEFLAGS="-j$(grep 'model name' /proc/cpuinfo --count)"
source=("http://www.kernel.org/pub/linux/kernel/v5.x/${_srcname}.tar.xz"
# "http://rcn-ee.com/deb/stretch-armhf/v${rcnver}-${rcnrel}/patch-${rcnver%.0}-${rcnrel}.diff.xz"
"http://rcn-ee.com/deb/sid-armhf/v${rcnver}-${rcnrel}/patch-${rcnver%.0}-${rcnrel}.diff.gz"
'https://raw.githubusercontent.com/archlinuxarm/PKGBUILDs/master/core/linux-armv7/0004-fix-mvsdio-eMMC-timing.patch'
'config'
'kernel.its'
'https://github.com/archlinuxarm/PKGBUILDs/raw/master/core/linux-armv7/kernel.keyblock'
'https://github.com/archlinuxarm/PKGBUILDs/raw/master/core/linux-armv7/kernel_data_key.vbprivk'
)
md5sums=('SKIP' 'SKIP' 'SKIP' 'SKIP' 'SKIP' 'SKIP' 'SKIP' ) #'SKIP')
prepare() {
cd "${srcdir}/${_srcname}"
# add upstream patch
#git apply --whitespace=nowarn ../patch-${pkgver}
# RCN patch
git apply ../patch-${rcnver%.0}-${rcnrel}.diff
# ALARM patches
git apply ../0004-fix-mvsdio-eMMC-timing.patch
cat "${srcdir}/config" > ./.config
# add pkgrel to extraversion
sed -ri "s|^(EXTRAVERSION =)(.*)|\1 \2-${pkgrel}|" Makefile
# don't run depmod on 'make install'. We'll do this ourselves in packaging
sed -i '2iexit 0' scripts/depmod.sh
}
build() {
cd "${srcdir}/${_srcname}"
make ${MAKEFLAGS} prepare
make ${MAKEFLAGS} menuconfig
#ff=" -O2 -pipe -march=armv7-a+mp+neon-vfpv4 --param l1-cache-size=64 --param l2-cache-size=1024 -mfpu=neon-vfpv4 -fno-plt -faggressive-loop-optimizations -fguess-branch-probability -floop-nest-optimize -fomit-frame-pointer -fsel-sched-pipelining -fsel-sched-pipelining-outer-loops -fpredictive-commoning -fprefetch-loop-arrays -ftree-loop-optimize -floop-interchange -floop-unroll-and-jam -fpeel-loops -funswitch-loops -fvect-cost-model=dynamic -fsimd-cost-model=dynamic -fsplit-ivs-in-unroller -ftree-loop-ivcanon -ftree-loop-im "
ff=" -O2 -pipe -march=armv7-a+mp+neon-vfpv4 --param l1-cache-size=64 --param l2-cache-size=1024 -mfpu=neon-vfpv4 -ftracer -funroll-loops -fprefetch-loop-arrays -fpredictive-commoning -fsel-sched-reschedule-pipelined"
export CFLAGS+="$ff"
export CXXFLAGS+="$ff"
echo force custom gcc flags
for tmpcycle in $(find -name Makefile); do
#sed -i "s/armv7-a/armv7-a+mp+neon-vfpv4 --param l1-cache-size=64 --param l2-cache-size=1024 -mfpu=neon-vfpv4 -fno-plt -faggressive-loop-optimizations -fguess-branch-probability -floop-nest-optimize -fomit-frame-pointer -fsel-sched-pipelining -fsel-sched-pipelining-outer-loops -fpredictive-commoning -fprefetch-loop-arrays -ftree-loop-optimize -floop-interchange -floop-unroll-and-jam -fpeel-loops -funswitch-loops -fvect-cost-model=dynamic -fsimd-cost-model=dynamic -fsplit-ivs-in-unroller -ftree-loop-ivcanon -ftree-loop-im /g" $tmpcycle
sed -i "s/armv7-a/armv7-a+mp+neon-vfpv4 --param l1-cache-size=64 --param l2-cache-size=1024 -O2 -ftracer /g" $tmpcycle
sed -i "s/vfpv /vfpv4 /g" $tmpcycle
sed -i "s/vfpv,/vfpv4,/g" $tmpcycle
sed -i "s/-Os/-O2/g" $tmpcycle
sed -i "s/-O2/-O2 --param l1-cache-size=64 --param l2-cache-size=1024 -ftracer -funroll-loops -fprefetch-loop-arrays -fpredictive-commoning -fsel-sched-reschedule-pipelined /g" $tmpcycle
#sed -i "s/-O2/-O2 -march=armv7-a+mp+neon-vfpv4 --param l1-cache-size=64 --param l2-cache-size=1024 -mfpu=neon-vfpv4 -fno-plt -faggressive-loop-optimizations -fguess-branch-probability -floop-nest-optimize -fomit-frame-pointer -fsel-sched-pipelining -fsel-sched-pipelining-outer-loops -fpredictive-commoning -fprefetch-loop-arrays -ftree-loop-optimize -floop-interchange -floop-unroll-and-jam -fpeel-loops -funswitch-loops -fvect-cost-model=dynamic -fsimd-cost-model=dynamic -fsplit-ivs-in-unroller -ftree-loop-ivcanon -ftree-loop-im /g" $tmpcycle
done
make ${MAKEFLAGS} zImage modules exynos5250-snow.dtb exynos5250-snow-rev5.dtb
}
package() {
pkgdesc="The Linux Kernel, flash image, modules and headers for samsung/google snow XE303C12 chromebook - ${_desc}"
depends=('coreutils' 'kmod' 'uboot-tools' 'vboot-utils')
optdepends=('linux-xe303c12-firmware: contains the necessary firmwares for the xe303c12 chromebook, takes up 5M or something'
'linux-firmware: contains all available firmwares, takes up 500M or something'
'crda: to set the correct wireless channels of your country'
'mkinitcpio>=0.7: not needed for this kernel actually')
backup=("etc/mkinitcpio.d/${pkgbase}.preset")
provides=("linux=${pkgver}" "WIREGUARD-MODULE" "linux-headers=${pkgver}" )
conflicts=('linux' 'linux-headers' )
replaces=('linux-armv7' 'linux-armv7-chromebook' 'linux-armv7-rc-chromebook' 'linux-armv7-rc' 'linux-armv7-rc-chromebook' 'linux-armv7-headers' 'linux-armv7-chromebook-headers' 'linux-armv7-rc-chromebook-headers' 'linux-armv7-rc-headers' 'linux-armv7-rc-chromebook-headers')
cd "${srcdir}/${_srcname}"
KARCH=arm
# get kernel version
_kernver="$(make kernelrelease)"
_basekernel=${_kernver%%-*}
_basekernel=${_basekernel%.*}
mkdir -p "${pkgdir}"/{boot,usr/lib/modules}
make ${MAKEFLAGS} INSTALL_MOD_PATH="${pkgdir}/usr" modules_install
# make INSTALL_DTBS_PATH="${pkgdir}/boot/dtbs" dtbs_install
# custom builded dtb will be installed manually
install -D arch/$KARCH/boot/dts/exynos5250-snow.dtb -m755 "${pkgdir}/boot/dtbs/exynos5250-snow.dtb"
install -D arch/$KARCH/boot/dts/exynos5250-snow-rev5.dtb -m755 "${pkgdir}/boot/dtbs/exynos5250-snow-rev5.dtb"
cp arch/$KARCH/boot/zImage "${pkgdir}/boot/zImage"
mkdir -p "${pkgdir}"/boot/reflash
cp ${srcdir}/kernel.keyblock ${pkgdir}/boot/reflash/kernel.keyblock
cp ${srcdir}/kernel_data_key.vbprivk ${pkgdir}/boot/reflash/kernel_data_key.vbprivk
echo '#!/bin/bash
if [ "$(whoami)" == "root" ]; then
# resign kernel
echo "
You may re-sign kernel and customize kernel boot string.
Regular user do not need it, so it is safe to press n.
Do you want to do this? (y/N)
"
read -r tmpvar1
if $(echo $tmpvar1 | grep -q [Yy]); then
bootcmd='"'console=tty0 init=/sbin/init root=PARTUUID=%U/PARTNROFF=1 rootwait rw noinitrd zswap.compressor=zstd zswap.max_pool_percent=40 audit=0'"'
echo "default bootcmd is
$bootcmd
Be very careful, without init=/sbin/init root=PARTUUID=%U/PARTNROFF=1
or something like that your could get a bootfail.
Now you may specify a new one or just press Enter
"
tmpvar2=""
read -r tmpvar2
if [ ! -z "$tmpvar2" ]; then
bootcmd="$tmpvar2"
else
echo " Will be used default boot string
"
fi
# make kernel.its
echo '"'"'
/dts-v1/;
/ {
description = "Chrome OS kernel image with one or more FDT blobs";
#address-cells = <1>;
images {
kernel@1 {
description = "kernel";
data = /incbin/("/boot/zImage");
type = "kernel_noload";
arch = "arm";
os = "linux";
compression = "none";
load = <0>;
entry = <0>;
};
fdt@1 {
description = "exynos5250-snow.dtb";
data = /incbin/("/boot/dtbs/exynos5250-snow.dtb");
type = "flat_dt";
arch = "arm";
compression = "none";
hash@1 {
algo = "sha1";
};
};
fdt@2 {
description = "exynos5250-snow-rev5.dtb";
data = /incbin/("/boot/dtbs/exynos5250-snow-rev5.dtb");
type = "flat_dt";
arch = "arm";
compression = "none";
hash@1 {
algo = "sha1";
};
};
};
configurations {
default = "conf@1";
conf@1 {
kernel = "kernel@1";
fdt = "fdt@1";
};
conf@2 {
kernel = "kernel@1";
fdt = "fdt@2";
};
};
};
'"'"'> /tmp/kernel.its
#
mkimage -D "-I dts -O dtb -p 2048" -f /tmp/kernel.its /tmp/vmlinux.uimg
# make empty bootloader
dd if=/dev/zero of=/tmp/bootloader.bin bs=512 count=1
echo $bootcmd > /tmp/cmdline
# backup default kernel_image
mv -f /boot/kernel_image /boot/backup_kernel_image
# final step
vbutil_kernel \
--pack /boot/kernel_image \
--version 1 \
--vmlinuz /tmp/vmlinux.uimg \
--arch arm \
--keyblock /boot/reflash/kernel.keyblock \
--signprivate /boot/reflash/kernel_data_key.vbprivk \
--config /tmp/cmdline \
--bootloader /tmp/bootloader.bin
# clear used files
rm -f /tmp/vmlinux.uimg /tmp/cmdline /tmp/bootloader.bin
fi
# flash kernel
krnprts=""
krnprtc=0
for i in $(ls /dev | grep -x --regexp="mmcblk[0-9]" --regexp="sd[a-z]" --regexp="vd[a-z]"); do
if $(cgpt show /dev/$i | grep Label | grep -q [Kk]ernel); then
if $(echo $i | grep -q mmcblk); then
krnprts+="$i""p$(cgpt show /dev/$i | grep Label | grep [Kk]ernel -m 1 | sed '"'"'s/ / /g'"'"' | sed '"'"'s/ / /g'"'"' | sed '"'"'s/ La.*//g'"'"' | sed '"'"'s/.* //g'"'"') "
else
krnprts+="$i$(cgpt show /dev/$i | grep Label | grep [Kk]ernel -m 1 | sed '"'"'s/ / /g'"'"' | sed '"'"'s/ / /g'"'"' | sed '"'"'s/ La.*//g'"'"' | sed '"'"'s/.* //g'"'"') "
fi
krnprtc=$(($krnprtc+1))
fi
done
echo ""
if [ "$krnprtc" -eq 0 ]; then
echo "Chrome OS kernel partition did not detected."
echo " You may need to flash kernel_image manually."
elif [ "$krnprtc" -eq 1 ]; then
if $(echo $krnprts | grep -q mmcblk0); then
pr_part_type="# usually internal MMC"
elif $(echo $krnprts | grep -q mmcblk1); then
pr_part_type="# usually SD-card"
elif $(echo $krnprts | grep -q sd); then
pr_part_type="# usually USB-disk"
else
pr_part_type="# unknown disk type"
fi
echo "Finded ChromeOs kernel partition - $krnprts $pr_part_type"
echo " Do you want to flash a new kernel to it? (y/N)"
read -r shouldwe
if [[ $shouldwe =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo make kernel partition backup to /boot/krn_pt_bk.gz
dd if=/dev/$krnprts | gzip --best > /boot/krn_pt_bk.gz
echo flash kernel
dd if=/boot/kernel_image of=/dev/$krnprts
sync
else
echo "You may flash kernel manually like:"
echo "dd if=/boot/kernel_image of=/dev/$krnprts"
fi
else
echo "Finded more than one Chrome OS kernel partition."
echo "Current root is /dev/$(mount | grep " / " | sed "s/.*dev\///g" | sed "s/ .*//g")"
echo "You need to specify next action"
echo " 0 for do not flash"
numpart=0
for i in $krnprts; do
numpart=$(($numpart+1))
if $(echo $i | grep -q mmcblk0); then
pr_part_type="# usually internal MMC"
elif $(echo $i | grep -q mmcblk1); then
pr_part_type="# usually SD-card"
elif $(echo $i | grep -q sd); then
pr_part_type="# usually USB-disk"
else
pr_part_type="# unknown disk type"
fi
echo " $numpart for flash $i partition $pr_part_type"
done
#echo ""
echo "Wrong partition may lead to bootfail. Be aware!
"
read -r shouldwe
if [ $shouldwe -gt 0 ]&&[ $shouldwe -le $numpart ]; then
numpart=0
for i in $krnprts; do
numpart=$(($numpart+1))
if [ $numpart -eq $shouldwe ]; then
echo make kernel partition backup to /boot/krn_pt_bk.gz
dd if=/dev/$i | gzip --best > /boot/krn_pt_bk.gz
echo flash kernel
dd if=/boot/kernel_image of=/dev/$i
sync
fi
done
else
echo " Ok, you may flash kernel manually"
fi
fi
else
echo superuser rights required
fi' > ${pkgdir}/boot/reflash/kerninst
chmod +x ${pkgdir}/boot/reflash/kerninst
# make room for external modules
local _extramodules="extramodules-${_basekernel}${_kernelname}"
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 "${pkgdir}"/usr/lib/modules/${_kernver}/{source,build}
# now we call depmod...
depmod -b "${pkgdir}/usr" -F System.map "${_kernver}"
## gen kernel flash script
echo '
post_install () {
/boot/reflash/kerninst
echo "
you may repeat this operations by runing /boot/reflash/kerninst
"
}
post_upgrade() {
/boot/reflash/kerninst
echo "
you may repeat this operations by runing /boot/reflash/kerninst
"
}
post_remove() {
rm -f boot/initramfs-linux.img
rm -f boot/backup_kernel_image
}
' >../../${pkgbase}.pkg
true && install=${pkgbase}.pkg
## install mkinitcpio preset file...
echo "# mkinitcpio preset file for the '${pkgbase}' package
#ALL_config='/etc/mkinitcpio.conf'
#ALL_kver='${_kernver}'
#PRESETS=('default')
#default_config='/etc/mkinitcpio.conf'
#default_image='/boot/initramfs-linux.img'
#default_options=''
" | install -Dm644 /dev/stdin "${pkgdir}/etc/mkinitcpio.d/${pkgbase}.preset"
## install pacman hooks
echo "[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Operation = Remove
Target = usr/lib/modules/${_kernver}/*
Target = usr/lib/modules/${_extramodules}/*
[Action]
Description = Updating ${pkgbase} module dependencies...
When = PostTransaction
Exec = /usr/bin/depmod ${_kernver}
" | install -Dm644 /dev/stdin "${pkgdir}/usr/share/libalpm/hooks/60-${pkgbase}.hook"
## not needed because kernel do not use initrd
# echo "[Trigger]
# Type = File
# Operation = Install
# Operation = Upgrade
# Target = boot/zImage
# Target = usr/lib/initcpio/*
#
# [Action]
# Description = Updating ${pkgbase} initcpios...
# When = PostTransaction
# Exec = /usr/bin/mkinitcpio -p ${pkgbase}
# " | install -Dm644 /dev/stdin "${pkgdir}/usr/share/libalpm/hooks/90-${pkgbase}.hook"
## include headers
#for i in $(ls include/); do
# cp -a include/${i} "${pkgdir}/usr/lib/modules/${_kernver}/build/include/"
#done
cd "${srcdir}/${_srcname}"
local _builddir="${pkgdir}/usr/lib/modules/${_kernver}/build"
install -Dt "${_builddir}" -m644 Makefile .config Module.symvers
install -Dt "${_builddir}/kernel" -m644 kernel/Makefile
mkdir "${_builddir}/.tmp_versions"
cp -t "${_builddir}" -a include scripts
install -Dt "${_builddir}/arch/${KARCH}" -m644 arch/${KARCH}/Makefile
# install -Dt "${_builddir}/arch/${KARCH}/kernel" -m644 arch/${KARCH}/kernel/asm-offsets.s arch/$KARCH/kernel/module.lds
cp -t "${_builddir}/arch/${KARCH}" -a arch/${KARCH}/include
for i in dove exynos omap2; do
mkdir -p "${_builddir}/arch/${KARCH}/mach-${i}"
#cp -t "${_builddir}/arch/${KARCH}/mach-${i}" -a arch/$KARCH/mach-${i}/include
done
for i in omap orion versatile; do
mkdir -p "${_builddir}/arch/${KARCH}/plat-${i}"
cp -t "${_builddir}/arch/${KARCH}/plat-${i}" -a arch/$KARCH/plat-${i}/include
done
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
# add xfs and shmem for aufs building
mkdir -p "${_builddir}"/{fs/xfs,mm}
# copy in Kconfig files
find . -name Kconfig\* -exec install -Dm644 {} "${_builddir}/{}" \;
# remove unneeded architectures
local _arch
for _arch in "${_builddir}"/arch/*/; do
[[ ${_arch} == */${KARCH}/ ]] && continue
rm -r "${_arch}"
done
# remove files already in linux-docs package
rm -r "${_builddir}/Documentation"
# remove now broken symlinks
find -L "${_builddir}" -type l -printf 'Removing %P\n' -delete
# Fix permissions
chmod -R u=rwX,go=rX "${_builddir}"
# strip scripts directory
local _binary _strip
while read -rd '' _binary; do
case "$(file -bi "${_binary}")" in
*application/x-sharedlib*) _strip="${STRIP_SHARED}" ;; # Libraries (.so)
*application/x-archive*) _strip="${STRIP_STATIC}" ;; # Libraries (.a)
*application/x-executable*) _strip="${STRIP_BINARIES}" ;; # Binaries
*) continue ;;
esac
/usr/bin/strip ${_strip} "${_binary}"
done < <(find "${_builddir}/scripts" -type f -perm -u+w -print0 2>/dev/null)
## include kernel flash image
cd "${srcdir}/${_srcname}"
cp ../kernel.its .
mkimage -D "-I dts -O dtb -p 2048" -f kernel.its vmlinux.uimg
dd if=/dev/zero of=bootloader.bin bs=512 count=1
echo 'console=tty0 init=/sbin/init root=PARTUUID=%U/PARTNROFF=1 rootwait rw noinitrd zswap.compressor=zstd zswap.max_pool_percent=40 audit=0 quiet loglevel=1 ' > cmdline
vbutil_kernel \
--pack kernel_image \
--version 1 \
--vmlinuz vmlinux.uimg \
--arch arm \
--keyblock ../kernel.keyblock \
--signprivate ../kernel_data_key.vbprivk \
--config cmdline \
--bootloader bootloader.bin
#mkdir -p "${pkgdir}/boot"
cp kernel_image "${pkgdir}/boot"
}