首先可以编辑在x86平台的模块
Hello_m.c如下
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
static int times = 1;
module_param(times, int, S_IRUGO);
static int hello_init(void)
{
int i = 0;
for (; i < times; i++)
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
Makefile如下
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
Insmod hello_m.ko
Cat /var/log/kern.log
烧写板子的uboot 内核 文件系统(2.6.13的内核 精简版的根文件系统)
1.
Make menuconfig 需要
ncurses
图形库
sudo apt-get install ncurses-dev
3.
使用天嵌提供的内核kernel-2.6.13-20081206.tar.bz2
load config_TQ2440_W35配置文件
4.
Make
5.
进入module目录修改makefile
KERNELDIR?= /home/shanshan/source/linux_kernel/2.6.13_compile_arm/opt/EmbedSky/kernel-2.6.13
原Makefile为
# To build modules outside of the kernel tree, we run "make"
# in the kernel source tree; the Makefile these then includes this
# Makefile once again.
# This conditional selects whether we are being included from the
# kernel Makefile or not.
ifeq ($(KERNELRELEASE),)
# You should set KERNELDIR in the environment if it's elsewhere
KERNELDIR ?= /home/shanshan/source/linux_kernel/2.6.13_compile_arm/opt/EmbedSky/kernel-2.6.13
# The current directory is passed to sub-makes as argument
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
.PHONY: modules clean
else
# called from kernel build system: just declare what our modules are
obj-m := hello_m.o
endif
6.
Make
7.
启动板子后讲/home/shanshan/roorfs挂在在板子的/tmp下
Mount -t nfs -o nolock,rsize=1024,wsize=1024,timeo=15 192.168.1.178:/home/shanshan/rootfs /tmp
8.
Insmod hello_m.ko
9.
可见打印helloworld
10.
也可修改vi /etc/init.d/rcS初始化脚本
加入insmod hello_m.ko 一行 开板子后即可看见helloworld