Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion builder/aarch64-package-filter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ filter_aarch64_packages() {
;;
amd-ucode|intel-ucode|syslinux|broadcom-wl|broadcom-wl-dkms|memtest86+|memtest86+-efi|edk2-shell|\
apple-bcm-firmware|apple-bcm-firmware-fetcher|apple-t2-audio-config|t2fanrd|tiny-dfr|macbook12-spi-driver-dkms|facetimehd-dkms|facetimehd-firmware-fetcher|\
asusctl|dell-xps13-sidecar-amps|linux-firmware-cirrus-dx13260|intel-ipu7-camera|intel-ipu7-drivers-dkms|linux-omarchy-ipu7|linux-omarchy-v4l2loopback|intel-lpmd|intel-media-driver|libva-intel-driver|vpl-gpu-rt|thermald|\
asusctl|dell-xps13-sidecar-amps|linux-firmware-cirrus-dx13260|intel-ipu7-camera|intel-ipu7-drivers-dkms|linux-omarchy-ipu7|intel-lpmd|intel-media-driver|libva-intel-driver|vpl-gpu-rt|thermald|\
linux-ptl|linux-ptl-headers|tuxedo-drivers-nocompatcheck-dkms|yt6801-dkms|\
nvidia-580xx-dkms|nvidia-580xx-utils|nvidia-dkms|lib32-*|vulkan-intel|vulkan-radeon|vulkan-asahi)
echo "aarch64: excluding x86-only package $package" >&2
Expand Down
155 changes: 150 additions & 5 deletions builder/build-root-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,141 @@ INSTALL
sort -u >"$root/var/lib/omarchy-iso/prebuilt-uki-n1x.modules"
}

# The Snapdragon UKI carries the arm64 kernel (63 MiB), the Qualcomm early
# modules, Adreno microcode and all Snapdragon device trees (~15 MiB), so it
# uses the same 256 MiB ceiling as the N1x UKI.
qualcomm_prebuilt_uki_size_ok() {
local bytes limit=$((256 * 1024 * 1024))
bytes=$(stat -c %s "$1")
if ((bytes > limit)); then
echo "ERROR: the Qualcomm pre-built UKI is $bytes bytes, over the $limit limit" >&2
return 1
fi
}

# Every early-loading module name named by the image's own mkinitcpio drop-ins
# and Omarchy's Qualcomm hardware scripts under $1, normalized (no ?, - -> _),
# excluding qcom_q6v5_pas: loading the DSP driver early resets USB-C controllers
# and breaks USB-root installs, so only machines that explicitly ask for it
# (Surface Laptop 8) build their own UKI with it.
qualcomm_module_names() {
local root=$1
python3 - "$root" <<'PY'
import pathlib, re, sys

root = pathlib.Path(sys.argv[1])
modules = set()

def extract(text):
for m in re.finditer(r"^\s*MODULES\s*\+?=\(([^)]*)\)", text, re.M | re.S):
for tok in m.group(1).split():
tok = tok.strip("'\"")
if not tok or tok.startswith("$") or tok.startswith("#"):
continue
name = tok.rstrip("?").replace("-", "_")
if re.fullmatch(r"[A-Za-z0-9_]+", name) and name != "qcom_q6v5_pas":
modules.add(name)

conf_dir = root / "etc" / "mkinitcpio.conf.d"
if conf_dir.is_dir():
for conf in sorted(conf_dir.glob("*.conf")):
extract(conf.read_text(errors="ignore"))

hw_dir = root / "usr" / "share" / "omarchy" / "install" / "hardware"
if hw_dir.is_dir():
for script in sorted(hw_dir.rglob("*.sh")):
text = script.read_text(errors="ignore")
if "omarchy-hw-aarch64-qualcomm" in text and "mkinitcpio" in text:
extract(text)

for name in sorted(modules):
print(name)
PY
}

# Adreno X1 / X2 GPU microcode shared by the Snapdragon display initramfs
# drop-ins (glymur-display.sh, hamoa-display.sh and board boot scripts), under
# 600 KiB total.
QUALCOMM_ADRENO_FIRMWARE=(
qcom/gen70500_sqe.fw
qcom/gen70500_gmu.bin
qcom/gen71500_sqe.fw
qcom/gen71500_gmu.bin
qcom/gen80100_sqe.fw
qcom/gen80100_gmu.bin
)

