Skip to content

pmbootstrap init: Wizard for new port device- and linux-packages

postmarketOS Bot requested to merge feature/init-create-device-linux-aport into master

Created by: ollieparanoid

First PR for #688 (closed) (new kernel porting workflow)

  • adds pmbootstrap aportgen device-* and pmbootstrap aportgen linux-*
  • ask for confirmation when selecting a non-existing device
  • generate the packages directly from init
  • refactor aportgen code
  • fixed some easy things in the linux- APKBUILD (more to come in follow-up PRs!):
    • _repository variable as @MartijnBraam suggested
    • removed some unused variables
    • restructured it to be more clear
    • automatically fill out pkgname, pkgdesc, arch, _carch, _flavor
    • use zImage-dtb if present
    • renamed _hash to _commit
    • reduced long based on ... comment at the top
    • don't require the user to accept defaults anymore (the yes "" | thing)

How to test

  • pmbootstrap init, confirm that you want a new device and look at the resulting device- and linux- packages
  • pmbootstrap aportgen device-...
  • pmbootstrap aportgen linnux-...

How it looks like

[01:01:03] Target device (either an existing one, or a new one for porting).
[01:01:03] Available (31): asus-flo, asus-grouper, fairphone-fp2, htc-ace, htc-bravo, huawei-angler, huawei-y530, lg-d285, lg-d855, lg-dory, lg-hammerhead, lg-lenok, lg-mako, motorola-osprey, motorola-titan, nokia-rx51, oneplus-bacon, qemu-aarch64, qemu-amd64, qemu-vexpress, samsung-i9003, samsung-i9070, samsung-i9100, samsung-i9305, samsung-maguro, samsung-n7100, sony-amami, sony-aries, sony-castor-windy, sony-yuga, t2m-flame
[01:01:03] Device [samsung-i9100]: purism-librem5
[01:01:10] You are about to do a new device port for 'purism-librem5'.
[01:01:10] Continue? (y/n) [y]: y
[01:01:12] Device architecture (armhf/aarch64) [armhf]: aarch64
[01:01:16] Who produced the device (e.g. LG)?
[01:01:16] Manufacturer: Purism
[01:01:19] What is the official name (e.g. Google Nexus 5)?
[01:01:19] Name: Purism Librem 5
[01:01:24] Username [user]:
...

Resulting kernel APKBUILD (more changes to come in follow-up PRs, see #688 (closed) ):

# Kernel config based on: arch/arm64/configs/(CHANGEME!)

pkgname="linux-purism-librem5"
pkgver=3.x.x
pkgrel=0
pkgdesc="Purism Librem 5 kernel fork"
arch="aarch64"
_carch="arm64"
_flavor="purism-librem5"
url="https://kernel.org"
license="GPL2"
options="!strip !check !tracedeps"
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev"
HOSTCC="${CC:-gcc}"
HOSTCC="${HOSTCC#${CROSS_COMPILE}}"

# Source
_repository="(REPLACEME)"
_commit="ffffffffffffffffffffffffffffffffffffffff"
_config="config-${_flavor}.${arch}"
source="
	$pkgname-$_commit.tar.gz::https://github.com/LineageOS/${_repository}/archive/${_commit}.tar.gz
	$_config
	compiler-gcc6.h
	02_gpu-msm-fix-gcc5-compile.patch
"
ksrcdir="$srcdir/${_repository}-${_commit}"

prepare() {
	local _patch_failed=
	cd "$ksrcdir"

	# first apply patches in specified order
	for i in $source; do
		case $i in
		*.patch)
			msg "Applying $i..."
			if ! patch -s -p1 -N -i "$srcdir"/$i; then
				echo $i >>failed
				_patch_failed=1
			fi
			;;
		esac
	done

	if ! [ -z "$_patch_failed" ]; then
		error "The following patches failed:"
		cat failed
		return 1
	fi

	# gcc6 support
	cp -v "$srcdir/compiler-gcc6.h" "$ksrcdir/include/linux/"

	# Prepare kernel config ('yes ""' for kernels lacking olddefconfig)
	mkdir -p "$srcdir"/build
	cp "$srcdir"/$_config "$srcdir"/build/.config
	yes "" | make -C "$ksrcdir" O="$srcdir"/build ARCH="$_carch" \
		HOSTCC="$HOSTCC" oldconfig
}

menuconfig() {
	cd "$srcdir"/build
	make ARCH="$_carch" menuconfig
	cp .config "$startdir"/$_config
}

build() {
	cd "$srcdir"/build
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}

package() {
	# kernel.release
	install -D "$srcdir/build/include/config/kernel.release" \
		"$pkgdir/usr/share/kernel/$_flavor/kernel.release"

	# zImage or zImage-dtb
	cd "$srcdir/build/arch/$_carch/boot"
	_zimg="zImage-dtb"
	[ -e "$_zimg" ] || _zimg="zImage"
	install -Dm644 "$_zimg" "$pkgdir/boot/vmlinuz-$_flavor"
}

sha512sums="(run 'pmbootstrap checksum linux-purism-librem5' to fill)"

Merge request reports