APKBUILD 9.11 KB
Newer Older
1 2
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>

3
pkgname=linux-rpi
4
pkgver=4.19.67
5
case $pkgver in
6 7
*.*.*)	_kernver=${pkgver%.*};;
*.*)	_kernver=${pkgver};;
8
esac
9
pkgrel=0
10 11
pkgdesc="Linux kernel with Raspberry Pi patches"
url=https://github.com/raspberrypi/linux
12 13
depends="mkinitfs"
_depends_dev="perl gmp-dev elfutils-dev bash"
14 15 16
makedepends="$_depends_dev sed installkernel bc linux-headers linux-firmware
	bison flex openssl-dev
"
17
options="!strip !check"
18 19
_rpi_repo="git://github.com/raspberrypi/linux.git"
_linux_repo="git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git"
20 21
source="https://kernel.org/pub/linux/kernel/v4.x/linux-$_kernver.tar.xz
	https://kernel.org/pub/linux/kernel/v4.x/patch-$pkgver.xz
22
	https://dev.alpinelinux.org/archive/rpi-patches/rpi-$pkgver-alpine.patch
23

24
	issue-4973.patch
Timo Teräs's avatar
Timo Teräs committed
25

26 27 28
	config-changes-rpi.armhf
	config-changes-rpi.aarch64
	config-changes-rpi2.armhf
29 30
	config-changes-rpi.armv7
	config-changes-rpi2.armv7
31
	"
32
subpackages=""
33
arch="armhf armv7 aarch64"
34
license="GPL-2.0"
Timo Teräs's avatar
Timo Teräs committed
35 36 37 38 39
_flavors=
for _i in $source; do
	case $_i in
	config-*.$CARCH)
		_f=${_i%.$CARCH}
40
		_f=${_f#config-changes-}
Timo Teräs's avatar
Timo Teräs committed
41
		_flavors="$_flavors ${_f}"
42 43
		[ "linux-$_f" != "$pkgname" ] && subpackages="$subpackages linux-${_f}::$CBUILD_ARCH"
		subpackages="$subpackages linux-${_f}-dev:_dev:$CBUILD_ARCH"
Timo Teräs's avatar
Timo Teräs committed
44 45 46 47
		;;
	esac
done

48 49 50 51 52 53 54
case "$CARCH" in
	aarch64) _carch="arm64" ;;
	arm*) _carch="arm" ;;
esac

HOSTCC="${CC:-gcc}"
HOSTCC="${HOSTCC#${CROSS_COMPILE}}"
55 56 57 58

prepare() {
	local _patch_failed=
	cd "$srcdir"/linux-$_kernver
59
	if [ "${pkgver%.0}" = "$pkgver" ]; then
60
		msg "Applying patch-$pkgver.xz"
61
		unxz -c < "$srcdir"/patch-$pkgver.xz | patch -p1 -N
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
	fi

	# first apply patches in specified order
	for i in $source; do
		case $i in
		*.patch)
			msg "Applying $i..."
			if ! patch -s -p1 -N -i "$srcdir"/${i##*/}; then
				echo $i >>failed
				_patch_failed=1
			fi
			;;
		esac
	done

	if ! [ -z "$_patch_failed" ]; then
		error "The following patches failed:"
		cat failed
		return 1
	fi

Timo Teräs's avatar
Timo Teräs committed
83
	# remove localversion from patch if any
84
	rm -f localversion*
85

86 87 88 89 90 91
	local flavor=
	for flavor in $_flavors; do
		local builddir="$srcdir"/build-$flavor
		mkdir -p "$builddir"
		echo "-$pkgrel-$flavor" > "$builddir"/localversion-alpine
		_genconfig $flavor
Timo Teräs's avatar
Timo Teräs committed
92
		make -C "$srcdir"/linux-$_kernver \
93 94 95 96 97
			O="$builddir" \
			ARCH="$_carch" \
			HOSTCC="$HOSTCC" \
			olddefconfig
		_verifyconfig $flavor
Timo Teräs's avatar
Timo Teräs committed
98
	done
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
# generate config from defconfig and apply local changes.
# config-changes-$flavor.$CARCH holds a list of = delimited
# config command and values used by kernel scripts/config script.
_genconfig() {
	local flavor=$1 defconfig=
	local builddir="$srcdir"/build-$flavor
	local defconfig=
	case $flavor in
		rpi) defconfig=bcmrpi_defconfig
		[ "$CARCH" = "aarch64" ] && defconfig=bcmrpi3_defconfig ;;
		rpi2) defconfig=bcm2709_defconfig ;;
		*) die "Unknown flavor: $flavor" ;;
	esac

	cp "$srcdir"/linux-$_kernver/arch/$_carch/configs/$defconfig \
		"$builddir"/.config

	while read line; do
		[ ${line:0:1} = "#" ] && continue
		local option=${line%%=*} str=
		local cmd=$(echo $line | cut -d= -f2)
		case "$cmd" in
			enable|disable|module) str= ;;
			set-str|set-val) str=${line##*=} ;;
			*) die "Command $cmd not accepted" ;;
		esac
		msg "[$flavor] $cmd: $option $str"
		"$srcdir"/linux-$_kernver/scripts/config \
			--file "$builddir"/.config \
			--${cmd} "$option" "${str//\"/}"
	done < "$srcdir"/config-changes-$flavor.${CARCH}
}

