pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363)

* As discussed in IRC/matrix, we're removing `linux-postmarketos-lts`
  for now. The kernel isn't used right now, and we save lots of
  maintenance effort with not updating it every week or so.
* new config option `"kernel"` with possible values:
  `"downstream", "mainline", "stable"` (downstream is always
  `linux-$devicename`)
* ask for the kernel during `pmbootstrap init` if the device package
  has kernel subpackages and install it in `_install.py`
* postmarketos-mkinitfs: display note instead of exit with error when
  the `deviceinfo_dtb` file is missing (because we expect it to be
  missing for downstream kernels)
* device-sony-amami:
  * add kernel subpackages for downstream, mainline
  * set `deviceinfo_dtb`
* device-qemu-amd64: add kernel subpackages for stable, lts, mainline
* test cases and test data for new functions
* test case that checks all aports for right usage of the feature:
  * don't mix specifying kernels in depends *and* subpackages
  * 1 kernel in depends is maximum
  * kernel subpackages must have a valid name
  * Test if devices packages reference at least one kernel
* Remove `_build_device_depends_note()` which informs the user that
  `--ignore-depends` can be used with device packages to avoid building
  the kernel. The idea was to make the transition easier after a change
  we did months ago, and now the kernel doesn't always get built before
  building the device package so it's not relevant anymore.
* pmb/chroot/other.py:
  * Add autoinstall=True to kernel_flavors_installed(). When the flag
    is set, the function makes sure that at least one kernel for the
    device is installed.
  * Remove kernel_flavor_autodetect() function, wherever it was used,
    it has been replaced with kernel_flavors_installed()[0].
* pmb.helpers.frontend.py: remove code to install at least one kernel,
  kernel_flavors_installed() takes care of that now.
This commit is contained in:
Oliver Smith 2018-04-03 23:50:09 +00:00 committed by GitHub
parent b7d4e2c11e
commit b66b5dcc34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 334 additions and 17042 deletions

View File

@ -1,14 +1,20 @@
pkgname=device-qemu-amd64
pkgver=1
pkgrel=16
pkgrel=17
pkgdesc="Simulated device in qemu with an x86 platform"
url="https://github.com/postmarketOS"
arch="noarch"
license="MIT"
# NOTE: 'pmbootstrap init' allows you to choose the mesa-dri-* package
depends="postmarketos-base linux-postmarketos-lts"
depends="postmarketos-base"
makedepends=""
subpackages="$pkgname-x11 $pkgname-weston"
subpackages="
$pkgname-x11
$pkgname-weston
$pkgname-kernel-stable:kernel_stable
$pkgname-kernel-mainline:kernel_mainline
"
source="deviceinfo weston.ini"
options="!check"
@ -29,5 +35,17 @@ weston() {
"$subpkgdir"/etc/xdg/weston/weston.ini
}
kernel_stable() {
pkgdesc="Stable for everyday usage (recommended)"
depends="linux-postmarketos-stable"
mkdir "$subpkgdir"
}
kernel_mainline() {
pkgdesc="Newest kernel features"
depends="linux-postmarketos-mainline"
mkdir "$subpkgdir"
}
sha512sums="eb12ff5fe6fe592661facd3f8c910e00752e963b2092f4d4062c4af67972249233d20d641355e03de17ab537f42617140ccb9c296c2dcfb6077785fa9eeb25fd deviceinfo
df0fe900693e5f176076c59f5379e56aaa96c3df16a4120448f15b71f530170730b43e5fe32733c40c118a00ca3581043231a062a8a1eb0a930bfbfbb6c52a47 weston.ini"

View File

@ -1,12 +1,12 @@
pkgname=device-qemu-vexpress
pkgver=1
pkgrel=19
pkgrel=20
pkgdesc="Simulated device in qemu with vexpress soc"
url="https://github.com/postmarketOS"
arch="noarch"
license="MIT"
# NOTE: 'pmbootstrap init' allows you to choose the mesa-dri-* package
depends="postmarketos-base linux-postmarketos-lts"
depends="postmarketos-base linux-postmarketos-stable"
makedepends=""
subpackages=""
source="deviceinfo"

View File

