2020년 6월 10일 수요일

Linux Device Driver for Embedded Processors 에피소드 2 - STM32MP157C Discovery Kit 소개(2)

지난 시간에 이어 STM32MP157C Discovery Kit를 계속 분석(두번째 시간)해 보도록 하겠다. 😎




목차
2. Firmware(부팅 image)설치하기
3. 부팅 image 생성하기 - Yocto project, Buildroot
8. References
(*) 목차는 처음 예정했던 내용과 차이가 날 수도 있다.


2. Firmware(부팅 image) 설치하기
STM32MP157C Discovery Kit(이하 DK2 보드)에는 크게 4개(종류)의 USB port가 있는데, 아래 그림은 그 중 3개를 보여주고 있다. 왼쪽 port는 Power supply(5V/3A USB type C)용이고, 우측의 USB OTG(USB type C) port는 firmware upgrade(to microSD) 용이다. 그리고 아래쪽 port(micro USB B to USB A)는 ST-Linux/V2-1에 연결되어 있는데, debug용(linux 관점에서)으로 보면 된다.


[그림 2.1] STM32MP1 Connection block diagram
참고: 아래 ST-Linux/V2-1에 연결된 USB port(아래쪽 포트)는 Linux console port로 사용되지만, Cortex-M4용 flash에 firmware를 write하는 용도로도 사용된다.

그럼, 이 상태에서 prebuilt firmware image를 이용해 microSD에 writing을 해 보기로 하자. 여기서는 microSD를 꺼내지 않고(즉, PC에 장착하지 않고), STM32CubeProgrammer & USB OTG port를 통해 직접(마치 nand flash writing을 하듯이) writing을 시도해 볼 것이다.

<Firmware 설치 방법>
MicroSD card <== ROM code(boot switch 조정) <== USB OTG <== STM32CubeProgrammer <== firmware image file

지금부터 소개하는 내용은 모두 아래 site의 내용을 기준으로 하였다. 따라서 자세한 내용은 아래 site 내용을 참조하기로 하고, 여기에서는 반드시 필요한 내용 위주로 간략히 정리하기로 한다.


<Desktop PC - Ubuntu 18.04>
$ sudo apt-get install openjdk-8-jre-headless
$ sudo update-alternatives --config java
   -> Select the java-8-openjdk
$ sudo apt purge openjfx
$ sudo apt install openjfx=8u161-b12-1ubuntu2 libopenjfx-jni=8u161-b12-1ubuntu2 libopenjfx-java=8u161-b12-1ubuntu2
$ sudo apt-mark hold openjfx libopenjfx-jni libopenjfx-java
$ sudo apt-get install libusb-1.0-0

Download STM32CubeProgrammer ...
$ unzip en.stm32cubeprog_v2-4-0.zip
./SetupSTM32CubeProgrammer-2.4.0.linux

[그림 2.2] STM32CubeProgrammer 설치 시작 화면

$ vi ~/.bashrc
$ export PATH=/home/chyi/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin:$PATH
$ source ~/.bashrc

Download STM32MP15-Ecosystem-v1.2.0 Starter Package ...
$ tar xvf en.FLASH-stm32mp1-openstlinux-20-02-19.tar.xz
  => 이안에 prebuilt booting image 파일이 포함되어 있음.

<Target board 설정>
1) (전원을 인가하지 않은 상태에서) Target board 뒷 면의 boot switch를 아래와 같이 조정한다.
   => firmware writing이 성공한 후, 재부팅을 하려면 다시 원복해 주어야 한다.

[그림 2.3] 보드 후면 부트 스위치 변경 모습

2) USB A to C cable을 USB OTG port에 연결한다.
3) 5V/3A power cable을 연결한다.
   => 5V/2A adapter 밖에 없으니, 이걸 일단 사용한다.
4) reset button을 눌러준다.

<Desktop PC>
1) 이 상태에서 앞서 설치한 STM32CubeProgrammer를 실행하자.
2) 화면 상단 우측의 USB 선택 후, Connect 버튼을 누른다.

[그림 2.4] STM32CubeProgrammer 실행 모습(1)

3) 화면 좌측의 Open file을 선택하여 image 파일을 선택한다.
stm32mp1-openstlinux-20-02-19/images/stm32mp1/flashlayout_st-image-weston/FlashLayout_sdcard_stm32mp157c-dk2-trusted.tsv

[그림 2.5] STM32CubeProgrammer 실행 모습(2)

4) 화면 우측 중앙의 Download 버튼을 눌러 programming(writing)을 시작한다.

[그림 2.6] STM32CubeProgrammer 실행 모습(3)

5) Download가 진행되었고, 이후 설치가 되어야 하는데 ... 어랍쇼~  에러가 나면서 program이 중지가 된다. Target board를 쳐다 보니, 빨간색 LED가 계속 깜빡거리고, serial console(minicom)에는 "ERROR USB Type-C connection in unattached mode"라는 메시지가 보인다. 뭔가 잘못되었다.

[그림 2.7] STM32CubeProgrammer 실행 모습(4) - 에러 발생

