Kickpi-Book
  • KICKPI Document
  • K5/K5C(A133)
    • A133中文文档
      • 01-主板介绍
        • 01-KICKPI-K5硬件介绍
        • 02-KICKPI-K5C硬件介绍
      • 02-入门必读
        • 01-网盘目录说明
        • 02-快速使用
        • 03-功能测试
        • 04-扩展引脚
      • 03-镜像烧录
        • 01-获取镜像文件
        • 02-SD卡烧录
        • 02-USB线烧录
      • 04-SDK编译
        • 01-编译环境搭建
        • 02-LINUX_SDK源码编译
        • 03-ANDROID_SDK源码编译
      • 05-外设驱动
        • LCD功能调试
        • LRADC按键配置
      • 06-ANDROID系统定制
        • 01-Android常用系统定制
      • 07-LINUX系统定制
        • 02-Linux常用系统定制
      • 08-进阶
        • K5C主板供电
        • 安卓休眠唤醒
        • 13-硬件工厂测试
    • en
      • 01-Development_board_Introduction
        • 01-KICKPI-K5_Hardware_Introduction
        • 02-KICKPI-K5C_Hardware_Introduction
      • 02-Getting_Started_Guide
        • 01-KICKPI_Cloud_Storage_Introduction
        • 02-Quick_Start_Guide
        • 03-Functional_Testing
        • 04-Expansion_Pins_Testing
      • 03-Image_Flashing_Guide
        • 01-How_to_Get_Image_File
        • 02-SD Card Burning
        • 03-USB_Cable_Flashing
      • 04-SDK_Compilation_Guide
        • 01-Compilation_Environment_Setup
        • 02-Linux_SDK_Compilation
        • 03-Android_SDK_Compilation
      • 06-Android_System_Customization
        • 01-Android_Common_System_Customization
      • 07-Linux_System_Customization
        • ADB_Tutorial
  • K2B/K2C(H618)
    • en
      • 01-Development_board_Introduction
        • 01-KICKPI-K2B_Hardware_Introduction
        • 02-KICKPI-K2B_Hardware_Introduction
      • 02-Getting_Started_Guide
        • 01-KICKPI_Cloud_Storage_Introduction
        • 02-Quick_Start_Guide
        • 03-Functional_Testing
        • 04-Expansion_Pins_Testing
      • 03-Image_Flashing_Guide
        • 01-SD_Card_Flashing
        • 02-USB_Cable_Flashing
      • 04-SDK_Compilation_Guide
        • 01-Compilation_Environment_Setup
        • 02-Linux_SDK_Compilation
        • 03-Android_SDK_Compilation
      • 05-Drivers_Development
        • RTC
      • 06-Android_System_Customization
        • 01-Android_Common_System_Customization
      • 07-Linux_System_Customization
        • 01-Linux_Common_System_Customization
      • 08-Advanced_Topics
        • Hardware_Factory_Testing
        • Keybox
    • zh
      • 01-主板介绍
        • 01-KICKPI-K2B硬件介绍
        • 02-KICKPI-K2C硬件介绍
      • 02-入门必读
        • 01-网盘目录说明
        • 02-快速使用
        • 03-功能测试
        • 04-扩展引脚
      • 03-镜像烧录
        • 01-SD卡烧录
        • 02-USB线烧录
      • 04-SDK编译
        • 01-编译环境搭建
        • 02-LINUX_SDK源码编译
        • 2. Android SDK编译
      • 05-外设驱动
        • RTC
      • 06-Android系统定制
        • Android常用系统定制
      • 07-Linux系统定制
        • 01-Linux常用系统定制
        • 02-Linux_QT开发环境搭建
      • 08-进阶
        • Keybox
        • Secure Boot
        • Windows_QT开发环境搭建
        • 扩展引脚功能定制
        • 硬件工厂测试
  • K1/K1B/K3/K8(RK356x-RK3588)
    • en
      • 01-Development_board_Introduction
        • 01-RK_Chip_Comparison_Introduction
        • 02-KICKPI-K1_Hardware_Introduction
        • 03-KICKPI-K1B_Hardware_Introduction
        • 04-KICKPI-K3_Hardware_Introduction
        • 05-KICKPI-K8_Hardware_Introduction
      • 02-Getting_Started_Guide
        • 01-Cloud_Storage_Directory_Description
        • 02-K1-Quick_Start_Guide
        • 02-K1B-Quick_Start_Guide
        • 02-K3-Quick_Start_Guide
        • 02-K8-Quick_Start_Guide
        • 03-Functional_Testing
        • 04-Expansion_Pins
      • 03-Image_Flashing_Guide
        • 01-USB_Cable_Flashing
      • 04-SDK_Compilation_Guide
        • 01-Compilation_Environment_Setup
        • 02-LINUX_SDK_Compilation
        • 03-ANDROID_SDK_Compilation
      • 05-Drivers_Development
        • GPIO
        • Kernel
        • LCD
        • PWM
        • RTC
      • 06-Android_System_Customization
        • 01-Common_Android_System_Customizations
        • 01-Common_Android_System_Customizations
      • 07-Linux_System_Customization
        • 01-Common_Linux_System_Customization
        • 02-Installing_VNC_on_Linux
        • 03-Linux_Docker
        • 04-Linux_QT_Environment_Setup
        • 05-Linux_NPU_YOLOV5S_object_detection
      • 08-Advanced_Topics
        • 01-Hardware_Factory_Test
        • 02-Hardware_Aging_Test
        • 03-Firmware_Unpacking_and_Packing
    • zh
      • 01-主板介绍
        • 01-RK芯片对比介绍
        • 02-KICKPI-K1硬件介绍
        • 03-KICKPI-K1B硬件介绍
        • 04-KICKPI-K3硬件介绍
        • 05-KICKPI-K8硬件介绍
      • 02-入门必读
        • 01-网盘目录说明
        • 02-K1-快速使用
        • 02-K1B-快速使用
        • 02-K3-快速使用
        • 02-K8-快速使用
        • 03-功能测试
        • 04-拓展引脚
      • 03-镜像烧录
        • 01-获取镜像文件
        • 02-USB线烧录
      • 04-SDK编译
        • 01-编译环境搭建
        • 02-LINUX_SDK编译
        • 03-ANDROID_SDK编译
      • 05-外设驱动
        • GPIO
        • Kernel
        • LCD
        • PWM
        • RTC
      • 06-ANDROID系统定制
        • 01-Android常用系统定制
        • 07-Android NPU YOLOV5 目标检测
      • 07-LINUX系统定制
        • 01-Linux常用系统定制
        • 02-Linux安装VNC
        • 03-Linux Docker环境搭建
        • 04-Linux QT环境搭建
        • 05-Linux NPU YOLOV5S 目标检测
      • 08-进阶
        • 01-硬件工厂测试
        • 02-硬件老化测试
        • 03-固件解包和打包
  • K7(RK3576)
    • en
      • 01-Development_board_Introduction
        • 01-KICKPI-K7_Hardware_Introduction
      • 02-Getting_Started_Guide
        • 01-KICKPI_Cloud_Storage_Introduction
        • 02-Quick_Start_Guide
        • 03-Functional_Testing
        • 04-Expansion_Pins_Testing
      • 03-Image_Flashing_Guide
        • 01-How_to_Get_Image_File
        • 02-USB_Cable_Flashing
      • 04-SDK_Compilation_Guide
        • 01-Compilation_Environment_Setup
        • 02-Linux_SDK_Compilation
        • 03-Android_SDK_Compilation
      • 05-Drivers_Development
        • ADC
        • PWM
      • 06-Android_System_Customization
        • 01-Android_Common_System_Customization
      • 07-Linux_System_Customization
        • 01-Linux_Common_System_Customization
        • 02-Linux_Docker_Environment_Setup
        • 03-Linux_NPU_YOLOv5s_Object_Detection
        • 04-Linux_DeepSeek_Large_Model
        • 05-Linux_VNC_Remote_Control
      • 08-Advanced_Topics
        • Advanced_Testing
    • zh
      • 01-主板介绍
        • 01-KICKPI-K7硬件介绍
      • 02-入门必读
        • 01-网盘目录说明
        • 02-快速使用
        • 03-功能测试
        • 04-拓展引脚
      • 03-镜像烧录
        • 01-获取镜像文件
        • 02-USB线烧录
      • 04-SDK编译
        • 01-编译环境搭建
        • 02-Linux_SDK编译
        • 03-Android_SDK编译
      • 05-外设驱动
        • ADC
        • PWM
      • 06-ANDROID系统定制
        • 01-Android常用系统定制
      • 07-LINUX系统定制
        • 01-Linux常用系统定制
        • 02-Linux Docker环境搭建
        • 03-Linux NPU YOLOV5S 目标检测
        • 04-Linux_Deepseek大模型
        • 05-Linux_VNC远程控制
      • 08-进阶
        • 进阶测试
  • K4B(T113-S3)
    • T113-S3中文文档
      • 01-KICKPI-K4B硬件介绍
      • 10-系统镜像烧录
      • 11-SDK源码编译
      • 12-硬件功能测试
      • 13-硬件工厂测试
      • LCD功能调试
      • 20-Ubuntu20.04系统定制
      • Buildroot_QT5配置
      • Buildroot系统定制
  • common
    • en
      • adb
        • ADB_Tutorial
      • allwinner_burnning
        • SD_Card_Flashing
        • USB_Cable_Flashing
      • debug
        • 01 - Log Collection
      • display
        • FPC_Interface_Introduction
      • linux
        • SSH
    • zh
      • adb
        • ADB教程
      • android
        • qt
      • debug
        • 01-日志抓取
        • 常见问题
      • display
        • FPC接口介绍
      • linux
        • SSH
        • VNC
        • qt
      • 全志烧录
        • SD卡烧录
        • USB线烧录