@ -1,14 +1,18 @@
pkgname=device-sony-amami
pkgver=1
pkgrel=19
pkgver=2
pkgrel=0
pkgdesc="Sony Xperia Z1 Compact"
url="https://github.com/postmarketOS"
arch="noarch"
license="MIT"
depends="postmarketos-base linux-sony-amami mkbootimg mdss-fb-init-hack mesa-dri-swrast"
depends="postmarketos-base mkbootimg mdss-fb-init-hack mesa-dri-swrast"
makedepends=""
install=""
subpackages="$pkgname-nonfree-firmware:nonfree_firmware"
subpackages="
$pkgname-kernel-downstream:kernel_downstream
$pkgname-kernel-mainline:kernel_mainline
$pkgname-nonfree-firmware:nonfree_firmware
"
source="deviceinfo 90-android-touch-dev.rules"
options="!check"
@ -19,11 +23,23 @@ package() {
"$pkgdir"/etc/udev/rules.d/90-android-touch-dev.rules
}
kernel_downstream() {
pkgdesc="Display and wifi works (see device table for details)"
depends="linux-sony-amami"
mkdir "$subpkgdir"
}
kernel_mainline() {
pkgdesc="For kernel development only (most features aren't working)"
depends="linux-postmarketos-mainline"
mkdir "$subpkgdir"
}
nonfree_firmware() {
pkgdesc="Wifi firmware"
depends="firmware-sony-amami"
mkdir "$subpkgdir"
}
sha512sums="cf674f3fa0506449aacf15c6389c1793d457cdf80e21637580db4f0d8003f49dfeb65e59732dba57d9a1ea474459debae2b19e0a4a12f4b5d4c6bfb9fed7eb34 deviceinfo
sha512sums="e6daf310a259483da1e1e8be66693dea876f8d1fa6db001c37035d913d7de6e5f1be4a40fae7dcaff404d1953b4c5a58b31d8e6b593b72b56b64ba78f859717c deviceinfo
8b6034c0338ab4c7d648f47983aad6da07e427e7dba47baabf85a1b3ddeeda47c8d7fbcd547a302c9a759b2943ee30d3e82c3b368d8582833a058e4671638a9e 90-android-touch-dev.rules"

View File

@ -7,7 +7,7 @@ deviceinfo_manufacturer="Sony"
deviceinfo_date=""
deviceinfo_keyboard="false"
deviceinfo_nonfree="????"
deviceinfo_dtb=""
deviceinfo_dtb="qcom-msm8974-sony-xperia-amami"
deviceinfo_modules_initfs=""
deviceinfo_external_storage="true"
deviceinfo_flash_method="fastboot"

View File

