Optee pre-provisioned RPMB key

Hi,

is it necessary to build 2 complete images, one with TDX_OPTEE_FS_RPMB_MODE ? set to “factory” and one with “production” and fuse the device then boot the “factory” and then reflash with the “production” - or can the provisioning (fuse and write rpmb key) be made manually on the “production” image ?

Any advice appreciated

Regards - Paul

Hi, I’m the Toradex AI Assistant.

I might make mistakes or occasionally get you wrong. Our support team will step in if needed.


RPMB Key Provisioning Options

You have two approaches for RPMB key provisioning with OP-TEE:

Option 1: Two-Image Approach (Recommended)

This is the standard workflow:

  1. Factory Image: Build with TDX_OPTEE_FS_RPMB_MODE = "factory"

    • This image is configured to program the RPMB key derived from the SoC’s Hardware Unique Key (HUK)
    • Use this in a secure factory provisioning environment only
  2. Production Image: Build with TDX_OPTEE_FS_RPMB_MODE = "production"

    • This assumes the RPMB key has already been programmed
    • Deploy this for production use

Option 2: Manual Provisioning

Manual RPMB key provisioning on a production image is technically possible but not recommended for several reasons:

  • Security Risk: The production image lacks the built-in safeguards and automation of the factory mode
  • Complexity: You’d need to manually handle the key derivation and RPMB programming process
  • Error-Prone: RPMB key programming can only be done once - mistakes are permanent

Key Considerations

  • RPMB Key Programming: This operation can only be performed once per device
  • Secure Environment: Factory provisioning should occur in a trusted, secure environment
  • Hardware Unique Key: The RPMB key is derived from the SoC’s HUK and device-specific information

Recommendation

Use the two-image approach for production deployment. The factory mode provides proper automation and security controls for the critical one-time RPMB key programming operation.

Could you let me know which hardware platform and OS version you’re working with? This will help me provide more specific guidance for your setup.

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

@ToradexAI can you supply a script for the manual provisioning?

Manual RPMB Provisioning Script

Unfortunately, I don’t have a specific manual provisioning script in the available sources. The documentation emphasizes that manual RPMB key provisioning is complex and not the recommended approach.

What the Sources Tell Us

The eMMC documentation explains that the RPMB (Replay Protected Memory Block) area is a vendor-specific area that uses more reliable storage technology than the regular user area (1). However, the specific implementation details for manual provisioning scripts aren’t provided in the current documentation.

Recommended Approach

Based on the available information, I strongly recommend using the two-image factory/production approach rather than manual provisioning, as this provides:

  • Built-in security safeguards
  • Proper automation
  • Reduced risk of errors (since RPMB key programming can only be done once)

Next Steps

To provide you with the most accurate guidance for manual provisioning, could you share:

  1. Which hardware platform you’re using (you can run tdx-info to get this information: Getting Device Information with Tdx-Info | Toradex Developer Center)
  2. Which OS version you’re running
  3. Your specific use case requirements that make manual provisioning necessary

This will help me provide more targeted assistance for your setup.

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

@ToradexAI

Software summary

Bootloader: U-Boot

Kernel version: 6.6.115-7.5.0-devel #1 SMP PREEMPT Wed Oct 29 13:07:06 UTC 2025
Kernel command line: ro rootwait console=tty1 console=ttymxc0,115200 root=PARTUUID=4fa9241c-02
Distro name: NAME=“TDX Wayland with XWayland Upstream”
Distro version: VERSION_ID=7.5.0-devel-20251118061447-build.0
Distro variant: -
Hostname: -

Hardware info

HW model: Toradex Colibri iMX7D 1GB (eMMC) on Colibri Evaluation Board V3

Toradex version: 0039 V1.1B
Serial number: 12827568
Processor arch: armv7l

Manual RPMB Provisioning Script for Colibri iMX7D

Based on your hardware information (Colibri iMX7D 1GB eMMC V1.1B with BSP 7.5.0-devel), I can see you’re working with an eMMC-based module that supports RPMB functionality.

Understanding RPMB on Your Module

Your Colibri iMX7D has eMMC storage with a dedicated RPMB (Replay Protected Memory Block) area (1). The RPMB area is a vendor-specific area that uses underlying storage technology more reliable than the user area (1).

