Github messages for voidlinux
 help / color / mirror / Atom feed
* [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
@ 2021-02-28 21:35 Piraty
  2021-02-28 22:10 ` the-maldridge
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: Piraty @ 2021-02-28 21:35 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1117 bytes --]

There is a new pull request by Piraty against master on the void-packages repository

https://github.com/Piraty/void-packages rpi-kernel-split
https://github.com/void-linux/void-packages/pull/29139

[NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
This is my second approach to the rpi4 problem (first try: https://github.com/void-linux/void-packages/pull/26000)

The problem is: how to not break existing systems while having a consistent naming scheme for rpi-kernel / rpi-base.

As demanded by @the-maldridge , `rpi-kernel` continues to provide the kernel for rpi0/rpi1 and becomes a meta package that pulls `rpi{2,3}-kernel` (based on target arch) to serve legacy systems.

To support legacy systems, rpi-base is split into rpiN-base which all ship the same udev rule and depend on the respective kernel. This (still) allows to have a single entry-point to raspberry related packages.

I performed (offline) testing of the package transition process, seems fine. Script here

@pbui @Duncaen @ahesford 

A patch file from https://github.com/void-linux/void-packages/pull/29139.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-rpi-kernel-split-29139.patch --]
[-- Type: text/x-diff, Size: 33681 bytes --]

From 5987c4a65f4350f24d6fbc2ae55a98859d4396e7 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:00 +0100
Subject: [PATCH 1/4] rpi-kernel: split into rpi, rpi2, rpi3

Until now, raspberry Pi variants were solely distiguished by the target
architecture; this is insufficient for handling the upcoming addition of
rpi4-kernel, so split them.

* rpi-kernel will continue to serve raspberry Pi variants rpi0 and rpi1 for armv6l
* rpi2-kernel and rpi3-kernel will serve their respective raspberry Pi variant
* rpi-kernel will be an empty meta package for arch != armv6l and pull
    * rpi2-kernel for armv7
    * rpi3-kernel for aarch64
    to support the transition of existing systems to the new packaging
    scheme
---
 srcpkgs/rpi-kernel/template  |  51 ++++---
 srcpkgs/rpi2-kernel-headers  |   1 +
 srcpkgs/rpi2-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 srcpkgs/rpi3-kernel-headers  |   1 +
 srcpkgs/rpi3-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 5 files changed, 537 insertions(+), 16 deletions(-)
 create mode 120000 srcpkgs/rpi2-kernel-headers
 create mode 100644 srcpkgs/rpi2-kernel/template
 create mode 120000 srcpkgs/rpi3-kernel-headers
 create mode 100644 srcpkgs/rpi3-kernel/template

diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index f9f170aedc0..6316f4188b3 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -10,12 +10,15 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi-kernel
 version=5.4.83
-revision=1
+revision=2
+archs="armv6l*"
 wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
 license="GPL-2.0-only"
-short_desc="The Linux kernel for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+short_desc="The Linux kernel for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
 distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
 checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
 python_version=2
@@ -27,10 +30,6 @@ nostrip=yes
 noverifyrdeps=yes
 noshlibprovides=yes
 
-# RPi, RPi2, RPi3
-archs="armv6l* armv7l* aarch64*"
-hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
-makedepends="ncurses-devel"
 triggers="kernel-hooks"
 # These files could be modified when an external module is built.
 mutable_files="
@@ -62,15 +61,6 @@ do_configure() {
 
 	# Use upstream's default configuration, no need to maintain ours.
 	case "$XBPS_TARGET_MACHINE" in
-		# RPi3
-		aarch64*)
-			target=bcmrpi3_defconfig
-			;;
-		# RPi2 / RPi3
-		armv7l*)
-			target=bcm2709_defconfig
-			;;
-		# RPi1
 		armv6l*)
 			target=bcmrpi_defconfig
 			;;
@@ -252,9 +242,38 @@ rpi-kernel-headers_package() {
 	nostrip=yes
 	noverifyrdeps=yes
 	noshlibprovides=yes
-	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	short_desc="The Linux kernel headers for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
 	pkg_install() {
 		vmove usr/src
 		vmove usr/lib/modules/${_kernver}/build
 	}
 }
+
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi{$n}-kernel package
+archs+=" armv7l* aarch64*"
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;                                              
+	*)
+		build_style=meta
+		short_desc="The Linux kernel for Raspberry Pi ( transitional dummy package)"
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends=rpi2-kernel ;;                                              
+			aarch64*) depends=rpi3-kernel ;;
+		esac
+		pre_configure() { : ; }
+		do_configure() { : ; }
+		do_build() { : ; }
+		do_install() { : ; }
+
+		rpi-kernel-headers_package() {
+			build_style=meta
+			short_desc="The Linux kernel headers for Raspberry Pi ( transitional dummy package)"
+			case "$XBPS_TARGET_MACHINE" in
+				armv7*) depends=rpi2-kernel-headers ;;                                              
+				aarch64*) depends=rpi3-kernel-headers ;;
+			esac
+		}
+		;;
+esac
diff --git a/srcpkgs/rpi2-kernel-headers b/srcpkgs/rpi2-kernel-headers
new file mode 120000
index 00000000000..fbe6d91aeb7
--- /dev/null
+++ b/srcpkgs/rpi2-kernel-headers
@@ -0,0 +1 @@
+rpi2-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
new file mode 100644
index 00000000000..81ecc432cd6
--- /dev/null
+++ b/srcpkgs/rpi2-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi2-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi2-kernel
+version=5.4.83
+revision=2
+archs="armv7l*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 2 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		armv7l*)
+			target=bcm2709_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+	
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi2-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}
diff --git a/srcpkgs/rpi3-kernel-headers b/srcpkgs/rpi3-kernel-headers
new file mode 120000
index 00000000000..29e9f333d66
--- /dev/null
+++ b/srcpkgs/rpi3-kernel-headers
@@ -0,0 +1 @@
+rpi3-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
new file mode 100644
index 00000000000..892d6ef7923
--- /dev/null
+++ b/srcpkgs/rpi3-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi3-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi3-kernel
+version=5.4.83
+revision=2
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 3 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcmrpi3_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+	
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi3-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From 643644789a50ece76f00e59636591d67a250753a Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:09 +0100
Subject: [PATCH 2/4] rpi-base: split into rpi, rpi2, rpi3

Until now, raspberry Pi variants were solely distiguished by the target
architecture; this is insufficient for handling the upcoming addition of
rpi4-base.
Technically it'd be fine for rpi-base to not depend on rpi-kernel as it
only ships a udev file but that would be bad for existing systems.

For now it's sufficient to have one package provide all subpackages, to
ease maintainance.

rpi3-base actually existed back in 2017 (depended on mainline linux
instead of rpi-kernel) and became obsolete in 2018 ; would have known
back then we may have to deal with rpi>3 some day...
---
 srcpkgs/rpi-base/template | 53 +++++++++++++++++++++++++++++++++++++--
 srcpkgs/rpi2-base         |  1 +
 srcpkgs/rpi3-base         |  1 +
 3 files changed, 53 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi2-base
 create mode 120000 srcpkgs/rpi3-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index 8fcf3581efd..d5ae22b2c78 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,9 +1,10 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
-version=2.6
+version=3.0
 revision=1
 archs="armv6l* armv7l* aarch64*"
-depends="virtual?ntp-daemon rpi-firmware rpi-kernel"
+_base_depends="virtual?ntp-daemon rpi-firmware"
+depends="${_base_depends} rpi-kernel"
 short_desc="Void Linux Raspberry Pi base files"
 maintainer="Orphaned <orphan@voidlinux.org>"
 license="Public Domain"
@@ -12,3 +13,51 @@ homepage="https://www.voidlinux.org"
 do_install() {
 	vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 }
+
+case "$XBPS_TARGET_MACHINE" in
+	armv6*)
+		subpackages=" "
+		;;
+	armv7*)
+		subpackages="rpi2-base"
+		;;
+	aarch64*)
+		subpackages="rpi3-base"
+		;;
+esac
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi${n}-base package
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc+=" (transitional dummy package)"
+	 	do_install() { : ; }
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*)
+				depends="rpi2-base"
+				;;
+			aarch64*)
+				depends="rpi3-base"
+				;;
+		esac
+		;;
+esac
+
+rpi2-base_package() {
+	depends="${_base_depends} rpi2-kernel"
+	short_desc="Void Linux Raspberry Pi 2 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
+
+
+rpi3-base_package() {
+	depends="${_base_depends} rpi3-kernel"
+	short_desc="Void Linux Raspberry Pi 3 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi2-base b/srcpkgs/rpi2-base
new file mode 120000
index 00000000000..c004915dfa8
--- /dev/null
+++ b/srcpkgs/rpi2-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi3-base b/srcpkgs/rpi3-base
new file mode 120000
index 00000000000..c004915dfa8
--- /dev/null
+++ b/srcpkgs/rpi3-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

From 4821e78c878635625ad742d0f3df7e62ac80345c Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:52:49 +0100
Subject: [PATCH 3/4] New package: rpi4-kernel-5.4.83

---
 srcpkgs/rpi4-kernel-headers  |   1 +
 srcpkgs/rpi4-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 2 files changed, 251 insertions(+)
 create mode 120000 srcpkgs/rpi4-kernel-headers
 create mode 100644 srcpkgs/rpi4-kernel/template

diff --git a/srcpkgs/rpi4-kernel-headers b/srcpkgs/rpi4-kernel-headers
new file mode 120000
index 00000000000..9c2fad14350
--- /dev/null
+++ b/srcpkgs/rpi4-kernel-headers
@@ -0,0 +1 @@
+rpi4-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi4-kernel/template b/srcpkgs/rpi4-kernel/template
new file mode 100644
index 00000000000..d0a70bb92b2
--- /dev/null
+++ b/srcpkgs/rpi4-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi4-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi4-kernel
+version=5.4.83
+revision=2
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 4 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcm2711_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+	
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi4-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From 61aa6a9f3c3de8655bfdb4cf26d8f45a10204982 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:56:40 +0100
Subject: [PATCH 4/4] rpi-base: add rpi4

---
 srcpkgs/rpi-base/template | 13 +++++++++++--
 srcpkgs/rpi4-base         |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi4-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index d5ae22b2c78..4711609bef8 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,7 +1,7 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
 version=3.0
-revision=1
+revision=2
 archs="armv6l* armv7l* aarch64*"
 _base_depends="virtual?ntp-daemon rpi-firmware"
 depends="${_base_depends} rpi-kernel"
@@ -22,7 +22,7 @@ case "$XBPS_TARGET_MACHINE" in
 		subpackages="rpi2-base"
 		;;
 	aarch64*)
-		subpackages="rpi3-base"
+		subpackages="rpi3-base rpi4-base"
 		;;
 esac
 
@@ -61,3 +61,12 @@ rpi3-base_package() {
 		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 	}
 }
+
+rpi4-base_package() {
+	depends="${_base_depends} rpi4-kernel"
+	short_desc="Void Linux Raspberry Pi 4 base files"
+	conflicts="rpi3-base"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi4-base b/srcpkgs/rpi4-base
new file mode 120000
index 00000000000..c004915dfa8
--- /dev/null
+++ b/srcpkgs/rpi4-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
@ 2021-02-28 22:10 ` the-maldridge
  2021-03-01  1:29 ` ahesford
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: the-maldridge @ 2021-02-28 22:10 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 397 bytes --]

New comment by the-maldridge on void-packages repository

https://github.com/void-linux/void-packages/pull/29139#issuecomment-787532365

Comment:
@Piraty nothing was demanded of you.  You were told the same thing as every other maintainer that if you want to make potentially hazardous changes down at the bottom layers of the stack, you are responsible for fixing breakage caused by your change.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
  2021-02-28 22:10 ` the-maldridge
@ 2021-03-01  1:29 ` ahesford
  2021-03-01 11:03 ` Piraty
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: ahesford @ 2021-03-01  1:29 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 594 bytes --]

New comment by ahesford on void-packages repository

https://github.com/void-linux/void-packages/pull/29139#issuecomment-787574865

Comment:
I think #26000 is a much cleaner approach. It isn't clear to me how moving `rpi-base` and `rpi-kernel` to metas that pull in their respective `rpi{1,2,3}-{base,kernel}` packages breaks image generation, but I haven't looked at it too closely. If there is a problem that I'm overlooking and this approach solves it, so be it.

If this approach is necessary, can a lot of the duplication in the `rpi*-kernel` packages be offloaded into a build style?


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
  2021-02-28 22:10 ` the-maldridge
  2021-03-01  1:29 ` ahesford
@ 2021-03-01 11:03 ` Piraty
  2021-04-25 18:53 ` [PR PATCH] [Updated] " Piraty
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-03-01 11:03 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1185 bytes --]

New comment by Piraty on void-packages repository

https://github.com/void-linux/void-packages/pull/29139#issuecomment-787861597

Comment:
> I think #26000 is a much cleaner approach. It isn't clear to me how moving `rpi-base` and `rpi-kernel` to metas that pull in their respective `rpi{1,2,3}-{base,kernel}` packages breaks image generation, but I haven't looked at it too closely. If there is a problem that I'm overlooking and this approach solves it, so be it.

I share your view. I'm not aware of the actual problem @the-maldridge [anticipated](https://github.com/void-linux/void-mklive/pull/153#discussion_r525026848) 
 
> If this approach is necessary, can a lot of the duplication in the `rpi*-kernel` packages be offloaded into a build style?