# Build /var/lib/omarchy-iso/prebuilt-uki-qualcomm.efi in a throwaway overlay
# of $root with all Snapdragon DTBs (DeviceTreeAuto), the Qualcomm early
# modules that exist as loadable modules in $image_kver, and the Adreno GPU
# microcode. Runs while the generic UKI's config and cmdline are still in $root.
build_qualcomm_uki_in() {
local merged=$1 _upper=$2 stub=/usr/lib/systemd-stub-omarchy/linuxaa64.efi.stub
local mod fn fw suffix dir dtb
local -a loadable_modules=() firmware_files=() recorded_firmware=() dtbs=()

[[ -f $merged$stub ]] || { echo "WARNING: $stub missing; skipping Qualcomm pre-built UKI" >&2; return 1; }
for dtb in "$merged/boot/dtbs/$image_kernel/qcom"/*.dtb; do
[[ -f $dtb ]] && dtbs+=("${dtb#"$merged"}")
done
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
((${#dtbs[@]} > 0)) || { echo "WARNING: no Qualcomm DTBs in $merged/boot/dtbs/$image_kernel/qcom; skipping Qualcomm pre-built UKI" >&2; return 1; }

# Resolve against $image_kver so systemd-modules-load never sees ? suffixes,
# built-ins or absent modules.
for mod in "${qcom_modules[@]}"; do
fn=$(modinfo --basedir "$merged" -k "$image_kver" -F filename "$mod" 2>/dev/null || true)
[[ $fn == /* ]] && loadable_modules+=("$mod")
done

for fw in "${QUALCOMM_ADRENO_FIRMWARE[@]}"; do
for suffix in '' .zst .xz; do
for dir in /usr/lib/firmware/updates /usr/lib/firmware; do
if [[ -f $merged$dir/$fw$suffix ]]; then
firmware_files+=("$dir/$fw$suffix")
recorded_firmware+=("$fw")
break 2
fi
done
done
done

sed -E "s/^MODULES=.*/MODULES=(${loadable_modules[*]})/" \
"$root/etc/mkinitcpio-prebuilt-uki.conf" >"$merged/etc/mkinitcpio-prebuilt-uki-qualcomm.conf" || return 1
if ((${#firmware_files[@]} > 0)); then
printf 'FILES+=(%s)\n' "${firmware_files[*]}" >>"$merged/etc/mkinitcpio-prebuilt-uki-qualcomm.conf" || return 1
fi

install -d "$merged/etc/kernel" || return 1
printf '[UKI]\nStub=%s\nDeviceTreeAuto=%s\n' "$stub" "${dtbs[*]}" \
>"$merged/etc/kernel/uki-prebuilt-qualcomm.conf" || return 1

echo "Pre-building the Qualcomm Snapdragon UKI (${#loadable_modules[@]} modules, ${#firmware_files[@]} firmware files, ${#dtbs[@]} DTBs)"
arch-chroot "$merged" mkinitcpio \
-k "/usr/lib/modules/${image_kver}/vmlinuz" \
-c /etc/mkinitcpio-prebuilt-uki-qualcomm.conf \
--cmdline /etc/kernel/cmdline.prebuilt-uki \
--ukiconfig /etc/kernel/uki-prebuilt-qualcomm.conf \
-U /var/lib/omarchy-iso/prebuilt-uki-qualcomm.efi \
-S autodetect 2>&1 | tail -25
[[ -f "$merged/var/lib/omarchy-iso/prebuilt-uki-qualcomm.efi" ]] || return 1
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
qualcomm_prebuilt_uki_size_ok "$merged/var/lib/omarchy-iso/prebuilt-uki-qualcomm.efi" || return 1
install -m 0644 "$merged/var/lib/omarchy-iso/prebuilt-uki-qualcomm.efi" \
"$root/var/lib/omarchy-iso/prebuilt-uki-qualcomm.efi" || return 1
echo "Pre-built Qualcomm UKI: $(du -h "$root/var/lib/omarchy-iso/prebuilt-uki-qualcomm.efi" | cut -f1)"
printf '%s\n' "${qcom_modules[@]}" | sort -u >"$root/var/lib/omarchy-iso/prebuilt-uki-qualcomm.modules"
printf '%s\n' "${recorded_firmware[@]}" | sort -u >"$root/var/lib/omarchy-iso/prebuilt-uki-qualcomm.files"
}

build_qualcomm_prebuilt_uki() {
local -a qcom_modules
mapfile -t qcom_modules < <(qualcomm_module_names "$root")
if ((${#qcom_modules[@]} == 0)); then
echo "WARNING: no Qualcomm initramfs modules found under $root" >&2
return 1
fi
with_image_overlay build_qualcomm_uki_in
}

# Build /var/lib/omarchy-iso/prebuilt-uki-n1x.efi from a throwaway overlay of
# $root. Runs while the generic UKI's config and cmdline are still in $root.
build_n1x_prebuilt_uki() {
Expand Down Expand Up @@ -777,11 +912,21 @@ CONF
>"$root/etc/kernel/cmdline.prebuilt-uki"

if [[ -n ${OMARCHY_SNAPDRAGON:-} ]]; then
# A Snapdragon ISO installs only Snapdragon laptops, whose platform builds
# its own UKI with board firmware and device trees, so shipping the generic
# ~116 MiB pre-built UKI only bloats the root image and slows image writes.
rm -f "$root/var/lib/omarchy-iso/prebuilt-uki.efi"
echo "Skipping generic pre-built UKI on Snapdragon image (platform builds its own)"
# A Snapdragon ISO installs only Snapdragon laptops, so skip the generic
# UKI and pre-build the Snapdragon UKI (all Snapdragon DTBs via
# DeviceTreeAuto + shared Qualcomm early modules + Adreno microcode) so
# standard Snapdragon installs copy it in place instead of spending ~7s
# running mkinitcpio + ukify on the target.
rm -f "$root/var/lib/omarchy-iso/prebuilt-uki.efi" \
"$root/var/lib/omarchy-iso/prebuilt-uki-qualcomm.efi" \
"$root/var/lib/omarchy-iso/prebuilt-uki-qualcomm.modules" \
"$root/var/lib/omarchy-iso/prebuilt-uki-qualcomm.files"
if ! build_qualcomm_prebuilt_uki; then
echo "WARNING: no Qualcomm pre-built UKI; Snapdragon installs will build their own"
rm -f "$root/var/lib/omarchy-iso/prebuilt-uki-qualcomm.efi" \
"$root/var/lib/omarchy-iso/prebuilt-uki-qualcomm.modules" \
"$root/var/lib/omarchy-iso/prebuilt-uki-qualcomm.files"
fi
else
echo "Pre-building the UKI in the image (kver=$image_kver, generic cmdline, systemd and sd-encrypt hooks, no autodetect)"
# mkinitcpio is called directly: the preset flow (-P) runs Limine's install
Expand Down
122 changes: 121 additions & 1 deletion configs/airootfs/usr/share/omarchy-iso/orchestrator/phases_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3836,6 +3836,119 @@ def _n1x_prebuilt_uki(target: Path, arm_platform: str) -> Path | None:
return uki if _initramfs_module_lines(target) == lines else None


# Drop-ins shipped by the base image (omarchy-settings / installer), not added
# by a Qualcomm laptop's hardware setup script.
_SYSTEM_MKINITCPIO_DROPINS = frozenset({
"00-omarchy-hooks.conf",
"i2c_hid_of_module.conf",
"omarchy_compression.conf",
"omarchy_hooks.conf",
"omarchy_mount_events.conf",
"omarchy_vconsole.conf",
"thunderbolt_module.conf",
"zz-omarchy-kernel-modules.conf",
})


def _qualcomm_hwid_matches(
target: Path,
dt_compatible_path: Path = Path("/sys/firmware/devicetree/base/compatible"),
) -> bool:
"""True when the running board's device-tree compatible is listed in the
target's systemd-stub HWID database, so DeviceTreeAuto selects its DTB
without needing a machine-specific DeviceTree= fallback."""
hwids_dir = target / "usr" / "lib" / "systemd" / "boot" / "hwids" / "aa64"
if not dt_compatible_path.is_file() or not hwids_dir.is_dir():
return False
try:
compatibles = {c for c in dt_compatible_path.read_bytes().decode("utf-8", errors="ignore").split("\x00") if c}
except OSError:
return False
if not compatibles:
return False
for path in hwids_dir.glob("*.json"):
try:
data = json.loads(path.read_text(encoding="utf-8", errors="ignore"))
except (OSError, ValueError):
continue
if data.get("compatible") in compatibles:
return True
return False


def _qualcomm_prebuilt_uki(
target: Path,
platform_name: str,
*,
dt_compatible_path: Path = Path("/sys/firmware/devicetree/base/compatible"),
) -> Path | None:
"""The image's Snapdragon UKI, for a Qualcomm laptop whose hardware setup
stays within what build-root-image.sh baked into it: covered early modules
(never qcom_q6v5_pas), no board-specific initcpio hooks beyond
omarchy-quiet-efivars (which is busybox-only), no board-specific or
Windows-extracted FILES beyond the baked Adreno microcode, no ADSP
blacklist modprobe override, and a matching HWID entry for DeviceTreeAuto.

Any machine needing extra hooks (Galaxy Book4 Edge 14), early DSP loading
(Surface Laptop 8), board-specific initramfs files (Surface Pro 11,
qcom-firmware.conf zap shader), or a DeviceTree= fallback returns None and
builds its own UKI via limine-mkinitcpio as before."""
uki = target / "var" / "lib" / "omarchy-iso" / "prebuilt-uki-qualcomm.efi"
recorded_mods_path = target / "var" / "lib" / "omarchy-iso" / "prebuilt-uki-qualcomm.modules"
recorded_files_path = target / "var" / "lib" / "omarchy-iso" / "prebuilt-uki-qualcomm.files"
if platform_name != "aarch64-qualcomm" or not uki.is_file() or not recorded_mods_path.is_file():
return None
if (target / "etc" / "mkinitcpio.conf.d" / "qcom-firmware.conf").exists():
return None
if (target / "etc" / "modprobe.d" / "qualcomm-adsp-nofw.conf").exists():
return None
if not _qualcomm_hwid_matches(target, dt_compatible_path=dt_compatible_path):
return None

covered_mods = {line.strip().replace("-", "_") for line in recorded_mods_path.read_text().splitlines() if line.strip()}
covered_files = (
{line.strip() for line in recorded_files_path.read_text().splitlines() if line.strip()}
if recorded_files_path.is_file() else set()
)
allowed_literal_files = covered_files | {"/etc/vconsole.conf", "/etc/systemd/system.conf.d/20-mount-events.conf"}

conf_dir = target / "etc" / "mkinitcpio.conf.d"
for conf in sorted(conf_dir.glob("*.conf")) if conf_dir.is_dir() else []:
text = conf.read_text(errors="ignore")
for match in re.finditer(r"^\s*MODULES\s*\+?=\(([^)]*)\)", text, re.M | re.S):
for tok in match.group(1).split():
tok = tok.strip("'\"")
if not tok or tok.startswith("$") or tok.startswith("#"):
continue
if tok.rstrip("?").replace("-", "_") not in covered_mods:
return None
if conf.name in _SYSTEM_MKINITCPIO_DROPINS:
continue
for match in re.finditer(r"^\s*HOOKS\s*\+?=\(([^)]*)\)", text, re.M | re.S):
for tok in match.group(1).split():
tok = tok.strip("'\"")
if tok and not tok.startswith("#") and tok != "omarchy-quiet-efivars":
return None
if "FILES" in text:
unwrapped = re.sub(r"\\\n", " ", text)
loop_items: list[str] = []
for match in re.finditer(r"\bfor\s+firmware\s+in\s+([^;\n]+);", unwrapped):
loop_items.extend(t.strip("'\"") for t in match.group(1).split() if t.strip("'\""))
if loop_items and not all(item in covered_files for item in loop_items):
return None
for match in re.finditer(r"^\s*FILES\s*\+?=\(([^)]*)\)", text, re.M | re.S):
for tok in match.group(1).split():
tok = tok.strip("'\"")
if not tok or tok.startswith("#"):
continue
if "$" in tok:
if not loop_items:
return None
elif tok not in allowed_literal_files:
return None
return uki


def _keymap_of(vconsole: Path) -> str:
"""KEYMAP= from a vconsole.conf, or "" when unset or unreadable."""
if not vconsole.is_file():
Expand Down Expand Up @@ -4246,6 +4359,13 @@ def finalize_limine_boot(ctx: InstallContext) -> None:
info("› N1x: using the image's N1x UKI, built with this machine's initramfs modules")
prebuilt_uki = n1x_uki
added_modules = []
# A Snapdragon ISO ships a Qualcomm UKI built with all Snapdragon DTBs
# (DeviceTreeAuto), shared Qualcomm early modules and Adreno microcode.
qualcomm_uki = _qualcomm_prebuilt_uki(ctx.target, hw_platform()) if not n1x_uki else None
if qualcomm_uki:
info("› Qualcomm: using the image's Snapdragon UKI, built with this machine's initramfs modules and device trees")
prebuilt_uki = qualcomm_uki
added_modules = []
if prebuilt_uki.is_file() and added_modules:
info(f"› hardware setup added initramfs modules ({'; '.join(added_modules)}); "
"building the UKI on this machine instead of using the pre-built one")
Expand Down Expand Up @@ -4306,7 +4426,7 @@ def _run_limine_install() -> None:
check=True,
)

if prebuilt_uki.is_file() and not skip_prebuilt and arch.has_uefi() and (n1x_uki or not _arm_platform_boot()):
if prebuilt_uki.is_file() and not skip_prebuilt and arch.has_uefi() and (n1x_uki or qualcomm_uki or not _arm_platform_boot()):
used_prebuilt_uki = True
limine_err: list[BaseException] = []

Expand Down
Loading
Loading