Files
pmaports-rtwo/main/devicepkg-dev/devicepkg_build.sh
T
Minecrell e3d07c832c main/{devicepkg-dev,postmarketos-mkinitfs}: statically generate splash screens (!899)
We need to generate the splash screens separately for each device,
because they are specific to the device's display resolution.

At the moment we do this dynamically during the installation process.
This has the advantage that there is no need to re-build all device
packages when one of the splash screen is changed (or a new one is added).

In reality, however, the splash screens do not change very frequently.
On the other hand, generating the splash screens dynamically has signficant
disk usage overhead for a minimal ("none" UI) rootfs:

The Python interpreter together with the necessary libraries requires
about ~60 MB of disk space on aarch64.
The splash screens itself require about ~100 KB for 720x1280.

This is not necessary if we move the splash screen generation into
devicepkg-dev, which is used to build the device package for all devices.
Another advantage is that we no longer need the (rather complicated)
caching mechanism for splash screens - so we actually end up with less
lines than before.

rootfs size for samsung-a5ulte ("none" UI):
  Before: 450M
  After:  388M (-62M)

After this change, every(!) device package needs to be rebuilt once.
No changes are necessary in device packages.
2020-01-28 15:33:40 +01:00

125 lines
4.5 KiB
Bash

#!/bin/sh
startdir=$1
pkgname=$2
if [ -z "$startdir" ] || [ -z "$pkgname" ]; then
echo "ERROR: missing argument!"
echo "Please call $0 with \$startdir \$pkgname as arguments."
exit 1
fi
srcdir="$startdir/src"
if [ ! -f "$srcdir/deviceinfo" ]; then
echo "NOTE: $0 is intended to be used inside of the build() function"
echo "of a device package's APKBUILD only."
echo "ERROR: deviceinfo file missing!"
exit 1
fi
# shellcheck disable=SC1090,SC1091
. "$srcdir/deviceinfo"
# Create splash screens
generate_splash_screens()
{
splash_config="/etc/postmarketos/splash.ini"
splash_width=${deviceinfo_screen_width:-720}
splash_height=${deviceinfo_screen_height:-1280}
# Overwrite $@ to easily iterate over the splash screens. Format:
# $1: splash_name
# $2: text
# $3: arguments
set -- "splash-loading" "Loading..." "--center" \
"splash-noboot" "boot partition not found\\nhttps://postmarketos.org/troubleshooting" "--center" \
"splash-noinitramfsextra" "initramfs-extra not found\\nhttps://postmarketos.org/troubleshooting" "--center" \
"splash-norootfs" "rootfs not found\\nhttps://postmarketos.org/troubleshooting" "--center" \
"splash-mounterror" "unable to mount root partition\\nhttps://postmarketos.org/troubleshooting" "--center" \
"splash-debug-shell" "WARNING\\ndebug-shell is active\\nhttps://postmarketos.org/debug-shell" "--center" \
"splash-charging-error" "CHARGING MODE\\nerror starting charging-sdl\\nhttps://postmarketos.org/troubleshooting" "--center"
# Loop through the splash screens definitions
while [ $# -gt 2 ]
do
splash_name=$1
splash_text=$2
splash_args=$3
if [ "${deviceinfo_framebuffer_landscape}" == "true" ]; then
splash_args="${splash_args} --landscape"
fi
# shellcheck disable=SC2086
pmos-make-splash --text="${splash_text}" $splash_args --config "${splash_config}" \
"$splash_width" "$splash_height" "$srcdir/${splash_name}.ppm"
gzip "$srcdir/${splash_name}.ppm"
shift 3 # move to the next 3 arguments
done
}
# Convert an input calibration matrix from pixel coordinates to 0-1 coordinates
# and echo it for libinput.
# Parameters:
# $1: x multiplier for x coordinate
# $2: y multiplier for x coordinate
# $3: pixel offset for x coordinate
# $4: x multiplier for y coordinate
# $5: y multiplier for y coordinate
# $6: pixel offset for y coordinate
echo_libinput_calibration()
{
# Check if we have got the required number of parameters.
if [ $# -ne 6 ]; then
echo "WARNING: There must be exactly 6 (or 0) values for the touchscreen calibration." >&2
echo "WARNING: No calibration matrix for x11/libinput will be generated." >&2
return
fi
# Check if we have got a screen width and screen height.
# shellcheck disable=SC2154
if [ -z "$deviceinfo_screen_width" ] || [ -z "$deviceinfo_screen_height" ]; then
echo "WARNING: Screen width and height are required to generate a calibration matrix for x11/libinput." >&2
echo "WARNING: No calibration matrix for x11/libinput will be generated." >&2
return
fi
# Perform the actual conversion: divide both offsets by width/height.
# As the "dc" command from "bc" is incompatible to the one provided by busybox,
# this calls busybox explicitly.
# shellcheck disable=SC2154
x_offset=$(busybox dc "$3" "$deviceinfo_screen_width" / p)
# shellcheck disable=SC2154
y_offset=$(busybox dc "$6" "$deviceinfo_screen_height" / p)
# Check if we have got results from dc. If there was an error, dc should have
# printed an error message that hopefully gives the user a hint why it failed.
if [ -z "$x_offset" ] || [ -z "$y_offset" ]; then
echo "WARNING: Calculating the offsets for the calibration matrix for x11/libinput failed." >&2
echo "No calibration matrix for x11/libinput will be generated." >&2
return
fi
echo "ENV{LIBINPUT_CALIBRATION_MATRIX}=\"$1 $2 $x_offset $4 $5 $y_offset\", \\"
}
generate_splash_screens
# shellcheck disable=SC2154
if [ -n "$deviceinfo_dev_touchscreen" ]; then
# Create touchscreen udev rule
{
echo "SUBSYSTEM==\"input\", ENV{DEVNAME}==\"$deviceinfo_dev_touchscreen\", \\"
# shellcheck disable=SC2154
if [ -n "$deviceinfo_dev_touchscreen_calibration" ]; then
echo "ENV{WL_CALIBRATION}=\"$deviceinfo_dev_touchscreen_calibration\", \\"
# The following intentionally expands the touchscreen calibration into the
# 6 values that should be there.
# shellcheck disable=SC2086
echo_libinput_calibration $deviceinfo_dev_touchscreen_calibration
fi
echo "ENV{ID_INPUT}=\"1\", ENV{ID_INPUT_TOUCHSCREEN}=\"1\""
} > "$srcdir/90-$pkgname.rules"
fi