that's for `build_style=linux` which i worked on already (but finishing it will take its time), though this will hardly be useful for #26000 (builds all kernel variants in a big loop).
In advance of a (future) kernel build style, splitting all kernel off to their own template appears more sane (I kepts many unnecesary things in the templates on purpose so `diff srcpkgs/rpi{2,3}-kernel/template` isn't clobbered too much)

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR PATCH] [Updated] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (2 preceding siblings ...)
  2021-03-01 11:03 ` Piraty
@ 2021-04-25 18:53 ` Piraty
  2021-04-25 19:27 ` Piraty
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-04-25 18:53 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

There is an updated pull request by Piraty against master on the void-packages repository

https://github.com/Piraty/void-packages rpi-kernel-split
https://github.com/void-linux/void-packages/pull/29139

[NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
This is my second approach to the rpi4 problem (first try: https://github.com/void-linux/void-packages/pull/26000)

The problem is: how to not break existing systems while having a consistent naming scheme for rpi-kernel / rpi-base.

As ~demanded~ suggested by @the-maldridge , `rpi-kernel` continues to provide the kernel for rpi0/rpi1 and becomes a meta package that pulls `rpi{2,3}-kernel` (based on target arch) to serve legacy systems.

To support legacy systems, rpi-base is split into rpiN-base which all ship the same udev rule and depend on the respective kernel. This (still) allows to have a single entry-point to raspberry related packages.

I performed (offline) testing of the package transition process, seems fine. Script [here](https://gist.github.com/Piraty/2b0bd709c58ca2e8dd2240cc5b1141c9)

@pbui @Duncaen @ahesford 

A patch file from https://github.com/void-linux/void-packages/pull/29139.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-rpi-kernel-split-29139.patch --]
[-- Type: text/x-diff, Size: 35316 bytes --]

From da206c55b914b560c1a2b46c18355186e3362be4 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:00 +0100
Subject: [PATCH 1/4] rpi-kernel: split into rpi, rpi2, rpi3

Until now, raspberry Pi variants were solely distiguished by the target
architecture; this is insufficient for handling the upcoming addition of
rpi4-kernel, so split them.

* rpi-kernel will continue to serve raspberry Pi variants rpi0 and rpi1 for armv6l
* rpi2-kernel and rpi3-kernel will serve their respective raspberry Pi variant
* rpi-kernel will be an empty meta package for arch != armv6l and pull
    * rpi2-kernel for armv7
    * rpi3-kernel for aarch64
    to support the transition of existing systems to the new packaging
    scheme
---
 srcpkgs/rpi-kernel/template  |  52 +++++---
 srcpkgs/rpi2-kernel-headers  |   1 +
 srcpkgs/rpi2-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 srcpkgs/rpi3-kernel-headers  |   1 +
 srcpkgs/rpi3-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 5 files changed, 538 insertions(+), 16 deletions(-)
 create mode 120000 srcpkgs/rpi2-kernel-headers
 create mode 100644 srcpkgs/rpi2-kernel/template
 create mode 120000 srcpkgs/rpi3-kernel-headers
 create mode 100644 srcpkgs/rpi3-kernel/template

diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index 1fe4e2477e1f..5c9b711465a4 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -10,12 +10,15 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi-kernel
 version=5.4.83
-revision=1
+revision=2
+archs="armv6l*"
 wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
 license="GPL-2.0-only"
-short_desc="The Linux kernel for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+short_desc="The Linux kernel for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
 distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
 checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
 python_version=2
@@ -27,10 +30,6 @@ nostrip=yes
 noverifyrdeps=yes
 noshlibprovides=yes
 
-# RPi, RPi2, RPi3
-archs="armv6l* armv7l* aarch64*"
-hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
-makedepends="ncurses-devel"
 triggers="kernel-hooks"
 # These files could be modified when an external module is built.
 mutable_files="
@@ -62,15 +61,6 @@ do_configure() {
 
 	# Use upstream's default configuration, no need to maintain ours.
 	case "$XBPS_TARGET_MACHINE" in
-		# RPi3
-		aarch64*)
-			target=bcmrpi3_defconfig
-			;;
-		# RPi2 / RPi3
-		armv7l*)
-			target=bcm2709_defconfig
-			;;
-		# RPi1
 		armv6l*)
 			target=bcmrpi_defconfig
 			;;
@@ -252,9 +242,39 @@ rpi-kernel-headers_package() {
 	nostrip=yes
 	noverifyrdeps=yes
 	noshlibprovides=yes
-	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	short_desc="The Linux kernel headers for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
 	pkg_install() {
 		vmove usr/src
 		vmove usr/lib/modules/${_kernver}/build
 	}
 }
+
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi{$n}-kernel package
+archs+=" armv7l* aarch64*"
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;                                              
+	*)
+		pre_configure() { : ; }
+		do_configure() { : ; }
+		do_build() { : ; }
+		do_install() { : ; }
+		build_style=meta
+		short_desc="The Linux kernel for Raspberry Pi ( transitional dummy package)"
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends=rpi2-kernel ;;                                              
+			aarch64*) depends=rpi3-kernel ;;
+		esac
+
+		rpi-kernel-headers_package() {
+			build_style=meta
+			short_desc="The Linux kernel headers for Raspberry Pi ( transitional dummy package)"
+			case "$XBPS_TARGET_MACHINE" in
+				armv7*) depends=rpi2-kernel-headers ;;                                              
+				aarch64*) depends=rpi3-kernel-headers ;;
+			esac
+		}
+		;;
+esac
diff --git a/srcpkgs/rpi2-kernel-headers b/srcpkgs/rpi2-kernel-headers
new file mode 120000
index 000000000000..fbe6d91aeb7f
--- /dev/null
+++ b/srcpkgs/rpi2-kernel-headers
@@ -0,0 +1 @@
+rpi2-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
new file mode 100644
index 000000000000..66ee0b1c1162
--- /dev/null
+++ b/srcpkgs/rpi2-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi2-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi2-kernel
+version=5.4.83
+revision=2
+archs="armv7l*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 2 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		armv7l*)
+			target=bcm2709_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+	
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi2-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}
diff --git a/srcpkgs/rpi3-kernel-headers b/srcpkgs/rpi3-kernel-headers
new file mode 120000
index 000000000000..29e9f333d668
--- /dev/null
+++ b/srcpkgs/rpi3-kernel-headers
@@ -0,0 +1 @@
+rpi3-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
new file mode 100644
index 000000000000..ee9bee09d772
--- /dev/null
+++ b/srcpkgs/rpi3-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi3-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi3-kernel
+version=5.4.83
+revision=2
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 3 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcmrpi3_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+	
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi3-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From fe1cd9c5d4c6e910a31072106d475ee6567ddfb2 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:09 +0100
Subject: [PATCH 2/4] rpi-base: split into rpi, rpi2, rpi3

Until now, raspberry Pi variants were solely distiguished by the target
architecture; this is insufficient for handling the upcoming addition of
rpi4-base.
Technically it would be fine for rpi-base to not depend on rpi-kernel as
it only ships a udev file but that would be bad for existing systems.

For now it's sufficient to have one package provide all subpackages, to
ease maintainance. But the templates can easiliy be split should the
need arise some day.

rpi3-base actually existed back in 2017 (it depended on mainline instead
of rpi-kernel) and became obsolete in 2018; who would have known back
then we may have to deal with rpi>3 some day...
---
 srcpkgs/rpi-base/template    | 53 ++++++++++++++++++++++++++++++++++--
 srcpkgs/rpi-kernel/template  |  2 +-
 srcpkgs/rpi2-base            |  1 +
 srcpkgs/rpi2-kernel/template |  2 +-
 srcpkgs/rpi3-base            |  1 +
 srcpkgs/rpi3-kernel/template |  2 +-
 6 files changed, 56 insertions(+), 5 deletions(-)
 create mode 120000 srcpkgs/rpi2-base
 create mode 120000 srcpkgs/rpi3-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index 8fcf3581efd9..d5ae22b2c784 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,9 +1,10 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
-version=2.6
+version=3.0
 revision=1
 archs="armv6l* armv7l* aarch64*"
-depends="virtual?ntp-daemon rpi-firmware rpi-kernel"
+_base_depends="virtual?ntp-daemon rpi-firmware"
+depends="${_base_depends} rpi-kernel"
 short_desc="Void Linux Raspberry Pi base files"
 maintainer="Orphaned <orphan@voidlinux.org>"
 license="Public Domain"
@@ -12,3 +13,51 @@ homepage="https://www.voidlinux.org"
 do_install() {
 	vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 }
+
+case "$XBPS_TARGET_MACHINE" in
+	armv6*)
+		subpackages=" "
+		;;
+	armv7*)
+		subpackages="rpi2-base"
+		;;
+	aarch64*)
+		subpackages="rpi3-base"
+		;;
+esac
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi${n}-base package
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc+=" (transitional dummy package)"
+	 	do_install() { : ; }
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*)
+				depends="rpi2-base"
+				;;
+			aarch64*)
+				depends="rpi3-base"
+				;;
+		esac
+		;;
+esac
+
+rpi2-base_package() {
+	depends="${_base_depends} rpi2-kernel"
+	short_desc="Void Linux Raspberry Pi 2 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
+
+
+rpi3-base_package() {
+	depends="${_base_depends} rpi3-kernel"
+	short_desc="Void Linux Raspberry Pi 3 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index 5c9b711465a4..8a3658ada5e0 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -242,7 +242,7 @@ rpi-kernel-headers_package() {
 	nostrip=yes
 	noverifyrdeps=yes
 	noshlibprovides=yes
-	short_desc="The Linux kernel headers for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
+	short_desc="${short_desc/kernel/kernel headers}"
 	pkg_install() {
 		vmove usr/src
 		vmove usr/lib/modules/${_kernver}/build
diff --git a/srcpkgs/rpi2-base b/srcpkgs/rpi2-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi2-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
index 66ee0b1c1162..6cf26b95e20c 100644
--- a/srcpkgs/rpi2-kernel/template
+++ b/srcpkgs/rpi2-kernel/template
@@ -13,7 +13,7 @@ version=5.4.83
 revision=2
 archs="armv7l*"
 wrksrc="linux-${_githash}"
-hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
 makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
diff --git a/srcpkgs/rpi3-base b/srcpkgs/rpi3-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi3-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
index ee9bee09d772..9e6edb16aeca 100644
--- a/srcpkgs/rpi3-kernel/template
+++ b/srcpkgs/rpi3-kernel/template
@@ -13,7 +13,7 @@ version=5.4.83
 revision=2
 archs="aarch64*"
 wrksrc="linux-${_githash}"
-hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
 makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"

From 6d3b7a8d378399e29a479e4532b8647090ed617a Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:52:49 +0100
Subject: [PATCH 3/4] New package: rpi4-kernel-5.4.83

---
 srcpkgs/rpi4-kernel-headers  |   1 +
 srcpkgs/rpi4-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 2 files changed, 251 insertions(+)
 create mode 120000 srcpkgs/rpi4-kernel-headers
 create mode 100644 srcpkgs/rpi4-kernel/template

diff --git a/srcpkgs/rpi4-kernel-headers b/srcpkgs/rpi4-kernel-headers
new file mode 120000
index 000000000000..9c2fad143506
--- /dev/null
+++ b/srcpkgs/rpi4-kernel-headers
@@ -0,0 +1 @@
+rpi4-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi4-kernel/template b/srcpkgs/rpi4-kernel/template
new file mode 100644
index 000000000000..88576116f3e9
--- /dev/null
+++ b/srcpkgs/rpi4-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi4-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi4-kernel
+version=5.4.83
+revision=2
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 4 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcm2711_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+	
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi4-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From c163434eb93092074946725b64df1178442ce61f Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:56:40 +0100
Subject: [PATCH 4/4] rpi-base: add rpi4

---
 srcpkgs/rpi-base/template | 13 +++++++++++--
 srcpkgs/rpi4-base         |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi4-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index d5ae22b2c784..4711609bef89 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,7 +1,7 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
 version=3.0
-revision=1
+revision=2
 archs="armv6l* armv7l* aarch64*"
 _base_depends="virtual?ntp-daemon rpi-firmware"
 depends="${_base_depends} rpi-kernel"
@@ -22,7 +22,7 @@ case "$XBPS_TARGET_MACHINE" in
 		subpackages="rpi2-base"
 		;;
 	aarch64*)
-		subpackages="rpi3-base"
+		subpackages="rpi3-base rpi4-base"
 		;;
 esac
 
@@ -61,3 +61,12 @@ rpi3-base_package() {
 		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 	}
 }
+
+rpi4-base_package() {
+	depends="${_base_depends} rpi4-kernel"
+	short_desc="Void Linux Raspberry Pi 4 base files"
+	conflicts="rpi3-base"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi4-base b/srcpkgs/rpi4-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi4-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR PATCH] [Updated] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (3 preceding siblings ...)
  2021-04-25 18:53 ` [PR PATCH] [Updated] " Piraty
@ 2021-04-25 19:27 ` Piraty
  2021-04-27 19:34 ` Piraty
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-04-25 19:27 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

There is an updated pull request by Piraty against master on the void-packages repository

https://github.com/Piraty/void-packages rpi-kernel-split
https://github.com/void-linux/void-packages/pull/29139

[NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
This is my second approach to the rpi4 problem (first try: https://github.com/void-linux/void-packages/pull/26000)

The problem is: how to not break existing systems while having a consistent naming scheme for rpi-kernel / rpi-base.

As ~demanded~ suggested by @the-maldridge , `rpi-kernel` continues to provide the kernel for rpi0/rpi1 and becomes a meta package that pulls `rpi{2,3}-kernel` (based on target arch) to serve legacy systems.

To support legacy systems, rpi-base is split into rpiN-base which all ship the same udev rule and depend on the respective kernel. This (still) allows to have a single entry-point to raspberry related packages.

I performed (offline) testing of the package transition process, seems fine. Script [here](https://gist.github.com/Piraty/2b0bd709c58ca2e8dd2240cc5b1141c9)

@pbui @Duncaen @ahesford 

A patch file from https://github.com/void-linux/void-packages/pull/29139.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-rpi-kernel-split-29139.patch --]
[-- Type: text/x-diff, Size: 35456 bytes --]

From 9a7ebb630eb4ad9b7cefd825f7bad04a37e8e4e1 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:00 +0100
Subject: [PATCH 1/4] rpi-kernel: split into rpi, rpi2, rpi3

Until now, raspberry Pi variants were solely distiguished by the target
architecture; this is insufficient for handling the upcoming addition of
rpi4-kernel, so split them.

* rpi-kernel will continue to serve raspberry Pi variants rpi0 and rpi1 for armv6l
* rpi2-kernel and rpi3-kernel will serve their respective raspberry Pi variant
* rpi-kernel will be an empty meta package for arch != armv6l and pull
    * rpi2-kernel for armv7
    * rpi3-kernel for aarch64
    to support the transition of existing systems to the new packaging
    scheme
---
 srcpkgs/rpi-kernel/template  |  54 +++++---
 srcpkgs/rpi2-kernel-headers  |   1 +
 srcpkgs/rpi2-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 srcpkgs/rpi3-kernel-headers  |   1 +
 srcpkgs/rpi3-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 5 files changed, 539 insertions(+), 17 deletions(-)
 create mode 120000 srcpkgs/rpi2-kernel-headers
 create mode 100644 srcpkgs/rpi2-kernel/template
 create mode 120000 srcpkgs/rpi3-kernel-headers
 create mode 100644 srcpkgs/rpi3-kernel/template

diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index 1fe4e2477e1f..981b04d3518f 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -10,12 +10,15 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi-kernel
 version=5.4.83
-revision=1
+revision=2
+archs="armv6l*"
 wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
 license="GPL-2.0-only"
-short_desc="The Linux kernel for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+short_desc="The Linux kernel for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
 distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
 checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
 python_version=2
@@ -27,10 +30,6 @@ nostrip=yes
 noverifyrdeps=yes
 noshlibprovides=yes
 
-# RPi, RPi2, RPi3
-archs="armv6l* armv7l* aarch64*"
-hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
-makedepends="ncurses-devel"
 triggers="kernel-hooks"
 # These files could be modified when an external module is built.
 mutable_files="
@@ -62,15 +61,6 @@ do_configure() {
 
 	# Use upstream's default configuration, no need to maintain ours.
 	case "$XBPS_TARGET_MACHINE" in
-		# RPi3
-		aarch64*)
-			target=bcmrpi3_defconfig
-			;;
-		# RPi2 / RPi3
-		armv7l*)
-			target=bcm2709_defconfig
-			;;
-		# RPi1
 		armv6l*)
 			target=bcmrpi_defconfig
 			;;
@@ -81,7 +71,7 @@ do_configure() {
 	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
 	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
 	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
-	
+
 	# IR Remote Support
 	echo "CONFIG_RC_CORE=y" >> "$defconfig"
 	echo "CONFIG_LIRC=y" >> "$defconfig"
@@ -252,9 +242,39 @@ rpi-kernel-headers_package() {
 	nostrip=yes
 	noverifyrdeps=yes
 	noshlibprovides=yes
-	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	short_desc="${short_desc/kernel/kernel headers}"
 	pkg_install() {
 		vmove usr/src
 		vmove usr/lib/modules/${_kernver}/build
 	}
 }
+
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi{$n}-kernel package
+archs+=" armv7l* aarch64*"
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		pre_configure() { : ; }
+		do_configure() { : ; }
+		do_build() { : ; }
+		do_install() { : ; }
+		build_style=meta
+		short_desc="The Linux kernel for Raspberry Pi ( transitional dummy package)"
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends=rpi2-kernel ;;
+			aarch64*) depends=rpi3-kernel ;;
+		esac
+
+		rpi-kernel-headers_package() {
+			build_style=meta
+			short_desc="The Linux kernel headers for Raspberry Pi ( transitional dummy package)"
+			case "$XBPS_TARGET_MACHINE" in
+				armv7*) depends=rpi2-kernel-headers ;;
+				aarch64*) depends=rpi3-kernel-headers ;;
+			esac
+		}
+		;;
+esac
diff --git a/srcpkgs/rpi2-kernel-headers b/srcpkgs/rpi2-kernel-headers
new file mode 120000
index 000000000000..fbe6d91aeb7f
--- /dev/null
+++ b/srcpkgs/rpi2-kernel-headers
@@ -0,0 +1 @@
+rpi2-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
new file mode 100644
index 000000000000..2a780d552484
--- /dev/null
+++ b/srcpkgs/rpi2-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi2-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi2-kernel
+version=5.4.83
+revision=2
+archs="armv7l*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 2 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		armv7l*)
+			target=bcm2709_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi2-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}
diff --git a/srcpkgs/rpi3-kernel-headers b/srcpkgs/rpi3-kernel-headers
new file mode 120000
index 000000000000..29e9f333d668
--- /dev/null
+++ b/srcpkgs/rpi3-kernel-headers
@@ -0,0 +1 @@
+rpi3-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
new file mode 100644
index 000000000000..650a365905aa
--- /dev/null
+++ b/srcpkgs/rpi3-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi3-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi3-kernel
+version=5.4.83
+revision=2
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 3 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcmrpi3_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi3-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From e459f43b95794db7207b4e0dea1a8f4e140034cd Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:09 +0100
Subject: [PATCH 2/4] rpi-base: split into rpi, rpi2, rpi3

Until now, raspberry Pi variants were solely distiguished by the target
architecture; this is insufficient for handling the upcoming addition of
rpi4-base.
Technically it would be fine for rpi-base to not depend on rpi-kernel
(and thus never have to account for new rpi variants anymore) but that
would be bad for existing installs.

For now it's sufficient to have one package provide all subpackages, to
ease maintainance. But the templates can easiliy be split should the
need arise some day.

rpi3-base actually existed back in 2017 (it depended on mainline instead
of rpi-kernel) and became obsolete in 2018; who would have known back
then we may have to deal with rpi>3 some day...
---
 srcpkgs/rpi-base/template    | 53 ++++++++++++++++++++++++++++++++++--
 srcpkgs/rpi-kernel/template  |  2 +-
 srcpkgs/rpi2-base            |  1 +
 srcpkgs/rpi2-kernel/template |  4 +--
 srcpkgs/rpi3-base            |  1 +
 srcpkgs/rpi3-kernel/template |  4 +--
 6 files changed, 58 insertions(+), 7 deletions(-)
 create mode 120000 srcpkgs/rpi2-base
 create mode 120000 srcpkgs/rpi3-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index 8fcf3581efd9..d5ae22b2c784 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,9 +1,10 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
-version=2.6
+version=3.0
 revision=1
 archs="armv6l* armv7l* aarch64*"
-depends="virtual?ntp-daemon rpi-firmware rpi-kernel"
+_base_depends="virtual?ntp-daemon rpi-firmware"
+depends="${_base_depends} rpi-kernel"
 short_desc="Void Linux Raspberry Pi base files"
 maintainer="Orphaned <orphan@voidlinux.org>"
 license="Public Domain"
@@ -12,3 +13,51 @@ homepage="https://www.voidlinux.org"
 do_install() {
 	vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 }
+
+case "$XBPS_TARGET_MACHINE" in
+	armv6*)
+		subpackages=" "
+		;;
+	armv7*)
+		subpackages="rpi2-base"
+		;;
+	aarch64*)
+		subpackages="rpi3-base"
+		;;
+esac
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi${n}-base package
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc+=" (transitional dummy package)"
+	 	do_install() { : ; }
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*)
+				depends="rpi2-base"
+				;;
+			aarch64*)
+				depends="rpi3-base"
+				;;
+		esac
+		;;
+esac
+
+rpi2-base_package() {
+	depends="${_base_depends} rpi2-kernel"
+	short_desc="Void Linux Raspberry Pi 2 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
+
+
+rpi3-base_package() {
+	depends="${_base_depends} rpi3-kernel"
+	short_desc="Void Linux Raspberry Pi 3 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index 981b04d3518f..38023f1900d9 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -10,7 +10,7 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi-kernel
 version=5.4.83
-revision=2
+revision=3
 archs="armv6l*"
 wrksrc="linux-${_githash}"
 hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
diff --git a/srcpkgs/rpi2-base b/srcpkgs/rpi2-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi2-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
index 2a780d552484..7b94e79cf9a0 100644
--- a/srcpkgs/rpi2-kernel/template
+++ b/srcpkgs/rpi2-kernel/template
@@ -10,10 +10,10 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi2-kernel
 version=5.4.83
-revision=2
+revision=1
 archs="armv7l*"
 wrksrc="linux-${_githash}"
-hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
 makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
diff --git a/srcpkgs/rpi3-base b/srcpkgs/rpi3-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi3-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
index 650a365905aa..4d69782c3fd9 100644
--- a/srcpkgs/rpi3-kernel/template
+++ b/srcpkgs/rpi3-kernel/template
@@ -10,10 +10,10 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi3-kernel
 version=5.4.83
-revision=2
+revision=1
 archs="aarch64*"
 wrksrc="linux-${_githash}"
-hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
 makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"

From b9c0007dbdce888480681f952d6368609c41ccd8 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:52:49 +0100
Subject: [PATCH 3/4] New package: rpi4-kernel-5.4.83

---
 srcpkgs/rpi4-kernel-headers  |   1 +
 srcpkgs/rpi4-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 2 files changed, 251 insertions(+)
 create mode 120000 srcpkgs/rpi4-kernel-headers
 create mode 100644 srcpkgs/rpi4-kernel/template

diff --git a/srcpkgs/rpi4-kernel-headers b/srcpkgs/rpi4-kernel-headers
new file mode 120000
index 000000000000..9c2fad143506
--- /dev/null
+++ b/srcpkgs/rpi4-kernel-headers
@@ -0,0 +1 @@
+rpi4-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi4-kernel/template b/srcpkgs/rpi4-kernel/template
new file mode 100644
index 000000000000..896f5f747dd1
--- /dev/null
+++ b/srcpkgs/rpi4-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi4-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi4-kernel
+version=5.4.83
+revision=1
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 4 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcm2711_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi4-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From e3694b168007efd1286bef7041502fc58a48a2b6 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:56:40 +0100
Subject: [PATCH 4/4] rpi-base: add rpi4

---
 srcpkgs/rpi-base/template | 13 +++++++++++--
 srcpkgs/rpi4-base         |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi4-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index d5ae22b2c784..4711609bef89 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,7 +1,7 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
 version=3.0
-revision=1
+revision=2
 archs="armv6l* armv7l* aarch64*"
 _base_depends="virtual?ntp-daemon rpi-firmware"
 depends="${_base_depends} rpi-kernel"
@@ -22,7 +22,7 @@ case "$XBPS_TARGET_MACHINE" in
 		subpackages="rpi2-base"
 		;;
 	aarch64*)
-		subpackages="rpi3-base"
+		subpackages="rpi3-base rpi4-base"
 		;;
 esac
 
@@ -61,3 +61,12 @@ rpi3-base_package() {
 		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 	}
 }
