aboutsummaryrefslogblamecommitdiffstats
path: root/testing/linux-elm/APKBUILD
blob: da873cc976609a255f8072a417b284859ad52a01 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11





                                                
             



                                       
        

                                                        



                                                                                


                                      
                                             









                                                                                        

                                       
                           
                                      


















































































































                                                                                                              
                                                        



























                                                                                                                                   
                                                                   





















































                                                                                                    
            
                                                                                                                                                   
                                                                                                                                                 
                                                                                                                                                    
                                                                                                                                                

                                                                                                                                                                 
                                                                                                                                                     
                                                                                                                                                                
 
# Maintainer: Milan P. Stanić <mps@arvanta.net>

_flavor=elm
pkgname=linux-${_flavor}
# NOTE: this kernel is intended for testing
# please resist urge to upgrade it blindly
pkgver=5.16.3
case $pkgver in
	*.*.*)	_kernver=${pkgver%.*};;
	*.*) _kernver=$pkgver;;
esac
pkgrel=0
pkgdesc="Linux latest stable kernel for elm chromebooks"
url="https://www.kernel.org"
_depends_dev="perl gmp-dev bash flex bison"
makedepends="$_depends_dev sed installkernel bc linux-headers linux-firmware-any
	openssl1.1-compat-dev diffutils findutils vboot-utils u-boot-tools dtc"
options="!strip !check"
_config=${config:-config-elm.${CARCH}}
install=

#subpackages="$pkgname-dev:_dev:$CBUILD_ARCH"
source="https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-$_kernver.tar.xz"
case $pkgver in
	*.*.0)	source="$source";;
	*.*.*)	source="$source
	https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/patch-$pkgver.xz" ;;
esac

	source="$source
	config-elm.aarch64
	kernel.its.elm
	fix-mmc1-speed.patch
	fix-spi-nor-max-frequency.patch
	fix-mmc-order.patch
	mps-ter12x24-font-kernel.patch
	"

arch="aarch64"
license="GPL-2.0"

_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}::$CBUILD_ARCH linux-${_f}-dev:_dev:$CBUILD_ARCH"
		fi
		;;
	esac
done

_carch=${CARCH}
case "$_carch" in
aarch64*) _carch="arm64" ;;
arm*) _carch="arm" ;;
esac

prepare() {
	local _patch_failed=
	cd "$srcdir"/linux-$_kernver
	case $pkgver in
		*.*.0);;
		*)
		msg "Applying patch-$pkgver.xz"
		unxz -c < "$srcdir"/patch-$pkgver.xz | patch -p1 -N ;;
	esac

	# 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*
	oldconfig
}

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

		cp "$srcdir"/$_config "$_builddir"/.config
		make -C "$srcdir"/linux-$_kernver \
			O="$_builddir" \
			ARCH="$_carch" \
			listnewconfig oldconfig
	done
}

build() {
	unset LDFLAGS
	export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
	for i in $_flavors; do
		cd "$srcdir"/build-$i.$CARCH
		make ARCH="$_carch" CC="${CC:-gcc}" \
			KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine"
	done
}

_package() {
	local _buildflavor="$1" _outdir="$2"
	local _abi_release=${pkgver}-${pkgrel}-${_buildflavor}
	export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"

	cd "$srcdir"/build-$_buildflavor.$CARCH
	# modules_install seems to regenerate a defect Modules.symvers on s390x. Work
	# around it by backing it up and restore it after modules_install
	cp Module.symvers Module.symvers.backup

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

	local _install
	case "$CARCH" in
		arm*|aarch64) _install="zinstall dtbs_install";;
		*) _install=install;;
	esac

	make -j1 modules_install $_install \
		ARCH="$_carch" \
		INSTALL_MOD_PATH="$_outdir" \
		INSTALL_PATH="$_outdir"/boot \
		INSTALL_DTBS_PATH="$_outdir/boot/dtbs-$_buildflavor"

	cp Module.symvers.backup Module.symvers

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

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