Powered by GitBook
On this page
  • 1. Firmware Configuration
  • 1.1 Customize Keybox List
  • 1.2 Keybox Configuration Reading
  • 1.3 Compile Secure Firmware
  • 1.4 Burn Verification
  • 2. Burn Keybox
  • 3. Read Keybox
  1. K2B/K2C(H618)
  2. en
  3. 08-Advanced_Topics

Keybox

Due to limited efuse space, Tina supports the Keybox Secure Storage feature by default. This document describes how to customize and burn keyboxes, as well as read them.


1. Firmware Configuration

Prerequisite: Secure firmware is required. For secure firmware details, refer to 14-Secure Boot.

1.1 Customize Keybox List

U-Boot loads keys into Secure OS based on the keybox_list environment variable. Configure this variable in the env.cfg file using comma-separated key names.

Example: Add a custom key name xie:

--- a/device/config/chips/h618/configs/default/env.cfg
+++ b/device/config/chips/h618/configs/default/env.cfg
@@ -13,7 +13,7 @@ mac=
 wifi_mac=
 bt_mac=
 specialstr=
-keybox_list=hdcpkey,widevine
+keybox_list=hdcpkey,widevine,xie
 #set kernel cmdline if boot.img or recovery.img has no cmdline we will use this
 setargs_nand=setenv bootargs earlyprintk=${earlyprintk} initcall_debug=${initcall_debug} console=${console} loglevel=${loglevel} root=${nand_root} init=${init} partitions=${partitions} cma=${cma} snum=${snum} mac_addr=${mac} wifi_mac=${wifi_mac} bt_mac=${bt_mac} selinux=${selinux} specialstr=${specialstr} gpt=1
 setargs_mmc=setenv  bootargs earlyprintk=${earlyprintk} initcall_debug=${initcall_debug} console=${console} loglevel=${loglevel} root=${mmc_root} rootwait init=${init} partitions=${partitions} cma=${cma} snum=${snum} mac_addr=${mac} wifi_mac=${wifi_mac} bt_mac=${bt_mac} selinux=${selinux} specialstr=${specialstr} gpt=1

