Changes

Jump to: navigation, search

Orange Pi CM4

724 bytes added, 11:45, 19 September 2023
How to install kernel header files
# The Linux image released by OPi comes with the deb package of the kernel header file by default, and the storage location is '''/opt/'''
::{| class="wikitable" style="width:800px;"
|-
|
orangepi@orangepi:~$ '''ls /opt/linux-headers*'''
/opt/linux-headers-legacy-rockchip-rk356x_x.x.x_arm64.deb
|}
<ol start="2" style="list-style-type: decimal;">
<li>Use the following command to install the deb package of the kernel header file</li>{| class="wikitable" style="background-color:#ffffdc;width:800px;" |-| </olbig> '''The name of the kernel header file deb package needs to be replaced with the actual name, please do not copy it.'''</big>|}{| class="wikitable" style="width:800px;" |-|
orangepi@orangepi:~$ '''sudo dpkg -i /opt/linux-headers-legacy-rockchip-rk356x_1.x.x_arm64.deb'''
|}</ol>
<ol start="3" style="list-style-type: decimal;">
<li>After installation, you can see the folder where the kernel header files are located under '''/usr/src'''</li></ol>{| class="wikitable" style="width:800px;" |-|
orangepi@orangepi:~$ '''ls /usr/src'''
linux-headers-5.10.160-rockchip-rk356x
|}</ol>
<ol start="4" style="list-style-type: decimal;">
<li><p>Then you can write a hello kernel module to test the kernel header file</p>
<ol style="list-style-type: lower-alpha;">
<li>First write the code of the hello kernel module, as follows:</li></ol></li></ol>{| class="wikitable" style="width:800px;" |-| orangepi@orangepi:~$ '''vim hello.c'''
orangepi@orangepi:~$ '''vim hello<p>#include &lt;linux/init.c'''h&gt;</p>
<p>#include &lt;linux/initmodule.h&gt;</p>
#include &lt;linux/module.h&gt;
static int hello_init(void)
{
:printk(&quot;Hello Orange Pi -- init\n&quot;); 
:return 0;
}
{
:printk(&quot;Hello Orange Pi -- exit\n&quot;); 
:return;
}
 
module_init(hello_init);
module_exit(hello_exit);
 
MODULE_LICENSE(&quot;GPL&quot;);
|}</ol>
<ol start="2" style="list-style-type: lower-alpha;">
<li>Then write the Makefile for compiling the hello kernel module, as follows:</li></ol>{| class="wikitable" style="width:800px;" |-|
orangepi@orangepi:~$ '''vim Makefile'''
all:
:make -C $(KDIR) M=$(PWD) modules
clean:
:rm -f *.ko *.o *.mod.o *.mod *.symvers *.cmd *.mod.c *.order
endif
|}</ol>
<ol start="3" style="list-style-type: lower-alpha;">
<li>Then use the make command to compile the hello kernel module. The output of the compilation process is as follows:</li>{| class="wikitable" style="background-color:#ffffdc;width:800px;" |-| </olbig> '''If there is a problem with compiling the code you copied here, please go to the official tool to download the source code and upload it to the Linux system of the development board for testing.''' [[File:cm4-img362.png]]</big>
[[File:cm4-img362.png|center]]
|}
{| class="wikitable" style="width:800px;"
|-
|
orangepi@orangepi:~$ '''make'''
make[1]: Entering directory '/usr/src/linux-headers-5.10.160-rockchip-rk35xx'
:CC [M] /home/orangepi/hello.o
:MODPOST /home/orangepi/Module.symvers
:CC [M] /home/orangepi/hello.mod.o
:LD [M] /home/orangepi/hello.ko
make[1]: Leaving directory '/usr/src/linux-headers-5.10.160-rockchip-rk35xx'
|}</ol>
<ol start="4" style="list-style-type: lower-alpha;">
<li>After compiling, the '''hello.ko''' kernel module will be generated</li></ol>{| class="wikitable" style="width:800px;" |-|
orangepi@orangepi:~$ '''ls *.ko'''
hello.ko
|}</ol>
<ol start="5" style="list-style-type: lower-alpha;">
<li>Use the '''insmod'''command to insert the '''hello.ko''' kernel module into the kernel</li></ol>{| class="wikitable" style="width:800px;" |-|
orangepi@orangepi:~$ '''sudo insmod hello.ko'''
|}</ol>
<ol start="6" style="list-style-type: lower-alpha;">
<li>Then use the '''demsg''' command to view the output of the '''hello.ko''' kernel module. If you can see the output below, it means that the'''hello.ko''' kernel module is loaded correctly.</li></ol>{| class="wikitable" style="width:800px;" |-|
orangepi@orangepi:~$ '''dmesg | grep &quot;Hello&quot;'''
[ 2871.893988] '''Hello Orange Pi -- init'''
|}</ol>
<ol start="7" style="list-style-type: lower-alpha;">
<li>Use the '''rmmod''' command to uninstall the '''hello.ko''' kernel module</li></ol>{| class="wikitable" style="width:800px;" |-|
orangepi@orangepi:~$ '''sudo rmmod hello'''
[ 3173.800892] '''Hello Orange Pi -- exit'''
|}
</ol>
</li></ol>
<span id="use-of-raspberry-pi-5-inch-screen"></span>
<span id="use-of-raspberry-pi-5-inch-screen"></span>
== Use of Raspberry Pi 5 Inch screen ==

Navigation menu