# main flavor installs in $pkgdir
package() {

	_package elm "$pkgdir"
	local _builddir="$srcdir"/build-$_flavor.$CARCH
	cd $_builddir
	cp $srcdir/kernel.its.elm .
	mkimage -D "-I dts -O dtb -p 2048" -f kernel.its.elm vmlinux.uimg

	dd if=/dev/zero of=bootloader.bin bs=512 count=1
	echo "console=tty1 earlyprintk=tty1 init=/sbin/init root=PARTUUID=%U/PARTNROFF=1 rootwait rw noinitrd loglevel=7" > cmdline
	vbutil_kernel \
		--pack $pkgdir/boot/vmlinux.kpart-$pkgver-$pkgrel-$_flavor \
		--version 1 \
		--vmlinuz vmlinux.uimg \
		--arch aarch64 \
		--keyblock /usr/share/vboot/devkeys/kernel.keyblock \
		--signprivate kernel_data_key.vbprivk \
		--signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
		--config cmdline \
		--bootloader bootloader.bin

	rm cmdline bootloader.bin
	rm $pkgdir/boot/vmlinuz-elm
	cd $pkgdir/boot
	ln -s vmlinux.kpart-$pkgver-$pkgrel-$_flavor vmlinux.kpart 
}

_dev() {
	local _flavor=$(echo $subpkgname | sed -E 's/(^linux-|-dev$)//g')
	local _abi_release=${pkgver}-${pkgrel}-$_flavor
	# 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 $_flavor kernel"
	depends="$_depends_dev"
	local dir="$subpkgdir"/usr/src/linux-headers-${_abi_release}
	export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"

	# first we import config, run prepare to set up for building
	# external modules, and create the scripts
	mkdir -p "$dir"
	cp "$srcdir"/config-$_flavor.${CARCH} "$dir"/.config
	echo "-$pkgrel-$_flavor" > "$dir"/localversion-alpine

	make -j1 -C "$srcdir"/linux-$_kernver O="$dir" ARCH="$_carch" \
		syncconfig prepare modules_prepare scripts

	# remove the stuff that points 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/ubuntu/ubuntu-zesty.git/tree/debian/rules.d/3-binary-indep.mk
	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' -o -name 'Platform' \) \
		-print | cpio -pdm "$dir"

	cp -a scripts include "$dir"

	find $(find arch -name include -type d -print) -type f \
		| cpio -pdm "$dir"

	install -Dm644 "$srcdir"/build-$_flavor.$CARCH/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
}

sha512sums="
7a257dd576bc8493595ec7d6f3c9cb6e22c772a8b2dbe735d2485c4f5c56e26a08695546e7e0f1f1cd04a533f25e829361958d4da0b98bf0ba8094dd57a85aaf  linux-5.16.tar.xz
728b22428891a39d727b71daa25f01cc0e4f700b96997b5e6294da1d441336d6d99526994ed8a2eab5cc784178560e17dbed5a4cb154e6238a8be1d7ac726ab5  patch-5.16.3.xz
95b1ac2d8944bf7426724b15ece7ff53442c5fdc1fc125c53149b7b749ba086e8c76dca4b87ea0797dfec29149ed5e0eb34ae45fdbbfbfdb11af147d4a9f4b56  config-elm.aarch64
112af92af4a3f61867ffc20076d057845aa8c9139e58153d0c88f4d7185d9a9628fa79d4edfa8855f095fb70d257bfbd7c4573a7431d4b17706415b411a50775  kernel.its.elm
65c57a6d9a5bd5b6ec8798d1c46091bb72377ed1349b66e9a0a1a50ffa077f044f2bfdd30eab974c9c9774fc62d8dd5020a38432d108fce7f4fc1ed6648ea703  fix-mmc1-speed.patch
9e17fb96b81590da0f9b0917ddd2b9d195bab5cde2a4e7feb19991c50a8ac8e4502445715153ced8666e5b6575137c1d49899bb0ae9ab4505ed8f1ff7e569269  fix-spi-nor-max-frequency.patch
00e7afdab1dc89a6e0426829685d85cebb98fb95cb13a253d01326fd22f78ddf792bbe3b5be4c9bc93784f1fa93f87f604a4b6c6710660319db6f2e35dd09835  fix-mmc-order.patch
fcea50a1ba2356d64a9c3ee0b7b7c326654996956d68eb445fafdb4320b4104b6321f768f0ce4ceb5cd4696be3a7332908ba1de7054fb20bf8c97f4234bfa6a4  mps-ter12x24-font-kernel.patch
"