<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[@sn00py_z0r0]]></title><description><![CDATA[@sn00py_z0r0]]></description><link>https://minh.pw</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 10:05:18 GMT</lastBuildDate><atom:link href="https://minh.pw/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Build KernelSU for Pixel Device]]></title><description><![CDATA[Note: This article is only available for devices without GKI (Pixel 5 and below, which Google calls Legacy Pixel) or MSM Project

Requirement

Pixel Device (recommend last oldest version, in this article is Pixel 3XL, image used image-crosshatch-qq3a...]]></description><link>https://minh.pw/build-kernelsu-for-pixel-device</link><guid isPermaLink="true">https://minh.pw/build-kernelsu-for-pixel-device</guid><category><![CDATA[android-kernel]]></category><category><![CDATA[Kernel]]></category><category><![CDATA[pixel]]></category><category><![CDATA[Android]]></category><dc:creator><![CDATA[sn00py z0r0]]></dc:creator><pubDate>Tue, 05 Aug 2025 09:24:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1754764920880/23fb8e94-45b6-4a57-b3ef-c46e38f2beb8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Note: This article is only available for devices without GKI (Pixel 5 and below, which Google calls Legacy Pixel) or MSM Project</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754375174844/b255a3be-4a11-4199-b8dd-74358674eda7.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-requirement">Requirement</h1>
<ul>
<li><p>Pixel Device (recommend last oldest version, in this article is Pixel 3XL, image used <code>image-crosshatch-qq3a.200805.001</code>)</p>
</li>
<li><p>Ubuntu machine (With 8-16 cores CPU, RAM higher than 16Gb, Hard Disk available at least 150Gb)</p>
</li>
</ul>
<h1 id="heading-pull-it">Pull it!</h1>
<p>The first thing you need to do is ensure that the kernel you build can run basic functionalities such as touch, Wi-Fi, etc. Based on the kernel to be determined branch name of kernel</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754376572553/fd5f9004-e6b9-41d2-83fc-c4c2a3eeaae9.png" alt class="image--center mx-auto" /></p>
<p>The commid id we are looking for is “dee0d123b122”. In my experience, I will go to <a target="_blank" href="https://android.googlesource.com/kernel/msm.git/">Kernel MSM</a> and find <code>device_name-versionKernel-androidx</code> (in my case is <code>crosshatch-4.9-android10</code>) then check all of branch to find matched. I found <a target="_blank" href="https://android.googlesource.com/kernel/msm.git/+/refs/heads/android-msm-crosshatch-4.9-android10-qpr3">android-msm-crosshatch-4.9-android10-qpr3</a> have commit id is <strong>dee0d123b122058c6eeeee7cec14548e2c037131</strong> matched with my kernel running on my Pixel device</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754377213275/64fec256-80d5-4539-a348-1d1d1d5dd8dc.png" alt class="image--center mx-auto" /></p>
<p>Normally, projects from Google like AOSP will use <code>repo</code> to manage the project instead of <code>git</code>, so firstly, install <code>repo</code> first, we also need to install requirement liked <code>make</code> or <code>g++</code>‘s library</p>
<pre><code class="lang-bash">sudo apt-get install sudo apt-get install make python-is-python3 gcc libssl-dev git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386  x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig make
curl https://storage.googleapis.com/git-repo-downloads/repo &gt; ~/repo
chmod a+x ~/repo
sudo mv ~/repo /usr/bin/repo
</code></pre>
<p>Create <code>kernel</code> folder and clone kernel</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Config git is necessary</span>
git config --global user.name <span class="hljs-string">"&lt;your name&gt;"</span>
git config --global user.email <span class="hljs-string">"&lt;your name&gt;"</span>
<span class="hljs-comment"># Create and clone with repo</span>
mkdir kernel &amp;&amp; <span class="hljs-built_in">cd</span> kernel
repo init -u https://android.googlesource.com/kernel/manifest -b android-msm-crosshatch-4.9-android10-qpr3
repo sync
</code></pre>
<p>It will take your time (~10 mins)</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754378456273/5f5d5999-457b-43d2-86e6-4804fe1f73ee.png" alt class="image--center mx-auto" /></p>
<p>Sync is done and your kernel on the device</p>
<h1 id="heading-build-it">Build it</h1>
<p>We have many ways to build but in my experience, we should extract ramdisk on original image and build kernel from that to make sure that touch and wifi can work. In this article, I will follow that methods.</p>
<h2 id="heading-prepare-for-build">Prepare for build</h2>
<h3 id="heading-modify-build-code">Modify build code</h3>
<p>At this time, <code>build</code> tool (it will pull when you use repo to clone kernel source) only support for <code>BOARD_HEADER_VERSION</code> 3 so our devices is <code>BOARD_HEADER_VERSION</code> 2 will out of scope, we also need to rollback</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> build
git checkout ec7e1bc932f45518c6368bf0275b99639b904001
</code></pre>
<p>To make sure that we correct build tool, please check conditional logic code in <code>build.sh</code></p>
<pre><code class="lang-bash">cat build.sh | grep <span class="hljs-string">"-eq \"3\""</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754378875467/7e994e8a-10d6-4861-a074-c6e4388c2324.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-extract-bootimg">Extract boot.img</h3>
<p>When we get firmware from Google, we will see <code>.zip</code> folder, let unpack it and get <code>boot.img</code> file</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754379092564/db538576-82cb-4917-a963-c03d75c20570.png" alt class="image--center mx-auto" /></p>
<p>Use <a target="_blank" href="https://github.com/draekko/AIK-Linux">Android Image Kitchen</a> to extract <code>boot.img</code>. We will get something like build parameters, randisk file, etc. Put <code>boot.img</code> inside <code>AIK-Linux</code> folder, then extract <code>boot.img</code></p>
<pre><code class="lang-bash">git <span class="hljs-built_in">clone</span> https://github.com/draekko/AIK-Linux.git &amp;&amp; <span class="hljs-built_in">cd</span> AIK-Linux
<span class="hljs-comment"># Move boot.img inside AIK-Linux</span>
./unpackimg.sh boot.img
</code></pre>
<pre><code class="lang-plaintext">Android Image Kitchen - UnpackImg Script
by osm0sis @ xda-developers

