第一个简单的内核编程实验:hello.c

 http://blog.chinaunix.net/u/21948/showart_240084.html

《Linux设备驱动程序》
 
    内核编程入门,就以最为简单的hello.c为例。
    环境:Redhat 9.0,内核版本2.4.20-8。
 
    虽然现在2.6.x的内核很早就就发布了,但是毕竟很多公司还在使用2.4.x的内核。作为新手,从2.4.x的内核入手是可行的。原因有如下几条:
    (1)2.4.x比较成熟。可能你遇到的绝大多数问题,网上都有解决方案。在这个过程中,你可以节省大量的时间,同时还可以对比网上的解决方案,加深认识,总结解决问题的方法,调整自己的学习方法和思路。
    (2)事物的发展总不可能是一蹴而就的。了解发展的历程,对深入理解问题有很大的好处。所以在2.4.x的内核的基础上学习2.6.x的内核,就能够体会 到2.6.x的内核在哪些方面要出色,或者为什么要采取这种改进技术。相信理论清晰了,即时2.6.x的内核也会容易上手。
 
    下面总结了第一个内核程序hello.c的学习过程。
 
(一)第一阶段:尽量简单
 

/*
 * hello.c
 */


#define MODULE
#include <linux/module.h>

int init_module(void)
{
        printk("Hello World!/n");
        return 0;
}

void cleanup_module(void)
{
        printk("Goodbye!/n");
}

执行,出现错误一:

[root@lqm drivers]# gcc -c hello.c
[root@lqm drivers]# insmod hello.o
hello.o: kernel-module version mismatch
        hello.o was compiled for kernel version 2.4.20
        while this kernel is version 2.4.20-8.

    这是因为内核源代码版本和编译器版本不一致造成的。

(1)编译器版本/usr/include/linux/version.h

#define UTS_RELEASE "2.4.20"
#define LINUX_VERSION_CODE 132116
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))

(2)内核源代码版本/usr/src/linux-2.4.20-8/include/linux/version.h

/usr/src/linux-2.4.20-8/include/linux
[root@lqm linux]# cat version.h
#include <linux/rhconfig.h>
#if defined(__module__smp)
#define UTS_RELEASE "2.4.20-8smp"
#elif defined(__module__BOOT)
#define UTS_RELEASE "2.4.20-8BOOT"
#elif defined(__module__bigmem)
#define UTS_RELEASE "2.4.20-8bigmem"
#else
#define UTS_RELEASE "2.4.20-8"
#endif
#define LINUX_VERSION_CODE 132116
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))

   可以采取修改编译器版本号与内核源代码版本号一致的办法来解决这个问题,即修改/usr/include/linux/version.h中

#define UTS_RELEASE "2.4.20"

#define UTS_RELEASE "2.4.20-8"

执行,出现错误二:

[root@lqm drivers]# gcc -c hello.c
[root@lqm drivers]# insmod hello.o
Warning: loading hello.o will taint the kernel: no license
  See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Module hello loaded, with warnings
[root@lqm drivers]# tail -n 1 /var/log/messages
Jan 30 12:02:08 lqm kernel: Hello

     也就是说出现了no license的警告。GNU的软件需要有GPL,所以修改源代码如下:

/*
 * hello.c
 */


#define MODULE
#include <linux/module.h>

MODULE_LICENSE("GPL");

int init_module(void)
{
        printk("Hello World!/n");
        return 0;
}

void cleanup_module(void)
{
        printk("Goodbye!/n");
}

    这时没有错误了。写了一个脚本,测试流程自动化:

#!/bin/bash

gcc -c hello.c
sleep 1

insmod hello.o && echo -e "Instal module - hello.o/n"
sleep 1
tail -n 1 /var/log/messages
lsmod | grep "hello" && echo -e "Module hello has instaled/n"

rmmod hello && echo -e "Remove module - hello/n"
sleep 1
tail -n 1 /var/log/messages
lsmod | grep "hello" || echo "Module hello has removed"

执行结果如下:

[root@lqm hello]# ./run

Instal module - hello.o

Jan 30 13:31:29 lqm kernel: Hello World!

hello 748 0 (unused)

Module hello has instaled

Remove module - hello

Jan 30 13:31:30 lqm kernel: Goodbye!

Module hello has removed

(二)第二阶段:完善,深入一点

/*
 * hello.c
 */


#ifndef __KERNEL__
        #define __KERNEL__
#endif
#ifndef MODULE
        #define MODULE
#endif

#include <linux/kernel.h> /*printk*/
#include <linux/module.h>

MODULE_LICENSE("GPL");

static int init_module(void)
{
        printk("Hello, world!/n");

        return 0;
}

static void cleanup_module(void)
{
        printk("Goodbye!/n");
}

写Makefile文件如下:

# Kernel Programming
# Shandong University, Linqingmin

# The path of kernel source code
INCLUDEDIR = /usr/src/linux-2.4.20-8/include/

# Compiler
CC = gcc

# Options
CFLAGS = -D__KERNEL__ -DMODULE -O -Wall -I$(INCLUDEDIR)

# Target
OBJS = hello.o

all: $(OBJS)

$(OBJS): hello.c /usr/include/linux/version.h
        $(CC) $(CFLAGS) -c $<

install:
        insmod $(OBJS)

uninstall:
        rmmod hello

.PHONY: clean
clean:
        rm -f *.o

    写Makefile时应该注意,不要用空格来代替<TAB>。否则会出现错误:missing separator. Stop.

修改执行脚本run:

#!/bin/bash

# The first step
make && make install && echo -e "Instal module - hello.o/n"
sleep 1
tail -n 1 /var/log/messages
lsmod | grep "hello" && echo -e "Module hello has instaled/n"

# The second step
make uninstall && echo -e "Remove module - hello/n"
sleep 1
tail -n 1 /var/log/messages
lsmod | grep "hello" || echo "Module hello has removed"

# The last step
make clean

执行结果如下:

[root@lqm hello]# ./run
gcc -D__KERNEL__ -DMODULE -O -Wall -I/usr/src/linux-2.4.20-8/include/ -c hello.c
hello.c:18: warning: `init_module' defined but not used
hello.c:25: warning: `cleanup_module'
defined but not used
insmod hello.o
Instal module - hello.o

Jan 31 13:40:23 lqm kernel: Hello,
hello 728 0 (unused)
Module hello has instaled

rmmod hello
Remove module - hello

Jan 31 13:40:24 lqm kernel:
Module hello has removed
rm -f *.o

(三)第三阶段:总结

1、一个内核模块至少应该包括两个函数:

(1)init_module:模块插入内核时调用

(2)cleanup_module:模块移除时调用

    这个简单的程序就是只实现了这两个函数,而且只做了打印信息的工作,没有使用价值。典型情况下,init_module为内核中的某些东西注册一个句柄,相当于模块初始化的工作。cleanup_module则是撤销模块前期的处理工作,使模块得以安全卸载。

2、insmod实现动态加载模块。在当前OS上,动态加载模块以测试硬件等,避免了繁琐的工作。但是,在这种情况下,会出现版本不匹配的情况。另 外,要分清楚内核源代码路径和编译器路径的不同,知道在编译时该指定那个路径。第二阶段开始出现过几个错误都是因为默认的路径是编译器路径,而不是内核源 代码路径。体会内核模块化带来的好处!

3、应用Make工具来管理项目。即使小,也要训练。在2.4内核和2.6内核下,Makefile的编写会有所不同。只是语法形式的不同,先深入掌握一种,另一种注意一下应该可以避免犯错误。

    继续努力!

2007/02/01补记

/*
 * Kernel Programming: hello.c
 */


/*define __KERNEL__ MODULE*/
#ifndef __KERNEL__
        #define __KERNEL__
