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

How it works...

Now, it's time to see how all of the previous steps work. In future sections, we're going to explain better what this code really does. However, at the moment, we should just notice the following.

In step 1, notice the calls to module_init() and module_exit(), kernel-provided C macros, which are used to tell the kernel that, during the boot or shutdown of the system, it must call the functions we provided, named dummy_code_init() and dummy_code_exit(), which, in turn, just print some information messages.

Later on in this chapter, we're going to see in detail what printk() does and what the KERN_INFO macro means but, for now, we should take into account only that they are used to print a message during the boot (or shutdown). For instance, the preceding code instructs the kernel to print out the message dummy-code loaded at some time during the boot stage.

In step 2, in the Makefile, we are simply telling the kernel that if CONFIG_DUMMY_CODE has been enabled (that is CONFIG_DUMMY_CODE=y), then dummy-code.c must be compiled and inserted into the kernel binary (linked), while with the Kconfig file, we just add our new module into the kernel configuration system.

In step 3, we enable the compilation of our code by using the make menuconfig command.

In step 4, finally, we recompiled the kernel in order to add our code within it.

In step 5, during the boot, we should see the following kernel message:

...
loop: module loaded
dummy-code loaded
ahci-mvebu d00e0000.sata: AHCI 0001.0300 32 slots 1 ports 6 Gbps
...
主站蜘蛛池模板: 天祝| 天祝| 德庆县| 桃园县| 徐汇区| 绍兴县| 垣曲县| 新绛县| 丹凤县| 砚山县| 江口县| 崇阳县| 许昌县| 阿鲁科尔沁旗| 阳春市| 鲜城| 凤山县| 彩票| 疏附县| 通化县| 方城县| 洛南县| 晋州市| 新余市| 隆子县| 太原市| 英吉沙县| 赣榆县| 随州市| 弥勒县| 忻城县| 汉寿县| 郓城县| 永清县| 依兰县| 抚顺县| 新绛县| 镇坪县| 项城市| 柘荣县| 济南市|