Simple linux kernel module build error with yocto external sdk

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Simple linux kernel module build error with yocto external sdk

5,910 Views
YuriF
Contributor I

Greetings, Colleagues!

I'm trying to build simple hello-world linux kernel module using yocto external sdk for i.MX8QuadPlus (MEK board) and currently stuck at compilation error:

ysfedorov@LAPTOP-TU9D1V4V:~/my_c$ make
make -C /opt/fsl-imx-xwayland/5.4-zeus/sysroots/aarch64-poky-linux/usr/src/kernel M=/home/ysfedorov/my_c modules
make[1]: Entering directory '/opt/fsl-imx-xwayland/5.4-zeus/sysroots/aarch64-poky-linux/lib/modules/5.4.47-2.2.0+g5ec03d06f54e/build'
    CC [M] /home/ysfedorov/my_c/my_module.o
In file included from ./include/linux/types.h:6,
                        from ./include/linux/list.h:5,
                        from ./include/linux/module.h:9,
                        from /home/ysfedorov/my_c/my_module.c:1:
./include/uapi/linux/types.h:5:10: fatal error: asm/types.h: No such file or directory
    5 | #include <asm/types.h>
       | ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [scripts/Makefile.build:266: /home/ysfedorov/my_c/my_module.o] Error 1
make[1]: *** [Makefile:1703: /home/ysfedorov/my_c] Error 2
make[1]: Leaving directory '/opt/fsl-imx-xwayland/5.4-zeus/sysroots/aarch64-poky-linux/lib/modules/5.4.47-2.2.0+g5ec03d06f54e/build'
make: *** [Makefile:6: all] Error 2

What i've done:

  • add to conf/local.conf TOOLCHAIN_TARGET_TASK_append = " kernel-devsrc" in order to build sdk with the kernel sources
  • used "bitbake core-image-minimal -c populate_sdk" to build sdk
  • installed it to default location (/opt/..)
  • after install cd to ~/my_c folder and source /opt/fsl-imx-xwayland/5.4-zeus/environment-setup-aarch64-poky-linux
  • and run "make" command (ARCH and CROSS_COMPILE has been defined by setup script)

Source file hello.c:

 

#include <linux/module.h>

static int __init hello_init(void)
{
    pr_info("hello from init\n");
    return 0;
}

static void __exit hello_exit(void)
{
    pr_info("hello from exit\n");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENCE("GPL");
MODULE_AUTHOR("ysfedorov");
MODULE_DESCRIPTION("This is simple hello world example of module");

 

Makefile:

obj-m += hello.o

KERNEL_DIR ?= $(SDKTARGETSYSROOT)/usr/src/kernel

all:
    make -C $(KERNEL_DIR) M=$(PWD) modules

clean:
    make -C $(KERNEL_DIR) M=$(PWD) clean
 
I've tried replace CC variables in kernel Makefile to variables from environment setup - still got that error.
What did i miss? Is there any additional setup steps i need to do?
Any help will be appreciated!
0 Kudos
Reply
5 Replies

5,901 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello YuriF,

 

You must correct the path of include/uapi/linux/types and you compile your project.

 

Regards

 

0 Kudos
Reply

5,884 Views
YuriF
Contributor I

Hello Bio_TICFSL

Thanks for your reply. Would you tell me what exactly path must be?

If try compile source like ordinary user application with $(CC) hello.c -o hello it will pass includes but break further at unknown symbols (__init) so it knows how to resolve/find any needed headers.

0 Kudos
Reply

5,486 Views
dan_hilgert
Contributor II

@YuriF ,

Did you figure this out. I see this issue too.

@Bio_TICFSL,

any additional info you can provide?

 

Thanks,

Dan

0 Kudos
Reply

5,474 Views
dan_hilgert
Contributor II

I think I figured it out.

It looks like there are a number of paths that need to be changed from asm to asm-generic.

I believe this is what Bio_TICFSL  was referring to. 

0 Kudos
Reply

5,441 Views
dan_hilgert
Contributor II

I was wrong and am not sure what @YuriF  was saying. 

 

This is what I did to resolve the issue.

  1. Install Yocto SDK on host machine in default location
  2. cd <sdk-install-path>/sysroots/<mach>/usr/src/kernel
    • My specific machine was 
      • cd /opt/fsl-imx-xwayland/4.19-thud/sysroots/aarch64-poky-linux/usr/src/kernel
  3. sudo bash -c "source /opt/fsl-imx-xwayland/4.19-thud/environment-setup-aarch64-poky-linux && make syncconfig scripts"
    • dan_hilgert_0-1618233178186.png

       


       

0 Kudos
Reply