Thread (1 message) 1 message, 1 author, 2021-10-17

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

From: Andreas Ziegler <hidden>
Date: 2021-10-17 09:45:40

Hi Esaie,

On 2021-10-17 09:13, Esa?e Ledoux NJONGSSI KOUAM [off-list ref] 
wrote:
Hi everyone .
Sorry for the inconvenience , ...

I want to know how to load my kernel module, run it see these traces 
using
dmesg and debug it.
Buildroot is essentially a deployment tool, not a development 
infrastructure. You do need a working package to be able to integrate 
it.

Preferably, you do this step-by-step:

-- develop your kernel module, make sure it compiles and works correctly 
in your development environment
-- integrate the package into Buildroot (see comments below)
-- check if the package builds correctly within Buildroot and gets 
deployed to target/lib/modules
-- test on target hardware
So , i have read this part of the  (manual
<https://buildroot.org/downloads/manual/manual.html#_infrastructure_for_packages_building_kernel_modules>)
, but i don't know how to use it :

| What you may have noticed is that, unlike other package 
infrastructures,
we | explicitly invoke a second infrastructure. This allows a package 
to
build a kernel | module, but also, if needed, use any one of other 
package
infrastructures to | build normal userland components (libraries,
executables?). Using the kernel-module infrastructure on its own is not
sufficient; another package infrastructure *must* be used.
This means that a 'normal' build infrastructure (make, cmake, etc.) has 
to be used; you covered this by using "generic-package" and providing a 
(project) make file.
but in my way , i have try something :

- Config.in

config BR2_PACKAGE_KERNEL_MODULE
        bool "kernel_module"
        depends on BR2_LINUX_KERNEL
        help
                Linux Kernel Module Cheat.

- external.mk

KERNEL_MODULE_VERSION = 1.0
KERNEL_MODULE_SITE = $(BR2_EXTERNAL_KERNEL_MODULE_PATH)
KERNEL_MODULE_SITE_METHOD = local
$(eval $(kernel-module))
$(eval $(generic-package))
This file has the same name as your package: "kernel-module.mk". Do not 
mix Buildroot configuration (BR2_EXTERNAL) and development project; 
provide a path to your source directory in KERNEL_MODULE_SITE.

If you want to use a BR2_EXTERNAL directory structure, some more work is 
necessary; see [1]. It will be easier to install your configuration in 
the Buildroot tree; in that case, all of these files go into the 
Buildroot package directory, inside a directory named "kernel-module". 
Edit "package/Config.in" and add your package under a convenient menu 
heading.

The files below go into your project directory, the one that is 
referenced by $KERNEL_MODULE_SITE
- Makefile

obj-m += $(addsuffix .o, $(notdir $(basename $(wildcard
$(BR2_EXTERNAL_KERNEL_MODULE_PATH)/*.c))))
ccflags-y := -DDEBUG -g -std=gnu99 -Wno-declaration-after-statement

.PHONY: all clean

all:
    $(MAKE) -C '$(LINUX_DIR)' M='$(PWD)' modules

clean:
    $(MAKE) -C '$(LINUX_DIR)' M='$(PWD)' clean
Do not use Buildroot specific variables in your project makefile. 
Variables should be initialized. You are missing a modules_install 
target, see [2].
- hello.c

#include <linux/module.h>#include <linux/kernel.h>

MODULE_LICENSE("GPL");
static int myinit(void)
{
    printk(KERN_INFO "hello init\n");
    return 0;
}
static void myexit(void)
{
    printk(KERN_INFO "hello exit\n");
}

module_init(myinit)
module_exit(myexit)

And in the terminal :

make BR2_EXTERNAL="$(pwd)/../kernel_module" qemu_x86_64_defconfig
echo 'BR2_PACKAGE_KERNEL_MODULE=y' >> .config
make BR2_JLEVEL="$(($(nproc) - 2))" all
qemu-system-x86_64 -M pc -kernel output/images/bzImage -drive
file=output/images/rootfs.ext2,if=virtio,format=raw -append
root=/dev/vda -net nic,model=virtio -net user
If you plan to use BR2_EXTERNAL, provide all necessary files.
make <defconfig> needs to be run only once, to create a configuration. 
The configuration persists, until you modify it with "make 
{menu,n}config" or you call "make distclean". For the different 
configuration editors, see [3].

Start the config editor, select your package, exit and save. Afterwards 
start the build process:
$ make nconfig
$ make
On qemu :

modprobe hello
modprobe: module hello not found in modules.dep
The module has not been built and is not present on the target system.
how can i solve it ??

please i need your help
Kind regards,
Andreas

[1] https://buildroot.org/downloads/manual/manual.html#outside-br-custom
[2] 
https://www.kernel.org/doc/html/latest/kbuild/modules.html?highlight=modules%20symvers
[3] 
https://buildroot.org/downloads/manual/manual.html#_buildroot_quick_start
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help