Manual Provisioning Considerations

Unfortunately, the available documentation doesn’t include specific manual provisioning scripts for RPMB key programming. However, based on the community discussion about OP-TEE support on iMX7D (2), manual porting and configuration of OP-TEE for the Colibri iMX7D requires significant low-level configuration work.

Key Technical Details for Your Module

For the Colibri iMX7D, you can access the eMMC information through U-Boot (3). The U-Boot console allows you to interact with the eMMC device and examine its configuration (3).

eMMC Device Structure

Your module’s eMMC has the following structure (1):

eMMC boot area:

  • Raw partition - U-Boot bootloader and environment, Toradex factory configuration block (1)
  • Raw partition - RPMB area for storing sensitive data such as authentication keys (1)

eMMC user area:

  • FAT32 partition - Kernel and device tree (1)
  • EXT-4 partition - Root file system (1)

Recommendation

Given the complexity and the one-time nature of RPMB key programming, I strongly recommend using the factory/production image approach rather than manual scripting. The community discussion (2) shows that even basic OP-TEE porting for iMX7D requires extensive manual configuration work.

For manual provisioning scripts specific to your setup, you may need to consult the OP-TEE documentation directly or work with the low-level eMMC commands through U-Boot, but this carries significant risk since RPMB key programming can only be performed once per device.

Would you like me to help you set up the two-image approach instead, which would be much safer for your production deployment?

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

@ToradexAI

can “mmc rpmb write-key /dev/mmcblk0rpmb $KEY” be used ?

Then i need instructions on how to get a key derived from the imx7 HUK

Regards - Paul

RPMB Key Programming and HUK Derivation on iMX7

Manual RPMB Key Programming

The mmc rpmb write-key command can indeed be used to program the RPMB key, but this is a one-time operation that cannot be reversed. The challenge is properly deriving the key from the iMX7 Hardware Unique Key (HUK).

Key Derivation Process

For OP-TEE on iMX7, the RPMB key is derived from the SoC’s Hardware Unique Key (HUK) and other device-specific information. The documentation indicates that when using factory mode (TDX_OPTEE_FS_RPMB_MODE = "factory"), OP-TEE is configured to program the RPMB key derived from the SoC’s Hardware Unique Key (HUK) and other device-specific information.

Technical Considerations for Your Setup

Based on your Colibri iMX7D 1GB eMMC module, the RPMB area is available as a dedicated partition for storing sensitive data such as authentication keys (1). However, the specific implementation details for manual HUK derivation aren’t provided in the current documentation.

Critical Warnings

  1. One-Time Operation: RPMB key programming can only be done once per device
  2. Irreversible: If you make an error, the device cannot be recovered
  3. Security Risk: Manual key derivation may not include all the security safeguards of the factory mode

Alternative Approach

Given the complexity and risks involved, I strongly recommend using the two-image factory/production approach:

  1. Factory Image: Build with TDX_OPTEE_FS_RPMB_MODE = "factory"
  2. Production Image: Build with TDX_OPTEE_FS_RPMB_MODE = "production"

This approach provides proper automation and security controls for the critical one-time RPMB key programming operation.

Next Steps

For the specific HUK derivation algorithm and manual provisioning script, you would need to examine the OP-TEE source code or consult the OP-TEE documentation directly, as these low-level implementation details aren’t covered in the available Toradex documentation.

Would you like guidance on setting up the recommended factory/production image workflow instead?

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

Greetings @pfarre,

To address your original question:

is it necessary to build 2 complete images, one with TDX_OPTEE_FS_RPMB_MODE ? set to “factory” and one with “production” and fuse the device then boot the “factory” and then reflash with the “production” - or can the provisioning (fuse and write rpmb key) be made manually on the “production” image ?

Based on the variable name I assume you’re enabling Optee via our meta-toradex-security meta-layer, correct?

If that is the case, then the response from the AI should be accurate and is described in more detail in the in-repo documentation here: meta-toradex-security/docs/README-optee.md at scarthgap-7.x.y · toradex/meta-toradex-security · GitHub

As for your follow-up question. I believe you’re asking how exactly you can write the RPMB key yourself to the device, correct?

