Linux kernel device driver Linux kernel module loading mechanism notes summary

Linux kernel device driver Linux kernel module loading mechanism notes summary

#include <linux/moduleparam.h>

1. Module parameters

Defining variables in the driver

static int num = 0; //When the loading module does not specify the value of num, it is 0
  • module_param(variable name, type, permissions); type: byte, int, uint, short, ushort, long, ulong, bool, charp, permissions cannot have write permissions
  • Pass parameters: insmod test.ko variable name 1 = value 1 variable name 2 = value 2

The calling relationship of module_param is as follows:

#define module_param(name, type, perm) \
module_param_named(name, name, type, perm)
#define module_param_named(name, value, type, perm) \
param_check_##type(name, &(value)); \
module_param_call(name, param_set_##type, param_get_##type, &value, perm); \
__MODULE_PARM_TYPE(name, #type)
#define module_param_call(name, set, get, arg, perm) \
__module_param_call(MODULE_PARAM_PREFIX, \
  name, set, get, arg, \
  __same_type(*(arg), bool), perm)
#define __module_param_call(prefix, name, set, get, arg, isbool, perm) \
static int __param_perm_check_##name __attribute__((unused)) = \
BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)) \
+ BUILD_BUG_ON_ZERO(sizeof(""prefix) > MAX_PARAM_PREFIX_LEN); \
static const char __param_str_##name[] = prefix #name; \
static struct kernel_param __moduleparam_const __param_##name \
__used \
  __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
= { __param_str_##name, perm, isbool ? KPARAM_ISBOOL : 0, \
  set, get, { arg } }

Multiple c files can be compiled into a module, which can be achieved using the instructions in the Makefile xxx-objs, as follows:

test-objs := ao bo //Compile into test.ko from ac and bc. Note that there cannot be a .o file with the same name as the target ko file obj-m += test.o

You can view the module information in the system under /sys/module/module name/

1. View the information of the elf file

readelf test.ko -a

Ko file composition

  • 1. elf file header
  • 2. text data ...
  • 3. Sections table
  • 4. Symbol table

2. EXPORT_SYMBOL(function name/variable address) //Export the address of the function/or variable to the kernel symbol table

EXPORT_SYMBOL_GPL(function name)
///////////

/proc/kallsyms View the symbol table of the current system

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • An easy way to port Linux code to Windows
  • 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 system call 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
  • Linux kernel device driver advanced character device driver notes
  • Linux kernel device driver address mapping notes
  • Linux kernel device driver Linux kernel basic notes summary
  • Steps to transplant the new kernel to the Linux system

<<:  Example of adding and deleting range partitions in MySQL 5.5

>>:  JavaScript implements the protocol example in which the user must check the box

Recommend

Problems installing TensorRT in docker container

Uninstall the installed version on Ubuntu: sudo a...

CSS Skills Collection - Classics among Classics

Remove the dotted box on the link Copy code The co...

Share the 15 best HTML/CSS design and development frameworks

Professional web design is complex and time-consu...

Summary of the differences between Vue's watch, computed, and methods

Table of contents 1 Introduction 2 Basic usage 2....

How to run multiple MySQL instances in Windows

Preface In Windows, you can start multiple MySQL ...

VMware Workstation Pro 16 License Key with Usage Tutorial

VMware Workstation is a powerful desktop virtual ...

Super detailed basic JavaScript syntax rules

Table of contents 01 JavaScript (abbreviated as: ...

How to redirect nginx directory path

If you want the path following the domain name to...

How to manually install MySQL 5.7 on CentOS 7.4

MySQL database is widely used, especially for JAV...

Ant designing vue table to achieve a complete example of scalable columns

Perfect solution to the scalable column problem o...

HTML+CSS implementation code for rounded rectangle

I was bored and suddenly thought of the implementa...

Even a novice can understand the difference between typeof and instanceof in js

Table of contents 1. typeof 2. instanceof 3. Diff...

The simplest form implementation of Flexbox layout

Flexible layout (Flexbox) is becoming increasingl...

Implementation steps of encapsulating components based on React

Table of contents Preface How does antd encapsula...