1. ARM Trusted Firmware-A

 

https://github.com/ARM-software/arm-trusted-firmware

 

ARM-software/arm-trusted-firmware

Read-only mirror of Trusted Firmware-A. Contribute to ARM-software/arm-trusted-firmware development by creating an account on GitHub.

github.com

Secure Monitor(EL3) 역할을 수행하며 ARM Trusted Firmware-A(BL31)를 통해 BL32 OPTEE OS를 구동함. 

아래의 세부 기능을 포함.

 

각 기능들은 SMC Calling Convention에 의거하여 구동되며, OPTEE로의 SMC 전달은 Runtime Services Framework - Secure-EL1 Payload Dispatcher(SPD) service를 통해 처리. (Standard service calls - ex) PSCI, Secure-EL1 Payload Dispatcher service, CPU implementation service등)

 

ARM Trusted Firmware Design에 대한 문서는 원문 참고.

원문 : https://chromium.googlesource.com/chromiumos/third_party/arm-trusted-firmware/+/factory-strago-7458.B/docs/firmware-design.md

 

ARM Trusted Firmware Design

ARM Trusted Firmware Design Contents : IntroductionCold bootEL3 runtime services frameworkPower State Coordination InterfaceSecure-EL1 Payloads and DispatchersCrash Reporting in BL3-1Guidelines for Reset HandlersCPU specific operations frameworkMemory layo

chromium.googlesource.com

부팅은 5단계에 의해 진행 - AArch64 case.

  • Boot Loader stage 1 (BL1) AP Trusted ROM
  • Boot Loader stage 2 (BL2) Trusted Boot Firmware
  • Boot Loader stage 3-1 (BL3-1) EL3 Runtime Firmware
  • Boot Loader stage 3-2 (BL3-2) Secure-EL1 Payload (optional)
  • Boot Loader stage 3-3 (BL3-3) Non-trusted Firmware

 

2. SMC Calling Convention

 

ARM에서는 SMC Call / HVC Call에 대한 규약을 미리 정해두었음. 

 

원문 : http://infocenter.arm.com/help/topic/com.arm.doc.den0028b/ARM_DEN0028B_SMC_Calling_Convention.pdf

불러오는 중입니다...

여기에 따라 Function identifier 값, Argument Passing 방법을 수행.

 

SMC는 2가지 종류로 구분 - Fast SMC, Standard SMC or yield SMC /

Atomic operation을 제공하느냐 여부로 구분되는데, 이는 결국 Interrupt masking을 통해 결정.

 

 

'OPTEE with Rasberry Pi 3B' 카테고리의 다른 글

SMC Call Sequence  (0) 2019.09.30
OPTEE Log Level  (0) 2019.09.18
NFS boot  (0) 2019.09.17
Rasberry Pi 3B vs 3B+  (0) 2019.09.04
OP-TEE Build for Rasberry Pi 3B  (0) 2019.09.03

1. SMC call in normal world.

 

SMC와 HVC(Hypervisor call) 가 정의되고 Export 됨.

 

1) smc, hvc call function 정의

 

2) export function

 

3) Wrapping function

 

4) 3번의 함수들을 OPTEE에서 함수로 제공

 

 

2. SMC Call in secure world - OPTEE

 

1) Init 과정에서 SMC Handler를 등록.

(중략)

미리 선언한 핸들러를 각 Thread에 mapping 시킴.

 

 

 

2) Vector table 에 등록되어있으므로, SMC 발생시 해당 함수가 실행.

 

초기화 과정에서 thread_std_smc_handler_ptr이 tee_entry_std이므로 아래 함수가 실행.

 

 

'OPTEE with Rasberry Pi 3B' 카테고리의 다른 글

ARM Trusted Firmware-A  (0) 2019.10.10
OPTEE Log Level  (0) 2019.09.18
NFS boot  (0) 2019.09.17
Rasberry Pi 3B vs 3B+  (0) 2019.09.04
OP-TEE Build for Rasberry Pi 3B  (0) 2019.09.03

1. OPTEE Log

 

1) 5가지의 Log 가 존재

TEE Core (OPTEE OS) : CFG_TEE_CORE_LOG_LEVEL
TA(Trusted Application) : CFG_TEE_TA_LOG_LEVEL
Client : CFG_TEE_CLIENT_LOG_LEVEL
Supplicant : CFG_TEE_SUPP_LOG_LEVEL
ARM-TF(Trusted Firmware) :  LOG_LEVEL

 

2) 각 레벨은 다음과 같이 구분 (ARM-TF 제외)

0 : None
1 : Error
2 : Error + Warning
3 : Error + Warning + Debug
4 : Error + Warning + Debug + Flow

ARM-TF : 10 ~ 50(10 단위, ERROR, NOTICE, WARINING, INFO, VERBOSE)

 

 

2. 설정 우선 순위 (ARM-TF 제외)

 

1. Make arguments ('make CFG_FOO=bar...')
2. The file specified by $(CFG_OPTEE_CONFIG) (if defined)
3. The environment ('CFG_FOO=bar make...')
4. The platform-specific configuration file: core/arch/arm32/plat-*/conf.mk
5. <optee-project>/optee_os/mk/config.mk
6. Subsystem-specific makefiles (*/sub.mk)

 

 

3. Make argument 제외한 실제 수정 위치

 

1) CFG_TEE_CORE_LOG_LEVEL : <optee-project>/build/common.mk
  - Makefile에서 최초로 참조
2) CFG_TEE_TA_LOG_LEVEL : <optee-project>/optee_os/mk/config.mk
3) CFG_TEE_CLIENT_LOG_LEVEL, CFG_TEE_SUPP_LOG_LEVEL : <optee-project>/optee_client/config.mk
4) ARM-TF Log level :
   (1) <optee-project>/build/Makefile
   (2) <optee-project>/arm-trusted-firmware/plat/rpi3/platform.mk => RPI3_RUNTIME_UART를 -1이 아닌 값으로 변경.

  # UART to use at runtime. -1 means the runtime UART is disabled.
  # Any other value means the default UART will be used.
  RPI3_RUNTIME_UART := -1

 

 

'OPTEE with Rasberry Pi 3B' 카테고리의 다른 글

ARM Trusted Firmware-A  (0) 2019.10.10
SMC Call Sequence  (0) 2019.09.30
NFS boot  (0) 2019.09.17
Rasberry Pi 3B vs 3B+  (0) 2019.09.04
OP-TEE Build for Rasberry Pi 3B  (0) 2019.09.03

1. 공유기 or Hub 환경 필요

 

Rasberrypi와 PC가 통신하기 위해 공유기 혹은 Hub 환경 구축 필요.

같은 Local domain에 속해야 통신 가능

 

 

2. Virtual box 세팅

 

Rasberrypi <-> PC <-> Host OS on VirtualBox의 경우, Virtual Box에 Network 세팅 추가 필요.

 

NAT : Host OS <-> Internet

Host Only Adapter : PC <-> Host OS on Virtual Box

Bridged Adapter : Host OS <-> Rasberrypi

 

Bridged Adapter 설정시 Host OS에서 추가된 Ethernet interface에 공유기 Domain의 IP 주소가 할당되므로 해당 주소 이용 가능.

 

 

3. Host OS 설정

 

1) 고정 IP 할당을 위해 /etc/network/interface 설정에 아래 내용 필요. (enp0s8이 Bridged Adapter인 경우)

auto enp0s8 
iface enp0s8 inet static 
address 192.168.0.50 
netmask 255.255.255.0 
network 192.168.0.0 
broadcast 192.168.0.255 
gateway 192.168.0.1

 

2) NFS 서버 설정 (NFS 디렉토리가 /home/dark/nfs/rpi일 경우)

$ sudo apt-get install nfs-kernel-server 
$ sudo vi /etc/exports
 -> /home/dark/nfs/rpi 192.168.0.*(rw,sync,no_root_squash,no_subtree_check)

 

3) NFS 디렉토리 설정

원하는 디렉토리 경로 지정 후 Root FS 설치. 주의할 점은 반드시 디렉토리가 Root 권한이어야 함. 아닌 경우 Mount 실패

$ mkdir -p /home/dark/nfs/rpi
$ sudo chown root /home/dark/nfs/rpi

 

 

4. U-boot 세팅

 

U-boot에 환경 변수 주소를 세팅해줘야 함. U-boot console mode에서

setenv gateway '192.168.0.1'
setenv nfsserverip '192.168.0.50'
setenv nfspath '/home/dark/nfs/rpi'
saveenv
run nfsboot

자동으로 nfs booting을 시키고 싶으면 bootcmd를 mmcboot에서 nfsboot로 변경
setenv bootcmd 'run nfsboot'
saveenv

 

 

5. NFS 부팅시 OP-TEE Permission 이슈

 

SD card로 부팅시에는 문제없으나 NFS 부팅시에는 3.4.0에서는 오류 발생

Starting logging: OK 
Initializing random number generator... done. 
Setting permissions on /dev/tee*... OK 
Starting tee-supplicant... ERR [97] TSUP:main:684: error tee_supp_fs_init 
FAIL
Starting network: ip: RTNETLINK answers: File exists 
FAIL

Network는 이미 설정된거라 문제 없으나 tee_supp_fs_init이 실패하면 op-tee가 정상 동작되지 않음

이와 관련하여 패치가 진행되었음 - https://github.com/OP-TEE/build/pull/341/commits/345ea6b9980a04972f5f057d177d44331c3111d3

 

Rpi3 nfs fixes by jbech-linaro · Pull Request #341 · OP-TEE/build

Some general fixes and one of them: Fixes: OP-TEE/optee_os#2773

github.com

해당 Patch는 3.4.0에는 미반영되어 있으나, 3.6.0에는 반영되어 있는 것을 확인함.

따라서 최신 버전으로 개발 진행 예정.

 

 

6. U-boot env 수정

 

4번 항목의 U-boot 설정은 rootfs.cpio 를 이용해 boot 업데이트시 매번 파일이 갱신되므로 env 파일을 업데이트해야함.

u-boot.env는 mkenvimage를 통해 encoding되는데, 3.4.0에서는 env에 대한 dependency가 제대로 설정되어 있지 않아 make u-boot-env가 동작하지 않아 수동으로 빌드해줘야 함.

3.6.0에서 수행을 권장.

$ vi <optee-project>/build/rpi3/firmware/uboot.env.txt 

원하는 대로 수정한 후

$ cd <optee-project>/build
$ make u-boot-env-clean
$ make u-boot-env

'OPTEE with Rasberry Pi 3B' 카테고리의 다른 글

ARM Trusted Firmware-A  (0) 2019.10.10
SMC Call Sequence  (0) 2019.09.30
OPTEE Log Level  (0) 2019.09.18
Rasberry Pi 3B vs 3B+  (0) 2019.09.04
OP-TEE Build for Rasberry Pi 3B  (0) 2019.09.03

1. OP-TEE에서는 Rasberry Pi 3B만 Officially 지원

 

HardwareSupported - https://optee.readthedocs.io/building/devices/rpi3.html#what-versions-of-raspberry-pi-will-work

Raspberry Pi 1 Model A No
Raspberry Pi 1 Model B No
Raspberry Pi 1+ Model A No
Raspberry Pi 1+ Model B No
Raspberry Pi 2 Model B No
Raspberry Pi 2 Model B v1.2 No
Raspberry Pi 3+ Model A No
Raspberry Pi 3 Model B Yes
Raspberry Pi 3+ Model B No
Zero - all versions No
Compute module - all versions No

 

2. Rasberry Pi 3B vs 3B+ specfications

https://www.androidcentral.com/raspberry-pi-3-model-b-vs-3-b

 

Raspberry Pi 3 Model B vs. 3 B+: Which should you buy?

Changes to the network interface and a small processor revision sound minor but could make a difference for your project.

www.androidcentral.com

Ethernet과 Wi-Fi, PoE 이외에는 동일하나, OP-TEE Kernel에서는 WiFi 포팅은 해놓지 않았고, PoE는 전원 연결부를 무시하면 Ethernet과 같기 때문에 Core clock과 Ethernet speed 이외에는 동일.

 

3. OP-TEE 포팅 

OP-TEE에서는 Rasberrypi 3B만 지원하며 3B+는 지원하지 않음.

bootcode.bin, start.elf, fixup.dat는 Source가 오픈되어 있지 않으며 Broadcom에서 Binary Type으로 전달.

3B+는 2018년 이후 발행된 bootcode.bin과 Kernel을 써야 인식이 되는데, OP-TEE에서 포팅한 바이너리는 그 이전 버전으로 그냥 3B+에 얹으면 부팅되지 않음.

 

3B+용 dtb도 별도 제공되는데, Rasberrian에서 제공하는 bootcode.bin과 start.elf가 아닌 git 상의 최신 바이너리로 시도시에도 동작하지 않아, 3B+은 별도의 포팅이 필요하다는 결론에 도달.

 

3B+는 포기하고 3B로 개발 진행.

 

