Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/linux-qcom-laptops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
with:
kernel_name: qcom-laptops
build_linux_deb_extra_args: '--repo https://github.com/linux-msm/laptops-kernel --ref qcom-laptops'
overlays: 'dtb-loader'
suites: '["forky"]'
secrets:
LAVATOKEN: ${{ secrets.LAVATOKEN }}
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ Here is the list of supported overlays:
<dd>
Special value to disable all overlays; this is the default.
</dd>
<dt>dtb-loader</dt>
Comment thread
obbardc marked this conversation as resolved.
Resolved
<dd>
kernel-install hook to wrap the EFI kernel image installed in the
ESP with systemd-stub based DTB loader, device trees for these
machines, and boot firmware signatures (CHID). Selecting this
overlay also installs the <tt>stubble</tt> package the hook needs.
</dd>
</dl>

#### Supported profiles
Expand Down Expand Up @@ -349,7 +356,7 @@ workflow submits.

### Flash the image

The `disk-sdcard.img` disk image can simply be written to an SD card, albeit most Qualcomm boards boot from internal storage by default. With an SD card, the board will use boot firmware from internal storage (eMMC or UFS) and do an EFI boot from the SD card if the firmware can't boot from internal storage.
The `disk-sdcard.img` disk image can simply be written to an external boot media such as a SD card or an USB stick, albeit most Qualcomm platforms boot from internal storage by default. With an external boot media, the platform will use its boot firmware from internal storage (eMMC, UFS or SPINOR) and perform an EFI boot from that media. This image should even be suitable for Snapdragon Windows on Arm systems, if it was built with the dtb-loader overlay.

For UFS boards, if there is no need to update the boot firmware, the `disk-ufs.img` disk image can also be flashed on the first LUN of the internal UFS storage with [qdl](https://github.com/linux-msm/qdl) and the provided `rawprogram-ufs.xml` file.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/sh
Comment thread
obbardc marked this conversation as resolved.
Resolved
Comment thread
obbardc marked this conversation as resolved.
Resolved
# from https://github.com/ubuntu/stubble/pull/89
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause
#
# Windows on ARM systems such as Snapdragon laptops ship with an UEFI firmware
# with an insufficient ACPI implementation for Linux and no device tree. Wrap
# the EFI kernel image installed in the ESP: add a systemd-stub based DTB
# loader, device trees of these machines, and boot firmware signatures (CHID).
#
# depends: stubble (for the finddtbs.py script, the stubblify command, and
# the machine id database)

# This hook will wrap kernel images installed in the ESP with `systemd-stub`,
# embedding the device trees from this kernel for the machines in the hardware
# ID database (using data from systemd-boot and stubble), plus the database
# itself.
#
# While stubblify is called, it's not producing a full UKI as it's called
# with an empty --os-release, which suppresses the .osrel section, and no
# --initrd or --cmdline. kernel-install identifies a UKI by .osrel, so the
# result is handled as an ordinary kernel image and keeps a normal Type #1
# boot loader entry, a host-generated initrd and an editable command line.

set -e

# kernel-install calls with these args:
# add KERNEL-VERSION $BOOT/ENTRY-TOKEN/KERNEL-VERSION/ KERNEL-IMAGE \
# [INITRD-FILE ...]
COMMAND="${1:?}"
KERNEL_VERSION="${2:?}"
ENTRY_DIR_ABS="${3:?}"
KERNEL_IMAGE="$4"
# $5 and later are initrds which we don't postprocess

[ "$COMMAND" = "add" ] || exit 0

log() {
if [ "${KERNEL_INSTALL_VERBOSE:-0}" -gt 0 ]; then
echo "$*" >&2
fi
}

fatal_w() {
log "Warning: $*. Not embedding device trees."
exit 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand why its not exit 1 if it is a fatal error. It should not be installed on platforms that do not need it in the first place? Also this kind of function has historically been called die which is well-known that it will exit the program after displaying a message.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 2c: I don't think installing this based on platform is a good idea as part of this PR, since currently we build generic images.

Instead it may be worthwhile bubbling the error up at runtime IF this platform needs the dtb-loader installed ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand why its not exit 1 if it is a fatal error. It should not be installed on platforms that do not need it in the first place? Also this kind of function has historically been called die which is well-known that it will exit the program after displaying a message.

I didn't call that die() or fail() because I didn't want to exit 1.

My 2c: I don't think installing this based on platform is a good idea as part of this PR, since currently we build generic images.

Yes, I want us to build generic images; since I know laptops need a number of workarounds, and some of them belong in packages, my initial thought was to put these behind a flag so that we have a way to trace them back, and return to clean images.

Very keen to hear about better / alternate ways of approaching this!

Instead it may be worthwhile bubbling the error up at runtime IF this platform needs the dtb-loader installed ?

The reason I'm not failing unconditionally is because I wasn't sure how to deliver that without breaking other legitimate uses, for instance:

  • I didn't want to break people like Agathe that have a working local UKI setup already
  • I didn't want to break chroot builds
  • I find it hard to recover from package postinsts failing, and these hooks are typically run from package postinsts

I'm trying to weigh the pros and cons :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good for me, let's come up with a clever solution to be more generic later when we need to, not blocking now :-)!

}

