There are two major work done recently. One is to transplant the video_copy project in dvsdk_4 to your own board. in the case of extremely scarce references, I continue to carry forward the hard work style and the spirit of the inner, and finally ran the DSP in omap3530 successfully. Another job is to start learning about driver development for Linux devices and prepare for writing drivers for new devices. The content of the dvsdk is complex and the work is still being organized. I will release it later. There are a lot of materials for Linux device driver development. I just record my work for beginners like me, and it will be more convenient to come back later. For more information about the shortcomings, see ~~
Half of the Linux kernel source code is composed of drivers. Drivers play an important role in completing the powerful functions of Linux. When developing your own system, sometimes you may find that the driver that supports specific hardware cannot be reproduced in the Code. This requires you to do your own work to make sure that you can get the best fit. Pai_^
Since ancient times, the first step in learning a new programming language is to write a program that prints "Hello world". In this article, we will learn to compile a simple kernel module device driver in the same way.
First, create a new HELLO. c file:
# Include <Linux/init. h>
# Include <Linux/module. h>
Module_license ("dual BSD/GPL ");
Static int hello_init (void)
{
Printk (kern_alert "Hello, world \ n ");
}
Static void hello_exit (void)
{
Printk (kern_alert "Goodbye, cruel world \ n ");
}
Module_init (hello_init );
Module_exit (hello_exit );
This module defines two functions. One is called (hello_init) when the module is loaded to the kernel, and the other is called (hello_exit) when the module is removed ). Module_init and module_exit use special kernel macros to indicate the roles of these two functions. Another special macro (module_license) is used to inform the kernel that the module has a free license. Without such instructions, the kernel reports an error when the module is loaded.
The printk function is defined in the Linux kernel and available to the module. It is similar to the Standard C library function printf. The kernel needs its own print function because it does not support the C library. The string kern_alert is the priority of the message. A high priority is specified in this module, because messages with the default priority may not be directly displayed, which depends on the running kernel version, the version and configuration of the klogd daemon.
To compile the module file, you can create a MAKEFILE file. This example is very simple. You only need one line. The command is as follows:
OBJ-M: = Hello. o
OBJ-M indicates the list of kernel modules to be compiled. *. O files are automatically generated by the corresponding *. c files (you do not need to explicitly list all source code files)
If you want to compile the above program into a module loaded and deleted during runtime, the compilation command is as follows.
Make-C/usr/src/kernels/2.6.25-14. fc9.i686 M = $ PWD modules
This command first changes the directory to the location specified by the-C option (that is, the kernel source code Directory, which depends on your own situation ). This M = option enables makefile to return to the module source code directory before constructing the modules target. Then, the modules target points to the module set in the obj-m variable. The compilation rules here mean: make the place where the kernel source code is included, and then compile
$ PWD (current) modules under the directory. This allows us to compile our kernel modules using all the rules defined under the kernel source code tree.
After compilation, the hello. Ko file will be generated in the source code Directory, which is the kernel driver module. We use the following command to load the hello module.
Insmod hello. Ko
The following command completes the opposite process: uninstall the hello module.
Rmmod hello
At this time, you will find that there is no output in the terminal. Don't worry, because printk is the kernel output function. To view it, you need to execute the following commands.
Dmesg | tail
In this case, the kernel information is printed on the terminal, as shown in.
So far, a simple kernel module driver is complete. Pai_^