User:Ollieparanoid/Run wlroots with fbdev

From postmarketOS
Note Integrating this properly into postmarketOS is being discussed in pmaports#948. Help wanted!
Phoc running with wlroots on framebuffer on the Samsung Galaxy SII

Documentation of my efforts to run wlroots with fbdev, so it runs on downstream kernels. I have created a pull request to wlroots (wlroots#2410) with the feature, in which it was suggested to turn this fbdev backend into a third party backend. This will be the next step (if you'd like to help out, see pmaports#948). Meanwhile, here are some notes on how to build my wlroots branch from source and running it on your phone.

Demo video

To get an idea of the performance, CPU usage etc. (there's a lot to be optimized), see this demo video running on the Nexus 4.

Update: the initial performance (as in the video) was pretty bad, thanks to helpful review comments it's much better now.

Caveats

Note These things should get documented with proper issues / be fixed with proper merge requests soon.

This was tested with the Samsung Galaxy S2 (i9100) and Nexus 4 (lg-mako).

Change framebuffer mode to RGBA

If the colors are off, make sure that your kernel has RGBA configured as framebuffer mode. This is hardcoded for now, until wlroots uses its upcoming own swapchain. In the i9100 kernel, it was needed to set CONFIG_FB_RGBA_ORDER=y, the lg-mako kernel had this mode set by default. Search for RGBA in your device's linux pmaport.

Fix elogind not starting

On lg-mako, elogind was not starting up. When trying to start it manually (grab the command from the openrc service file), it would fail with:

 [   21.387150] elogind-daemon[1538]: Failed to determine whether /sys/fs/cgroup is a mount point: Symbolic link loop                              
 [   21.388341] elogind-daemon[1538]: Failed to mount cgroup at /sys/fs/cgroup/elogind: No such file or directory    

To fix this, apply this patch to your kernel (as in pmaports!776).

MR to fix this for lg-mako: pmaports!1606

SSH may be broken on edge

As of writing, SSH was broken on edge (pmaports#808): after authenticating, the phone would abort the connection. I worked around this by copying the pmaports relevant to the device I wanted to test from edge to current stable, and then built it against stable.

Can't flash big images to lg-mako

Although the userdata partition of lg-mako is 5.8 GB in size, fastboot refused to flash a fully blown phosh install to it. I worked around this by building an install with UI=none, and installing related packages afterwards with apk.

gnuchess is broken?

In my demo video I wanted to play chess. gnome-chess didn't work with gnuchess, but building the gambit-fruit chess engine from source worked. Put the gfruit binary in /usr/local/bin and gnome-chess will pick it up and use it.

Upstream issue: https://gitlab.alpinelinux.org/alpine/aports/-/issues/11983

Building wlroots + compositor

Installing dependencies

To build wlroots, sway and phoc, install these packages. Set up USB Internet if necessary.

#!/bin/sh
sudo apk add  \
        git \
        alpine-sdk \
        consolekit2 \
        sway \
        \
        elogind-dev \
        eudev-dev \
        libcap-dev \
        libinput-dev \
        libxcb-dev \
        libxkbcommon-dev \
        mesa-dev \
        meson \
        ninja \
        pixman-dev \
        wayland-dev \
        wayland-protocols \
        xcb-util-image-dev \
        xcb-util-wm-dev \
        xkeyboard-config \
        \
        json-c-dev \
        pango-dev \
        gdk-pixbuf-dev \
        libevdev-dev \
        gnome-desktop-dev

Clone sources

Then clone the relevant sources:

#!/bin/sh -ex
mkdir ~/code
cd ~/code
git clone https://github.com/swaywm/wlroots.git
git -C wlroots remote add -f ollieparanoid https://github.com/ollieparanoid/wlroots.git
git -C wlroots checkout fbdev
git clone https://github.com/swaywm/sway.git
git clone https://source.puri.sm/Librem5/phoc.git

Build and install wlroots

Remember to always rebuild compositors against wlroots before running them!

#!/bin/sh -ex
JOBS=3
cd ~/code/wlroots

abuild-meson \
        -Dlogind=enabled \
        -Dlogind-provider=elogind \
        -Dexamples=false \
        -Dfbdev-backend=enabled \
        . build
 
meson compile ${JOBS:+-j ${JOBS}} -C build
sudo meson install --no-rebuild -C build

Build and install sway

#!/bin/sh -ex
JOBS=3           
cd ~/code/sway
             
abuild-meson \  
        . build              
 
meson compile ${JOBS:+-j ${JOBS}} -C build
sudo meson install --no-rebuild -C build

Build and install phoc

#!/bin/sh -ex
JOBS=3
cd ~/code/phoc

abuild-meson \
        -Dembed-wlroots=disabled \
        . build

meson compile ${JOBS:+-j ${JOBS}} -C build
sudo meson install --no-rebuild -C build

Running a compositor

The only way I was able to set up the session properly, is by letting lightdm do it. Install postmarketos-ui-phosh, then edit /usr/share/wayland-sessions/phosh.desktop and make it point to some script you can easily edit (e.g. /home/user/bin/lightdm-wrapper). Inside the wrapper script, put:

#!/bin/sh -ex
# lightdm starts this, logs to ~/.xsession-errors

export WLR_BACKENDS="fbdev,libinput"
export WLR_SESSION_LOGIND_NO_WAIT_CAN_GRAPHICAL=1

/usr/bin/phosh "$@"
# /usr/bin/sway -d "$@"


# To compare with weston (not wlroots based!)
# export XDG_RUNTIME_DIR=/tmp/xdg
# mkdir -p /tmp/xdg
# (sleep 3 && postmarketos-demos ) &
# weston -B fbdev-backend.so

Set scaling

To change the scaling of Phosh, put this in your /etc/phoc/phoc.ini (same works for sway with sway's config etc.):

[output:FBDEV-1]
scale = 2

(Note that many pmaports use /etc/phosh/rootston.ini, that's the legacy path which also works but should be changed to phoc.ini eventually. See phosh.in.)