P.S : OPTEE 3.4.0 일때는 미동작하나, 3.6.0에서는 3B+ dtb가 들어와있는 것을 확인. 추후 동작 여부 확인 필요.

'OPTEE with Rasberry Pi 3B' 카테고리의 다른 글

ARM Trusted Firmware-A  (0) 2019.10.10
SMC Call Sequence  (0) 2019.09.30
OPTEE Log Level  (0) 2019.09.18
NFS boot  (0) 2019.09.17
OP-TEE Build for Rasberry Pi 3B  (0) 2019.09.03

1. Ubuntu apt-get lock error 발생시 조치

$ sudo rm /var/lib/apt/lists/lock

$ sudo rm /var/cache/apt/archives/lock

$ sudo rm /var/lib/dpkg/lock

$ sudo apt-get clean

$ sudo apt-get update

$ sudo dpkg --configure -a

   

 

2. OPTEE Setup

- 전체 과정은 https://optee.readthedocs.io/en/latest/building/index.html 참고(기존 링크 변경됨.)

 

 

3. Prerequire package installation

https://optee.readthedocs.io/building/prerequisites.html#prerequisites

 

$ sudo apt-get install android-tools-adb android-tools-fastboot autoconf \
        automake bc bison build-essential ccache cscope curl device-tree-compiler \
        expect flex ftp-upload gdisk iasl libattr1-dev libc6:i386 libcap-dev \
        libfdt-dev libftdi-dev libglib2.0-dev libhidapi-dev libncurses5-dev \
        libpixman-1-dev libssl-dev libstdc++6:i386 libtool libz1:i386 make \
        mtools netcat python-crypto python3-pyelftools python-serial \
        unzip uuid-dev xdg-utils xterm xz-utils zlib1g-dev

 

 

4. Repo setup

$ sudo apt-get install repo

 

 

5. Check xml file for rasberry pi

https://github.com/OP-TEE/manifest

 

 

 

6. Get source from Git server

TARGET : rpi3.xml

BRANCH : OPTEE v.3.0 이하는 rpi3_stable.xml, 3.1 이상은 3.x.0 형식

$ mkdir -p  <optee-project>
$ cd  <optee-project>
$ repo init -u https://github.com/OP-TEE/manifest.git -m ${TARGET}.xml [-b ${BRANCH}]

   => repo init -u https://github.com/OP-TEE/manifest.git -m rpi3.xml -b 3.6.0
$ repo sync -j4 --no-clone-bundle

만약 git config를 해주지 않았다면 git config user.name과 user.email 선행 설정 필요.

 

 

7. Toolchain build

$ cd <optee-project>/build
$ make -j2 toolchains

 

 

8. Source build

$ make -j2 

 

 

9. Build 전 수정사항

1) UART enable

RPI3의 경우 BT와 UART0, Mini UART를 할당해서 BT가 Enable되면 UART로 로그가 나오지 않음.

이를 위해 아래 내용 수정

$ vi <optee-project>/build/rpi3/firmware/config.txt

맨 마지막 항에 아래 구문 추가

dtoverlay=pi3-disable-bt 

 

2) check-bin-arch 수정

최초 빌드에는 괜찮은데, 한번 빌드 된 뒤에 Rebuild 수행시 binary architecture checking 과정에서 bootcode.bin, start.elf 등 Broadcom release binary에 대해 64bit 용이 아니라고 에러가 발생.

부팅시 32Bit으로 부팅하고, Trusted firmware와 U boot이 올라가면서 64bit으로 변경해주기 때문에 해당 과정은 불필요.

따라서 주석 처리함.

$ vi <optee-project>/buildroot/support/scripts/check-bin-arch

 

    # Architecture is correct
    if test "${arch}" = "${arch_name}" ; then
        continue
    fi  

    printf 'ERROR: architecture for "%s" is "%s", should be "%s"\n' \
           "${f}" "${arch}" "${arch_name}"
    continue
#exitcode=1
done < <( sed -r -e "/^${package},\.(.+)$/!d; s//\1/;" ${pkg_list} )

 

'OPTEE with Rasberry Pi 3B' 카테고리의 다른 글

ARM Trusted Firmware-A  (0) 2019.10.10
SMC Call Sequence  (0) 2019.09.30
OPTEE Log Level  (0) 2019.09.18
NFS boot  (0) 2019.09.17
Rasberry Pi 3B vs 3B+  (0) 2019.09.04

+ Recent posts