打开主菜单

Wiki-Orange Pi β

更改

Orange Pi Zero 2W

添加553字节, 2023年9月21日 (四) 17:47
安装内核头文件的方法
== 安装内核头文件的方法 ==
{| class="wikitable" style="background-color:#ffffdc;width:800px;" |-| <big>'''<span style="color:#FF0000">Linux6.1内核的Debian11系统编译内核模块时会报GCC的错误。所以如果要编译内核模块请使用Debian12或者Ubuntu221</span>内核的Debian11系统编译内核模块时会报GCC的错误。所以如果要编译内核模块请使用Debian12或者Ubuntu22.04。'''</big>|}
<ol style="list-style-type: decimal;">
<li><p>OPi发布的Linux镜像默认自带了内核头文件的deb包,存放的位置为'''/opt/'''</p>
{| class="wikitable" style="width:800px;"
|-
|
<p>orangepi@orangepi:~$ '''ls /opt/linux-headers*'''</p>
<p>/opt/linux-headers-xxx-sun50iw9_x.x.x_arm64.deb</p>|}</li>
<li><p>使用下面的命令可以安装内核头文件的deb包</p>
{| class="wikitable" style="width:800px;" |-| <p>orangepi@orangepi:~$ '''sudo dpkg -i /opt/linux-headers*.deb'''</p>|}</li>
<li><p>安装完后在'''/usr/src'''下就能看到内核头文件所在的文件夹</p>
{| class="wikitable" style="width:800px;"
|-
|
<p>orangepi@orangepi:~$ '''ls /usr/src'''</p>
<p>linux-headers-x.x.x</p>|}</li>
<li><p>然后可以编译下Linux镜像中自带的hello内核模块的源码,hello模块的源码在'''/usr/src/hello'''中,进入此目录后,然后使用make命令编译即可。</p>
{| class="wikitable" style="width:800px;"
|-
|
<p>orangepi@orangepi:~$ '''cd /usr/src/hello/'''</p>
<p>orangepi@orangepi:/usr/src/hello$ '''sudo make'''</p>
<p>make -C /lib/modules/5.4.125/build M=/usr/src/hello modules</p>
<p>make[1]: Entering directory '/usr/src/linux-headers-5.4.125'</p>
:<p>CC [M] /usr/src/hello/hello.o</p>:<p>Building modules, stage 2.</p>:<p>MODPOST 1 modules</p>:<p>CC [M] /usr/src/hello/hello.mod.o</p>:<p>LD [M] /usr/src/hello/hello.ko</p><p>make[1]: Leaving directory '/usr/src/linux-headers-5.4.125'</p>|}</li>
<li><p>编译完后会生成'''hello.ko'''内核模块</p>
{| class="wikitable" style="width:800px;"
|-
|
<p>orangepi@orangepi:/usr/src/hello$ '''ls *.ko'''</p>
<p>hello.ko</p>|}</li>
<li><p>使用'''insmod'''命令可以将'''hello.ko'''内核模块插入内核中</p>
{| class="wikitable" style="width:800px;" |-| <p>orangepi@orangepi:/usr/src/hello$ '''sudo insmod hello.ko'''</p>|}</li>
<li><p>然后使用'''demsg'''命令可以查看下'''hello.ko'''内核模块的输出,如果能看到下面的输出说明'''hello.ko'''内核模块加载正确</p>
{| class="wikitable" style="width:800px;"
|-
|
<p>orangepi@orangepi:/usr/src/hello$ '''dmesg | grep &quot;Hello&quot;'''</p>
<p>[ 2871.893988] '''Hello Orange Pi -- init'''</p>|}</li>
<li><p>使用'''rmmod'''命令可以卸载'''hello.ko'''内核模块</p>
{| class="wikitable" style="width:800px;"
|-
|
<p>orangepi@orangepi:/usr/src/hello$ '''sudo rmmod hello'''</p>
<p>orangepi@orangepi:/usr/src/hello$ '''dmesg | grep &quot;Hello&quot;'''</p>
<p>[ 2871.893988] Hello Orange Pi -- init</p>
<p>[ 3173.800892] '''Hello Orange Pi -- exit'''</p>|}</li></ol>
<span id="linux系统支持的部分编程语言测试"></span>
 
== Linux系统支持的部分编程语言测试 ==
8,460
个编辑