Kernel - loadable module 작성하기

숲사람·2022년 3월 24일
0

Linux Kernel

목록 보기
2/10

external loadable module 작성하기

기본 소스코드

  • example_module.c
#include <linux/init.h>
#include <linux/module.h>

int example_init(void)
{
  return 0;
{

void example_exit(void)
{
}
module_init(example_init);
module_exit(example_exit);
  • Makefile
obj-m := example_module.o

obj-m := <module_name>.o

The kbuild system will build <module_name>.o from <module_name>.c

<module_name>-y := <src1>.o <src2>.o ...

When the module is built from multiple sources, an additional line is needed listing the files:

만약 여러 소스코드를 같이 빌드해야한다면

obj-m := example_module.o
example_module-y := additional_src1.o  additional_src2.o

빌드

  • build using Kbuild
$ make -C <path_to_kernel_src> M=$PWD <target>

빌드할때 커널 소스코드가 필요(-C옵션), M는 생성되는 module 위치
마지막 에 modules를 넣으면 됨 (자세한 내용은 아래 2.3 Targets 확인)
https://www.kernel.org/doc/html/latest/kbuild/modules.html

Load 모듈

 $

docs

https://www.kernel.org/doc/html/latest/kbuild/modules.html

profile
기록 & 정리 아카이브 용도 (보다 완성된 글은 http://soopsaram.com/documentudy)

0개의 댓글