Can't build hello world kernel module on Android JellyBean - android

I'm trying to build a simple kernel module on Android JellyBean.
Code:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */
MODULE_LICENSE("GPL");
MODULE_AUTHOR("test");
MODULE_DESCRIPTION("Android ko test");
int init_module(void)
{
printk(KERN_ALERT, "Hello world\n");
// A non 0 return means init_module failed; module can't be loaded.
return 0;
}
void cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world 1.\n");
}
Makefile:
obj-m +=hello.o
KERNELDIR ?= ~/android/kernel
PWD := $(shell pwd)
CROSS_COMPILE=~/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-
ARCH=arm
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
Output:
make -C ~/android/kernel M=/home/test/testmod ARCH=arm CROSS_COMPILE=~/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- modules
make[1]: Entering directory `/home/test/android/kernel'
ERROR: Kernel configuration is invalid.
include/generated/autoconf.h or include/config/auto.conf are missing.
Run 'make oldconfig && make prepare' on kernel src to fix it.
WARNING: Symbol version dump /home/test/android/kernel/Module.symvers
is missing; modules will have no dependencies and modversions.
CC [M] /home/test/testmod/hello.o
In file included from <command-line>:0:
/home/test/android/kernel/include/linux/kconfig.h:4:32: error: generated/autoconf.h: No such file or directory
In file included from /home/test/android/kernel/arch/arm/include/asm/types.h:4,
from include/linux/types.h:4,
from include/linux/list.h:4,
from include/linux/module.h:9,
from /home/test/testmod/hello.c:1:
include/asm-generic/int-ll64.h:11:29: error: asm/bitsperlong.h: No such file or directory
In file included from /home/test/android/kernel/arch/arm/include/asm/posix_types.h:38,
from include/linux/posix_types.h:47,
from include/linux/types.h:17,
from include/linux/list.h:4,
from include/linux/module.h:9,
from /home/test/testmod/hello.c:1:
include/asm-generic/posix_types.h:70:5: warning: "__BITS_PER_LONG" is not defined
error, forbidden warning: posix_types.h:70
make[2]: *** [/home/test/testmod/hello.o] Error 1
make[1]: *** [_module_/home/test/testmod] Error 2
make[1]: Leaving directory `/home/test/android/kernel'
make: *** [default] Error 2
If I follow the suggestion in the output, and run 'make oldconfig && make prepare' on the kernel, it leads me through dozens of kernel config yes / no questions. After that, the compile still fails on the next error, which is about bitsperlong.h.

Android puts output binaries under out directory. So for example one can have out/target/product/<target name>/obj/KERNEL_OBJ/ or $ANDROID_PRODUCT_OUT/obj/KERNEL_OBJ/ if $ANDROID_PRODUCT_OUT is defined. This directory may have a different name from different vendors but simply that's the directory containing vmlinux.
So when you compile a kernel module under Android repo, you should submit make command like below inside your module's directory.
make -C $ANDROID_PRODUCT_OUT/obj/KERNEL_OBJ/ M=`pwd` ARCH=arm CROSS_COMPILE=arm-eabi- modules

Make modules should be done after compiling the kernel at least once. You have not compiled the kernel, that's why Module.symvers is missing. During compilation certain header files like asm/bitsperlong.h are created.

Firstly make sure that you have compiled kernel in the specified path.
that is
" /home/test/android/kernel" but you are using
" /home/android/kernel " during compilation of module
KERNELDIR ?= ~/android/kernel has to be KERNELDIR ?= ~/test/android/kernel
If not then in the ~/android/kernel directory run the below command to compile the kernel.
make ARCH=arm CROSS_COMPILE=~/test/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi
After your kernel is compiled you will get this "__BITS_PER_LONG" variable defined in System.map file of kernel i,e
~/test/android/kernel/System.map
After this you will be able to compile your module without any hurdle

Related

Android kernel modules build failed

