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

JavaScript to achieve simple provincial and municipal linkage

This article shares the specific code for JavaScr...

Building .NET Core 2.0 + Nginx + Supervisor environment under Centos7 system

1. Introduction to Linux .NET Core Microsoft has ...

When backing up files in Centos7, add the backup date to the backup file

Linux uses files as the basis to manage the devic...

jQuery realizes the shuttle box function

This article example shares the specific code of ...

Compatibility with the inline-block property

<br />A year ago, there were no articles abo...

Summary of MySQL injection bypass filtering techniques

First, let’s look at the GIF operation: Case 1: S...

Layui implements the login interface verification code

This article example shares the specific code of ...

Vue implements various ideas for detecting sensitive word filtering components

Table of contents Written in front Requirements A...

How MLSQL Stack makes stream debugging easier

Preface A classmate is investigating MLSQL Stack&...

Vue implements user login and token verification

In the case of complete separation of the front-e...

Detailed explanation of eight methods to achieve CSS page bottom fixed

When we are writing a page, we often encounter a ...

Detailed explanation of the cache implementation principle of Vue computed

Table of contents Initialize computed Dependency ...

Detailed explanation of the use of React list bar and shopping cart components

This article example shares the specific code of ...

How to optimize a website to increase access speed update

Recently, the company has begun to evaluate all s...

Vue3 draggable left and right panel split component implementation

Table of contents Breaking down components Left P...