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:

  2. Enable the following options:

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

  3. Verify changes:

  4. Add platform-specific dev-kit:

1.2.2 Modifications for optee-efuse-read Demo

Add debug prints for keybox buffer:

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

1.2.3 Allwinner-Specific APIs

  • utee_sunxi_keybox

    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

    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

    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:

    image-20241122101659346
  2. Build firmware:

    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:

  2. Verify TA/CA functionality:


2. Burn Keybox

Use the DragonSN tool to burn keyboxes via USB.

  1. Open DragonSN: image-20250318152318389

  2. Configure key settings:

    • Select Key Configuration: image-20250514092816895

    image-20250514093013109
    • Add key entry (xie in this example): image-20250318152922597

  3. Select key file and burn options:

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

    • Select key file: image-20250318153520969

  4. Start burning: image-20250318154134143

  5. Completion: image-20250318154206857


3. Read Keybox

  1. U-Boot Verification:

  2. System-Level Read:

    Output:

    Compare the output with your burned key for verification.

Last updated