[Android Q&A, Help & Troubleshooting] hoodz017:
Thanks in advance for any help that I may receive.

Samsung Galaxy J7 Perx

Model # - SM-J727P

SW Ver. - J727PVPU3AQJ3

HW Ver. - J727P.02

Kernel Version - 3.18.31-12377328

Baseband Version - J727PVPU3AQJ3

Build Number - NRD90M.J727PVPU3AQJ3

SE - Enforcing (can't change!)

Knox Version -2.7.1

CPU - 2.2 GHz Qualcomm Snapdragon 625 MSM8953 (aarch64) (8 Cores)

RAM - 2GB

Preface

I'm not a noob but I'm no dev either, please be precise and as laymen as possible in your answering. I am not primarily a linux user (thats changing ;)) but I can keep up with good instruction.

I recently flashed a rooted and deodexed stock rom to my Galaxy J7 Perx via Odin. All went well except for the fact that I tripped my KNOX counter in the process. From what I understand, (and please do correct me if I'm wrong) resetting the KNOX counter requires SElinux to be set to 'Permissive' mode. The problem is, my (if not all) Samsung device(s) sets the SElinux parameter to 'Enforcing' by default through the kernel configurations. Long story short, in order to permanently change the SElinux value from 'Enforcing' to 'Permissive', I set out to compile a custom kernel.

Using Linux Mint (18.2 Cinnamon 64-bit v3.4.6) I configured GCC (v4.8.5) and installed all required libraries (to my understanding) for cross-compiling aarch64 kernels.

I sourced my phone's kernel from here. Version J727PVPU2AQI3. (Please prefix urls.)

opensource.samsung.com/reception/receptionSub.do?method=sub&sub=F&searchValue=sm-j727p

The Toolchain was sourced from Android NDK (r16b)

The README in the downloaded kernel .zip file requires that I use the toolchain named 'aarch64-linux-android-4.9' which is found in this package. (Please prefix urls.)

developer.android.com/ndk/downloads/index.html

The Setup.

Kernel .zip extracted to path ~/Kernel

NDK .zip extracted to path ~/NDK

There is only only one thing I want to change in my kernel. That is the SElinux value. I navigated to

~/Kernel/security/selinux/Makefile

In Makefile I changed this value from

EXTRA_CFLAGS += -DCONFIG_ALWAYS_ENFORCE=true

to

EXTRA_CFLAGS += -DCONFIG_ALWAYS_ENFORCE=false

Save and quit no problems there. Mission accomplished.

Okay so now for the build. Here are my inputs and corresponding outputs.

INPUT

$ cd ~/Kernel
$ export ARCH=arm64
$ export CROSS_COMPILE=~/NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-

A little pre-cleanup to avoid errors...

INPUT

$ make clean && make mrproper

OUTPUT

CLEAN scripts/basic
CLEAN scripts/kconfig
CLEAN include/config include/generated
CLEAN .config .config.old

Now to apply a config file.

INPUT

$ make ARCH=arm msm8953_sec_eng_defconfig

I selected this .config because the prefix matches my processor model number. I assume this stands for secure english default configuration for msm8953 hardware? (Will using this defconfig affect the changes I made to the Makefile located in ~/Kernel/security/selinux/Makefile?)

PS - My defconfig directory: ~/Kernel/arch/arm/configs

OUTPUT

HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/zconf.lex.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
drivers/soc/qcom/Kconfig:938:warning: ignoring type redefinition of 'TIMA_LOG' from 'tristate' to 'boolean'
drivers/soc/qcom/Kconfig:938:warning: ignoring type redefinition of 'TIMA_LOG' from 'tristate' to 'boolean'
drivers/input/touchscreen/Kconfig:18:warning: config symbol defined without type
drivers/soc/qcom/Kconfig:368:warning: choice value used outside its choice group
drivers/soc/qcom/Kconfig:373:warning: choice value used outside its choice group
KCONFIG_SELINUX((null))
KCONFIG_LOG_SELINUX((null))
KCONFIG_TIMA((null))
KCONFIG_DMVERITY((null))
KCONFIG_VARIANT((null))
KCONFIG_DEBUG((null))
KCONFIG_KASLR((null))
#
# configuration written to .config
#

This is where it begins to look a little shady. What am I to make of these warnings? ('make menuconfig' command is working at this point) Any expert insight will be greatly appreciated on this and the following section. Nevertheless, the defconfig takes and onward I charge...

In accordance with the README in the kernel package I made an output folder using the following commands:

INPUT

$ mkdir out

OUTPUT

mkdir: cannot create directory ‘out’: File exists

Probably my doing. I've run that command previously.

INPUT

OUTPUT_DIR=out

Next, I amended the EXTRAVERSION and cross-compiler value within the Makefile located in ~/Kernel.

Original

EXTRAVERSION =

CROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)

Edited

EXTRAVERSION = 12377328

CROSS_COMPILE	?= ~/NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-

Save and close. Now time to compile. Yet again in compliance with the README.

INPUT

$ ./build_kernel.sh

OUTPUT