Supplied image: boot.img

Setting up work folders...

Image type: AOSP

Signature with "AVBv2" type detected.

Splitting image to "split_img/"...
ANDROID! magic found at: 0
BOARD_KERNEL_CMDLINE console=ttyMSM0,115200n8 androidboot.console=ttyMSM0 printk.devkmsg=on msm_rtb.filter=0x237 ehci-hcd.park=3 service_locator.enable=1 cgroup.memory=nokmem lpm_levels.sleep_disabled=1 usbcore.autosuspend=7 loop.max_part=7 androidboot.boot_devices=soc/1d84000.ufshc androidboot.super_partition=system buildvariant=user
BOARD_KERNEL_BASE 0x00000000
BOARD_NAME
BOARD_PAGE_SIZE 4096
BOARD_HASH_TYPE sha1
BOARD_KERNEL_OFFSET 0x00008000
BOARD_RAMDISK_OFFSET 0x01000000
BOARD_SECOND_OFFSET 0x00f00000
BOARD_TAGS_OFFSET 0x00000100
BOARD_OS_VERSION 10.0.0
BOARD_OS_PATCH_LEVEL 2020-08
BOARD_HEADER_VERSION 2
BOARD_HEADER_SIZE 1660
BOARD_DTB_SIZE 862396
BOARD_DTB_OFFSET 0x01f00000

Unpacking ramdisk (as root) to "ramdisk/"...

Compression used: gzip
40878 blocks

Done!
</code></pre>
<p>Please note this log, after unpacking have new <code>ramdisk</code> and <code>split_img</code> folders. We found <code>split_img\boot.img-ramdisk.cpio.gz</code> is ramdisk, unzip it and move to kernel root folder</p>
<pre><code class="lang-bash">gzip -dk split_img/boot.img-ramdisk.cpio.gz
mv split_img/boot.img-ramdisk.cpio ../kernel/ <span class="hljs-comment"># Move to root kernel</span>
</code></pre>
<h3 id="heading-get-mkbootimg">Get <strong>mkbootimg</strong></h3>
<p>Inside root folder of kernel get <code>mkbootimg.py</code>. Here I will manual copy <a target="_blank" href="https://android.googlesource.com/platform/system/tools/mkbootimg/+/9c46d9eee9a1b469ccf46db917ac78fc9f0fdaf1/mkbootimg.py">mkbootimg.py</a></p>
<h2 id="heading-analyse-build-code">Analyse build code</h2>
<p>This part can skip, but please modify <code>build/build.sh</code> first. Please add below before <code>Files copied to…</code> line</p>
<pre><code class="lang-bash"><span class="hljs-keyword">if</span> [ -f <span class="hljs-string">"<span class="hljs-variable">${VENDOR_RAMDISK_BINARY}</span>"</span> ]; <span class="hljs-keyword">then</span>
  cp <span class="hljs-variable">${VENDOR_RAMDISK_BINARY}</span> <span class="hljs-variable">${DIST_DIR}</span>