+
+rpi4-base_package() {
+	depends="${_base_depends} rpi4-kernel"
+	short_desc="Void Linux Raspberry Pi 4 base files"
+	conflicts="rpi3-base"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi4-base b/srcpkgs/rpi4-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi4-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR PATCH] [Updated] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (4 preceding siblings ...)
  2021-04-25 19:27 ` Piraty
@ 2021-04-27 19:34 ` Piraty
  2021-04-27 20:04 ` Piraty
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-04-27 19:34 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

There is an updated pull request by Piraty against master on the void-packages repository

https://github.com/Piraty/void-packages rpi-kernel-split
https://github.com/void-linux/void-packages/pull/29139

[NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
This is my second approach to the rpi4 problem (first try: https://github.com/void-linux/void-packages/pull/26000)

The problem is: how to not break existing systems while having a consistent naming scheme for rpi-kernel / rpi-base.

As ~demanded~ suggested by @the-maldridge , `rpi-kernel` continues to provide the kernel for rpi0/rpi1 and becomes a meta package that pulls `rpi{2,3}-kernel` (based on target arch) to serve legacy systems.

To support legacy systems, rpi-base is split into rpiN-base which all ship the same udev rule and depend on the respective kernel. This (still) allows to have a single entry-point to raspberry related packages.

I performed (offline) testing of the package transition process, seems fine. Script [here](https://gist.github.com/Piraty/2b0bd709c58ca2e8dd2240cc5b1141c9)

@pbui @Duncaen @ahesford 

A patch file from https://github.com/void-linux/void-packages/pull/29139.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-rpi-kernel-split-29139.patch --]
[-- Type: text/x-diff, Size: 35456 bytes --]

From 4e9cbfba09de27b8ae05586793dd9761dae755d0 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:00 +0100
Subject: [PATCH 1/4] rpi-kernel: split into rpi, rpi2, rpi3

Until now, raspberry Pi variants were solely distiguished by the target
architecture; this is insufficient for handling the upcoming addition of
rpi4-kernel, so split them.

* rpi-kernel will continue to serve raspberry Pi variants rpi0 and rpi1 for armv6l
* rpi2-kernel and rpi3-kernel will serve their respective raspberry Pi variant
* rpi-kernel will be an empty meta package for arch != armv6l and pull
    * rpi2-kernel for armv7
    * rpi3-kernel for aarch64
    to support the transition of existing systems to the new packaging
    scheme
---
 srcpkgs/rpi-kernel/template  |  54 +++++---
 srcpkgs/rpi2-kernel-headers  |   1 +
 srcpkgs/rpi2-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 srcpkgs/rpi3-kernel-headers  |   1 +
 srcpkgs/rpi3-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 5 files changed, 539 insertions(+), 17 deletions(-)
 create mode 120000 srcpkgs/rpi2-kernel-headers
 create mode 100644 srcpkgs/rpi2-kernel/template
 create mode 120000 srcpkgs/rpi3-kernel-headers
 create mode 100644 srcpkgs/rpi3-kernel/template

diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index 1fe4e2477e1f..981b04d3518f 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -10,12 +10,15 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi-kernel
 version=5.4.83
-revision=1
+revision=2
+archs="armv6l*"
 wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
 license="GPL-2.0-only"
-short_desc="The Linux kernel for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+short_desc="The Linux kernel for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
 distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
 checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
 python_version=2
@@ -27,10 +30,6 @@ nostrip=yes
 noverifyrdeps=yes
 noshlibprovides=yes
 
-# RPi, RPi2, RPi3
-archs="armv6l* armv7l* aarch64*"
-hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
-makedepends="ncurses-devel"
 triggers="kernel-hooks"
 # These files could be modified when an external module is built.
 mutable_files="
@@ -62,15 +61,6 @@ do_configure() {
 
 	# Use upstream's default configuration, no need to maintain ours.
 	case "$XBPS_TARGET_MACHINE" in
-		# RPi3
-		aarch64*)
-			target=bcmrpi3_defconfig
-			;;
-		# RPi2 / RPi3
-		armv7l*)
-			target=bcm2709_defconfig
-			;;
-		# RPi1
 		armv6l*)
 			target=bcmrpi_defconfig
 			;;
@@ -81,7 +71,7 @@ do_configure() {
 	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
 	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
 	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
-	
+
 	# IR Remote Support
 	echo "CONFIG_RC_CORE=y" >> "$defconfig"
 	echo "CONFIG_LIRC=y" >> "$defconfig"
@@ -252,9 +242,39 @@ rpi-kernel-headers_package() {
 	nostrip=yes
 	noverifyrdeps=yes
 	noshlibprovides=yes
-	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	short_desc="${short_desc/kernel/kernel headers}"
 	pkg_install() {
 		vmove usr/src
 		vmove usr/lib/modules/${_kernver}/build
 	}
 }
+
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi{$n}-kernel package
+archs+=" armv7l* aarch64*"
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		pre_configure() { : ; }
+		do_configure() { : ; }
+		do_build() { : ; }
+		do_install() { : ; }
+		build_style=meta
+		short_desc="The Linux kernel for Raspberry Pi ( transitional dummy package)"
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends=rpi2-kernel ;;
+			aarch64*) depends=rpi3-kernel ;;
+		esac
+
+		rpi-kernel-headers_package() {
+			build_style=meta
+			short_desc="The Linux kernel headers for Raspberry Pi ( transitional dummy package)"
+			case "$XBPS_TARGET_MACHINE" in
+				armv7*) depends=rpi2-kernel-headers ;;
+				aarch64*) depends=rpi3-kernel-headers ;;
+			esac
+		}
+		;;
+esac
diff --git a/srcpkgs/rpi2-kernel-headers b/srcpkgs/rpi2-kernel-headers
new file mode 120000
index 000000000000..fbe6d91aeb7f
--- /dev/null
+++ b/srcpkgs/rpi2-kernel-headers
@@ -0,0 +1 @@
+rpi2-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
new file mode 100644
index 000000000000..2a780d552484
--- /dev/null
+++ b/srcpkgs/rpi2-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi2-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi2-kernel
+version=5.4.83
+revision=2
+archs="armv7l*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 2 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		armv7l*)
+			target=bcm2709_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi2-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}
diff --git a/srcpkgs/rpi3-kernel-headers b/srcpkgs/rpi3-kernel-headers
new file mode 120000
index 000000000000..29e9f333d668
--- /dev/null
+++ b/srcpkgs/rpi3-kernel-headers
@@ -0,0 +1 @@
+rpi3-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
new file mode 100644
index 000000000000..650a365905aa
--- /dev/null
+++ b/srcpkgs/rpi3-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi3-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi3-kernel
+version=5.4.83
+revision=2
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 3 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcmrpi3_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi3-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From 370780071189f7e7f89213626cda6d39d4c58916 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:09 +0100
Subject: [PATCH 2/4] rpi-base: split into rpi, rpi2, rpi3

Until now, raspberry Pi variants were solely distiguished by the target
architecture; this is insufficient for handling the upcoming addition of
rpi4-base.
Technically it would be fine for rpi-base to not depend on rpi-kernel
(and thus never have to account for new rpi variants anymore) but that
would be bad for existing installs.

For now it's sufficient to have one package provide all subpackages, to
ease maintainance. But the templates can easiliy be split should the
need arise some day.

rpi3-base actually existed back in 2017 (it depended on mainline instead
of rpi-kernel) and became obsolete in 2018; who would have known back
then we may have to deal with rpi>3 some day...
---
 srcpkgs/rpi-base/template    | 53 ++++++++++++++++++++++++++++++++++--
 srcpkgs/rpi-kernel/template  |  2 +-
 srcpkgs/rpi2-base            |  1 +
 srcpkgs/rpi2-kernel/template |  4 +--
 srcpkgs/rpi3-base            |  1 +
 srcpkgs/rpi3-kernel/template |  4 +--
 6 files changed, 58 insertions(+), 7 deletions(-)
 create mode 120000 srcpkgs/rpi2-base
 create mode 120000 srcpkgs/rpi3-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index 8fcf3581efd9..d5ae22b2c784 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,9 +1,10 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
-version=2.6
+version=3.0
 revision=1
 archs="armv6l* armv7l* aarch64*"
-depends="virtual?ntp-daemon rpi-firmware rpi-kernel"
+_base_depends="virtual?ntp-daemon rpi-firmware"
+depends="${_base_depends} rpi-kernel"
 short_desc="Void Linux Raspberry Pi base files"
 maintainer="Orphaned <orphan@voidlinux.org>"
 license="Public Domain"
@@ -12,3 +13,51 @@ homepage="https://www.voidlinux.org"
 do_install() {
 	vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 }
+
+case "$XBPS_TARGET_MACHINE" in
+	armv6*)
+		subpackages=" "
+		;;
+	armv7*)
+		subpackages="rpi2-base"
+		;;
+	aarch64*)
+		subpackages="rpi3-base"
+		;;
+esac
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi${n}-base package
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc+=" (transitional dummy package)"
+	 	do_install() { : ; }
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*)
+				depends="rpi2-base"
+				;;
+			aarch64*)
+				depends="rpi3-base"
+				;;
+		esac
+		;;
+esac
+
+rpi2-base_package() {
+	depends="${_base_depends} rpi2-kernel"
+	short_desc="Void Linux Raspberry Pi 2 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
+
+
+rpi3-base_package() {
+	depends="${_base_depends} rpi3-kernel"
+	short_desc="Void Linux Raspberry Pi 3 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index 981b04d3518f..38023f1900d9 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -10,7 +10,7 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi-kernel
 version=5.4.83
-revision=2
+revision=3
 archs="armv6l*"
 wrksrc="linux-${_githash}"
 hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
diff --git a/srcpkgs/rpi2-base b/srcpkgs/rpi2-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi2-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
index 2a780d552484..7b94e79cf9a0 100644
--- a/srcpkgs/rpi2-kernel/template
+++ b/srcpkgs/rpi2-kernel/template
@@ -10,10 +10,10 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi2-kernel
 version=5.4.83
-revision=2
+revision=1
 archs="armv7l*"
 wrksrc="linux-${_githash}"
-hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
 makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
diff --git a/srcpkgs/rpi3-base b/srcpkgs/rpi3-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi3-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
index 650a365905aa..4d69782c3fd9 100644
--- a/srcpkgs/rpi3-kernel/template
+++ b/srcpkgs/rpi3-kernel/template
@@ -10,10 +10,10 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi3-kernel
 version=5.4.83
-revision=2
+revision=1
 archs="aarch64*"
 wrksrc="linux-${_githash}"
-hostmakedepends="perl kmod uboot-mkimage libressl-devel bc bison flex"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
 makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"

From 671a3dadde85c0fd0a231d692a3d4880e7633fd4 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:52:49 +0100
Subject: [PATCH 3/4] New package: rpi4-kernel-5.4.83

---
 srcpkgs/rpi4-kernel-headers  |   1 +
 srcpkgs/rpi4-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 2 files changed, 251 insertions(+)
 create mode 120000 srcpkgs/rpi4-kernel-headers
 create mode 100644 srcpkgs/rpi4-kernel/template

diff --git a/srcpkgs/rpi4-kernel-headers b/srcpkgs/rpi4-kernel-headers
new file mode 120000
index 000000000000..9c2fad143506
--- /dev/null
+++ b/srcpkgs/rpi4-kernel-headers
@@ -0,0 +1 @@
+rpi4-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi4-kernel/template b/srcpkgs/rpi4-kernel/template
new file mode 100644
index 000000000000..896f5f747dd1
--- /dev/null
+++ b/srcpkgs/rpi4-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi4-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi4-kernel
+version=5.4.83
+revision=1
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 4 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcm2711_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi4-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From f9c9a9a768f5fb6912bc1428971a53a1edd5ee08 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:56:40 +0100
Subject: [PATCH 4/4] rpi-base: add rpi4

---
 srcpkgs/rpi-base/template | 13 +++++++++++--
 srcpkgs/rpi4-base         |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi4-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index d5ae22b2c784..4711609bef89 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,7 +1,7 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
 version=3.0
-revision=1
+revision=2
 archs="armv6l* armv7l* aarch64*"
 _base_depends="virtual?ntp-daemon rpi-firmware"
 depends="${_base_depends} rpi-kernel"
@@ -22,7 +22,7 @@ case "$XBPS_TARGET_MACHINE" in
 		subpackages="rpi2-base"
 		;;
 	aarch64*)
-		subpackages="rpi3-base"
+		subpackages="rpi3-base rpi4-base"
 		;;
 esac
 
@@ -61,3 +61,12 @@ rpi3-base_package() {
 		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 	}
 }
+
+rpi4-base_package() {
+	depends="${_base_depends} rpi4-kernel"
+	short_desc="Void Linux Raspberry Pi 4 base files"
+	conflicts="rpi3-base"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi4-base b/srcpkgs/rpi4-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi4-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR PATCH] [Updated] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (5 preceding siblings ...)
  2021-04-27 19:34 ` Piraty
@ 2021-04-27 20:04 ` Piraty
  2021-04-28 21:11 ` Piraty
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-04-27 20:04 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

There is an updated pull request by Piraty against master on the void-packages repository

https://github.com/Piraty/void-packages rpi-kernel-split
https://github.com/void-linux/void-packages/pull/29139

[NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
This is my second approach to the rpi4 problem (first try: https://github.com/void-linux/void-packages/pull/26000)

The problem is: how to not break existing systems while having a consistent naming scheme for rpi-kernel / rpi-base.

As ~demanded~ suggested by @the-maldridge , `rpi-kernel` continues to provide the kernel for rpi0/rpi1 and becomes a meta package that pulls `rpi{2,3}-kernel` (based on target arch) to serve legacy systems.

To support legacy systems, rpi-base is split into rpiN-base which all ship the same udev rule and depend on the respective kernel. This (still) allows to have a single entry-point to raspberry related packages.

I performed (offline) testing of the package transition process, seems fine. Script [here](https://gist.github.com/Piraty/2b0bd709c58ca2e8dd2240cc5b1141c9)

@pbui @Duncaen @ahesford 

A patch file from https://github.com/void-linux/void-packages/pull/29139.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-rpi-kernel-split-29139.patch --]
[-- Type: text/x-diff, Size: 33744 bytes --]

From bbf1505c8ca5a878778d318384fa1a0c8bc7d73a Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:00 +0100
Subject: [PATCH 1/4] rpi-kernel: split into rpi, rpi2, rpi3

Until now, raspberry Pi variants were solely distiguished by the target
architecture; this is insufficient for handling the upcoming addition of
rpi4-kernel, so split them.

* rpi-kernel will continue to serve raspberry Pi variants rpi0 and rpi1 for armv6l
* rpi2-kernel and rpi3-kernel will serve their respective raspberry Pi variant
* rpi-kernel will be an empty meta package for arch != armv6l and pull
    * rpi2-kernel for armv7
    * rpi3-kernel for aarch64
    to support the transition of existing systems to the new packaging
    scheme
---
 srcpkgs/rpi-kernel/template  |  55 +++++---
 srcpkgs/rpi2-kernel-headers  |   1 +
 srcpkgs/rpi2-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 srcpkgs/rpi3-kernel-headers  |   1 +
 srcpkgs/rpi3-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 5 files changed, 540 insertions(+), 17 deletions(-)
 create mode 120000 srcpkgs/rpi2-kernel-headers
 create mode 100644 srcpkgs/rpi2-kernel/template
 create mode 120000 srcpkgs/rpi3-kernel-headers
 create mode 100644 srcpkgs/rpi3-kernel/template

diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index 1fe4e2477e1f..f3f37534431f 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -10,12 +10,15 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi-kernel
 version=5.4.83
-revision=1
+revision=2
+archs="armv6l*"
 wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
 license="GPL-2.0-only"
-short_desc="The Linux kernel for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+short_desc="The Linux kernel for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
 distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
 checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
 python_version=2
@@ -27,10 +30,6 @@ nostrip=yes
 noverifyrdeps=yes
 noshlibprovides=yes
 
-# RPi, RPi2, RPi3
-archs="armv6l* armv7l* aarch64*"
-hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
-makedepends="ncurses-devel"
 triggers="kernel-hooks"
 # These files could be modified when an external module is built.
 mutable_files="
@@ -62,15 +61,6 @@ do_configure() {
 
 	# Use upstream's default configuration, no need to maintain ours.
 	case "$XBPS_TARGET_MACHINE" in
-		# RPi3
-		aarch64*)
-			target=bcmrpi3_defconfig
-			;;
-		# RPi2 / RPi3
-		armv7l*)
-			target=bcm2709_defconfig
-			;;
-		# RPi1
 		armv6l*)
 			target=bcmrpi_defconfig
 			;;
@@ -81,7 +71,7 @@ do_configure() {
 	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
 	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
 	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
-	
+
 	# IR Remote Support
 	echo "CONFIG_RC_CORE=y" >> "$defconfig"
 	echo "CONFIG_LIRC=y" >> "$defconfig"
@@ -252,9 +242,40 @@ rpi-kernel-headers_package() {
 	nostrip=yes
 	noverifyrdeps=yes
 	noshlibprovides=yes
-	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	short_desc="${short_desc/kernel/kernel headers}"
 	pkg_install() {
 		vmove usr/src
 		vmove usr/lib/modules/${_kernver}/build
 	}
 }
+
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi{$n}-kernel package
+archs+=" armv7l* aarch64*"
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc="The Linux kernel for Raspberry Pi ( transitional dummy package)"
+
+		pre_configure() { : ; }
+		do_configure() { : ; }
+		do_build() { : ; }
+		do_install() { : ; }
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends=rpi2-kernel ;;
+			aarch64*) depends=rpi3-kernel ;;
+		esac
+
+		rpi-kernel-headers_package() {
+			build_style=meta
+			short_desc="The Linux kernel headers for Raspberry Pi ( transitional dummy package)"
+			case "$XBPS_TARGET_MACHINE" in
+				armv7*) depends=rpi2-kernel-headers ;;
+				aarch64*) depends=rpi3-kernel-headers ;;
+			esac
+		}
+		;;
+esac
diff --git a/srcpkgs/rpi2-kernel-headers b/srcpkgs/rpi2-kernel-headers
new file mode 120000
index 000000000000..fbe6d91aeb7f
--- /dev/null
+++ b/srcpkgs/rpi2-kernel-headers
@@ -0,0 +1 @@
+rpi2-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
new file mode 100644
index 000000000000..7b94e79cf9a0
--- /dev/null
+++ b/srcpkgs/rpi2-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi2-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi2-kernel
+version=5.4.83
+revision=1
+archs="armv7l*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 2 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		armv7l*)
+			target=bcm2709_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi2-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}
diff --git a/srcpkgs/rpi3-kernel-headers b/srcpkgs/rpi3-kernel-headers
new file mode 120000
index 000000000000..29e9f333d668
--- /dev/null
+++ b/srcpkgs/rpi3-kernel-headers
@@ -0,0 +1 @@
+rpi3-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
new file mode 100644
index 000000000000..4d69782c3fd9
--- /dev/null
+++ b/srcpkgs/rpi3-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi3-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi3-kernel
+version=5.4.83
+revision=1
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 3 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcmrpi3_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi3-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From b8052a2ab3d2082b364bdef5085f520d78447daf Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:09 +0100
Subject: [PATCH 2/4] rpi-base: split into rpi, rpi2, rpi3

