# Maintainer: Thiago Foganholi <thiagaoplusplus@outlook.com>
# Co-Maintainer: Newbyte <newbyte@disroot.org>
# Kernel config based on: arch/arm/configs/exynos_defconfig

pkgname=linux-postmarketos-exynos4
pkgver=6.1
pkgrel=2
pkgdesc="Mainline kernel fork for Samsung Exynos4 devices"
arch="armv7"
_carch="arm"
_flavor="${pkgname#linux-}"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	"
makedepends="
	bash
	bison
	busybox-static-armv7
	findutils
	flex
	gmp-dev
	mpc1-dev
	mpfr-dev
	openssl-dev
	perl
	postmarketos-installkernel
	xz
"

# Source
_config="config-$_flavor.$arch"
case $pkgver in
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac
source="
	https://cdn.kernel.org/pub/linux/kernel/v${_kernver%%.*}.x/linux-$_kernver.tar.xz
	$_config
	0001-ARM-decompressor-Flush-tlb-before-swiching-domain-0-.patch
	0002-ARM-dts-exynos-Add-reboot-modes-to-midas.patch
	0003-mmc-core-Workaround-VTU00M-0xf1-FTL-metadata-corrupt.patch
	0004-drivers-drm-Add-backlight-control-support-for-s6e8aa.patch
	0005-power_supply-max77693-Listen-for-cable-events-and-en.patch
	0006-mfd-max77693-Add-defines-for-charger-current-control.patch
	0007-power_supply-max77693-change-the-supply-type-to-POWE.patch
	0008-samsung-t0lte-add-leds.patch
	0009-Add-display-support-for-Samsung-Galaxy-Note-2-GT-N71.patch
	0010-drm-Allow-DRM_IOCTL_MODE_CREATE_DUMB-on-render-nodes.patch
	0011-ARM-dts-exynos-disable-HDMI-on-Midas.patch
	initramfs.list
	init
"
builddir="$srcdir/linux-${_kernver//_/-}"

prepare_isorec() {
	# https://wiki.postmarketos.org/wiki/Boot_process#isorec
	cp -v /usr/$(arch_to_hostspec $arch)/bin/busybox.static \
		"$builddir"/usr/
	cp -v "$srcdir"/init "$builddir"/usr/
	cp -v "$srcdir"/initramfs.list "$builddir"/usr/
}

prepare() {
	default_prepare
	prepare_isorec
	cp -v "$srcdir/$_config" .config
}

build() {
	unset LDFLAGS
	# V=1: workaround for pma#1990
	make ARCH="$_carch" CC="${CC:-gcc}" KCFLAGS="-Wno-array-bounds" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS" \
		V=1
}

package() {
	mkdir -p "$pkgdir"/boot
	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/boot/dtbs"

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir/usr/share/kernel/$_flavor/kernel.release"
}

sha512sums="
6ed2a73c2699d0810e54753715635736fc370288ad5ce95c594f2379959b0e418665cd71bc512a0273fe226fe90074d8b10d14c209080a6466498417a4fdda68  linux-6.1.tar.xz
677d6488fb4f466debcef800069d8a8567cac3cdece7be8b7b5c0433689aad4b47034c5b256b153c782b75109aefa359fddc23593a8f9f12f15afb69b8d98449  config-postmarketos-exynos4.armv7
b65a114f5dd7e62e96e48c5ae59a377999aead19d8dcc79f81e8eb533d97bb131779165b66878135185c6f235a66bd7b1908021b21e713ed79bc3c6e0e3b4d5f  0001-ARM-decompressor-Flush-tlb-before-swiching-domain-0-.patch
4de1c0c359b85ba0bb99a17b19fe795c3f3486785f1e14249da07b9f168b2e5b92e61ad5657a0332c95866032598ba0df0795580970ae2b4e73f8a6b1286ba4b  0002-ARM-dts-exynos-Add-reboot-modes-to-midas.patch
7956323f9a22e1cd5ed2a877b117ff4bb5ab6188dc7953e6b6a874d66192ea7c34df32969153dabe0070b40de080871b8fd1282b8d49f19014dabc91b267c679  0003-mmc-core-Workaround-VTU00M-0xf1-FTL-metadata-corrupt.patch
be042b8a949c26a4c0ee720b8622cf6d06f9532c35bb62a7c349f9306cd750504f8c858e1a5924f0dc261a3d52fb61077e5225f34257e3bd2b623ad014243f2d  0004-drivers-drm-Add-backlight-control-support-for-s6e8aa.patch
c35ce1e5619a18ebf9a0f39bfff129e77fb051fe680f01fe2603c64a4f656992f42e3033fa27508caea705b8d5b7fe192ddc6983cc408fe053cf8fe18dda2cc8  0005-power_supply-max77693-Listen-for-cable-events-and-en.patch
0301616fb5d4b6ccdca330e7888bbe9ca3cf0c8a448523f361bd3520d9fb3874343fd2c64e2bb5f84a9ab2c3364d86fc948a667a2e367852b46e37f0e2d8bac7  0006-mfd-max77693-Add-defines-for-charger-current-control.patch
e23725aae447c847a467a06e8cfeb759fe1b3f9915f61cca6ead8cc2392370015939e9d93e97c88764221bb7ee0b407780308718e199ec779809cffa2319ad77  0007-power_supply-max77693-change-the-supply-type-to-POWE.patch
2b991f210505ed430aaa4388069368824a394d55c7f62f20fb7d1fe20a512b785b5ca2208385d636dfc634b16e0ef8164bb95370e5bff43110356efb8f0faf23  0008-samsung-t0lte-add-leds.patch
cb8b78a472759fab3fbba22be4969d5e0e6ee67af23a224b51075dcab68bad64e6ac31e159d490bbef10ff5c5dda14cb2b40073ea7da783a29e89a534b4d5606  0009-Add-display-support-for-Samsung-Galaxy-Note-2-GT-N71.patch
2b62597047c3f217513803b601923c3556ee51beddf6e24ae25b5b48a51aa1050107bd3fdd963bace0809a5f6d488e2285c8ca43c0ba47b48bad2f439b536fb8  0010-drm-Allow-DRM_IOCTL_MODE_CREATE_DUMB-on-render-nodes.patch
40d24ae8fa64c934e688f7473cbdee979b5acab8f7c0bf3434bbc23b4159e29c939d62f0a896301dd15814296270d54454378cd75de5a778d1426f457c9386fb  0011-ARM-dts-exynos-disable-HDMI-on-Midas.patch
aaff0332b90e1f9f62de1128cace934717336e54ab09de46477369fa808302482d97334e43a85ee8597c1bcab64d3484750103559fea2ce8cd51776156bf7591  initramfs.list
09f1f214a24300696809727a7b04378887c06ca6f40803ca51a12bf2176a360b2eb8632139d6a0722094e05cb2038bdb04018a1e3d33fc2697674552ade03bee  init
"
