0

When I have a kernel module that uses multiple source files bitbake doesn't seem to build them appropriately. This example module just performs a printk on loading and unloading the module. When it is built with the comments in the code in place as shown below, I see the printks when loading and unloading the module. When I remove the comments and effectively enable the second source code file, testprint.c/h, I no longer see anything at all when I load and unload the module. Bitbake also runs as expected and I don't see any errors or warnings from the build.

When I un-comment the lines in hello.c but leave the hello-objs line commented out in the makefile bitbake fails (understandably) to build the module with the ERROR that testprint is undefined.

Am I doing something wrong here?

Test module folder hierarchy,

test-mod
|- files
|--- COPYING
|--- Makefile
|--- hello.c
|--- testprint.c
|--- testprint.h
|- test-mod_0.1.bb

hello.c,

// works when the below /* */ comments are in place
#include <linux/module.h>
/* #include "testprint.h" */

int init_module(void)
{
    printk("Hello World!\n");
    /* testprint(); */
    return 0;
}

void cleanup_module(void)
{
    printk("Goodbye Cruel World!\n");
}

MODULE_LICENSE("GPL");

testprint.h,

void testprint(void);

testprint.c,

#include "testprint.h"
#include <linux/module.h>

MODULE_LICENSE("GPL");

void testprint(void)
{
    printk("howdy\n");
}

makefile,

obj-m := hello.o
# hello-objs := testprint.o

SRC := $(shell pwd)
all:
    $(MAKE) -C $(KERNEL_SRC) M=$(SRC) I=$(INC)

modules_install:
    $(MAKE) -C $(KERNEL_SRC) M=$(SRC) I=$(INC) modules_install

clean:
    rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c

test-mod_0.1.bb,

SUMMARY = "Example of how to build an external Linux kernel module"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e"

inherit module

SRC_URI = "file://Makefile \
           file://hello.c \
           file://testprint.c \
           file://testprint.h \
           file://COPYING \
          "

S = "${WORKDIR}"
gutelfuldead
  • 562
  • 4
  • 22
  • @Tsyvarev unfortunately not. Looks like my makefile is already using the suggested formats in the answers. – gutelfuldead Jul 17 '23 at 15:56
  • "Looks like my makefile is already using the suggested formats in the answers." - What "suggested format" do you use in your Makefile? You cannot build the module named `hello` from the source files `hello.c` and `testprint.c`, whether you specify `hello-objs` or not. You need to rename either the module or the source file. – Tsyvarev Jul 17 '23 at 16:13
  • @Tsyvarev ah I misunderstood, you are 100% correct; tested and confirmed by renaming the module and adding hello.o to the *-objs. I misunderstood the format. This is a repeat question and I'll close it as such. Thank you. – gutelfuldead Jul 17 '23 at 16:33

0 Answers0