Until now, raspberry Pi variants were solely distiguished by the target
architecture; this is insufficient for handling the upcoming addition of
rpi4-base.
Technically it would be fine for rpi-base to not depend on rpi-kernel
(and thus never have to account for new rpi variants anymore) but that
would be bad for existing installs.

For now it's sufficient to have one package provide all subpackages, to
ease maintainance. But the templates can easiliy be split should the
need arise some day.

rpi3-base actually existed back in 2017 (it depended on mainline instead
of rpi-kernel) and became obsolete in 2018; who would have known back
then we may have to deal with rpi>3 some day...
---
 srcpkgs/rpi-base/template | 51 +++++++++++++++++++++++++++++++++++++--
 srcpkgs/rpi2-base         |  1 +
 srcpkgs/rpi3-base         |  1 +
 3 files changed, 51 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi2-base
 create mode 120000 srcpkgs/rpi3-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index 8fcf3581efd9..cbe8e79526f4 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,9 +1,10 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
-version=2.6
+version=3.0
 revision=1
 archs="armv6l* armv7l* aarch64*"
-depends="virtual?ntp-daemon rpi-firmware rpi-kernel"
+_base_depends="virtual?ntp-daemon rpi-firmware"
+depends="${_base_depends} rpi-kernel"
 short_desc="Void Linux Raspberry Pi base files"
 maintainer="Orphaned <orphan@voidlinux.org>"
 license="Public Domain"
@@ -12,3 +13,49 @@ homepage="https://www.voidlinux.org"
 do_install() {
 	vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 }
+
+case "$XBPS_TARGET_MACHINE" in
+	armv6*)
+		subpackages=" "
+		;;
+	armv7*)
+		subpackages="rpi2-base"
+		;;
+	aarch64*)
+		subpackages="rpi3-base"
+		;;
+esac
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi${n}-base package
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc+=" (transitional dummy package)"
+
+	 	do_install() { : ; }
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends="rpi2-base" ;;
+			aarch64*) depends="rpi3-base" ;;
+		esac
+		;;
+esac
+
+rpi2-base_package() {
+	depends="${_base_depends} rpi2-kernel"
+	short_desc="Void Linux Raspberry Pi 2 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
+
+
+rpi3-base_package() {
+	depends="${_base_depends} rpi3-kernel"
+	short_desc="Void Linux Raspberry Pi 3 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi2-base b/srcpkgs/rpi2-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi2-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi3-base b/srcpkgs/rpi3-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi3-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

From b7c114715ca51e97319c57d20905dddd6f35640f Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:52:49 +0100
Subject: [PATCH 3/4] New package: rpi4-kernel-5.4.83

---
 srcpkgs/rpi4-kernel-headers  |   1 +
 srcpkgs/rpi4-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 2 files changed, 251 insertions(+)
 create mode 120000 srcpkgs/rpi4-kernel-headers
 create mode 100644 srcpkgs/rpi4-kernel/template

diff --git a/srcpkgs/rpi4-kernel-headers b/srcpkgs/rpi4-kernel-headers
new file mode 120000
index 000000000000..9c2fad143506
--- /dev/null
+++ b/srcpkgs/rpi4-kernel-headers
@@ -0,0 +1 @@
+rpi4-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi4-kernel/template b/srcpkgs/rpi4-kernel/template
new file mode 100644
index 000000000000..896f5f747dd1
--- /dev/null
+++ b/srcpkgs/rpi4-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi4-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi4-kernel
+version=5.4.83
+revision=1
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 4 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcm2711_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi4-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From c87851a72041af2a4ff53d89090af4f5fcda500a Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:56:40 +0100
Subject: [PATCH 4/4] rpi-base: add rpi4

---
 srcpkgs/rpi-base/template | 13 +++++++++++--
 srcpkgs/rpi4-base         |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi4-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index cbe8e79526f4..8940033c83ab 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,7 +1,7 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
 version=3.0
-revision=1
+revision=2
 archs="armv6l* armv7l* aarch64*"
 _base_depends="virtual?ntp-daemon rpi-firmware"
 depends="${_base_depends} rpi-kernel"
@@ -22,7 +22,7 @@ case "$XBPS_TARGET_MACHINE" in
 		subpackages="rpi2-base"
 		;;
 	aarch64*)
-		subpackages="rpi3-base"
+		subpackages="rpi3-base rpi4-base"
 		;;
 esac
 
@@ -59,3 +59,12 @@ rpi3-base_package() {
 		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 	}
 }
+
+rpi4-base_package() {
+	depends="${_base_depends} rpi4-kernel"
+	short_desc="Void Linux Raspberry Pi 4 base files"
+	conflicts="rpi3-base"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi4-base b/srcpkgs/rpi4-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi4-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR PATCH] [Updated] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (6 preceding siblings ...)
  2021-04-27 20:04 ` Piraty
@ 2021-04-28 21:11 ` Piraty
  2021-05-04  9:09 ` Piraty
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-04-28 21:11 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1625 bytes --]

There is an updated pull request by Piraty against master on the void-packages repository

https://github.com/Piraty/void-packages rpi-kernel-split
https://github.com/void-linux/void-packages/pull/29139

[NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
This is my second approach to the rpi4 problem (first try: https://github.com/void-linux/void-packages/pull/26000)

The problem is: how to not break existing systems while having a consistent naming scheme for rpi-kernel / rpi-base.

As ~demanded~ suggested by @the-maldridge , `rpi-kernel` continues to provide the kernel for rpi0/rpi1 and becomes a meta package that pulls `rpi{2,3}-kernel` (based on target arch) so legacy pull the new update systems.
This may be optional though and we could require users to manually install the new kernel package, possibly posting a new post on the website for that.

To support legacy systems, rpi-base is split into rpiN-base which all ship the same udev rule and depend on the respective kernel. This (still) allows to have a single entry-point to raspberry related packages.

I performed (offline) testing of the package transition process, seems fine. Script [here](https://gist.github.com/Piraty/2b0bd709c58ca2e8dd2240cc5b1141c9)


### How to
1. checkout this branch
2. build one of `rpi4-base` (aarch64*) or `rpi-base` (`armv6*`, `armv7l*` or `aarch64*`)
3. update your pi with the new packages or build fresh images: see https://github.com/void-linux/void-mklive/pull/153

---

@pbui @Duncaen @ahesford 

A patch file from https://github.com/void-linux/void-packages/pull/29139.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-rpi-kernel-split-29139.patch --]
[-- Type: text/x-diff, Size: 34260 bytes --]

From c3e44100d4e61cec5f355bc4217e62b4b6ef0f0c Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:00 +0100
Subject: [PATCH 1/4] rpi-kernel: split into rpi, rpi2, rpi3

Until now, rpi-kernel served rpi0/rpi1 + rpi2 + rpi3 all at once.  The
variants were solely distiguished by the target architecture; it was
nice while it lasted, but now that rpi4 is on its way, we need to split
things up a little.

With the split,
* rpi-kernel serves rpi0 + rpi1, armv6l* only
* rpi2-kernel serves rpi2, armv7l* only
* rpi3-kernel serves rpi3, aarch64* only

To help migrate existing devices to the new kernel packages, rpi-kernel
will be an empty mega package for !armv6l* and depend on rpi2-kernel or
rpi3-kernel (depending on target architecture) for the foreseeable
future, thus resolving like this:
* rpi-kernel -> rpi2-kernel (armv7l*)
* rpi-kernel -> rpi3-kernel (aarch64*)
---
 srcpkgs/rpi-kernel/template  |  55 +++++---
 srcpkgs/rpi2-kernel-headers  |   1 +
 srcpkgs/rpi2-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 srcpkgs/rpi3-kernel-headers  |   1 +
 srcpkgs/rpi3-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 5 files changed, 540 insertions(+), 17 deletions(-)
 create mode 120000 srcpkgs/rpi2-kernel-headers
 create mode 100644 srcpkgs/rpi2-kernel/template
 create mode 120000 srcpkgs/rpi3-kernel-headers
 create mode 100644 srcpkgs/rpi3-kernel/template

diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index 1fe4e2477e1f..f3f37534431f 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -10,12 +10,15 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi-kernel
 version=5.4.83
-revision=1
+revision=2
+archs="armv6l*"
 wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
 license="GPL-2.0-only"
-short_desc="The Linux kernel for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+short_desc="The Linux kernel for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
 distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
 checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
 python_version=2
@@ -27,10 +30,6 @@ nostrip=yes
 noverifyrdeps=yes
 noshlibprovides=yes
 
-# RPi, RPi2, RPi3
-archs="armv6l* armv7l* aarch64*"
-hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
-makedepends="ncurses-devel"
 triggers="kernel-hooks"
 # These files could be modified when an external module is built.
 mutable_files="
@@ -62,15 +61,6 @@ do_configure() {
 
 	# Use upstream's default configuration, no need to maintain ours.
 	case "$XBPS_TARGET_MACHINE" in
-		# RPi3
-		aarch64*)
-			target=bcmrpi3_defconfig
-			;;
-		# RPi2 / RPi3
-		armv7l*)
-			target=bcm2709_defconfig
-			;;
-		# RPi1
 		armv6l*)
 			target=bcmrpi_defconfig
 			;;
@@ -81,7 +71,7 @@ do_configure() {
 	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
 	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
 	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
-	
+
 	# IR Remote Support
 	echo "CONFIG_RC_CORE=y" >> "$defconfig"
 	echo "CONFIG_LIRC=y" >> "$defconfig"
@@ -252,9 +242,40 @@ rpi-kernel-headers_package() {
 	nostrip=yes
 	noverifyrdeps=yes
 	noshlibprovides=yes
-	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	short_desc="${short_desc/kernel/kernel headers}"
 	pkg_install() {
 		vmove usr/src
 		vmove usr/lib/modules/${_kernver}/build
 	}
 }
+
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi{$n}-kernel package
+archs+=" armv7l* aarch64*"
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc="The Linux kernel for Raspberry Pi ( transitional dummy package)"
+
+		pre_configure() { : ; }
+		do_configure() { : ; }
+		do_build() { : ; }
+		do_install() { : ; }
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends=rpi2-kernel ;;
+			aarch64*) depends=rpi3-kernel ;;
+		esac
+
+		rpi-kernel-headers_package() {
+			build_style=meta
+			short_desc="The Linux kernel headers for Raspberry Pi ( transitional dummy package)"
+			case "$XBPS_TARGET_MACHINE" in
+				armv7*) depends=rpi2-kernel-headers ;;
+				aarch64*) depends=rpi3-kernel-headers ;;
+			esac
+		}
+		;;
+esac
diff --git a/srcpkgs/rpi2-kernel-headers b/srcpkgs/rpi2-kernel-headers
new file mode 120000
index 000000000000..fbe6d91aeb7f
--- /dev/null
+++ b/srcpkgs/rpi2-kernel-headers
@@ -0,0 +1 @@
+rpi2-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
new file mode 100644
index 000000000000..7b94e79cf9a0
--- /dev/null
+++ b/srcpkgs/rpi2-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi2-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi2-kernel
+version=5.4.83
+revision=1
+archs="armv7l*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 2 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		armv7l*)
+			target=bcm2709_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi2-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}
diff --git a/srcpkgs/rpi3-kernel-headers b/srcpkgs/rpi3-kernel-headers
new file mode 120000
index 000000000000..29e9f333d668
--- /dev/null
+++ b/srcpkgs/rpi3-kernel-headers
@@ -0,0 +1 @@
+rpi3-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
new file mode 100644
index 000000000000..4d69782c3fd9
--- /dev/null
+++ b/srcpkgs/rpi3-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi3-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi3-kernel
+version=5.4.83
+revision=1
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 3 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcmrpi3_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi3-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From 78bfff9c8f022a67d2beee3d30b3e772b8984dea Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:09 +0100
Subject: [PATCH 2/4] rpi-base: split into rpi, rpi2, rpi3

Until now, rpi-base served rpi0/rpi1 + rpi2 + rpi3 all at once.  The
variants were solely distiguished by the target architecture; it was
nice while it lasted, but now that rpi4 is on its way, we need to split
things up a little.

With the split,
* rpi-base depends on rpi-kernel, armv6l* only,
* rpi2-base depends on rpi2-kernel, armv7l* only
* rpi3-base depends on rpi3-kernel, aarch64* only,

To help migrate existing devices to the new base packages, rpi-base
will be an empty mega package for !armv6l* and depend on rpi2-base or
rpi3-base for the foreseeable future, thus resolving like this:
* rpi-base -> rpi2-base (armv7l*)
* rpi-base -> rpi3-base (aarch64*)

For now it's sufficient to have one package provide all subpackages, to
ease maintainance. The template can easiliy be split (as we did with
rpi-kernel) should the need arise some day.

rpi3-base actually existed back in 2017 (it depended on mainline kernel
instead of rpi-kernel) and became obsolete in 2018;
who would have known back then we may have to deal with rpi>3 some day...
---
 srcpkgs/rpi-base/template | 51 +++++++++++++++++++++++++++++++++++++--
 srcpkgs/rpi2-base         |  1 +
 srcpkgs/rpi3-base         |  1 +
 3 files changed, 51 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi2-base
 create mode 120000 srcpkgs/rpi3-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index 8fcf3581efd9..cbe8e79526f4 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,9 +1,10 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
-version=2.6
+version=3.0
 revision=1
 archs="armv6l* armv7l* aarch64*"
-depends="virtual?ntp-daemon rpi-firmware rpi-kernel"
+_base_depends="virtual?ntp-daemon rpi-firmware"
+depends="${_base_depends} rpi-kernel"
 short_desc="Void Linux Raspberry Pi base files"
 maintainer="Orphaned <orphan@voidlinux.org>"
 license="Public Domain"
@@ -12,3 +13,49 @@ homepage="https://www.voidlinux.org"
 do_install() {
 	vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 }
+
+case "$XBPS_TARGET_MACHINE" in
+	armv6*)
+		subpackages=" "
+		;;
+	armv7*)
+		subpackages="rpi2-base"
+		;;
+	aarch64*)
+		subpackages="rpi3-base"
+		;;
+esac
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi${n}-base package
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc+=" (transitional dummy package)"
+
+	 	do_install() { : ; }
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends="rpi2-base" ;;
+			aarch64*) depends="rpi3-base" ;;
+		esac
+		;;
+esac
+
+rpi2-base_package() {
+	depends="${_base_depends} rpi2-kernel"
+	short_desc="Void Linux Raspberry Pi 2 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
+
+
+rpi3-base_package() {
+	depends="${_base_depends} rpi3-kernel"
+	short_desc="Void Linux Raspberry Pi 3 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi2-base b/srcpkgs/rpi2-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi2-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi3-base b/srcpkgs/rpi3-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi3-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

From 8fff353139ff74d55b7a14e1f4d15229871d3ec3 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:52:49 +0100
Subject: [PATCH 3/4] New package: rpi4-kernel-5.4.83

---
 srcpkgs/rpi4-kernel-headers  |   1 +
 srcpkgs/rpi4-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 2 files changed, 251 insertions(+)
 create mode 120000 srcpkgs/rpi4-kernel-headers
 create mode 100644 srcpkgs/rpi4-kernel/template

diff --git a/srcpkgs/rpi4-kernel-headers b/srcpkgs/rpi4-kernel-headers
new file mode 120000
index 000000000000..9c2fad143506
--- /dev/null
+++ b/srcpkgs/rpi4-kernel-headers
@@ -0,0 +1 @@
+rpi4-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi4-kernel/template b/srcpkgs/rpi4-kernel/template
new file mode 100644
index 000000000000..896f5f747dd1
--- /dev/null
+++ b/srcpkgs/rpi4-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi4-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi4-kernel
+version=5.4.83
+revision=1
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 4 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcm2711_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi4-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From 87345c2014014881d93dcd2d41ce595bdec27fbc Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:56:40 +0100
Subject: [PATCH 4/4] rpi-base: add rpi4

---
 srcpkgs/rpi-base/template | 13 +++++++++++--
 srcpkgs/rpi4-base         |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi4-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index cbe8e79526f4..8940033c83ab 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,7 +1,7 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
 version=3.0
-revision=1
+revision=2
 archs="armv6l* armv7l* aarch64*"
 _base_depends="virtual?ntp-daemon rpi-firmware"
 depends="${_base_depends} rpi-kernel"
@@ -22,7 +22,7 @@ case "$XBPS_TARGET_MACHINE" in
 		subpackages="rpi2-base"
 		;;
 	aarch64*)
-		subpackages="rpi3-base"
+		subpackages="rpi3-base rpi4-base"
 		;;
 esac
 
@@ -59,3 +59,12 @@ rpi3-base_package() {
 		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 	}
 }
+
+rpi4-base_package() {
+	depends="${_base_depends} rpi4-kernel"
+	short_desc="Void Linux Raspberry Pi 4 base files"
+	conflicts="rpi3-base"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi4-base b/srcpkgs/rpi4-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi4-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR PATCH] [Updated] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (7 preceding siblings ...)
  2021-04-28 21:11 ` Piraty
