aboutsummaryrefslogtreecommitdiffstats
path: root/main/linux-rpi/APKBUILD
blob: 580253b1ccba12c1013832e26a21917ecf10e867 (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.10
case $pkgver in
*.*.*)	_kernver=${pkgver%.*};;
*.*)	_kernver=${pkgver};;
esac
pkgrel=1
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-20151006.patch
	rpi-cirrus-4.1.x-20151006.patch
	0001-inet-fix-potential-deadlock-in-reqsk_queue_unlink.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
599cb082ef44d8fb76ad8fd49d1b50fc  patch-4.1.10.xz
161b4c74b6071d5bfb51ac5175cbab04  linux-4.1.y-rpi-20151006.patch
0d7a68e45940e4ea33ee78e98dd2220a  rpi-cirrus-4.1.x-20151006.patch
ffa7fdc282af20f2b48b95b2687b7452  0001-inet-fix-potential-deadlock-in-reqsk_queue_unlink.patch
ed39ac7b625c6fbe29c8e503f2657d21  config-rpi.armhf
2247472fa947c79450406ae0de2ec910  config-rpi2.armhf
e587cae1dca2f5992555d9bcf53deecf  markdt"
sha256sums="caf51f085aac1e1cea4d00dbbf3093ead07b551fc07b31b2a989c05f8ea72d9f  linux-4.1.tar.xz
929e210fe6dbd5dd26812c146630be14e979aae6c960a2feb39544babb8e73cb  patch-4.1.10.xz
777909c66d87d0f18796cc4fe426a30ae89ce20380c62ae00976bbffd28374ec  linux-4.1.y-rpi-20151006.patch
ce55c9d56b862de3d1ac1eb39f0bbac2a4c0659dc5b0e298094a9c42556acf11  rpi-cirrus-4.1.x-20151006.patch
c56583010561ca7d7b5e5aa3eed67c939f67deb2d22af7155e475c10baa4d7a5  0001-inet-fix-potential-deadlock-in-reqsk_queue_unlink.patch
838218b4df392befad9566cdd761b6475c6e473c9bc47ee107df09dc4f07169c  config-rpi.armhf
87bda7066763cf6ef16de7f3863300c8b6d89caa76d06e58e3b0a0ac2be2e4b5  config-rpi2.armhf
0f6681fc5c3590e1dbe13a2bde796403bd1529cf0fe19720899eaa0db79bcb49  markdt"
sha512sums="168ef84a4e67619f9f53f3574e438542a5747f9b43443363cb83597fcdac9f40d201625c66e375a23226745eaada9176eb006ca023613cec089349e91751f3c0  linux-4.1.tar.xz
3b5cb5c8f494958c39a06a1b416e3e5a075a3c76c44f8bf1ae5a14deec9861407100c2ef59b0720e8fc0729b5c8422b4d819ff59f1f7ec4eed20c5ba8a95d6d5  patch-4.1.10.xz
fa9022592a4ea1ce7cc2cadac672ba120471be6453f40acef8b8ac6ad50fa36701bd4ebe335507dff848d335c2b7f4e74ec0313ea039edfa7a35900c31639097  linux-4.1.y-rpi-20151006.patch
c8e3b1a4a18a2b1864831e7b9de26e2c0d0bf7956632741152b150a7d749f1b0ab955f04f8db0c533c81f34b9580476007e2b5d9c5f01688441a14870675617f  rpi-cirrus-4.1.x-20151006.patch
32ae58cf74d5e02cb09445be35772dad0a517949bd1836f8dbc90b871de67901b61dba5eccdc2a795a9f7e5c06831335504a738205eb49768f7424cf30ddd8ae  0001-inet-fix-potential-deadlock-in-reqsk_queue_unlink.patch
ddab2fed512e73b6ae501f0ab795f58c4b9a05afc297cff1a3b710048458db7c13c727af096b8a0fa24306c8dd1eba80a4e6c1c71cc5219fa8aa21b843f2d9f8  config-rpi.armhf
b07701ce1069e2a29d609dd67f6f578fa3d3f10c0fbdf01ebe7b97680fcfb4c793948e655471e577f9eb73326891d9cac3a8ed9110b29c92b3b41584caa867f3  config-rpi2.armhf
a4ecd1f48db64f9d6a189250d1937d7f2cd3a049a3d24cc527d04d05db06137722f1ba44bcd6033794781c3f2cfe2fbe065410a16de4bfdf4b1cd95d89322a77  markdt"