아무래도 전류가 딸리는 모양이다. 5V/2A power adapter가 문제인 거 같다. 어쩔 수 없다. 5V/3A adapter를 하나 구매하는 수 밖에... 😂

[나중에 다시 작성한 것임] 5V/3A power adapter가 도착했다. 위의 작업을 계속 이어서 진행해 보니, 역시나 제대로 동작한다.

[그림 2.8] STM32CubeProgrammer 실행 모습(5) - OK 화면

[Tip] 끝까지 진행하는데 생각보다 시간이 꽤나 걸린다.


[그림 2.9] STM32CubeProgrammer 실행 모습(6) - LCD에 출력 모습

[그림 2.10] 재부팅 모습

<여기서 잠깐 ! STM32MP boot chains에 관하여>
아래 그림에서 보는 것과 같이 STM32MP의 booting flow(chain)는 꽤나 복잡하게 구성되어 있다. 단순히 u-boot, linux kernel만 이해한다고 끝날게 아닌 것 같다. 좀 더 면밀히 분석할 필요가 있어 보인다.

[그림 2.11] Trusted boot chain

참고: TF-A, OP-TEE 등은 trusted boot(or secure boot)를 위해 개발된 open source들인데, 추후 좀 더 알아보아야 할 듯 하다.

5V/3A power adapter를 구매하는데 시간이 좀 필요하므로, 그 전에 bootloader, kernel code 등을 먼저 build해 보아야 겠다.


3. 부팅 image 생성하기
2장을 보면서 느꼈겠지만, STM32MPU booting에 필요한 요소(TF-A, OP-TEE, u-boot, kernel, coprocessor용 firmware 등)가 생각보다 많고 꽤나 복잡해 보인다. 따라서 이번 장에서는 Yocto project와 Buildroot를 통해 이런 요소들이 전체적으로 어떻게 build되고 생성되는지를 따져 보도록 하자.

a) Yocto project를 통한 이미지 생성
먼저 이절에서는 아래 site 내용을 참조하여 Yocto/OpenEmbedded를 기반으로 image를 생성하는 방법을 정리해 보도록 하겠다.



[그림 3.1] Distribution 패키지 구성 요소

$ mkdir openstlinux-20-02-19
$ cd openstlinux-20-02-19
repo init -u https://github.com/STMicroelectronics/oe-manifest.git -b refs/tags/openstlinux-20-02-19
repo sync

[그림 3.2] meta-st 관련 주요 파일들

DISTRO=openstlinux-weston MACHINE=stm32mp1 source layers/meta-st/scripts/envsetup.sh
[HOST DISTRIB check]
Linux Distrib: Ubuntu
Linux Release: 18.04

[source layers/openembedded-core/oe-init-build-env][from nothing]

[EULA configuration]

[Configure *.conf files]
[INFO] No 'site.conf.sample' file available at /home/chyi/workspace/Boards/STM32MP1/workspace/distribution/openstlinux-20-02-19/layers/meta-st/scripts. Create default one...

===========================================================================
Configuration files have been created for the following configuration:

    DISTRO            :  openstlinux-weston
    DISTRO_CODENAME   :  thud
    MACHINE           :  stm32mp1
    BB_NUMBER_THREADS :  <no-custom-config-set>
    PARALLEL_MAKE     :  <no-custom-config-set>

    BUILDDIR          :  build-openstlinuxweston-stm32mp1
    DOWNLOAD_DIR      :  <no-custom-config-set>
    SSTATE_DIR        :  <no-custom-config-set>

    SOURCE_MIRROR_URL :  <no-custom-config-set>
    SSTATE_MIRRORS    :  <no-custom-config-set>

    WITH_EULA_ACCEPTED:  YES

===========================================================================

Available images for OpenSTLinux layers are:

  - Official OpenSTLinux images:
      st-image-weston       -   OpenSTLinux weston image with basic Wayland support (if enable in distro)

  - Other OpenSTLinux images:
      - Supported images:
          st-image-core         -   OpenSTLinux core image
      - Proposed images as example only:
          st-example-image-qt   -   ST example of image based on Qt framework   (require 'openstlinux-eglfs' distro)
          st-example-image-x11  -   ST example of image based on X11            (require 'openstlinux-x11' distro)
          st-example-image-xfce -   ST example of image based on XFCE framework (require 'openstlinux-x11' distro)
          and more images are available on meta-st-openstlinux/recipes-samples/images.

You can now run 'bitbake <image>'

$ bitbake st-image-weston

[그림 3.3] Yocto/OpenEmbedded build 모습

