aboutsummaryrefslogtreecommitdiffci
path: root/kernel-surface.spec
blob: ee6e132d25c37883827b5e7ad1b5fcb5cab687cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# Vanilla upstream kernel plus the Surface Pro 12" (Snapdragon X1P-42-100)
# patch set from the miasvanklei Gentoo overlay, packaged for Fedora.
#
# Build inputs are produced by make-sources.sh in this directory; see README.md.

# Upstream tarball version. For a release candidate this is the git.kernel.org
# snapshot name (linux-7.3-rc1); for a stable release it is the tarball name
# from cdn.kernel.org (linux-7.2.3).
#
# Both versions here are defaults, for a build driven straight off a checkout.
# The release pipeline reads them out of the git tag it was triggered by and
# passes them in with --define, which takes precedence -- so keep the plain
# `%%global <name> <value>` shape, which make-sources.sh reads with awk.
%if %{undefined upstream_ver}
%global upstream_ver 7.2.4
%endif

# Bumped whenever the patch tarball changes without the upstream version moving.
%if %{undefined patchset_ver}
%global patchset_ver 1
%endif

# rpm gives - to the version-release separator, so it cannot appear in Version
# itself. A release candidate's own Makefile reports the version it leads up to
# anyway -- 7.3-rc1 builds 7.3.0 -- and %%prep drops the EXTRAVERSION that would
# otherwise carry the -rcN into uname -r. A stable version passes through.
%global kversion %(echo %{upstream_ver} | sed -e 's/-rc[0-9]*$/.0/')

# The kernel's own release string: what uname -r reports and what names
# /usr/lib/modules/<...>. Matches Fedora's <version>-<release>.<arch> convention.
%global kverrel %{version}-%{release}.%{_target_cpu}

# No -debuginfo: modules are stripped at install time via INSTALL_MOD_STRIP.
%global debug_package %{nil}
%global _missing_build_ids_terminate_build 0

# rpm's kernel module file attribute would decorate every .ko with
# kernel(<symbol>) provides and requires, which only Fedora's own split kernel
# packaging can satisfy. Keep the module tree out of the dependency generator
# entirely; the dependencies this package really has are declared by hand below.
%global __provides_exclude_from ^/usr/lib/(modules|surface-dtb)/.*$
%global __requires_exclude_from ^/usr/lib/(modules|surface-dtb)/.*$

Name:           kernel-surface
Version:        %{kversion}
Release:        %{patchset_ver}%{?dist}
Summary:        Linux kernel for the Microsoft Surface Pro 12-inch (Snapdragon X1P-42-100)
License:        GPL-2.0-only
URL:            https://github.com/miasvanklei/Gentoo-overlay

ExclusiveArch:  aarch64

Source0:        https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/snapshot/linux-%{upstream_ver}.tar.gz
Source1:        kernel-surface-patches-%{upstream_ver}-%{patchset_ver}.tar.gz
Source2:        base-aarch64.config
Source3:        surface.config
Source4:        live-image.config
Source5:        no-debug-info.config
Source6:        foreign-socs.config

BuildRequires:  bc
BuildRequires:  binutils
BuildRequires:  bison
BuildRequires:  bzip2
BuildRequires:  diffutils
BuildRequires:  elfutils-devel
BuildRequires:  elfutils-libelf-devel
BuildRequires:  findutils
BuildRequires:  flex
BuildRequires:  gcc
BuildRequires:  gzip
BuildRequires:  hostname
BuildRequires:  kmod
BuildRequires:  make
BuildRequires:  openssl
BuildRequires:  openssl-devel
BuildRequires:  patch
BuildRequires:  perl-interpreter
BuildRequires:  python3
BuildRequires:  rsync
BuildRequires:  tar
BuildRequires:  xz
BuildRequires:  zstd

Requires:       dracut
Requires:       kmod
Requires:       linux-firmware
Requires:       systemd >= 254

