LINUX module Loading records

Source: Internet
Author: User

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

 

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.