# With layout=auto or no layout set, recent kernel-install will set the layout
# to bls when installing kernels that use UAPI.1 Boot Loader Specification[2]
# Type #1 layout which is the only case where the post-processing done here is
# useful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an implementation detail of kernel-install, why is it stated here instead of just saying we only support bls? (and removing the comment as well)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I developed this file and was reviewing it, I had to learn about the different layouts supported by the config, and then understand that not all of them would be reflected at runtime. This was my way of bringing it back in context here. Some day, there might be new layout types added.

if [ "$KERNEL_INSTALL_LAYOUT" != "bls" ]; then
fatal_w "KERNEL_INSTALL_LAYOUT=${KERNEL_INSTALL_LAYOUT} (!= bls)"
fi

# 90-loaderentry.install has already copied the kernel to ENTRY_DIR_ABS and
# pointed the entry at it; replace it in place with the wrapped image.
KERNEL_DEST="$ENTRY_DIR_ABS/linux"
[ -n "$KERNEL_IMAGE" ] || KERNEL_IMAGE="$KERNEL_DEST"

HWIDS=/usr/share/stubble/hwids
if [ ! -d "$HWIDS" ]; then
fatal_w "$HWIDS not found; install stubble"
fi

if ! command -v stubblify >/dev/null; then
fatal_w "stubblify not found; install stubble"
fi

# Wrapping an already wrapped image would nest a second stub, and a real UKI
# (.osrel) is not ours to post-process.
if stubblify inspect "$KERNEL_IMAGE" 2>/dev/null | grep -Eq '^\.(hwids|osrel):'; then
fatal_w "Wrapper already present on $KERNEL_IMAGE"
fi

FINDDTBS=/usr/libexec/stubble/finddtbs.py
if [ ! -x "$FINDDTBS" ]; then
fatal_w "$FINDDTBS not found; install stubble"
fi

DTB_DIR="/usr/lib/linux-image-${KERNEL_VERSION}"
if [ ! -d "$DTB_DIR" ]; then
fatal_w "$DTB_DIR does not exist"
fi

DTBS=$("$FINDDTBS" "$DTB_DIR" "$HWIDS")

# finddtbs might return an empty output when this kernel carries no device
# tree for any machine in the database.
if [ -z "$DTBS" ]; then
fatal_w "No device tree in $DTB_DIR matches $HWIDS"
fi

set --
for dtb in $DTBS; do
set -- "$@" --devicetree-auto="$dtb"
done

log "Embedding $# device trees from $DTB_DIR into $KERNEL_DEST"

stubblify build \
--linux="$KERNEL_IMAGE" \
--uname="$KERNEL_VERSION" \
--os-release= \
--hwids="$HWIDS" \
"$@" \
--output="$KERNEL_DEST.tmp"

chmod 644 "$KERNEL_DEST.tmp"
chown root:root "$KERNEL_DEST.tmp" || :
mv "$KERNEL_DEST.tmp" "$KERNEL_DEST"
95 changes: 95 additions & 0 deletions debos-recipes/overlays/dtb-loader/etc/kernel/postinst.d/50-stubble
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/sh
# from https://github.com/ubuntu/stubble/pull/89
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause
#
# Windows on ARM systems such as Snapdragon laptops ship with an UEFI firmware
# with an insufficient ACPI implementation for Linux and no device tree. Wrap
# the kernel image just installed in /boot: add a systemd-stub based DTB
# loader, device trees of these machines, and boot firmware signatures (CHID).
#
# depends: stubble (for the finddtbs.py script, the stubblify command, and
# the machine id database)

