Skip to content

Commit 04f8fd7

Browse files
committed
ci: add archlinux kernel build script
Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>
1 parent ee43f45 commit 04f8fd7

6 files changed

Lines changed: 214 additions & 4 deletions

File tree

kernel-patches/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linux.deb
2+
headers.deb
3+
linux.pkg.tar.zst
4+
headers.pkg.tar.zst
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM archlinux:latest
2+
RUN pacman -Sy && pacman -S --noconfirm git bc libelf pahole cpio perl tar xz coreutils kmod initramfs base-devel
3+
RUN useradd -m build
4+
USER build
5+
WORKDIR /home/build
6+
7+
RUN mkdir kernel
8+
RUN cd kernel && git clone https://anongit.freedesktop.org/git/drm/drm-misc.git -b drm-misc-next --depth=1 archlinux-linux
9+
COPY config PKGBUILD 0001-drm-edid-non-desktop.patch 0003-drm-edid-dsc-bpp-parse.patch 0004-drm-amd-dsc-bpp-apply.patch kernel/
10+
11+
RUN cd kernel && makepkg --holdver
12+
RUN cd kernel && mv linux-*-headers-*.pkg.tar.zst headers.pkg.tar.zst && mv linux-*.pkg.tar.zst linux.pkg.tar.zst
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
FROM ubuntu:latest
2-
RUN apt update && apt install -y build-essential linux-source bc kmod cpio flex libncurses5-dev libelf-dev libssl-dev dwarves bison git
3-
RUN git clone https://anongit.freedesktop.org/git/drm/drm-misc.git -b drm-misc-next --depth=1 kernel
2+
RUN apt update && apt install -y build-essential linux-source bc kmod cpio flex libncurses5-dev libelf-dev libssl-dev dwarves bison git rsync python3 zstd
43

