2440 driver qitan -- helloworld, 2440 -- helloworld
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. The drivers that can be removed by insmod include: LCD Driver (including the logo option), touch screen driver, audio driver, watchdog driver, I2C driver, pwm driver, led driver, button driver, 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 my first driver. In order to commemorate a summer drama, the more I play the TV series, the more I 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:= helloworld.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 helloworld.kormmod:rmmod helloworldactive: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! An error occurs when the invalid module format is incorrect. The three helloworlds must be changed with the helloworld. c file name.
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 may be because the files generated by the previous compilation are not deleted after the makefile is modified. Except for makefile and. c files, delete the remaining files and then make
It may also be a problem with the KDIR path, which is the directory of the Development Board kernel, that is, the Directory of the linux-2.6.32.2
Arm-linux-gcc cross-compilation test: Segment fault occurs in the helloworld Program
Segment errors are generally caused by cross-border pointer access, such:
Int buf [10];
For (int I = 0; I ++ ){
If (* buf [I] = 100) printf ().....
}
It has nothing to do with cross-compilation. Check your code.
LPCTSTR str = "helloworld ";
LPCTSTR str = _ T ("helloworld ");