Hello Program
#include <linux/init.h>#include <linux/module.h>MODULE_LICENSE("Dual BSD/GPL");MODULE_AUTHOR("Hanson He");static int __init hello_init(void){ printk(KERN_ALERT "Hello world\n"); return 0;}static void __exit hello_exit(void){ printk(KERN_ALERT " Hello world exit\n");}module_init(hello_init);module_exit(hello_exit);
Makefile content
ifeq ($(KERNELRELEASE),)KERNELDIR ?=/root/Desktop/linux-2.6.32.2PWD := $(shell pwd)modules: $(MAKE) -C $(KERNELDIR) M=$(PWD) modulesmodules_install: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_installclean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions.PHONY: modules modules_install cleanelse obj-m := hello.oendif
The following error occurs when the terminal executes make:
ERROR: Kernel configuration is invalid.include/linux/autoconf.h or include/config/auto.conf are missing. Run 'make oldconfig && make prepare' on kernel src to fix it.
The reason is that the kernel is not compiled. The solution is as follows:To compile the kernel, follow these steps:
1. CP menu_mini2440_x35. config
2. Modify the makefile in the kernel directory
Arch? = Arm
Cross_compile? = Arm-Linux-
3. Make menuconfig
4. Make
After completing these steps, execute make in the hello directory to display the hello. Ko file.
Copy the hello. Ko file to the Development Board for execution.
[root@FriendlyARM share]# insmod hello.ko Hello world[root@FriendlyARM share]# lsmodhello 505 0 - Live 0xbf000000[root@FriendlyARM share]# rmmod hello Hello world exitrmmod: module 'hello' not found
For devices, create a node file after the driver is loaded.
Mknod/dev/beep C major 0
Beep indicates the device name.
C Represents a bit character device
Major indicates the master device number.
0 indicates the sub-device number.
The execution result with parameters is as follows:
[root@FriendlyARM share]# insmod hello_ext.ko howmany=4 whom="jiejie"Hello jiejieHello jiejieHello jiejieHello jiejie[root@FriendlyARM share]# rmmod hello_ext.ko [root@FriendlyARM share]# rmmod hello_ext Hello world exitrmmod: module 'hello_ext' not found