In the case of factory mode we rely on the Optee software to do the programming. For your case, it seems like you want to write keys as a separate step?

There is a blog here about RPMB in general including programming keys: RPMB, a secret place inside the eMMC - sergioprado.blog

This was written by the developer who added the RPMB Optee support to our meta-layer so it should be very relevant.

Best Regards,
Jeremias

@ToradexAI

is the writing of the RPMB key done by optee code in u-boot, the kernel or code in the rootfs?

RPMB Key Programming Location

Based on the available documentation, the RPMB key programming in OP-TEE occurs in the OP-TEE OS (Trusted Execution Environment) itself, not in U-Boot, the kernel, or rootfs code.

Technical Implementation Details

The OP-TEE implementation uses platform-specific hooks to control when RPMB key programming is allowed. The documentation indicates that OP-TEE includes a software hook, plat_rpmb_key_is_ready(), which platforms can use to enforce security logic.

For iMX-based devices like your Colibri iMX7D, the RPMB key cannot be written unless secure boot is enabled. This behavior can be modified by overriding the plat_rpmb_key_is_ready() function in the core/drivers/imx_snvs.c file of the OP-TEE OS source code.

When Key Programming Occurs

The key programming happens when OP-TEE is running in the Trusted Execution Environment (TEE), which occurs after U-Boot has loaded OP-TEE but before or during Linux kernel execution. The OP-TEE OS handles the actual RPMB communication and key derivation from the Hardware Unique Key (HUK).

Configuration Variables

The behavior is controlled by the TDX_OPTEE_FS_RPMB_MODE variable:

  • factory: OP-TEE is configured to program the RPMB key derived from the SoC’s HUK
  • production: OP-TEE assumes the RPMB key has already been programmed

Boot Sequence Context

In the boot sequence, this occurs:

  1. U-Boot loads and starts OP-TEE OS (1)
  2. OP-TEE OS runs in the secure world and can access hardware security features
  3. OP-TEE handles RPMB key programming (if in factory mode)
  4. Linux kernel starts in the normal world
  5. tee-supplicant in rootfs communicates with OP-TEE for ongoing RPMB operations

The actual key programming is handled by OP-TEE OS code running in the secure world, not by U-Boot, kernel, or userspace applications.

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

@ToradexAI

more specific my question is : do i need to update all parts of the system when going from “factory” to “production” mode or could i just update one part either u-boot the fitImage or the rootfs?

Unfortunately, I don’t have specific information in the available sources about which exact components need to be updated when transitioning from “factory” to “production” mode for OP-TEE RPMB configuration.

What We Know About the Configuration

The TDX_OPTEE_FS_RPMB_MODE variable controls the RPMB behavior at the OP-TEE level, but the available documentation doesn’t specify exactly which parts of the system (U-Boot, FIT image, or rootfs) contain the mode-specific configuration.

Key Considerations

Since OP-TEE runs as part of the secure world and is typically loaded by U-Boot (1), the configuration might be embedded in:

  • The OP-TEE OS binary itself (part of the FIT image)
  • U-Boot environment variables (1)
  • Runtime configuration in the rootfs

Recommendation

Given the critical nature of RPMB key programming (which can only be done once per device) and the lack of specific documentation about partial updates, I strongly recommend updating the complete system image when transitioning from factory to production mode.

This ensures:

  • All components are synchronized
  • No configuration mismatches occur
  • The transition is reliable and secure

Next Steps

For the specific implementation details about which components contain the RPMB mode configuration, you might want to examine the meta-toradex-security layer source code or consult the OP-TEE documentation directly.

Could you share more details about your deployment constraints that make partial updates preferable? This would help me provide more targeted guidance for your specific use case.

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

As per the Optee documentation: Secure storage — OP-TEE documentation documentation

They are handled by the tee-supplicant process which further relies on the kernel’s ioctl() interface to access the device. ``

Which tells me the kernel is what is being relied upon for the key programming, if done through Optee.

What is your use-case exactly? Do you want to field-update the device so that it programs the RPMB key in-field? That’s not a use-case we specifically have thought about, or designed for.

The factory mode will program the key during device flashing/provisioning via optee. The production mode assumes the device has already been programmed, or provisioned with the key by some other process prior.

Best Regards,
Jeremias