1.2 Keybox Configuration Reading

Keybox reading uses Allwinner-provided APIs. Tina includes demo implementations for these APIs. Keybox access requires TA/CA interaction.

  • CA: A Linux user-space application dependent on optee-client libraries.

  • TA: A secure application compiled using TA dev-kit.

1.2.1 TA/CA Compilation Configuration

  1. Run kernel configuration:

    $ make menuconfig
  2. Enable the following options:

    Tina Configuration
    └─> Security ‑‑‑>
        └─> OPTEE ‑‑‑>
            └─> -*- optee-client............................... optee-client 
            └─> <*> optee-efuse-read................... OPTEE efuse read demo
            └─> <*> optee-helloworld....................... OPTEE Hello World
            └─> -*- optee-os-dev-kit...................... optee-os-dev-kit  

    optee-efuse-read: Example for keybox reading. optee-helloworld: Example to verify TA/CA environment.

  3. Verify changes:

    $ git diff target/allwinner/h618-p2/defconfig
    diff --git a/target/allwinner/h618-p2/defconfig b/target/allwinner/h618-p2/defconfig
    index c6c47b5f4..d3b2737eb 100755
    --- a/target/allwinner/h618-p2/defconfig
    +++ b/target/allwinner/h618-p2/defconfig
    @@ -4232,10 +4232,10 @@ CONFIG_PACKAGE_wpa_supplicant_rtl=y
     #
     # CONFIG_PACKAGE_optee-aes-hmac is not set
     # CONFIG_PACKAGE_optee-base64 is not set
    -# CONFIG_PACKAGE_optee-client is not set
    -# CONFIG_PACKAGE_optee-efuse-read is not set
    -# CONFIG_PACKAGE_optee-helloworld is not set
    -# CONFIG_PACKAGE_optee-os-dev-kit is not set
    +CONFIG_PACKAGE_optee-client=y
    +CONFIG_PACKAGE_optee-efuse-read=y
    +CONFIG_PACKAGE_optee-helloworld=y
    +CONFIG_PACKAGE_optee-os-dev-kit=y
     # CONFIG_PACKAGE_optee-rotpk is not set
     # CONFIG_PACKAGE_optee-secure-storage is not set
     # CONFIG_PACKAGE_optee-test is not set
  4. Add platform-specific dev-kit:

    $ cd package/security/optee-os-dev-kit/dev_kit/
    $ cp -rp arm-plat-sun50iw1p1 arm-plat-sun50iw9p1

