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

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'

主站蜘蛛池模板: 西乌珠穆沁旗| 荔波县| 屏南县| 金塔县| 噶尔县| 龙州县| 宣城市| 唐山市| 湟中县| 蒲江县| 内黄县| 龙胜| 普洱| 集安市| 美姑县| 政和县| 大埔县| 五峰| 莆田市| 宁武县| 金华市| 绿春县| 广德县| 阳江市| 新建县| 平舆县| 措勤县| 阿坝县| 济阳县| 札达县| 镇远县| 都匀市| 正安县| 宁陕县| 南郑县| 洛南县| 渝中区| 庆城县| 祁东县| 夹江县| 安阳县|