본문 바로가기

Embedded/Device Driver

[Device Driver] 커널에 Systemcall 등록 및 실행

작업 환경

-메인 OS : Windows 8.1K(Intel Core i5-4590)

-작업 OS : Ubuntu 14.04.5 LTS 64bit(VirtualBox)

-장 비 명 : Hybus-Smart4412



1. 초기설정

- cd ~/Smart4412/Development/Source/Kernel/kernel_4412/kernel

- hellocall.c를 만든다


hellocall.c

#include<linux/kernel.h>

asmlinkage long sys_hellocall()
{
printk("==========\n");
printk("Hello ~ sys call\n");
printk("==========\n");
return 0;
}



2. Kernel에 코드 등록

- cd /Smart4412/Development/Source/Kernel/kernel_4412/kernel

- vim Makefile

- obj-y 끝에 hellocall.o 추가 


- cd /Smart4412/Development/Source/Kernel/kernel_4412/arch/arm/include/asm/

- vi unistd.h

- #define __NR_hellocall      (__NR_SYSCALL_BASE+376) 추가


- cd /Smart4412/Development/Source/Kernel/kernel_4412/include/linux

- vi syscalls.h
- asmlinkage long sys_hellocall(int value); 추가


- cd /Smart4412/Development/Source/Kernel/kernel_4412/arch/arm/kernel

- calls.S ->커널 시작시 가장 먼저 시작하는 파일

- vi calls.S
/* 376 */   CALL(sys_hellocall) 추가

 


3. Kernel 파일 생성 및 Porting

cd /Smart4412/Development/Source/Kernel/kernel_4412

- make distclean

- ./build_kernel

- 만들어진 zImage만 다시 올린다 (http://cccding.tistory.com/56 (5.Kernel Porting) 참조)


4. syshello.c 작성 후 H-Smart4412에서 실행


- mkdir device(device 디렉토리에 syshello.c를 만든다)


syshello.c

#include<stdio.h>

#include</home/cjs/Smart4412/Development/Source/Kernel/kernel_4412/arch/arm/include/asm/unistd.h>


int main()

{

syscall(__NR_hellocall);

return 0;

}



/opt/gnueabi/opt/ext-toolchain/bin/arm-linux-gnueabihf-gcc syshello.c -o syshello (해당 디렉토리에서 컴파일)

- 위에서 수정한 unistd.h를 include 시켜줘야 정상 작동.

- Tera term으로 이동 (http://cccding.tistory.com/58 에서 1) 참조)

- 해당 파일 업로드 후 실행시키면 Hello ~ sys call 출력