[Samsung Galaxy S8 Guides, News, & Discussion] karatekid430:
Okay. How to make kernel from scratch and flash to device (at your own risk, backup all data off the device first as messing with kernels can get messy).

You need Windows and Linux. I use the default distro that comes with WSL on Windows 10.

For Windows: https://xdaforums.com/showthread.php?t=2073775 - Android Image Kitchen - to pack and unpack kernel.

https://xdaforums.com/galaxy-tab-s/general/tool-samfirm-samsung-firmware-t2988647 - to download firmware without the nonsense you have to put up with on sammobile.com/firmwares.

7-zip - extract boot.img from firmware

Latest applicable source code from opensource.samsung.com for SM-G950F or SM-G955F.

1. On Linux,

cd ~

mkdir toolchain && cd toolchain

git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9

export CROSS_COMPILE=~/toolchain/aarch64-linux-android-4.9/bin/aarch64-linux-android-4.9-

export ARCH=arm64

export ANDROID_MAJOR_VERSION=7

cd ..

unzip Samsung-sourcecode.zip

mkdir kernel && cd kernel && tar -zxvf ../sourcecode.zip

chmod -R +w .

nano arch/arm64/configs/exynos8895-dream.... (there is only one file in configs dir) - set CONFIG_TIMA_RKP=n and CONFIG_DISPLAYPORT_ENG=y and save

nano drivers/ccic/ccic_alternate.c (and make the function process_check_accessory(void *data) look like the attached image) and save

make exynos8895-dreamlte_eur_open_defconfig if SM-G950F otherwise make exynos8895-dream2lte_eur_open_defconfig

make -jX (replace X with number of CPU threads * 2)

Now if everything went correctly, you will end up with file arch/arm64/boot/Image, and no mentions of section mismatch during compilation. Copy the file to Windows.

In Windows:

DISABLE NORTON F****** ANTIVIRUS AS IT LIKES TO REMOVE THE EXECUTABLES FROM ANDROID IMAGE KITCHEN WITHOUT ASKING.

Extract Android Image Kitchen from the zip.

Use SamFirm utility to download the official ROM for your device - straight from Samsung at high speed.

Use 7-zip to extract the stock boot.img from the AP file from the official ROM you downloaded from the SamFirm utility.

Copy the boot.img into the Android Image Kitchen directory and drop it on unpackimg.bat to extract it.

From the split_img directory that was just created, delete boot.img-zImage. Copy the compiled kernel Image file to split_img directory, and rename it to boot.img-zImage

Go back to previous directory and run repackimg.bat to produce the image-new.img - now rename it to something meaningful so that later after you have repacked dozens of images, you can identify it.

At your own risk, copy to Galaxy S8 and flash the file using TWRP as boot.img (make sure you back up all your data on your device). If you don't know how to recover from this going wrong then you probably shouldn't be doing it. Remember that flashing boot.img removes systemless root and other similar modifications, so these will need to be reflashed over the top.

Did it boot? Yes - yay. No - go back to TWRP and flash the stock boot.img you extracted from the AP (assuming you downloaded the compatible firmware version).

For me this worked with the patched /system from flashing Jesse S8 kernel - but it should work with stock /system - I hope.

If passing dm-verity will allow me to use encryption, then this will make me happy.

I plan to merge changes from the Jesse kernel which fake bootloader locked, disable SELinux but fake enforcing status, etc, etc, without bringing it too far from stock.

Just a note about the source code. Before I had made changes to several files, including drivers/video/fbdev/exynos/dpu/displayport_drv.c to fake the sysfs entries. Turns out that is not required at all - it seems to happen by itself if you change ccic_alternate.c properly. The idea behind this file is that we want the Samsung HDMI adapter, and the Samsung Multiport Adapter to be recognised as DeX, as well as anything else. We let the switch entries run, and if dock_type is not set (third party device) or equal to CCIC_DOCK_HDMI, or equal to CCIC_DOCK_MPA, we run the code from the switch case that was there for the DeX, setting dock_type to CCIC_DOCK_DEX, resulting in the usbpd_data->acc_type being set to equal CCIC_DOCK_DEX, as if it were connected.

If somebody knows how to debug kernels, please let me know what sorts of things trigger this function - I have a hunch it is only USB-C type, but it might be all OTG accessories, in which case it might be smart to come up with a way of deciding whether the connected device should be treated as a DeX station.

Have fun! Somebody who is familiar with Git, please make a patch. We can hopefully produce a stock kernel for the Galaxy Note 8, hours after the source code is released for its kernel.