모듈 컴파일시 에러가 발생하네요

beggarstar의 이미지

모듈 프로그래밍 연습 중에 연습예제에서 에러가 나네요.
무슨 문젠지 도움 부탁드립니다.

커널 모드에서 모듈을 적재해 hello 문자를 출력하려고 합니다.
module1.c, Makefile 파일은 아래와 같습니다. 에러도 복사해 넣었습니다.

답변 기다리겠습니다.

커널 버젼 : 2.6.16
gcc 버젼 : 4.0

module1.c
------------------------------------------------------------------------------------
#include
#include

/*
#ifdef CONFIG_MODVERSIONS
#define MODVERSIONS
#include
#endif
*/

int init_module(void)
{
printk("hello!!\n");

return 0;
}

void cleanup_module(void)
{
printk("bye!!\n");
}
---------------------------------------------------------------------------------------------

Makefile
===================================================================
CC = gcc

KERNELDIR = /usr/src/linux
CFLAGS = -D__KERNEL__ -DMODULE -I$(KERNELDIR)/include -g -Wall

all : module1.o

mudule1.0 : module1.c
$(CC) $(CFLAGS) -c module1.c

clean :
rm -f core module1.o
====================================================================

에러메시지
====================================================================
root@beggarstar:/home/soo/workspace/embeded/homework2# make
gcc -D__KERNEL__ -DMODULE -I/usr/src/linux/include -g -Wall -c -o module1.o module1.c
In file included from /usr/src/linux/include/linux/sched.h:20,
from /usr/src/linux/include/linux/module.h:10,
from module1.c:1:
/usr/src/linux/include/asm/semaphore.h: In function ‘down’:
/usr/src/linux/include/asm/semaphore.h:105: error: syntax error before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/semaphore.h: In function ‘down_interruptible’:
/usr/src/linux/include/asm/semaphore.h:130: error: syntax error before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/semaphore.h: In function ‘down_trylock’:
/usr/src/linux/include/asm/semaphore.h:155: error: syntax error before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/semaphore.h: In function ‘up’:
/usr/src/linux/include/asm/semaphore.h:179: error: syntax error before ‘KBUILD_BASENAME’
make: *** [module1.o] 오류 1
=====================================================================

kslee80의 이미지

커널 2.6 의 모듈 부분은 커널 2.4 의 모듈 부분에 비해 매우 많은 변화가 있습니다.
소스코드와 Makefile 을 보니 커널 2.4 를 기준으로 설명한 책(or 문서) 을 보시는것 같은데,
커널을 2.4 로 내리시거나 아니면 보는 책(or 문서) 을 2.6 기준으로 된 것으로 바꾸서야 할 것입니다.

beggarstar의 이미지

말씀하신대로 해보고 결과 보고하겠습니다.

yiky98의 이미지

2.6.16 인가 어디에선가 spinlock.h가 patch가 되었는데
LOCK_SECTION 관련 매크로가 바뀌면서 예전 모듈을 컴파일할때
에러가 발생한 적이 있습니다.

http://lkml.org/lkml/2006/3/28/186
여기 보시고 patch를 revert 시키면 된다고 하오니 참고하세요.