From 2d0181bbd39535929beabfe62bf83698a712f5a2 Mon Sep 17 00:00:00 2001 From: Sam & Claude Date: Thu, 4 Jun 2026 21:30:38 +0200 Subject: [PATCH] Prefer staged NVIDIA branch on dedicated live builds (Sam & Codex) --- build.sh | 4 ++ live/operator-session/clawdie-live-gpu | 77 +++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index cf4c2f1f..2782dd58 100755 --- a/build.sh +++ b/build.sh @@ -1512,6 +1512,8 @@ EOF set_config_line "${MOUNT_POINT}/etc/rc.conf" 'sddm_enable="YES"' set_config_line "${MOUNT_POINT}/etc/rc.conf" 'display_manager="sddm"' set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_live_gpu_enable="YES"' + set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_live_gpu_mode="auto"' + set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_live_gpu_nvidia_branch=""' set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_live_wifi_enable="YES"' set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_live_seed_enable="YES"' set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_enable="YES"' @@ -1552,6 +1554,8 @@ EOF acpi_video case "${GPU_DRIVER:-}" in nvidia-390|nvidia-470|nvidia-590) + set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_live_gpu_mode="nvidia"' + set_config_line "${MOUNT_POINT}/etc/rc.conf" "clawdie_live_gpu_nvidia_branch=\"${GPU_DRIVER#nvidia-}\"" append_rc_list_values "${MOUNT_POINT}/etc/rc.conf" kld_list \ nvidia-modeset nvidia ;; diff --git a/live/operator-session/clawdie-live-gpu b/live/operator-session/clawdie-live-gpu index a701026c..2970afc9 100644 --- a/live/operator-session/clawdie-live-gpu +++ b/live/operator-session/clawdie-live-gpu @@ -3,6 +3,7 @@ # Detect display hardware and load a conservative KMS module before SDDM. # Prefer integrated/open drivers so hybrid laptops boot the broadest path first; # keep NVIDIA proprietary loading opt-in by requiring an installed nvidia.ko. +# Dedicated NVIDIA-target images can override that preference in rc.conf. # PROVIDE: clawdie_live_gpu # REQUIRE: FILESYSTEMS devfs @@ -30,6 +31,47 @@ clawdie_live_gpu_display_blocks() ' } +clawdie_live_gpu_nvidia_block() +{ + echo "$1" | awk ' + BEGIN { RS = ""; IGNORECASE = 1 } + /(^|[[:space:]])vendor=0x10de([[:space:]]|$)/ { print; exit } + ' +} + +clawdie_live_gpu_nvidia_device_id() +{ + _block=$(clawdie_live_gpu_nvidia_block "$1") + [ -n "$_block" ] || return 1 + + echo "$_block" | grep -Eo 'chip=0x10de[0-9a-fA-F]+' | head -1 | cut -c11-14 +} + +clawdie_live_gpu_nvidia_branch_for_device() +{ + _device_id="$1" + [ -n "$_device_id" ] || return 1 + + _device_num=$(printf '%d' "0x$_device_id" 2>/dev/null || echo "0") + + if [ "$_device_num" -ge 8288 ]; then + echo "590" + return 0 + fi + + if [ "$_device_num" -ge 4928 ] && [ "$_device_num" -le 8582 ]; then + echo "470" + return 0 + fi + + if [ "$_device_num" -ge 4480 ] && [ "$_device_num" -le 5100 ]; then + echo "390" + return 0 + fi + + echo "590" +} + clawdie_live_gpu_has_pci_vendor() { _blocks="$1" @@ -48,6 +90,35 @@ clawdie_live_gpu_has_pci_vendor() clawdie_live_gpu_select_modules() { _blocks="$1" + _mode="${clawdie_live_gpu_mode:-auto}" + _nvidia_branch="${clawdie_live_gpu_nvidia_branch:-}" + + if [ "$_mode" = "safe" ]; then + clawdie_live_gpu_log "safe graphics mode requested; skipping KMS modules" + return 0 + fi + + if clawdie_live_gpu_has_pci_vendor "$_blocks" "0x10de"; then + _device_id=$(clawdie_live_gpu_nvidia_device_id "$_blocks" || true) + _detected_branch="" + if [ -n "$_device_id" ]; then + _detected_branch=$(clawdie_live_gpu_nvidia_branch_for_device "$_device_id" || true) + clawdie_live_gpu_log "detected NVIDIA device id: ${_device_id} (recommended branch: ${_detected_branch:-unknown})" + fi + + if [ -e /boot/modules/nvidia.ko ]; then + if [ -n "$_nvidia_branch" ] && [ -n "$_detected_branch" ] && [ "$_nvidia_branch" != "$_detected_branch" ]; then + clawdie_live_gpu_log "WARN: staged NVIDIA branch ${_nvidia_branch} does not match detected device recommendation ${_detected_branch}; skipping proprietary load" + elif [ "$_mode" = "nvidia" ]; then + echo "nvidia-modeset nvidia" + return 0 + fi + elif [ "$_mode" = "nvidia" ]; then + clawdie_live_gpu_log "WARN: NVIDIA mode requested but /boot/modules/nvidia.ko is missing" + fi + elif [ "$_mode" = "nvidia" ]; then + clawdie_live_gpu_log "WARN: NVIDIA mode requested but no NVIDIA display device was detected" + fi # Hybrid laptops often expose Intel or AMD integrated graphics plus a # discrete NVIDIA GPU. Prefer the integrated/open KMS path for live boot. @@ -70,9 +141,7 @@ clawdie_live_gpu_select_modules() if clawdie_live_gpu_has_pci_vendor "$_blocks" "0x10de"; then # NVIDIA packages are bundled in the offline repo, but the live image - # does not install a branch-specific NVIDIA kmod by default because the - # 390/470/current branches conflict. Only load NVIDIA if an operator or - # future build profile has installed a concrete branch into the rootfs. + # only loads a concrete branch when one was explicitly staged. if [ -e /boot/modules/nvidia.ko ]; then echo "nvidia-modeset nvidia" fi @@ -130,5 +199,7 @@ clawdie_live_gpu_start() load_rc_config "$name" : ${clawdie_live_gpu_enable:="NO"} +: ${clawdie_live_gpu_mode:="auto"} +: ${clawdie_live_gpu_nvidia_branch:=""} run_rc_command "$1" -- 2.45.3