- Linux Device Driver Development Cookbook
- Rodolfo Giometti
- 272字
- 2021-06-24 13:54:14
How to do it...
Let's see how to do it by following these steps:
- After placing the dummy-code.c and Makefile files in our current working directory on the host PC, it should look like the following when using the ls command, as follows:
$ ls
dummy-code.c Makefile
- Then, we can compile our module by using the following command:
$ make KERNEL_DIR=../../../linux/
make -C ../../../linux/ \
ARCH=arm64 \
CROSS_COMPILE=aarch64-linux-gnu- \
SUBDIRS=/home/giometti/Projects/ldddc/github/chapter_2/module modules
make[1]: Entering directory '/home/giometti/Projects/ldddc/linux'
CC [M] /home/giometti/Projects/ldddc/github/chapter_2/module/dummy-code.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/giometti/Projects/ldddc/github/chapter_2/module/dummy-code.mod.o
LD [M] /home/giometti/Projects/ldddc/github/chapter_2/module/dummy-code.ko
make[1]: Leaving directory '/home/giometti/Projects/ldddc/linux'
As we can see, now we have several files in the current working directory, and one of them is named dummy-code.ko; this is our kernel module ready to be transferred to the ESPRESSObin!
- Once the module has been moved into the target system (for example, by using the scp command), we can load it by using the insmod utility, as follows:
# insmod dummy-code.ko
- Now, by using the lsmod command, we can ask the system to display all loaded modules. On my ESPRESSObin, I only have the dummy-code.ko module, so my output is as shown:
# lsmod
Module Size Used by
dummy_code 16384 0
Note that the .ko postfix has been removed by the kernel module name, as the - character is replaced by _.
- Then, we can remove our module from the kernel by using the rmmod command, as follows:
# rmmod dummy_code
In case you get the following error, please verify you're running the correct Image file we got in Chapter 1 , Installing the Development System
rmmod: ERROR: ../libkmod/libkmod.c:514 lookup_builtin_file() could not open builtin file '/lib/modules/4.18.0-dirty/modules.builtin.bin'
rmmod: ERROR: ../libkmod/libkmod.c:514 lookup_builtin_file() could not open builtin file '/lib/modules/4.18.0-dirty/modules.builtin.bin'
推薦閱讀
- 嵌入式Linux開發技術
- Learning Windows Server Containers
- 大學計算機應用基礎實踐教程(Windows 7+Office 2013)
- Linux從零開始學(視頻教學版)
- Extending Puppet
- Installing and Configuring Windows 10:70-698 Exam Guide
- Linux系統安全基礎:二進制代碼安全性分析基礎與實踐
- AWS Development Essentials
- 跟老男孩學Linux運維:Shell編程實戰
- Linux 從入門到項目實踐(超值版)
- Drupal 7 Cookbook
- Ubuntu Linux操作系統實用教程
- Zabbix監控系統之深度解析和實踐
- Android應用性能優化最佳實踐
- 鴻蒙入門:HarmonyOS應用開發