Building custom kernel module


I tried to build my first kernel module for Linux builded from scratch. My problem is when I use make:

make ARCH=arm CROSS_COMIPLE=arm-cortex_a8-linux-gnueabi- -C ~/Desktop/LFS_v2/linux-3.5.3/ M=$pwd modules

I get:


cc1: error: unrecognized command line option ‘-mlittle-endian’
cc1: error: unrecognized command line option ‘-mno-thumb-interwork’
kernel/bounds.c:1:0: error: unknown ABI (aapcs-linux) for -mabi= switch
kernel/bounds.c:1:0: error: bad value (armv5t) for -march= switch
kernel/bounds.c:1:0: error: bad value (strongarm) for -mtune= switch
make[1]: *** [kernel/bounds.s] Błąd 1
make: *** [prepare0] Błąd 2


I run make command from directory with module C file and Makefile.
My module is simple example from book which only prints messages so it should be ok.
My Makefile has just one line:``
obj-m += first_module.o


I read that it is often problem with cross compiler.
Kernel compilation was previously made with the same CROSS_COMPILE parameter. And that cross compiler still exist and arm-cortex_a8-linux-gnueabi- is recognized command in terminal.

Because I’m not sure what are the paths in -C and M parameters: In my -C is path to directory where are kernel sources unpacked. M is like you see, pwd, and this directory is just next to linux-3.5.3 (from -C).

I don’t know if it is important, but at the beginning I didn’t know where to put first_module.c and Makefile files. So I put it first into kernel sources directory. That caused overwriting of original Makefile. So I restored that file from originally downloaded kernel tar.gz archive. I don’t know if sometimes that Makefile wasn’t changed when I was configuring kernel before building some time ago and now there is something wrong.

Do you know how to help?


I usually build my module using -C option

Say u are buiding a module some directory
In that Makefile
obj-m += usb-net.o

I would have sourced the for cross compilation
Then using the below command i make modules

#make -C /Your kernel directory M=pwd modules

For more information u can look at Kernel Documentation kbuild/modules.txt


Thanks for answer kavitha.

Can you tell me what should be in that script?
I found something like this for Angstrom [1]:


export SYSROOTS=${HOME}/angstrom-setup-scripts/build/tmp-angstrom_2008_1/sysroots
export PATH=${PATH}:${SYSROOTS}/i686-linux/usr/armv7a/bin
export ARCH=arm
export CROSS_COMPILE=arm-angstrom-linux-gnueabi-
export KERNELDIR=${SYSROOTS}/beagleboard-angstrom-linux-gnueabi/kernel
make -C ${KERNELDIR} M=$(pwd) modules


ARCH, CROSS_COMPILE and that what is with ‘make’ command I get.
SYSROOTS is general path for easier creating KERNELDIR path and for easier adding path to cross-compiler?

I tried to create my own Linux. This is what I do with kernel sources, maybe I missed something, but this Linux starts on Beagle:

make mrproper
make ARCH=arm omap2plus_defconfig
make ARCH=arm menuconfig (changes only in Initial RAM filesystem and RAM disk() and USB Network Adapter Driver)
make ARCH=arm CROSS_COMPILE=arm-cortex_a8-linux-gnueabi- modules (looks familiar :D)
make ARCH=arm INSTALL_MOD_PATH=/home/valdez/Desktop/LFS_v3/target modules_install

and after creating ramdisk:

make ARCH=arm CROSS_COMPILE=arm-cortex_a8-linux-gnueabi- uImage

I tried all procedure again from downloading kernel sources to that module compilation but have the same error.
Anyone see my mistake?


W dniu niedziela, 23 września 2012 21:36:39 UTC+2 użytkownik valdez napisał:

Look at first code line in my first post… especially in cross-comipler part…
I wrote that command line once and then used it from history, agrrrrrrrrr

W dniu niedziela, 23 września 2012 21:36:39 UTC+2 użytkownik valdez napisał: