필자가 이더켓을 라즈베리파이를 이용해서 이더켓 마스터와 클라이언트를 구현하기 위해서 자룔를 찾다가 보니 라즈베리파이에 W5500을 이용해서 구현한 마스터 샘플를 찾았는데 라즈베리에서 이용하려면 리얼타임 커널 패치를 하라고 되어있었다. 

     

      필자가 작성한 문서가 약 1년 쯤 전이었으니, 아마 커널은 조금 변경 되었지 싶긴한데 변경된 버전만 찾으면 되니까... 라즈베리파이에 리얼타임을 적용하는 방법을 안내하도록 하겠다. 

     

    1. Rasbian Buster Real-Time system using Preempt-RT

    1.1. Getting the source

      본 가이의 대부분 (커널 구성 및 컴파일) Raspberry Pi!가 아니라 Linux를 실행하는 호스트 컴퓨터 (x86 / x64)에서 수행됨, 라즈베리파이에서 실행할 부분은 별도 표시.

     

    (1) 작업디렉터리 생성

    ~$ mkdir ~/rpi-kernel
    ~$ cd ~/rpi-kernel
    ~rpi-kernel$ mkdir rt-kernel

     

    (2) 커널 소스 및 툴체인 다운로드

      커널 다운로드

    ~/rpi-kernel$ git clone https://github.com/raspberrypi/linux.git -b rpi-4.19.y-rt
    ~/rpi-kernel$ git clone https://github.com/raspberrypi/tools.git

     

    1.2. Environment Setting

    (1) 크로스 컴파일 환경 설정 

    ~/rpi-kernel$ export ARCH=arm
    ~/rpi-kernel$ export CROSS_COMPILE=~/works/ethercat/rpi-kernel/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-

     

    커널 모듈 설치 위치와 디바이스 트리 설치 위치 설정

    ~/rpi-kernel$ export INSTALL_MOD_PATH=~/works/ethercat/rpi-kernel/rt-kernel
    ~/rpi-kernel$ export INSTALL_DTBS_PATH=~/works/ethercat/rpi-kernel/rt-kernel

     

    (2) 커널빌드 설정

    -RaspberryPi 2, 3B(+)

    ~/rpi-kernel$ export KERNEL=kernel7
    ~/rpi-kernel$ cd ~/works/ethercat/rpi-kernel/linux/
    ~/rpi-kernel/linux/$ make bcm2709_defconfig

     

    - RaspberryPi 4B

    ~/rpi-kernel$ export KERNEL=kernel7l
    ~/rpi-kernel$ cd ~/works/ethercat/rpi-kernel/linux/
    ~/rpi-kernel/linux/$ make bcm2711_defconfig

     

    1.3. 커널 컴파일

    (1) 커널 이미지 생성

    ~/works/ethercat/rpi-kernel/linux$ make -j4 zImage

     

    (2) 커널 모듈 빌드

    ~/works/ethercat/rpi-kernel/linux$ make -j4 modules

     

    (3) 디바이스 트리 빌드

    ~/works/ethercat/rpi-kernel/linux$ make -j4 dtbs

     

    (4) 빌드된 모듈 설치

    ~/works/ethercat/rpi-kernel/linux$ make -j4 modules_install

    (5) 디바이스 트리 설치

    ~/works/ethercat/rpi-kernel/linux$ make -j4 dtbs_install

     

    1.4. 커널 배포 이미지 생성

    (1) 부트 디렉터리 생성

    ~/works/ethercat/rpi-kernel/linux$ mkdir $INSTALL_MOD_PATH/boot

     

    (2) 커널 이미지 생성

    ~/works/ethercat/rpi-kernel/linux$ ./scripts/mkknlimg ./arch/arm/boot/zImage $INSTALL_MOD_PATH/boot/$KERNEL.img

     

    (3) 커널 이미지 디렉터리로 이동 후 파일이름 변경

    ~/works/ethercat/rpi-kernel/linux$ cd $INSTALL_MOD_PATH/boot
    ~/works/ethercat/rpi-kernel/linux$ mv $KERNEL.img kernel7_rt.img

     

    1.5. 커널 전송

      컴파일이 완료되면 모든 파일을 압축하여 라즈베리파이로 전송.

    (1) 커널 이미지 압축

    ~/works/ethercat/rpi-kernel/linux$ cd $INSTALL_MOD_PATH
    ~/works/ethercat/rpi-kernel/rt-kernel$ tar czf ../rt-kernel.tgz *

     

    (2) 커널 이미지 전송

      전송중 connection refused가 표시되면 라즈베리파이설정(raspi-config)에서 ssh를 enable로 설정후 다시 시도.

    ~/works/ethercat/rpi-kernel/rt-kernel$ cd ..
    ~/works/ethercat/rpi-kernel$ scp rt-kernel.tgz pi@<ipaddress>:/tmp
    Ex) ~/works/ethercat/rpi-kernel$ scp rt-kernel.tgz pi@192.168.0.64:/tmp

    파일 전송전 핑거프린터 Yes 입력 후 진행

    ~/works/ethercat/rpi-kernel$ scp rt-kernel.tgz pi@192.168.0.64:/tmp
    The authenticity of host '192.168.0.64 (192.168.0.64)' can't be established.
    ECDSA key fingerprint is SHA256:lgyiOSKj0MbVrRkr7Qffp0iB...(생략)...
    Are you sure you want to continue connecting (yes/no)? yes

     

    ### 여기서부터 라즈베리파이에서 진행

    1.6. 라즈베리파이에서 이미지 처리

    (1) 전송된 압축파일 확인

      호스트에서 scp로 전달된 파일 내용을 확인한다.

    ~$ cd /tmp
    /tmp$ ls
    … (생략) …  rt-kernel.tgz  ... (생략) …

     

    (2) 압축파일 해제

      압축에 제대로 풀렸는지 확인 -C는 압축 풀 디렉터리를 지정하는 옵션임.

    /tmp$ mkdir rt-kernel
    /tmp$ tar xzf rt-kernel.tgz -C ./rt-kernel
    /tmp$ cd rt-kernel

     

    (3) 부트관련 파일 복사

      라즈베리에서 부트 관련된 파일이 있는 디렉터리(/boot)로 필요한 파일 복사.

    /tmp/rt-kernel$ cd boot
    /tmp/rt-kernel/boot$ sudo cp -rd * /boot
    /tmp/rt-kernel/boot$ sync

     

    (4) 라이브러리 관련 파일 복사

      시스템에서 사용할 라이브러리 복사

    /tmp/rt-kernel/boot$ cd ../lib
    /tmp/rt-kernel/lib$ sudo cp -dr * /lib
    /tmp/rt-kernel/lib$ sync

     

    (5) 오버레이 관련 파일 복사

      오버레이 설정 파일 복사 

    /tmp/rt-kernel/lib$ cd ../overlays
    /tmp/rt-kernel/overlay$ sudo cp -d * /boot/overlays
    /tmp/rt-kernel/overlay$ sync

     

    (6) 기타 부트관련 파일 복사

    /tmp/rt-kernel/overlay$ cd ..
    /tmp/rt-kernel$ sudo cp -d bcm* /boot
    /tmp/rt-kernel$ sync

     

    (7) 부트 설정 변경

      부트할 때 참조할 커널 이미지를 rt커널로 변경한다.

    sudo vim /tmp/rt-kernel$ nano /boot/config.txt

     

    추가할 내용은 아래와 같다. 

    # Add the following option:
    kernel=kernel7_rt.img

     

    (8) 커널 변경 확인

    uname 명령으로 커널 버전을 확인한다.

    ~$ uname -r
    4.19.71-rt23-v7+

     

    레퍼런스 사이트 안내 : 아래의 사이트 내용 참조.

    https://lemariva.com/blog/2019/09/raspberry-pi-4b-preempt-rt-kernel-419y-performance-test

     

     

    # 이상 라즈베리파이 리얼타임 커널 포팅... 끝.

     

     

    반응형
    • 네이버 블러그 공유하기
    • 네이버 밴드에 공유하기
    • 페이스북 공유하기
    • 카카오스토리 공유하기