Tq2440 load the hello World Driver Module

Source: Internet
Author: User

After nearly a month, I finally transplanted the Linux kernel according to the manual. Next I will start porting the driver module. I checked some information on the Internet and summarized it as follows:

Target Platform: tq2440 ARM9.

Kernel version: Linux-2.6.25

Premise: the cross-compilation tool has been installed on the host machine, because it was used during Linux kernel transplantation.

Enter the subject

1. First, go to a directory and create a folder in it.

# Cd/home/wanyao/Module

# Vim hello. c

   1. #include <linux/init.h>  
2. #include <linux/module.h>
3. MODULE_LICENSE("Dual BSD/GPL");
4.
5. static int hello_init(void)
6. {
7. printk(KERN_ALERT "Hello, world\n");
8. return 0;
9. }
10.
11. static void hello_exit(void)
12. {
13. printk(KERN_ALERT "Goodbye, cruel world\n");
14. return 0;
15. }
16.
17. module_init(hello_init);
18. module_exit(hello_exit);

2. Create a makefile

# Vim makefile

   1. KERNELDIR=/opt/EmbedSky/linux-2.6.25     
2. PWD:=$(shell pwd)
3. INSTALLDIR=$(PWD)
4. CC=arm-linux-gcc
5. obj-m := hello.o
6. modules:
7. $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
8. clean:
9. rm -rf *.o *.ko *.mod.c *.markers *.order *.symvers
10. .PHONY:modules clean

Note: The driver module does not have to be placed in the kernel tree. As long as your makefile specifies the path of the kernel tree, there is no problem, therefore, I have created a Module Directory in/home/wanyao/to develop the driver module.

3. Make

# Make

Many files are generated. Hello. Ko is the module File we need to load.

4. Use TFTP to upload the hello. Ko module file to the Development Board (this step is described in detail in my other blog)

5. Load the module and perform the test (the following operations are performed on the system terminal in the Development Board)

# Insmod hello. Ko
Hello, world
# Rmmod hello

Goodbye, cruel world

Success!

 

Possible insmod errors:

1. Hello: Version magic '2. 6.30.4 mod_unload armv4 'could be '2. 6.30.4-embedsky mod_unload armv4'
Insmod: cannot insert 'hello. Ko ': Invalid module format

Error cause: the module version does not match the kernel version!
Solution: import the preset configuration information and enter menuconfig to continue general config-> () local version-> Add the following content to the brackets: "-embedsky" and save it. config, re-compile the kernel and driver modules, and then load the modules.

2. Hello: Unknown symbol _ aeabi_unwind_cpp_pr0
Insmod: cannot insert 'hello. Ko ': Unknown symbol in module, or unknown
Parameter

Cause of error: the module and kernel image do not match

Solution: Use the kernel image zimage and zimage that you use to compile the driver at the same time. There is a sentence on ldd3:Although not required, it is best to run the kernel corresponding to the module.

At the beginning, I learned the driver and finally loaded the hello World module!
This is a small step driven by learning, but it is a huge step for me!

 

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.