- Linux Device Driver Development Cookbook
- Rodolfo Giometti
- 443字
- 2021-06-24 13:54:15
How it works...
Once compiled as before, a new file, module_par.ko, should be ready to be loaded into our ESPRESSObin. However, before doing it, let's use the modinfo utility on it, as follows:
# modinfo module_par.ko
filename: /root/module_par.ko
version: 0.1
description: Module with parameters
author: Rodolfo Giometti
license: GPL
srcversion: 21315B65C307ABE9769814F
depends:
name: module_par
vermagic: 4.18.0 SMP preempt mod_unload aarch64
parm: var:an integer value (int)
parm: str:a string value (charp)
parm: arr:an array of 8 values (array of int)
As we can see in the last three lines (all prefixed by the parm: string), we have a list of module's parameters defined in the code by the module_param() and module_param_array() macros and described with MODULE_PARM_DESC().
Now, if we simply insert the module as before, we get default values, as shown in the following code block:
# insmod module_par.ko
[ 6021.345064] module_par:module_par_init: loaded
[ 6021.347028] module_par:module_par_init: var = 0x3f
[ 6021.351810] module_par:module_par_init: str = "default string"
[ 6021.357904] module_par:module_par_init: arr = 0 0 0 0 0 0 0 0
But if we use the next command line, we force new values:
# insmod module_par.ko var=0x01 str=\"new value\" arr='1,2,3'
[ 6074.175964] module_par:module_par_init: loaded
[ 6074.177915] module_par:module_par_init: var = 0x01
[ 6074.184932] module_par:module_par_init: str = "new value"
[ 6074.189765] module_par:module_par_init: arr = 1 2 3 0 0 0 0 0
As a final note, let me suggest taking a closer look at the following module parameter definition:
static int var = 0x3f;
module_param(var, int, S_IRUSR | S_IWUSR);
MODULE_PARM_DESC(var, "an integer value");
First, we have the declaration of the variable that represents the parameter, then we have the real module parameter definition (where we specify the type and the file access permissions), and then we have the description.
The modinfo command is able to display all of the preceding information, except the file access permissions, which refer to the file related to this parameter within the sysfs filesystem! In fact, if we take a look at the /sys/module/module_par/parameters/ directory, we get the following:
# ls -l /sys/module/module_par/parameters/
total 0
-rw------- 1 root root 4096 Feb 1 12:46 arr
-rw------- 1 root root 4096 Feb 1 12:46 str
-rw------- 1 root root 4096 Feb 1 12:46 var
Now, it should be clear what parameters S_IRUSR and S_IWUSR means; they allow the module user (that is, the root user) to write into these files and then read from them the corresponding parameters.
- Designing Purpose:Built Drones for Ardupilot Pixhawk 2.1
- 每天5分鐘玩轉(zhuǎn)Kubernetes
- Hands-On DevOps with Vagrant
- 嵌入式Linux系統(tǒng)開發(fā):基于Yocto Project
- 精解Windows 8
- 精解Windows8
- 高性能Linux服務(wù)器構(gòu)建實(shí)戰(zhàn):系統(tǒng)安全、故障排查、自動(dòng)化運(yùn)維與集群架構(gòu)
- 嵌入式系統(tǒng)原理及開發(fā)
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)(Windows 7+Office 2016)
- Linux設(shè)備驅(qū)動(dòng)開發(fā)
- Troubleshooting Docker
- Windows 7使用詳解(修訂版)
- 操作系統(tǒng)之哲學(xué)原理第2版
- Mastering Eclipse Plug-in Development
- Hadoop Operations and Cluster Management Cookbook