module compile

joyjoj의 이미지

module compile을 하려고 하는데요.

hello.c를 다음과 같이 작성했구요.

#include <linux/module.h>
#include <linux/tty.h>
#include <linux/init.h>
#include <linux/kernel.h>

int hello_init(void)
{
    printk(KERN_ALERT "HELLO, World\n");
    return 0;
}

void hello_exit(void)
{
    printk(KERN_ALERT "bye bye\n");
}

module_init(hello_init);
module_exit(hello_exit); 

Makefile을 다음과 같이 만들었습니다.

KERNEL_SRC = /usr/src/linux
           SUBDIR = $(KERNEL_SRC)/net/hello/
           all: modules

           obj-m := module.o
           hello-objs := hello.o

           EXTRA_FLAGS += -DDEBUG=1

           modules:
                $(MAKE) -C $(KERNEL_SRC) SUBDIR=$(SUBDIR) modules

커널 버전은 2.6.5이구요. make하면 다음처럼 결과가 나오는데요.

make -C /usr/src/linux-2.6.5 SUBDIR=/usr/src/linux-2.6.5/net/hello/ modules
make[1]: Entering directory '/usr/src/linux-2.6.5'
   CHK        include/linux/version.h
make[2]: 'arch/i386/kernel/asm-offsets.s' is up to date.
   CHK        include/asm-i386/asm_offsets.h
drivers/net/wireless/acx100/Makefile:3: ACX_DEBUG was not defined, assuming 1
   Building modules, stage 2.
   MODPOST
make[1]: Leaving directory '/usr/src/linux-2.6.5'

make가 제대로 안된 것 같은데... object 파일이 생성되지 않아서요. 무슨 문제가 있는거죠? compile이 된 다음에 load하려면 insmod명령을 사용하면 되나요? 2.4하고 다른 명령이 생긴것 같기도 하던데...

고수님들의 답을 부탁드립니다.

sjpark의 이미지

$(KERNEL_SRC)/drivers/char/hello/

요세 2.6에서 모듈 만들일이 없어 기억이 가물가물 하지만.
저 폴더 안에 ko가 생성되지 않았을까 해서요..
(혹시나 아니면...... 윽..=0= )

joyjoj의 이미지

sub directory로 path를 바꾸어주었습니다. module compile하려는 source가 들어있는 폴더거든요. make 결과는 문제가 없는건가요?

sjpark의 이미지

sjpark mod2.6 # make -C /usr/src/linux SUBDIRS=/root/Work/mod2.6 modules
make: Entering directory `/usr/src/linux-2.6.5'
*** Warning: Overriding SUBDIRS on the command line can cause
***          inconsistencies
make[1]: `arch/i386/kernel/asm-offsets.s' is up to date.
  CC [M]  /root/Work/mod2.6/test.o
  Building modules, stage 2.
/usr/src/linux-2.6.5/scripts/Makefile.modpost:17: Trouble: /root/Work/mod2.6/preempt_test.ko
/usr/src/linux-2.6.5/scripts/Makefile.modpost:18: *** Uh-oh, you have stale module entries. You messed with SUBDIRS,
/usr/src/linux-2.6.5/scripts/Makefile.modpost:19: do not complain if something goes wrong.
  MODPOST
  CC      /root/Work/mod2.6/test.mod.o
  LD [M]  /root/Work/mod2.6/test.ko
make: Leaving directory `/usr/src/linux-2.6.5'
sjpark mod2.6 # ls
Makefile  test.c  test.ko  test.mod.c  test.mod.o  test.o

간단한 코드만들어서 컴파일 해 보았습니다.

(갖은 협박을 다 하고 있는것 같지만..훗.. 다 무시해버렸지요. 훗)

ps. 앞서 포스팅한 제 글은 틀린것으로 ... 되새겼습니당;

sldk의 이미지

sjpark mod2.6 # make -C /usr/src/linux SUBDIRS=/root/Work/mod2.6 modules
make: Entering directory `/usr/src/linux-2.6.5'
*** Warning: Overriding SUBDIRS on the command line can cause
***          inconsistencies
make[1]: `arch/i386/kernel/asm-offsets.s' is up to date.
  CC [M]  /root/Work/mod2.6/test.o
  Building modules, stage 2.
/usr/src/linux-2.6.5/scripts/Makefile.modpost:17: Trouble: /root/Work/mod2.6/preempt_test.ko
/usr/src/linux-2.6.5/scripts/Makefile.modpost:18: *** Uh-oh, you have stale module entries. You messed with SUBDIRS,
/usr/src/linux-2.6.5/scripts/Makefile.modpost:19: do not complain if something goes wrong.
  MODPOST
  CC      /root/Work/mod2.6/test.mod.o
  LD [M]  /root/Work/mod2.6/test.ko
make: Leaving directory `/usr/src/linux-2.6.5'
sjpark mod2.6 # ls
Makefile  test.c  test.ko  test.mod.c  test.mod.o  test.o

사실 2.6 모듈 컴파일의 가장 기본은

Makefile에

      obj-m :=(filename).o

이렇게만 놔두고

make -C (linux 경로) SUBDIR=(모듈.c의 경로) modules

이렇게 실행을 하는겁니다.

위의 makefile은 제가 봤던 문서에도 예제로 나온 코드인데,

makefile을 좀 조작해서 trick을 쓴거구요.

위 경우에는, makefile내에서 SUBDIR과 KERNEL_SRC 경로를

적당히 정해주신 뒤에,

make만 하면, all: 에서 modules:를 부르고 이게

make -C ... SUBDIR=... modules라는 커맨드를 실행시키게 하는거죠.

즉, 위와 같이 makefile을 만드셨으면, 변수 셋팅 하고 "make" 만 치시면 됩니다.

위 경우에는 컴파일은 제대로 된 것으로 보이는데,

make -C .. SUBDIR=... modules 해주셨기 때문에,

makefile내부의 SUBDIR과 충돌이 난 것 같군요.

Easy come, easy go.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.