$ cd tmp-glibc/deploy/images/stm32mp1
$ ls -la
합계 1870164
drwxr-xr-x 4 chyi chyi     16384  6월  9 21:01 .
drwxr-xr-x 3 chyi chyi      4096  6월  9 18:22 ..
lrwxrwxrwx 2 chyi chyi        44  6월  9 19:21 Image -> Image--4.19-r0.2-stm32mp1-20200609082922.bin
-rw-r--r-- 2 chyi chyi  17589768  6월  9 19:21 Image--4.19-r0.2-stm32mp1-20200609082922.bin
lrwxrwxrwx 2 chyi chyi        44  6월  9 19:21 Image-stm32mp1.bin -> Image--4.19-r0.2-stm32mp1-20200609082922.bin
drwxr-xr-x 2 chyi chyi      4096  6월  9 21:01 flashlayout_st-image-weston
drwxr-xr-x 2 chyi chyi      4096  6월  9 18:22 scripts
-rw-r--r-- 2 chyi chyi  67108864  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922.bootfs.ext4
-rw-r--r-- 2 chyi chyi   6732772  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922.bootfs.tar.xz
-rw-r--r-- 2 chyi chyi       139  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922.rootfs.manifest
-rw-r--r-- 2 chyi chyi    355706  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922.testdata.json
-rw-r--r-- 2 chyi chyi  11010048  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.bootfs.ubi
-rw-r--r-- 2 chyi chyi  10158080  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.bootfs.ubifs
-rw-r--r-- 2 chyi chyi       355  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.ubinize.cfg.ubi
lrwxrwxrwx 2 chyi chyi        70  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1.ext4 -> st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922.bootfs.ext4
lrwxrwxrwx 2 chyi chyi        74  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1.manifest -> st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922.rootfs.manifest
lrwxrwxrwx 2 chyi chyi        72  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1.tar.xz -> st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922.bootfs.tar.xz
lrwxrwxrwx 2 chyi chyi        72  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1.testdata.json -> st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922.testdata.json
lrwxrwxrwx 2 chyi chyi        80  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1_nand_4_256.ubi -> st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.bootfs.ubi
lrwxrwxrwx 2 chyi chyi        82  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1_nand_4_256.ubifs -> st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.bootfs.ubifs
lrwxrwxrwx 2 chyi chyi        85  6월  9 20:49 st-image-bootfs-openstlinux-weston-stm32mp1_nand_4_256.ubinize.cfg.ubi -> st-image-bootfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.ubinize.cfg.ubi
-rw-r--r-- 2 chyi chyi     11080  6월  9 20:08 st-image-userfs-openstlinux-weston-stm32mp1-20200609082922.rootfs.manifest
-rw-r--r-- 2 chyi chyi    355775  6월  9 20:08 st-image-userfs-openstlinux-weston-stm32mp1-20200609082922.testdata.json
-rw-r--r-- 2 chyi chyi 100308992  6월  9 20:08 st-image-userfs-openstlinux-weston-stm32mp1-20200609082922.userfs.ext4
-rw-r--r-- 2 chyi chyi  62478284  6월  9 20:09 st-image-userfs-openstlinux-weston-stm32mp1-20200609082922.userfs.tar.xz
-rw-r--r-- 2 chyi chyi       357  6월  9 20:08 st-image-userfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.ubinize.cfg.ubi
-rw-r--r-- 2 chyi chyi  72351744  6월  9 20:09 st-image-userfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.userfs.ubi
-rw-r--r-- 2 chyi chyi  69582848  6월  9 20:09 st-image-userfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.userfs.ubifs
lrwxrwxrwx 2 chyi chyi        70  6월  9 20:08 st-image-userfs-openstlinux-weston-stm32mp1.ext4 -> st-image-userfs-openstlinux-weston-stm32mp1-20200609082922.userfs.ext4
lrwxrwxrwx 2 chyi chyi        74  6월  9 20:08 st-image-userfs-openstlinux-weston-stm32mp1.manifest -> st-image-userfs-openstlinux-weston-stm32mp1-20200609082922.rootfs.manifest
lrwxrwxrwx 2 chyi chyi        72  6월  9 20:09 st-image-userfs-openstlinux-weston-stm32mp1.tar.xz -> st-image-userfs-openstlinux-weston-stm32mp1-20200609082922.userfs.tar.xz
lrwxrwxrwx 2 chyi chyi        72  6월  9 20:08 st-image-userfs-openstlinux-weston-stm32mp1.testdata.json -> st-image-userfs-openstlinux-weston-stm32mp1-20200609082922.testdata.json
lrwxrwxrwx 2 chyi chyi        80  6월  9 20:09 st-image-userfs-openstlinux-weston-stm32mp1_nand_4_256.ubi -> st-image-userfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.userfs.ubi
lrwxrwxrwx 2 chyi chyi        82  6월  9 20:09 st-image-userfs-openstlinux-weston-stm32mp1_nand_4_256.ubifs -> st-image-userfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.userfs.ubifs
lrwxrwxrwx 2 chyi chyi        85  6월  9 20:09 st-image-userfs-openstlinux-weston-stm32mp1_nand_4_256.ubinize.cfg.ubi -> st-image-userfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.ubinize.cfg.ubi
-rw-r--r-- 2 chyi chyi       274  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922.rootfs.manifest
-rw-r--r-- 2 chyi chyi    356324  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922.testdata.json
-rw-r--r-- 2 chyi chyi  16777216  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922.vendorfs.ext4
-rw-r--r-- 2 chyi chyi   2251344  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922.vendorfs.tar.xz
-rw-r--r-- 2 chyi chyi       367  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.ubinize.cfg.ubi
-rw-r--r-- 2 chyi chyi   7864320  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.vendorfs.ubi
-rw-r--r-- 2 chyi chyi   7110656  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.vendorfs.ubifs
lrwxrwxrwx 2 chyi chyi        74  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1.ext4 -> st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922.vendorfs.ext4
lrwxrwxrwx 2 chyi chyi        76  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1.manifest -> st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922.rootfs.manifest
lrwxrwxrwx 2 chyi chyi        76  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1.tar.xz -> st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922.vendorfs.tar.xz
lrwxrwxrwx 2 chyi chyi        74  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1.testdata.json -> st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922.testdata.json
lrwxrwxrwx 2 chyi chyi        84  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1_nand_4_256.ubi -> st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.vendorfs.ubi
lrwxrwxrwx 2 chyi chyi        86  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1_nand_4_256.ubifs -> st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.vendorfs.ubifs
lrwxrwxrwx 2 chyi chyi        87  6월  9 19:48 st-image-vendorfs-openstlinux-weston-stm32mp1_nand_4_256.ubinize.cfg.ubi -> st-image-vendorfs-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.ubinize.cfg.ubi
-rw-r--r-- 1 chyi chyi    303914  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1-20200609082922-license_content.html
-rw-r--r-- 1 chyi chyi     21707  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1-20200609082922.license
-rw-r--r-- 1 chyi chyi 530441216  6월  9 21:00 st-image-weston-openstlinux-weston-stm32mp1-20200609082922.rootfs.ext4
-rw-r--r-- 1 chyi chyi     79102  6월  9 20:59 st-image-weston-openstlinux-weston-stm32mp1-20200609082922.rootfs.manifest
-rw-r--r-- 1 chyi chyi 103492068  6월  9 21:00 st-image-weston-openstlinux-weston-stm32mp1-20200609082922.rootfs.tar.xz
-rw-r--r-- 1 chyi chyi    359952  6월  9 20:59 st-image-weston-openstlinux-weston-stm32mp1-20200609082922.testdata.json
-rw-r--r-- 1 chyi chyi 216006656  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.rootfs.ubi
-rw-r--r-- 1 chyi chyi 208748544  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.rootfs.ubifs
-rw-r--r-- 1 chyi chyi       357  6월  9 21:00 st-image-weston-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.ubinize.cfg.ubi
-rw-r--r-- 1 chyi chyi 305659904  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1-20200609082922_nand_4_256_multivolume.rootfs.ubi
-rw-r--r-- 1 chyi chyi      1545  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1-20200609082922_nand_4_256_multivolume.ubinize.cfg.ubi
lrwxrwxrwx 1 chyi chyi        79  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1-license_content.html -> st-image-weston-openstlinux-weston-stm32mp1-20200609082922-license_content.html
lrwxrwxrwx 1 chyi chyi        70  6월  9 21:00 st-image-weston-openstlinux-weston-stm32mp1.ext4 -> st-image-weston-openstlinux-weston-stm32mp1-20200609082922.rootfs.ext4
lrwxrwxrwx 1 chyi chyi        66  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1.license -> st-image-weston-openstlinux-weston-stm32mp1-20200609082922.license
lrwxrwxrwx 1 chyi chyi        74  6월  9 20:59 st-image-weston-openstlinux-weston-stm32mp1.manifest -> st-image-weston-openstlinux-weston-stm32mp1-20200609082922.rootfs.manifest
lrwxrwxrwx 1 chyi chyi        72  6월  9 21:00 st-image-weston-openstlinux-weston-stm32mp1.tar.xz -> st-image-weston-openstlinux-weston-stm32mp1-20200609082922.rootfs.tar.xz
lrwxrwxrwx 1 chyi chyi        72  6월  9 20:59 st-image-weston-openstlinux-weston-stm32mp1.testdata.json -> st-image-weston-openstlinux-weston-stm32mp1-20200609082922.testdata.json
lrwxrwxrwx 1 chyi chyi        80  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1_nand_4_256.ubi -> st-image-weston-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.rootfs.ubi
lrwxrwxrwx 1 chyi chyi        82  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1_nand_4_256.ubifs -> st-image-weston-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.rootfs.ubifs
lrwxrwxrwx 1 chyi chyi        85  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1_nand_4_256.ubinize.cfg.ubi -> st-image-weston-openstlinux-weston-stm32mp1-20200609082922_nand_4_256.ubinize.cfg.ubi
lrwxrwxrwx 1 chyi chyi        92  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1_nand_4_256_multivolume.ubi -> st-image-weston-openstlinux-weston-stm32mp1-20200609082922_nand_4_256_multivolume.rootfs.ubi
lrwxrwxrwx 1 chyi chyi        97  6월  9 21:01 st-image-weston-openstlinux-weston-stm32mp1_nand_4_256_multivolume.ubinize.cfg.ubi -> st-image-weston-openstlinux-weston-stm32mp1-20200609082922_nand_4_256_multivolume.ubinize.cfg.ubi
-rw-r--r-- 2 chyi chyi     71751  6월  9 19:21 stm32mp157a-dk1--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        54  6월  9 19:21 stm32mp157a-dk1-stm32mp1.dtb -> stm32mp157a-dk1--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        54  6월  9 19:21 stm32mp157a-dk1.dtb -> stm32mp157a-dk1--4.19-r0.2-stm32mp1-20200609082922.dtb
-rw-r--r-- 2 chyi chyi     73578  6월  9 19:21 stm32mp157c-dk2--4.19-r0.2-stm32mp1-20200609082922.dtb
-rw-r--r-- 2 chyi chyi     73626  6월  9 19:21 stm32mp157c-dk2-a7-examples--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        66  6월  9 19:21 stm32mp157c-dk2-a7-examples-stm32mp1.dtb -> stm32mp157c-dk2-a7-examples--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        66  6월  9 19:21 stm32mp157c-dk2-a7-examples.dtb -> stm32mp157c-dk2-a7-examples--4.19-r0.2-stm32mp1-20200609082922.dtb
-rw-r--r-- 2 chyi chyi     74162  6월  9 19:21 stm32mp157c-dk2-m4-examples--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        66  6월  9 19:21 stm32mp157c-dk2-m4-examples-stm32mp1.dtb -> stm32mp157c-dk2-m4-examples--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        66  6월  9 19:21 stm32mp157c-dk2-m4-examples.dtb -> stm32mp157c-dk2-m4-examples--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        54  6월  9 19:21 stm32mp157c-dk2-stm32mp1.dtb -> stm32mp157c-dk2--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        54  6월  9 19:21 stm32mp157c-dk2.dtb -> stm32mp157c-dk2--4.19-r0.2-stm32mp1-20200609082922.dtb
-rw-r--r-- 2 chyi chyi     68471  6월  9 19:21 stm32mp157c-ed1--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        54  6월  9 19:21 stm32mp157c-ed1-stm32mp1.dtb -> stm32mp157c-ed1--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        54  6월  9 19:21 stm32mp157c-ed1.dtb -> stm32mp157c-ed1--4.19-r0.2-stm32mp1-20200609082922.dtb
-rw-r--r-- 2 chyi chyi     78033  6월  9 19:21 stm32mp157c-ev1--4.19-r0.2-stm32mp1-20200609082922.dtb
-rw-r--r-- 2 chyi chyi     78340  6월  9 19:21 stm32mp157c-ev1-a7-examples--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        66  6월  9 19:21 stm32mp157c-ev1-a7-examples-stm32mp1.dtb -> stm32mp157c-ev1-a7-examples--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        66  6월  9 19:21 stm32mp157c-ev1-a7-examples.dtb -> stm32mp157c-ev1-a7-examples--4.19-r0.2-stm32mp1-20200609082922.dtb
-rw-r--r-- 2 chyi chyi     78673  6월  9 19:21 stm32mp157c-ev1-m4-examples--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        66  6월  9 19:21 stm32mp157c-ev1-m4-examples-stm32mp1.dtb -> stm32mp157c-ev1-m4-examples--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        66  6월  9 19:21 stm32mp157c-ev1-m4-examples.dtb -> stm32mp157c-ev1-m4-examples--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        54  6월  9 19:21 stm32mp157c-ev1-stm32mp1.dtb -> stm32mp157c-ev1--4.19-r0.2-stm32mp1-20200609082922.dtb
lrwxrwxrwx 2 chyi chyi        54  6월  9 19:21 stm32mp157c-ev1.dtb -> stm32mp157c-ev1--4.19-r0.2-stm32mp1-20200609082922.dtb
-rw-r--r-- 1 chyi chyi       300  6월  9 20:00 tee-header_v2-stm32mp157a-dk1-optee.stm32
-rw-r--r-- 1 chyi chyi       300  6월  9 20:00 tee-header_v2-stm32mp157c-dk2-optee.stm32
-rw-r--r-- 1 chyi chyi       300  6월  9 20:00 tee-header_v2-stm32mp157c-ed1-optee.stm32
-rw-r--r-- 1 chyi chyi       300  6월  9 20:00 tee-header_v2-stm32mp157c-ev1-optee.stm32
-rw-r--r-- 1 chyi chyi    147712  6월  9 20:00 tee-pageable_v2-stm32mp157a-dk1-optee.stm32
-rw-r--r-- 1 chyi chyi    147712  6월  9 20:00 tee-pageable_v2-stm32mp157c-dk2-optee.stm32
-rw-r--r-- 1 chyi chyi    147712  6월  9 20:00 tee-pageable_v2-stm32mp157c-ed1-optee.stm32
-rw-r--r-- 1 chyi chyi    151808  6월  9 20:00 tee-pageable_v2-stm32mp157c-ev1-optee.stm32
-rw-r--r-- 1 chyi chyi     84512  6월  9 20:00 tee-pager_v2-stm32mp157a-dk1-optee.stm32
-rw-r--r-- 1 chyi chyi     84512  6월  9 20:00 tee-pager_v2-stm32mp157c-dk2-optee.stm32
-rw-r--r-- 1 chyi chyi     84512  6월  9 20:00 tee-pager_v2-stm32mp157c-ed1-optee.stm32
-rw-r--r-- 1 chyi chyi     84544  6월  9 20:00 tee-pager_v2-stm32mp157c-ev1-optee.stm32
-rw-r--r-- 1 chyi chyi   4048748  6월  9 20:00 tee-stm32mp157a-dk1-optee.elf
-rw-r--r-- 1 chyi chyi   4048748  6월  9 20:00 tee-stm32mp157c-dk2-optee.elf
-rw-r--r-- 1 chyi chyi   4048748  6월  9 20:00 tee-stm32mp157c-ed1-optee.elf
-rw-r--r-- 1 chyi chyi   4052844  6월  9 20:00 tee-stm32mp157c-ev1-optee.elf
-rw-r--r-- 1 chyi chyi    833568  6월  9 20:49 tf-a-bl2-optee.elf
-rw-r--r-- 1 chyi chyi    943132  6월  9 20:49 tf-a-bl2-trusted.elf
-rw-r--r-- 1 chyi chyi    900152  6월  9 20:49 tf-a-bl32-trusted.elf
-rw-r--r-- 1 chyi chyi    224997  6월  9 20:49 tf-a-stm32mp157a-dk1-optee.stm32
-rw-r--r-- 1 chyi chyi    245384  6월  9 20:49 tf-a-stm32mp157a-dk1-trusted.stm32
-rw-r--r-- 1 chyi chyi    224997  6월  9 20:49 tf-a-stm32mp157c-dk2-optee.stm32
-rw-r--r-- 1 chyi chyi    245384  6월  9 20:49 tf-a-stm32mp157c-dk2-trusted.stm32
-rw-r--r-- 1 chyi chyi    224997  6월  9 20:49 tf-a-stm32mp157c-ed1-optee.stm32
-rw-r--r-- 1 chyi chyi    245384  6월  9 20:49 tf-a-stm32mp157c-ed1-trusted.stm32
-rw-r--r-- 1 chyi chyi    224997  6월  9 20:49 tf-a-stm32mp157c-ev1-optee.stm32
-rw-r--r-- 1 chyi chyi    245384  6월  9 20:49 tf-a-stm32mp157c-ev1-trusted.stm32
-rw-r--r-- 1 chyi chyi   2312644  6월  9 20:54 u-boot-spl.elf-stm32mp157a-dk1-basic
-rw-r--r-- 1 chyi chyi   2312644  6월  9 20:54 u-boot-spl.elf-stm32mp157c-dk2-basic
-rw-r--r-- 1 chyi chyi   2312644  6월  9 20:54 u-boot-spl.elf-stm32mp157c-ed1-basic
-rw-r--r-- 1 chyi chyi   2312644  6월  9 20:54 u-boot-spl.elf-stm32mp157c-ev1-basic
-rw-r--r-- 1 chyi chyi    101049  6월  9 20:54 u-boot-spl.stm32-stm32mp157a-dk1-basic
-rw-r--r-- 1 chyi chyi    101113  6월  9 20:54 u-boot-spl.stm32-stm32mp157c-dk2-basic
-rw-r--r-- 1 chyi chyi    102415  6월  9 20:54 u-boot-spl.stm32-stm32mp157c-ed1-basic
-rw-r--r-- 1 chyi chyi    103521  6월  9 20:54 u-boot-spl.stm32-stm32mp157c-ev1-basic
-rw-r--r-- 1 chyi chyi   9028612  6월  9 20:54 u-boot-stm32mp157a-dk1-basic.elf
-rw-r--r-- 1 chyi chyi    812862  6월  9 20:54 u-boot-stm32mp157a-dk1-basic.img
-rw-r--r-- 1 chyi chyi   8755788  6월  9 20:54 u-boot-stm32mp157a-dk1-optee.elf
-rw-r--r-- 1 chyi chyi    808778  6월  9 20:54 u-boot-stm32mp157a-dk1-optee.stm32
-rw-r--r-- 1 chyi chyi   8755684  6월  9 20:54 u-boot-stm32mp157a-dk1-trusted.elf
-rw-r--r-- 1 chyi chyi    808674  6월  9 20:54 u-boot-stm32mp157a-dk1-trusted.stm32
-rw-r--r-- 1 chyi chyi   9028612  6월  9 20:54 u-boot-stm32mp157c-dk2-basic.elf
-rw-r--r-- 1 chyi chyi    814689  6월  9 20:54 u-boot-stm32mp157c-dk2-basic.img
-rw-r--r-- 1 chyi chyi   8755788  6월  9 20:54 u-boot-stm32mp157c-dk2-optee.elf
-rw-r--r-- 1 chyi chyi    810605  6월  9 20:54 u-boot-stm32mp157c-dk2-optee.stm32
-rw-r--r-- 1 chyi chyi   8755684  6월  9 20:54 u-boot-stm32mp157c-dk2-trusted.elf
-rw-r--r-- 1 chyi chyi    810501  6월  9 20:54 u-boot-stm32mp157c-dk2-trusted.stm32
-rw-r--r-- 1 chyi chyi   9028612  6월  9 20:54 u-boot-stm32mp157c-ed1-basic.elf
-rw-r--r-- 1 chyi chyi    809668  6월  9 20:54 u-boot-stm32mp157c-ed1-basic.img
-rw-r--r-- 1 chyi chyi   8755788  6월  9 20:54 u-boot-stm32mp157c-ed1-optee.elf
-rw-r--r-- 1 chyi chyi    805584  6월  9 20:54 u-boot-stm32mp157c-ed1-optee.stm32
-rw-r--r-- 1 chyi chyi   8755684  6월  9 20:54 u-boot-stm32mp157c-ed1-trusted.elf
-rw-r--r-- 1 chyi chyi    805480  6월  9 20:54 u-boot-stm32mp157c-ed1-trusted.stm32
-rw-r--r-- 1 chyi chyi   9028612  6월  9 20:54 u-boot-stm32mp157c-ev1-basic.elf
-rw-r--r-- 1 chyi chyi    819589  6월  9 20:54 u-boot-stm32mp157c-ev1-basic.img
-rw-r--r-- 1 chyi chyi   8755788  6월  9 20:54 u-boot-stm32mp157c-ev1-optee.elf
-rw-r--r-- 1 chyi chyi    815505  6월  9 20:54 u-boot-stm32mp157c-ev1-optee.stm32
-rw-r--r-- 1 chyi chyi   8755684  6월  9 20:54 u-boot-stm32mp157c-ev1-trusted.elf
-rw-r--r-- 1 chyi chyi    815401  6월  9 20:54 u-boot-stm32mp157c-ev1-trusted.stm32
lrwxrwxrwx 2 chyi chyi        45  6월  9 19:21 uImage -> uImage--4.19-r0.2-stm32mp1-20200609082922.bin
-rw-r--r-- 2 chyi chyi   6722112  6월  9 19:21 uImage--4.19-r0.2-stm32mp1-20200609082922.bin
lrwxrwxrwx 2 chyi chyi        45  6월  9 19:21 uImage-stm32mp1.bin -> uImage--4.19-r0.2-stm32mp1-20200609082922.bin
lrwxrwxrwx 2 chyi chyi        46  6월  9 19:21 vmlinux -> vmlinux--4.19-r0.2-stm32mp1-20200609082922.bin
-rw-r--r-- 2 chyi chyi 210023156  6월  9 19:21 vmlinux--4.19-r0.2-stm32mp1-20200609082922.bin
lrwxrwxrwx 2 chyi chyi        46  6월  9 19:21 vmlinux-stm32mp1.bin -> vmlinux--4.19-r0.2-stm32mp1-20200609082922.bin
lrwxrwxrwx 2 chyi chyi        45  6월  9 19:21 zImage -> zImage--4.19-r0.2-stm32mp1-20200609082922.bin
-rw-r--r-- 2 chyi chyi   6722048  6월  9 19:21 zImage--4.19-r0.2-stm32mp1-20200609082922.bin
lrwxrwxrwx 2 chyi chyi        45  6월  9 19:21 zImage-stm32mp1.bin -> zImage--4.19-r0.2-stm32mp1-20200609082922.bin