@ -1,198 +0,0 @@
_flavor=postmarketos-lts
_config="config-${_flavor}.${CARCH}"
pkgname=linux-${_flavor}
pkgver=4.14.29
case $pkgver in
*.*.*) _kernver=${pkgver%.*};;
*.*) _kernver=$pkgver;;
esac
pkgrel=0
arch="x86_64 armhf aarch64"
pkgdesc="Linux for pmOS supported chipsets (LTS)"
url="https://kernel.org/"
depends=""
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev file"
options="!strip !check !tracedeps"
install=
source="
https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-$_kernver.tar.xz
config-${_flavor}.armhf
config-${_flavor}.aarch64
config-${_flavor}.x86_64
"
if [ "${pkgver%.0}" = "$pkgver" ]; then
source="$source
https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/patch-$pkgver.xz"
fi
subpackages="$pkgname-dev"
license="GPL2"
_abi_release=${pkgver}
_carch=${CARCH}
case "$_carch" in
aarch64*) _carch="arm64" ;;
arm*) _carch="arm" ;;
ppc*) _carch="powerpc" ;;
s390*) _carch="s390" ;;
esac
HOSTCC="${CC:-gcc}"
HOSTCC="${HOSTCC#${CROSS_COMPILE}}"
ksrcdir="$srcdir/linux-$_kernver"
prepare() {
local _patch_failed=
cd "$ksrcdir"
if [ "$_kernver" != "$pkgver" ]; then
msg "Applying patch-$pkgver.xz"
unxz -c < "$srcdir"/patch-$pkgver.xz | patch -p1 -N
fi
# first apply patches in specified order
for i in $source; do
case $i in
*.patch)
msg "Applying $i..."
if ! patch -s -p1 -N -i "$srcdir"/$i; then
echo $i >>failed
_patch_failed=1
fi
;;
esac
done
if ! [ -z "$_patch_failed" ]; then
error "The following patches failed:"
cat failed
return 1
fi
mkdir -p "$srcdir"/build
cp -v "$srcdir"/$_config "$srcdir"/build/.config
make -C "$ksrcdir" O="$srcdir"/build ARCH="$_carch" HOSTCC="$HOSTCC" \
olddefconfig
}
# this is so we can do: 'abuild menuconfig' to reconfigure kernel
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" \
CFLAGS_MODULE=-fno-pic
}
package() {
cd "$srcdir/build/arch/${_carch}/boot"
if [ "$CARCH" == "aarch64" ]; then
install -Dm644 "$srcdir/build/arch/${_carch}/boot/Image" \
"$pkgdir/boot/vmlinuz-$_flavor"
else
install -Dm644 "$srcdir/build/arch/${_carch}/boot/"*zImage \
"$pkgdir/boot/vmlinuz-$_flavor"
fi
install -D "$srcdir/build/include/config/kernel.release" \
"$pkgdir/usr/share/kernel/$_flavor/kernel.release"
cd "$srcdir"/build
local _install
case "$CARCH" in
aarch64*|arm*) _install="modules_install dtbs_install" ;;
*) _install="modules_install" ;;
esac
make -j1 $_install \
ARCH="$_carch" \
INSTALL_MOD_PATH="$pkgdir" \
INSTALL_DTBS_PATH="$pkgdir/usr/share/dtb"
}
dev() {
# copy the only the parts that we really need for build 3rd party
# kernel modules and install those as /usr/src/linux-headers,
# simlar to what ubuntu does
#
# this way you dont need to install the 300-400 kernel sources to
# build a tiny kernel module
#
pkgdesc="Headers and script for third party modules for postmarketos kernel"
depends="gmp-dev bash perl"
local dir="$subpkgdir"/usr/src/linux-headers-${_abi_release}
# first we import config, run prepare to set up for building
# external modules, and create the scripts
mkdir -p "$dir"
cp "$srcdir"/$_config "$dir"/.config
make -j1 -C "$srcdir"/linux-$_kernver O="$dir" ARCH="$_carch" HOSTCC="$HOSTCC" \
olddefconfig prepare modules_prepare scripts
# needed for 3rd party modules
# https://bugzilla.kernel.org/show_bug.cgi?id=11143
case "$CARCH" in
ppc*) (cd "$dir" && make arch/powerpc/lib/crtsavres.o);;
esac
# remove the stuff that points to real sources. we want 3rd party
# modules to believe this is the soruces
rm "$dir"/Makefile "$dir"/source
# copy the needed stuff from real sources
#
# this is taken from ubuntu kernel build script
# http://kernel.ubuntu.com/git/ubuntu/ubuntu-zesty.git/tree/debian/rules.d/3-binary-indep.mk
cd "$srcdir"/linux-$_kernver
find . -path './include/*' -prune \
-o -path './scripts/*' -prune -o -type f \
\( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
-name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \
-print | cpio -pdm "$dir"
cp -a scripts include "$dir"
find $(find arch -name include -type d -print) -type f \
| cpio -pdm "$dir"
install -Dm644 "$srcdir"/build/Module.symvers \
"$dir"/Module.symvers
mkdir -p "$subpkgdir"/lib/modules/${_abi_release}
ln -sf /usr/src/linux-headers-${_abi_release} \
"$subpkgdir"/lib/modules/${_abi_release}/build
# cross-compiling: delete binaries with host arch and replace them with
# symlinks to binaries with the target arch (packaged in kernel-scripts)
if [ -n "$CROSS_COMPILE" ]; then
msg "Symlinking binary scripts..."
depends="$depends kernel-scripts"
cd "$dir/scripts"
local i
for i in $(find . -type f); do
local type="$(file -b --mime-type "$i")"
[ "$type" != "application/x-sharedlib" ] && continue
local native="/usr/bin/kernel-scripts/$(echo "$i" | cut -d '/' -f 2-)"
ln -svf "$native" "$i"
done
fi
}
sha512sums="77e43a02d766c3d73b7e25c4aafb2e931d6b16e870510c22cef0cdb05c3acb7952b8908ebad12b10ef982c6efbe286364b1544586e715cf38390e483927904d8 linux-4.14.tar.xz
7de482169eb64cca001c298091471d803421dfef5835fa9a693840bd96083bdc42bc12a5217ececb5780ac285cf23674f2bd008183e651b81a7fc2882b819f01 config-postmarketos-lts.armhf
f7dcf05c3c3042c6105748bcbe60ff8c02fac91c7de260a51b568c983df7f2a69c2bde6ebc3ddc4b7283e4aba7e1a8b0e9e4baff6ab863553dc3767679f54f62 config-postmarketos-lts.aarch64
d1e6ca8faee80641a2e882b3b9b0009b05a73adee8e939ace17be7879f8a87f4f2e7cb7bbbb9590e9b6c1491ed076505dbef599c0dc9e71fe71a8d451a7b635e config-postmarketos-lts.x86_64
f2e87f9205924097b5aaa39ca6967449fa78a9a13d27fd4edac829cbb411f28881b2dc4fc5f8c270ec8673118bf260f7411646f0900c00f8511283fe0eb3c7e7 patch-4.14.29.xz"