@ 2021-05-04  9:09 ` Piraty
  2021-05-04 19:32 ` Piraty
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-05-04  9:09 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1625 bytes --]

There is an updated pull request by Piraty against master on the void-packages repository

https://github.com/Piraty/void-packages rpi-kernel-split
https://github.com/void-linux/void-packages/pull/29139

[NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
This is my second approach to the rpi4 problem (first try: https://github.com/void-linux/void-packages/pull/26000)

The problem is: how to not break existing systems while having a consistent naming scheme for rpi-kernel / rpi-base.

As ~demanded~ suggested by @the-maldridge , `rpi-kernel` continues to provide the kernel for rpi0/rpi1 and becomes a meta package that pulls `rpi{2,3}-kernel` (based on target arch) so legacy pull the new update systems.
This may be optional though and we could require users to manually install the new kernel package, possibly posting a new post on the website for that.

To support legacy systems, rpi-base is split into rpiN-base which all ship the same udev rule and depend on the respective kernel. This (still) allows to have a single entry-point to raspberry related packages.

I performed (offline) testing of the package transition process, seems fine. Script [here](https://gist.github.com/Piraty/2b0bd709c58ca2e8dd2240cc5b1141c9)


### How to
1. checkout this branch
2. build one of `rpi4-base` (aarch64*) or `rpi-base` (`armv6*`, `armv7l*` or `aarch64*`)
3. update your pi with the new packages or build fresh images: see https://github.com/void-linux/void-mklive/pull/153

---

@pbui @Duncaen @ahesford 

A patch file from https://github.com/void-linux/void-packages/pull/29139.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-rpi-kernel-split-29139.patch --]
[-- Type: text/x-diff, Size: 34249 bytes --]

From f5941507e5e7823ece52a8b4ca8a65d93664ad05 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:00 +0100
Subject: [PATCH 1/4] rpi-kernel: split into rpi, rpi2, rpi3

Until now, rpi-kernel served rpi0/rpi1 + rpi2 + rpi3 all at once.  The
variants were solely distiguished by the target architecture; it was
nice while it lasted, but now that rpi4 is on its way, we need to split
things up a little.

With the split,
* rpi-kernel serves rpi0 + rpi1, armv6l* only
* rpi2-kernel serves rpi2, armv7l* only
* rpi3-kernel serves rpi3, aarch64* only

To help migrate existing devices to the new kernel packages, rpi-kernel
will be an empty mega package for !armv6l* and depend on rpi2-kernel or
rpi3-kernel (depending on target architecture) for the foreseeable
future, thus resolving like this:
* rpi-kernel -> rpi2-kernel (armv7l*)
* rpi-kernel -> rpi3-kernel (aarch64*)
---
 srcpkgs/rpi-kernel/template  |  55 +++++---
 srcpkgs/rpi2-kernel-headers  |   1 +
 srcpkgs/rpi2-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 srcpkgs/rpi3-kernel-headers  |   1 +
 srcpkgs/rpi3-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 5 files changed, 540 insertions(+), 17 deletions(-)
 create mode 120000 srcpkgs/rpi2-kernel-headers
 create mode 100644 srcpkgs/rpi2-kernel/template
 create mode 120000 srcpkgs/rpi3-kernel-headers
 create mode 100644 srcpkgs/rpi3-kernel/template

diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index 1fe4e2477e1f..e3126aa6462e 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -10,12 +10,15 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi-kernel
 version=5.4.83
-revision=1
+revision=2
+archs="armv6l*"
 wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
 license="GPL-2.0-only"
-short_desc="The Linux kernel for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+short_desc="The Linux kernel for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
 distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
 checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
 python_version=2
@@ -27,10 +30,6 @@ nostrip=yes
 noverifyrdeps=yes
 noshlibprovides=yes
 
-# RPi, RPi2, RPi3
-archs="armv6l* armv7l* aarch64*"
-hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
-makedepends="ncurses-devel"
 triggers="kernel-hooks"
 # These files could be modified when an external module is built.
 mutable_files="
@@ -62,15 +61,6 @@ do_configure() {
 
 	# Use upstream's default configuration, no need to maintain ours.
 	case "$XBPS_TARGET_MACHINE" in
-		# RPi3
-		aarch64*)
-			target=bcmrpi3_defconfig
-			;;
-		# RPi2 / RPi3
-		armv7l*)
-			target=bcm2709_defconfig
-			;;
-		# RPi1
 		armv6l*)
 			target=bcmrpi_defconfig
 			;;
@@ -81,7 +71,7 @@ do_configure() {
 	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
 	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
 	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
-	
+
 	# IR Remote Support
 	echo "CONFIG_RC_CORE=y" >> "$defconfig"
 	echo "CONFIG_LIRC=y" >> "$defconfig"
@@ -252,9 +242,40 @@ rpi-kernel-headers_package() {
 	nostrip=yes
 	noverifyrdeps=yes
 	noshlibprovides=yes
-	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	short_desc="${short_desc/kernel/kernel headers}"
 	pkg_install() {
 		vmove usr/src
 		vmove usr/lib/modules/${_kernver}/build
 	}
 }
+
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi{$n}-kernel package
+archs+=" armv7l* aarch64*"
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc="The Linux kernel for Raspberry Pi (transitional dummy package)"
+
+		pre_configure() { : ; }
+		do_configure() { : ; }
+		do_build() { : ; }
+		do_install() { : ; }
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends=rpi2-kernel ;;
+			aarch64*) depends=rpi3-kernel ;;
+		esac
+
+		rpi-kernel-headers_package() {
+			build_style=meta
+			short_desc="The Linux kernel headers for Raspberry Pi (transitional dummy package)"
+			case "$XBPS_TARGET_MACHINE" in
+				armv7*) depends=rpi2-kernel-headers ;;
+				aarch64*) depends=rpi3-kernel-headers ;;
+			esac
+		}
+		;;
+esac
diff --git a/srcpkgs/rpi2-kernel-headers b/srcpkgs/rpi2-kernel-headers
new file mode 120000
index 000000000000..fbe6d91aeb7f
--- /dev/null
+++ b/srcpkgs/rpi2-kernel-headers
@@ -0,0 +1 @@
+rpi2-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
new file mode 100644
index 000000000000..7b94e79cf9a0
--- /dev/null
+++ b/srcpkgs/rpi2-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi2-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi2-kernel
+version=5.4.83
+revision=1
+archs="armv7l*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 2 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		armv7l*)
+			target=bcm2709_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi2-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}
diff --git a/srcpkgs/rpi3-kernel-headers b/srcpkgs/rpi3-kernel-headers
new file mode 120000
index 000000000000..29e9f333d668
--- /dev/null
+++ b/srcpkgs/rpi3-kernel-headers
@@ -0,0 +1 @@
+rpi3-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
new file mode 100644
index 000000000000..b707c154e985
--- /dev/null
+++ b/srcpkgs/rpi3-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi3-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi3-kernel
+version=5.4.83
+revision=1
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 3 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcmrpi3_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/*dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi3-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From a953a4c3e09fcb1de61a7d2026472008c1ee8593 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:09 +0100
Subject: [PATCH 2/4] rpi-base: split into rpi, rpi2, rpi3

Until now, rpi-base served rpi0/rpi1 + rpi2 + rpi3 all at once.  The
variants were solely distiguished by the target architecture; it was
nice while it lasted, but now that rpi4 is on its way, we need to split
things up a little.

With the split,
* rpi-base depends on rpi-kernel, armv6l* only,
* rpi2-base depends on rpi2-kernel, armv7l* only
* rpi3-base depends on rpi3-kernel, aarch64* only,

To help migrate existing devices to the new base packages, rpi-base
will be an empty mega package for !armv6l* and depend on rpi2-base or
rpi3-base for the foreseeable future, thus resolving like this:
* rpi-base -> rpi2-base (armv7l*)
* rpi-base -> rpi3-base (aarch64*)

For now it's sufficient to have one package provide all subpackages, to
ease maintainance. The template can easiliy be split (as we did with
rpi-kernel) should the need arise some day.

rpi3-base actually existed back in 2017 (it depended on mainline kernel
instead of rpi-kernel) and became obsolete in 2018;
who would have known back then we may have to deal with rpi>3 some day...
---
 srcpkgs/rpi-base/template | 51 +++++++++++++++++++++++++++++++++++++--
 srcpkgs/rpi2-base         |  1 +
 srcpkgs/rpi3-base         |  1 +
 3 files changed, 51 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi2-base
 create mode 120000 srcpkgs/rpi3-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index 8fcf3581efd9..cbe8e79526f4 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,9 +1,10 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
-version=2.6
+version=3.0
 revision=1
 archs="armv6l* armv7l* aarch64*"
-depends="virtual?ntp-daemon rpi-firmware rpi-kernel"
+_base_depends="virtual?ntp-daemon rpi-firmware"
+depends="${_base_depends} rpi-kernel"
 short_desc="Void Linux Raspberry Pi base files"
 maintainer="Orphaned <orphan@voidlinux.org>"
 license="Public Domain"
@@ -12,3 +13,49 @@ homepage="https://www.voidlinux.org"
 do_install() {
 	vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 }
+
+case "$XBPS_TARGET_MACHINE" in
+	armv6*)
+		subpackages=" "
+		;;
+	armv7*)
+		subpackages="rpi2-base"
+		;;
+	aarch64*)
+		subpackages="rpi3-base"
+		;;
+esac
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi${n}-base package
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc+=" (transitional dummy package)"
+
+	 	do_install() { : ; }
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends="rpi2-base" ;;
+			aarch64*) depends="rpi3-base" ;;
+		esac
+		;;
+esac
+
+rpi2-base_package() {
+	depends="${_base_depends} rpi2-kernel"
+	short_desc="Void Linux Raspberry Pi 2 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
+
+
+rpi3-base_package() {
+	depends="${_base_depends} rpi3-kernel"
+	short_desc="Void Linux Raspberry Pi 3 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi2-base b/srcpkgs/rpi2-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi2-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi3-base b/srcpkgs/rpi3-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi3-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

From b0388e98db14f91dfd8d030fce8e1634b00b76c2 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:52:49 +0100
Subject: [PATCH 3/4] New package: rpi4-kernel-5.4.83

---
 srcpkgs/rpi4-kernel-headers  |   1 +
 srcpkgs/rpi4-kernel/template | 251 +++++++++++++++++++++++++++++++++++
 2 files changed, 252 insertions(+)
 create mode 120000 srcpkgs/rpi4-kernel-headers
 create mode 100644 srcpkgs/rpi4-kernel/template

diff --git a/srcpkgs/rpi4-kernel-headers b/srcpkgs/rpi4-kernel-headers
new file mode 120000
index 000000000000..9c2fad143506
--- /dev/null
+++ b/srcpkgs/rpi4-kernel-headers
@@ -0,0 +1 @@
+rpi4-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi4-kernel/template b/srcpkgs/rpi4-kernel/template
new file mode 100644
index 000000000000..0908fff64660
--- /dev/null
+++ b/srcpkgs/rpi4-kernel/template
@@ -0,0 +1,251 @@
+# Template file for 'rpi4-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi4-kernel
+version=5.4.83
+revision=1
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 4 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+conflicts=rpi3-kernel
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcm2711_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/*dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi4-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From 015612f5206ed56ffd2f50082712423051a3b007 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:56:40 +0100
Subject: [PATCH 4/4] rpi-base: add rpi4

---
 srcpkgs/rpi-base/template | 13 +++++++++++--
 srcpkgs/rpi4-base         |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi4-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index cbe8e79526f4..8940033c83ab 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,7 +1,7 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
 version=3.0
-revision=1
+revision=2
 archs="armv6l* armv7l* aarch64*"
 _base_depends="virtual?ntp-daemon rpi-firmware"
 depends="${_base_depends} rpi-kernel"
@@ -22,7 +22,7 @@ case "$XBPS_TARGET_MACHINE" in
 		subpackages="rpi2-base"
 		;;
 	aarch64*)
-		subpackages="rpi3-base"
+		subpackages="rpi3-base rpi4-base"
 		;;
 esac
 
@@ -59,3 +59,12 @@ rpi3-base_package() {
 		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 	}
 }
+
+rpi4-base_package() {
+	depends="${_base_depends} rpi4-kernel"
+	short_desc="Void Linux Raspberry Pi 4 base files"
+	conflicts="rpi3-base"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi4-base b/srcpkgs/rpi4-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi4-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (8 preceding siblings ...)
  2021-05-04  9:09 ` Piraty
@ 2021-05-04 19:32 ` Piraty
  2021-05-04 19:36 ` [PR PATCH] [Updated] " Piraty
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-05-04 19:32 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

New comment by Piraty on void-packages repository

https://github.com/void-linux/void-packages/pull/29139#issuecomment-832190234

Comment:
This is ready for review.
* rpi4-base/rpi4-kernel are trivial and work as expected
* rpi{,2,3}-kernel / and -base need testing regarding package transition and successful boot

I did a successful transition of my rpi3 ([log here](https://gist.github.com/Piraty/bae850ed52d19e3702d2c6ac22e20196)) and would like more testers to check this.

How to:
1. build the packages: `rpi3-kernel rpi3-base rpi-kernel rpi-base`
2. copy to rpi: `rsync ... hostdir/binpkgs/<branch>/* rpi:/tmp`
3. install: `xbps-install --repository /tmp -Su` 

ping the usual suspects: @pbui @ahesford @ericonr @Duncaen @the-maldridge 
as well as interested users as of @26000:  @jsav0, @CMB , @manneorama , @LeamHall , @Anachron , @agausmann , @CameronNemo , @liketechnik 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR PATCH] [Updated] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (9 preceding siblings ...)
  2021-05-04 19:32 ` Piraty
@ 2021-05-04 19:36 ` Piraty
  2021-05-04 19:53 ` [PR REVIEW] " ericonr
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-05-04 19:36 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1625 bytes --]

There is an updated pull request by Piraty against master on the void-packages repository

https://github.com/Piraty/void-packages rpi-kernel-split
https://github.com/void-linux/void-packages/pull/29139

[NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
This is my second approach to the rpi4 problem (first try: https://github.com/void-linux/void-packages/pull/26000)

The problem is: how to not break existing systems while having a consistent naming scheme for rpi-kernel / rpi-base.

As ~demanded~ suggested by @the-maldridge , `rpi-kernel` continues to provide the kernel for rpi0/rpi1 and becomes a meta package that pulls `rpi{2,3}-kernel` (based on target arch) so legacy pull the new update systems.
This may be optional though and we could require users to manually install the new kernel package, possibly posting a new post on the website for that.

To support legacy systems, rpi-base is split into rpiN-base which all ship the same udev rule and depend on the respective kernel. This (still) allows to have a single entry-point to raspberry related packages.

I performed (offline) testing of the package transition process, seems fine. Script [here](https://gist.github.com/Piraty/2b0bd709c58ca2e8dd2240cc5b1141c9)


### How to
1. checkout this branch
2. build one of `rpi4-base` (aarch64*) or `rpi-base` (`armv6*`, `armv7l*` or `aarch64*`)
3. update your pi with the new packages or build fresh images: see https://github.com/void-linux/void-mklive/pull/153

---

@pbui @Duncaen @ahesford 

A patch file from https://github.com/void-linux/void-packages/pull/29139.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-rpi-kernel-split-29139.patch --]
[-- Type: text/x-diff, Size: 34249 bytes --]

From ef115e65675994e8e3cb65a2b2a02a4e9a53feac Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:00 +0100
Subject: [PATCH 1/4] rpi-kernel: split into rpi, rpi2, rpi3

Until now, rpi-kernel served rpi0/rpi1 + rpi2 + rpi3 all at once.  The
variants were solely distiguished by the target architecture; it was
nice while it lasted, but now that rpi4 is on its way, we need to split
things up a little.

With the split,
* rpi-kernel serves rpi0 + rpi1, armv6l* only
* rpi2-kernel serves rpi2, armv7l* only
* rpi3-kernel serves rpi3, aarch64* only

To help migrate existing devices to the new kernel packages, rpi-kernel
will be an empty mega package for !armv6l* and depend on rpi2-kernel or
rpi3-kernel (depending on target architecture) for the foreseeable
future, thus resolving like this:
* rpi-kernel -> rpi2-kernel (armv7l*)
* rpi-kernel -> rpi3-kernel (aarch64*)
---
 srcpkgs/rpi-kernel/template  |  55 +++++---
 srcpkgs/rpi2-kernel-headers  |   1 +
 srcpkgs/rpi2-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 srcpkgs/rpi3-kernel-headers  |   1 +
 srcpkgs/rpi3-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 5 files changed, 540 insertions(+), 17 deletions(-)
 create mode 120000 srcpkgs/rpi2-kernel-headers
 create mode 100644 srcpkgs/rpi2-kernel/template
 create mode 120000 srcpkgs/rpi3-kernel-headers
 create mode 100644 srcpkgs/rpi3-kernel/template

diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index 1fe4e2477e1f..e3126aa6462e 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -10,12 +10,15 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi-kernel
 version=5.4.83
-revision=1
+revision=2
+archs="armv6l*"
 wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
 license="GPL-2.0-only"
-short_desc="The Linux kernel for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+short_desc="The Linux kernel for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
 distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
 checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
 python_version=2
@@ -27,10 +30,6 @@ nostrip=yes
 noverifyrdeps=yes
 noshlibprovides=yes
 
-# RPi, RPi2, RPi3
-archs="armv6l* armv7l* aarch64*"
-hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
-makedepends="ncurses-devel"
 triggers="kernel-hooks"
 # These files could be modified when an external module is built.
 mutable_files="
@@ -62,15 +61,6 @@ do_configure() {
 
 	# Use upstream's default configuration, no need to maintain ours.
 	case "$XBPS_TARGET_MACHINE" in
-		# RPi3
-		aarch64*)
-			target=bcmrpi3_defconfig
-			;;
-		# RPi2 / RPi3
-		armv7l*)
-			target=bcm2709_defconfig
-			;;
-		# RPi1
 		armv6l*)
 			target=bcmrpi_defconfig
 			;;
@@ -81,7 +71,7 @@ do_configure() {
 	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
 	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
 	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
-	
+
 	# IR Remote Support
 	echo "CONFIG_RC_CORE=y" >> "$defconfig"
 	echo "CONFIG_LIRC=y" >> "$defconfig"
@@ -252,9 +242,40 @@ rpi-kernel-headers_package() {
 	nostrip=yes
 	noverifyrdeps=yes
 	noshlibprovides=yes
-	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	short_desc="${short_desc/kernel/kernel headers}"
 	pkg_install() {
 		vmove usr/src
 		vmove usr/lib/modules/${_kernver}/build
 	}
 }
+
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi{$n}-kernel package
+archs+=" armv7l* aarch64*"
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc="The Linux kernel for Raspberry Pi (transitional dummy package)"
+
+		pre_configure() { : ; }
+		do_configure() { : ; }
+		do_build() { : ; }
+		do_install() { : ; }
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends=rpi2-kernel ;;
+			aarch64*) depends=rpi3-kernel ;;
+		esac
+
+		rpi-kernel-headers_package() {
+			build_style=meta
+			short_desc="The Linux kernel headers for Raspberry Pi (transitional dummy package)"
+			case "$XBPS_TARGET_MACHINE" in
+				armv7*) depends=rpi2-kernel-headers ;;
+				aarch64*) depends=rpi3-kernel-headers ;;
+			esac
+		}
+		;;
+esac
diff --git a/srcpkgs/rpi2-kernel-headers b/srcpkgs/rpi2-kernel-headers
new file mode 120000
index 000000000000..fbe6d91aeb7f
--- /dev/null
+++ b/srcpkgs/rpi2-kernel-headers
@@ -0,0 +1 @@
+rpi2-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
new file mode 100644
index 000000000000..074488818ed1
--- /dev/null
+++ b/srcpkgs/rpi2-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi2-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi2-kernel
+version=5.4.83
+revision=2
+archs="armv7l*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 2 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		armv7l*)
+			target=bcm2709_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi2-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}
diff --git a/srcpkgs/rpi3-kernel-headers b/srcpkgs/rpi3-kernel-headers
new file mode 120000
index 000000000000..29e9f333d668
--- /dev/null
+++ b/srcpkgs/rpi3-kernel-headers
@@ -0,0 +1 @@
+rpi3-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
new file mode 100644
index 000000000000..2f97235288ba
--- /dev/null
+++ b/srcpkgs/rpi3-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi3-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi3-kernel
+version=5.4.83
+revision=2
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 3 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcmrpi3_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/*dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi3-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From ab8fa4d1e3f897fb3e07b212e231888e8944fde0 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:09 +0100
Subject: [PATCH 2/4] rpi-base: split into rpi, rpi2, rpi3

Until now, rpi-base served rpi0/rpi1 + rpi2 + rpi3 all at once.  The
variants were solely distiguished by the target architecture; it was
nice while it lasted, but now that rpi4 is on its way, we need to split
things up a little.

With the split,
* rpi-base depends on rpi-kernel, armv6l* only,
* rpi2-base depends on rpi2-kernel, armv7l* only
* rpi3-base depends on rpi3-kernel, aarch64* only,

To help migrate existing devices to the new base packages, rpi-base
will be an empty mega package for !armv6l* and depend on rpi2-base or
rpi3-base for the foreseeable future, thus resolving like this:
* rpi-base -> rpi2-base (armv7l*)
* rpi-base -> rpi3-base (aarch64*)

For now it's sufficient to have one package provide all subpackages, to
ease maintainance. The template can easiliy be split (as we did with
rpi-kernel) should the need arise some day.

rpi3-base actually existed back in 2017 (it depended on mainline kernel
instead of rpi-kernel) and became obsolete in 2018;
who would have known back then we may have to deal with rpi>3 some day...
---
 srcpkgs/rpi-base/template | 51 +++++++++++++++++++++++++++++++++++++--
 srcpkgs/rpi2-base         |  1 +
 srcpkgs/rpi3-base         |  1 +
 3 files changed, 51 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi2-base
 create mode 120000 srcpkgs/rpi3-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index 8fcf3581efd9..cbe8e79526f4 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,9 +1,10 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
-version=2.6
+version=3.0
 revision=1
 archs="armv6l* armv7l* aarch64*"
-depends="virtual?ntp-daemon rpi-firmware rpi-kernel"
+_base_depends="virtual?ntp-daemon rpi-firmware"
+depends="${_base_depends} rpi-kernel"
 short_desc="Void Linux Raspberry Pi base files"
 maintainer="Orphaned <orphan@voidlinux.org>"
 license="Public Domain"
@@ -12,3 +13,49 @@ homepage="https://www.voidlinux.org"
 do_install() {
 	vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 }
+
+case "$XBPS_TARGET_MACHINE" in
+	armv6*)
+		subpackages=" "
+		;;
+	armv7*)
+		subpackages="rpi2-base"
+		;;
+	aarch64*)
+		subpackages="rpi3-base"
+		;;
+esac
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi${n}-base package
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc+=" (transitional dummy package)"
+
+	 	do_install() { : ; }
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends="rpi2-base" ;;
+			aarch64*) depends="rpi3-base" ;;
+		esac
+		;;
+esac
+
+rpi2-base_package() {
+	depends="${_base_depends} rpi2-kernel"
+	short_desc="Void Linux Raspberry Pi 2 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
+
+
+rpi3-base_package() {
+	depends="${_base_depends} rpi3-kernel"
+	short_desc="Void Linux Raspberry Pi 3 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi2-base b/srcpkgs/rpi2-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi2-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi3-base b/srcpkgs/rpi3-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi3-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

From 7fbb32194e37a48af592d8147fccda1306485387 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:52:49 +0100
Subject: [PATCH 3/4] New package: rpi4-kernel-5.4.83

---
 srcpkgs/rpi4-kernel-headers  |   1 +
 srcpkgs/rpi4-kernel/template | 251 +++++++++++++++++++++++++++++++++++
 2 files changed, 252 insertions(+)
 create mode 120000 srcpkgs/rpi4-kernel-headers
 create mode 100644 srcpkgs/rpi4-kernel/template

diff --git a/srcpkgs/rpi4-kernel-headers b/srcpkgs/rpi4-kernel-headers
new file mode 120000
index 000000000000..9c2fad143506
--- /dev/null
+++ b/srcpkgs/rpi4-kernel-headers
@@ -0,0 +1 @@
+rpi4-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi4-kernel/template b/srcpkgs/rpi4-kernel/template
new file mode 100644
index 000000000000..0908fff64660
--- /dev/null
+++ b/srcpkgs/rpi4-kernel/template
@@ -0,0 +1,251 @@
+# Template file for 'rpi4-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi4-kernel
+version=5.4.83
+revision=1
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="The Linux kernel for Raspberry Pi 4 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+conflicts=rpi3-kernel
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcm2711_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/*dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi4-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From 25cc7ebee759faced4082ec41e6c5428ab821be7 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:56:40 +0100
Subject: [PATCH 4/4] rpi-base: add rpi4

---
 srcpkgs/rpi-base/template | 13 +++++++++++--
 srcpkgs/rpi4-base         |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi4-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index cbe8e79526f4..8940033c83ab 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,7 +1,7 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
 version=3.0
-revision=1
+revision=2
 archs="armv6l* armv7l* aarch64*"
 _base_depends="virtual?ntp-daemon rpi-firmware"
 depends="${_base_depends} rpi-kernel"
@@ -22,7 +22,7 @@ case "$XBPS_TARGET_MACHINE" in
 		subpackages="rpi2-base"
 		;;
 	aarch64*)
-		subpackages="rpi3-base"
+		subpackages="rpi3-base rpi4-base"
 		;;
 esac
 
@@ -59,3 +59,12 @@ rpi3-base_package() {
 		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 	}
 }
+
+rpi4-base_package() {
+	depends="${_base_depends} rpi4-kernel"
+	short_desc="Void Linux Raspberry Pi 4 base files"
+	conflicts="rpi3-base"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi4-base b/srcpkgs/rpi4-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi4-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR REVIEW] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (10 preceding siblings ...)
  2021-05-04 19:36 ` [PR PATCH] [Updated] " Piraty
@ 2021-05-04 19:53 ` ericonr
  2021-05-04 19:53 ` ericonr
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: ericonr @ 2021-05-04 19:53 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 170 bytes --]

New review comment by ericonr on void-packages repository

https://github.com/void-linux/void-packages/pull/29139#discussion_r626061850

Comment:
Shouldn't be necessary.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (11 preceding siblings ...)
  2021-05-04 19:53 ` [PR REVIEW] " ericonr
@ 2021-05-04 19:53 ` ericonr
  2021-05-06 10:10 ` [PR REVIEW] " Piraty
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: ericonr @ 2021-05-04 19:53 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 202 bytes --]

New comment by ericonr on void-packages repository

https://github.com/void-linux/void-packages/pull/29139#issuecomment-832202303

Comment:
Also the kernel should be `python_version=3` by now, I think?

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR REVIEW] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (12 preceding siblings ...)
  2021-05-04 19:53 ` ericonr
@ 2021-05-06 10:10 ` Piraty
  2021-05-06 10:10 ` Piraty
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-05-06 10:10 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 184 bytes --]

New review comment by Piraty on void-packages repository

https://github.com/void-linux/void-packages/pull/29139#discussion_r627287629

Comment:
let's fix this in another patch maybe?

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR REVIEW] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (13 preceding siblings ...)
  2021-05-06 10:10 ` [PR REVIEW] " Piraty
@ 2021-05-06 10:10 ` Piraty
  2021-05-06 10:11 ` [PR PATCH] [Updated] " Piraty
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-05-06 10:10 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 218 bytes --]

New review comment by Piraty on void-packages repository

https://github.com/void-linux/void-packages/pull/29139#discussion_r627287629

Comment:
let's fix this in another patch maybe (or even kernel build style soon)?

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR PATCH] [Updated] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (14 preceding siblings ...)
  2021-05-06 10:10 ` Piraty
@ 2021-05-06 10:11 ` Piraty
  2021-05-06 14:02 ` Piraty
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-05-06 10:11 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1625 bytes --]

There is an updated pull request by Piraty against master on the void-packages repository

https://github.com/Piraty/void-packages rpi-kernel-split
https://github.com/void-linux/void-packages/pull/29139

[NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
This is my second approach to the rpi4 problem (first try: https://github.com/void-linux/void-packages/pull/26000)

The problem is: how to not break existing systems while having a consistent naming scheme for rpi-kernel / rpi-base.

As ~demanded~ suggested by @the-maldridge , `rpi-kernel` continues to provide the kernel for rpi0/rpi1 and becomes a meta package that pulls `rpi{2,3}-kernel` (based on target arch) so legacy pull the new update systems.
This may be optional though and we could require users to manually install the new kernel package, possibly posting a new post on the website for that.

To support legacy systems, rpi-base is split into rpiN-base which all ship the same udev rule and depend on the respective kernel. This (still) allows to have a single entry-point to raspberry related packages.

I performed (offline) testing of the package transition process, seems fine. Script [here](https://gist.github.com/Piraty/2b0bd709c58ca2e8dd2240cc5b1141c9)


### How to
1. checkout this branch
2. build one of `rpi4-base` (aarch64*) or `rpi-base` (`armv6*`, `armv7l*` or `aarch64*`)
3. update your pi with the new packages or build fresh images: see https://github.com/void-linux/void-mklive/pull/153

---

@pbui @Duncaen @ahesford 

A patch file from https://github.com/void-linux/void-packages/pull/29139.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-rpi-kernel-split-29139.patch --]
[-- Type: text/x-diff, Size: 34886 bytes --]

From f9e42cf3126608464402c60abd247a00c3393cda Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:00 +0100
Subject: [PATCH 1/4] rpi-kernel: split into rpi, rpi2, rpi3

Until now, rpi-kernel served rpi0/rpi1 + rpi2 + rpi3 all at once.  The
variants were solely distiguished by the target architecture; it was
nice while it lasted, but now that rpi4 is on its way, we need to split
things up a little.

With the split,
* rpi-kernel serves rpi0 + rpi1, armv6l* only
* rpi2-kernel serves rpi2, armv7l* only
* rpi3-kernel serves rpi3, aarch64* only

To help migrate existing devices to the new kernel packages, rpi-kernel
will be an empty mega package for !armv6l* and depend on rpi2-kernel or
rpi3-kernel (depending on target architecture) for the foreseeable
future, thus resolving like this:
* rpi-kernel -> rpi2-kernel (armv7l*)
* rpi-kernel -> rpi3-kernel (aarch64*)
---
 srcpkgs/rpi-kernel/template  |  57 +++++---
 srcpkgs/rpi2-kernel-headers  |   1 +
 srcpkgs/rpi2-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 srcpkgs/rpi3-kernel-headers  |   1 +
 srcpkgs/rpi3-kernel/template | 250 +++++++++++++++++++++++++++++++++++
 5 files changed, 541 insertions(+), 18 deletions(-)
 create mode 120000 srcpkgs/rpi2-kernel-headers
 create mode 100644 srcpkgs/rpi2-kernel/template
 create mode 120000 srcpkgs/rpi3-kernel-headers
 create mode 100644 srcpkgs/rpi3-kernel/template

diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index 1fe4e2477e1f..03b9c1d22016 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -10,15 +10,18 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi-kernel
 version=5.4.83
-revision=1
+revision=2
+archs="armv6l*"
 wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
 license="GPL-2.0-only"
-short_desc="The Linux kernel for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+short_desc="Linux kernel for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
 distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
 checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
-python_version=2
+python_version=3
 
 _kernver="${version}_${revision}"
 
@@ -27,10 +30,6 @@ nostrip=yes
 noverifyrdeps=yes
 noshlibprovides=yes
 
-# RPi, RPi2, RPi3
-archs="armv6l* armv7l* aarch64*"
-hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
-makedepends="ncurses-devel"
 triggers="kernel-hooks"
 # These files could be modified when an external module is built.
 mutable_files="
@@ -62,15 +61,6 @@ do_configure() {
 
 	# Use upstream's default configuration, no need to maintain ours.
 	case "$XBPS_TARGET_MACHINE" in
-		# RPi3
-		aarch64*)
-			target=bcmrpi3_defconfig
-			;;
-		# RPi2 / RPi3
-		armv7l*)
-			target=bcm2709_defconfig
-			;;
-		# RPi1
 		armv6l*)
 			target=bcmrpi_defconfig
 			;;
@@ -81,7 +71,7 @@ do_configure() {
 	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
 	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
 	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
-	
+
 	# IR Remote Support
 	echo "CONFIG_RC_CORE=y" >> "$defconfig"
 	echo "CONFIG_LIRC=y" >> "$defconfig"
@@ -252,9 +242,40 @@ rpi-kernel-headers_package() {
 	nostrip=yes
 	noverifyrdeps=yes
 	noshlibprovides=yes
-	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	short_desc="${short_desc/kernel/kernel headers}"
 	pkg_install() {
 		vmove usr/src
 		vmove usr/lib/modules/${_kernver}/build
 	}
 }
+
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi{$n}-kernel package
+archs+=" armv7l* aarch64*"
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc="Linux kernel for Raspberry Pi (transitional dummy package)"
+
+		pre_configure() { : ; }
+		do_configure() { : ; }
+		do_build() { : ; }
+		do_install() { : ; }
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends=rpi2-kernel ;;
+			aarch64*) depends=rpi3-kernel ;;
+		esac
+
+		rpi-kernel-headers_package() {
+			build_style=meta
+			short_desc="Linux kernel headers for Raspberry Pi (transitional dummy package)"
+			case "$XBPS_TARGET_MACHINE" in
+				armv7*) depends=rpi2-kernel-headers ;;
+				aarch64*) depends=rpi3-kernel-headers ;;
+			esac
+		}
+		;;
+esac
diff --git a/srcpkgs/rpi2-kernel-headers b/srcpkgs/rpi2-kernel-headers
new file mode 120000
index 000000000000..fbe6d91aeb7f
--- /dev/null
+++ b/srcpkgs/rpi2-kernel-headers
@@ -0,0 +1 @@
+rpi2-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
new file mode 100644
index 000000000000..bac599777248
--- /dev/null
+++ b/srcpkgs/rpi2-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi2-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi2-kernel
+version=5.4.83
+revision=2
+archs="armv7l*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="Linux kernel for Raspberry Pi 2 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=3
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		armv7l*)
+			target=bcm2709_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi2-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}
diff --git a/srcpkgs/rpi3-kernel-headers b/srcpkgs/rpi3-kernel-headers
new file mode 120000
index 000000000000..29e9f333d668
--- /dev/null
+++ b/srcpkgs/rpi3-kernel-headers
@@ -0,0 +1 @@
+rpi3-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
new file mode 100644
index 000000000000..0ae2d8366926
--- /dev/null
+++ b/srcpkgs/rpi3-kernel/template
@@ -0,0 +1,250 @@
+# Template file for 'rpi3-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi3-kernel
+version=5.4.83
+revision=2
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="Linux kernel for Raspberry Pi 3 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=3
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcmrpi3_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/*dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi3-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From fac6b94f483778bb765b577cfefe8bc2597af2e1 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:09 +0100
Subject: [PATCH 2/4] rpi-base: split into rpi, rpi2, rpi3

Until now, rpi-base served rpi0/rpi1 + rpi2 + rpi3 all at once.  The
variants were solely distiguished by the target architecture; it was
nice while it lasted, but now that rpi4 is on its way, we need to split
things up a little.

With the split,
* rpi-base depends on rpi-kernel, armv6l* only,
* rpi2-base depends on rpi2-kernel, armv7l* only
* rpi3-base depends on rpi3-kernel, aarch64* only,

To help migrate existing devices to the new base packages, rpi-base
will be an empty mega package for !armv6l* and depend on rpi2-base or
rpi3-base for the foreseeable future, thus resolving like this:
* rpi-base -> rpi2-base (armv7l*)
* rpi-base -> rpi3-base (aarch64*)

For now it's sufficient to have one package provide all subpackages, to
ease maintainance. The template can easiliy be split (as we did with
rpi-kernel) should the need arise some day.

rpi3-base actually existed back in 2017 (it depended on mainline kernel
instead of rpi-kernel) and became obsolete in 2018;
who would have known back then we may have to deal with rpi>3 some day...
---
 srcpkgs/rpi-base/template | 51 +++++++++++++++++++++++++++++++++++++--
 srcpkgs/rpi2-base         |  1 +
 srcpkgs/rpi3-base         |  1 +
 3 files changed, 51 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi2-base
 create mode 120000 srcpkgs/rpi3-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index 8fcf3581efd9..cbe8e79526f4 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,9 +1,10 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
-version=2.6
+version=3.0
 revision=1
 archs="armv6l* armv7l* aarch64*"
-depends="virtual?ntp-daemon rpi-firmware rpi-kernel"
+_base_depends="virtual?ntp-daemon rpi-firmware"
+depends="${_base_depends} rpi-kernel"
 short_desc="Void Linux Raspberry Pi base files"
 maintainer="Orphaned <orphan@voidlinux.org>"
 license="Public Domain"
@@ -12,3 +13,49 @@ homepage="https://www.voidlinux.org"
 do_install() {
 	vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 }
+
+case "$XBPS_TARGET_MACHINE" in
+	armv6*)
+		subpackages=" "
+		;;
+	armv7*)
+		subpackages="rpi2-base"
+		;;
+	aarch64*)
+		subpackages="rpi3-base"
+		;;
+esac
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi${n}-base package
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc+=" (transitional dummy package)"
+
+	 	do_install() { : ; }
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends="rpi2-base" ;;
+			aarch64*) depends="rpi3-base" ;;
+		esac
+		;;
+esac
+
+rpi2-base_package() {
+	depends="${_base_depends} rpi2-kernel"
+	short_desc="Void Linux Raspberry Pi 2 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
+
+
+rpi3-base_package() {
+	depends="${_base_depends} rpi3-kernel"
+	short_desc="Void Linux Raspberry Pi 3 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi2-base b/srcpkgs/rpi2-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi2-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi3-base b/srcpkgs/rpi3-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi3-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

From b3ca146c6a7322d3c11c2f17382d559802100225 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:52:49 +0100
Subject: [PATCH 3/4] New package: rpi4-kernel-5.4.83

---
 srcpkgs/rpi4-kernel-headers  |   1 +
 srcpkgs/rpi4-kernel/template | 251 +++++++++++++++++++++++++++++++++++
 2 files changed, 252 insertions(+)
 create mode 120000 srcpkgs/rpi4-kernel-headers
 create mode 100644 srcpkgs/rpi4-kernel/template

diff --git a/srcpkgs/rpi4-kernel-headers b/srcpkgs/rpi4-kernel-headers
new file mode 120000
index 000000000000..9c2fad143506
--- /dev/null
+++ b/srcpkgs/rpi4-kernel-headers
@@ -0,0 +1 @@
+rpi4-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi4-kernel/template b/srcpkgs/rpi4-kernel/template
new file mode 100644
index 000000000000..9e529964c4f5
--- /dev/null
+++ b/srcpkgs/rpi4-kernel/template
@@ -0,0 +1,251 @@
+# Template file for 'rpi4-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi4-kernel
+version=5.4.83
+revision=1
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="Linux kernel for Raspberry Pi 4 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+conflicts=rpi3-kernel
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcm2711_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		mv ${DESTDIR}/boot/broadcom/*dtb ${DESTDIR}/boot
+		;;
+	esac
+
+	vmkdir boot
+	# Generate kernel.img and install it to destdir.
+	case "$XBPS_TARGET_MACHINE" in
+	aarch64*)
+		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+		;;
+	armv7l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+		;;
+	armv6l*)
+		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
+		;;
+	esac
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi4-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From b0da819900ee722c5199983458cceb4ff502819b Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:56:40 +0100
Subject: [PATCH 4/4] rpi-base: add rpi4

---
 srcpkgs/rpi-base/template    | 13 +++++++++++--
 srcpkgs/rpi4-base            |  1 +
 srcpkgs/rpi4-kernel/template |  2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)
 create mode 120000 srcpkgs/rpi4-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index cbe8e79526f4..8940033c83ab 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,7 +1,7 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
 version=3.0
-revision=1
+revision=2
 archs="armv6l* armv7l* aarch64*"
 _base_depends="virtual?ntp-daemon rpi-firmware"
 depends="${_base_depends} rpi-kernel"
@@ -22,7 +22,7 @@ case "$XBPS_TARGET_MACHINE" in
 		subpackages="rpi2-base"
 		;;
 	aarch64*)
-		subpackages="rpi3-base"
+		subpackages="rpi3-base rpi4-base"
 		;;
 esac
 
@@ -59,3 +59,12 @@ rpi3-base_package() {
 		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 	}
 }
+
+rpi4-base_package() {
+	depends="${_base_depends} rpi4-kernel"
+	short_desc="Void Linux Raspberry Pi 4 base files"
+	conflicts="rpi3-base"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi4-base b/srcpkgs/rpi4-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi4-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi4-kernel/template b/srcpkgs/rpi4-kernel/template
index 9e529964c4f5..8f8168a1a7ca 100644
--- a/srcpkgs/rpi4-kernel/template
+++ b/srcpkgs/rpi4-kernel/template
@@ -21,7 +21,7 @@ license="GPL-2.0-only"
 short_desc="Linux kernel for Raspberry Pi 4 (${version%.*} series [git ${_gitshort}])"
 distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
 checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
-python_version=2
+python_version=3
 conflicts=rpi3-kernel
 
 _kernver="${version}_${revision}"

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR PATCH] [Updated] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (15 preceding siblings ...)
  2021-05-06 10:11 ` [PR PATCH] [Updated] " Piraty
@ 2021-05-06 14:02 ` Piraty
  2021-05-06 17:45 ` Duncaen
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-05-06 14:02 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1625 bytes --]

There is an updated pull request by Piraty against master on the void-packages repository

https://github.com/Piraty/void-packages rpi-kernel-split
https://github.com/void-linux/void-packages/pull/29139

[NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
This is my second approach to the rpi4 problem (first try: https://github.com/void-linux/void-packages/pull/26000)

The problem is: how to not break existing systems while having a consistent naming scheme for rpi-kernel / rpi-base.

As ~demanded~ suggested by @the-maldridge , `rpi-kernel` continues to provide the kernel for rpi0/rpi1 and becomes a meta package that pulls `rpi{2,3}-kernel` (based on target arch) so legacy pull the new update systems.
This may be optional though and we could require users to manually install the new kernel package, possibly posting a new post on the website for that.

To support legacy systems, rpi-base is split into rpiN-base which all ship the same udev rule and depend on the respective kernel. This (still) allows to have a single entry-point to raspberry related packages.

I performed (offline) testing of the package transition process, seems fine. Script [here](https://gist.github.com/Piraty/2b0bd709c58ca2e8dd2240cc5b1141c9)


### How to
1. checkout this branch
2. build one of `rpi4-base` (aarch64*) or `rpi-base` (`armv6*`, `armv7l*` or `aarch64*`)
3. update your pi with the new packages or build fresh images: see https://github.com/void-linux/void-mklive/pull/153

---

@pbui @Duncaen @ahesford 

A patch file from https://github.com/void-linux/void-packages/pull/29139.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-rpi-kernel-split-29139.patch --]
[-- Type: text/x-diff, Size: 34767 bytes --]

From 212f5d462c766851931ac32d9fde790519548d18 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:00 +0100
Subject: [PATCH 1/4] rpi-kernel: split into rpi, rpi2, rpi3

Until now, rpi-kernel served rpi0/rpi1 + rpi2 + rpi3 all at once.  The
variants were solely distiguished by the target architecture; it was
nice while it lasted, but now that rpi4 is on its way, we need to split
things up a little.

With the split,
* rpi-kernel serves rpi0 + rpi1, armv6l* only
* rpi2-kernel serves rpi2, armv7l* only
* rpi3-kernel serves rpi3, aarch64* only

To help migrate existing devices to the new kernel packages, rpi-kernel
will be an empty mega package for !armv6l* and depend on rpi2-kernel or
rpi3-kernel (depending on target architecture) for the foreseeable
future, thus resolving like this:
* rpi-kernel -> rpi2-kernel (armv7l*)
* rpi-kernel -> rpi3-kernel (aarch64*)
---
 srcpkgs/rpi-kernel/template  |  78 ++++++------
 srcpkgs/rpi2-kernel-headers  |   1 +
 srcpkgs/rpi2-kernel/template | 233 ++++++++++++++++++++++++++++++++++
 srcpkgs/rpi3-kernel-headers  |   1 +
 srcpkgs/rpi3-kernel/template | 236 +++++++++++++++++++++++++++++++++++
 5 files changed, 512 insertions(+), 37 deletions(-)
 create mode 120000 srcpkgs/rpi2-kernel-headers
 create mode 100644 srcpkgs/rpi2-kernel/template
 create mode 120000 srcpkgs/rpi3-kernel-headers
 create mode 100644 srcpkgs/rpi3-kernel/template

diff --git a/srcpkgs/rpi-kernel/template b/srcpkgs/rpi-kernel/template
index 1fe4e2477e1f..8067f5d7ab7f 100644
--- a/srcpkgs/rpi-kernel/template
+++ b/srcpkgs/rpi-kernel/template
@@ -10,15 +10,18 @@ _gitshort="${_githash:0:7}"
 
 pkgname=rpi-kernel
 version=5.4.83
-revision=1
+revision=2
+archs="armv6l*"
 wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
 maintainer="Piraty <piraty1@inbox.ru>"
 homepage="http://www.kernel.org"
 license="GPL-2.0-only"
-short_desc="The Linux kernel for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+short_desc="Linux kernel for Raspberry Pi zero/1 (${version%.*} series [git ${_gitshort}])"
 distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
 checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
-python_version=2
+python_version=3
 
 _kernver="${version}_${revision}"
 
@@ -27,10 +30,6 @@ nostrip=yes
 noverifyrdeps=yes
 noshlibprovides=yes
 
-# RPi, RPi2, RPi3
-archs="armv6l* armv7l* aarch64*"
-hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
-makedepends="ncurses-devel"
 triggers="kernel-hooks"
 # These files could be modified when an external module is built.
 mutable_files="
@@ -62,15 +61,6 @@ do_configure() {
 
 	# Use upstream's default configuration, no need to maintain ours.
 	case "$XBPS_TARGET_MACHINE" in
-		# RPi3
-		aarch64*)
-			target=bcmrpi3_defconfig
-			;;
-		# RPi2 / RPi3
-		armv7l*)
-			target=bcm2709_defconfig
-			;;
-		# RPi1
 		armv6l*)
 			target=bcmrpi_defconfig
 			;;
@@ -81,7 +71,7 @@ do_configure() {
 	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
 	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
 	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
-	
+
 	# IR Remote Support
 	echo "CONFIG_RC_CORE=y" >> "$defconfig"
 	echo "CONFIG_LIRC=y" >> "$defconfig"
@@ -128,26 +118,9 @@ do_install() {
 	# Install device tree blobs
 	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
 
-	# move dtb that ended up in /boot/broadcom
-	case "$XBPS_TARGET_MACHINE" in
-	aarch64*)
-		mv ${DESTDIR}/boot/broadcom/bcm{2710,2837}-*.dtb ${DESTDIR}/boot
-		;;
-	esac
-
-	vmkdir boot
 	# Generate kernel.img and install it to destdir.
-	case "$XBPS_TARGET_MACHINE" in
-	aarch64*)
-		cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
-		;;
-	armv7l*)
-		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
-		;;
-	armv6l*)
-		cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
-		;;
-	esac
+	vmkdir boot
+	cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel.img
 
 	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
 
@@ -252,9 +225,40 @@ rpi-kernel-headers_package() {
 	nostrip=yes
 	noverifyrdeps=yes
 	noshlibprovides=yes
-	short_desc="The Linux kernel headers for Raspberry Pi (${version%.*} series [git ${_gitshort}])"
+	short_desc="${short_desc/kernel/kernel headers}"
 	pkg_install() {
 		vmove usr/src
 		vmove usr/lib/modules/${_kernver}/build
 	}
 }
+
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi{$n}-kernel package
+archs+=" armv7l* aarch64*"
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc="Linux kernel for Raspberry Pi (transitional dummy package)"
+
+		pre_configure() { : ; }
+		do_configure() { : ; }
+		do_build() { : ; }
+		do_install() { : ; }
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends=rpi2-kernel ;;
+			aarch64*) depends=rpi3-kernel ;;
+		esac
+
+		rpi-kernel-headers_package() {
+			build_style=meta
+			short_desc="Linux kernel headers for Raspberry Pi (transitional dummy package)"
+			case "$XBPS_TARGET_MACHINE" in
+				armv7*) depends=rpi2-kernel-headers ;;
+				aarch64*) depends=rpi3-kernel-headers ;;
+			esac
+		}
+		;;
+esac
diff --git a/srcpkgs/rpi2-kernel-headers b/srcpkgs/rpi2-kernel-headers
new file mode 120000
index 000000000000..fbe6d91aeb7f
--- /dev/null
+++ b/srcpkgs/rpi2-kernel-headers
@@ -0,0 +1 @@
+rpi2-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi2-kernel/template b/srcpkgs/rpi2-kernel/template
new file mode 100644
index 000000000000..cda240234550
--- /dev/null
+++ b/srcpkgs/rpi2-kernel/template
@@ -0,0 +1,233 @@
+# Template file for 'rpi2-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi2-kernel
+version=5.4.83
+revision=2
+archs="armv7l*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="Linux kernel for Raspberry Pi 2 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=3
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		armv7l*)
+			target=bcm2709_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# Generate kernel.img and install it to destdir.
+	vmkdir boot
+	cp arch/arm/boot/zImage ${DESTDIR}/boot/kernel7.img
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi2-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}
diff --git a/srcpkgs/rpi3-kernel-headers b/srcpkgs/rpi3-kernel-headers
new file mode 120000
index 000000000000..29e9f333d668
--- /dev/null
+++ b/srcpkgs/rpi3-kernel-headers
@@ -0,0 +1 @@
+rpi3-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi3-kernel/template b/srcpkgs/rpi3-kernel/template
new file mode 100644
index 000000000000..a3a16bc577fc
--- /dev/null
+++ b/srcpkgs/rpi3-kernel/template
@@ -0,0 +1,236 @@
+# Template file for 'rpi3-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi3-kernel
+version=5.4.83
+revision=2
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="Linux kernel for Raspberry Pi 3 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=3
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcmrpi3_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	mv ${DESTDIR}/boot/broadcom/*dtb ${DESTDIR}/boot
+
+	# Generate kernel.img and install it to destdir.
+	vmkdir boot
+	cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi3-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From 779aee2c0526101318b39c717bcad8cc5e12e1ab Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Mon, 22 Feb 2021 21:35:09 +0100
Subject: [PATCH 2/4] rpi-base: split into rpi, rpi2, rpi3

Until now, rpi-base served rpi0/rpi1 + rpi2 + rpi3 all at once.  The
variants were solely distiguished by the target architecture; it was
nice while it lasted, but now that rpi4 is on its way, we need to split
things up a little.

With the split,
* rpi-base depends on rpi-kernel, armv6l* only,
* rpi2-base depends on rpi2-kernel, armv7l* only
* rpi3-base depends on rpi3-kernel, aarch64* only,

To help migrate existing devices to the new base packages, rpi-base
will be an empty mega package for !armv6l* and depend on rpi2-base or
rpi3-base for the foreseeable future, thus resolving like this:
* rpi-base -> rpi2-base (armv7l*)
* rpi-base -> rpi3-base (aarch64*)

For now it's sufficient to have one package provide all subpackages, to
ease maintainance. The template can easiliy be split (as we did with
rpi-kernel) should the need arise some day.

rpi3-base actually existed back in 2017 (it depended on mainline kernel
instead of rpi-kernel) and became obsolete in 2018;
who would have known back then we may have to deal with rpi>3 some day...
---
 srcpkgs/rpi-base/template | 51 +++++++++++++++++++++++++++++++++++++--
 srcpkgs/rpi2-base         |  1 +
 srcpkgs/rpi3-base         |  1 +
 3 files changed, 51 insertions(+), 2 deletions(-)
 create mode 120000 srcpkgs/rpi2-base
 create mode 120000 srcpkgs/rpi3-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index 8fcf3581efd9..cbe8e79526f4 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,9 +1,10 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
-version=2.6
+version=3.0
 revision=1
 archs="armv6l* armv7l* aarch64*"
-depends="virtual?ntp-daemon rpi-firmware rpi-kernel"
+_base_depends="virtual?ntp-daemon rpi-firmware"
+depends="${_base_depends} rpi-kernel"
 short_desc="Void Linux Raspberry Pi base files"
 maintainer="Orphaned <orphan@voidlinux.org>"
 license="Public Domain"
@@ -12,3 +13,49 @@ homepage="https://www.voidlinux.org"
 do_install() {
 	vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 }
+
+case "$XBPS_TARGET_MACHINE" in
+	armv6*)
+		subpackages=" "
+		;;
+	armv7*)
+		subpackages="rpi2-base"
+		;;
+	aarch64*)
+		subpackages="rpi3-base"
+		;;
+esac
+
+# support legacy systems (before rpi-kernel was split to rpi{,2,3})
+# archs != armv6* are emtpy meta packages to pull the new rpi${n}-base package
+case "$XBPS_TARGET_MACHINE" in
+	armv6*) : ;;
+	*)
+		build_style=meta
+		short_desc+=" (transitional dummy package)"
+
+	 	do_install() { : ; }
+
+		case "$XBPS_TARGET_MACHINE" in
+			armv7*) depends="rpi2-base" ;;
+			aarch64*) depends="rpi3-base" ;;
+		esac
+		;;
+esac
+
+rpi2-base_package() {
+	depends="${_base_depends} rpi2-kernel"
+	short_desc="Void Linux Raspberry Pi 2 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
+
+
+rpi3-base_package() {
+	depends="${_base_depends} rpi3-kernel"
+	short_desc="Void Linux Raspberry Pi 3 base files"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi2-base b/srcpkgs/rpi2-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi2-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi3-base b/srcpkgs/rpi3-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi3-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file

From e9d0f663d4d93e5f1a63970f724a86a136d2539e Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:52:49 +0100
Subject: [PATCH 3/4] New package: rpi4-kernel-5.4.83

---
 srcpkgs/rpi4-kernel-headers  |   1 +
 srcpkgs/rpi4-kernel/template | 237 +++++++++++++++++++++++++++++++++++
 2 files changed, 238 insertions(+)
 create mode 120000 srcpkgs/rpi4-kernel-headers
 create mode 100644 srcpkgs/rpi4-kernel/template

diff --git a/srcpkgs/rpi4-kernel-headers b/srcpkgs/rpi4-kernel-headers
new file mode 120000
index 000000000000..9c2fad143506
--- /dev/null
+++ b/srcpkgs/rpi4-kernel-headers
@@ -0,0 +1 @@
+rpi4-kernel
\ No newline at end of file
diff --git a/srcpkgs/rpi4-kernel/template b/srcpkgs/rpi4-kernel/template
new file mode 100644
index 000000000000..b69cd945758d
--- /dev/null
+++ b/srcpkgs/rpi4-kernel/template
@@ -0,0 +1,237 @@
+# Template file for 'rpi4-kernel'
+#
+# We track the latest Raspberry Pi LTS kernel as that is what is used in the
+# official Raspbian distribution. This is currently 5.4:
+#
+#   https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769
+
+_githash="76c49e60e742d0bebd798be972d67dd3fd007691"
+_gitshort="${_githash:0:7}"
+
+pkgname=rpi4-kernel
+version=5.4.83
+revision=1
+archs="aarch64*"
+wrksrc="linux-${_githash}"
+hostmakedepends="perl kmod uboot-mkimage openssl-devel bc bison flex"
+makedepends="ncurses-devel"
+maintainer="Piraty <piraty1@inbox.ru>"
+homepage="http://www.kernel.org"
+license="GPL-2.0-only"
+short_desc="Linux kernel for Raspberry Pi 4 (${version%.*} series [git ${_gitshort}])"
+distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
+checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
+python_version=2
+conflicts=rpi3-kernel
+
+_kernver="${version}_${revision}"
+
+nodebug=yes
+nostrip=yes
+noverifyrdeps=yes
+noshlibprovides=yes
+
+triggers="kernel-hooks"
+# These files could be modified when an external module is built.
+mutable_files="
+	/usr/lib/modules/${_kernver}/modules.dep
+	/usr/lib/modules/${_kernver}/modules.dep.bin
+	/usr/lib/modules/${_kernver}/modules.symbols
+	/usr/lib/modules/${_kernver}/modules.symbols.bin
+	/usr/lib/modules/${_kernver}/modules.alias
+	/usr/lib/modules/${_kernver}/modules.alias.bin
+	/usr/lib/modules/${_kernver}/modules.devname"
+
+_arch=
+case "$XBPS_TARGET_MACHINE" in
+	arm*) _arch=arm ;;
+	aarch64*) _arch=arm64 ;;
+esac
+_cross=
+if [ "$CROSS_BUILD" ]; then
+	_cross="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
+fi
+
+pre_configure() {
+	# Remove .git directory, otherwise scripts/setkernelversion.sh
+	# modifies KERNELRELEASE and appends + to it.
+	rm -rf .git
+}
+do_configure() {
+	local target defconfig
+
+	# Use upstream's default configuration, no need to maintain ours.
+	case "$XBPS_TARGET_MACHINE" in
+		aarch64*)
+			target=bcm2711_defconfig
+			;;
+	esac
+
+	defconfig="arch/${_arch}/configs/${target}"
+	echo "CONFIG_CONNECTOR=y" >> "$defconfig"
+	echo "CONFIG_PROC_EVENTS=y" >> "$defconfig"
+	echo "CONFIG_F2FS_FS_SECURITY=y" >> "$defconfig"
+	echo "CONFIG_CGROUP_PIDS=y" >> "$defconfig"
+
+	# IR Remote Support
+	echo "CONFIG_RC_CORE=y" >> "$defconfig"
+	echo "CONFIG_LIRC=y" >> "$defconfig"
+	echo "CONFIG_RC_DECODERS=y" >> "$defconfig"
+	echo "CONFIG_RC_DEVICES=y" >> "$defconfig"
+	echo "CONFIG_IR_RC6_DECODER=m" >> "$defconfig"
+	echo "CONFIG_IR_MCEUSB=m" >> "$defconfig"
+
+	# HID Controllers
+	echo "CONFIG_HID_STEAM=y" >> "$defconfig"
+
+	# LXD 4.2+ support
+	echo "CONFIG_BRIDGE_VLAN_FILTERING=y" >> "$defconfig"
+
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+
+	# Always use our revision to CONFIG_LOCALVERSION to match our pkg version.
+	vsed -i -e "s|^\(CONFIG_LOCALVERSION=\).*|\1\"_${revision}\"|" .config
+}
+do_build() {
+	local target
+
+	case "$XBPS_TARGET_MACHINE" in
+		arm*)
+			target="zImage modules dtbs"
+			;;
+		aarch64*)
+			target="Image modules dtbs"
+			;;
+	esac
+
+	make ${makejobs} ${_cross} ARCH=${_arch} prepare
+	make ${makejobs} ${_cross} ARCH=${_arch} ${target}
+}
+do_install() {
+	local hdrdest
+
+	# Run depmod after compressing modules.
+	sed -i '2iexit 0' scripts/depmod.sh
+
+	# Install kernel, firmware and modules
+	make ${makejobs} ARCH=${_arch} INSTALL_MOD_PATH=${DESTDIR} modules_install
+
+	# Install device tree blobs
+	make ${makejobs} ARCH=${_arch} INSTALL_DTBS_PATH=${DESTDIR}/boot dtbs_install
+
+	# move dtb that ended up in /boot/broadcom
+	mv ${DESTDIR}/boot/broadcom/*dtb ${DESTDIR}/boot
+
+	# Generate kernel.img and install it to destdir.
+	vmkdir boot
+	cp arch/arm64/boot/Image ${DESTDIR}/boot/kernel8.img
+
+	hdrdest=${DESTDIR}/usr/src/${sourcepkg}-headers-${_kernver}
+
+	# Switch to /usr.
+	vmkdir usr
+	mv ${DESTDIR}/lib ${DESTDIR}/usr
+
+	cd ${DESTDIR}/usr/lib/modules/${_kernver}
+	rm -f source build
+	ln -sf ../../../src/${sourcepkg}-headers-${_kernver} build
+
+	cd ${wrksrc}
+	# Install required headers to build external modules
+	install -Dm644 Makefile ${hdrdest}/Makefile
+	install -Dm644 kernel/Makefile ${hdrdest}/kernel/Makefile
+	install -Dm644 .config ${hdrdest}/.config
+	for file in $(find . -name Kconfig\*); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	for file in $(find arch/${_arch} -name module.lds -o -name Kbuild.platforms -o -name Platform); do
+		mkdir -p ${hdrdest}/$(dirname $file)
+		install -Dm644 $file ${hdrdest}/${file}
+	done
+	mkdir -p ${hdrdest}/include
+
+	# Remove firmware stuff provided by the "linux-firmware" pkg.
+	rm -rf ${DESTDIR}/usr/lib/firmware
+
+	for i in acpi asm-generic clocksource config crypto drm generated linux \
+		math-emu media net pcmcia scsi sound trace uapi video xen; do
+		[ -d include/$i ] && cp -a include/$i ${hdrdest}/include
+	done
+
+	cd ${wrksrc}
+	# Remove helper binaries built for host,
+	# if generated files from the scripts/ directory need to be included,
+	# they need to be copied to ${hdrdest} before this step
+	if [ "$CROSS_BUILD" ]; then
+		make ${makejobs} ARCH=${_arch} _mrproper_scripts
+		# remove host specific objects as well
+		find scripts -name '*.o' -delete
+	fi
+
+	# Copy files necessary for later builds.
+	cp Module.symvers ${hdrdest}
+	cp -a scripts ${hdrdest}
+	mkdir -p ${hdrdest}/security/selinux
+	cp -a security/selinux/include ${hdrdest}/security/selinux
+	mkdir -p ${hdrdest}/tools/include
+	cp -a tools/include/tools ${hdrdest}/tools/include
+	if [ -d "arch/${_arch}/tools" ]; then
+		cp -a arch/${_arch}/tools ${hdrdest}/arch/${_arch}
+	fi
+
+	# copy arch includes for external modules
+	mkdir -p ${hdrdest}/arch/${_arch}
+	cp -a arch/${_arch}/include ${hdrdest}/arch/${_arch}
+
+	mkdir -p ${hdrdest}/arch/${_arch}/kernel
+	cp arch/${_arch}/Makefile ${hdrdest}/arch/${_arch}
+	cp arch/${_arch}/kernel/asm-offsets.s ${hdrdest}/arch/${_arch}/kernel
+	if [ "$_arch" = "arm64" ] ; then
+		cp -a arch/${_arch}/kernel/vdso ${hdrdest}/arch/${_arch}/kernel/
+	fi
+
+	# Add md headers
+	mkdir -p ${hdrdest}/drivers/md
+	cp drivers/md/*.h ${hdrdest}/drivers/md
+
+	# Add inotify.h
+	mkdir -p ${hdrdest}/include/linux
+	cp include/linux/inotify.h ${hdrdest}/include/linux
+
+	# Add wireless headers
+	mkdir -p ${hdrdest}/net/mac80211/
+	cp net/mac80211/*.h ${hdrdest}/net/mac80211
+
+	# add dvb headers for external modules
+	mkdir -p ${hdrdest}/include/config/dvb/
+	cp include/config/dvb/*.h ${hdrdest}/include/config/dvb/
+
+	# Remove unneeded architectures
+	# (save the correct one + Kconfig and delete all others)
+	mkdir -p arch-backup
+	cp -r ${hdrdest}/arch/${_arch} ${hdrdest}/arch/Kconfig arch-backup/
+	rm -rf ${hdrdest}/arch
+	mv arch-backup ${hdrdest}/arch
+	# Keep arch/x86/ras/Kconfig as it is needed by drivers/ras/Kconfig
+	mkdir -p ${hdrdest}/arch/x86/ras
+	cp -a arch/x86/ras/Kconfig ${hdrdest}/arch/x86/ras/Kconfig
+
+	# Compress all modules with xz to save a few MBs.
+	msg_normal "$pkgver: compressing kernel modules with gzip, please wait...\n"
+	find ${DESTDIR} -name '*.ko' | xargs -n1 -P0 gzip -9
+
+	# ... and run depmod again.
+	depmod -b ${DESTDIR}/usr -F System.map ${_kernver}
+}
+
+rpi4-kernel-headers_package() {
+	nostrip=yes
+	noverifyrdeps=yes
+	noshlibprovides=yes
+	short_desc="${short_desc/kernel/kernel headers}"
+	pkg_install() {
+		vmove usr/src
+		vmove usr/lib/modules/${_kernver}/build
+	}
+}

From b8bd028338da1a206c0e468f9e4dfbb17c5354e7 Mon Sep 17 00:00:00 2001
From: Piraty <piraty1@inbox.ru>
Date: Sun, 28 Feb 2021 19:56:40 +0100
Subject: [PATCH 4/4] rpi-base: add rpi4

---
 srcpkgs/rpi-base/template    | 13 +++++++++++--
 srcpkgs/rpi4-base            |  1 +
 srcpkgs/rpi4-kernel/template |  2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)
 create mode 120000 srcpkgs/rpi4-base

diff --git a/srcpkgs/rpi-base/template b/srcpkgs/rpi-base/template
index cbe8e79526f4..8940033c83ab 100644
--- a/srcpkgs/rpi-base/template
+++ b/srcpkgs/rpi-base/template
@@ -1,7 +1,7 @@
 # Template file for 'rpi-base'
 pkgname=rpi-base
 version=3.0
-revision=1
+revision=2
 archs="armv6l* armv7l* aarch64*"
 _base_depends="virtual?ntp-daemon rpi-firmware"
 depends="${_base_depends} rpi-kernel"
@@ -22,7 +22,7 @@ case "$XBPS_TARGET_MACHINE" in
 		subpackages="rpi2-base"
 		;;
 	aarch64*)
-		subpackages="rpi3-base"
+		subpackages="rpi3-base rpi4-base"
 		;;
 esac
 
@@ -59,3 +59,12 @@ rpi3-base_package() {
 		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
 	}
 }
+
+rpi4-base_package() {
+	depends="${_base_depends} rpi4-kernel"
+	short_desc="Void Linux Raspberry Pi 4 base files"
+	conflicts="rpi3-base"
+	pkg_install() {
+		vinstall "${FILESDIR}/71-raspberrypi.rules" 644 usr/lib/udev/rules.d
+	}
+}
diff --git a/srcpkgs/rpi4-base b/srcpkgs/rpi4-base
new file mode 120000
index 000000000000..c004915dfa8a
--- /dev/null
+++ b/srcpkgs/rpi4-base
@@ -0,0 +1 @@
+rpi-base
\ No newline at end of file
diff --git a/srcpkgs/rpi4-kernel/template b/srcpkgs/rpi4-kernel/template
index b69cd945758d..04fbb7d64bb4 100644
--- a/srcpkgs/rpi4-kernel/template
+++ b/srcpkgs/rpi4-kernel/template
@@ -21,7 +21,7 @@ license="GPL-2.0-only"
 short_desc="Linux kernel for Raspberry Pi 4 (${version%.*} series [git ${_gitshort}])"
 distfiles="https://github.com/raspberrypi/linux/archive/${_githash}.tar.gz"
 checksum=4a98ea0d68c6e74d479789c12fc97619c872cb2607ae87a881a9491c1c3fbc35
-python_version=2
+python_version=3
 conflicts=rpi3-kernel
 
 _kernver="${version}_${revision}"

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (16 preceding siblings ...)
  2021-05-06 14:02 ` Piraty
@ 2021-05-06 17:45 ` Duncaen
  2021-05-08 19:54 ` [PR PATCH] [Closed]: " Piraty
  2021-05-08 20:01 ` jsumners
  19 siblings, 0 replies; 21+ messages in thread
From: Duncaen @ 2021-05-06 17:45 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 229 bytes --]

New comment by Duncaen on void-packages repository

https://github.com/void-linux/void-packages/pull/29139#issuecomment-833729813

Comment:
rpi2 upgraded fine too: https://gist.github.com/Duncaen/e6ee8a5b4cf3afdd7be14682f01dfe5e

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PR PATCH] [Closed]: rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (17 preceding siblings ...)
  2021-05-06 17:45 ` Duncaen
@ 2021-05-08 19:54 ` Piraty
  2021-05-08 20:01 ` jsumners
  19 siblings, 0 replies; 21+ messages in thread
From: Piraty @ 2021-05-08 19:54 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1452 bytes --]

There's a closed pull request on the void-packages repository

rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
https://github.com/void-linux/void-packages/pull/29139

Description:
This is my second approach to the rpi4 problem (first try: https://github.com/void-linux/void-packages/pull/26000)

The problem is: how to not break existing systems while having a consistent naming scheme for rpi-kernel / rpi-base.

As ~demanded~ suggested by @the-maldridge , `rpi-kernel` continues to provide the kernel for rpi0/rpi1 and becomes a meta package that pulls `rpi{2,3}-kernel` (based on target arch) so legacy pull the new update systems.
This may be optional though and we could require users to manually install the new kernel package, possibly posting a new post on the website for that.

To support legacy systems, rpi-base is split into rpiN-base which all ship the same udev rule and depend on the respective kernel. This (still) allows to have a single entry-point to raspberry related packages.

I performed (offline) testing of the package transition process, seems fine. Script [here](https://gist.github.com/Piraty/2b0bd709c58ca2e8dd2240cc5b1141c9)


### How to
1. checkout this branch
2. build one of `rpi4-base` (aarch64*) or `rpi-base` (`armv6*`, `armv7l*` or `aarch64*`)
3. update your pi with the new packages or build fresh images: see https://github.com/void-linux/void-mklive/pull/153

---

@pbui @Duncaen @ahesford 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: rpi-kernel: split into rpi, rpi2, rpi3, add rpi4
  2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
                   ` (18 preceding siblings ...)
  2021-05-08 19:54 ` [PR PATCH] [Closed]: " Piraty
@ 2021-05-08 20:01 ` jsumners
  19 siblings, 0 replies; 21+ messages in thread
From: jsumners @ 2021-05-08 20:01 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 160 bytes --]

New comment by jsumners on void-packages repository

https://github.com/void-linux/void-packages/pull/29139#issuecomment-835492157

Comment:
Well done @Piraty 

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2021-05-08 20:01 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-28 21:35 [PR PATCH] [NOMERGE] rpi-kernel: split into rpi, rpi2, rpi3, add rpi4 Piraty
2021-02-28 22:10 ` the-maldridge
2021-03-01  1:29 ` ahesford
2021-03-01 11:03 ` Piraty
2021-04-25 18:53 ` [PR PATCH] [Updated] " Piraty
2021-04-25 19:27 ` Piraty
2021-04-27 19:34 ` Piraty
2021-04-27 20:04 ` Piraty
2021-04-28 21:11 ` Piraty
2021-05-04  9:09 ` Piraty
2021-05-04 19:32 ` Piraty
2021-05-04 19:36 ` [PR PATCH] [Updated] " Piraty
2021-05-04 19:53 ` [PR REVIEW] " ericonr
2021-05-04 19:53 ` ericonr
2021-05-06 10:10 ` [PR REVIEW] " Piraty
2021-05-06 10:10 ` Piraty
2021-05-06 10:11 ` [PR PATCH] [Updated] " Piraty
2021-05-06 14:02 ` Piraty
2021-05-06 17:45 ` Duncaen
2021-05-08 19:54 ` [PR PATCH] [Closed]: " Piraty
2021-05-08 20:01 ` jsumners

Github messages for voidlinux

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/voidlinux-github

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 voidlinux-github voidlinux-github/ http://inbox.vuxu.org/voidlinux-github \
		voidlinux-github@inbox.vuxu.org
	public-inbox-index voidlinux-github

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.github.voidlinux


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git