오 이런 ~ 너무나도 많은 결과 파일이 생긴다. 이번 posting에서는 Yocto 관련 내용은 요 정도만 언급하고, 나머지는 부분은 모두 Buildroot 환경에서 확인할 생각이다.

b) Buildroot를 통한 이미지 생성
다행히도 최신 buildroot source에는 DK2 board가 이미 porting되어 있다. 따라서 아래와 같은 간단한 방법으로 build가 가능하다.

git clone git://git.buildroot.net/buildroot
$ cd buildroot

$ make stm32mp157c_dk2_defconfig

[그림 3.4] stm32mp157c_dk2_defconfig 파일

$ make menuconfig

[그림 3.5] Bootloaders 메뉴 - u-boot SPL(FSBL), u-boot(SSBL)

$ make
   => buildroot는 상대적으로 결과물이 매우 단출하다.
   => 특이한 점은 u-boot이 SPL(u-boot-spl.stm32)과 u-boot.img로 2개가 만들어 진다는 점이다.

[그림 3.6] buildroot build 결과 파일

Buildroot는 file system image를 build하고 나면, support/scripts/genimage.sh 파일을 통해 최종 sdcard.img 파일을 생성하게 된다(이때, genimage.cfg 파일이 사용됨).

<configs/stm32mp157c_dk2_defconfig>
     BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh"
     BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/stmicroelectronics/common/stm32mp157/genimage.cfg"

