Skip to content

Commit c4bc5a1

Browse files
committed
Support patching based on SusFS Version
1 parent bbd6ccb commit c4bc5a1

File tree

3 files changed

+543
-30
lines changed

3 files changed

+543
-30
lines changed

.github/actions/action.yml

Lines changed: 383 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,383 @@
1+
name: Build
2+
permissions:
3+
contents: write # Allow writing to repository contents (for pushing tags)
4+
actions: write # Allows triggering actions
5+
6+
7+
inputs:
8+
model:
9+
required: true
10+
type: string
11+
soc:
12+
required: true
13+
type: string
14+
branch:
15+
required: true
16+
type: string
17+
manifest:
18+
required: true
19+
type: string
20+
android_version:
21+
required: true
22+
type: string
23+
kernel_version:
24+
required: true
25+
type: string
26+
ksun_branch:
27+
required: true
28+
type: string
29+
default: stable
30+
susfs_branch:
31+
required: true
32+
type: string
33+
default: ""
34+
35+
runs:
36+
using: "composite"
37+
steps:
38+
- name: Setup Build System
39+
shell: bash
40+
run: |
41+
export DEBIAN_FRONTEND=noninteractive
42+
echo "DEBIAN_FRONTEND=noninteractive" >> $GITHUB_ENV
43+
44+
df -h
45+
46+
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/local/share/powershell /usr/share/swift || true
47+
sudo docker image prune --all --force
48+
echo "some directories deleted"
49+
50+
# Remove large unwanted packages
51+
sudo apt-get purge -y \
52+
aria2 ansible azure-cli shellcheck rpm xorriso zsync \
53+
esl-erlang firefox gfortran-8 gfortran-9 google-chrome-stable \
54+
google-cloud-sdk imagemagick \
55+
libmagickcore-dev libmagickwand-dev libmagic-dev ant ant-optional kubectl \
56+
mercurial apt-transport-https mono-complete libmysqlclient \
57+
unixodbc-dev yarn chrpath libssl-dev libxft-dev \
58+
libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev \
59+
snmp pollinate libpq-dev postgresql-client powershell ruby-full \
60+
sphinxsearch subversion mongodb-org microsoft-edge-stable || true
61+
62+
# Regex-based purges (for bulk families like mysql, php, dotnet)
63+
sudo apt-get purge -y $(dpkg-query -W -f='${binary:Package}\n' | grep -E '^mysql|^php|^dotnet') || true
64+
65+
# Clean up
66+
sudo apt-get autoremove -y
67+
sudo apt-get autoclean -y
68+
echo "some packages purged"
69+
70+
df -h
71+
72+
# Install dependencies
73+
echo "Installing Repo and Python"
74+
sudo apt update
75+
sudo apt install -y python3 python-is-python3
76+
77+
mkdir -p ./git-repo
78+
curl -sSL https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo
79+
chmod a+rx ./git-repo/repo
80+
echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV
81+
82+
# Set CONFIG Environment Variable
83+
echo "CONFIG=${{ inputs.model }}" >> $GITHUB_ENV
84+
85+
- name: Clone AnyKernel3 and Other Dependencies
86+
shell: bash
87+
run: |
88+
echo "Cloning AnyKernel3 and other dependencies..."
89+
90+
ANYKERNEL_BRANCH="gki-2.0"
91+
if [[ -z "${{ inputs.susfs_branch }}" ]]; then
92+
SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
93+
else
94+
SUSFS_BRANCH="${{ inputs.susfs_branch }}"
95+
fi
96+
97+
# Debug print the branches
98+
echo "Using branch for AnyKernel3: $ANYKERNEL_BRANCH"
99+
echo "Using branch for SUSFS: $SUSFS_BRANCH"
100+
101+
# Clone repositories using the branch names
102+
git clone https://github.com/TheWildJames/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
103+
git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
104+
git clone https://github.com/TheWildJames/kernel_patches.git
105+
106+
- name: Initialize and Sync Kernel Source
107+
shell: bash
108+
run: |
109+
echo "Creating folder for configuration: $CONFIG..."
110+
mkdir -p "$CONFIG"
111+
cd "$CONFIG"
112+
113+
# Initialize and sync kernel source
114+
echo "Initializing and syncing kernel source..."
115+
$REPO init -u https://github.com/OnePlusOSS/kernel_manifest.git -b ${{ inputs.branch }} -m ${{ inputs.manifest }} --repo-rev=v2.16 --depth=1 --no-clone-bundle --no-tags
116+
117+
# Sync repo and apply patches
118+
$REPO --version
119+
$REPO --trace sync -c --no-clone-bundle --no-tags --optimized-fetch -j$(nproc --all) --fail-fast
120+
121+
- name: Add KernelSU Next
122+
shell: bash
123+
run: |
124+
echo "Changing to configuration directory: $CONFIG..."
125+
cd "$CONFIG/kernel_platform"
126+
127+
echo "Adding KernelSU Next..."
128+
129+
if [ "${{ inputs.ksun_branch }}" == "stable" ]; then
130+
curl -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash -
131+
else
132+
curl -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash -s ${{ inputs.ksun_branch }}
133+
fi
134+
135+
- name: Apply SUSFS Patches
136+
shell: bash
137+
run: |
138+
echo "Changing to configuration directory: $CONFIG..."
139+
cd "$CONFIG/kernel_platform"
140+
141+
echo "Applying SUSFS patches..."
142+
143+
# Copy SUSFS patches
144+
cp ../../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./common/
145+
cp ../../susfs4ksu/kernel_patches/fs/* ./common/fs/
146+
cp ../../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
147+
148+
cd ./KernelSU-Next
149+
150+
echo "Applying next SUSFS patches..."
151+
susfs_version=$(grep '#define SUSFS_VERSION' ../common/include/linux/susfs.h | awk -F'"' '{print $2}')
152+
echo "SUSVER=$susfs_version" >> $GITHUB_ENV
153+
BASE_VERSION=10200
154+
KSU_VERSION=$(expr $(curl -sI -H "https://api.github.com/repos/KernelSU-Next/KernelSU-Next/commits?sha=${{ inputs.ksun_branch }}&per_page=1" | grep -i "link:" | sed -n 's/.*page=\([0-9]*\)>; rel="last".*/\1/p') "+" $BASE_VERSION)
155+
echo "KSUVER=$KSU_VERSION" >> $GITHUB_ENV
156+
echo "KernelSU Next Version: $KSU_VERSION"
157+
echo "SusFS Version: $susfs_version"
158+
159+
case "$susfs_version" in
160+
"v1.5.5"|"v1.5.6"|"v1.5.7")
161+
cp "../../../kernel_patches/next/0001-kernel-implement-susfs-v1.5.5-v1.5.7-KSUN-v1.0.8.patch" "./ksun_susfs_latest.patch"
162+
;;
163+
"v1.5.8")
164+
cp "../../../kernel_patches/next/0001-kernel-implement-susfs-v1.5.8-KernelSU-Next-v1.0.8.patch" "./ksun_susfs_latest.patch"
165+
;;
166+
*)
167+
echo "Invalid version: $susfs_version"
168+
exit 1
169+
;;
170+
esac
171+
patch -p1 --forward < ksun_susfs_latest.patch || true
172+
173+
174+
# Change to common directory and apply SUSFS patch
175+
cd ../common
176+
if [ "${{ inputs.android_version }}" = "android15" ] && [ "${{ inputs.kernel_version }}" = "6.6" ]; then
177+
if ! grep -qxF '#include <trace/hooks/fs.h>' ./fs/namespace.c; then
178+
sed -i '/#include <trace\/hooks\/blk.h>/a #include <trace\/hooks\/fs.h>' ./fs/namespace.c
179+
else
180+
echo "Line already present. Skipping insert."
181+
fi
182+
fi
183+
patch -p1 < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch || true
184+
185+
if ! grep -qxF '#define CMD_SUSFS_HIDE_SUS_MNTS_FOR_ALL_PROCS 0x55561' ./include/linux/susfs_def.h; then
186+
curl -Ls https://raw.githubusercontent.com/fatalcoder524/kernel_patches_additional/refs/heads/main/hide_sus_mnts_for_all_procs.patch | patch -p1 -F 3
187+
else
188+
echo "Line already present. Skipping SUSFS_HIDE_SUS_MNTS_FOR_ALL_PROCS Patch."
189+
fi
190+
191+
KERNEL_VERSION="${{ inputs.kernel_version }}"
192+
MIN_VERSION="5.16"
193+
194+
if [ "$(printf '%s\n' "$KERNEL_VERSION" "$MIN_VERSION" | sort -V | head -n1)" = "$KERNEL_VERSION" ]; then
195+
echo "Patching ptrace!"
196+
curl -Ls https://raw.githubusercontent.com/fatalcoder524/kernel_patches_additional/refs/heads/main/ptrace.patch | patch -p1 -F 3
197+
else
198+
echo "Kernel >= $MIN_VERSION, skipping ptrace patch"
199+
fi
200+
201+
- name: Apply KSUN Hooks
202+
shell: bash
203+
run: |
204+
echo "Changing to configuration directory: $CONFIG..."
205+
cd "$CONFIG/kernel_platform/common"
206+
echo "Applying KSUN Hooks..."
207+
cp ../../../kernel_patches/next/scope_min_manual_hooks_v1.4.patch ./manual_hooks.patch
208+
patch -p1 --fuzz=3 < ./manual_hooks.patch
209+
210+
- name: Apply Hide Stuff Patches
211+
shell: bash
212+
run: |
213+
echo "Changing to configuration directory: $CONFIG..."
214+
cd "$CONFIG/kernel_platform/common"
215+
# Apply additional patch
216+
cp ../../../kernel_patches/69_hide_stuff.patch ./
217+
patch -p1 -F 3 < 69_hide_stuff.patch
218+
219+
- name: Add KernelSU-Next and SUSFS Configuration Settings
220+
shell: bash
221+
run: |
222+
echo "Changing to configuration directory: $CONFIG..."
223+
cd "$CONFIG/kernel_platform"
224+
225+
echo "Adding configuration settings to gki_defconfig..."
226+
227+
# Add KSU configuration settings
228+
echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig
229+
echo "CONFIG_KSU_KPROBES_HOOK=n" >> ./common/arch/arm64/configs/gki_defconfig
230+
231+
# Add SUSFS configuration settings
232+
echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig
233+
echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
234+
echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig
235+
echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
236+
echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
237+
echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
238+
echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig
239+
echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=n" >> ./common/arch/arm64/configs/gki_defconfig
240+
echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
241+
echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
242+
echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig
243+
echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig
244+
echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig
245+
echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig
246+
echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig
247+
echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> ./common/arch/arm64/configs/gki_defconfig
248+
249+
# Add additional tmpfs config setting
250+
echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig
251+
echo "CONFIG_TMPFS_POSIX_ACL=y" >> ./common/arch/arm64/configs/gki_defconfig
252+
253+
- name: Add BBR Support
254+
shell: bash
255+
run: |
256+
echo "Changing to configuration directory: $CONFIG..."
257+
cd "$CONFIG/kernel_platform"
258+
259+
echo "Adding configuration settings to gki_defconfig..."
260+
echo "CONFIG_TCP_CONG_ADVANCED=y" >> ./common/arch/arm64/configs/gki_defconfig
261+
echo "CONFIG_TCP_CONG_BBR=y" >> ./common/arch/arm64/configs/gki_defconfig
262+
echo "CONFIG_TCP_CONG_BIC=n" >> ./common/arch/arm64/configs/gki_defconfig
263+
echo "CONFIG_TCP_CONG_WESTWOOD=n" >> ./common/arch/arm64/configs/gki_defconfig
264+
echo "CONFIG_TCP_CONG_HTCP=n" >> ./common/arch/arm64/configs/gki_defconfig
265+
266+
echo "CONFIG_NET_SCH_FQ=y" >> ./common/arch/arm64/configs/gki_defconfig
267+
echo "CONFIG_NET_SCH_FQ_CODEL=y" >> ./common/arch/arm64/configs/gki_defconfig
268+
269+
- name: Add TTL Target Support
270+
shell: bash
271+
run: |
272+
echo "Changing to configuration directory: $CONFIG..."
273+
cd "$CONFIG/kernel_platform"
274+
275+
echo "Adding configuration settings to gki_defconfig..."
276+
echo "CONFIG_IP_NF_TARGET_TTL=y" >> ./common/arch/arm64/configs/gki_defconfig
277+
echo "CONFIG_IP6_NF_TARGET_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
278+
echo "CONFIG_IP6_NF_MATCH_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
279+
280+
- name: Run sed and perl Commands
281+
shell: bash
282+
run: |
283+
echo "Changing to configuration directory: $CONFIG..."
284+
cd "$CONFIG/kernel_platform"
285+
286+
echo "Running sed commands..."
287+
288+
sed -i 's/CONFIG_LTO=n/CONFIG_LTO=y/' "./common/arch/arm64/configs/gki_defconfig"
289+
sed -i 's/CONFIG_LTO_CLANG_FULL=y/CONFIG_LTO_CLANG_THIN=y/' "./common/arch/arm64/configs/gki_defconfig"
290+
sed -i 's/CONFIG_LTO_CLANG_NONE=y/CONFIG_LTO_CLANG_THIN=y/' "./common/arch/arm64/configs/gki_defconfig"
291+
292+
# Run sed commands for modifications
293+
sed -i 's/check_defconfig//' ./common/build.config.gki
294+
# For Old setlocalversion Script
295+
tac ./common/scripts/setlocalversion | sed '0,/echo "\$res"/s//res=\$\(echo \$res \| cut -d- -f1-2\)-OP-Wild\;echo "\$res"\;/' | tac > ./common/scripts/setlocalversion.tmp && mv ./common/scripts/setlocalversion.tmp ./common/scripts/setlocalversion
296+
tac ./msm-kernel/scripts/setlocalversion | sed '0,/echo "\$res"/s//res=\$\(echo \$res \| cut -d- -f1-2\)-OP-Wild\;echo "\$res"\;/' | tac > ./msm-kernel/scripts/setlocalversion.tmp && mv ./msm-kernel/scripts/setlocalversion.tmp ./msm-kernel/scripts/setlocalversion
297+
tac ./external/dtc/scripts/setlocalversion | sed '0,/echo "\$res"/s//res=\$\(echo \$res \| cut -d- -f1-2\)-OP-Wild\;echo "\$res"\;/' | tac > ./external/dtc/scripts/setlocalversion.tmp && mv ./external/dtc/scripts/setlocalversion.tmp ./external/dtc/scripts/setlocalversion
298+
# For New setlocalversion Script
299+
sed -i 's/echo "${KERNELVERSION}${file_localversion}${config_localversion}${LOCALVERSION}${scm_version}"/echo "${KERNELVERSION}-${{ inputs.android_version }}-OP-Wild"/' ./common/scripts/setlocalversion
300+
sed -i 's/echo "${KERNELVERSION}${file_localversion}${config_localversion}${LOCALVERSION}${scm_version}"/echo "${KERNELVERSION}-${{ inputs.android_version }}-OP-Wild"/' ./msm-kernel/scripts/setlocalversion
301+
sed -i 's/echo "${KERNELVERSION}${file_localversion}${config_localversion}${LOCALVERSION}${scm_version}"/echo "${KERNELVERSION}-${{ inputs.android_version }}-OP-Wild"/' ./external/dtc/scripts/setlocalversion
302+
chmod +x ./common/scripts/setlocalversion
303+
chmod +x ./msm-kernel/scripts/setlocalversion
304+
chmod +x ./external/dtc/scripts/setlocalversion
305+
sed -i "/stable_scmversion_cmd/s/-maybe-dirty//g" ./build/kernel/kleaf/impl/stamp.bzl || echo "No stamp.bzl!"
306+
sed -i 's/-dirty//' ./common/scripts/setlocalversion
307+
sed -i 's/-dirty//' ./msm-kernel/scripts/setlocalversion
308+
sed -i 's/-dirty//' ./external/dtc/scripts/setlocalversion
309+
sed -i 's/-dirty//' ./build/kernel/kleaf/workspace_status_stamp.py || echo "No workspace_status_stamp.py!"
310+
311+
sed -i '/echo "LTO $LTO "/i export LTO=thin' ./oplus/build/oplus_setup.sh
312+
sed -i 's/export REPACK_IMG=true/export REPACK_IMG=false/g' ./oplus/build/oplus_setup.sh
313+
314+
# Run perl command to modify UTS_VERSION
315+
DATESTR=$(date -u)
316+
perl -pi -e 's{UTS_VERSION="\$\(echo \$UTS_VERSION \$CONFIG_FLAGS \$TIMESTAMP \| cut -b -\$UTS_LEN\)"}{UTS_VERSION="#1 SMP PREEMPT $DATESTR"}' ./common/scripts/mkcompile_h
317+
perl -pi -e 's{UTS_VERSION="\$\(echo \$UTS_VERSION \$CONFIG_FLAGS \$TIMESTAMP \| cut -b -\$UTS_LEN\)"}{UTS_VERSION="#1 SMP PREEMPT $DATESTR"}' ./msm-kernel/scripts/mkcompile_h
318+
319+
- name: Build the Kernel
320+
shell: bash
321+
run: |
322+
echo "Changing to configuration directory: $CONFIG..."
323+
cd "$CONFIG"
324+
325+
echo "Building the kernel..."
326+
# Clear Cache
327+
sudo sh -c 'sync; echo 3 > /proc/sys/vm/drop_caches'
328+
329+
rm ./kernel_platform/common/android/abi_gki_protected_exports_* || echo "No protected exports!"
330+
rm ./kernel_platform/msm-kernel/android/abi_gki_protected_exports_* || echo "No protected exports!"
331+
332+
BUILD_TYPE="gki"
333+
BAZEL_ARGS=(--jobs=$(nproc --all) --lto=thin)
334+
if [ "${{ inputs.soc }}" == "sun" ]; then
335+
BUILD_TYPE="perf"
336+
BAZEL_ARGS+=(-g)
337+
fi
338+
339+
(stdbuf -oL bash -c '
340+
while true; do
341+
echo "=== $(date) ==="
342+
free -h
343+
echo "======"
344+
df -h
345+
echo "======"
346+
top -b -n 1 | head -n 15
347+
echo ""
348+
sleep 60
349+
done
350+
') &
351+
MONITOR_PID=$!
352+
trap "kill $MONITOR_PID" EXIT
353+
354+
if [ -f ./kernel_platform/build_with_bazel.py ]; then
355+
./kernel_platform/oplus/bazel/oplus_modules_variant.sh ${{ inputs.soc }} "$BUILD_TYPE" ""
356+
./kernel_platform/build_with_bazel.py -t ${{ inputs.soc }} $BUILD_TYPE "${BAZEL_ARGS[@]}" -o "$(pwd)/out"
357+
else
358+
LTO=thin ./kernel_platform/oplus/build/oplus_build_kernel.sh ${{ inputs.soc }} "$BUILD_TYPE"
359+
fi
360+
361+
- name: Create ZIP Files for Different Formats
362+
shell: bash
363+
run: |
364+
echo "Changing to configuration directory: $CONFIG..."
365+
cd "$CONFIG"
366+
367+
echo "Copying Image"
368+
cp ./out/dist/Image ../AnyKernel3/Image
369+
370+
echo "Navigating to AnyKernel3 directory..."
371+
cd ../AnyKernel3
372+
373+
# Zip the files in the AnyKernel3 directory with a new naming convention
374+
ZIP_NAME="AnyKernel3_${{ inputs.model }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}_Next_${{ env.KSUVER }}_SUSFS_${{ env.SUSVER }}.zip"
375+
echo "Creating zip file $ZIP_NAME..."
376+
zip -r "../$ZIP_NAME" ./*
377+
378+
- name: Upload Build Artifacts
379+
uses: actions/upload-artifact@v4
380+
with:
381+
name: kernel-${{ env.CONFIG }}
382+
path: |
383+
*.zip

0 commit comments

Comments
 (0)