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

Analysis of several situations where MySQL index fails

1. Best left prefix principle - If multiple colum...

How to view files in Docker image

How to view files in a docker image 1. If it is a...

Some findings and thoughts about iframe

This story starts with an unexpected discovery tod...

Solve the problem that ElementUI custom CSS style does not take effect

For example, there is an input box <el-input r...

Example code of the spread operator and its application in JavaScript

The spread operator allows an expression to be ex...

...

Linux command line operation Baidu cloud upload and download files

Table of contents 0. Background 1. Installation 2...

javascript input image upload and preview, FileReader preview image

FileReader is an important API for front-end file...

MySQL Index Optimization Explained

In daily work, we sometimes run slow queries to r...

Why is IE6 used by the most people?

First and foremost, I am a web designer. To be mor...

How to use CSS to pull down a small image to view a large image and information

Today I will talk about a CSS special effect of h...

How to import CSS styles into HTML external style sheets

The link-in style is to put all the styles in one...

Webpack loads css files and its configuration method

webpack loads css files and its configuration Aft...

Ubuntu 15.04 opens mysql remote port 3306

Ubuntu 15.04 opens MySQL remote port 3306. All th...