[그림 3.7] board/stmicroelectronics/common/stm32mp157/genimage.cfg 파일

sdcard.img 생성 및 부팅과 관련해서는 몇가지 집고 넘어가야할 내용이 있는데, 이를 간단히 정리해 보면 다음과 같다.

1) sdcard.img는 GPT partition table 스펙에 맞는 파티션 정보를 갖도록 만들어진다.


2) 위의 그림 3.7에서 linux kernel 및 dtb 파일은 별도의 파티션이 아니라 rootfs 파티션(정확히는 /boot 디렉토리)에 포함되어 있다.

3)  rootfs 파티션에는 bootable="yes" 부분이 있는데, 이는 u-boot으로 하여금 bootable로 표시된 파티션을 찾은 후, 다시  (해당 파일 시스템에서) extlinux.conf(예: /boot/extlinux/extlinux.conf) 파일을 찾아내어 이를 토대로 부팅하도록 도와 준다. 즉, u-boot이 kernel 파티션이 없는 상황에서 어디에 kernel이 위치하고, kernel image 명이 무엇인지를 확인하기 위해 extlinux.conf 파일이 활용된다는 뜻이다.

4) extlinux.conf 파일 내용 중, root=/dev/mmcblk0p4 rootwait 스트링은 u-boot이 kernel에 argument로 넘기는 내용이다. kernel은 이 내용을 보고 rootfs가 어느 파티션에 위치하는지를 알게 된다.

