embedded linux의 경우는 kernel 소스에 module까지 들어가 있는데다가
menuconfig로 설정할 수 있게 환경이 다 되어 있습니다.
때문에 개별로 모듈을 빌드하기 위해서 Makefile을 구성할 필요가 없습니다.
만약 별도로 전용 Makefile을 만든다고 해도, 커널별로 Makefile을 분석해서
다른 필요한 component 만들어 채워야 하기 때문에, 기존에 있는 소스를 이용하는 방법이 최선이겠더군요.

필요한 파일은 다음과 같습니다.
Kconfig (menuconfig 설정 파일: 추가)
Makefile (obj-$() += hello.o 추가)
module 소스 파일(hello.c)

일단 테스트로 간단하게 hello.c 모듈을 만들었습니다.
테스트 용으로 char 장치를 추가 하였기 때문에
/kernel/char/ 위치에 파일을 추가하였습니다.
(Kconfig와 Makefile도 /kernel/char/에 위치하는 것을 수정합니다.)

//hello.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>

static int anumber = 1;
static char *astring = NULL;

module_param(anumber,int,0);
module_param(astring,charp,0);

int hellow_init(void)
{
printk("<1>Hello, world [anumber=%d:astring=%s]\n",anumber,astring);
return 0;
}

void hellow_exit(void)
{
printk("<1>Goodbye World\n");
}

module_init(hellow_init);
module_exit(hellow_exit);

MODULE_AUTHOR("lebych");
MODULE_DESCRIPTION("Module test #2");
MODULE_LICENSE("Dual BSD/GPL");

그리고 Kconfig에 다음과 같이 추가합니다.

config MINI2440_TEST
tristate "mini2440 test driver" <-메뉴 선택 화면에 나오는 이름
depends on ARCH_S3C2410 <-관련된 아키텍쳐
help
mini2440 hello world! test driver. <-Help를 누를 때 나오는 설명

다음에는 Makefile에 다음과 같이 추가합니다.

obj-$(CONFIG_MINI2440_TEST) += hello.o

보시다 시피 CONFIG_~ 이하의 이름이 Kconfig와 Makefile이 같아야 합니다.

위와 같이 완료되었으면, 커널 루트로 돌아가서

make menuconfig

를 실행해서 해당 모듈을 [M] (Modulize: 모듈로 선택적 로드) 로 만듭니다.



그리고 저장하고 빠져나온 다음

make modules

를 실행하면, 변경된 파일만 빌드를 합니다.
이 결과로 char/ 위치에 2.6.x 모듈인 hello.ko가 생성됩니다.

이 파일을 타깃 시스템으로 옮겨서 다음과 같이 실행합니다.

insmod hello.ko
dmesg |tail
rmmod hello.ko
dmesg |tail

제대로 모듈이 실행되었는지를 확인하면 됩니다.

[root@FriendlyARM /test]# insmod hello.ko anumber=0x11 astring="test string"
Hello, world [anumber=17:astring=test string]

[root@FriendlyARM /test]# dmesg |tail
<4>backlight initialized
<7>selected clock c02d9e94 (pclk) quot 26, calc 117187
<1>Hello, world [anumber=1:astring=]
<1>Goodbye cruel Worled
<3>hello: Unknown parameter `11'
<3>hello: Unknown parameter `11'
<3>hello: Unknown parameter `11'
<1>Hello, world [anumber=1:astring=]
<1>Goodbye cruel Worled
<1>Hello, world [anumber=17:astring=test string]

[root@FriendlyARM /test]# rmmod hello.ko
Goodbye cruel Worled

[root@FriendlyARM /test]# dmesg |tail
<7>selected clock c02d9e94 (pclk) quot 26, calc 117187
<1>Hello, world [anumber=1:astring=]
<1>Goodbye cruel Worled
<3>hello: Unknown parameter `11'
<3>hello: Unknown parameter `11'
<3>hello: Unknown parameter `11'
<1>Hello, world [anumber=1:astring=]
<1>Goodbye cruel Worled
<1>Hello, world [anumber=17:astring=test string]
<1>Goodbye cruel Worled
[root@FriendlyARM /test]#
Posted by 벅스바니
,