2440-driven qitan-helloworld

Source: Internet
Author: User

Do you want to crop the kernel before writing the driver? Okay, as shown in the user manual, "the LED driver has been compiled into the default kernel, so it cannot be loaded using the insmod method. "I re-customized the kernel in the manual and checked out some of the drivers I was about to write so that I could use insmod.

The removed drivers include: LCD drivers (including logo options), touch screen drivers, audio drivers, watchdog drivers, I2C drivers, PWM drivers, LED Drivers, and key-press drivers, a/D driver, RTC driver

Because the LCD driver is disabled, QT is not written in the Development Board, and rootfs is written in the file system. The file name is rootfs_rtm_2440.img (Disk Directory: image/Linux/RTM)


This is the first driver. In order to commemorate a summer drama, the more you play the TV series, the more you play, the more you play.

System: Ubuntu 12.04

Driver cross-compilation kernel: linux-2.6.32.2 // build cross-Compilation

Development Board: mini2440 (128 M nandflash) // for how to download Linux to the Development Board, click. For Linux rootfs, select rootfs_rtm_2440.img (Disk Directory: image/Linux/RTM)

Tools required for development: NFS network file minicom

PC end:

First, create a self-written driver folder.

1. # mkdir/home/lianghuiyong/my2440drivers // create a folder

2. # cd/home/lianghuiyong/my2440drivers // enter the folder

3. # Vim helloworld. c

Helloworld. C content:

   #include<linux/init.h>   #include<linux/module.h>      static int hello_init(void)   {       printk(KERN_ALERT "Hello,mini2440 module is installed!\n");       return 0;   }     static void hello_cleanup(void)  {      printk(KERN_ALERT "Good-bye,mini2440 module was removed!\n");  }   module_init(hello_init);  module_exit(hello_cleanup);  MODULE_LICENSE("Daul BSD/GPL");

In the code, module_init and module_exit are the driver module loading and uninstalling functions. module_license ("Daul BSD/GPL") is the module license statement, which complies with the Daul BSD/GPL protocol.

4. Vim makefile

Makefile content: (the 2.4 kernel and 2.6 kernel are written in a different way. The following is the 2.6 kernel)

PWD = $(shell pwd)KDIR =/opt/FriendlyARM/mini2440/linux-2.6.32.2/obj-m:= <span style="color:#ff0000;">helloworld</span>.oall:$(MAKE) -C $(KDIR) M=$(PWD) CONFIG_DEBUG_SECTION_MISMATCH=yclean:rm -rf *.o *~core.depend. *.cmd *.ko *.mod.c .tmp_versionsrm -rf *.order Module.*insmod:insmod <span style="color:#ff0000;">helloworld</span>.kormmod:rmmod <span style="color:#ff0000;">helloworld</span>active:echo -e "$(MAKE) \n"$(MAKE) -C $(KDIR) M=$(PWD)
NOTE 1: The directory followed by kdir should be the directory for Kernel installation provided by the friendly arm. Before that, I used the "kdir: =/lib/modules/$ (shell uname-R)/build. In fact, the directory here is the Ubuntu Kernel Directory, UBUNTU kernel version (3.2) and the development board kernel version (2.6) is different, so if the driver compiled under the Ubuntu kernel is not in the Development Board insmod! The invalid module format error is displayed. The three helloworld (red) values must be changed with helloworld. C.

5. # Make

6. # cp./helloworld. Ko/nfsboot/


NOTE 2: Because the kernel of the driver is the kernel of the Development Board (2.6) and the kernel of Ubuntu is 3.2, this driver cannot be installed on Ubuntu. Attachment (if the driver is written in the Ubuntu kernel, no information is printed after insmod. You can use CAT/var/log/Kern. log | tail to view the log)




On the Development Board: 1. Enable minicom (when the color of minicom is set to minicom-C on). On the Development Board, power on 2 and # Mount-T nfs-O nolock 192.168.1.102: /nfsboot/mnt // Mount/nfsboot directory to the Development Board/mnt // Configure NFS network file 3, # cd/mnt4, # ls5, # insmod helloworld. ko6, # lsmod7, # rmmod helloworld

It may occur when the driver is loaded for the first time:
helloworld: module license 'Daul BSD/GPL' taints kernel.Disabling lock debugging due to kernel taintHello,mini2440 module is installed!
It's just a kernel prompt. It doesn't matter. The third line is the information we need. When I perform the second insmod operation, the above two lines are gone.


Error notes:

1. Make: ***/opt/friendlyarm/mini2440/linux-2.6.32.2M =/home/lianghuiyong/my2440driversmodeles: No file or directory. Stop.

This should be a makefile writing problem. Different kernel versions may have different writes. For details, click


2. insmod: Can't read 'helloworld': no such file or directory

The file suffix. Ko must be added to insmod.


3. insmod: Error inserting '*****. Ko':-1 file exists

No rmmod after insmod. Solution: rmmod ****


4. insmod: cannot insert 'helloworld. Ko ': Invalid module format

This is because after the makefile is modified, the files generated by the previous compilation are not deleted. Except for makefile and. c files, delete the remaining files and then make

Another important reason is that kdir is the directory of the Development Board kernel, that is, the Directory of the linux-2.6.32.2.

2440-driven qitan-helloworld

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.