Linux driver development initialization parameters, linux driver development

Source: Internet
Author: User

Linux driver development initialization parameters, linux driver development

First run the Code:

#include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/moduleparam.h>static char* whom = "World";static int howmany = 1;module_param( howmany, int, S_IRUGO );module_param( whom, charp, S_IRUGO );static int hello_init(void){        int i;        printk( KERN_ALERT "Hello, world! I'm Lizhixing.\n" );        for( i=0; i< howmany; ++i )        {                printk( KERN_ALERT "Hello, %s !\n", whom );        }        return 0;};static void hello_exit(void){        printk( KERN_ALERT "Good bye, cruel world. Tommorow is another day! \n" );};module_init( hello_init );module_exit( hello_exit );


Parameters can be accepted during Linux driver initialization. The command is as follows:

insmod hello.ko howmany=10 whom="Daddy"

Here, two parameters are input, howmany and whom.

To enable the module to receive the two parameters:

1. Include the header file moduleparam. h. This header file defines the required parameters.
2. Declare parameters. Supported types include:
Bool/invbool, both boolean, invbool reversed black and white, swap true and false, wonderful design, understanding can't .....
Charp is the string.
Int/long/short/uint/ulong/ushort. These are familiar old faces that cannot be used.
In addition, the Array parameter is supported, and that's all. If you want to use other types, you need to register the callback function for processing.
3. Use module_param (name, type, permission) to register this parameter, so that the kernel will assign values to the variable using the parameters in the command line.

Load module:
insmod hello.ko howmany=10 whom="Daddy"

Dmesg, printed:

33553.819340] Good bye, cruel world. Tommorow is another day! [383720.555138] perf samples too long (2516 > 2500), lowering kernel.perf_event_max_sample_rate to 50000[565169.015155] Hello, world! I'm Lizhixing.[565169.015179] Hello, Daddy[565169.015187] Hello, Daddy[565169.015194] Hello, Daddy[565169.015200] Hello, Daddy[565169.015207] Hello, Daddy[565169.015213] Hello, Daddy[565169.015220] Hello, Daddy[565169.015226] Hello, Daddy[565169.015232] Hello, Daddy[565169.015239] Hello, Daddy[565181.213351] Good bye, cruel world. Tommorow is another day! 








What are the classic reference books for studying underlying linux driver development?

You have completed all the structures, operating systems, architecture, compilation principles, and computer networks.

I think it can be divided into four stages, from low to high.
From installation and use => common linux commands => linux system programming => kernel development, read the kernel source code

When learning common linux commands, you must learn to compile the kernel, optimize the system, and adjust parameters.

There are too many installation and frequently-used command books. If you want to find this book in a little more details, you need to learn regular expressions.

Advanced unix environment programming is recommended for system programming.
And unix network programming.
At this time, you may also need to read the materials to understand the elf File Format, connectors and loaders. It is better to name a cmu textbook in Chinese as "Understanding the computer system in depth ".

For kernel development, read the kernel source code stage and start with the write driver to gradually develop the Linux kernel.
The reference book is linux device drivers, which is called ldd.
Linux kernel development
Understading the linux kernel, which is called utlk
Linux source code Scenario Analysis
These four books are essential books for kernel development.

Finally, the third and fourth stages are the most important. It is useless to give blank words, and reading is not covered.

How to Learn linux/unix programming methods

Recommended learning path:

First, learn the editor, vim, emacs, and anything.
Then, learn to make file. You only need to know a bit, so that you can prepare the program.

Then let's take a look at "C programming language" K & R. In this way, we can basically perform general programming. By the way, let's look at this data structure book.

If you want to learn UNIX/LINUX programming, APUE is a classic teaching material. Learn more about UNP. In this way, you can master the system.

Then look at Douglus E. comer's "using TCP/IP for Internet connection" Volume 1, learn about the network, and then read the first volume of "UNP", not only learn network programming, in addition, I am very familiar with some common techniques of system programming. If you continue network programming, we recommend that you read the third volume of "TCP/IP for Internet interconnection, there are a lot of programming about the application protocol telnet, ftp and other protocols.
If you want to write a device driver, first you must be familiar with the system programming interfaces such as files and IPC, and then learn "LDD" 2.

Comments on several classic textbooks:

The C program design textbook K & R is The inventor of C Language. Although it is a bit old, I often flip through a necessary manual. The length is relatively small, but every time you read it, you will get it again. It can also be replaced by Tan haoqiang's C language programming.

Advanced Programing in Unix Envirement W. Richard Steven S: it's also a very classic book (nonsense, but it's not a classic of the Steven s book !), Although it can be viewed by beginners, it is actually an auxiliary document in Unix Network Programing. The Chinese Translation of "Advanced Programming in UNIX environment" is not very good. Now there is a photoplate, it is easier to directly read English than to read Chinese.

Unix Network Programing W. richard Steven s: the first volume is about BSD Socket network programming interface and another network programming interface, but now we usually use BSD Socket, so this book only needs to read about half of it. The second volume is not designed for the network, mainly for inter-process communication and Posix Threads. After reading APUE, you can read it. Basically, the system is summarized by APUE and UNP vol2. After reading UNP, you will know the vast majority of programming skills in system programming, even if the first volume is about network programming. In China, Tsinghua translated Uni... the remaining full text>

Which of the following is a detailed description of linux driver and linux driver development?

Let me show you the book.
Dai Youwei, a C language programming book that surpasses K & R, Linux C Programming one-stop learning

This book has the following features:
• The C language is not isolated, but combined with the compilation principle, operating system, and computer architecture. In other words, the content of this book is only based on the C language. It really talks about the principles of computers and programs.
• Emphasizes the basic concepts and principles, and attaches great importance to the dependency between concepts in programming order. Each time a new concept is introduced, it only depends on the concepts mentioned in the previous chapter, it will never rely on the concepts described in the following chapters. In some cases, we will also reference the content to be discussed later in order to make a complete description. For example, "we will go to Chapter XX to explain it carefully." No such reference is necessary, if it does not exist, just continue to look down.
• Try to introduce every knowledge point until it is used. Introducing a knowledge point too early, and having finished speaking it, the reader will soon forget it, which is not in line with the cognitive rules.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.