View File

@ -1,5 +1,5 @@
pkgname=postmarketos-mkinitfs
pkgver=0.6.2
pkgver=0.6.3
pkgrel=0
pkgdesc="Tool to generate initramfs images for postmarketOS"
url="https://github.com/postmarketOS"
@ -25,4 +25,4 @@ package() {
}
sha512sums="a09a48026a5cac308fa54e37c72e89fd7901e749f73720f3e8d3ec11a4d1527dbc1e5011aff53b1beffb6ff444c8df11a56e43d27ac0180ce8ddc79332be1d0d init.sh.in
f45548b295393cb078e4c456acef0eaac11705c4b5bc33981c320580c843231589fdfc78b25e182cd202435381d1be37085df01b6e272eee0af2ca0f89b3b4f5 init_functions.sh
833f8a6c3753da7581fefb56a6a68f61663f2910d6b89b7a9cc3033ac922589b1d07ba246cbcd8e0a99fc8df128f9ae1b1bf2bd8cf3cad65a323cf712c03ae2d mkinitfs.sh"
b80a773efe22a6fe33ffb6f92ff279e425ff7034a4946497a628ea6c4e2300112adcde7d09d790a04b851610d3f17271001b6e3d36ba39321dba69f48b393f89 mkinitfs.sh"

View File

@ -352,11 +352,13 @@ append_device_tree()
dtb="/usr/share/dtb/${deviceinfo_dtb}.dtb"
kernel="${outfile/initramfs-/vmlinuz-}"
echo "==> kernel: appending device-tree ${deviceinfo_dtb}"
if ! [ -e "$dtb" ]; then
echo "ERROR: File not found: $dtb"
exit 1
if [ -e "$dtb" ]; then
cat "$kernel" "$dtb" > "${kernel}-dtb"
else
echo "NOTE: device tree does not exist, not appending it to the kernel."
echo "This is expected for downstream kernels."
cp "$kernel" "${kernel}-dtb"
fi
cat $kernel $dtb > "${kernel}-dtb"
}
# Create the initramfs-extra archive

View File

@ -95,7 +95,8 @@ def ls(args, flavor, suffix, extra=False):
def frontend(args):
# Find the appropriate kernel flavor
suffix = "rootfs_" + args.device
flavor = pmb.chroot.other.kernel_flavor_autodetect(args, suffix)
flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix)
flavor = flavors[0]
if hasattr(args, "flavor") and args.flavor:
flavor = args.flavor
@ -124,7 +125,7 @@ def frontend(args):
pmb.chroot.initfs_hooks.delete(args, args.hook, suffix)
# Rebuild the initfs for all kernels after adding/removing a hook
for flavor in pmb.chroot.other.kernel_flavors_installed(args, suffix):
for flavor in flavors:
build(args, flavor, suffix)
if action in ["ls", "extract"]:

View File