# verify if options are set to correct value
_verifyconfig() {
	local flavor=$1
	local builddir="$srcdir"/build-$flavor
	while read line; do
		[ ${line:0:1} = "#" ] && continue
		local option=${line%%=*} str= invert=
		local cmd=$(echo $line | cut -d= -f2)
		case "$cmd" in
			enable) str="$option=y" ;;
			disable) str="$option"; invert="-v" ;;
			module) str="$option=m" ;;
			set-val) str="$option=${line##*=}" ;;
			set-str) str=${line##*=}
				str="$option=\"${str//\"/}\"" ;;
		esac
		grep -q $invert "^$str" "$builddir"/.config || \
			die "Config: $option not properly set!"
	done < "$srcdir"/config-changes-$flavor.${CARCH}
}

155
build() {
156
	unset LDFLAGS
Timo Teräs's avatar
Timo Teräs committed
157 158
	for i in $_flavors; do
		cd "$srcdir"/build-$i
159 160
		make ARCH="$_carch" CC="${CC:-gcc}" \
			KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine"
Timo Teräs's avatar
Timo Teräs committed
161
	done
162 163
}

Timo Teräs's avatar
Timo Teräs committed
164 165 166 167
_package() {
	local _buildflavor="$1" _outdir="$2"
	local _abi_release=${pkgver}-${pkgrel}-${_buildflavor}

168
	cd "$srcdir"/build-$_buildflavor
Timo Teräs's avatar
Timo Teräs committed
169 170 171 172 173 174

	mkdir -p "$_outdir"/boot "$_outdir"/lib/modules

	local _install
	case "$CARCH" in
	arm*)
175
		_install="zinstall dtbs_install"
Timo Teräs's avatar
Timo Teräs committed
176
		;;
177 178 179
	aarch64)
		_install="install dtbs_install"
		;;
Timo Teräs's avatar
Timo Teräs committed
180 181 182 183 184
	*)
		_install=install
		;;
	esac

185
	cd "$srcdir"/build-$_buildflavor
186
	local INSTALL_DTBS_PATH="$_outdir"/usr/lib/linux-${_abi_release}
187 188
	make -j1 modules_install $_install \
		ARCH="$_carch" \
Timo Teräs's avatar
Timo Teräs committed
189 190
		INSTALL_MOD_PATH="$_outdir" \
		INSTALL_PATH="$_outdir"/boot \
191
		INSTALL_DTBS_PATH="$INSTALL_DTBS_PATH"
192

Timo Teräs's avatar
Timo Teräs committed
193 194 195
	rm -f "$_outdir"/lib/modules/${_abi_release}/build \
		"$_outdir"/lib/modules/${_abi_release}/source
	rm -rf "$_outdir"/lib/firmware
196 197

	install -D include/config/kernel.release \
198
		"$_outdir"/usr/share/kernel/$_buildflavor/kernel.release
199

