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

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'

主站蜘蛛池模板: 宽城| 喀什市| 威海市| 武平县| 岚皋县| 南陵县| 盐池县| 安阳县| 江都市| 城口县| 如东县| 紫金县| 景宁| 图木舒克市| 汝州市| 黄陵县| 交城县| 阜平县| 平谷区| 隆化县| 永春县| 府谷县| 礼泉县| 天峻县| 武隆县| 阿鲁科尔沁旗| 太仓市| 甘孜| 民勤县| 南雄市| 龙井市| 北安市| 谢通门县| 夏邑县| 偏关县| 阿克陶县| 汉沽区| 铅山县| 丰镇市| 武平县| 天峨县|