#endif
#ifndef MODULE
        #define MODULE
#endif

#include <linux/kernel.h> /*printk*/
#include <linux/module.h>
#include <linux/init.h> /*module_init module_exit*/

MODULE_LICENSE("GPL"); /*declaration license*/

static int __init hello_init(void)
{
        printk("<1>Hello, world!/n");

        return 0;
}

static void __exit hello_exit(void)
{
        printk("<1>Goodbye!/n");
}

module_init(hello_init);
module_exit(hello_exit);

 

# Kernel Programming
# Shandong University, Linqingmin

# The path of kernel source code
KERNELDIR = /usr/src/linux-2.4.20-8

# Compiler
CC = gcc

# Options
CFLAGS = -D__KERNEL__ -DMODULE -I$(KERNELDIR)/include -O -Wall

ifdef CONFIG_SMP
        CFLAGS += -D__SMP__ -DSMP
endif

# OBJS
OBJS = hello.c

# Target
TARGET = hello.o

$(TARGET): hello.c
        $(CC) $(CFLAGS) -c $<

install:
        insmod $(TARGET)

uninstall:
        rmmod hello

.PHONY: clean
clean:
        rm -f *.o

 

#!/bin/bash

# The first step
make && make install && echo -e "Instal module - hello.o/n"
sleep 1
lsmod | grep "hello" && echo -e "Module hello has instaled/n"

# The second step
make uninstall && echo -e "Remove module - hello/n"
sleep 1
lsmod | grep "hello" || echo "Module hello has removed"

# The last step
make clean

执行结果:

gcc -D__KERNEL__ -DMODULE -I/usr/src/linux-2.4.20-8/include -O -Wall -c hello.c
insmod hello.o
Hello,World!
Instal module - hello.o

hello 776 0 (unused)
Module hello has instaled

rmmod hello
Goodbye!
Remove module - hello

Module hello has removed
rm -f *.o

说明:

    这个版本采取了显式的初始化和清除函数,显然无论是调试的便利还是编程风格,都比前几个版本要好。这种机制具体描述如下:如果你将模块初始化函数命名为 my_init(而不是init_module),将清除函数命名为my_exit,则可以使用下面两行来进行标记(通常在源文件的末尾)

module_init(my_init);

module_exit(my_exit);

注意必须包含头文件<linux/init.h>。


 
第一个简单的内核编程实验:hello.c
 
 
《Linux设备驱动程序》
 
    内核编程入门,就以最为简单的hello.c为例。
    环境:Redhat 9.0,内核版本2.4.20-8。
 
    虽然现在2.6.x的内核很早就就发布了,但是毕竟很多公司还在使用2.4.x的内核。作为新手,从2.4.x的内核入手是可行的。原因有如下几条:
    (1)2.4.x比较成熟。可能你遇到的绝大多数问题,网上都有解决方案。在这个过程中,你可以节省大量的时间,同时还可以对比网上的解决方案,加深认识,总结解决问题的方法,调整自己的学习方法和思路。
    (2)事物的发展总不可能是一蹴而就的。了解发展的历程,对深入理解问题有很大的好处。所以在2.4.x的内核的基础上学习2.6.x的内核,就能够体会 到2.6.x的内核在哪些方面要出色,或者为什么要采取这种改进技术。相信理论清晰了,即时2.6.x的内核也会容易上手。
 
    下面总结了第一个内核程序hello.c的学习过程。
 
(一)第一阶段:尽量简单
 

/*
 * hello.c
 */


#define MODULE
#include <linux/module.h>

int init_module(void)
{
        printk("Hello World!/n");
        return 0;
}

void cleanup_module(void)
{
        printk("Goodbye!/n");
}

执行,出现错误一:

[root@lqm drivers]# gcc -c hello.c
[root@lqm drivers]# insmod hello.o
hello.o: kernel-module version mismatch
        hello.o was compiled for kernel version 2.4.20
        while this kernel is version 2.4.20-8.

    这是因为内核源代码版本和编译器版本不一致造成的。