@ -19,9 +19,24 @@ along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
import os
import glob
import pmb.chroot.apk
import pmb.install
def kernel_flavors_installed(args, suffix):
def kernel_flavors_installed(args, suffix, autoinstall=True):
"""
Get all installed kernel flavors and make sure that there's at least one
:param suffix: the chroot suffix, e.g. "native" or "rootfs_qemu-amd64"
:param autoinstall: make sure that at least one kernel flavor is installed
:returns: list of installed kernel flavors, e.g. ["postmarketos-mainline"]
"""
# Automatically install the selected kernel
if autoinstall:
packages = (["device-" + args.device] +
pmb.install.get_kernel_package(args, args.device))
pmb.chroot.apk.install(args, packages, suffix)
# Find all kernels in /boot
prefix = "vmlinuz-"
prefix_len = len(prefix)
pattern = args.work + "/chroot_" + suffix + "/boot/" + prefix + "*"
@ -31,18 +46,11 @@ def kernel_flavors_installed(args, suffix):
if flavor[-4:] == "-dtb":
flavor = flavor[:-4]
ret.append(flavor)
# Return without duplicates
return list(set(ret))
def kernel_flavor_autodetect(args, suffix):
"""
Make sure, that there is at least one kernel installed, return the first
kernel that can be found.
"""
pmb.chroot.apk.install(args, ["device-" + args.device], suffix)
return kernel_flavors_installed(args, suffix)[0]
def tempfolder(args, path, suffix="native"):
"""
Create a temporary folder inside the chroot, that belongs to "user".

View File

@ -46,7 +46,7 @@ work_version = 2
# Only save keys to the config file, which we ask for in 'pmbootstrap init'.
config_keys = ["ccache_size", "device", "extra_packages", "hostname", "jobs",
"keymap", "nonfree_firmware", "nonfree_userland",
"kernel", "keymap", "nonfree_firmware", "nonfree_userland",
"qemu_native_mesa_driver", "timezone", "ui", "user", "work"]
# Config file/commandline default values
@ -68,6 +68,7 @@ defaults = {
# target device: <https://github.com/postmarketOS/pmbootstrap/issues/429>
"iter_time": "200",
"jobs": str(multiprocessing.cpu_count() + 1),
"kernel": "stable",
"keymap": "",
"log": "$WORK/log.txt",
"mirror_alpine": "http://dl-cdn.alpinelinux.org/alpine/",

View File

@ -124,6 +124,47 @@ def ask_for_timezone(args):
return "GMT"
def ask_for_device_kernel(args, device):
"""
Ask for the kernel that should be used with the device.
:param device: code name, e.g. "lg-mako"
:returns: None if the kernel is hardcoded in depends without subpackages
:returns: kernel type ("downstream", "stable", "mainline", ...)
"""
# Get kernels
kernels = pmb.parse._apkbuild.kernels(args, device)
if not kernels:
return args.kernel
# Get default
default = args.kernel
if default not in kernels:
default = list(kernels.keys())[0]
# Ask for kernel (extra message when downstream and upstream are available)
logging.info("Which kernel do you want to use with your device?")
if "downstream" in kernels:
logging.info("Downstream kernels are typically the outdated Android"
" kernel forks.")
if "downstream" in kernels and len(kernels) > 1:
logging.info("Upstream kernels (mainline, stable, ...) get security"
" updates, but may have less working features than"
" downstream kernels.")
# List kernels
logging.info("Available kernels (" + str(len(kernels)) + "):")
for type in sorted(kernels.keys()):
logging.info("* " + type + ": " + kernels[type])
while True:
ret = pmb.helpers.cli.ask(args, "Kernel", None, default, True)
if ret in kernels.keys():
return ret
logging.fatal("ERROR: Invalid kernel specified, please type in one"
" from the list above.")
return ret
def ask_for_device_nonfree(args, device):
"""
Ask the user about enabling proprietary firmware (e.g. Wifi) and userland
@ -190,8 +231,9 @@ def ask_for_device(args):
pmb.aportgen.generate(args, "linux-" + device)
break
kernel = ask_for_device_kernel(args, device)
nonfree = ask_for_device_nonfree(args, device)
return (device, device_exists, nonfree)
return (device, device_exists, kernel, nonfree)
def ask_for_qemu_native_mesa_driver(args, device, arch_native):
@ -259,8 +301,9 @@ def frontend(args):
cfg["pmbootstrap"]["work"] = args.work = ask_for_work_path(args)
# Device
device, device_exists, nonfree = ask_for_device(args)
device, device_exists, kernel, nonfree = ask_for_device(args)
cfg["pmbootstrap"]["device"] = device
cfg["pmbootstrap"]["kernel"] = kernel
cfg["pmbootstrap"]["nonfree_firmware"] = str(nonfree["firmware"])
cfg["pmbootstrap"]["nonfree_userland"] = str(nonfree["userland"])

