發表文章

目前顯示的是 5月, 2014的文章

Cross Compile Hello world kernel module - PowerPC

寫了幾年的程式,常常在改人家寫好的kernel module,好像沒自己寫過,今天就來試試看。 1.先寫好hello.c 這段整個是reference copy來的。 #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ int init_module(void) { printk(KERN_INFO "Hello world 1.\n"); /* * A non 0 return means init_module failed; module can't be loaded. */ return 0; } void cleanup_module(void) { printk(KERN_INFO "Goodbye world 1.\n"); } 2. Makefile kernel module的compile方式跟 userspace application 有點不同。 我實驗用的開發板是PowerPC平台,其make file如下。 # Cross compilation Makefile for ARM KERN_SRC=../../linux-2.6.37_build obj-m := hello.o all: make -C $(KERN_SRC) ARCH=powerpc CROSS_COMPILE=/opt/powerpc/usr/bin/powerpc-linux- M=`pwd` modules clean: make -C $(KERN_SRC) ARCH=powerpc CROSS_COMPILE=/opt/powerpc/usr/bin/powerpc-linux- M=`pwd` clean 3.把hello.ko tftp至機器上測試 [root@localhost /sbin]# insmod hello.ko Hell