(1)编译器版本/usr/include/linux/version.h

#define UTS_RELEASE "2.4.20"
#define LINUX_VERSION_CODE 132116
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))

(2)内核源代码版本/usr/src/linux-2.4.20-8/include/linux/version.h

/usr/src/linux-2.4.20-8/include/linux
[root@lqm linux]# cat version.h
#include <linux/rhconfig.h>
#if defined(__module__smp)
#define UTS_RELEASE "2.4.20-8smp"
#elif defined(__module__BOOT)
#define UTS_RELEASE "2.4.20-8BOOT"
#elif defined(__module__bigmem)
#define UTS_RELEASE "2.4.20-8bigmem"
#else
#define UTS_RELEASE "2.4.20-8"
#endif
#define LINUX_VERSION_CODE 132116
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))

   可以采取修改编译器版本号与内核源代码版本号一致的办法来解决这个问题,即修改/usr/include/linux/version.h中

#define UTS_RELEASE "2.4.20"

#define UTS_RELEASE "2.4.20-8"

执行,出现错误二:

[root@lqm drivers]# gcc -c hello.c
[root@lqm drivers]# insmod hello.o
Warning: loading hello.o will taint the kernel: no license
  See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Module hello loaded, with warnings
[root@lqm drivers]# tail -n 1 /var/log/messages
Jan 30 12:02:08 lqm kernel: Hello

     也就是说出现了no license的警告。GNU的软件需要有GPL,所以修改源代码如下:

/*
 * hello.c
 */


#define MODULE
#include <linux/module.h>

MODULE_LICENSE("GPL");

int init_module(void)
{
        printk("Hello World!/n");
        return 0;
}

void cleanup_module(void)
{
        printk("Goodbye!/n");
}

    这时没有错误了。写了一个脚本,测试流程自动化:

#!/bin/bash

gcc -c hello.c
sleep 1

insmod hello.o && echo -e "Instal module - hello.o/n"
sleep 1
tail -n 1 /var/log/messages
lsmod | grep "hello" && echo -e "Module hello has instaled/n"

rmmod hello && echo -e "Remove module - hello/n"
sleep 1
tail -n 1 /var/log/messages
lsmod | grep "hello" || echo "Module hello has removed"

执行结果如下:

[root@lqm hello]# ./run

Instal module - hello.o

Jan 30 13:31:29 lqm kernel: Hello World!

hello 748 0 (unused)

Module hello has instaled

Remove module - hello

Jan 30 13:31:30 lqm kernel: Goodbye!

Module hello has removed

(二)第二阶段:完善,深入一点

/*
 * hello.c
 */


#ifndef __KERNEL__
        #define __KERNEL__
#endif
#ifndef MODULE
        #define MODULE
#endif

#include <linux/kernel.h> /*printk*/
#include <linux/module.h>

MODULE_LICENSE("GPL");

static int init_module(void)
{
        printk("Hello, world!/n");

        return 0;
}

static void cleanup_module(void)
{
        printk("Goodbye!/n");
}

写Makefile文件如下:

# Kernel Programming
# Shandong University, Linqingmin

# The path of kernel source code
INCLUDEDIR = /usr/src/linux-2.4.20-8/include/

# Compiler
CC = gcc

# Options
CFLAGS = -D__KERNEL__ -DMODULE -O -Wall -I$(INCLUDEDIR)

# Target
OBJS = hello.o

all: $(OBJS)

$(OBJS): hello.c /usr/include/linux/version.h
        $(CC) $(CFLAGS) -c $<

install:
        insmod $(OBJS)

uninstall:
        rmmod hello

.PHONY: clean
clean:
        rm -f *.o

    写Makefile时应该注意,不要用空格来代替<TAB>。否则会出现错误:missing separator. Stop.

修改执行脚本run:

