[Samsung Galaxy J4+ Guides, News, & Discussion] cocacola2015:
I'm going to show you how to build a custom kernel, and a custom boot.img.

Requirements

A linux OS

Kernel source code from Samsung

Android Image Kitchen (Required for the SEANDROID metadata it appends automatically)

GCC Cross Compilation Toolchain 4.8 (You may just clone the repo with git, or download a zip)

Hypothetical workspace directory on the filesystem: /workspace, now prepare it like this:

Go to http://opensource.samsung.com/reception.do and search for SM-J415, download one of the results, extract Kernel.tar.gz to /workspace/kernel. I believe SWA stands for South West Asia, and MAE - Middle-east Africa, it doesn't matter which you pick, it is related to radio regulations.

Now overwrite the file /workspace/kernel/build_kernel.sh with:

#!/bin/bash

# The cross compilation toolchain path
export TOOLCHAIN=$(pwd)/../toolchain/arm-linux-androideabi-4.8
# This is the directory for the compiled kernel
export OUTDIR="O=$(pwd)/../build"

export PATH=$TOOLCHAIN/bin:$PATH
export ARCH=arm
export CROSS_COMPILE=arm-linux-androideabi-
export THREADS=$(nproc --all)
export COMMON_ARGS="-j$THREADS $OUTDIR arch=arm CFLAGS_MODULE=-fno-pic arch=arm"
if [ "$1" == "build" ]; then
make $COMMON_ARGS j4primelte_sea_open_defconfig
make $COMMON_ARGS
elif [ "$1" == "rebuild" ]; then
make $COMMON_ARGS
elif [ "$1" == "clean" ]; then
make $COMMON_ARGS distclean
make $COMMON_ARGS clean
else
echo "./build_kernel.sh build|rebuild|clean"
fi

Building kernel source code

Run the script:

$ cd /workspace/kernel/

edit: /workspace/kernel/arch/arm/configs/j4primelte_sea_open_defconfig

change CONFIG_SECURITY_DEFEX=y to CONFIG_SECURITY_DEFEX=n

$ bash build_kernel.sh build

It should build normally, if it fails there's something wrong with your OS setup. After a long time, you should see the compiled and compressed kernel with the DTP appended at:

/workspace/target/arch/arm/boot/zImage-dtb

The kernel configuration it created from the defconfig files in the kernel source tree is at

/workspace/target/.config

Build a new boot.img

$ cd /workspace/kitchen

$ bash unpackimg.sh /path/to/a/boot/or/recovery.img

Now you will have the unpacked kernel in: /workspace/kitchen/split_img/boot.img-zImage

Delete it

$ rm split_img/boot.img-zImage

Link the built custom kernel there instead

$ ln -s /workspace/target/arch/arm/boot/zImage-dtb /workspace/kitchen/split_img/boot.img-zImage

Now each time you create the boot.img, it will include your custom kernel instead.

Tweak the files and ramdisk as much as you want, and repackage the boot.img

$ bash repackimg.sh

Now you have a boot.img at /workspace/kitchen/image-new.img that is ready to flash to the device. You can unpack custom recoveries the same way as you unpacked boot.img to make them use your custom kernel.

Kernel configurations tried

CONFIG_SECURITY=n - boot loop

CONFIG_SECURITY_SELINUX=n - boot loop

CONFIG_SECURITY_DEFEX=n - works

CONFIG_DM_VERITY=n - works, does not prevent initramfs from using DM-VERITY, you still need some sort of ramdisk hack to disable verification of the next boot phase after initrd.

Often when editing the defconfig files, the same variables are declared in many different files so you might be better off using "sed' to change the variables, example:

$ grep -lr "CONFIG_SECURITY=y" | while read line; do sed -i 's/CONFIG_SECURITY=y/CONFIG_SECURITY=n/g' $line; done

When running "build_kernel.sh build", it will print "configuration written to .config" so verify that the variable was actually changed in the final config /workspace/build/.config

:eek: