22 files changed, 424 insertions, 171 deletions
diff --git a/Fedora.kiwi b/Fedora.kiwi index 37d86a5..6ac2adb 100644 --- a/Fedora.kiwi +++ b/Fedora.kiwi @@ -15,7 +15,7 @@ <release-version>45</release-version> </preferences> <include from="this://./repositories/core.xml"/> - <include from="this://./repositories/kernel-surface.xml"/> + <include from="this://./repositories/kernel-sp12in.xml"/> <include from="this://./components/common.xml"/> <include from="this://./components/boot.xml"/> <include from="this://./components/desktops/common.xml"/> diff --git a/Jenkinsfile b/Jenkinsfile index 0797a5f..1732307 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,17 +14,16 @@ pipeline { B2_ENDPOINT = 'https://s3.eu-central-003.backblazeb2.com' AWS_DEFAULT_REGION = 'eu-central-003' - RPM_BUCKET = 'dist-sayagit-fedora-rpm' ISO_BUCKET = 'dist-sayagit-fedora-iso' + // Must match the <source path="..."/> in + // repositories/kernel-sp12in.xml. + KERNEL_SURFACE_REPO_URL = 'https://rpm.sayag.it/kernel-sp12in/fedora/45/aarch64' + // awscli2 sends CRC32 checksums by default, which B2 rejects. Ask for // them only where the S3 API requires them. AWS_REQUEST_CHECKSUM_CALCULATION = 'when_required' AWS_RESPONSE_CHECKSUM_VALIDATION = 'when_required' - - // Must match the <source path="dir://..."/> in - // repositories/kernel-surface.xml. - KERNEL_SURFACE_REPO = '/var/lib/kernel-surface-repo' } stages { @@ -68,37 +67,23 @@ spec: // The kernel-surface RPM is a build input, not // something this repository can produce: the image // installs kernel-surface by name and <ignore>s - // Fedora's kernel packages, so it has to be in the - // local repository before kiwi starts. The buckets - // stay private, so it is pulled with credentials - // rather than fetched over a public URL. - withCredentials([usernamePassword( - credentialsId: 'backblaze-b2-dist-rpm', - usernameVariable: 'AWS_ACCESS_KEY_ID', - passwordVariable: 'AWS_SECRET_ACCESS_KEY')]) { - sh ''' - set -eux - - dnf --assumeyes install awscli2 createrepo_c - - mkdir -p "${KERNEL_SURFACE_REPO}" - aws s3 sync --endpoint-url "${B2_ENDPOINT}" \\ - "s3://${RPM_BUCKET}/fedora/${IMAGE_VERSION}/aarch64/" \\ - "${KERNEL_SURFACE_REPO}/" \\ - --exclude '*' --include 'kernel-surface-*.rpm' + // Fedora's kernel packages. Its pipeline publishes + // it to rpm.sayag.it, which repositories/kernel-sp12in.xml + // points at directly, so there is nothing to stage + // here. Fail now rather than several minutes into + // kiwi on an unresolvable package name. + sh ''' + set -eux - # Say so here rather than letting kiwi fail - # several minutes later on an unresolvable - # package name. - if ! ls "${KERNEL_SURFACE_REPO}"/kernel-surface-*.rpm; then - echo "No kernel-surface RPM in ${RPM_BUCKET} for Fedora ${IMAGE_VERSION}." >&2 - echo "Run the kernel-surface pipeline first." >&2 - exit 1 - fi + dnf --assumeyes install curl - createrepo_c "${KERNEL_SURFACE_REPO}" - ''' - } + repomd="${KERNEL_SURFACE_REPO_URL}/repodata/repomd.xml" + if ! curl -fsS --retry 3 -o /dev/null "${repomd}"; then + echo "No kernel-surface repository at ${repomd}." >&2 + echo "Run the kernel-surface pipeline for Fedora ${IMAGE_VERSION} first." >&2 + exit 1 + fi + ''' sh ''' dnf --assumeyes install git kiwi kiwi-systemdeps distribution-gpg-keys @@ -165,7 +150,8 @@ spec: mv "${src}" "${dst}" ls -lh - s5cmd --endpoint-url "${B2_ENDPOINT}" cp \\ + /s5cmd --endpoint-url "${B2_ENDPOINT}" cp \\ + --content-type "application/x-iso9660-image" \\ "${dst}" \\ "s3://${ISO_BUCKET}/fedora/${IMAGE_VERSION}/aarch64/${dst}" ''' @@ -1,9 +1,13 @@ # Fedora KIWI image descriptions, modified to build & launch for Surface Pro 12" Gen 1 + + +**UPD Sep 10 2026:** There has been huge progress made in this project since August! Thanks to kernel patches, pushed onto Linux 7.2 mainstream and [Gentoo overlay](https://github.com/miasvanklei/Gentoo-overlay), most of the previous features which this release lacked (stable suspend on GNOME, accelerometer sensor, dedicated video output, cameras) are now implemented. The project has diverged into [patched kernel](https://sayag.it/fedora-linux-surface-pro-12in/kernel-surface.git) + [libcamera](https://sayag.it/fedora-linux-surface-pro-12in/libcamera.git) builds with an [RPM repo](https://rpm.sayag.it/kernel-sp12in/) publicly available. You can see current state of things in a [feature matrix](#feature-matrix) down below. +  -It is the fork of the original [KIWI image descriptions](https://forge.fedoraproject.org/releng/kiwi-descriptions), modified for launching Fedora Linux Rawhide Live ISO on Surface Pro 12" Gen 1 (and further installing it on the device). +It is the fork of the original [KIWI image descriptions](https://forge.fedoraproject.org/releng/kiwi-descriptions), modified for launching Fedora Linux 45 Live ISO on Surface Pro 12" Gen 1 (and further installing it on the device). I bought this device as I viewed it as a great Linux GNOME tablet, but after several days, many hours of work of trying to do so, I must say that installing a distribution here (and then having it work fine) is a huge pain in the ass. @@ -11,9 +15,9 @@ I bought this device as I viewed it as a great Linux GNOME tablet, but after sev ## How to run -**The compiled ISOs can be downloaded [here](https://dist.sayag.it/surface-pro-12in-ports/fedora/rawhide).** +**The compiled ISOs can be downloaded [here](https://dist.sayag.it/fedora/45/aarch64).** -This KIWI project is built mainly on the base of Fedora Workstation Rawhide LiveCD ISO. Trying a stable version (the latest is Fedora 44 at the time of writing this) is possible, but not tested for now. +This KIWI project is built mainly on the base of Fedora Workstation 45 (Pre-release) LiveCD ISO. Trying a stable version (the latest is Fedora 44 at the time of writing this) is possible, but not tested for now. If you want to compile this image manually, **the build arch must be `aarch64`**. It means that if you are on an `amd64` machine, you would have to use aarch64 instructions emulation tools like `binfmt`. Unfortunately, such a tool will drastically increase the compilation time. @@ -30,26 +34,47 @@ To build this on Fedora Linux: []$ sudo ./kiwi-build --kiwi-file=Fedora.kiwi --image-type=iso --image-profile=Workstation-Live --output-dir ./outdir ``` -## What is left out (for now) +## Feature matrix + +| Hardware | State | Nuances | +| --- | --- | --- | +| Keyboard | ✓ | | +| Touchpad | ✓ | | +| Tablet Mode | ✓ | | +| Touchscreen | ✓ | | +| Pen | ✓ | Tested with Surface Slim Pen | +| WiFi | ✓ | 2.4/5 GHz networks | +| Bluetooth | ✓ | | +| Speakers | ✓ | | +| Buttons | ✓ | | +| Suspend | ✓ | `s2idle` tested | +| Hibernate | ? | | +| Sensors | ✓ | Accelerometer works, but light sensor outputs garbage, so adaptive brightness is disabled | +| Battery Status | ✓ | | +| Cameras | ✓ | Front camera -- overexposured areas tend to get green; back camera -- uncalibrated | +| GPU acceleration | ✓ | Video encoding/decoding driver is taken dynamically from a Windows partition | +| USB 3 | ✓ | Video passthrough on hubs (via HDMI) also tested and works | +| DisplayPort out | ✓ | Found issues with suspending while an external monitor is active, where the system freezes | + +## Compromises * Live CD has to run in RAM, so `rd.live.ram=1` is set for cmdline. Otherwise, at least on my ancient flash drive, it fails to load multiple necessary services, including `polkit`. So, ~5 minutes of loading on USB 2 drive, while screen is not backlit, is to be expected. * No rescue vmlinuz. * No secure boot possible for this ISO for now, as the platform used is `efi` and not `uefi`. * No GRUB auto hidden menu. Trying to have the menu hidden results in system restarting after trying to boot it. -* `wireupcameras.service` (which enables tablet's cameras to be used) fails on installed system (not in Live CD though), as no `/dev/media*` gets initialized. -* No hardware video encoding/decoding for now, as the iris video codec (`qcvss8380_pa.mbn`) is Windows-only (as far as I researched), but you can copy one from `/path/to/mounted/windows/drive/Windows/System32/DriverStore/FileRepository/qcdx8380.inf_arm64_*/qcvss8380_pa.mbn` to `/lib/firmware/qcom/x1p42100/Microsoft/Surface12/`, if you keep Windows ARM64 partition. -* Suspend on Snapdragon X is still very unstable. No deep sleep is available, so `mem_sleep_default=s2idle` was set. Even that leads to compromises as suspending via GNOME results in hard freeze, so the default power button behavior was changed to `interactive` and should not be changed back to `suspend`. +* Hardware video encoding/decoding needs a firmware blob the image is not allowed to ship. The `qcom/vpu/vpu30_p1_s7.mbn` that `linux-firmware` provides is the same codec signed with Qualcomm's SecTools *test* key chain, which a retail Surface's TrustZone rejects -- `qcom_scm_pas_init_image()` fails and the kernel logs `qcom-iris aa00000.video-codec: error -22 initializing firmware`. The production-signed build exists only inside Microsoft's Surface driver package, which grants no redistribution right, so what ships here is the means and not the blob: + * If you kept the Windows ARM64 partition, `surface-video-firmware.service` finds it on the first boot after install and copies `qcvss8380_pa.mbn` out of its DriverStore. Nothing to do. + * If Windows is gone, download the [Surface Pro 12-inch driver pack](https://www.microsoft.com/en-us/download/details.aspx?id=108199) (~500 MB MSI) and run `sudo surface-video-firmware.sh -m /path/to/SurfacePro_12in_*.msi`. + + The kernel's device tree already points `iris` at `/lib/firmware/qcom/x1p42100/Microsoft/Surface12/qcvss8380_pa.mbn`, so the driver picks it up as soon as it is there. +* Explicitly set `s2idle` suspend mode, as `deep` mode did not work properly as of August (when the iso was built without kernel patches). Currently untested if `deep` mode works now. +* No 6 GHz network support (at least my device does not detect mine). +* Adaptive brightness is disabled, as of now the light sensor outputs garbage. ## Image variants Please look at [`VARIANTS`](VARIANTS.md) for details on the available configurations that can be built. -## CI information - -This project is yet to adapt CI, but it is coming. - -For now the images are being built and tested manually on my personal Surface Pro 12" Gen 1 (16 GB RAM, 512 GB storage). - ## Licensing This is free software: you can redistribute it and/or modify diff --git a/components/boot.xml b/components/boot.xml index 36d8ffa..11b48a5 100644 --- a/components/boot.xml +++ b/components/boot.xml @@ -50,7 +50,7 @@ set for this board (device tree, SAM RTC, SAM suspend workaround, CAMSS/CSI-2, remoteproc attach, clk/PCI/irqchip fixes). It is built from the sibling ../kernel-surface checkout and comes from the repository - repositories/kernel-surface.xml adds. + repositories/kernel-sp12in.xml adds. It is a single package (kernel image, every module, device trees) and Provides kernel, kernel-core, kernel-modules, kernel-modules-core and @@ -436,10 +436,13 @@ fi # Surface Pro 12" customizations #-------------------------------------- +install -Dm644 /tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/yum.repos.d/kernel-sp12in.repo \ + /etc/yum.repos.d/kernel-sp12in.repo + # Device tree. kernel-surface compiles the patched dts in-tree and installs the -# result twice: into its own module tree (dtb/qcom, from dtbs_install) and -# version-independently into /usr/lib/surface-dtb. The latter is the master copy -# 60-surface-dtb.install re-stages into each new kernel's module tree on update, +# result twice: into its own module tree (dtb/qcom, from dtbs_install) and into +# /usr/lib/surface-dtb/<kver>/. The latter is the master copy +# 60-surface-dtb.install re-stages into a kernel that shipped without one, # which is the only reason the image no longer carries a prebuilt blob of its # own -- the description installs kernel-surface by name and <ignore>s Fedora's # kernel packages, so the package is always there. @@ -453,9 +456,12 @@ fi # module-tree copy, anything keyed off /usr/lib/modules/$kver/dtb (including the # anaconda post-script) finds nothing and silently does nothing. dtb_name=x1p42100-microsoft-sp12in.dtb -dtb_src="/usr/lib/surface-dtb/$dtb_name" -if [[ ! -f "$dtb_src" ]]; then - printf 'Error: %s is missing, so kernel-surface (built from ../kernel-surface) is not installed.\n' "$dtb_src" >&2 +# One directory per kernel version under /usr/lib/surface-dtb: kernel-surface is +# installonly, so nothing it owns can be version-unqualified. Only one release is +# ever installed at this point in the build, but glob anyway rather than assume. +dtb_src=$(ls -1 /usr/lib/surface-dtb/*/"$dtb_name" 2>/dev/null | sort -V | tail -n1) +if [[ -z "$dtb_src" ]]; then + printf 'Error: no %s under /usr/lib/surface-dtb/, so kernel-surface (built from ../kernel-surface) is not installed.\n' "$dtb_name" >&2 exit 1 fi install -Dm644 "$dtb_src" "/usr/lib/modules/$kver/dtb/qcom/$dtb_name" @@ -638,33 +644,84 @@ install -Dm644 /tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system # hexagonrpc.service in through the drop-in above. systemctl enable hexagonrpc.service -# Rear camera pipeline (msm/camss) needs /dev/media0, which only exists once the -# real silicon probes on the booted system -- install the wiring but do not run -# it here, there is no camera hardware in the KIWI build chroot. +# Fedora's SELinux policy has no qipcrtr_socket permissions for +# iiosensorproxy_t; the libssc backend needs them to probe the QRTR bus, and +# without them the daemon exits with "No sensors or missing kernel drivers". +# Compile and install the local module that grants them (see the .te for +# details). checkmodule/semodule_package come from checkpolicy; it stays +# installed because removing it takes policycoreutils-python-utils +# (semanage, audit2allow) with it. +dnf install -y checkpolicy +install -Dm644 /tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/local/share/selinux/iio-qipcrtr.te \ + /usr/local/share/selinux/iio-qipcrtr.te +checkmodule -M -m -o /usr/local/share/selinux/iio-qipcrtr.mod \ + /usr/local/share/selinux/iio-qipcrtr.te +semodule_package -o /usr/local/share/selinux/iio-qipcrtr.pp \ + -m /usr/local/share/selinux/iio-qipcrtr.mod +semodule -i /usr/local/share/selinux/iio-qipcrtr.pp + +# Cameras (msm/camss). Nothing has to be wired up at boot. libcamera's "simple" +# pipeline handler claims qcom-camss and builds the media graph itself in +# configure(), including flipping the csiphy -> msm_csid0 link between the rear +# ov13858 and the front ov02c10, so a media-ctl unit only fights it: pinning +# csid0 to the rear sensor at boot leaves the front camera disconnected until +# something re-links it, and the formats such a unit has to guess are what made +# the old wireupcameras.service die with "Unable to setup formats: Invalid +# argument (22)" on every boot. +# +# v4l-utils stays, for inspecting the graph by hand -- media-ctl -p, and +# v4l2-ctl --stream-mmap on the RDI node to check the sensor below libcamera. dnf install -y v4l-utils -install -Dm755 /tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/local/bin/wireupcameras.sh \ - /usr/local/bin/wireupcameras.sh -install -Dm644 /tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system/wireupcameras.service \ - /etc/systemd/system/wireupcameras.service -systemctl enable wireupcameras.service -# Suspend on Snapdragon is still very unstable. This is the reason why -# 'mem_sleep_default=s2idle' is set explicitly in the cmdline as 'deep' mode -# does not function at all. -# Even then, suspending via gnome settings daemon results in hard freeze. -# This is why: -# logind behavior is kept intact with suspend behavior. -# gnome default power button behavior was replaced with 'interactive'. +# The front ov02c10 needs a libcamera that knows its analogue gain model and +# black level; upstream libcamera has neither, and there is no plugin mechanism +# for them, but kernel-sp12in repo offers libcamera with supported models. +# Pulled in by name because it would otherwise only arrive as a dependency, +# which makes it easy to lose without noticing. +dnf install -y libcamera libcamera-ipa + +libcamera_nevra=$(rpm -q libcamera) +case "${libcamera_nevra}" in + *.sp12in*) printf 'Using %s\n' "${libcamera_nevra}" ;; + *) + printf 'Error: %s is Fedora'"'"'s libcamera, not the sp12in rebuild.\n' \ + "${libcamera_nevra}" >&2 + printf 'Fedora has probably bumped the release past the rebuild; rebase\n' >&2 + printf 'patches/ in ../libcamera and tag a new release suffix.\n' >&2 + exit 1 + ;; +esac + +# Hardware video decode needs firmware this image is not allowed to carry. The +# qcom/vpu/vpu30_p1_s7.mbn in linux-firmware is the same codec signed with +# Qualcomm's SecTools test keys, which a retail Surface's TrustZone rejects, and +# the production-signed build exists only inside Microsoft's Surface driver +# package, under terms that grant no redistribution right. +# +# So the image ships the means rather than the blob: a script that copies it out +# of a Windows install the owner already has a licence for, and a unit that runs +# that once on a dual-boot machine. Where Windows is gone, the script says which +# driver pack to download and how to point it at one. +dnf install -y msitools +install -Dm755 /tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/local/bin/surface-video-firmware.sh \ + /usr/local/bin/surface-video-firmware.sh +install -Dm644 /tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system/surface-video-firmware.service \ + /etc/systemd/system/surface-video-firmware.service +systemctl enable surface-video-firmware.service + install -Dm644 /tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/logind.conf.d/60-surface-power-key.conf \ - /etc/systemd/login.conf.d/60-surface-power-key.conf -install -Dm644 /tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/dconf/db/local.d/00-power-button \ - /etc/dconf/db/local.d/00-power-button + /etc/systemd/logind.conf.d/60-surface-power-key.conf + +# Ambient light sensor seems to go nuts after I fixed iio-sensor-proxy. Turning +# it off for now. +install -Dm644 /tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/dconf/db/local.d/00-als \ + /etc/dconf/db/local.d/00-als install -Dm644 /tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/dconf/profile/user \ /etc/dconf/profile/user dconf update -restorecon -Rv /usr /lib /etc/systemd /etc/dconf /etc/udev/rules.d +restorecon -Rv /usr /lib /etc/systemd /etc/dconf /etc/udev/rules.d /etc/yum.repos.d #====================================== # Set the WSL name for ELN diff --git a/docs/Fedora45Progress.jpg b/docs/Fedora45Progress.jpg Binary files differnew file mode 100644 index 0000000..0f4a22b --- /dev/null +++ b/docs/Fedora45Progress.jpg diff --git a/iio-qipcrtr.pp b/iio-qipcrtr.pp Binary files differnew file mode 100644 index 0000000..9eedadb --- /dev/null +++ b/iio-qipcrtr.pp diff --git a/iio-qipcrtr.te b/iio-qipcrtr.te new file mode 100644 index 0000000..5ea7434 --- /dev/null +++ b/iio-qipcrtr.te @@ -0,0 +1,20 @@ + +module iio-qipcrtr 1.0; + +require { + type iiosensorproxy_t; + type systemd_userdbd_t; + type xdm_var_run_t; + class sock_file read; + class qipcrtr_socket { create getattr getopt setopt }; +} + +#============= iiosensorproxy_t ============== + +#!!!! This avc is allowed in the current policy +allow iiosensorproxy_t self:qipcrtr_socket { create getattr getopt setopt }; + +#============= systemd_userdbd_t ============== + +#!!!! This avc is allowed in the current policy +allow systemd_userdbd_t xdm_var_run_t:sock_file read; diff --git a/repositories/kernel-sp12in.xml b/repositories/kernel-sp12in.xml new file mode 100644 index 0000000..2419e06 --- /dev/null +++ b/repositories/kernel-sp12in.xml @@ -0,0 +1,6 @@ +<image> + <!-- Surface Pro 12" (Snapdragon X1P-42-100): the patched kernel + libcamera.--> + <repository type="rpm-md" alias="kernel-surface" priority="1"> + <source path="https://rpm.sayag.it/kernel-sp12in/fedora/$releasever/aarch64/"/> + </repository> +</image> diff --git a/repositories/kernel-surface.xml b/repositories/kernel-surface.xml deleted file mode 100644 index f92c1b0..0000000 --- a/repositories/kernel-surface.xml +++ /dev/null @@ -1,31 +0,0 @@ -<image> - <!-- Surface Pro 12" (Snapdragon X1P-42-100): the patched kernel. - Built from the sibling ../kernel-surface checkout (see that directory's - README.md). components/boot.xml installs kernel-surface by name and - ignores Fedora's kernel packages, so this repository is not optional: - without it the image cannot depsolve at all. - - priority="1" beats the fedora/updates repositories, which carry no - priority and therefore sit at dnf's default 99 (lower number wins). - - A local directory repository, which is what a plain `createrepo_c` over - a directory of RPMs produces. In CI the Jenkinsfile fills it from the - dist-sayagit-fedora-rpm B2 bucket that the kernel-surface pipeline - publishes to, then runs createrepo_c, all before kiwi starts. The - bucket stays private, so the RPM is pulled with credentials instead of - this description pointing at a public URL. By hand: - - sudo mkdir -p /var/lib/kernel-surface-repo - sudo cp ~/rpmbuild/RPMS/aarch64/kernel-surface-*.rpm \ - /var/lib/kernel-surface-repo/ - sudo createrepo_c /var/lib/kernel-surface-repo - - The path has to exist on the build host before kiwi starts; kiwi binds - a dir:// repository into the image root at the same path. It has no - <signing> element, so kiwi configures it with gpgcheck off. Changing - the path here means changing KERNEL_SURFACE_REPO in the Jenkinsfile - too. --> - <repository type="rpm-md" alias="kernel-surface" priority="1"> - <source path="dir:///var/lib/kernel-surface-repo"/> - </repository> -</image> diff --git a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/dconf/db/local.d/00-power-button b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/dconf/db/local.d/00-als index 1b69eab..ae14928 100644 --- a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/dconf/db/local.d/00-power-button +++ b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/dconf/db/local.d/00-als @@ -1,2 +1,2 @@ [org/gnome/settings-daemon/plugins/power] -power-button-action='interactive' +ambient-enabled=false diff --git a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system/hexagonrpc.service b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system/hexagonrpc.service index 2e3cf82..4ec7250 100644 --- a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system/hexagonrpc.service +++ b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system/hexagonrpc.service @@ -1,8 +1,9 @@ [Unit] Description=HexagonRPC Service +ConditionPathExists=/dev/fastrpc-adsp [Service] -ExecStart=/usr/local/bin/hexagonrpcd -f /dev/fastrpc-adsp-secure -s +ExecStart=/usr/local/bin/hexagonrpcd -f /dev/fastrpc-adsp -d adsp -s Restart=on-failure [Install] diff --git a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system/surface-video-firmware.service b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system/surface-video-firmware.service new file mode 100644 index 0000000..5c83962 --- /dev/null +++ b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system/surface-video-firmware.service @@ -0,0 +1,12 @@ +[Unit] +Description=Install Surface Pro 12in video codec firmware from a Windows partition +ConditionPathExists=!/lib/firmware/qcom/x1p42100/Microsoft/Surface12/qcvss8380_pa.mbn +After=local-fs.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/bin/surface-video-firmware.sh + +[Install] +WantedBy=multi-user.target diff --git a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system/wireupcameras.service b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system/wireupcameras.service deleted file mode 100644 index 31eff6c..0000000 --- a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/systemd/system/wireupcameras.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Wire up Surface Pro rear camera (media-ctl pipeline) - -[Service] -Type=oneshot -ExecStart=/usr/local/bin/wireupcameras.sh -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target diff --git a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/udev/rules.d/61-sensors-surface-pro-12-inch.rules b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/udev/rules.d/61-sensors-surface-pro-12-inch.rules index e6ddb1f..82051c5 100644 --- a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/udev/rules.d/61-sensors-surface-pro-12-inch.rules +++ b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/udev/rules.d/61-sensors-surface-pro-12-inch.rules @@ -1 +1,3 @@ -ACTION=="add|change", SUBSYSTEM=="misc", KERNEL=="fastrpc-adsp-secure", ENV{ACCEL_MOUNT_MATRIX}="-1, 0, 0; 0, -1, 0; 0, 0, 1" +ACTION=="add|change", SUBSYSTEM=="misc", KERNEL=="fastrpc-adsp*", ENV{ACCEL_MOUNT_MATRIX}="-1, 0, 0; 0, -1, 0; 0, 0, 1" +SUBSYSTEM=="misc", KERNEL=="fastrpc-adsp*", ENV{IIO_SENSOR_PROXY_TYPE}+="ssc-accel" +ACTION=="add", SUBSYSTEM=="misc", KERNEL=="fastrpc-adsp", TAG+="systemd", ENV{SYSTEMD_WANTS}+="hexagonrpc.service" diff --git a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/yum.repos.d/kernel-sp12in.repo b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/yum.repos.d/kernel-sp12in.repo new file mode 100644 index 0000000..24fe9f3 --- /dev/null +++ b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/etc/yum.repos.d/kernel-sp12in.repo @@ -0,0 +1,7 @@ +[kernel-sp12in] +name=kernel-sp12in for Fedora $releasever - $basearch +baseurl=https://rpm.sayag.it/kernel-sp12in/fedora/$releasever/$basearch/ +enabled=1 +priority=1 +gpgcheck=0 +metadata_expire=6h diff --git a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/lib/kernel/install.d/60-surface-dtb.install b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/lib/kernel/install.d/60-surface-dtb.install index 2dadac5..7622406 100644 --- a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/lib/kernel/install.d/60-surface-dtb.install +++ b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/lib/kernel/install.d/60-surface-dtb.install @@ -8,23 +8,30 @@ KVER="$2" DTB_NAME=x1p42100-microsoft-sp12in.dtb DEST="/usr/lib/modules/${KVER}/dtb/qcom/${DTB_NAME}" -# The master copy comes from kernel-surface: it builds the dtb in-tree from the +# The master copies come from kernel-surface: it builds the dtb in-tree from the # patched dts and installs it under /usr/lib/surface-dtb, deliberately outside -# any /usr/lib/modules/<kver>, so it can be re-staged into any kernel installed -# alongside it. -SRC="/usr/lib/surface-dtb/${DTB_NAME}" -[ -f "${SRC}" ] || SRC="" +# any /usr/lib/modules/<kver>, so it can be re-staged into a kernel that ships +# no device tree of its own -- a stock Fedora one. +# +# One directory per kernel version, because kernel-surface is installonly and +# rpm will not let two installed releases own one unqualified path once the file +# differs. They are all the same board, so the highest version is as good a +# choice as any, and is the one most likely to carry recent fixes. +SRC=$(ls -1 /usr/lib/surface-dtb/*/"${DTB_NAME}" 2>/dev/null | sort -V | tail -n1) case "${COMMAND}" in add) - # No master and no dtb already in this kernel's tree means there is - # nothing this board can boot with, so say so rather than failing - # silently three steps later in the boot loader. + # kernel-surface ships its own dtb through dtbs_install, and that + # one is the release-matched copy. Leave it alone; the master is + # only for kernels that arrived without one. + if [ -f "${DEST}" ]; then + exit 0 + fi + # Neither means there is nothing this board can boot with, so say + # so rather than failing silently three steps later in the boot + # loader. if [ -z "${SRC}" ]; then - if [ -f "${DEST}" ]; then - exit 0 - fi - echo "60-surface-dtb: no ${DTB_NAME} in /usr/lib/surface-dtb" >&2 + echo "60-surface-dtb: no ${DTB_NAME} under /usr/lib/surface-dtb" >&2 exit 1 fi mkdir -p "$(dirname ${DEST})" diff --git a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/lib/kernel/install.d/95-surface-dtb-patch.install b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/lib/kernel/install.d/95-surface-dtb-patch.install index f0314b0..65b8745 100644 --- a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/lib/kernel/install.d/95-surface-dtb-patch.install +++ b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/lib/kernel/install.d/95-surface-dtb-patch.install @@ -38,9 +38,10 @@ BOOT_ROOT="${KERNEL_INSTALL_BOOT_ROOT:-/boot}" # (or was removed). DTB_SRC="/usr/lib/modules/${KVER}/dtb/${DTB_REL}" if [ ! -f "$DTB_SRC" ]; then - DTB_SRC="/usr/lib/surface-dtb/$DTB_NAME" + # One directory per kernel version under here; see 60-surface-dtb.install. + DTB_SRC=$(ls -1 /usr/lib/surface-dtb/*/"$DTB_NAME" 2>/dev/null | sort -V | tail -n1) fi -[ -f "$DTB_SRC" ] || exit 0 +[ -n "$DTB_SRC" ] && [ -f "$DTB_SRC" ] || exit 0 # The boot loader reads the dtb from the boot filesystem, not the module tree install -Dm644 "$DTB_SRC" "${BOOT_ROOT}/dtb-${KVER}/${DTB_REL}" diff --git a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/local/bin/surface-video-firmware.sh b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/local/bin/surface-video-firmware.sh new file mode 100755 index 0000000..35dfdf1 --- /dev/null +++ b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/local/bin/surface-video-firmware.sh @@ -0,0 +1,183 @@ +#!/bin/bash +# Surface Pro 12" (Snapdragon X1P-42-100): install the video codec firmware. +# +# The iris video codec needs firmware TrustZone will accept. linux-firmware's +# qcom/vpu/vpu30_p1_s7.mbn is the same codec signed with Qualcomm's SecTools +# *test* key chain, which a retail Surface rejects: +# +# qcom-iris aa00000.video-codec: error -22 initializing firmware qcom/vpu/vpu30_p1_s7.mbn +# +# The production-signed build ships only inside Microsoft's Surface driver +# package, which grants no redistribution right, so the image cannot carry it. +# What it can do is copy it out of a Windows install the owner already has a +# licence for, or out of a driver pack they downloaded themselves. This script +# does the copying; it never fetches anything the caller did not ask for. +# +# Usage: surface-video-firmware.sh [-m MSI] [-u URL] [-n] +# +# (no options) look for a Windows partition on this machine and copy the +# firmware out of its DriverStore. No network access. +# -m MSI extract from a Surface driver pack already on disk +# -u URL download a driver pack and extract from that +# -n say what would happen, change nothing +# +# The driver pack is a ~500 MB MSI from +# +# https://www.microsoft.com/en-us/download/details.aspx?id=108199 +# +# There is no stable direct link to hardcode: the Download Center hands out +# per-session URLs and the file name carries the driver release, so -u takes +# the URL the browser was given rather than guessing one that would rot. + +set -euo pipefail + +FW_DIR=/lib/firmware/qcom/x1p42100/Microsoft/Surface12 +BLOB=qcvss8380_pa.mbn +DRIVERSTORE=Windows/System32/DriverStore/FileRepository +PAGE=https://www.microsoft.com/en-us/download/details.aspx?id=108199 + +msi="" +url="" +dry_run=false + +while getopts ':m:u:nh' opt; do + case "${opt}" in + m) msi=${OPTARG} ;; + u) url=${OPTARG} ;; + n) dry_run=true ;; + h) sed -n '2,31p' "${BASH_SOURCE[0]}"; exit 0 ;; + *) echo "unknown option -${OPTARG}" >&2; exit 2 ;; + esac +done + +log() { printf 'surface-video-firmware: %s\n' "$*"; } +die() { printf 'surface-video-firmware: %s\n' "$*" >&2; exit 1; } + +if [[ -f "${FW_DIR}/${BLOB}" ]]; then + log "${FW_DIR}/${BLOB} is already installed" + exit 0 +fi + +[[ ${EUID} -eq 0 ]] || die "must run as root" + +cleanup_dirs=() +cleanup_mounts=() +cleanup() { + local m d + for m in ${cleanup_mounts[@]+"${cleanup_mounts[@]}"}; do + mountpoint -q "${m}" && umount "${m}" || true + done + for d in ${cleanup_dirs[@]+"${cleanup_dirs[@]}"}; do + rm -rf "${d}" || true + done +} +trap cleanup EXIT + +install_blob() { + local src=$1 + if [[ ${dry_run} == true ]]; then + log "would install ${src} as ${FW_DIR}/${BLOB}" + return 0 + fi + + install -Dm644 "${src}" "${FW_DIR}/${BLOB}" + log "installed ${FW_DIR}/${BLOB}" + + # The driver only asks for its firmware while probing, so it has to be + # reloaded to pick this up. It refuses while a decode session holds it, + # which is why a failure here is only worth a note. + if lsmod | grep -q '^qcom_iris'; then + if modprobe -r qcom_iris 2>/dev/null && modprobe qcom_iris 2>/dev/null; then + log "reloaded qcom_iris" + else + log "could not reload qcom_iris; reboot to start using the firmware" + fi + fi +} + +# Everything below hands find(1) the bare file name rather than a full path: +# the DriverStore directory carries a per-build hash, and the layout inside an +# extracted MSI is not documented anywhere worth trusting. +find_blob() { + find "$1" -type f -name "${BLOB}" -print -quit 2>/dev/null +} + +from_windows() { + local dev fstype part_mnt mnt found + + while read -r dev fstype part_mnt; do + [[ ${fstype} == ntfs* ]] || continue + + if [[ -n ${part_mnt} ]]; then + mnt=${part_mnt} + else + mnt=$(mktemp -d) + cleanup_dirs+=("${mnt}") + if ! mount -t ntfs3 -o ro,noatime "/dev/${dev}" "${mnt}" 2>/dev/null && + ! mount -o ro,noatime "/dev/${dev}" "${mnt}" 2>/dev/null; then + log "/dev/${dev}: could not mount read-only, skipping" + log "/dev/${dev}: if Windows is hibernated, shut it down fully and retry" + continue + fi + cleanup_mounts+=("${mnt}") + fi + + [[ -d "${mnt}/${DRIVERSTORE}" ]] || continue + + found=$(find_blob "${mnt}/${DRIVERSTORE}") + if [[ -n ${found} ]]; then + log "found ${BLOB} on /dev/${dev}" + install_blob "${found}" + return 0 + fi + log "/dev/${dev}: a Windows install, but no ${BLOB} in its DriverStore" + done < <(lsblk -rno NAME,FSTYPE,MOUNTPOINT) + + return 1 +} + +from_msi() { + local pack=$1 work found + + command -v msiextract >/dev/null || die "msiextract is missing; install msitools" + + work=$(mktemp -d) + cleanup_dirs+=("${work}") + + log "extracting ${pack}" + ( cd "${work}" && msiextract "${pack}" >/dev/null ) + + found=$(find_blob "${work}") + [[ -n ${found} ]] || die "no ${BLOB} inside ${pack}; is it the Surface Pro 12in driver pack?" + + log "found ${BLOB} in the driver pack" + install_blob "${found}" +} + +if [[ -n ${url} ]]; then + dl=$(mktemp -d) + cleanup_dirs+=("${dl}") + msi="${dl}/driverpack.msi" + log "downloading ${url}" + curl -fL --retry 3 --progress-bar -o "${msi}" "${url}" +fi + +if [[ -n ${msi} ]]; then + [[ -f ${msi} ]] || die "${msi} does not exist" + from_msi "${msi}" + exit 0 +fi + +if from_windows; then + exit 0 +fi + +# Nothing found, and nothing was asked for. Not an error: most of the time this +# is a machine with no Windows left on it, and the only thing left to do is say +# how to finish the job by hand. +log "no Windows install on this machine carries ${BLOB}" +log "hardware video decode stays off until it is installed. To finish by hand:" +log " 1. download the Surface Pro 12in driver pack (~500 MB) from" +log " ${PAGE}" +log " 2. sudo surface-video-firmware.sh -m /path/to/SurfacePro_12in_*.msi" +exit 0 diff --git a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/local/bin/wireupcameras.sh b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/local/bin/wireupcameras.sh deleted file mode 100644 index 833a422..0000000 --- a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/local/bin/wireupcameras.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -set -e - -# Wait for /dev/media0 to appear (MSM VFE driver may need firmware to probe) -# Timeout after 10 seconds to avoid infinite hangs on systems without camera hardware -MAX_WAIT=10 -WAIT_COUNT=0 -while [ ! -e /dev/media0 ] && [ $WAIT_COUNT -lt $MAX_WAIT ]; do - sleep 1 - WAIT_COUNT=$((WAIT_COUNT + 1)) -done - -if [ ! -e /dev/media0 ]; then - echo "wireupcameras: /dev/media0 not found after ${MAX_WAIT}s, skipping" >&2 - exit 0 -fi - -SENSOR="ov13858 1-0010" - -# Tell each pad in the path what format to expect -media-ctl -V "\"$SENSOR\":0[fmt:SGRBG10_1X10/4224x3136]" -media-ctl -V '"msm_csiphy0":0[fmt:SGRBG10_1X10/4224x3136]' -media-ctl -V '"msm_csiphy0":1[fmt:SGRBG10_1X10/4224x3136]' -media-ctl -V '"msm_csid0":0[fmt:SGRBG10_1X10/4224x3136]' -media-ctl -V '"msm_csid0":1[fmt:SGRBG10_1X10/4224x3136]' -media-ctl -V '"msm_vfe0_rdi0":0[fmt:SGRBG10_1X10/4224x3136]' - -# Disable the OV02C10 path so it doesn't fight for csid0 -media-ctl -l '"msm_csiphy4":1->"msm_csid0":0[0]' - -# Enable the rear path -media-ctl -l '"msm_csiphy0":1->"msm_csid0":0[1]' diff --git a/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/local/share/selinux/iio-qipcrtr.te b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/local/share/selinux/iio-qipcrtr.te new file mode 100644 index 0000000..b3be8fb --- /dev/null +++ b/root/tmp/SayaAndy/surface-pro-12-inch-linux-fedora/usr/local/share/selinux/iio-qipcrtr.te @@ -0,0 +1,19 @@ +module iio-qipcrtr 1.0; + +# Fedora's policy grants iiosensorproxy_t no qipcrtr_socket permissions at +# all: the class exists but nothing allows it, because upstream +# iio-sensor-proxy talks to sensors over IIO and never needed QRTR. The SSC +# backend libssc brings in here reaches the Qualcomm Sensor Core over the +# QRTR bus (libssc probes AF_QIPCRTR first; the fastrpc/hexagonrpcd path is +# what actually serves this board, but the probe alone gets the daemon +# killed by "QRTR bus unavailable" + "No sensors" without these perms). +# +# Hand-written rather than audit2allow'd per-incident: create/bind/... is +# the full client lifecycle, so a policy reload or libssc update cannot +# surface a new denied perm one at a time. +require { + type iiosensorproxy_t; + class qipcrtr_socket { create bind connect read write getattr setattr getopt setopt shutdown }; +} + +allow iiosensorproxy_t self:qipcrtr_socket { create bind connect read write getattr setattr getopt setopt shutdown }; diff --git a/surface-editbootconfig.sh b/surface-editbootconfig.sh index a426645..e6cc67c 100755 --- a/surface-editbootconfig.sh +++ b/surface-editbootconfig.sh @@ -27,12 +27,12 @@ esac dtb_name=x1p42100-microsoft-sp12in.dtb -# The working directory is the image root, so this is kernel-surface's own -# version-independent copy. config.sh has already failed the build if the -# package did not provide it. -dtb_src="usr/lib/surface-dtb/${dtb_name}" -if [[ ! -f "${dtb_src}" ]]; then - echo "surface-editbootconfig: ${dtb_src} not found in the image root" >&2 +# The working directory is the image root, so this is kernel-surface's own copy, +# under a directory named for the kernel version because that package is +# installonly. config.sh has already failed the build if it is not there. +dtb_src=$(ls -1 usr/lib/surface-dtb/*/"${dtb_name}" 2>/dev/null | sort -V | tail -n1) +if [[ -z "${dtb_src}" ]]; then + echo "surface-editbootconfig: no ${dtb_name} under usr/lib/surface-dtb/ in the image root" >&2 exit 1 fi |