Repository navigation
feat: Support for Windows on Arm laptops #642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ea0b8c2
2cb86b7
b6f110a
643ec22
37d25cb
4da5640
56c7004
6f36fa8
6523955
d5e179b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| #!/bin/sh | ||
|
obbardc marked this conversation as resolved.
Resolved
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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I didn't call that die() or fail() because I didn't want to exit 1.
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!
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'm trying to weigh the pros and cons :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
| 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" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -644,6 +644,21 @@ actions: | |
| {{- range $kernelpackage := split "," $kernelpackages }} | ||
| - {{$kernelpackage}} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- range $overlay := split "," $overlays }} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :-)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a normal APT command-line we could also use something like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've used
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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/ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: can we link to a tracking issue here at all?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: spurious newline
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed, thanks |
||
| # Omnivision sensor on Zenbooks | ||
| CONFIG_VIDEO_OV02C10=m | ||
|
|
||
|
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 | ||
Uh oh!
There was an error while loading. Please reload this page.