[그림 3.8] board/stmicroelectronics/stm32mp157c-dk2/overlay/boot/extlinux/extlinux.conf 파일


앞서 얻은 결과를 토대로, 전체적인 부팅 순서를 정리해 보면 대략 아래와 같다.

Boot ROM code -> u-boot SPL(first stage bootloader) -> u-boot(second stage bootloader) -> linux kernel ...
참고: 편의 상 Coprocessor(Cortex-M4)에 설치된 firmware를 구동시키는 부분은 내용에서 제외하였다. 정확치는 않지만 u-boot or linux kernel에서 이를 수행하는 듯 보인다.

1) STM32MP157 ROM code는 GPT partition 중 fsbl로 시작하는 파티션을 찾은 후, 그 내용을 내부 system memory에 loading 후 실행한다(=> first stage bootloader).

2) First stage bootloader(u-boot SPL)는 sdcard의 3번째 파티션의 내용(second stage bootloader)을 loading하도록 hard coding되어 있다. 따라서 external RAM을 초기화한 후, second stage bootloader(u-boot)를 RAM에 loading후, 이를 실행시킨다.

3) Second stage bootloader는 sdcard 파티션 중 bootable로 표시된 녀석을 찾은 후, 다시 /boot/extlinux/extlinux.conf 파일을 찾아 이 내용을 참조하여 kernel과 dtb file을 RAM에 loading 시킨다. 이후 kernel을 실행하면서, argument로 "root=/dev/mmcblk0p4 rootwait"를 전달한다.

