Describes the Linux driver "Hello world !"

Source: Internet
Author: User

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.

 
 
  1. /*hello_module.c*/  
  2. #include <linux/module.h> 
  3. #include <linux/init.h> 
  4. static int __init mini2440_hello_module_init(void)  
  5. {  
  6.     printk("Hello, Mini2440 module is installed !\n");  
  7.     return 0;  
  8. }  
  9. static void __exit mini2440_hello_module_cleanup(void)  
  10. {  
  11.     printk("Good-bye, Mini2440 module was removed!\n");  
  12. }  
  13. module_init(mini2440_hello_module_init);  
  14. module_exit(mini2440_hello_module_cleanup);  
  15. 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:

 
 
  1. obj-m:=hello_module.o  
  2. CURRENT_PATH:=$(shell pwd)  
  3. ARM_LINUX_KERNEL:=/opt/linux-2.6.29.1  
  4. all:  
  5. $(MAKE) -C $(ARM_LINUX_KERNEL) SUBDIRS=$(CURRENT_PATH) modules  
  6. clean:  
  7. rm -RF *.cmd *.o *.ko *.mod.c *.symvers *.order 

The above is the Linux driver "Hello world !" .

  1. Easy understanding of Linux shutdown commands
  2. Describes how to enter and exit a Linux operating system
  3. Describe Linux operating system deficiencies and Development Trends
  4. Introduction to Linux Application Scope
  5. This gives you a better understanding of common Linux software.

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.