aboutsummaryrefslogtreecommitdiffstats
path: root/main/linux-rpi/APKBUILD
blob: d74002c85e69f6c8f1521438f8e0a24f1f86d3c8 (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=3.18.16
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/v3.x/linux-$_kernver.tar.xz
	http://ftp.kernel.org/pub/linux/kernel/v3.x/patch-$pkgver.xz
	http://dev.alpinelinux.org/~tteras/linux-3.18.y-rpi-20150617.patch
	aslr-pie.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="GPL-2"

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}
		mkdir -p "$_dtbdir" "$_dtbdir"/overlays
		for i in arch/arm/boot/dts/*.dtb ; do
			case "$i" in
			*-overlay.dtb)	install -m644 "$i" "$_dtbdir/overlays" ;;
			*.dtb)		install -m644 "$i" "$_dtbdir" ;;
			esac
		done

		_install=zinstall
		;;
	*)
		_install=install
		;;
	esac

	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="9e854df51ca3fef8bfe566dbd7b89241  linux-3.18.tar.xz
96aeccef48037aee98911634664af68e  patch-3.18.16.xz
4224a13261d65db5c09e88e6a14d670b  linux-3.18.y-rpi-20150617.patch
6f5854b710be8f38f67fc7ec8f3d0625  aslr-pie.patch
1363c986e464d95a090c9e30fa2b5253  config-rpi.armhf
895a0286802f8dc0eeecd2d31443074d  config-rpi2.armhf
1f3dda659442fa7e2afc62bffeceb129  markdt"
sha256sums="becc413cc9e6d7f5cc52a3ce66d65c3725bc1d1cc1001f4ce6c32b69eb188cbd  linux-3.18.tar.xz
f60602c8de2ae7b1507c538b6af65d5b933727a06f56075898ff64fdcf650313  patch-3.18.16.xz
82f881bfbb3f761ae4c81ec6272ee0b62f1066deb9fff9b290774f844d838638  linux-3.18.y-rpi-20150617.patch
e1db8126b13507f4442b1fa5c3d2648fa453f0ca3ea75145ec6f0faeab923c08  aslr-pie.patch
d4d77d5b9defb84add2f77e045c39ba4a067f7fdd908d13be0e7b6b18caf00c4  config-rpi.armhf
927ec7509b059fc8f4f4220f917571c68404c15683724e0090e3669417e32fd3  config-rpi2.armhf
289a7509bc294295b65680c7fff0b2ec07cf359ea8a57cef00267396885f9b54  markdt"
sha512sums="2f0b72466e9bc538a675738aa416573d41bbbd7e3e2ffd5b5b127afde609ebc278cec5a3c37e73479607e957c13f1b4ed9782a3795e0dcc2cf8e550228594009  linux-3.18.tar.xz
868de9793e67e741dc69d61339f66c25d08d36a7d67b09d5644e855e05faf239c1e6e01299812a68edc52a39e132d7ec459929cb5d8a0936fe6aa580a72af80c  patch-3.18.16.xz
f48822399d842f60d533d11be0c1eeb881d21fb69fa110d19cb0778d271e9f2bd230673a9dffca98483a317150fac62c0eb1e0fae50d85751b05fa0b7a58132f  linux-3.18.y-rpi-20150617.patch
8b2080b72cd0a1bf8f528e8a7a4ab7921ee9e1e425a5c0439e9409b599eca23ad992f5fec67924da736c20de9728c7f0cb2f3087212a278e82ba8ecfc8fac7d0  aslr-pie.patch
35a51b1fb94605cc522a76389be940f9283361fe4062de3fd0439f87e1b2fdc8852de3e7c93b0657641577f266697cfe7e953b3ec5d82e45f45ba7901b2d0e74  config-rpi.armhf
98943cedaa265f0e7a1b45ba12ee6bcc5118841b2ae1789036e475da640f2d3fa65e871cd8e184a1acdc3120bda98001de92682cdbaaaad737de7da4a50b9632  config-rpi2.armhf
89601aa0e4f77fb07fb1d58c6a9394c8683bc7dfc905ca6612d607ef4188637662d295fa3d5640e3e0a4cd08c98c10511a4f3cea41e7568167b12d0a6c813e8b  markdt"