Compilation Method for Rockchip Driver
Compile the driver to the kernel:
Create the hello folder for the kernel driver source code, add the hello. c and Makefile file, modify the parent directory/kernel/drivers/Makefile file, and execute the full compilation operation.
Modify as follows:
/hello/Makefile is:obj-y += hello.o
/kernel/drivers/Makefile; add the following code:obj-y += hello
Compile the driver as a module:
Method 1:
Create the hello folder for the kernel driver source code, add the hello. c and Makefile file, modify the parent directory/kernel/drivers/Makefile file, and execute the full compilation operation.
Modify as follows:
/hello/Makefile is:obj-m += hello.o
/kernel/drivers/Makefile; add the following code:obj-y += hello
If wanting to compile the driver but not wanting to perform a full compile operation that takes too much time, the following method can be chosen.
Method 2:
Create a hello folder in the kernel driver source code, add the hello. c and Makefile file, modify the parent directory/kernel/drivers/Makefile file, modify the/kernel/Makefile file to add the architecture and cross-compiler, and execute the make modules command.
Modify as follows:
/hello/Makefile is:obj-m += hello.o
/kernel/drivers/Makefile; add the following code:obj-y += hello
/kernel/Makefile, add the following code:
ARCH?= arm64
CROSS_COMPILE?=
$(srctree)/../prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
Advantages: When executing the make modules command, only the modules will be compiled, and the compilation time will be shortened.
Disadvantages: The driver source code needs to be added to the kernel, which is not easy to find and modify. In addition, the make modules command will determine that the source code is configured as a module and will be compiled.
Issues encountered:
Solution: The kernel top-level Makefile file specifies the architecture and cross-compiler.
Method 3:
Create a folder named "hello" at any path, and add the files ''hello.c'' and ''Makefile''. In the ''/hello/Makefile'', add the architecture and cross-compiler. Then, execute the ''make'' command in the directory where ''hello.c'' is located.
/hello/Makefile to write the following code.
Advantages: Execute the make command, and only hello. C driver files will be compiled separately.
Issues encountered:
Solution: The kernel top-level Makefile file specifies the architecture and cross-compiler.
Appendix:
hello.c #include#include MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void) { printk(KERN_ALERT "Hello World enter\n"); return 0; } static void hello_exit(void) { printk(KERN_ALERT "Hello World exit\n"); } module_init(hello_init); module_exit(hello_exit); MODULE_DESCRIPTION("A Sample Hello World Module"); MODULE_ALIAS("A Sample module");
Dear friends, we have created an exclusive embedded technical exchange group on Facebook, where our experts share the latest technological trends and practical skills. Join us and grow together!