#!/bin/bash

# The first step
make && make install && echo -e "Instal module - hello.o/n"
sleep 1
tail -n 1 /var/log/messages
lsmod | grep "hello" && echo -e "Module hello has instaled/n"

# The second step
make uninstall && echo -e "Remove module - hello/n"
sleep 1
tail -n 1 /var/log/messages
lsmod | grep "hello" || echo "Module hello has removed"

# The last step
make clean

执行结果如下:

[root@lqm hello]# ./run
gcc -D__KERNEL__ -DMODULE -O -Wall -I/usr/src/linux-2.4.20-8/include/ -c hello.c
hello.c:18: warning: `init_module' defined but not used
hello.c:25: warning: `cleanup_module'
defined but not used
insmod hello.o
Instal module - hello.o

Jan 31 13:40:23 lqm kernel: Hello,
hello 728 0 (unused)
Module hello has instaled

rmmod hello
Remove module - hello

Jan 31 13:40:24 lqm kernel:
Module hello has removed
rm -f *.o

(三)第三阶段:总结

1、一个内核模块至少应该包括两个函数:

(1)init_module:模块插入内核时调用

(2)cleanup_module:模块移除时调用

    这个简单的程序就是只实现了这两个函数,而且只做了打印信息的工作,没有使用价值。典型情况下,init_module为内核中的某些东西注册一个句柄,相当于模块初始化的工作。cleanup_module则是撤销模块前期的处理工作,使模块得以安全卸载。

2、insmod实现动态加载模块。在当前OS上,动态加载模块以测试硬件等,避免了繁琐的工作。但是,在这种情况下,会出现版本不匹配的情况。另 外,要分清楚内核源代码路径和编译器路径的不同,知道在编译时该指定那个路径。第二阶段开始出现过几个错误都是因为默认的路径是编译器路径,而不是内核源 代码路径。体会内核模块化带来的好处!

3、应用Make工具来管理项目。即使小,也要训练。在2.4内核和2.6内核下,Makefile的编写会有所不同。只是语法形式的不同,先深入掌握一种,另一种注意一下应该可以避免犯错误。

    继续努力!

2007/02/01补记

/*
 * Kernel Programming: hello.c
 */


/*define __KERNEL__ MODULE*/
#ifndef __KERNEL__
        #define __KERNEL__
#endif
#ifndef MODULE
        #define MODULE
#endif

#include <linux/kernel.h> /*printk*/
#include <linux/module.h>
#include <linux/init.h> /*module_init module_exit*/

MODULE_LICENSE("GPL"); /*declaration license*/

static int __init hello_init(void)
{
        printk("<1>Hello, world!/n");

        return 0;
}

static void __exit hello_exit(void)
{
        printk("<1>Goodbye!/n");
}

module_init(hello_init);
module_exit(hello_exit);

 

# Kernel Programming
# Shandong University, Linqingmin

# The path of kernel source code
KERNELDIR = /usr/src/linux-2.4.20-8

# Compiler
CC = gcc

# Options
CFLAGS = -D__KERNEL__ -DMODULE -I$(KERNELDIR)/include -O -Wall

ifdef CONFIG_SMP
        CFLAGS += -D__SMP__ -DSMP
endif

# OBJS
OBJS = hello.c

# Target
TARGET = hello.o

$(TARGET): hello.c
        $(CC) $(CFLAGS) -c $<

install:
        insmod $(TARGET)

uninstall:
        rmmod hello

.PHONY: clean
clean:
        rm -f *.o

 

#!/bin/bash

# The first step
make && make install && echo -e "Instal module - hello.o/n"
sleep 1
lsmod | grep "hello" && echo -e "Module hello has instaled/n"

# The second step
make uninstall && echo -e "Remove module - hello/n"
sleep 1
lsmod | grep "hello" || echo "Module hello has removed"

# The last step
make clean

执行结果:

