Files
pmaports-rtwo/main/postmarketos-initramfs/init.sh
T
Caleb Connolly 8400fffefb postmarketos-initramfs: refactor cmdline parsing
Currently the initramfs is littered with various code snippets which
read /proc/cmdline. This is error prone and results in more complicated
code especially as we want to standardise all the pmos specific cmdline
arguments, and where some arguments have the same behaviour as
deviceinfo variables.

Let's do the parsing correctly, once, and set global variables to
enable/disable/configure parts of the initramfs. At the same time
introduce namespaced and standard versions of the remaining arguments
which haven't been standardised yet.

Now (for example) to check if the splash is disabled, rather than
grepping /proc/cmdline for PMOS_NOSPLASH AND checking if
deviceinfo_no_framebuffer is true, you can just check if "$nosplash" =
"y".

This will drastically simplify the process of adding additional
configuration options in the future.

Most of the code here was taken from the Arch Linux initramfs and
simplified/adjusted to better fix our use case.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/6172
2025-03-14 20:24:07 +00:00

77 lines
1.9 KiB
Bash

#!/bin/sh
# shellcheck disable=SC1091
# Export all variables so they're available in /init_2nd.sh
set -a
IN_CI="false"
LOG_PREFIX="[pmOS-rd]"
[ -e /hooks/10-verbose-initfs.sh ] && set -x
[ -e /hooks/05-ci.sh ] && IN_CI="true"
[ -e /etc/unudhcpd.conf ] && . /etc/unudhcpd.conf
. ./init_functions.sh
. /usr/share/misc/source_deviceinfo
[ -e /etc/os-release ] && . /etc/os-release
# provide a default for os-release's VERSION in case the file doesn't exist
VERSION="${VERSION:-unknown}"
# This is set during packaging and is used when triaging bug reports
INITRAMFS_PKG_VERSION="<<INITRAMFS_PKG_VERSION>>"
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
/bin/busybox --install -s
/bin/busybox-extras --install -s
# Mount everything, set up logging, modules, mdev
mount_proc_sys_dev
parse_cmdline < /proc/cmdline
setup_log
echo " ❬❬ PMOS STAGE 1 ❭❭"
echo "initramfs version: $INITRAMFS_PKG_VERSION"
setup_firmware_path
# Jump straight to the 2nd stage init if available
# (no separate -extra) or no-op otherwise
jump_init_2nd
echo "Loading initramfs-extra..."
# We need mdev to find the boot partition
setup_mdev
load_modules /lib/modules/initramfs.load
setup_usb_network
start_unudhcpd
if [ "$IN_CI" = "false" ]; then
setup_framebuffer
show_splash "Loading..."
fi
# Discover the partitions if they're "subpartitions"
# (where the whole disk image is flashed to a partition)
mount_subpartitions
# Poll for the boot partition to become available or crash
wait_boot_partition
mount_boot_partition /boot
extract_initramfs_extra /boot/initramfs-extra
# /boot is mounted later into the rootfs
umount /boot
# Kill mdev, since it's replaced by udev in the
# second stage init
kill mdev 2>/dev/null
# Now we can jump to the 2nd stage init
jump_init_2nd
# Somehow init_2nd.sh is missing
echo "$LOG_PREFIX ERROR: /init_2nd.sh not found!"
echo "$LOG_PREFIX For more information, see <https://postmarketos.org/debug-shell>"
fail_halt_boot