# This hook will wrap an image that was just installed to /boot with a DTB
# loader in front.
#
# While stubblify is called, it's not producing a full UKI as it's called
# with an empty --os-release, which suppresses the .osrel section, and no
# --initrd or --cmdline. The result stays an ordinary kernel image, so e.g.
# GRUB keeps generating a normal menu entry for it, with a host-generated
# initrd and an editable command line.

set -e

# /etc/kernel/postinst.d/ hooks are called with these args:
# KERNEL-VERSION [KERNEL-IMAGE]
KERNEL_VERSION="${1:?}"
KERNEL_IMAGE="${2:-/boot/vmlinuz-$KERNEL_VERSION}"

PROG="${0##*/}"

fatal_w() {
echo "$PROG: warning: $*. Not embedding device trees." >&2
exit 0
}

if ! [ -f "$KERNEL_IMAGE" ]; then
fatal_w "$KERNEL_IMAGE does not exist"
fi

if ! command -v stubblify >/dev/null; then
fatal_w "stubblify not found; install stubble"
fi

# Wrapping an already wrapped image would nest a second stub, and a real UKI
# (.osrel) is not ours to post-process. This hook rewrites the file in place,
# so the check also keeps it idempotent.
if stubblify inspect "$KERNEL_IMAGE" 2>/dev/null | grep -Eq '^\.(hwids|osrel):'; then
fatal_w "Wrapper already present on $KERNEL_IMAGE"
fi

HWIDS=/usr/share/stubble/hwids
if [ ! -d "$HWIDS" ]; then
fatal_w "$HWIDS not found; install stubble"
fi

FINDDTBS=/usr/libexec/stubble/finddtbs.py
if [ ! -x "$FINDDTBS" ]; then
fatal_w "$FINDDTBS not found; install stubble"
fi

DTB_DIR="/usr/lib/linux-image-${KERNEL_VERSION}"
if [ ! -d "$DTB_DIR" ]; then
fatal_w "$DTB_DIR does not exist"
fi

DTBS=$("$FINDDTBS" "$DTB_DIR" "$HWIDS")

# finddtbs might return an empty output when this kernel carries no device
# tree for any machine in the database.
if [ -z "$DTBS" ]; then
fatal_w "No device tree in $DTB_DIR matches $HWIDS"
fi

set --
for dtb in $DTBS; do
set -- "$@" --devicetree-auto="$dtb"
done

echo "$PROG: embedding $# device trees from $DTB_DIR into $KERNEL_IMAGE"

# Build beside the target and rename, so a failure or a crash leaves the
# bootable image that is already in place untouched.
KERNEL_TMP="$KERNEL_IMAGE.stubble.tmp"
trap 'rm -f "$KERNEL_TMP"' EXIT HUP INT TERM

stubblify build \
--linux="$KERNEL_IMAGE" \
--uname="$KERNEL_VERSION" \
--os-release= \
--hwids="$HWIDS" \
"$@" \
--output="$KERNEL_TMP"

mv "$KERNEL_TMP" "$KERNEL_IMAGE"
29 changes: 29 additions & 0 deletions debos-recipes/qualcomm-linux-debian-rootfs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,21 @@ actions:
{{- range $kernelpackage := split "," $kernelpackages }}
- {{$kernelpackage}}
{{- end }}
{{- end }}

