1419b0af8Sopenharmony_ci# Tzdriver driver 2419b0af8Sopenharmony_ci 3419b0af8Sopenharmony_ci## Introduction 4419b0af8Sopenharmony_ci 5419b0af8Sopenharmony_ciTzdriver is a kernel driver deployed on the REE side, supporting communication between REE and TEE. Tzdriver processes commands from Tee Client and sends instructions to switch from REE to TEE. Tzdriver supports data sharing between REE and TEE by managing shared memory. 6419b0af8Sopenharmony_ci 7419b0af8Sopenharmony_ciTzdriver includes the following main modules: 8419b0af8Sopenharmony_ci 9419b0af8Sopenharmony_cismc: Send smc instructions to switch the CPU from the REE side to the TEE side for operation. 10419b0af8Sopenharmony_ci 11419b0af8Sopenharmony_cisession_manager: Manage communication sessions between REE and TEE. 12419b0af8Sopenharmony_ci 13419b0af8Sopenharmony_cimailbox:Data is shared between REE and TEE through the mailbox. 14419b0af8Sopenharmony_ci 15419b0af8Sopenharmony_cicmd_monitor:Monitor the operation of SMC instructions and provides a timeout detection mechanism. 16419b0af8Sopenharmony_ci 17419b0af8Sopenharmony_citzdebug:Create debugfs debugging nodes to facilitate developers in debugging TEE functionality 18419b0af8Sopenharmony_ci 19419b0af8Sopenharmony_citlogger:TEE log driver module, supporting TEE log recording and printing. 20419b0af8Sopenharmony_ci 21419b0af8Sopenharmony_ciFigure 1: Tzdriver architecture diagram 22419b0af8Sopenharmony_ci 23419b0af8Sopenharmony_ci 24419b0af8Sopenharmony_ci 25419b0af8Sopenharmony_ci## Directory 26419b0af8Sopenharmony_ci 27419b0af8Sopenharmony_ci``` 28419b0af8Sopenharmony_ci/kernel/linux/common_modules/tzdriver 29419b0af8Sopenharmony_ci├── core 30419b0af8Sopenharmony_ci│ ├── cmdmonitor.c # SMC instruction execution monitoring 31419b0af8Sopenharmony_ci ├── gp_ops.c # GP TEE specification processing logic 32419b0af8Sopenharmony_ci ├── mailbox_mempool.c # REE and TEE shared memory management 33419b0af8Sopenharmony_ci ├── session_manager.c # Session management for CA access to TA 34419b0af8Sopenharmony_ci ├── smc_smp.c # Send SMC command to switch to TEE 35419b0af8Sopenharmony_ci ├── tzdebug.c # Debugging module 36419b0af8Sopenharmony_ci├── tlogger # TEE log driver 37419b0af8Sopenharmony_ci``` 38419b0af8Sopenharmony_ci 39419b0af8Sopenharmony_ci## Configuration Option 40419b0af8Sopenharmony_ci 41419b0af8Sopenharmony_ciIf you want to enable the Tzdriver driver, you need to modify the defconfig file of the device in the Linux kernel code repository and add configuration options for Tzdriver: 42419b0af8Sopenharmony_ci 43419b0af8Sopenharmony_ci``` 44419b0af8Sopenharmony_ci# 45419b0af8Sopenharmony_ci# TEEOS 46419b0af8Sopenharmony_ci# 47419b0af8Sopenharmony_ciCONFIG_TZDRIVER=y 48419b0af8Sopenharmony_ciCONFIG_CPU_AFF_NR=1 49419b0af8Sopenharmony_ciCONFIG_KERNEL_CLIENT=y 50419b0af8Sopenharmony_ciCONFIG_TEELOG=y 51419b0af8Sopenharmony_ciCONFIG_PAGES_MEM=y 52419b0af8Sopenharmony_ciCONFIG_THIRDPARTY_COMPATIBLE=y 53419b0af8Sopenharmony_ci``` 54419b0af8Sopenharmony_ci 55419b0af8Sopenharmony_ciThe meanings of each option are shown in the table below: 56419b0af8Sopenharmony_ci 57419b0af8Sopenharmony_ci**Table 1** Configuration Options Description 58419b0af8Sopenharmony_ci 59419b0af8Sopenharmony_ci| Parameters | Description | 60419b0af8Sopenharmony_ci| ---------------------------- | ------------------------------------------------------------ | 61419b0af8Sopenharmony_ci| CONFIG_TZDRIVER | Tzdriver module switch. | 62419b0af8Sopenharmony_ci| CONFIG_CPU_AFF_NR | CA binding core function, non-zero values represent restrictions on CPUID less than CONFIG_ CPU_ AFF_ NR's CPU can enter TEE, where 0 represents unlimited. Currently, Tzdriver only supports running on 0 cores, so the value is 1. | 63419b0af8Sopenharmony_ci| CONFIG_KERNEL_CLIENT | Support the kernel CA option. | 64419b0af8Sopenharmony_ci| CONFIG_TEELOG | TEE log switch, it is recommended to enable. | 65419b0af8Sopenharmony_ci| CONFIG_PAGES_MEM | TEE log memory management, it is recommended to enable. | 66419b0af8Sopenharmony_ci| CONFIG_THIRDPARTY_COMPATIBLE | Used for compatibility with third-party optee, such as the RK3568 chip, which requires this option to be enabled. | 67419b0af8Sopenharmony_ci 68419b0af8Sopenharmony_ci## Compile Command 69419b0af8Sopenharmony_ci 70419b0af8Sopenharmony_ciTzdriver is compiled together with the kernel. Taking the rk3568 chip as an example, the "boot_linux.img" can be compiled separately. The compilation command is as follows 71419b0af8Sopenharmony_ci 72419b0af8Sopenharmony_ci``` 73419b0af8Sopenharmony_ci./build.sh --product-name rk3568 --ccache --build-target kernel --gn-args linux_kernel_version=\"linux-5.10\" 74419b0af8Sopenharmony_ci``` 75419b0af8Sopenharmony_ci 76419b0af8Sopenharmony_ci## Related code repository 77419b0af8Sopenharmony_ci 78419b0af8Sopenharmony_ci[tee_client](https://gitee.com/openharmony/tee_tee_client) 79