Analysis of parameter transfer process of driver module in Linux

Analysis of parameter transfer process of driver module in Linux

Declare the parameter name, type and permission you want to pass in the driver module

module_param(variable name, type, permissions);

#include <linux/init.h>
#include <linux/module.h>

static char *p_name = "Usr";
module_param(p_name, charp, S_IRUGO);
MODULE_PARM_DESC(p_name, "This is a char * string.");

static int __init hi_init(void)
{
  printk(KERN_INFO "Hi enter %s\n",p_name);
  return 0;
}
module_init(hi_init);

static void __exit hi_exit(void)
{
  printk(KERN_INFO "Hi exit %s\n ",p_name);
}
module_exit(hi_exit);

MODULE_AUTHOR("libra13179");
MODULE_LICENSE("GPL v2");
KVERS = $(shell uname -r)

# Kernel modules
obj-m += hi.o

# Specify flags for the module compilation.
#EXTRA_CFLAGS=-g -O0

build: kernel_modules

kernel_modules:
  make -C /lib/modules/$(KVERS)/build M=$(CURDIR) modules
# @echo $(KVERS)

clean:
  make -C /lib/modules/$(KVERS)/build M=$(CURDIR) clean

If not set, the default value is used.

root@lin-virtual-machine:/home/lin/hi# insmod ./hi.ko
root@lin-virtual-machine:/home/lin/hi# cat /var/log/syslog | grep Hi
...
Jul 25 15:11:38 lin-virtual-machine kernel: [ 203.238178] Hi enter Usr
...

When using settings

root@lin-virtual-machine:/home/lin/hi# insmod hi.ko p_name='God'

After loading the module, a module folder will be generated under /sys/modules, and there will be a parameters folder under the folder.

It contains the file node named after the parameter name, which stores the value we set, for example, in p_name

root@lin-virtual-machine:/home/lin/hi# cat /sys/module/hi/parameters/p_name
God

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Linux kernel device driver memory management notes
  • Linux kernel device driver kernel time management notes
  • Linux kernel device driver character device driver notes
  • Linux kernel device driver virtual file system notes
  • Linux kernel device driver kernel debugging technical notes collation
  • Linux kernel device driver kernel linked list usage notes
  • Linux kernel device driver proc file system notes
  • Detailed explanation of Linux camera driver writing

<<:  Additional instructions for using getters and actions in Vuex

>>:  A detailed guide to custom directives in Vue

Recommend

Vue.js style layout Flutter business development common skills

Correspondence between flutter and css in shadow ...

Detailed explanation of using Docker to build externally accessible MySQL

Install MySQL 8.0 docker run -p 63306:3306 -e MYS...

Sample code for implementing a background gradient button using div+css3

As the demand for front-end pages continues to in...

Solution to ONLY_FULL_GROUP_BY error in Mysql5.7 and above

Recently, during the development process, the MyS...

Detailed explanation of JavaScript Promise and Async/Await

Table of contents Overview Four examples Example ...

MySql 8.0.11-Winxp64 (free installation version) configuration tutorial

1. Unzip the zip package to the installation dire...

How to choose between MySQL CHAR and VARCHAR

Table of contents VARCHAR and CHAR Types Conclusi...

Detailed explanation of Nginx configuration file

The main configuration file of Nginx is nginx.con...

Native Js implementation of calendar widget

This article example shares the specific code of ...

Use href to simply click on a link to jump to a specified place on the page

After clicking the a tag in the page, you want to ...

How to change the root user's password in MySQL

Method 1: Use the SET PASSWORD command mysql> ...

The benefits and examples of placing the site map at the bottom of the web page

In the past, almost every website had a sitemap p...

In-depth understanding of MySQL master-slave replication thread state transition

Preface The basic principle of MySQL master-slave...