4+
RUN git clone https://anongit.freedesktop.org/git/drm/drm-misc.git -b drm-misc-next --depth=1 kernel
55
RUN mkdir patches
66
COPY 0001-drm-edid-non-desktop.patch 0003-drm-edid-dsc-bpp-parse.patch 0004-drm-amd-dsc-bpp-apply.patch patches/
77
RUN cd kernel && git apply ../patches/*
8-
98
COPY .config kernel/
109

11-
RUN apt install -y rsync python3 zstd
1210
RUN cd kernel && nice make -j`nproc` bindeb-pkg
1311
RUN rm linux-image-*-dbg_*.deb && mv linux-image-*.deb linux.deb && mv linux-headers-*.deb headers.deb

kernel-patches/PKGBUILD

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
2+
3+
pkgbase=linux-drm-misc-next-git
4+
pkgver=6.1.0
5+
pkgrel=1
6+
pkgdesc='Linux with patches requied to use steamvr proxy driver'
7+
_product="${pkgbase%-git}"
8+
_branch="${_product#linux-}"
9+
arch=(x86_64)
10+
license=(GPL2)
11+
makedepends=(
12+
bc libelf pahole cpio perl tar xz git
13+
)
14+
options=('!strip')
15+
_srcname=archlinux-linux
16+
source=(
17+
"$_srcname::git+https://anongit.freedesktop.org/git/drm/drm-misc.git#branch=$_branch"
18+
config # the main kernel config file
19+
0001-drm-edid-non-desktop.patch
20+
0003-drm-edid-dsc-bpp-parse.patch
21+
0004-drm-amd-dsc-bpp-apply.patch
22+
)
23+
sha256sums=('SKIP'
24+
'SKIP'
25+
'SKIP'
26+
'SKIP'
27+
'SKIP')
28+
29+
pkgver() {
30+
cd $_srcname
31+
local version="$(grep \^VERSION Makefile|cut -d"=" -f2|cut -d" " -f2)"
32+
local patch="$(grep \^PATCHLEVEL Makefile|cut -d"=" -f2|cut -d" " -f2)"
33+
34+
printf "%s.%s.r%s.%s" "${version}" "${patch}" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
35+
}
36+
37+
export KBUILD_BUILD_HOST=archlinux
38+
export KBUILD_BUILD_USER=$pkgbase
39+
export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
40+
41+
prepare() {
42+
cd $_srcname
43+
44+
echo "Setting version..."
45+
scripts/setlocalversion --save-scmversion
46+
echo "-$pkgrel" > localversion.10-pkgrel
47+
echo "${pkgbase#linux}" > localversion.20-pkgname
48+
49+
local src
50+
for src in "${source[@]}"; do
51+
src="${src%%::*}"
52+
src="${src##*/}"
53+
[[ $src = *.patch ]] || continue
54+
echo "Applying patch $src..."
55+
patch -Np1 < "../$src"
56+
done
57+
58+
echo "Setting config..."
59+
cp ../config .config
60+
make olddefconfig
61+
diff -u ../config .config || :
62+
63+
make -s kernelrelease > version
64+
echo "Prepared $pkgbase version $(<version)"
65+
}
66+
67+
build() {
68+
cd $_srcname
69+
make -j`nproc` all
70+
}
71+
72+
_package() {
73+
pkgdesc="The $pkgdesc kernel and modules"
74+
depends=(coreutils kmod initramfs)
75+
optdepends=('wireless-regdb: to set the correct wireless channels of your country'
76+
'linux-firmware: firmware images needed for some devices')
77+
provides=(VIRTUALBOX-GUEST-MODULES WIREGUARD-MODULE KSMBD-MODULE)
78+
replaces=(virtualbox-guest-modules-arch wireguard-arch)
79+
80+
cd $_srcname
81+
local kernver="$(<version)"
82+
local modulesdir="$pkgdir/usr/lib/modules/$kernver"
83+
84+
echo "Installing boot image..."
85+
# systemd expects to find the kernel here to allow hibernation
86+
# https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
87+
install -Dm644 "$(make -s image_name)" "$modulesdir/vmlinuz"
88+
89+
# Used by mkinitcpio to name the kernel
90+
echo "$pkgbase" | install -Dm644 /dev/stdin "$modulesdir/pkgbase"
91+
92+
echo "Installing modules..."
93+
make INSTALL_MOD_PATH="$pkgdir/usr" INSTALL_MOD_STRIP=1 \
94+
DEPMOD=/doesnt/exist modules_install # Suppress depmod
95+
96+
# remove build and source links
97+
rm "$modulesdir"/{source,build}
98+
}
99+
100+
_package-headers() {
101+
pkgdesc="Headers and scripts for building modules for the $pkgdesc kernel"
102+
depends=(pahole)
103+
104+
cd $_srcname
105+
local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
106+
107+
echo "Installing build files..."
108+
install -Dt "$builddir" -m644 .config Makefile Module.symvers System.map \
109+
localversion.* version vmlinux
110+
install -Dt "$builddir/kernel" -m644 kernel/Makefile
111+
install -Dt "$builddir/arch/x86" -m644 arch/x86/Makefile
112+
cp -t "$builddir" -a scripts
113+
114+
# required when STACK_VALIDATION is enabled
115+
install -Dt "$builddir/tools/objtool" tools/objtool/objtool
116+
117+
# required when DEBUG_INFO_BTF_MODULES is enabled
118+
install -Dt "$builddir/tools/bpf/resolve_btfids" tools/bpf/resolve_btfids/resolve_btfids
119+
120+
echo "Installing headers..."
121+
cp -t "$builddir" -a include
122+
cp -t "$builddir/arch/x86" -a arch/x86/include
123+
install -Dt "$builddir/arch/x86/kernel" -m644 arch/x86/kernel/asm-offsets.s
124+
125+
install -Dt "$builddir/drivers/md" -m644 drivers/md/*.h
126+
install -Dt "$builddir/net/mac80211" -m644 net/mac80211/*.h
127+
128+
# https://bugs.archlinux.org/task/13146
129+
install -Dt "$builddir/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h
130+
131+
# https://bugs.archlinux.org/task/20402
132+
install -Dt "$builddir/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
133+
install -Dt "$builddir/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
134+
install -Dt "$builddir/drivers/media/tuners" -m644 drivers/media/tuners/*.h
135+
136+
# https://bugs.archlinux.org/task/71392
137+
install -Dt "$builddir/drivers/iio/common/hid-sensors" -m644 drivers/iio/common/hid-sensors/*.h
138+
139+
echo "Installing KConfig files..."
140+
find . -name 'Kconfig*' -exec install -Dm644 {} "$builddir/{}" \;
141+
142+
echo "Removing unneeded architectures..."
143+
local arch
144+
for arch in "$builddir"/arch/*/; do
145+
[[ $arch = */x86/ ]] && continue
146+
echo "Removing $(basename "$arch")"
147+
rm -r "$arch"
148+
done
149+
150+
echo "Removing documentation..."
151+
rm -r "$builddir/Documentation"
152+
153+
echo "Removing broken symlinks..."
154+
find -L "$builddir" -type l -printf 'Removing %P\n' -delete
155+
156+
echo "Removing loose objects..."
157+
find "$builddir" -type f -name '*.o' -printf 'Removing %P\n' -delete
158+
159+
echo "Stripping build tools..."
160+
local file
161+
while read -rd '' file; do
162+
case "$(file -bi "$file")" in
163+
application/x-sharedlib\;*) # Libraries (.so)
164+
strip -v $STRIP_SHARED "$file" ;;
165+
application/x-archive\;*) # Libraries (.a)
166+
strip -v $STRIP_STATIC "$file" ;;
167+
application/x-executable\;*) # Binaries
168+
strip -v $STRIP_BINARIES "$file" ;;
169+
application/x-pie-executable\;*) # Relocatable binaries
170+
strip -v $STRIP_SHARED "$file" ;;
171+
esac
172+
done < <(find "$builddir" -type f -perm -u+x ! -name vmlinux -print0)
173+
174+
echo "Stripping vmlinux..."
175+
strip -v $STRIP_STATIC "$builddir/vmlinux"
176+
177+
echo "Adding symlink..."
178+
mkdir -p "$pkgdir/usr/src"
179+
ln -sr "$builddir" "$pkgdir/usr/src/$pkgbase"
180+
}
181+
182+
pkgname=("$pkgbase" "$pkgbase-headers")
183+
for _p in "${pkgname[@]}"; do
184+
eval "package_$_p() {
185+
$(declare -f "_package${_p#$pkgbase}")
186+
_package${_p#$pkgbase}
187+
}"
188+
done
189+
190+
# vim:set ts=8 sts=2 sw=2 et:

kernel-patches/build-archlinux.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env sh
2+
3+
docker build . -f Dockerfile.archlinux-kernel -t proxy-driver-archlinux-kernel
4+
docker run proxy-driver-archlinux-kernel cat kernel/linux.pkg.tar.zst > linux.pkg.tar.zst
5+
docker run proxy-driver-archlinux-kernel cat kernel/headers.pkg.tar.zst > headers.pkg.tar.zst

kernel-patches/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.config

0 commit comments

Comments
 (0)