1.2.2 Modifications for optee-efuse-read Demo

Add debug prints for keybox buffer:

--- a/package/security/optee-efuse-read/src/ta/efuse_read_demo_ta.c
+++ b/package/security/optee-efuse-read/src/ta/efuse_read_demo_ta.c
@@ -96,13 +96,16 @@ TEE_Result TA_InvokeCommandEntryPoint(void *pSessionContext,
                        memcpy(keyname,"testkey",sizeof("testkey"));
                        keyname[49]=0;
                }
-               i = utee_sunxi_keybox((const char*)keyname, rdbuf, 16);
+               printf("keyname: %s \n",keyname);
+               i = utee_sunxi_keybox((const char*)keyname, rdbuf, 128);
                if (i != TEE_SUCCESS) {
                        printf("read key:%s from keybox failed with:%d\n",keyname,i);
                        return i;
                } else {
-                       i = utee_sunxi_read_efuse("oem_secure", &rd_len,
-                                                 rdbuf + 16);
+                       printf("keybox:\n");
+                       dump(rdbuf, 128);
+                       i = utee_sunxi_read_efuse("widevine", &rd_len,
+                                                 rdbuf + 128);
                        if (i == TEE_SUCCESS) {
                                printf("read result:\n");
                                dump(rdbuf, rd_len + 16);

dump is a built-in hex print function. 128 corresponds to the key length.

1.2.3 Allwinner-Specific APIs

  • utee_sunxi_keybox

    TEE_Result utee_sunxi_keybox(const char *keyname, uint8_t *out_buf, uint32_t size);

    Purpose: Read keybox data by name. Parameters:

    • keyname: Key name (must match entries in keybox_list).

    • out_buf: Output buffer (size ≥ size).

    • size: Data length to read. Return: 0 (success), -1 (failure).

  • utee_sunxi_read_efuse

    TEE_Result utee_sunxi_read_efuse(const char *keyname, uint8_t *result_len, uint8_t *rd_buf);

    Purpose: Read efuse data. Parameters:

    • keyname: Key name.

    • result_len: Output data length.

    • rd_buf: Output buffer. Return: 0 (success), others (failure).

  • utee_sunxi_write_efuse

    TEE_Result utee_sunxi_write_efuse(const char* keyname, uint8_t write_len, uint8_t *wr_buf);

    Purpose: Burn data to efuse. Parameters:

    • keyname: Key name.

    • write_len: Data length (bytes).

    • wr_buf: Data buffer. Return: 0 (success), others (failure).


1.3 Compile Secure Firmware

  1. Enable burn_key in sys_config.fex:

    [target]
    burn_key = 1
  2. Build firmware:

    $ source build/envsetup.sh
    $ lunch apollo_p2-userdebug
    $ pack -sv

    Output: longan/out/h618_android12_p2_uart0_secure_secure_v0.img (v0 is the default version number).


1.4 Burn Verification

  1. Check keybox_list in U-Boot:

    => printenv
    keybox_list=hdcpkey,widevine,xie
  2. Verify TA/CA functionality:

    # tee-supplicant &
    # hello_world_na 
    NA:init context
    NA:open session
    TA:creatyentry!
    TA:open session!
    NA:allocate memory
    NA:invoke command
    TA:rec cmd 0x210
    TA:hello world!
    NA:finish with 0

2. Burn Keybox

Use the DragonSN tool to burn keyboxes via USB.

  1. Configure key settings:

  2. Select key file and burn options:

    • Enable Erase Before Burn and Power Off After Burn (for production).


3. Read Keybox

  1. U-Boot Verification:

    => pst read
    [259.435]name in map xie
    [259.450]1 data:
    48 39 25 17 00 00 00 00 78 69 65 00 00 00 00 00 
    ... (truncated)
  2. System-Level Read:

    # tee-supplicant &
    # efuse_read_demo_na -ext_key xie

    Output:

    NA:init context
    NA:open session
    TA:creatyentry!
    TA:open session!
    NA:allocate memoryTA:rec cmd 0x220
    
    NA:invoke command
    keyname: xie 
    keybox:
    0x11 0x11 0x11 0x11 0x11 0x11 0x11 0x11 
    ... (truncated)

    Compare the output with your burned key for verification.

Last updated 1 day ago

image-20241122101659346

Open DragonSN:

Select Key Configuration:

image-20250514093013109

Add key entry (xie in this example):

Select key file:

Start burning:

Completion: