aboutsummaryrefslogtreecommitdiffstats
path: root/main/linux-rpi/APKBUILD
blob: bb12d59160b6ad976b4fa71d5b0e47b0e3003783 (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
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>

_mainflavor=rpi
pkgname=linux-$_mainflavor
pkgver=4.1.13
case $pkgver in
*.*.*)	_kernver=${pkgver%.*};;
*.*)	_kernver=${pkgver};;
esac
pkgrel=0
pkgdesc="Linux kernel with Raspberry Pi patches"
url=https://github.com/raspberrypi/linux
depends="mkinitfs linux-firmware"
makedepends="perl installkernel bash gmp-dev bc"
options="!strip"
install=
source="http://ftp.kernel.org/pub/linux/kernel/v4.x/linux-$_kernver.tar.xz
	http://ftp.kernel.org/pub/linux/kernel/v4.x/patch-$pkgver.xz
	http://dev.alpinelinux.org/~tteras/linux-4.1.y-rpi-20151119.patch
	rpi-dma-i2s-fix.patch
	rpi-cirrus-4.1.x-20151025.patch

	config-rpi.armhf
	config-rpi2.armhf
	markdt
	"
subpackages="$pkgname-dev"
_flavors=
for _i in $source; do
	case $_i in
	config-*.$CARCH)
		_f=${_i%.$CARCH}
		_f=${_f#config-}
		_flavors="$_flavors ${_f}"
		if [ "linux-$_f" != "$pkgname" ]; then
			subpackages="$subpackages linux-${_f}"
		fi
		;;
	esac
done

arch="armhf"
license="GPL2"

prepare() {
	local _patch_failed=
	cd "$srcdir"/linux-$_kernver
	if [ "${pkgver%.0}" = "$pkgver" ]; then
		msg "Applying patch-$pkgver.xz"
		unxz -c < "$srcdir"/patch-$pkgver.xz | patch -p1 -N || return 1
	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

	# remove localversion from patch if any
	rm -f localversion*

	for i in $_flavors; do
		local _config=config-$i.${CARCH}
		local _builddir="$srcdir"/build-$i
		mkdir -p "$_builddir"
		echo "-$pkgrel-$i" > "$srcdir"/build-$i/localversion-alpine \
			|| return 1

		cp "$srcdir"/$_config "$_builddir"/.config || return 1
		make -C "$srcdir"/linux-$_kernver \
			O="$_builddir" \
			HOSTCC="${CC:-gcc}" \
			silentoldconfig || return 1
	done
}

build() {
	export GCC_SPECS=hardenednopie.specs
	for i in $_flavors; do
		cd "$srcdir"/build-$i
		make CC="${CC:-gcc}" \
			KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine" \
			|| return 1
	done
}

_package() {
	local _buildflavor="$1" _outdir="$2"
	local _abi_release=${pkgver}-${pkgrel}-${_buildflavor}

	cd "$srcdir"/build-$_buildflavor || return 1

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

	local _install
	case "$CARCH" in
	arm*)
		local _dtbdir="$_outdir"/usr/lib/linux-${_abi_release}
		cd "$srcdir"/build-$_buildflavor/arch/arm/boot/dts || return 1
		mkdir -p "$_dtbdir"
		find . -name "*.dtb" -type f | cpio -pdm "$_dtbdir"
		_install=zinstall
		;;
	*)
		_install=install
		;;
	esac

	cd "$srcdir"/build-$_buildflavor || return 1
	make -j1 modules_install firmware_install $_install \
		INSTALL_MOD_PATH="$_outdir" \
		INSTALL_PATH="$_outdir"/boot \
		|| return 1

	# tell rpi bootloader we are device tree capable
	"$srcdir"/markdt "$_outdir"/boot/vmlinuz-$_buildflavor \
		|| return 1

	rm -f "$_outdir"/lib/modules/${_abi_release}/build \
		"$_outdir"/lib/modules/${_abi_release}/source
	rm -rf "$_outdir"/lib/firmware

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

# main flavor installs in $pkgdir
package() {
	_package rpi "$pkgdir"
}

# subflavors install in $subpkgdir
rpi2() {
	_package rpi2 "$subpkgdir"
}

