Error Building Android Kernel Module on Ubuntu 14.04 - android

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!

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.

android kernel error: 'struct dentry' has no member named 'd_alias'

So I have cloned the android kernel source for my motorola mobile, and was in the process of building it.
Android Kernel Info:
Name: Android Kernel Motorola MSM8610
Device(Intended): Moto E
Hardware: MSM8610
Github: Kernel Source Link
Procedure:
First, I made the .config file using
make ARCH=arm msm8610_defconfig
then I tried to build the kernel image by creating a file name startBuild
startBuild:
make ARCH=arm SUBARCH=arm CROSS_COMPILE=/media/mohit/776b997b-f9a1-46c2-92a0-7f438c7b78e3/code/toolchain/arm-eabi-4.6/bin/arm-eabi- -j4
giving it required permissions
chmod +x startBuild
and executing it
./startBuild
But I am getting the following error message:
CHK include/linux/version.h
make[1]: Nothing to be done for 'arch/arm/boot/dtbs'.
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
CHK kernel/config_data.h
CC fs/overlayfs/inode.o
fs/overlayfs/inode.c: In function 'ovl_permission':
fs/overlayfs/inode.c:71:11: error: 'struct dentry' has no member named 'd_alias'
fs/overlayfs/inode.c:71:11: warning: initialization from incompatible pointer type [enabled by default]
error, forbidden warning: inode.c:71
scripts/Makefile.build:307: recipe for target 'fs/overlayfs/inode.o' failed
make[2]: *** [fs/overlayfs/inode.o] Error 1
scripts/Makefile.build:443: recipe for target 'fs/overlayfs' failed
make[1]: *** [fs/overlayfs] Error 2
Makefile:957: recipe for target 'fs' failed
make: *** [fs] Error 2
make: *** Waiting for unfinished jobs..
So how to fix this error?
Thank you.
Since version 3.19 of Linux kernel d_alias member of struct dentry has been moved to the member's union d_u, see definition of struct dentry in include/linux/dcache.h.
So, replacing reference to d_alias member to d_u.d_alias should help with that compatibility problem.
That replasing may also be performed globally in all files, see e.g. this post about fixing given error in vmware-tools.

Building LibVLC for x86

I've been trying to use LibVLC for Android and I followed the instructions at https://wiki.videolan.org/AndroidCompile and got it to work perfectly for ARM. However, when trying to compile it to x86, I set:
export ANDROID_ABI=x86
and then compiled in the same way, but now I have a problem as it fails to compile. Here's a truncated build log:
~/vlc-android$ sh compile.sh
VLC source found
Building tools
You are ready to build VLC and its contribs
Building the contribs
Generating EGL pkg-config file
Generating GLESv2 pkg-config file
Guessing build system... x86_64-linux-gnu
Creating configuration file... config.mak
Bootstrap completed.
...
config.status: executing libtool commands
Type "make; make install" to compile and install Speex
cd speexdsp && make install
make[1]: Entering directory `/home/user/vlc-android/vlc/contrib/contrib-android-i686-linux-android/speexdsp'
Making install in libspeexdsp
make[2]: Entering directory `/home/user/vlc-android/vlc/contrib/contrib-android-i686-linux-android/speexdsp/libspeexdsp'
CC resample.lo
In file included from resample.c:104:0:
resample_neon.h:142:21: error: redefinition of 'inner_product_single'
static inline float inner_product_single(const float *a, const float *b, unsigned int len)
^
In file included from resample.c:100:0:
resample_sse.h:40:21: note: previous definition of 'inner_product_single' was here
static inline float inner_product_single(const float *a, const float *b, unsigned int len)
^
make[2]: *** [resample.lo] Error 1
make[2]: Leaving directory `/home/user/vlc-android/vlc/contrib/contrib-android-i686-linux-android/speexdsp/libspeexdsp'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/home/user/vlc-android/vlc/contrib/contrib-android-i686-linux-android/speexdsp'
make: *** [.speexdsp] Error 2
As far as I can tell, in that project for some reason both the ARM headers and the SSE headers are being included, causing a redefinition error. However, I don't know why or what to try to fix it. Any suggestions would be much appreciated.
Autoconf doesn't look quite right, x86 build has nothing to do with NEON instruction set hence should not include resample_neon.h. I haven't found the root cause yet but for a quick solution, open resample.c under ../vlc-android/vlc/contrib/contrib-android-i686-linux-android/speexdsp/libspeexdsp and delete the following lines:
...
#ifdef _USE_NEON
#include "resample_neon.h"
#endif
...
then rerun the compile.sh, you should get a working apk for your x86 emulator/device.

Can't build hello world kernel module on Android JellyBean

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

Cross compiling to arm-linux using cygwin

I am trying to cross-compile strace using cygwin to Android emulator. I used this article
as my starting point. I installed the cross-compiler following these instructions. Then I prepared the makefile using
./configure -host=arm-linux
Now when I do make I get the following error:
$ make
make all-recursive
make[1]: Entering directory `/home/bruce/strace-4.6'
Making all in tests
make[2]: Entering directory `/home/bruce/strace-4.6/tests'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/bruce/strace-4.6/tests'
make[2]: Entering directory `/home/bruce/strace-4.6'
arm-linux-gcc -DHAVE_CONFIG_H -I. -I./linux/arm -I./linux -I./linux -Wall -Wwr
ite-strings -g -O2 -MT block.o -MD -MP -MF .deps/block.Tpo -c -o block.o block.c
block.c: In function `block_ioctl':
block.c:198: error: `u64' undeclared (first use in this function)
block.c:198: error: (Each undeclared identifier is reported only once
block.c:198: error: for each function it appears in.)
block.c:271: error: `BLKTRACESTOP' undeclared (first use in this function)
make[2]: *** [block.o] Error 1
make[2]: Leaving directory `/home/bruce/strace-4.6'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/bruce/strace-4.6'
make: *** [all] Error 2
This occurs even if I append -static after CFLAGS variable in Makefile (Why do I need to do this?). Please help.
Here are the lines 198-206:
case BLKGETSIZE64:
if (exiting(tcp)) {
uint64_t val;
if (syserror(tcp) || umove(tcp, arg, &val) < 0)
tprintf(", %#lx", arg);
else
tprintf(", %" PRIu64, val);
}
break;
First of all, what's BLKGETSIZE64 #defined as?
There might be a "u64" token hiding in the definition.
Is a 64-bit int actually a well defined object as far as arm-linux-gcc is concerned? Just a thought...but it must be, right?
And the -static addition to CFLAGS causes the binary program to be linked statically, as opposed to dynamically.
That means that all the code it needs to run will be built into the executable.
Ordinarily, it would dynamically link to Shared Object libraries (.so files, DLLs under Windows), but you can't necessarily count on the particular libraries that your program needs being included in an embedded device. Rather than install all the libraries on the handheld, you can (probably) save space by just building the relevant bits into your executable.

Categories

Resources