i want to build pixel3 blueline android10 kernel module.
my example test.c:
#include"linux/module.h"
#include"linux/kernel.h"
int init_module(void)
{
printk(KERN_INFO "Hello android kernel...\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye android kernel...\n");
}
my Makefile:
obj-m += test.o
all:
make -C /home/ijiami/newdisk/android10/aosp_kernel M=$(PWD) modules
i get android kernel branch android-msm-crosshatch-4.9-android10-qpr3:
ijiami#ijiami-All-Series:~/newdisk/android10/aosp_kernel$ ls
build build.config out prebuilts prebuilts-master private
the error:
ijiami#ijiami-All-Series:~/newdisk/android10/ko_test$ make
make -C /home/ijiami/newdisk/android10/aosp_kernel M=/home/ijiami/newdisk/android10/ko_test modules
make[1]: Entering directory '/home/ijiami/newdisk/android10/aosp_kernel'
make[1]: *** No rule to make target 'modules'. Stop.
make[1]: Leaving directory '/home/ijiami/newdisk/android10/aosp_kernel' Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
It appears that the makefile in the specified directory is not being found or is not being executed properly. Make sure that you are in the correct directory and that the makefile exists.
The error message also suggests that there is no rule for building target 'modules' in the makefile. Check the makefile in the specified directory and ensure that it has the correct target and dependencies for building the kernel modules.
Make sure that the kernel source has been successfully built and that the environment is set up correctly for building kernel modules. This typically involves setting the CROSS_COMPILE variable to point to the correct toolchain and ensuring that the correct headers are in place.
Also check if you have the necessary build dependencies installed.
It might be helpful to check the build documentation for the specific Android version and device that you are working with to ensure that you are following the correct steps for building kernel modules.

Error Building Android Kernel Module on Ubuntu 14.04

I am trying to build a hello world kernel module and load it on to my google nexus 5. I have succeeded in building the entire android kernel as a way of checking to make sure my kernel files are in order. Here is the version of the kernel that I checked out from git:
git clone https://android.googlesource.com/kernel/msm -b android-msm-hammerhead-3.4-lollipop-release
Here is my module, hello-1.c:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
static int hello3_data __initdata = 3;
static int __init hello_3_init(void)
{
printk(KERN_INFO "Hello, world %d\n", hello3_data);
return 0;
}
static void __exit hello_3_exit(void)
{
printk(KERN_INFO "Goodbye, world 3\n");
}
module_init(hello_3_init);
module_exit(hello_3_exit);
I am making this module with the following Makefile:
obj-m := hello-1.o
KDIR = ~/kernel2/
COMPDIR = ~/linaro3/bin/arm-eabi-
all:
$(MAKE) ARCH=arm CROSS_COMPILE=$(COMPDIR) -C $(KDIR) M=$(shell pwd) modules
clean:
$(MAKE) -C $(KDIR) M=$(shell pwd) clean
And here is the output of my Makefile:
make ARCH=arm CROSS_COMPILE=~/linaro3/bin/arm-eabi- -C ~/kernel2/ M=/home/isaac/modules modules
make[1]: Entering directory `/home/isaac/kernel2'
Building modules, stage 2.
MODPOST 1 modules
WARNING: "__aeabi_unwind_cpp_pr1" [/home/isaac/modules/hello-1.ko] undefined!
WARNING: "printk" [/home/isaac/modules/hello-1.ko] undefined!
CC /home/isaac/modules/hello-1.mod.o
/home/isaac/modules/hello-1.mod.c:8:1: error: variable '__this_module' has initializer but incomplete type
/home/isaac/modules/hello-1.mod.c:9:2: error: unknown field 'name' specified in initializer
/home/isaac/modules/hello-1.mod.c:9:2: warning: excess elements in struct initializer [enabled by default]
error, forbidden warning: hello-1.mod.c:9
make[2]: *** [/home/isaac/modules/hello-1.mod.o] Error 1
make[1]: *** [modules] Error 2
make[1]: Leaving directory `/home/isaac/kernel2'
make: *** [all] Error 2
However, I have actually run make menuconfig in my kernel root folder and enabled loadable module support,forced module loading, checked module unloading, and forced module unloading. This worked for people on other stackoverflow threads but did not work for me. I can answer further questions regarding specifics if they are posted as comments. Thanks!

Compiling kernel module without exact kernel source

