[Buildroot] how can i implement my kernel module and debug it

Esaïe Ledoux NJONGSSI KOUAM kouamdoux at gmail.com
Thu Oct 21 07:58:21 UTC 2021


Okay ...
I think I have a new form of error, I think it is while compiling.

buildroot# make kernel_module_test-dirclean
rm -Rf /home/ledoux/Documents/buildroot/output/build/kernel_module_test

/buildroot# make
>>> kernel_module_test  Extracting
>>> kernel_module_test  Patching
>>> kernel_module_test  Configuring
>>> kernel_module_test  Building
>>> kernel_module_test  Building kernel module(s)
PATH="/home/ledoux/Documents/buildroot/output/host/bin:/home/ledoux/Documents/buildroot/output/host/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games"
PKG_CONFIG="/home/ledoux/Documents/buildroot/output/host/bin/pkg-config"
PKG_CONFIG_SYSROOT_DIR="/" PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
PKG_CONFIG_LIBDIR="/home/ledoux/Documents/buildroot/output/host/lib/pkgconfig:/home/ledoux/Documents/buildroot/output/host/share/pkgconfig"
BR_BINARIES_DIR=/home/ledoux/Documents/buildroot/output/images
KCFLAGS=-Wno-attribute-alias /usr/bin/make -j3 -C
/home/ledoux/Documents/buildroot/output/build/linux-5.10.73
HOSTCC="/usr/bin/gcc -O2
-I/home/ledoux/Documents/buildroot/output/host/include
-L/home/ledoux/Documents/buildroot/output/host/lib
-Wl,-rpath,/home/ledoux/Documents/buildroot/output/host/lib" ARCH=x86_64
INSTALL_MOD_PATH=/home/ledoux/Documents/buildroot/output/target
CROSS_COMPILE="/home/ledoux/Documents/buildroot/output/host/bin/x86_64-buildroot-linux-uclibc-"
DEPMOD=/home/ledoux/Documents/buildroot/output/host/sbin/depmod
INSTALL_MOD_STRIP=1
 PWD=/home/ledoux/Documents/buildroot/output/build/kernel_module_test/.
M=/home/ledoux/Documents/buildroot/output/build/kernel_module_test/. modules
make[1] : on entre dans le répertoire
« /home/ledoux/Documents/buildroot/output/build/linux-5.10.73 »
scripts/Makefile.build:44:
/home/ledoux/Documents/buildroot/output/build/kernel_module_test/./Makefile:
Aucun fichier ou dossier de ce type
make[2]: *** Aucune règle pour fabriquer la cible
« /home/ledoux/Documents/buildroot/output/build/kernel_module_test/./Makefile
».
Arrêt.
make[1]: *** [Makefile:1822 :
/home/ledoux/Documents/buildroot/output/build/kernel_module_test/.] Erreur 2
make[1] : on quitte le répertoire
« /home/ledoux/Documents/buildroot/output/build/linux-5.10.73 »
make: *** [package/pkg-generic.mk:295 :
/home/ledoux/Documents/buildroot/output/build/kernel_module_test/.stamp_built]
Erreur 2


however here is what is inside the files:

Config.in :

config BR2_PACKAGE_KERNEL_MODULE_TEST
        bool "kernel_module_test"
        depends on BR2_LINUX_KERNEL
        help
                Linux Kernel Module Cheat.

Makefile :

obj-m := HelloKernelModule.o
HelloKernelModule-objs := hello.o

MAKE := make
KSRC := /lib/modules/$(shell uname -r)/build/
SRC := $(shell pwd)

modules:
        $(MAKE) -C $(KSRC) M=$(SRC) modules

modules_install:
        $(MAKE) -C $(KSRC) M=$(SRC) modules_install

clean:
        $(MAKE) -C $(KSRC) M=$(SRC) clean

external.desc :

name: KERNEL_MODULE_TEST

kernel_module_test.mk :

KERNEL_MODULE_VERSION = 1.0
KERNEL_MODULE_SITE =
$(BR2_EXTERNAL_KERNEL_MODULE_TEST_PATH)/kernel_module_test
KERNEL_MODULE_SITE_METHOD = local
$(eval $(kernel-module))
$(eval $(generic-package))

I'm not understanding very well that compilation error??
Where is it coming from ??

Le mer. 20 oct. 2021 à 08:17, Andreas Ziegler <br015 at umbiko.net> a écrit :

