编译一个linux内核模块
看源代码。
#include <linux/kernel.h>
#include <linux/module.h>
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif
int init_module()
{
printk("Hello, I'm kernel\n");
return 0;
}
void cleanup_module()
{
printk("I'm kernel, bye\n");
}
再来看 makefile的写法
TARGET = hello
OBJS = hello.o
MDIR = drivers/misc
EXTRA_CFLAGS = -DEXPORT_SYMTAB
CURRENT = $(shell uname -r)
KDIR = /lib/modules/$(CURRENT)/build
PWD = $(shell pwd)
DEST = /lib/modules/$(CURRENT)/kernel/$(MDIR)
obj-m := $(TARGET).o
default:
make -C $(KDIR) SUBDIRS=$(PWD) modules
$(TARGET).o: $(OBJS)
$(LD) $(LD_RFLAG) -r -o $@ $(OBJS)
ifneq (,$(findstring 2.4.,$(CURRENT)))
install:
echo $(DEST) $(LD_RFLAG)
su -c "cp -v $(TARGET).o $(DEST) && /sbin/depmod -a"
else
install:
su -c "cp -v $(TARGET).ko $(DEST) && /sbin/depmod -a"
endif
clean:
-rm -f *.o *.ko .*.cmd .*.flags *.mod.c
-include $(KDIR)/Rules.make
好了 放入到位置运行makefile即可
插入模块的命令是这样的
$insmod hello.ko(PS:尽管你看不到有.ko这样的文件,但是的确是这么来做的)
用 dmesg 就可以看到 输出啦。。。。
补充一个错误:
./linux/include/asm/elf.h: In function `start_ia32_thread':
./linux/include/asm/elf.h:153: warning: implicit declaration of function `load_g
s_index'
./linux/include/asm/elf.h: In function `elf_common_init':
./linux/include/asm/elf.h:166: error: structure has no member named `r8'
./linux/include/asm/elf.h:166: error: structure has no member named `r9'
./linux/include/asm/elf.h:166: error: structure has no member named `r10'
./linux/include/asm/elf.h:166: error: structure has no member named `r11'
./linux/include/asm/elf.h:167: error: structure has no member named `r12'
./linux/include/asm/elf.h:167: error: structure has no member named `r13'
./linux/include/asm/elf.h:167: error: structure has no member named `r14'
./linux/include/asm/elf.h:167: erro
相关文档:
经常需要Kill多个进程,这些进程包含共同的关键字,可以用一条命令Kill掉它们。 ps aux | grep "common" | cut –c 9-15 | xargs kill –9 管道符“|”用来隔开两个命令,管道符左边命令的输出会作为管道符右边命令的输入。下面说说用管道符联接起来的几个命令: "ps aux" 查看所有进程的命令。这时检索出的 ......
将联网方式设置为NAT
第一步:
cd到/etc/sysconfig/network-scripts系的ifcfg-eth0
第二步:
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
#BOOTPROTO=static
BOOTPROTO=none
BROADCAST=192.168.174.255
HWADDR=00:0C:29:F2:BB:A9
IPADDR=192.168.174.11
......
前言:
目前正在忙于ARM平台的Linux应用程序的开发(其实是刚刚起步学习啦)。底层的东西不用考虑了,开发板子提供了NAND Bootloader,和Linux 2.6的源码,而且都编译好了。自己编译的bootloader可以用,但是Linux编译后,文件很大,暂且就用人家编译的系统,先专心写应用程序 吧。。
正文:要做的任务是,把一块板子上的 ......