I managed to compile my kernel module with a very similar kernel source like my Android device owns, but during the installation i get 'disagrees about version of symbol module_layout' error message, what is an expected behavior.
I picked the binary kernel image from the device and extracted the Module.symvers file. I tried to place the extracted file to the following places:
changed the original one in the similar kernel source's directory
next to my module source code (after compilation it is always emptied /imho because i don't export any symbol/)
After compiling my module, the values from the newly extracted file are still not used. The modulename.mod.c file still contains the original values.
Here is my Makefile for the module:
KERNEL_DIR=~/android/kernels/kernel_3.4.0
obj-m += module.o
PWD := $(shell pwd)
default:
$(MAKE) ARCH=arm CROSS_COMPILE=arm-eabi- -C $(KERNEL_DIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) clean
What am I missing?

android kernel source code compilation error

I need to customize the kernel of android to run on my Nexus S.
So I download the kernel with branch name "remotes/origin/android-samsung-2.6.35-gingerbread"
I tried to follow the instruction here http://source.android.com/source/building-kernels.html to build the kernel. To do this, I need the cross compile tool.In my target android source code version android-2.3.5_r1, there is no such tool(no prebuilts/ folder). So I downloaded the version 4.1.2 and set up the tool as path prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin .
Then I tried to build my kernel, but I got the following error:
[root#localhost samsung]# make
scripts/kconfig/conf -s arch/arm/Kconfig
CHK include/linux/version.h
CHK include/generated/utsrelease.h
make[1]: `include/generated/mach-types.h' is up to date.
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
CC drivers/gpu/pvr/osfunc.o
In file included from drivers/gpu/pvr/osfunc.c:39:0:
include/linux/pagemap.h: In function 'fault_in_pages_readable':
include/linux/pagemap.h:415:16: error: variable 'c' set but not used [-Werror=unused-but-set-variable]
drivers/gpu/pvr/osfunc.c: In function 'OSAccessOK':
drivers/gpu/pvr/osfunc.c:2144:13: error: variable 'linuxType' set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
make[3]: *** [drivers/gpu/pvr/osfunc.o] Error 1
make[2]: *** [drivers/gpu/pvr] Error 2
make[1]: *** [drivers/gpu] Error 2
make: *** [drivers] Error 2
Should I just disable the "all warnings being treated as errors" to solve it? Or maybe I need a better toolchain?
PS: The tool chain of the master branch and branch 4.2 can not be used by me. Because it looks like they are made for a 64-bit OS while my linux is 32-bit
Do you have the path of ARCH=ARM and TOOLCHAIN pointing to the toolchain in \prebuilts folder?
make ARCH=ARM TOOLCHAIN=\<homeofAOSP>\prebuilt\.. herring_defconfig
make clean before you do the make

Error while building Android V2.2[Froyo] Source Code

I'm getting the following error while building the Froyo Code -
No private recovery resources for TARGET_DEVICE passion
target Generated: libclearsilver-jni <= out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar
target Generated: libclearsilver-jni <= out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar
host C: libneo_util <= external/clearsilver/util/neo_hash.c
host Executable: acp (out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp)
/bin/bash: javah: command not found
/bin/bash: javah: command not found
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver- jni_intermediates/org_clearsilver_CS.h] Error 127
make: *** Waiting for unfinished jobs....
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver- jni_intermediates/org_clearsilver_HDF.h] Error 127
true
Please help me to find out the root cause for this build error.
This is probably a PATH issue. For me I had to do
export PATH=$PATH:/usr/java/jdk1.6.0_25/bin/
To make it work properly.
$ uname -m
x86_64
depending upon x86_64 or XXX32
modified the following files to use m64 for x86_64 and m32 for xxx32 in android directory
/external/clearsilver/cgi/Android.mk
/external/clearsilver/java-jni/Android.mk
/external/clearsilver/util/Android.mk
/external/clearsilver/cs/Android.mk
Edit the above mentioned files using vi or vim editor.
type
LOCAL_CFLAGS += -m64
LOCAL_LDFLAGS += -m64
command in the files below the line "LOCAL_CFLAGS := "
NOTE: If your system is x86_64 download JDK_1.5_update_xx_amd64.bin
Javah is a part of the JDK. Download and install one.

Categories

Resources