make: Entering directory '/home/anthony/Kernel'
make[1]: Entering directory '/home/anthony/Kernel/out'
HOSTCC scripts/basic/fixdep
GEN ./Makefile
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
drivers/soc/qcom/Kconfig:938:warning: ignoring type redefinition of 'TIMA_LOG' from 'tristate' to 'boolean'
drivers/soc/qcom/Kconfig:938:warning: ignoring type redefinition of 'TIMA_LOG' from 'tristate' to 'boolean'
drivers/input/touchscreen/Kconfig:18:warning: config symbol defined without type
drivers/soc/qcom/Kconfig:368:warning: choice value used outside its choice group
drivers/soc/qcom/Kconfig:373:warning: choice value used outside its choice group
arch/arm64/configs/msm8953_sec_defconfig:454:warning: override: reassigning to symbol HID_ACRUX_FF
arch/arm64/configs/msm8953_sec_defconfig:811:warning: override: reassigning to symbol USER_RESET_DEBUG
KCONFIG_SELINUX(arch/arm64/configs/selinux_defconfig)
arch/arm64/configs/selinux_defconfig:1:warning: override: reassigning to symbol EXT2_FS_XATTR
arch/arm64/configs/selinux_defconfig:4:warning: override: reassigning to symbol EXT4_FS_SECURITY
arch/arm64/configs/selinux_defconfig:5:warning: override: reassigning to symbol AUDIT
arch/arm64/configs/selinux_defconfig:6:warning: override: reassigning to symbol AUDITSYSCALL
arch/arm64/configs/selinux_defconfig:7:warning: override: reassigning to symbol SECURITY
arch/arm64/configs/selinux_defconfig:8:warning: override: reassigning to symbol LSM_MMAP_MIN_ADDR
arch/arm64/configs/selinux_defconfig:9:warning: override: reassigning to symbol SECURITY_NETWORK
arch/arm64/configs/selinux_defconfig:13:warning: symbol value 'y' invalid for SECURITY_SELINUX_CHECKREQPROT_VALUE
arch/arm64/configs/selinux_defconfig:15:warning: override: reassigning to symbol NF_CONNTRACK_SECMARK
arch/arm64/configs/selinux_defconfig:16:warning: override: reassigning to symbol NETFILTER_XT_TARGET_CONNSECMARK
arch/arm64/configs/selinux_defconfig:18:warning: override: reassigning to symbol IP_NF_SECURITY
KCONFIG_LOG_SELINUX((null))
KCONFIG_TIMA((null))
KCONFIG_DMVERITY((null))
KCONFIG_VARIANT(arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig)
arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig:19:warning: override: reassigning to symbol AFC_CHARGER_MODE
arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig:67:warning: override: reassigning to symbol USB_HOST_NOTIFY
arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig:94:warning: override: reassigning to symbol SLIMBUS
arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig:95:warning: override: reassigning to symbol SLIMBUS_MSM_NGD
arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig:96:warning: override: reassigning to symbol SOUNDWIRE
arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig:112:warning: override: reassigning to symbol NET_SCH_PRIO
arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig:113:warning: override: reassigning to symbol NET_SCHED
arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig:116:warning: override: reassigning to symbol NET_CLS_ACT
arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig:117:warning: override: reassigning to symbol NET_ACT_MIRRED
arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig:118:warning: override: reassigning to symbol NET_EMATCH
arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig:119:warning: override: reassigning to symbol NET_SCH_INGRESS
arch/arm64/configs/msm8953_sec_j7poplte_usa_spr_defconfig:136:warning: override: reassigning to symbol ZSMALLOC
KCONFIG_DEBUG((null))
KCONFIG_KASLR((null))
#
# configuration written to .config
#
make[1]: Leaving directory '/home/anthony/Kernel/out'
make: Leaving directory '/home/anthony/Kernel'
make: Entering directory '/home/anthony/Kernel'
make[1]: Entering directory '/home/anthony/Kernel/out'
GEN ./Makefile
scripts/kconfig/conf --silentoldconfig Kconfig
drivers/soc/qcom/Kconfig:938:warning: ignoring type redefinition of 'TIMA_LOG' from 'tristate' to 'boolean'
drivers/soc/qcom/Kconfig:938:warning: ignoring type redefinition of 'TIMA_LOG' from 'tristate' to 'boolean'
drivers/input/touchscreen/Kconfig:18:warning: config symbol defined without type
drivers/soc/qcom/Kconfig:368:warning: choice value used outside its choice group
drivers/soc/qcom/Kconfig:373:warning: choice value used outside its choice group
/home/anthony/Kernel/Makefile:661: Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR: -fstack-protector not supported by compiler
CHK include/config/kernel.release
UPD include/config/kernel.release
Using .. as source for kernel
.. is not clean, please run 'make mrproper'
in the '..' directory.
/home/anthony/Kernel/Makefile:979: recipe for target 'prepare3' failed
make[1]: *** [prepare3] Error 1
make[1]: Leaving directory '/home/anthony/Kernel/out'
Makefile:145: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2
make: Leaving directory '/home/anthony/Kernel'
cp: cannot stat 'out/arch/arm64/boot/Image': No such file or directory

From here I'm at a standstill. Can anyone make sense of what I may be doing wrong or missing?

And in advance.... Yes, I do understand all the risks that come with flashing a custom kernel. I have backups on standby.

Again, any and all help is greatly appreciated! Thanks!!!

Special thanks to TheWizardOfROMs. A lot of the progress I made was due to his tutorial here. (Please prefix urls.)

xdaforums.com/showthread.php?t=2152819

Build Machine Specs

OS - Linux Mint 18.2 Cinnamon 64-bit v3.4.6

Processor - Intel Pentium CPU 2127U @ 1.90GHz x2

Ram - 8GB