<span class="hljs-keyword">fi</span>  

<span class="hljs-built_in">echo</span> <span class="hljs-string">"========================================================"</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">" Files copied to <span class="hljs-variable">${DIST_DIR}</span>"</span>
</code></pre>
<p>Now you can skip to next part 😔, or see my analyse build code to know how to build the kernel</p>
<p>My target here is use <code>BUILD_BOOT_IMG</code> to create <code>boot.img</code>. This will help me avoid compatibility during create <code>boot.img</code>. In the note of build code mentioned we need some information</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754381067138/3c09c215-7f68-46a3-8717-00b68e65f75f.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-plaintext">#     - MKBOOTIMG_PATH=&lt;path to the mkbootimg.py script which builds boot.img&gt;
#       (defaults to tools/mkbootimg/mkbootimg.py)
#     - GKI_RAMDISK_PREBUILT_BINARY=&lt;Name of the GKI ramdisk prebuilt which includes
#       the generic ramdisk components like init and the non-device-specific rc files&gt;
#     - VENDOR_RAMDISK_BINARY=&lt;Name of the vendor ramdisk binary which includes the
#       device-specific components of ramdisk like the fstab file and the
#       device-specific rc files.&gt;
#     - KERNEL_BINARY=&lt;name of kernel binary, eg. Image.lz4, Image.gz etc&gt;
#     - BOOT_IMAGE_HEADER_VERSION=&lt;version of the boot image header&gt;
#       (defaults to 3)
#     - KERNEL_CMDLINE=&lt;string of kernel parameters for boot&gt;
#     - KERNEL_VENDOR_CMDLINE=&lt;string of kernel parameters for vendor boot image,
#       vendor_boot when BOOT_IMAGE_HEADER_VERSION &gt;= 3; boot otherwise&gt;
#     - VENDOR_FSTAB=&lt;Path to the vendor fstab to be included in the vendor
#       ramdisk&gt;
#     If the BOOT_IMAGE_HEADER_VERSION is less than 3, two additional variables must
#     be defined:
#     - BASE_ADDRESS=&lt;base address to load the kernel at&gt;
#     - PAGE_SIZE=&lt;flash page size&gt;
</code></pre>
<p>So we need</p>
<ul>
<li><p>MKBOOTIMG_PATH =&gt; We already have inside kernel root folder</p>
</li>
<li><p>GKI_RAMDISK_PREBUILT_BINARY =&gt; We can skip because inside code, it only use if <code>BOOT_IMAGE_HEADER_VERSION</code> is more than 3 =&gt; We 2 now</p>
</li>
<li><p>VENDOR_RAMDISK_BINARY =&gt; Path of <code>boot.img-ramdisk.cpio</code> file extracted from <code>.gz</code> file</p>
</li>
<li><p>KERNEL_BINARY =&gt; Used default name Image.lz4, lz4 is compress type of pixel image</p>
</li>
<li><p>BOOT_IMAGE_HEADER_VERSION =&gt; It is 2 (get from AIK)</p>
</li>
<li><p>KERNEL_CMDLINE =&gt; From AIK</p>
</li>
<li><p>KERNEL_VENDOR_CMDLINE =&gt; Can skip (<code>BOOT_IMAGE_HEADER_VERSION</code> &gt; 3)</p>
</li>
<li><p>VENDOR_FSTAB =&gt; Can skip (<code>BOOT_IMAGE_HEADER_VERSION</code> &gt; 3)</p>
</li>
<li><p>BASE_ADDRESS =&gt; From AIK</p>
</li>
<li><p>PAGE_SIZE =&gt; From AIK</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754381177386/142b00e2-ea96-4e55-811f-8fe252e16eb1.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754381379056/e956bc68-aade-4f89-8402-75846cb107ba.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-build">Build</h2>
<p>To build it compare all and use <code>build/build.sh</code>. I will use <code>private/msm-google/build.config.common</code> config to avoid bug</p>
<pre><code class="lang-bash">BUILD_CONFIG=private/msm-google/build.config.bluecross BUILD_BOOT_IMG=1 MKBOOTIMG_PATH=mkbootimg.py VENDOR_RAMDISK_BINARY=boot.img-ramdisk.cpio KERNEL_BINARY=Image.lz4 BOOT_IMAGE_HEADER_VERSION=2 KERNEL_CMDLINE=<span class="hljs-string">"console=ttyMSM0,115200n8 androidboot.console=ttyMSM0 printk.devkmsg=on msm_rtb.filter=0x237 ehci-hcd.park=3 service_locator.enable=1 cgroup.memory=nokmem lpm_levels.sleep_disabled=1 usbcore.autosuspend=7 loop.max_part=7 androidboot.boot_devices=soc/1d84000.ufshc androidboot.super_partition=system buildvariant=user"</span> BASE_ADDRESS=0x00000000 PAGE_SIZE=4096 build/build.sh
</code></pre>
<p>Choose <code>BUILD_CONFIG</code> affects whether your device has touch or not. My recommend its use <strong>BUILD_CONFIG</strong> inside <code>private/msm-google</code>.</p>
<p>Some repo have a confuse name like <code>build.config.bluecross</code> and <code>build.config.bonito</code>, like Pixel 3, <strong>bluehatch</strong> and <strong>crosshatch</strong> is Pixel 3 and Pixel 3XL; <strong>bonito</strong> is Pixel 3a, if we build bonito config and flash to 3XL its can make device not working. One point is check <strong>DEFCONFIG</strong> inside <code>build.config</code> file. Like my config <code>blue.config.bluecross</code> use <strong>DEFCONFIG=b1c1_defconfig</strong> <code>b1c1</code> is name of Pixel 3/3XL (I found this information inside android-info.txt, inside .zip file in firmware)</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754385833505/cae3e3ee-c7a9-4edc-b433-6eb7928030d0.png" alt class="image--center mx-auto" /></p>
<p>It will stuck at <code>LTO vmlinux.o</code>, if stuck its maybe work 😂</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754383714442/c0e86d3e-cd1e-4a4b-a8ff-816989f372b5.png" alt class="image--center mx-auto" /></p>
<p>After build <code>boot.img</code> placed in <code>out/android-msm-pixel-4.9/dist/boot.img</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754385009876/0c4ab848-e711-4fd0-bc29-4b55fed06cc7.png" alt class="image--center mx-auto" /></p>
<p>We will try to <code>boot</code> this file via fastboot. This only <strong>boot</strong> its mean if you reboot, its will disappear. You can revert to your kernel by restart device</p>
<pre><code class="lang-bash">adb reboot bootloader
fastboot boot out/android-msm-pixel-4.9/dist/boot.img
</code></pre>
<p>After boot, make sure that touch and wifi work, you can check to make sure that you running on custom kernel by below command. Original kernel will have (abfarm) but custom build can be customize username, hostname</p>
<pre><code class="lang-bash">adb shell cat /proc/version
<span class="hljs-comment"># Linux version 4.9.210 (build-user@build-host) (Android (5484270 based on r353983c) clang version 9.0.3 (https://android.googlesource.com/toolchain/clang 745b335211bb9eadfa6aa6301f84715cee4b37c5) (https://android.googlesource.com/toolchain/llvm 60cf23e54e46c807513f7a36d0a7b777920b5881) (based on LLVM 9.0.3svn)) #1 SMP PREEMPT 2020-06-08 23:19:21</span>
</code></pre>
<p>If everything work, you can be applied by <code>fastboot flash boot</code> or continue to patch KernelSU</p>
<h1 id="heading-patch-kernelsu-next">Patch KernelSU Next</h1>
<p>Firstly, running the script</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> private/msm-google
curl -LSs <span class="hljs-string">"https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh"</span> | bash -
</code></pre>
<h2 id="heading-patch-manual">Patch Manual</h2>
<p>On non-GKI device, we will have 2 ways to use KernelSU are <code>KPROBES_HOOK</code> and Manually way. Fun fact, Pixel 3 XL is older than Pixel 4 XL but running on Kernel newers than (Pixel 3 is 4.9 but 4.14 on Pixel 4). <s> I do not know why but KPROBES is unstable and I do not know exactly what happends, so I will disabled KSU hook by </s> <code>KPROBES_HOOK</code> <s> and patch manually</s> (Now I know why, please check on next part) Find <code>private/msm-google/KerneSU-Next\kernel\Kconfig</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754409974058/23767a89-4241-4311-bd89-b9639bb13af8.png" alt class="image--center mx-auto" /></p>
<p>Change <code>default y</code> to <code>default n</code> to disable it</p>
<p>If you want to know we changed successful to Manual, just rebuild and boot to kernel</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754410328637/ab995b54-c43d-4475-be2a-c1f11ab09b70.png" alt class="image--center mx-auto" /></p>
<p>Follow on <a target="_blank" href="https://kernelsu.org/guide/how-to-integrate-for-non-gki.html#manually-modify-the-kernel-source">Manually modify the kernel source part on KernelSU</a> to patch Kernel</p>
<p>Depends on you kernel, patch is different, on my kernel like this</p>
<p>open.c</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754410621480/19f438f0-4172-4357-8bce-8b5d0f3b6861.png" alt="open.c" class="image--center mx-auto" /></p>
<p>exec.c</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754411103864/ed96f840-8dbb-4ef1-b770-26979c4d0872.png" alt class="image--center mx-auto" /></p>
<p>read_write.c</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754410798129/3b30e0ea-d900-4f0f-9ac6-da32f0e984c1.png" alt class="image--center mx-auto" /></p>
<p>stat.c</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754411066974/efe475db-b3e6-4e90-bb0c-9bee75e541fa.png" alt class="image--center mx-auto" /></p>
<p>Just rebuild and flash again.</p>
<h2 id="heading-why-if-config-not-persistence">Why if config not persistence?</h2>
<p>Config not persistence because keyring its have bug, its appear on 4.14 kernel version (Pixel 4XL) and can fix by <a target="_blank" href="https://github.com/Unb0rn/android_kernel_samsung_exynos9820/blob/e424dac6ce3f99e128aaabb0711d69adf4079c77/ksu_keyring.patch">this patch</a>. I recommended that you need to read and patch manually and rebuild and flash</p>
<h2 id="heading-why-still-cannot-install-module">Why still cannot install module?</h2>
<p>A strange thing happened is I cannot enable the modules on my Pixel 3. First idea is because KPROBES hook not working but I’m wrong, its will happend even through I patched manually. Try to get log and I see error</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754414939370/3ce46f14-2e42-406d-9312-f5a6fa34a2bf.png" alt class="image--center mx-auto" /></p>
<p>Do not permission mean something block it execute system folder :/ What is this? I think its SELinux. After 1-2 hours to research I found <a target="_blank" href="https://github.com/tiann/KernelSU/issues/419">issue</a> on Github of KernelSU. And bingo I think my problem here because I used 4.9 kernel</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754415007465/4c56694d-7ebf-4ac4-b3f9-5cf8a1c49a0a.png" alt class="image--center mx-auto" /></p>
<p>Try to patch <code>security/selinux/hooks.c</code> and waiting to build :d</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754415097770/c2fbb3f7-0ab7-4d98-982d-2b5a06e6cebc.png" alt class="image--center mx-auto" /></p>
<p>It worked!!!!!!!!!!!!!!!!!!! In next time if patch can be used hook dont need patch manual for supported kernel</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754415375466/0c373fd0-6eab-49eb-9158-92abb258336b.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-flash">Flash</h1>
<p>If everything is work, we need patch persistent to device by</p>
<pre><code class="lang-bash">fastboot flash boot boot-new.img
</code></pre>
<p>Then install <a target="_blank" href="https://github.com/KernelSU-Next/KernelSU-Next/tags"><strong>KernelSU Next</strong></a>, please use latest version in tags to compatible with kernel</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1754387451741/5d1bfad3-4706-45eb-a04c-e3f4fc494aa1.png" alt class="image--center mx-auto" /></p>
]]></content:encoded></item></channel></rss>