Last active
November 7, 2023 17:40
-
-
Save ppsilv/a4ab68ae7649cab766e553be0a1c0f9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| To compile linux drivers | |
| 1 - You must have a correct environment with the linux headers for your kernel or for the kernel you are compiling the driver maybe you are crosscompiling the driver | |
| thing that I don't know it is possible. | |
| * For orangepi 5 plus the kernel and ubuntu 22.04 jammy header are in /opt | |
| when I am writing this the package is: /opt/linux-headers-legacy-rockchip-rk3588_1.0.6_arm64.deb for the kernel 5.10.110-rockchip-rk3588, use uname -r to get your | |
| kernel version. | |
| * Some distributions you can use apt-get install linux-headers$('shell uname -r') | |
| * Unforunately you will must discover how to get your linux kernel headers. | |
| 2 - The header home is: /usr/src/linux-headers-5.10.110-rockchip-rk3588 | |
| * This is the path header must reside. | |
| 3 - The modules home is: /lib/modules/5.10.110-rockchip-rk3588/kernel | |
| 4 - You can compile you driver in your projects directory since you have a Makefile | |
| like this: | |
| Makefile | |
| +---------------------------------------------------------------------------+ | |
| | obj-m += hello.o | | |
| | | | |
| | all: | | |
| | make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules | | |
| | | | |
| | clean: | | |
| | make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean | | |
| +---------------------------------------------------------------------------+ | |
| hello.c | |
| +---------------------------------------------------------------------------+ | |
| |#include <linux/module.h> | | |
| |#include <linux/init.h> | | |
| | | | |
| |/*Meta information*/ | | |
| |MODULE_LICENSE("GPL"); | | |
| |MODULE_AUTHOR("Paulo da Silva"); | | |
| |MODULE_DESCRIPTION("My first driver in orange pi"); | | |
| |MODULE_INFO(intree, "Y"); | | |
| | | | |
| |static int __init ModuleInit(void) | | |
| |{ | | |
| | printk("hello: Input - This is my first Kernel driver "); | | |
| | return(0); | | |
| |} | | |
| | | | |
| |static void __exit ModuleExit(void) | | |
| |{ | | |
| | printk("hello: Output - Module exiting..."); | | |
| |} | | |
| | | | |
| |module_init(ModuleInit); | | |
| |module_exit(ModuleExit); | | |
| | | | |
| +---------------------------------------------------------------------------+ | |
| 5 - To compile: [make all] as simple as that | |
| * - When compiled, copy you driver in this case hello.ko to: | |
| cd /lib/modules/5.10.110-rockchip-rk3588/kernel/drivers | |
| mkdir hello | |
| cd hello | |
| cp <your project dir>/hello.ko . | |
| 6 - After your driver is compiled you must run the command depmod as root in | |
| directory: /lib/modules/5.10.110-rockchip-rk3588 | |
| cd /lib/modules/5.10.110-rockchip-rk3588 | |
| depmod | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment