Compilation Method for Rockchip Driver

by yir65681 in Circuits > Microcontrollers

28 Views, 1 Favorites, 0 Comments

Compilation Method for Rockchip Driver

20240926162850091.png

There are 2 ways to compile the rockchip driver, one is from the kernel, another one is as the module.

Supplies

Rockchip

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:

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.

Compile the Driver As a Module:

file (4).png

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 as the pic

Solution: The kernel top-level Makefile file specifies the architecture and cross-compiler.

Compile the Driver As a Module:

file (5).png
file (6).png

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. as in pic 1

Advantages: Execute the make command, and only hello. C driver files will be compiled separately.

Issues encountered: as in pic 2

Solution: The kernel top-level Makefile file specifies the architecture and cross-compiler.


Appendix:

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");