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

pkgname=linux-rpi
pkgver=4.4.20
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/rpi/linux-4.4.y-rpi-20160909.patch
	http://dev.alpinelinux.org/~tteras/rpi/rpi-cirrus-4.4.y-20160909.patch
	gpio-mcp23s08-pullups.patch
	rotary-encoder-fix.patch
	issue-4973.patch

	config-rpi.armhf
	config-rpi2.armhf
	markdt
	"
subpackages=""
_flavors=
for _i in $source; do
	case $_i in
	config-*.$CARCH)
		_f=${_i%.$CARCH}
		_f=${_f#config-}
		_flavors="$_flavors ${_f}"
		[ "linux-$_f" != "$pkgname" ] && subpackages="$subpackages linux-${_f}"
		subpackages="$subpackages linux-${_f}-dev:_${_f}_dev"
		;;
	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*)
		_install="zinstall dtbs_install"
		;;
	*)
		_install=install
		;;
	esac

	cd "$srcdir"/build-$_buildflavor || return 1
	make -j1 modules_install firmware_install $_install \
		INSTALL_MOD_PATH="$_outdir" \
		INSTALL_PATH="$_outdir"/boot \
		INSTALL_DTBS_PATH="$_outdir"/usr/lib/linux-${_abi_release} \
		|| 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"
}

_dev() {
	local _abi_release=${pkgver}-${pkgrel}-$1
	# 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 $1 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-$1.${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-$1/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
}

for _f in $_flavors; do
	[ "linux-$_f" != "$pkgname" ] && eval "${_f}() { _package "$_f" "$subpkgdir"; }"
	eval "_${_f}_dev() { _dev $_f; }"
done

md5sums="9a78fa2eb6c68ca5a40ed5af08142599  linux-4.4.tar.xz
335c5874b26a814987960b9170547a64  patch-4.4.20.xz
5f29cfb75f9ad6ffa8c9bc480bfbf077  linux-4.4.y-rpi-20160909.patch
0ef4cc8955f879dccf859932c86963e7  rpi-cirrus-4.4.y-20160909.patch
b66e8aa4991ca5c2ccd61559ed7e6491  gpio-mcp23s08-pullups.patch
5508d2b3e5967bd57f92f551d90b3e54  rotary-encoder-fix.patch
29281b74d2cef6965fa4ab6d826a2aa4  issue-4973.patch
7a3525bf77bfbbacd0e9c93916467767  config-rpi.armhf
1c7e19b1fb3ac587008ba6ee4ac6efdb  config-rpi2.armhf
e587cae1dca2f5992555d9bcf53deecf  markdt"
sha256sums="401d7c8fef594999a460d10c72c5a94e9c2e1022f16795ec51746b0d165418b2  linux-4.4.tar.xz
da9d7d3548070bc4a333786778f628eaa2a76e10f21a34567f591834a9e87d27  patch-4.4.20.xz
93bcceac6316588c1f9f63db138c4f9d31af13200cf71a3bfcfc0601c93804ac  linux-4.4.y-rpi-20160909.patch
5235b8c8a81dceb8fa525f45edfdd31876f72ca6207d43d3c72b2c6d0ed194e5  rpi-cirrus-4.4.y-20160909.patch
b389a556bbd98053881b43deef1adf20640f980557c5f37cfd7ece2daeecbda9  gpio-mcp23s08-pullups.patch
ab6740577fe8c1d71d2c716720ebbbf9a750985963d6938093b4ca9194b6e871  rotary-encoder-fix.patch
3a16e927ce53a8c56e7f1dd86fe8ad08b1c06466f5206c521a7e2de1e4796d6c  issue-4973.patch
5ffd8851bc03ebd43da77993be81881d41b04c43a98af6e2d46e5599e3a5de34  config-rpi.armhf
8c613dfe0b41b3c73ba99fde148cbdfda69638249b5dac956777ef6662c78dba  config-rpi2.armhf
0f6681fc5c3590e1dbe13a2bde796403bd1529cf0fe19720899eaa0db79bcb49  markdt"
sha512sums="13c8459933a8b80608e226a1398e3d1848352ace84bcfb7e6a4a33cb230bbe1ab719d4b58e067283df91ce5311be6d2d595fc8c19e2ae6ecc652499415614b3e  linux-4.4.tar.xz
551c375ce851304edbf8969e104e4d5b570b280a90ef5502f560dc482f6d8140256baba057ce4ffeea1a9338b2775cc1dbdc9a5f2acdf630c78fce32932deadb  patch-4.4.20.xz
47fe7dc572d010faf1239a94af7e99b9d8485088cbeb0ed89690c5d03fec7d2fb7584d5d0b7debf5d84660e4b1a0b30d4a417e973716ba527e75061c5823058d  linux-4.4.y-rpi-20160909.patch
a00d5172b9075d36e72a1f80071221f39257eeb448a9692d22c6480c7d242de60520e1829eb06314706379c95b8b52b4e131a24415e61a6a5ee0afb2ed818331  rpi-cirrus-4.4.y-20160909.patch
36724ba56cb8fdf3a3d347cffb67ae1cc3d7b1052d526b6b5134ebf6baae9f9724b586c97833453dc7697ab24699426f0749af78b6a80be36967a80033a0cf40  gpio-mcp23s08-pullups.patch
3a711e2cdb6c0ecaceb3755437d38626dec8403e8aa167a6e16f64d8a8b7cc5bdc7e04aa7c05938719ebc90e319ec4124ee2151a7855e7838ee143b62d140ad0  rotary-encoder-fix.patch
501c91bf2538a18102da59bbccc3097f9c3c90079acc0e946ff075074160c09b8a66934e5ce5470e170f0e4f93d114709a95230367426d0bb7ea02c4bdf4cc9b  issue-4973.patch
bef21233ad83b17e5fbbfc119bcd57f39b25940055392853350fe8774ba5405e155041662d6387aa7e2ce6158c8958a30cc2a857e67c0d4746b28f9531b8fa68  config-rpi.armhf
7a55325c576c49e272ee3e461d69c5ec3d62fbb1f1c5bae9d1d42b2d30b8ad798d57025779c2311816d74c31fd093bb72bcbff76d5728675e23b1a81d69af6ea  config-rpi2.armhf
a4ecd1f48db64f9d6a189250d1937d7f2cd3a049a3d24cc527d04d05db06137722f1ba44bcd6033794781c3f2cfe2fbe065410a16de4bfdf4b1cd95d89322a77  markdt"