View File

@ -44,41 +44,16 @@ import pmb.parse
import pmb.qemu
def _build_device_depends_note(args, pkgname):
"""
Previously 'pmbootstrap build device-...' built the device package in the
native chroot without installing its dependencies (e.g. armhf kernel!) and
created a symlink to all supported architectures.
Not installing depends while building is incompatible with how Alpine's
abuild does it, so we changed the behavior. Now pmbootstrap reads the
device's architecture from the deviceinfo file and automatically builds
for that architecture, if you did not specify any architecture. And the
dependencies get installed correctly before the build.
To make migration easier for the users, we show a hint if building a device
package was requested.
"""
# Only relevant for device packages when -i is not set
if not pkgname.startswith("device-") or getattr(args, "ignore_depends"):
return
device = pkgname.split("-", 1)[1]
logging.info("NOTE: " + device + "'s kernel will be installed as dependency"
" before building (old behavior: 'pmbootstrap build -i')")
def _parse_flavor(args):
"""
Verify the flavor argument if specified, or return a default value.
"""
# Make sure, that at least one kernel is installed
# Install at least one kernel and get installed flavors
suffix = "rootfs_" + args.device
pmb.chroot.apk.install(args, ["device-" + args.device], suffix)
flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix)
# Parse and verify the flavor argument
flavor = args.flavor
flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix)
if flavor:
if flavor not in flavors:
raise RuntimeError("No kernel installed with flavor " + flavor + "!" +
@ -116,11 +91,6 @@ def build(args):
if args.strict:
pmb.chroot.zap(args, False)
# Detect old usage for device- packages
if not args.ignore_depends:
for package in args.packages:
_build_device_depends_note(args, package)
# Set src and force
src = os.path.realpath(os.path.expanduser(args.src[0])) if args.src else None
force = True if src else args.force

View File

@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
from pmb.install._install import install
from pmb.install._install import get_kernel_package
from pmb.install.partition import partition
from pmb.install.format import format
from pmb.install.partition import partitions_mount

View File

@ -92,6 +92,30 @@ def get_nonfree_packages(args, device):
return ret
def get_kernel_package(args, device):
"""
Get the kernel package based on user's choice in "pmbootstrap init".
:param device: code name, e.g. "lg-mako"
:returns: [] or the package in a list, e.g. ["linux-postmarketos-stable"]
"""
# Get kernels for the device
kernels = pmb.parse._apkbuild.kernels(args, device)
if not kernels or args.kernel == "none":
return []
# Sanity check
if args.kernel not in kernels:
raise RuntimeError("Selected kernel (" + args.kernel + ") is not"
" configured for device " + device + ". Please"
" run 'pmbootstrap init' to select a valid kernel.")
# Return the pkgname
if args.kernel == "downstream":
return ["linux-" + device]
return ["linux-postmarketos-" + args.kernel]
def copy_files_from_chroot(args):
"""
Copy all files from the rootfs chroot to /mnt/install, except
@ -365,6 +389,7 @@ def install(args):
args.device))
install_packages = (pmb.config.install_device_packages +
["device-" + args.device] +
get_kernel_package(args, args.device) +
get_nonfree_packages(args, args.device))
if args.ui.lower() != "none":
install_packages += ["postmarketos-ui-" + args.ui]

View File

@ -209,3 +209,37 @@ def subpkgdesc(path, function):
raise RuntimeError("Could not find pkgdesc of subpackage function '" +
function + "' (spaces used instead of tabs?) in " +
path)
def kernels(args, device):
"""
Get the possible kernels from a device-* APKBUILD.
:param device: the device name, e.g. "lg-mako"
:returns: None when the kernel is hardcoded in depends
:returns: kernel types and their description (as read from the subpackages)
possible types: "downstream", "stable", "mainline"
example: {"mainline": "Mainline description",
"downstream": "Downstream description"}
"""
# Read the APKBUILD
apkbuild_path = args.aports + "/device/device-" + device + "/APKBUILD"
if not os.path.exists(apkbuild_path):
return None
subpackages = apkbuild(args, apkbuild_path)["subpackages"]
# Read kernels from subpackages
ret = {}
subpackage_prefix = "device-" + device + "-kernel-"
for subpackage in subpackages:
if not subpackage.startswith(subpackage_prefix):
continue
name = subpackage[len(subpackage_prefix):]
func = "kernel_" + name
desc = pmb.parse._apkbuild.subpkgdesc(apkbuild_path, func)
ret[name] = desc
# Return
if ret:
return ret
return None

View File

@ -117,7 +117,7 @@ def command_qemu(args, arch, device, img_path, spice_enabled):
if args.flavor:
flavor = args.flavor
else:
flavor = pmb.chroot.other.kernel_flavor_autodetect(args, suffix)
flavor = pmb.chroot.other.kernel_flavors_installed(args, suffix)[0]
command = [qemu_bin]
command += ["-kernel", rootfs + "/boot/vmlinuz-" + flavor]
command += ["-initrd", rootfs + "/boot/initramfs-" + flavor]

View File

@ -25,6 +25,7 @@ import sys
pmb_src = os.path.realpath(os.path.join(os.path.dirname(__file__) + "/.."))
sys.path.append(pmb_src)
import pmb.parse
import pmb.parse._apkbuild
@pytest.fixture
@ -52,7 +53,6 @@ def test_aports_device(args):
"""
Various tests performed on the /device/device-* aports.
"""
for path in glob.glob(args.aports + "/device/device-*/APKBUILD"):
apkbuild = pmb.parse.apkbuild(args, path)
@ -68,3 +68,57 @@ def test_aports_device(args):
" depends of " + path + ". These go into"
" subpackages now, see"
" <https://postmarketos.org/devicepkg>.")
def test_aports_device_kernel(args):
"""
Verify the kernels specified in the device packages:
* Kernel must not be in depends when kernels are in subpackages
* Check if only one kernel is defined in depends
* Validate kernel subpackage names
"""
# Generate list of valid subpackages
valid_subpackages = ["downstream"]
for path in glob.glob(args.aports + "/main/linux-postmarketos-*"):
suffix = os.path.basename(path)[len("linux-postmarketos-"):]
valid_subpackages.append(suffix)
# Iterate over device aports
for path in glob.glob(args.aports + "/device/device-*/APKBUILD"):
# Parse apkbuild and kernels from subpackages
apkbuild = pmb.parse.apkbuild(args, path)
device = apkbuild["pkgname"][len("device-"):]
kernels_subpackages = pmb.parse._apkbuild.kernels(args, device)
# Parse kernels from depends
kernels_depends = []
for depend in apkbuild["depends"]:
if not depend.startswith("linux-"):
continue
kernels_depends.append(depend)
# Kernel in subpackages *and* depends
if kernels_subpackages:
raise RuntimeError("Kernel package '" + depend + "' needs to"
" be removed when using kernel" +
" subpackages: " + path)
# No kernel
if not kernels_depends and not kernels_subpackages:
raise RuntimeError("Device doesn't have a kernel in depends or"
" subpackages: " + path)
# Multiple kernels in depends
if len(kernels_depends) > 1:
raise RuntimeError("Please use kernel subpackages instead of"
" multiple kernels in depends (see"
" <https://postmarketos.org/deviceinfo>): " +
path)
# Verify subpackages
if kernels_subpackages:
for subpackage in kernels_subpackages:
if subpackage not in valid_subpackages:
raise RuntimeError("Invalid kernel subpackage name '" +
subpackage + "', valid: " +
str(valid_subpackages))

View File

@ -24,10 +24,20 @@ import sys
# Import from parent directory
pmb_src = os.path.realpath(os.path.join(os.path.dirname(__file__) + "/.."))
sys.path.append(pmb_src)
import pmb.parse._apkbuild
@pytest.fixture
def args(tmpdir, request):
import pmb.parse
sys.argv = ["pmbootstrap.py", "init"]
args = pmb.parse.arguments()
args.log = args.work + "/log_testsuite.txt"
pmb.helpers.logging.init(args)
request.addfinalizer(args.logfd.close)
return args
def test_subpkgdesc():
func = pmb.parse._apkbuild.subpkgdesc
testdata = pmb_src + "/test/testdata"
@ -48,3 +58,17 @@ def test_subpkgdesc():
with pytest.raises(RuntimeError) as e:
func(path, "subpackage")
assert str(e.value).startswith("Could not find pkgdesc of subpackage")
def test_kernels(args):
# Kernel hardcoded in depends
args.aports = pmb_src + "/test/testdata/init_questions_device/aports"
func = pmb.parse._apkbuild.kernels
device = "lg-mako"
assert func(args, device) is None
# Upstream and downstream kernel
device = "sony-amami"
ret = {"downstream": "Downstream description",
"mainline": "Mainline description"}
assert func(args, device) == ret

View File

@ -110,6 +110,7 @@ def test_questions_device(args, monkeypatch):
args.device = "lg-mako"
args.nonfree_firmware = True
args.nonfree_userland = False
args.kernel = "downstream"
# Do not generate aports
def fake_generate(args, pkgname):
@ -120,15 +121,36 @@ def test_questions_device(args, monkeypatch):
func = pmb.config.init.ask_for_device
nonfree = {"firmware": True, "userland": False}
fake_answers(monkeypatch, ["lg-mako"])
assert func(args) == ("lg-mako", True, nonfree)
kernel = args.kernel
assert func(args) == ("lg-mako", True, kernel, nonfree)
# Non-existing device, go back, existing device
fake_answers(monkeypatch, ["whoops-typo", "n", "lg-mako"])
assert func(args) == ("lg-mako", True, nonfree)
assert func(args) == ("lg-mako", True, kernel, nonfree)
# New device
fake_answers(monkeypatch, ["new-device", "y"])
assert func(args) == ("new-device", False, nonfree)
assert func(args) == ("new-device", False, kernel, nonfree)
def test_questions_device_kernel(args, monkeypatch):
# Prepare args
args.aports = pmb_src + "/test/testdata/init_questions_device/aports"
args.kernel = "downstream"
# Kernel hardcoded in depends
func = pmb.config.init.ask_for_device_kernel
device = "lg-mako"
assert func(args, device) == args.kernel
# Choose "mainline"
device = "sony-amami"
fake_answers(monkeypatch, ["mainline"])
assert func(args, device) == "mainline"
# Choose "downstream"
fake_answers(monkeypatch, ["downstream"])
assert func(args, device) == "downstream"
def test_questions_device_nonfree(args, monkeypatch):

View File

@ -0,0 +1,45 @@
pkgname=device-sony-amami
pkgver=2
pkgrel=0
pkgdesc="Sony Xperia Z1 Compact"
url="https://github.com/postmarketOS"
arch="noarch"
license="MIT"
depends="postmarketos-base mkbootimg mdss-fb-init-hack mesa-dri-swrast"
makedepends=""
install=""
subpackages="
$pkgname-kernel-downstream:kernel_downstream
$pkgname-kernel-mainline:kernel_mainline
$pkgname-nonfree-firmware:nonfree_firmware
"
source="deviceinfo 90-android-touch-dev.rules"
options="!check"
package() {
install -D -m644 "$srcdir/deviceinfo" \
"$pkgdir/etc/deviceinfo"
install -D -m644 "$srcdir"/90-android-touch-dev.rules \
"$pkgdir"/etc/udev/rules.d/90-android-touch-dev.rules
}
kernel_downstream() {
pkgdesc="Downstream description"
depends="linux-sony-amami"
mkdir "$subpkgdir"
}
kernel_mainline() {
pkgdesc="Mainline description"
depends="linux-postmarketos-mainline"
mkdir "$subpkgdir"
}
nonfree_firmware() {
pkgdesc="Wifi firmware"
depends="firmware-sony-amami"
mkdir "$subpkgdir"
}
sha512sums="e6daf310a259483da1e1e8be66693dea876f8d1fa6db001c37035d913d7de6e5f1be4a40fae7dcaff404d1953b4c5a58b31d8e6b593b72b56b64ba78f859717c deviceinfo
8b6034c0338ab4c7d648f47983aad6da07e427e7dba47baabf85a1b3ddeeda47c8d7fbcd547a302c9a759b2943ee30d3e82c3b368d8582833a058e4671638a9e 90-android-touch-dev.rules"