How to build modules using WRLinux SDK
1. Prepare sdk
===============
In $PRJ directory, execute
# make export-sdk
then ensure that wrlinux-8.0.0.24-glibc-x86_64-intel_x86_64-wrlinux-image-glibc-std-sdk.sh is generated in $PRJ/export.
Copy the sdk to a work directory and extract the sdk.
# cp $PRJ/export/wrlinux-8.0.0.24-glibc-x86_64-intel_x86_64-wrlinux-image-glibc-std-sdk.sh /path-to-work-dir
# cd /path-to-work-dir
# ./wrlinux-8.0.0.24-glibc-x86_64-intel_x86_64-wrlinux-image-glibc-std-sdk.sh
setup the buid env
# source ./env.sh
# cd sysroots/corei7-64-wrs-linux/usr/src/kernel
# make scripts
# cd /path-to-work-dir
2. An example for building ko
==============================
a. Create a directory to create ko source.
b. Generate a C file in the ko source as below:
/* hello.c */
#include // included for all kernel modules
#include // included for KERN_INFO
#include // included for __init and __exit macros
MODULE_LICENSE("GPL");
MODULE_AUTHOR("my_name");
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);
c. Generate a Makefile in the ko source as below:
#Makefile for modules
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
d. Build the ko
# make
then the ko could be created.
阅读(888) | 评论(0) | 转发(0) |