gcc -D__KERNEL__ -DMODULE -I/usr/src/linux-2.4.20-8/include -O -Wall -c hello.c
insmod hello.o
Hello,World!
Instal module - hello.o

hello 776 0 (unused)
Module hello has instaled

rmmod hello
Goodbye!
Remove module - hello

Module hello has removed
rm -f *.o

说明:

    这个版本采取了显式的初始化和清除函数,显然无论是调试的便利还是编程风格,都比前几个版本要好。这种机制具体描述如下:如果你将模块初始化函数命名为 my_init(而不是init_module),将清除函数命名为my_exit,则可以使用下面两行来进行标记(通常在源文件的末尾)

module_init(my_init);

module_exit(my_exit);

注意必须包含头文件<linux/init.h>。

发表于: 2007-01-30,修改于: 2007-02-01 14:44,已浏览2894次,有评论14条 推荐 投诉
 
 


 
网友评论
 
网友: huangweiinhit123 时间:2007-01-30 13:22:29 IP地址:61.167.60.★
 
 
 
很高兴能看到你的网页并能向你学习嵌入式linux

我也在开始学习源代码和驱动编程

我在编写第一个驱动hello.c时

insmod hello.o出现错误

kernel requres old insmod,but couldn't run insmod.old:no such file of directory 怎么解决

希望能和你成为学习的好朋友:)
 
 

 
网友: piaoxiang 时间:2007-01-30 13:38:03 IP地址:122.4.32.★
 
 
 
我也是刚开始学习。

对你的问题,不清楚你的环境。根据提示,内核版本和insmod版本不匹配。你可以做以下几步分析:

(1)uname -r  看内核版本

(2)insmod -V 看insmod版本

(3)确定是root权限。因为内核编译需要root权限才能运行。

(4)确定insmod后对象hello.o的路径是正确的。

试试看吧,如果不能解决,推荐到CU的内核版问问牛人

 
 

 
网友: huangweiinhit123 时间:2007-01-30 14:10:36 IP地址:61.167.60.★
 
 
 
我刚刚看了一下

用insmod -V

时还是显示上面的结果

估计是没有安装insmod这个东东:)

奇怪 我的也是RedHat 9.0

怎么就没有装呢:(

谢谢你的答复:)

以前我都是做一些用dsp的模块

后来看到我们实验室的一个师兄用Vxword做的海量数据存储

然后就知道嵌入式操作系统 然后才开始学习的

觉得这个操作系统挑战性比较大 比较有意思:)

但是刚刚开始 还什么都不会 我用的实验室开发板也是和你的一样 

但是我们实验室没有人用过linux所以在实验室没有人问

以后希望你能多多指教
 
 

 
网友: huangweiinhit123 时间:2007-01-30 14:51:09 IP地址:61.167.60.★
 
 
 
我刚刚上网看了一下

我用/sbin/insmod hell.o就好了

对了我对PATH不太了解 到底是什么意思 啊

你看我怎么样设置才能使直接用insmod 就可以

是不是export什么的设置环境变量

 
 

 
网友: piaoxiang 时间:2007-01-30 15:09:38 IP地址:122.4.32.★
 
 
 
http://blog.chinaunix.net/u/21948/showart_158080.html

(1)如果你是以非root身份登陆,然后用su切换到root执行insmod,那么容易出现这个问题,也就是说在当前搜索路径列表所执行的目标位置找不到insmod这个可执行程序。方法比较简单,根据上述连接应该很容易理解。

(2)如果你本来就是用root身份登陆,默认初始化配置中PATH应该包含路径/sbin。

所以推测你可能是(1),而PATH中没有/sbin
 
 

 
网友: piaoxiang 时间:2007-01-30 15:19:42 IP地址:122.4.32.★
 
 
 
所有用户皆可用的系统程序放在/bin

超级用户才能使用的系统程序放在/sbin

所有用户都可用的应用程序放在/usr/bin

超级用户才能使用的应用程序放在/usr/sbin

