# Qualcomm Snapdragon 8cx Gen 3 Adreno 690 Qualcomm WCN685x Wi-Fi 6E Qualcomm Snapdragon X55 5G Bluetooth 5.1 declare -g BOARD_NAME="ThinkPad X13s" declare -g BOARD_MAINTAINER="PeterChrz rpardini" declare -g BOARDFAMILY="uefi-arm64" declare -g KERNEL_TARGET="sc8280xp" declare -g BOOT_LOGO=desktop ########################################################################################################### # Absolutely watch this video https://www.youtube.com/watch?v=qffWt4o334Y - jhovold explains it all there. # @TODO list # - cleanup the .config using jhovold's defconfig. # - consider dropping steev's kernel in favor of jhovold's. [DONE] # - rework the initramfs firmware/modules required, according to jhovold's defconfig-commit-msg instructions ########################################################################################################### # Userspace TO-DO: # - deploy fprintd/libpam-fprintd (sic) for fingerprint authentication [done] # - (ubuntu, mantic for sure): protection-domain-mapper's pd-mapper.service has a condition on "-laptop" kernel, use override to get rid of it [done] # This board boots via EFI/Grub, but requires a DTB to be passed, from Grub, to the Kernel. declare -g GRUB_CMDLINE_LINUX_DEFAULT="clk_ignore_unused pd_ignore_unused arm64.nopauth efi=noruntime" # iommu.passthrough=0 iommu.strict=0 pcie_aspm.policy=powersupersave declare -g BOOT_FDT_FILE="qcom/sc8280xp-lenovo-thinkpad-x13s.dtb" enable_extension "grub-with-dtb" # important, puts the whole DTB handling in place. # Use the full firmware, complete linux-firmware plus Armbian's declare -g BOARD_FIRMWARE_INSTALL="-full" function post_family_config_branch_sc8280xp__jhovolds_wip_kernel() { declare -g KERNEL_MAJOR_MINOR="6.15" # Major and minor versions of this kernel. declare -g KERNELBRANCH='branch:wip/sc8280xp-6.15' # @TODO: this is up to 47 patches, from 28 around 6.13; wait a bit until speculating about merging with uefi-arm64 declare -g KERNELSOURCE='https://github.com/jhovold/linux.git' declare -g LINUXCONFIG="linux-${ARCH}-${BRANCH}" # for this board: linux-arm64-sc8280xp display_alert "Set up jhovold's kernel ${KERNELBRANCH} for" "${BOARD}" "info" } function x13s_is_userspace_supported() { [[ "${RELEASE}" == "trixie" || "${RELEASE}" == "sid" || "${RELEASE}" == "noble" || "${RELEASE}" == "oracular" ]] && return 0 return 1 } # https://wiki.debian.org/InstallingDebianOn/Thinkpad/X13s function post_family_config__debian_now_has_userspace_for_the_x13s() { if ! x13s_is_userspace_supported; then if [[ "${RELEASE}" != "" ]]; then display_alert "Missing userspace for ${BOARD}" "${RELEASE} does not have the userspace necessary to support the ${BOARD}" "warn" fi return 0 fi display_alert "Setting up extra Debian packages for ${BOARD}" "${RELEASE}///${BOARD}" "info" add_packages_to_image "bluez" "bluetooth" # for bluetooth stuff add_packages_to_image "protection-domain-mapper" # for charging; see https://packages.ubuntu.com/protection-domain-mapper and https://packages.debian.org/protection-domain-mapper add_packages_to_image "qrtr-tools" # for charging; see https://packages.ubuntu.com/qrtr-tools and https://packages.debian.org/qrtr-tools add_packages_to_image "alsa-ucm-conf" # for audio; see https://packages.ubuntu.com/alsa-ucm-conf and https://packages.debian.org/alsa-ucm-conf - we need 1.2.10 + patches, see below add_packages_to_image "acpi" # general ACPI support add_packages_to_image "zstd" # for zstd compression of initrd add_packages_to_image "mtools" # for access to the EFI partition add_packages_to_image "fprintd" # for fingerprint reader; see https://packages.ubuntu.com/fprintd and https://packages.debian.org/fprintd add_packages_to_image "libpam-fprintd" # for fingerprint reader PAM support; see https://packages.ubuntu.com/libpam-fprintd and https://packages.debian.org/libpam-fprintd # Also needed, not listed here: # - mesa > 23.1.5; see https://packages.ubuntu.com/mesa-vulkan-drivers and https://packages.debian.org/mesa-vulkan-drivers } # Distros don't carry the necessary alsa-ucm-conf files. # We need https://github.com/alsa-project/alsa-ucm-conf/pull/335 # Specifically https://github.com/Srinivas-Kandagatla/alsa-ucm-conf.git branch x13s-volume-fixes # And specifically SHA1 e8c3e7792336e9f68aa560db8ad19ba06ba786bb -- it has been force pushed a few times # As quick-n-dirty solution, we dump the whole contents of that branch on top of the distro's alsa-ucm-conf. # This means the fixes will be lost if package is updated, so we apt-mark it to hold. # Also means that this will break when ucm package is actually updated, so we can remove this when it is upstreamed. function pre_customize_image__x13s_debian_ucm_hack_via_patch() { if ! x13s_is_userspace_supported; then return 0 fi # No longer needed for Trixie, as of 2024-08-29, Trixie already has 1.2.12 which is higher than the 1.2.11 needed. if [[ "${RELEASE}" == "trixie" ]]; then display_alert "No alsa-ucm-conf hacks needed for ${BOARD}" "${RELEASE} already has the necessary alsa-ucm-conf" "info" return 0 fi display_alert "Fixing alsa-ucm-conf for ${BOARD}" "${RELEASE}///${BOARD}" "warn" ( cd "${SDCARD}/usr/share/alsa" || exit 6 curl -L "https://github.com/alsa-project/alsa-ucm-conf/archive/refs/heads/master.tar.gz" | tar xvzf - --strip-components=1 ) chroot_sdcard "apt-mark hold alsa-ucm-conf" } function post_family_tweaks_bsp__thinkpad_x13s_bsp_bluetooth_addr() { ### The bluetooth does not have a public MAC address set in DT, and BT won't start without one. ### Use a systemd override to hook up setting a public-addr before starting bluetoothd declare random_mac_address="" # would be much better to rnd mac on board-side though random_mac_address=$(printf '02:%02X:%02X:%02X:%02X:%02X' $((RANDOM % 256)) $((RANDOM % 256)) $((RANDOM % 256)) $((RANDOM % 256)) $((RANDOM % 256))) display_alert "Adding systemd override for bluetooth public address init" "${BOARD} :: bt mac ${random_mac_address}" "info" add_file_from_stdin_to_bsp_destination "/etc/systemd/system/bluetooth.service.d/override.conf" <<- EOD [Service] ExecStartPre=/bin/bash -c 'sleep 5 && yes | btmgmt public-addr ${random_mac_address}' EOD } function post_family_tweaks_bsp__thinkpad_x13s_bsp_always_start_pdmapper() { ### (At least) Ubuntu's version of protection-domain-mapper's pd-mapper.service has a kernel condition. ### On Debian, this does not hurt. ### Remove it using a systemd override. add_file_from_stdin_to_bsp_destination "/etc/systemd/system/pd-mapper.service.d/override.conf" <<- EOD [Unit] Description=Qualcomm PD mapper service (always starts) ConditionKernelVersion= EOD } ## ## Include certain firmware in the initrd ## function post_family_tweaks_bsp__thinkpad_x13s_bsp_firmware_in_initrd() { display_alert "Adding to bsp-cli" "${BOARD}: firmware in initrd" "info" declare file_added_to_bsp_destination # will be filled in by add_file_from_stdin_to_bsp_destination add_file_from_stdin_to_bsp_destination "/etc/initramfs-tools/hooks/x13s-firmware" <<- 'FIRMWARE_HOOK' #!/bin/bash [[ "$1" == "prereqs" ]] && exit 0 . /usr/share/initramfs-tools/hook-functions for f in /lib/firmware/qcom/sc8280xp/LENOVO/21BX/* ; do add_firmware "${f#/lib/firmware/}" done add_firmware "qcom/a660_sqe.fw" # extra one for dpu add_firmware "qcom/a660_gmu.bin" # extra one for gpu add_firmware "qcom/a690_gmu.bin" # extra one for gpu (is a symlink) FIRMWARE_HOOK run_host_command_logged chmod -v +x "${file_added_to_bsp_destination}" } ## Modules, required to boot, add them to initrd; might need to be done in '.d/x13s-modules' instead function post_family_tweaks_bsp__thinkpad_x13s_bsp_modules_in_initrd() { display_alert "Adding to bsp-cli" "${BOARD}: modules in initrd" "info" add_file_from_stdin_to_bsp_destination "/etc/initramfs-tools/modules" <<- 'EXTRA_MODULES' # @TODO this list is outdated, much has changed; check jhovold's defconfig commit msg pwm_bl phy_qcom_qmp_pcie pcie_qcom phy_qcom qmp_pcie phy_qcom_qmp_combo qrtr phy_qcom_edp gpio_sbu_mux i2c_hid_of i2c_qcom_geni pmic_glink_altmode leds_qcom_lpg qcom_q6v5_pas # This module loads a lot of FW blobs panel_edp msm nvme usb_storage uas gpucc_sc8280xp dispcc_sc8280xp EXTRA_MODULES } # armbian-firstrun waits for systemd to be ready, but snapd.seeded might cause it to hang due to wrong clock. # if the battery runs out, the clock is reset to 1970. This causes snapd.seeded to hang, and armbian-firstrun to hang. function pre_customize_image__disable_snapd_seeded() { [[ "${DISTRIBUTION}" != "Ubuntu" ]] && return 0 # only needed for Ubuntu display_alert "Disabling snapd.seeded" "${BOARD}" "info" chroot_sdcard systemctl disable snapd.seeded.service "||" true } # Utility to get firmware needed; this is used to populate armbian/firmware, and is here for reference only. function x13s_obtain_firmware() { display_alert "Getting extra firmware for ${BOARD}" "${RELEASE}///${BOARD}" "info" declare fw_target="${SDCARD}/lib/firmware" mkdir -p "${fw_target}/qcom/sc8280xp/LENOVO/21BX" # video acceleration firmware/interconnect stuff; get it from ironrobin's repo; wget --output-document "${fw_target}/qcom/sc8280xp/LENOVO/21BX/qcvss8280.mbn" "https://raw.githubusercontent.com/ironrobin/x13s-alarm/trunk/x13s-firmware/qcvss8280.mbn" # add a link to audio fw (cd "${fw_target}/qcom/sc8280xp" && ln -s "LENOVO/21BX/audioreach-tplg.bin" "SC8280XP-LENOVO-X13S-tplg.bin") # gpu, link 690 to 660 gmu (cd "${fw_target}/qcom/" && ln -s a660_gmu.bin a690_gmu.bin) return 0 }