On Mon, 02 Sep 2024 14:47:17 +0100 Daniel Thompson <debianb...@redfelineninja.org.uk> wrote:
Package: initramfs-tools
Version: 0.145
Severity: normal
Tags: patch
X-Debbugs-Cc: debianb...@redfelineninja.org.uk

Dear Maintainer,

Currently initramfs-tools relies on modinfo to identify firmware that must
be included in the initramfs. This is incomplete on systems where the name
of the firmware to load is provided by the devicetree rather than being
hardcoded and recorded in the MODULE_FIRMWARE() macro.

As a concrete example, recent Windows-on-Snapdragon laptops (Thinkpad X13s for
example) require firmware for the remoteproc drivers. If this firmware is not
available when the driver comes up then significant functionality (battery
status, external display, etc) is disabled. The combination of my MODULES=most
setup (plus encrypted rootfs and a few explicitly named modules) is exactly
that.

I disliked the idea that having a richer initramfs (including the remoteproc
drivers) can kills functionality so rather than try and blocklist things I
instead added an initramfs hook to scan the current devicetree and include any
firmware that might be needed.

~~~
#!/bin/sh -e

# Copyright (C) Linaro Ltd, 2024
# SPDX-License-Identifier: GPL-2.0-or-later

# Add firmware whose names are dictated by the devicetree. Such firmware cannot
# be described in a MODULE_FIRMWARE() meaning modinfo based discovery tools are
# insufficient to handle these cases.

# No prereqs
if [ "$1" = "prereqs" ]; then exit 0; fi

. /usr/share/initramfs-tools/hook-functions

# Only run if this system is booted with a devicetree
if [ ! -d /sys/firmware/devicetree ]; then exit 0; fi

# Scan for appropriately named devicetree nodes and add any firmware
# we discover this way to the initramfs. Sadly we cannot tell the difference
# between boot-critical firmware and any other so we have to be over-zealous.
# However the impact on initramfs size should be acceptable because we only
# scan the devicetree of the booted system.
for node in $(find /sys/firmware/devicetree -name firmware-name); do
        firmware="$(cat "${node}")"
        if ! add_firmware "${firmware}"; then
                echo "W: Possible missing firmware /lib/firmware/${firmware}
found in devicetree" >&2
        fi
done
~~~

It occurred to me that adding any devicetree specified firmware is a fairly
sensible default. The above code is harmless on ACPI-based systems and although
it's slightly over-zealous it shouldn't bloat the initramfs since too much

I tried this fix out on x13s as I tried booting 6.12-rc1 today and found various of my devices not coming up.

Worked first time.

Tested-by: Bryan O'Donoghue <bryan.odonog...@linaro.org>

Reply via email to