Search code examples
linux-kernelraspberry-pilinux-device-drivercross-compiling

Trying to cross-compile the driver during kernel compilation; the driver does not compile


I'm trying to learn Linux and compile the kernel with my simple driver.

Unfortunately, I do not see the driver in the logs and the compiled file is not created.

drivers/misc/answer.c:

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
 
/* Module Init function */
static int __init hello_world_init(void)
{
    printk(KERN_INFO "This is the Simple Module\n");
    printk(KERN_INFO "Kernel Module Inserted Successfully...\n");
    return 0;
}
/* Module Exit function */
static void __exit hello_world_exit(void)
{
    printk(KERN_INFO "Kernel Module Removed Successfully...\n");
}
 
module_init(hello_world_init);
module_exit(hello_world_exit);
 
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("A simple hello world driver");
MODULE_VERSION("2:1.0");

drivers/misc/Makefile:

...
odj-$(CONFIG_ANSWER)            += answer.o
...

drivers/misc/Kconfig:

...
config ANSWER
        tristate "Add the answer"
        help
                my module
...

.config

...
# Misc devices
CONFIG_ANSWER=y
...

Compile the kernel

$ sudo make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs

I don't see my file in the command output. Also the driver is not compiled. I added the driver to the menu; shown in .config.

I simplified the driver as much as possible. If there were errors in it, would it appear in the output?

I also tried to change the permissions.

-rw-rw-r-- 1 user user   955 Jul 31 17:52 answer.c

What am I doing wrong?


Solution

  • You have a typo in your Makefile.

    odj-$(CONFIG_ANSWER)            += answer.o
    

    Should be

    obj-$(CONFIG_ANSWER)            += answer.o