# This package stands in for the whole of Fedora's split kernel packaging, so
# anything with a plain `Requires: kernel-core` (anaconda, dracut config,
# desktop groups) resolves against it. It deliberately does not Obsolete the
# Fedora packages: the KIWI description picks this one by name and <ignore>s
# the Fedora ones, which keeps the repo safe to enable on a normal system.
Provides:       kernel = %{version}-%{release}
Provides:       kernel-core = %{version}-%{release}
Provides:       kernel-modules = %{version}-%{release}
Provides:       kernel-modules-core = %{version}-%{release}
Provides:       kernel-modules-extra = %{version}-%{release}
Provides:       kernel-uname-r = %{kverrel}
Provides:       kernel-core-uname-r = %{kverrel}
Provides:       kernel-modules-uname-r = %{kverrel}
Provides:       kernel-modules-core-uname-r = %{kverrel}
Provides:       kernel-modules-extra-uname-r = %{kverrel}
Provides:       installonlypkg(kernel)

# Fedora's kernel-uki-dtbloader carries ~3000 boards' device trees and conflicts
# with a plain kernel image package; this board is not in its database anyway.
Conflicts:      kernel-uki-dtbloader

%description
The Linux kernel built from vanilla upstream sources with the Microsoft Surface
Pro 12-inch (Snapdragon X1P-42-100) patch set from the miasvanklei Gentoo
overlay applied.

Beyond the device tree for the board, the patch set adds a Surface Aggregator
Module RTC driver, a suspend workaround for the aggregator controller, CAMSS
and CSI-2 D-PHY support for the tablet's cameras, remoteproc attach support for
the already-running DSPs, and assorted clock, PCI and interrupt controller
fixes for the platform.

This package provides kernel, kernel-core, kernel-modules and
kernel-modules-extra, so it can be installed in place of Fedora's kernel
packages.

%prep
%setup -q -n linux-%{upstream_ver} -a 1

# Apply every patch directory in the order given by patch-order.txt, which
# make-sources.sh encoded into the tarball's directory names.
#
# The patch flags are Portage's eapply flags (patch -p1 -f -g0
# --no-backup-if-mismatch), which is what the overlay's patches are maintained
# against: they carry stale context lines from before upstream refactors and
# only apply at GNU patch's default fuzz of 2. Forcing --fuzz=0 here rejects
# roughly a fifth of the set. What guards against a silently mis-applied patch
# is not the fuzz level but the .config and kernelrelease assertions below.
for patchdir in patches/*/; do
    for patchfile in "${patchdir}"*.patch; do
        [ -e "${patchfile}" ] || continue
        echo "Applying ${patchfile}"
        patch -p1 -f -g0 --no-backup-if-mismatch -i "${patchfile}"
    done
done
rm -rf patches

# The camera series calls devm_phy_get_by_of_node(), which only the phy series
# adds -- and the overlay's own 7.2.3 ebuild left phy out of its loop while
# shipping the camera patch that needs it. Applying one without the other
# compiles for twenty-odd minutes before failing in camss-csiphy.c, so assert
# the declaration is here while it is still cheap to say so.
grep -q 'devm_phy_get_by_of_node' include/linux/phy/phy.h || {
    echo "ERROR: include/linux/phy/phy.h does not declare devm_phy_get_by_of_node."
    echo "The camera patches need the phy ones; check phy is in patch-order.txt"
    echo "and that it exists at the pinned overlay commit."
    exit 1
}

# Fold the -rcN suffix into the package release instead of carrying it in
# uname -r, so the module directory is named the way Fedora names it.
sed -i 's/^EXTRAVERSION[[:space:]]*=.*/EXTRAVERSION =/' Makefile

cp -f %{SOURCE2} .config

# The base config still carries Fedora's own build salt, which feeds the
# kernel's build ID; reset it so this kernel does not share one with the
# Fedora build it was seeded from.
cat > .release.config <<EOF
CONFIG_LOCALVERSION="-%{release}.%{_target_cpu}"
CONFIG_BUILD_SALT="%{kverrel}"
EOF

ARCH=arm64 scripts/kconfig/merge_config.sh -m -O . \
    .config .release.config %{SOURCE3} %{SOURCE4} %{SOURCE5} %{SOURCE6}
make ARCH=arm64 olddefconfig

# merge_config.sh is only advisory about symbols it could not set, so check the
# ones that exist solely because the patch set applied.
for sym in CONFIG_RTC_DRV_SURFACE CONFIG_PHY_QCOM_MIPI_CSI2; do
    grep -q "^${sym}=" .config || {
        echo "ERROR: ${sym} missing from .config; the patch set did not apply"
        exit 1
    }
