한국어
Embedded
 

HelloWorld 커널 모듈 예제와 yocto 레시피를 작성하고 모듈을 적재 및 제거하는 내용을 다룬다.

 

개발환경: 우분투 리눅스 18.04, yocto

타겟: wandboard (i.MX6)

 

NXP에서 제공하는 욕토 레이어 meta-freescale, meta-freescale-3rdparty, meta-freescale-distro 를 사용할 수 있다.

이글은 간단한 커널 모듈을 적재하는 방법을 설명할 것이며 이미지는 아주 작은 것을 사용한다. 다음의 명령으로 이미지를 빌드 할 수 있다.

bitbake core-image-minimal

 

meta-freescale-3rdparty 레이어에 레시피 추가

 

위에서 언급한 레이어에 간단한 커널 모듈을 위한 레시피를 추가하려한다. 먼저 적당한 이름의 디렉토리를 만든다.

<your source path>/meta-freescale-3rdparty/recipes-kernel$ mkdir hello-module

 

$ cd hello-module

 

레시피 작성

hello-module.bb

#
# Yocto recipe to build a kernel module out of the kernel tree
# hello-module.bb 
# www.makersweb.net
#

DESCRIPTION = "Hello kernel module out of the kernel tree"
SECTION = "examples"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e"
PR = "r0"

inherit module

SRC_URI =  "file://hello.c \
                        file://Makefile \
                        file://COPYING \
                        "

S = "${WORKDIR}"

 

$ mkdir files

$ cd files/

 

모듈 프로그램 작성

hello.c

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

static int __init hello_init(void)
{
    printk("Hello World!\n");
    return 0;
}

static void __exit hello_exit(void)
{
    printk("Good bye!\n");
}

module_init(hello_init); // when insmod
module_exit(hello_exit); // when rmmod

MODULE_LICENSE("GPL v2");

 

Makefile 작성

Makefile

obj-m += hello.o

SRC := $(shell pwd)

all:
        $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules

modules_install:
        $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install

clean:
        rm *.o

 

디렉토리 구조

hello-module

├── files

│   ├── COPYING

│   ├── hello.c

│   └── Makefile

└── hello-module.bb

 

해당 레시피를 빌드

$ bitbake hello-module

 

빌드된 모듈 위치 찾기

$ bitbake -e hello-module | grep ^WORKDIR=

 

모듈을 이미지에 포함시키기

<build dir>/conf/local.conf 파일에 다음 라인 추가

IMAGE_INSTALL_append = " hello-module"

 

이미지 다시 빌드

$ bitbake core-image-minimal

 

이미지를 sd메모리에 쓰고 부팅

hello-module은 /lib/modules/4.9.67-fslc+g953c6e30c970/extra 에서 찾을 수 있다.

 

모듈 적재 및 제거

image.png

 

번호 제목 글쓴이 날짜 조회 수
52 [Uboot 명령어 및 환경 변수 요약]U-Boot에 Command 및 Parameter에 대한 설명 pjk 2014.01.09 10388
51 printk() makersweb 2014.02.27 5154
50 GNU C 레퍼런스 메뉴얼 - 부록 D secret makersweb 2014.02.28 5
49 임베디드 시스템 개발 환경 선택 makersweb 2014.03.05 3529
48 부트로더의 start.S 분석 file makersweb 2014.03.23 3614
47 시리얼 인터페이스 커넥터를 위한 핀아웃 file pjk 2014.10.10 4798
46 USB 핀아웃 file pjk 2014.10.11 8432
45 폴링(Polling), 인터럽트(Interrupt), DMA(Direct Memory Access) file pjk 2014.10.24 6012
44 USB OTG 기술의 개념 file pjk 2014.11.03 15254
43 실시간 운영 체제 또는 RTOS(Real Time Operating System) pjk 2014.12.02 5847
42 AVR(AT90USB162)을 USB to Serial 로 이용하기 file makersweb 2015.02.14 4821
41 ST, STM32 MCU용 ‘통합 개발 환경(IDE)’ 무료 제공 makersweb 2015.03.04 8859
40 JFlashARM으로 MCU에 bin(바이너리)다운로드 file makersweb 2015.06.07 4301
39 이클립스에서 IAR프로젝트 사용방법 file makersweb 2015.07.09 8779
38 AVRISP mkII 펌웨어 업그레이드 file makersweb 2015.07.22 6936
37 윈도우10에서 Prolific USB to Serial 드라이버 인식문제 file makersweb 2016.01.24 22792
36 STM32와 CAN(Controller Area Network) Loop Back file makersweb 2017.01.23 5414
35 STM32(Cortex-M3) 개발환경구축 with Eclipse file makersweb 2018.11.08 3591
34 yocto project, 라즈베리파이를 위한 Qt + 임베디드리눅스 빌드 file makersweb 2019.02.01 11018
33 욕토 프로젝트를 이용한 Qt SDK 빌드 for 라즈베리파이3 file makersweb 2019.03.19 3067