# we only provide -dev for main flavor for now
dev() {
	local _abi_release=${pkgver}-${pkgrel}-$_mainflavor
	# 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
	#
	pkgdesc="Headers and script for third party modules for grsec kernel"
	depends="gmp-dev bash"
	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"
	cp "$srcdir"/config-$_mainflavor.${CARCH} "$dir"/.config
	make -j1 -C "$srcdir"/linux-$_kernver O="$dir" HOSTCC="${CC:-gcc}" \
		silentoldconfig prepare modules_prepare scripts

	# remove the stuff that poits to real sources. we want 3rd party
	# 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
	# http://kernel.ubuntu.com/git?p=ubuntu/ubuntu-jaunty.git;a=blob;f=debian/rules.d/3-binary-indep.mk;hb=HEAD
	cd "$srcdir"/linux-$_kernver
	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' \) | cpio -pdm "$dir"
	cp -a drivers/media/dvb/dvb-core/*.h "$dir"/drivers/media/dvb/dvb-core
	cp -a drivers/media/video/*.h "$dir"/drivers/media/video
	cp -a drivers/media/dvb/frontends/*.h "$dir"/drivers/media/dvb/frontends
	cp -a scripts include "$dir"
	find $(find arch -name include -type d -print) -type f \
		| cpio -pdm "$dir"

	install -Dm644 "$srcdir"/build-$_mainflavor/Module.symvers \
		"$dir"/Module.symvers

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

md5sums="fe9dc0f6729f36400ea81aa41d614c37  linux-4.1.tar.xz
e1005015404c53692e8aa6dd14efff74  patch-4.1.13.xz
351cb861020321c0fd23fdc5a201463a  linux-4.1.y-rpi-20151119.patch
52787712305201c60ab9bc128c9e373b  rpi-dma-i2s-fix.patch
e3429d7772cb3bf73ff4c51aabb2a5cf  rpi-cirrus-4.1.x-20151025.patch
cb71e2a517e7d019596eab9cbc91a080  config-rpi.armhf
59f634c4646dab6bc1fe059efaf773e9  config-rpi2.armhf
e587cae1dca2f5992555d9bcf53deecf  markdt"
sha256sums="caf51f085aac1e1cea4d00dbbf3093ead07b551fc07b31b2a989c05f8ea72d9f  linux-4.1.tar.xz
1c3ba78cbaa1a260798d6d0d2aa319ff41ae676b443e5bf06ab441436dcdd171  patch-4.1.13.xz
cdb26705b8841bbadcf4e862dc3f582049fe8169a4951e4c4a34de1f3dac4293  linux-4.1.y-rpi-20151119.patch
f1349b95149f4a21949ebc3dae1c2b144278d170322afeb7975d2cea7f64f10c  rpi-dma-i2s-fix.patch
b1b5b8bf16e2eacec19931279984f2bc96851da6e9786d4c9422caa1ac7af2fe  rpi-cirrus-4.1.x-20151025.patch
c38d092ae49c4d3f642c4a99432d139092c331f2b33e81c5855b38381ad79411  config-rpi.armhf
5f450314b5af2d6079d32c3a67eb7df49dd73c4732cff392a953b19838fa6e6a  config-rpi2.armhf
0f6681fc5c3590e1dbe13a2bde796403bd1529cf0fe19720899eaa0db79bcb49  markdt"
sha512sums="168ef84a4e67619f9f53f3574e438542a5747f9b43443363cb83597fcdac9f40d201625c66e375a23226745eaada9176eb006ca023613cec089349e91751f3c0  linux-4.1.tar.xz
0fa60b9fceb6103c11ed1df8d4f264d1c4efcd75da258709f1d0a6813f8117977fa2279b36da22bd69cc2bc808b092207a438c2e80a65a988f4c72363a605832  patch-4.1.13.xz
cae26e2303fccf5246d1b3f8c78425860410ad7667ab7a9805497493d4926978b99ebe95486f00324e3af9cd86fb9e1965f719531ccff9c56efab8ea29b180d0  linux-4.1.y-rpi-20151119.patch
080ba354e40f86338278339b8b3fc2cfd5b77c38c34067b0b7e2b31d07834baf99b3bf04153844e86433bda6fc0de5d86679e1d99521109b1a9a5dbeee6df2b6  rpi-dma-i2s-fix.patch
3e4717c21def19d7c9714b1d9d07f8dbf8fd27e986cbd978eda50c586cc21d1399b50db4255589d09abb6fe5b532c3959481098f229c4ea4526a044fc1da17b0  rpi-cirrus-4.1.x-20151025.patch
69b5beae27dc58e7e7cf1aa351923a980ae453b39f9092fe97220f0b508f46e7e45197da22a2088723bafd6f9293c31475741c63a9ed8e587a1d45392addb9af  config-rpi.armhf
7d2f238f0a460fa4cbf6b26188fdbe8241a07846eaf3f6c6f4be33bdb836e9e26c58312109d51092e6faeb304c9281541c62da46539faa1614ef4c1bdacc08eb  config-rpi2.armhf
a4ecd1f48db64f9d6a189250d1937d7f2cd3a049a3d24cc527d04d05db06137722f1ba44bcd6033794781c3f2cfe2fbe065410a16de4bfdf4b1cd95d89322a77  markdt"