4) Kernel은 부팅 후반부에 root=/dev/mmcblk0p4 내용을 참조하여 root  file system을 mount하게 되는데, rootfs mount가 진행되고 나면, kernel은 user space process(예: init)를 실행시키게 된다.

5) 제일 처음 실행되는 /sbin/init process는 busybox에 포함된 녀석(buildroot 기준)이며, 몇가지 service를 시작시킨 후, login prompt를 띄우게 된다.

USB OTG를 통한 firmware writing이 현재로써는 불가(전류 문제)하니, microSD를 desktop PC에 붙여 image writing을 시도해 보도록 하자. 이와 관련해서는 아래 위치에 있는 readme.txt 파일을 참고할 필요가 있다.

board/stmicroelectronics/stm32mp157c-dk2/readme.txt

<Desktop PC>
$ sudo dd if=./output/images/sdcard.img of=/dev/sdb
247694+0 레코드 들어옴
247694+0 레코드 나감
126819328 bytes (127 MB, 121 MiB) copied, 26.464 s, 4.8 MB/s

microSD를 다시 board에 장착 후, 부팅을 시도해 보니, u-boot SPL(FSBL) => u-boot(SSBL)까지 구동되고 멈춰 버린다.

[그림 3.9] sdcard.img 설치 후, 부팅 모습(u-boot SL => u-boot)

오, 이런... 5V/3A 없으면 부팅도 안되는 군 ... s**t, f**k 👿

(주문한지 2틀만에) 5V/3A USB-C type power adapter가 도착했다(정말 우리는 배달의 민족^^). 전원을 넣어 보니, 역시 정상적으로 부팅이 된다. 🙆

[그림 3.10] sdcard.img 설치 후, 정상 부팅 모습(u-boot SL => u-boot => kernel)


[그림 3.11] 정상 부팅 모습 - LCD에 부팅 message 출력


4. Qt application 개발환경 설정 및 테스트해 보기
이 장에서는 DK2 보드에서 Qt5 application을 돌려 보기 위해 필요한 환경 설정 부분과 몇가지 Qt app을 실행하는 내용을 소개해 보고자 한다.

To be continued...



8. References
[1] https://www.st.com/en/embedded-software/stm32cubemp1.html


Slowboot

댓글 3개: