顯示具有 kernel 標籤的文章。 顯示所有文章
顯示具有 kernel 標籤的文章。 顯示所有文章

星期四, 9月 10, 2009

Study LDD3 on Debian

在 Debian 上建立學習 Linux Device Driver 的環境

aptitude install build-essential
aptitude install linux-headers-2.6.30-1-686
aptitude install linux-headers-2.6.30-1-common
aptitude install linux-kbuild-2.6.30
如此會在 /usr/src 安裝好編繹 kernel module 的環境

接著按照 LLD3 上寫的第一個範例 hello.c
#include
#include
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
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 ?= /usr/src/linux
PWD := $(shell pwd)
RM = rm -rf
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
clean:
$(RM) *.ko *.o *.mod.c .*.cmd Module.* modules.* .tmp_versions
接著下 make 就可以編出 hello.ko 了 :D

星期一, 9月 08, 2008

How to build kernel module

要將某 driver 編成 kernel module
則其 Makefile 需要下面規則

obj-m += hello-1.o

all:
make -C M=$(shell pwd) modules

clean:
make -C M=$(shell pwd) clean

然後下 make 就可以了。

參考自
http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN121

星期一, 1月 21, 2008

no machine record defined

編核心時,遇到下面這個問題

arm-9tdmi-linux-gnu-ld: no machine record defined


在 google 查到的都是說將arch/arm/kernel/vmlinux.lds的最後兩行(如下),給註解起來,但都沒說是為了什麼
ASSERT((__proc_info_end - __proc_info_begin), "missing CPU support")
ASSERT((__arch_info_end - __arch_info_begin), "no machine record defined")


後來自己到 arch/arm/kernel/vmlinux.lds 裡看的時候,才發現別有洞天。原來那兩行的上頭寫著
/*
* These must never be empty
* If you have to comment these two assert statements out, your
* binutils is too old (for other reasons as well)
*/
ASSERT((__proc_info_end - __proc_info_begin), "missing CPU support")
ASSERT((__arch_info_end - __arch_info_begin), "no machine record defined")


查了一下所使用的 binutils 版本是 2.15,與 HOST 上的 2.17 比起來確實有點舊了。
所以暫時方向先重新弄一版 crosstool 吧 :)

星期一, 11月 12, 2007

編核心的經驗

1. 執行 make zImage 時出現下面訊息

make: *** No rule to make target `include/linux/autoconf.h', needed by `include/config/MARKER'. Stop.

->autoconf.h 是由 make menuconfig 所產生的,所以會出現這樣的訊息,是因為 make menuconfig 後沒有存檔或是選好吧!