所有用户都可用的与本地机器无关的程序存放在/usr/local/bin

超级用户才能使用的与本地机器无关的程序存放在/usr/local/sbin

这是一个默认的存放原则。s应该是代表superusr的含义吧。上面回复中有一点说的不明确。你如果在普通用户切换到超级用户root权限时,采用命令:

su -

注意,不是su,su后面还有-,那么就完全转入root的初始环境配置。也就不存在你所说的问题了。如果只是su,虽然可以转为root,但是shell的初始环境仍然为普通用户的当前环境设置。所以,推荐的方法是:

以普通用户身份登陆,按照默认的环境配置就可以,需要root权限的时候,执行su -。这样既安全,又方便。

建议:

先看一些基础的东西。虽然我也是初学者,但是像这样的问题,网上都有,最好是先搜索一下,实在不理解再问。
 
 

 
网友: huangweiinhit123 时间:2007-01-30 16:19:49 IP地址:61.167.60.★
 
 
 
今天终于把第一个驱动运行了:)

太高兴了

谢谢你啦  最近我也在研究uboot

现在是看它烧写dataflash的程序 

 
 

 
网友: nnnqpnnn 时间:2007-02-07 14:09:14 IP地址:60.209.248.★
 
 
 
>>这是因为内核源代码版本和编译器版本不一致造成的。

第一个问题并不是内核源码版本与编译器版本不一致造成的。而是内核源代码版本跟当前使用的内核版本标志不一致造成的,不影响模块的使用但是会有警告。

希望没说错。
 
 

 
网友: piaoxiang 时间:2007-02-07 15:45:12 IP地址:122.4.32.★
 
 
 
实际上就是UTS_RELEASE这个标志的不一致。不过我使用的内核源代码就是当前使用的内核的源代码。而编译器的头文件version.h与这个不符合。还是觉得内核源代码版本和编译器对应的内核版本不一致。说编译器版本是有点不妥。

谢谢nnnqpnnn

 
 

 
网友: wrf_ferrari 时间:2007-02-08 23:06:48 IP地址:210.78.32.★
 
 
 
能看到你这篇文章很高兴,多谢了!
 
 

 
网友: qiaobinbin 时间:2007-02-09 11:06:40 IP地址:203.86.47.★
 
 
 
我编译上面的hello.c出现错误!

错误信息如下:

insmod: error inserting 'hello.o': -1 Invalid module format

我的内核版本:2.6.15-1.2054_FC5

编译版本:

#define UTS_RELEASE "2.6.15"

#define LINUX_VERSION_CODE 132116

#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))

~                                                              
 
 

 
网友: piaoxiang 时间:2007-02-11 08:02:49 IP地址:122.4.32.★
 
 
 
2.6的内核和2.4核下面不一样,我这里是基于2.4核的,如果你在2.6核下面实验,应该选择2.6核下的方式。参考《Linux设备驱动》第三版解决
 
 

 
网友: 本站网友 时间:2007-04-20 12:54:19 IP地址:218.18.115.★
 
 
 
"写了一个脚本,测试流程自动化"





请问如何实现编写一个脚本,脚本文件类型是什么,应该放在什么路径下?

另:makefile是对系统的还是对这个模块的?在哪里编辑?



谢谢

Blog作者的回复:
请参考Bash Shell的书籍,或者参考blog软件关于bash shell的总结文章。

 
 

 
网友: 我爱酸奶 时间:2007-04-26 09:35:19 IP地址:210.47.223.★
 
 
 
你好,看了你的这篇文章对我收益菲浅。有个问题。我按照你的方法一步一步的做。但是在./run之后,出现了一个warm:

hello.c: In function `init_module':                                            

hello.c:16: warning: implicit declaration of function `printk'                 

/usr/src/linux-2.4.20-8/include/asm/atomic.h: At top level: 

这个我不知道怎么解决了。谢谢你了。^o^


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值