done

# The build derives /usr/lib/modules/<...> from CONFIG_LOCALVERSION. A mismatch
# here means it would not be the directory %%files and the scriptlets name,
# which otherwise only shows up as a broken package.
kernelrelease=$(make -s ARCH=arm64 kernelrelease | tail -n1)
test "${kernelrelease}" = "%{kverrel}" || {
    echo "ERROR: kernelrelease is ${kernelrelease}, expected %{kverrel}"
    exit 1
}

%build
export KCFLAGS="-mcpu=oryon-1+nopauth"
%make_build ARCH=arm64 Image modules dtbs

%install
%make_build ARCH=arm64 \
    INSTALL_MOD_PATH=%{buildroot}/usr INSTALL_MOD_STRIP=1 \
    modules_install

%make_build ARCH=arm64 \
    INSTALL_DTBS_PATH=%{buildroot}/usr/lib/modules/%{kverrel}/dtb \
    dtbs_install

# modules_install leaves symlinks into the build tree, which does not exist on
# the installed system.
rm -f %{buildroot}/usr/lib/modules/%{kverrel}/build
rm -f %{buildroot}/usr/lib/modules/%{kverrel}/source

# GRUB loads the aarch64 kernel as an EFI application, so this is the
# uncompressed Image, not Image.gz. kernel-install copies it into /boot.
install -Dm644 arch/arm64/boot/Image \
    %{buildroot}/usr/lib/modules/%{kverrel}/vmlinuz
install -Dm644 System.map \
    %{buildroot}/usr/lib/modules/%{kverrel}/System.map
install -Dm644 .config \
    %{buildroot}/usr/lib/modules/%{kverrel}/config
install -Dm644 arch/arm64/boot/dts/qcom/x1p42100-microsoft-sp12in.dtb \
    %{buildroot}/usr/lib/surface-dtb/%{kverrel}/x1p42100-microsoft-sp12in.dtb

%post
/usr/sbin/depmod -a %{kverrel} || :

%posttrans
# Same as Fedora's kernel-core: hand the kernel to kernel-install, which
# generates the initramfs, copies vmlinuz into /boot and writes the BLS loader
# entry.
if [ -x /usr/bin/kernel-install ]; then
    /usr/bin/kernel-install add %{kverrel} \
        /usr/lib/modules/%{kverrel}/vmlinuz || :
fi

%preun
if [ -x /usr/bin/kernel-install ]; then
    /usr/bin/kernel-install remove %{kverrel} || :
fi

%files
%license COPYING
/usr/lib/modules/%{kverrel}/
/usr/lib/surface-dtb/%{kverrel}/
%ghost %attr(0644,root,root) /boot/config-%{kverrel}
%ghost %attr(0644,root,root) /boot/initramfs-%{kverrel}.img
%ghost %attr(0600,root,root) /boot/System.map-%{kverrel}
%ghost %attr(0644,root,root) /boot/vmlinuz-%{kverrel}

%changelog
* Wed Sep 09 2026 Saya Andy  7.2.4-2
- Compile kernel specifically for Oryon v1 instruction set (Snapdragon X1 cpu)

* Tue Sep 08 2026 Saya Andy  7.2.4-1
- Update Linux kernel from 7.2.3 to 7.2.4

* Mon Sep 07 2026 Saya Andy  7.2.3-4
- Turn off all the ARM64 platform kernel modules besides qcom and vexpress
  (used in qemu)
- Fix Bayer order in rear camera resulting in color space shift

* Mon Sep 07 2026 Saya Andy  7.2.3-3
- Key the /usr/lib/surface-dtb copy of the device tree by kernel version. This
  package is installonly, so an unqualified path there conflicts between two
  installed releases as soon as the device tree they build differs.

* Sun Sep 06 2026 Saya Andy  7.2.3-2
- Local camera patch: report the right bayer order when mirrored (fixes the
  black-green monochrome output issue)
- Local surface patch: point iris at the OEM video firmware (fixes error -22
  for video encoding/decoding)

* Sun Sep 06 2026 Saya Andy  7.2.3-1
- Initial package: vanilla 7.2.3 with the overlay's Surface Pro 12" patch set