Hybris

From postmarketOS
Note libhybris has been dropped from postmarketOS, and hybrisOS is no longer in development. This page is left for historic purposes.

Libhybris is an Android compatibility layer, allowing libraries compiled with bionic (Android) libc to be loaded by applications built with different libc (originally glibc, musl in postmarketOS case). It allows a device to run proprietary Android userspace drivers on top of a downstream kernel by running parts of Android in a container. The upsides and downsides of this approach are discussed in pmaports#703.

Currently, libhybris for postmarketOS exists in the form of the hybrisaports repo, and exists as an unofficial method of running postmarketOS without having to work on mainline or kernel drivers (assuming your kernel is compatible).

The aim is for the hybrisOS project to coexist with postmarketOS and ideally make it possible for users to experience postmarketOS on devices that otherwise wouldn't be able to run it (due to missing mainline support or poor quality kernels).

Booting hybris on your device

Get in touch

For help, feel free to come chat with us in #hybrisos:kde.org on Matrix, or @hybrisOS on Telegram!

Halium 9 based ports

Requirements

Target Device

For Halium adaptation to work, your device must have:

  • armv7 or aarch64 architecture
  • Linux 3.17 or newer(need getrandom and memfd_create syscalls) - it is possible to backport these to 3.4 and perhaps 3.10
  • Project Treble support and Android 9 /vendor partition OR official Halium-9 port without Treble halium devices list.

Preparing kernel

For preparing kernel, you need to clone your device kernel repo (Lineage OS kernel is recommended), as well as the halium-boot repo:

$ git clone https://github.com/Halium/halium-boot

Then, check kernel config with this command:

$ ./halium-boot/check-kernel-config path/to/defconfig -w
Note You can find out which defconfig your device uses by finding a lineageOS device tree and looking in the BoardConfig.mk file for the TARGET_KERNEL_CONFIG variable

It is recommended to run the command twice to make sure everything got fixed. Then run the command again without -w flag to check that it was able to find and enable all needed config options.

You should now push your defconfig changes up to a public git repository and follow the porting guide to create your kernel package using the kernel you just modified (don't forget to come back here after!).

pmaports

To add hybris packages to pmaports run the following:

$ cd $(pmbootstrap config aports)
$ git submodule add https://gitlab.com/hybrisos/hybrisaports hybris

Building

Make sure your kernel package is up to date:

$ pmbootstrap build linux-$(pmbootstrap config device) # e.g. linux-oneplus-enchilada-hybris

Generate udev rules

Similarly to the ubports GSI, you will need to generate udev rules to make sure android device nodes and files all get the right permissions. Boot your device into TWRP and get a shell, then run:

# cat /vendor/ueventd*.rc /system_root/ueventd*.rc /system/ueventd*.rc | grep ^/dev | sed -e 's/^\/dev\///' | awk '{printf "ACTION==\"add\", KERNEL==\"%s\", OWNER=\"%s\", GROUP=\"%s\", MODE=\"%s\"\n",$1,$3,$4,$2}' | sed -e 's/\r//' > /sdcard/70-halium.rules
Note Adapted from ubports halium 9 porting notes

Then from your host:

$ adb pull /sdcard/70-halium.rules

Make device-specific hybris package

Devices wishing to use hybris packages must use a slightly modified device package in order to make sure all the hybris packages get installed.

From an existing device package

If you already have a device package, you can simply make a copy - don't forget to change the device codename in the deviceinfo file!

$ cp -r $(pmbootstrap config aports)/device/testing/device-$(pmbootstrap config device) \
      $(pmbootstrap config aports)/device/testing/device-$(pmbootstrap config device)-hybris

Apply needed modifications for hybris

Copy the 70-halium.rules file you generated above to the new device package.

Use the OnePlus 6 device repo as an example to add the following changes to your APKBUILD.

source="
    ...
    70-halium.rules
    ...
"
subpackages="
	$pkgname-nonfree-userland:nonfree_userland
	$pkgname-hybris
	$pkgname-hybris-x11:hybris_x11
	$pkgname-hybris-phosh:hybris_phosh
	$pkgname-hybris-quirks:hybris_quirks
"


nonfree_userland() {
	pkgdesc="Libhybris (Android 9) hardware adaptation packages"
	depends="$pkgname-hybris"
	mkdir "$subpkgdir"
}

hybris() {
	pkgdesc="Metapackage for libhybris (Android 9) adaptation"
	depends="hybris-gsi-9.0 pulseaudio-modules-droid-9.0 bluebinder"
	mkdir "$subpkgdir"
}

hybris_x11() {
	pkgdesc="X11 modules for libhybris (Android 9) adaptation"
	depends="hybris-base-9.0-x11"
	install_if="$pkgname-hybris libx11"
	mkdir $subpkgdir
}

hybris_phosh() {
	pkgdesc="Phosh configuration for libhybris adaptation"
	install_if="$pkgname-hybris postmarketos-ui-phosh"
	depends="wlroots-hwc2"
        mkdir $subpkgdir
}

# Any quirks or extra packages needed for this port
hybris_quirks() {
	pkgdesc="Fixes for this libhybris adaptation specific quirks"
	depends="hexdump hostapd dnsmasq"
	install_if="$pkgname-hybris"
	mkdir $subpkgdir
}

You can now follow the postmarketOS install guide as normal from the installation section.

Halium 7 based ports

Icon TODO: Halium 7 is theoretically supported, but requires a lot more work as Android 7 device don't have a vendor partition. This section will be updated when we have more devices to work with, if you want to get postmarketOS booting with halium on your Android 7 device definitely come chat!

See also