{{- range $overlay := split "," $overlays }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if it makes sense to install these packages in the image recipe unconditionally, since we already install some bootloader packages in the image recipe?

(may have to force-disable ukify hook scripts too, when dtb-loader is not enabled)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy either way (packages pre-installed but not used, or not installed); if it's not too confusing to have stubble installed but not used, let's add it unconditionally.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i think i'd prefer installing it unconditionally, possibly in its own apt action or alongside other similar packages (also noticed this is a duplicate review comment from me, oops)

{{- if eq $overlay "dtb-loader" }}
# The kernel-install hook installed by the dtb-loader overlay needs these at
# image build time, when the systemd-boot postinst runs "kernel-install add",
# and on the running system, so that a kernel upgrade re-wraps the new kernel
# instead of quietly installing one with no device tree.
- action: apt
description: Install DTB loader generation
recommends: true
packages:
# provides stubblify, the hardware ID database and the finddtbs script
- stubble

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. i'd be in favour of always installing stubble, I don't think there's anything detrimental about that?
  2. add stubble to backportpackages so we get latest in trixie :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loïc Minier (@lool) I'd like it if we could add stubble to backportpackages, it's a minor change but I think worth doing. If not, happy to do in a follow-up

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that makes sense

Would be cool if this could land ubuntu/stubble#89, then adding a binary package for it, and then using it from backports

{{- end }}
{{- end }}

# this is currently needed on boards such as RB1 which are using Android
Expand Down Expand Up @@ -779,6 +794,20 @@ actions:
rm -rf "$workdir"
{{- end }}

# systemd recommends systemd-tpm, but it isn't used; on Snapdragon
# Windows-on-ARM laptops, the firmware advertises a TPM2 in the EFI
# variables but no device is exposed for it ("TPM2 Support: firmware
# only, driver unavailable" in bootctl status), so its units wait for a
# long timeout on boot; see #717
- action: run
description: Purge systemd-tpm if installed
chroot: true
command: |
set -eux
if dpkg-query -W -f='${Status}' systemd-tpm 2>/dev/null | grep -q "ok installed"; then
apt-get -y purge systemd-tpm

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the record this is not very elegant, but I will allow it as this PR has been blocked for too long and promise to clean it up later with some kind of apt-mark hold :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a normal APT command-line we could also use something like apt install systemd systemd-tpm- to avoid that Recommends... but I'm unclear of how this could be reflected in the Debos schema.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem is systemd is pulled during deboostrap; I guess we could hack systemd-tpm- in --extra-packages somehow

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used systemctl mask tpm2.target locally on another distro but maybe that's not an option here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's a decent workaround too

(FYI, we're also working on actually getting a proper driver for that TPM so that it just works :))

fi

# All packages are installed by this point, so re-enable initramfs
# generation (see "Disable initramfs generation until all packages are
# installed" above) and generate it once here, for every installed kernel.
Expand Down
43 changes: 43 additions & 0 deletions kernel-configs/qcom-laptops.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,46 @@
# needed for M.2 pwrseq driver
# https://lore.kernel.org/linux-pci/20260501164440.11788-1-manivannan.sadhasivam@oss.qualcomm.com/
CONFIG_POWER_SEQUENCING_PCIE_M2=m

# override qcom-next prune.config as we need this on Lenovo T14s Gen6 (hamoa);
# see https://github.com/qualcomm-linux/kernel/issues/1148
CONFIG_DRM_SIMPLE_BRIDGE=m

# Qualcomm SPEL (SoC Power and Electrical Limits) powercap driver, useful on
# Glymur/X2; the driver comes from
# https://lore.kernel.org/all/20260702-qcom_spel_driver_upstream-v3-0-434d50f0c5b0@oss.qualcomm.com/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: can we link to a tracking issue here at all?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# but the defconfig patch was not yet set, pending the inclusion of the
# patchset upstream; see #718
CONFIG_POWERCAP=y
CONFIG_QCOM_SPEL=m

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: spurious newline

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, thanks

# Omnivision sensor on Zenbooks
CONFIG_VIDEO_OV02C10=m

Comment thread
lool marked this conversation as resolved.
Resolved
# defconfig sets DEBUG_KERNEL=y which implies DMABUF_DEBUG=y; the msm driver
# relies on some internal details that aren't provided when this is set, so
# disable that for the libcamera GPU backend to work
CONFIG_DMABUF_DEBUG=n

# Fn keys for ASUS laptops
CONFIG_HID_ASUS=m

# Bluetooth
# Bluetooth Low Energy; needed for most modern mice, keyboards, earbuds etc.
CONFIG_BT_LE=y
# BlueZ needs /dev/uhid for HID over GATT (BLE keyboards, mice, gamepads)
CONFIG_UHID=m
# serial port emulation; used by some headsets (HFP/HSP AT commands), phones
CONFIG_BT_RFCOMM=m
CONFIG_BT_RFCOMM_TTY=y
# Bluetooth network tethering (PAN)
CONFIG_BT_BNEP=m
CONFIG_BT_BNEP_MC_FILTER=y
CONFIG_BT_BNEP_PROTO_FILTER=y
# vendor HCI extensions used by BlueZ, e.g. for LE advertisement monitoring
CONFIG_BT_MSFTEXT=y
CONFIG_BT_AOSPEXT=y

# needed by keyd, input remappers, some Bluetooth/HID tools, Waydroid and Steam
# Input; commonly expected to be there
CONFIG_INPUT_UINPUT=m
Loading