> Hi Esaïe,
>
> TL;DR: Main problem is probably the one Arnout mentioned. Fix
> external.desc, kernel-module-test.mk and Makefile; in that order.
>
> There are still some inconsistencies in your configuration, see remarks
> below.
>
> Stick to '-' (dash) in file names and '_' (underscore) in (k)config
> variables. The Linux kernel uses the same convention.
>
> On 2021-10-19 14:34, Esaïe Ledoux NJONGSSI KOUAM wrote:
> > so i have develop my kernel module and it is working very well.
> >
> > there is my folder :
> >
> > hello.c :
> >
> > #include <linux/module.h>    // included for all kernel modules
> > #include <linux/kernel.h>    // included for KERN_INFO
> > #include <linux/init.h>      // included for __init and __exit macros
> >
> > MODULE_LICENSE("GPL");
> > MODULE_AUTHOR("Lakshmanan");
> > MODULE_DESCRIPTION("A Simple Hello World module");
> >
> > static int __init hello_init(void)
> > {
> >     printk(KERN_INFO "Hello world!\n");
> >     return 0;    // Non-zero return means that the module couldn't be
> > loaded.
> > }
> >
> > static void __exit hello_cleanup(void)
> > {
> >     printk(KERN_INFO "Cleaning up module.\n");
> > }
> >
> > module_init(hello_init);
> > module_exit(hello_cleanup);
> >
> >> Makefile :
> >
> > obj-m += helloKernelModule.o
> > all:
> > make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
> >
> > clean:
> > make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
> >
> > when i run make , it generate some files like hello.o , hello.ko , ...
>
> This Makefile is broken, and will also not work correctly when run from
> inside the Buildroot environment: the syntax is incorrect, there is no
> rule how to make helloKernelModule.o from hello.c, you have an absolute
> reference to your host kernel, which is different from the one Buildroot
> uses.
>
> Introduce variables that work on your development machine, but can be
> overridden by Buildroot:
>
> obj-m := HelloKernelModule.o
> HelloKernelModule-objs := hello.o
>
> MAKE := make
> KSRC := /lib/modules/$(shell uname -r)/build/
> SRC := $(shell pwd)
>
> modules:
>         $(MAKE) -C $(KSRC) M=$(SRC) modules
>
> modules_install:
>         $(MAKE) -C $(KSRC) M=$(SRC) modules_install
>
> clean:
>         $(MAKE) -C $(KSRC) M=$(SRC) clean
>
> >> integrate the package into Buildroot (see comments below)
> >
> > But , i'm not understanding very well when you said i integrate the
> > package on buildroot. Is it only the Makefile and the hello.c code or
> > Makefile , hello.c code ,  hello.o , hello.ko , ... ?
>
> None of these. Your project is distinct; Buildroot sees it only as a
> source code package - a tarball that you download from the internet.
> Buildroot integration means defining where the source code can be found
> and what to to with it (Config.in and kernel-module-test.mk).
>
> >> check if the package builds correctly within Buildroot and gets
> > deployed to target/lib/modules
> >
> > Okay , i have put the project on one folder kernel_module_test in
> > buildroot tree
> >
> > external.desc :
> >
> > name: BR2_PACKAGE_KERNEL_MODULE_TEST
>
> This is not a Buildroot variable, but something that you define. So call
> it just KERNEL_MODULE_TEST. The string defined here will be inserted
> between 'BR2_EXTERNAL_' and '_PATH' ...
>
> > external.mk [1] :
> >
> > include $(sort $(wildcard
> > $(BR2_EXTERNAL_KERNEL_MODULE_TEST_PATH)/*/*.mk))
>
> BR2_EXTERNAL_KERNEL_MODULE_TEST_PATH is undefined and expands to an
> empty string. This probably works only because the files are located
> inside the buildroot tree. Should work correctly, once you fix 'name' in
> external.desc.
>
> > Config.in :
> >
> > config BR2_PACKAGE_KERNEL_MODULE_TEST
> >         bool "kernel_module_test"
> >         depends on BR2_LINUX_KERNEL
> >         help
> >                 Linux Kernel Module Cheat.
> >
> > kernel_module_test.mk [2] :
> >
> > KERNEL_MODULE_VERSION = 1.0
> > KERNEL_MODULE_SITE =
> > $(BR2_EXTERNAL_KERNEL_MODULE_TEST_PATH)/kernel_module_test
> > KERNEL_MODULE_SITE_METHOD = local
> > $(eval $(kernel_module_test))
> > $(eval $(generic-package))
>
> You renamed the project to KERNEL_MODULE_TEST. You must also do this to
> the variables in the .mk file. But do NOT rename $(eval
> $(kernel-module))!
>
> > As you can see , i want to use a BR2_EXTERNAL directory structure.
> >
> > So i have make it by typing :
> >
> > /buildroot# make BR2_EXTERNAL=kernel_module_test menuconfig
> >
> > Go ahead into External Options , and fortunatly , i have see my
> > package inside, .. so i have saved it and exit.
> >
> > After that i have type make.
> >
> >  i have seen my package on output/build , looks like
> > kernel_module_test folder that contains some files.
>
> Yes, but which files? They should be identical to the output of 'make'
> in the project folder. The important file is HelloKernelModule.ko.
>
> > Finaly , i have seen some files on
> > output/target/lib/modules/${BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE} but
> > not my module.
>
> Eventually you will have a folder 'extra' in target/lib/modules/$(uname
> -r), containing HelloKernelModule.ko. Also modules.dep will have a
> corresponding entry at the end.
>
> > So i think that it means that my modules/package was not loaded and i
> > can't exploit it.
> >
> > please where i have mistaken ??
> >
> >
> > Links:
> > ------
> > [1] http://external.mk
> > [2] http://kernel_module_test.mk
>
> Kind regards,
> Andreas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.buildroot.org/pipermail/buildroot/attachments/20211021/6e76efe6/attachment.html>


More information about the buildroot mailing list