Building kernel module

Ideas and dreaming will go this forum
Post Reply

eigma
Posts: 9
Joined: Sun Jul 19, 2020 2:48 am

Building kernel module

Post by eigma »

Hello,

UN40H5201
T-N14M6AKUC-1110
Linux version 3.8.13 (a.vishwakarm@DELL-BUILD25) (gcc version 4.7.4 (VDLinux.v7a8.GA3.2013-10-11) ) #1 PREEMPT Tue Sep 11 13:55:41 IST 2018
vermagic=0146, product preempt mod_unload ARMv7
Toolchain: VDLinux-armv7a8-toolchain-lite_20100630.tar.xz edit: This is a bad toolchain to use. It has an old gcc version (4.4.1), which has a bug, which causes kernel build to detect CC_HAVE_ASM_GOTO=n, HAVE_JUMP_LABEL=n and ultimately breaks the struct layout of 'struct module'. Use arm-v7a8v4r3.tar.xz, which matches the kernel.

I am trying to build a custom (very small) kernel module that will work on my device.

In general I am following this procedure (viewtopic.php?p=80976#p80976):
1) download toolchain (done)
2) download kernel sources
My model is too old, there is nothing on opensource.samsung.com.
Instead I have downloaded mainline kernel 3.8.13 and extracted.
3) "make ARCH=arm CROSS_COMPILE=arm-v7a8v4r3-linux-gnueabi- menuconfig"
Selected "ARM system type (TI OMAP)" (one of the few system types that produces "ARMv7" vermagic)
also through many attempts, found other config options that are necessary (details below)
4) some hack to force the needed vermagic on compilation
5) in my module directory, "make -C ../linux-3.8.13 ARCH=arm CROSS_COMPILE=arm-v7a8v4r3-linux-gnueabi- M=$(pwd)"
The module builds successfully, but I had many issues loading it on the device. See below.

Kernel configuration (.config)
The kernel options (eg. CONFIG_PREEMPT=y) make a huge difference in compatibility of module with the Samsung kernel. For example, I found the following are necessary:

Code: Select all

CONFIG_UNUSED_SYMBOLS=n
CONFIG_MODULE_SIG=n
CONFIG_GENERIC_BUG=y
CONFIG_KALLSYMS=n
CONFIG_SMP=n
CONFIG_FTRACE=n
CONFIG_JUMP_LABEL=y
CONFIG_PREEMPT=y
CONFIG_MODULE_UNLOAD=y
CONFIG_ARM_PATCH_PHYS_VIRT=n
CONFIG_FUNCTION_TRACER=n
This helps overcome many issues (symbol error __gnu_mcount_nc, kernel stack trace on insmod, mismatching 'struct module' layout and crashes on insert). It helps to check offsets of init_module and cleanup_module against stock modules:

mtd_exe/WIFI_LIB/QCA/ath6kl_usb.ko

Code: Select all

$ readelf -a rootfs//mtd_exe/WIFI_LIB/QCA/ath6kl_usb.ko -W
Relocation section '.rel.gnu.linkonce.this_module' at offset 0xc7114 contains 2 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name
000000bc  00099f02 R_ARM_ABS32            0003a85c   init_module
00000114  00095202 R_ARM_ABS32            0003a9dc   cleanup_module
0xbc - offset of module.init.
0x114 - offset of module.exit.

0x11c - section size of .gnu.linkonce.this_module - should match sizeof(struct module)

I guess the Samsung kernel has many code modifications, and it would really help to know the combination of CONFIG.

As I mentioned, opensource.samsung.com no longer has any source code for my device (UN40H5201 / T-N14M6AKUC-1110). Does anyone still have these files and would be able to share? It would greatly help my work.
UN40H5201 / T-N14M6AKUC-1111.1
eigma
Posts: 9
Joined: Sun Jul 19, 2020 2:48 am

Re: Building kernel module

Post by eigma »

Got samsung opensource release "14_UNxxH65xx_X14.zip", which contains VDLinux 3.8.2, and checking the kernel configuration:

Code: Select all

$ egrep '(CONFIG_UN...N_TRACER)(=| is not)' arch/arm/configs/X14_defconfig_release
# CONFIG_ARM_PATCH_PHYS_VIRT is not set
CONFIG_GENERIC_BUG=y
# CONFIG_KALLSYMS is not set
CONFIG_JUMP_LABEL=y
CONFIG_MODULE_UNLOAD=y
# CONFIG_MODULE_SIG is not set
CONFIG_SMP=y
CONFIG_PREEMPT=y
# CONFIG_UNUSED_SYMBOLS is not set
# CONFIG_FTRACE is not set
seems I got most of it right, except CONFIG_SMP=y
UN40H5201 / T-N14M6AKUC-1111.1

Post Reply

Return to “[H] Brainstorm”