官术网_书友最值得收藏!

How to do it...

Let's see how to do it by following these steps:

  1. 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
  1. 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!

  1. 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
  1. 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 _.
  1. 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'

主站蜘蛛池模板: 亳州市| 东台市| 七台河市| 福鼎市| 望城县| 福建省| 吉木萨尔县| 衡阳市| 南宁市| 双城市| 库车县| 湖北省| 日土县| 永年县| 庐江县| 定西市| 泰宁县| 晴隆县| 中阳县| 潢川县| 景宁| 文登市| 弥勒县| 中西区| 宜川县| 霸州市| 鹤岗市| 叶城县| 娱乐| 穆棱市| 张家口市| 光泽县| 确山县| 西平县| 连城县| 禹城市| 尉氏县| 全南县| 上林县| 德化县| 铜鼓县|