To learn about Linux, you may encounter embedded Linux. Next we will introduce the first Linux driver "Hello world !", "Hello world" may be the program written by the first programmer. Here I also start writing it. Although it is very simple, it records the process of learning the Linux driver.
- /*hello_module.c*/
- #include <linux/module.h>
- #include <linux/init.h>
- static int __init mini2440_hello_module_init(void)
- {
- printk("Hello, Mini2440 module is installed !\n");
- return 0;
- }
- static void __exit mini2440_hello_module_cleanup(void)
- {
- printk("Good-bye, Mini2440 module was removed!\n");
- }
- module_init(mini2440_hello_module_init);
- module_exit(mini2440_hello_module_cleanup);
- MODULE_LICENSE("GPL");
Simple analysis: the header files "linux/module. h" and "linux/init. h" used in this program should be included in all the module code. MODULE_LICENSE ("GPL"); is the license that the kernel module complies. The function is decorated with _ init, indicating that the function is only used during initialization. When the module is loaded, the initialization function is thrown away and the memory occupied by the function is released. The initialization function can also be modified without _ init, which only occupies part of the memory and can be called by other functions. _ Exit modifier indicates that the code is used for module uninstallation. Any other call to this function will fail.
The Makefile file of the module is as follows:
- obj-m:=hello_module.o
- CURRENT_PATH:=$(shell pwd)
- ARM_LINUX_KERNEL:=/opt/linux-2.6.29.1
- all:
- $(MAKE) -C $(ARM_LINUX_KERNEL) SUBDIRS=$(CURRENT_PATH) modules
- clean:
- rm -RF *.cmd *.o *.ko *.mod.c *.symvers *.order
The above is the Linux driver "Hello world !" .
- Easy understanding of Linux shutdown commands
- Describes how to enter and exit a Linux operating system
- Describe Linux operating system deficiencies and Development Trends
- Introduction to Linux Application Scope
- This gives you a better understanding of common Linux software.