1 / 12

모듈 프로그래밍

Module programming. 모듈 프로그래밍. 모듈프로그래밍. 초기 리눅스 : 커널 변경시 커널 전체를 다시 컴파일 모듈 프로그램으로 개발하면 해당 모듈만 컴파일하고 필요할 때만 동적으로 링크시켜 커널의 일부로 사용할 수 있어 효율적 자주 사용하지 않는 커널 기능은 메모리에 상주시키지 않아도 됨 확장성과 재사용성을 높일 수 있음. 모듈 프로그래밍의 특징 사건 구동형 (event-driven program) 방식으로 작성 내부에 main() 이 없음

emma-hinton
Download Presentation

모듈 프로그래밍

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Module programming 모듈 프로그래밍

  2. 모듈프로그래밍 • 초기 리눅스: 커널 변경시 커널 전체를 다시 컴파일 • 모듈 프로그램으로 개발하면 해당 모듈만 컴파일하고 필요할 때만 동적으로 링크시켜 커널의 일부로 사용할 수 있어 효율적 • 자주 사용하지 않는 커널 기능은 메모리에 상주시키지 않아도 됨 • 확장성과 재사용성을 높일 수 있음.

  3. 모듈 프로그래밍의 특징 • 사건 구동형(event-driven program) 방식으로 작성 • 내부에 main()이 없음 • 커널에 적재/제거하기 위한 규칙과 유틸리티가 필요 • 외부로 공개할 전역변수 사용에 주의 • 커널에 적재된 모듈 프로그램은 무제한의 특권을 가지므로 신중하게 작성해야 함

  4. 심볼 및 관련 매크로 • 전역변수와 전역 함수 이름을 심볼 테이블에 등록 • 커널 심볼 테이블의 내용은 /proc/kallsyms라는 텍스트 파일로 외부에 제공 • EXPORT_NO_SYMBOLS: 공개하지 않음 • EXPORT_SYMBOL(), EXPORT_SYMBOL_GPL(): 공개

  5. 모듈 프로그램의 기본 형태

  6. 호스트 시스템에서 모듈 생성을 위한 Makefile 기본 형태 • 타겟 시스템에서 모듈 생성을 위한 Makefile 기본 형태

  7. 실습 [모듈기초]-1호스트 시스템의 커널 공개 심볼 살펴보기 • head /proc/kallsyms, tail /proc/kallsyms를 입력해 커널 심볼 테이블의 내용을 확인

  8. insmod: 모듈을 커널로 적재하는 명령 • rmmod: 제거하는 명령 • lsmod: 정상적으로 적재되었는지 확인하는 명령

  9. 실습[모듈기초]-2Hello 모듈 프로그램 작성 및 실행 • 모듈 프로그램 hello.c 작성 01 #include <linux/kernel.h> 02 #include<linux/module.h> 03 #include<linux/init.h> 04 05 static int module_begin(void) // 모듈 초기화 함수 06 { 07 printk("Hello, Module!\n"); 08 return 0; 09 } 10 11 static void module_end(void) // 모듈 마무리 함수 12 { 13 printk("Good bye!\n"); 14 } 15 16 module_init(module_begin); 17 module_exit(module_end);

  10. ② ③ ④ ⑤ 실습 [모듈기초]-3Hello 모듈 프로그램 작성 및 실행 • Makefile을 작성 앞의 호스트시스템용 makefile에서 test.o→hello.o • make로 hello.ko 모듈 프로그램을 생성하고 테스트

  11. 실습 [모듈기초]-4Hello 모듈 프로그램 작성 및 실행 • cat /proc/kallsyms 명령으로 커널 심볼 테이블에 있는 hello.c의 심볼들을 확인

  12. 실습 [모듈기초]-5타겟시스템용 모듈 작성 • 기본적으로 호스트 시스템용 모듈과 유사 • 다음을 수정 • 타겟시스템용Makefile에서 KDIR 수정 • KDIR := /achro4210/kernel # if 보드용커널의 위치가 /achro4210/kernel • Minicom 을이용하여 보드로 hello.ko이동 • 보드에서 다음을 수행 • insmodhello.ko • lsmod | grep hello • dmesg | tail –n 5 • rmmod hello

More Related