200 201 202 203 204
	if [ "$CARCH" = "aarch64" ]; then
		mv -f "$INSTALL_DTBS_PATH"/broadcom/*.dtb \
			"$INSTALL_DTBS_PATH"
		rmdir "$INSTALL_DTBS_PATH"/broadcom
	fi
Timo Teräs's avatar
Timo Teräs committed
205 206
}

207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
genpatch() {
	local RPI_REPO_PATH="$HOME/repositories/linux-rpi"
	msg "Checking out/pulling the Linux kernel git repository.."
	mkdir -p "$RPI_REPO_PATH" && cd "$RPI_REPO_PATH"
	git clone "$_linux_repo" "$RPI_REPO_PATH" 2>/dev/null || git pull
	msg "Fetching raspberry git repository.."
	git remote add rpi "$_rpi_repo" 2>/dev/null || true
	git fetch rpi
	msg "Generating rpi patch: rpi-$pkgver.patch"
	mkdir -p "$srcdir"
	git diff v$pkgver remotes/rpi/rpi-${pkgver%.*}.y > \
		"$srcdir"/rpi-$pkgver.patch
	msg "Sending patch to dev.alpinelinux.org.."
	scp "$srcdir"/rpi-$pkgver.patch \
		dev.alpinelinux.org:/archive/rpi-patches/rpi-$pkgver.patch
	cd "$startdir" && abuild checksum
}

Timo Teräs's avatar
Timo Teräs committed
225 226
# main flavor installs in $pkgdir
package() {
227
	depends="$depends linux-firmware-brcm"
Timo Teräs's avatar
Timo Teräs committed
228 229 230
	_package rpi "$pkgdir"
}

231 232
# subflavors install in $subpkgdir
rpi2() {
233
	depends="$depends linux-firmware-brcm"
234

235 236 237
	_package rpi2 "$subpkgdir"
}

238
_dev() {
239 240
	local _flavor=$(echo $subpkgname | sed -E 's/(^linux-|-dev$)//g')
	local _abi_release=${pkgver}-${pkgrel}-$_flavor
241 242 243 244 245 246 247
	# copy the only the parts that we really need for build 3rd party
	# kernel modules and install those as /usr/src/linux-headers,
	# simlar to what ubuntu does
	#
	# this way you dont need to install the 300-400 kernel sources to
	# build a tiny kernel module
	#
248
	pkgdesc="Headers and script for third party modules for $_flavor kernel"
249
	depends="$_depends_dev"
250 251 252 253 254
	local dir="$subpkgdir"/usr/src/linux-headers-${_abi_release}

	# first we import config, run prepare to set up for building
	# external modules, and create the scripts
	mkdir -p "$dir"
255
	cp "$srcdir"/build-$_flavor/.config "$dir"/.config
256
	make -j1 -C "$srcdir"/linux-$_kernver O="$dir" HOSTCC="${CC:-gcc}" \
257
		silentoldconfig prepare modules_prepare scripts
258

259
	# remove the stuff that points to real sources. we want 3rd party
260 261 262 263 264 265
	# modules to believe this is the soruces
	rm "$dir"/Makefile "$dir"/source

	# copy the needed stuff from real sources
	#
	# this is taken from ubuntu kernel build script
266
	# http://kernel.ubuntu.com/git/ubuntu/ubuntu-zesty.git/tree/debian/rules.d/3-binary-indep.mk
267
	cd "$srcdir"/linux-$_kernver
268 269 270 271
	find .  -path './include/*' -prune \
		-o -path './scripts/*' -prune -o -type f \
		\( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
		   -name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \
272
		-print | cpio -pdm "$dir"
273

274
	cp -a scripts include "$dir"
275 276 277
	find $(find arch -name include -type d -print) -type f \
		| cpio -pdm "$dir"

278
	install -Dm644 "$srcdir"/build-$_flavor/Module.symvers \
279 280 281 282 283 284 285
		"$dir"/Module.symvers

	mkdir -p "$subpkgdir"/lib/modules/${_abi_release}
	ln -sf /usr/src/linux-headers-${_abi_release} \
		"$subpkgdir"/lib/modules/${_abi_release}/build
}

286
sha512sums="ab67cc746b375a8b135e8b23e35e1d6787930d19b3c26b2679787d62951cbdbc3bb66f8ededeb9b890e5008b2459397f9018f1a6772fdef67780b06a4cb9f6f4  linux-4.19.tar.xz
287 288
a73ea67811cdb6c7b86a249f21252e76af5926b50df7cd7a3b418b49a24afd5c66e69394cd0152dcbd8837c1271af485b794953d18595c936d4d62ac54442107  patch-4.19.67.xz
eb3d355d3c8c79d77abf3aad18ad9bca53ded43c0b7127a01f6794fa8688de6439fcd23c9029cb931b7b8e4d2a912419afd372ca03d4db6df8bb0be8188f666f  rpi-4.19.67-alpine.patch
289
501c91bf2538a18102da59bbccc3097f9c3c90079acc0e946ff075074160c09b8a66934e5ce5470e170f0e4f93d114709a95230367426d0bb7ea02c4bdf4cc9b  issue-4973.patch
290 291 292 293 294
6c1c1c61ceb323eecb0e81e226af6b5b8fef7c8c075b1eb836639f465de5ef5d23648716c953d295250f8c6567546782956afe644573b84920a4f6902a1a0454  config-changes-rpi.armhf
6c1c1c61ceb323eecb0e81e226af6b5b8fef7c8c075b1eb836639f465de5ef5d23648716c953d295250f8c6567546782956afe644573b84920a4f6902a1a0454  config-changes-rpi.aarch64
6c1c1c61ceb323eecb0e81e226af6b5b8fef7c8c075b1eb836639f465de5ef5d23648716c953d295250f8c6567546782956afe644573b84920a4f6902a1a0454  config-changes-rpi2.armhf
6c1c1c61ceb323eecb0e81e226af6b5b8fef7c8c075b1eb836639f465de5ef5d23648716c953d295250f8c6567546782956afe644573b84920a4f6902a1a0454  config-changes-rpi.armv7
6c1c1c61ceb323eecb0e81e226af6b5b8fef7c8c075b1eb836639f465de5ef5d23648716c953d295250f8c6567546782956afe644573b84920a4f6902a1a0454  config-changes-rpi2.armv7"