Skip to content

Conversation

@tretter
Copy link
Contributor

@tretter tretter commented Sep 26, 2025

The OTP handling is useful outside the rk3588 platform implementation. For example, the fuses for secure boot are accessible via the OTP.

Extract the OTP write and read support to a separate driver to make it available for other modules.

@tretter
Copy link
Contributor Author

tretter commented Sep 26, 2025

I extracted the patch to extract the Rockchip OTP from #7511, because the refactoring is useful even without the rksecure PTA.

#include <string_ext.h>
#include <utee_defines.h>

#include <drivers/rockchip_otp.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this directive above:

 #include <common.h>
+#include <drivers/rockchip_otp.h>
 #include <io.h>
 #include <kernel/panic.h>		

#include <mm/core_memprot.h>
#include <utee_defines.h>

#include <drivers/rockchip_otp.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 #include <common.h>
+#include <drivers/rockchip_otp.h>
 #include <io.h>
 #include <kernel/panic.h>

@@ -0,0 +1,189 @@
// SPDX-License-Identifier: BSD-3-Clause
/*
* Copyright (C) 2025, Pengutronix, Michael Tretter <[email protected]>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should also add the original copyrigth owners:

 * Copyright (C) 2019, Theobroma Systems Design und Consulting GmbH
 * Copyright (c) 2024, Rockchip, Inc. All rights reserved.

return TEE_SUCCESS;
}

register_phys_mem_pgdir(MEM_AREA_IO_SEC, OTP_S_BASE, OTP_S_SIZE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this above function definitions?

@tretter
Copy link
Contributor Author

tretter commented Oct 6, 2025

All comments have been addressed

@tretter tretter requested a review from etienne-lms October 6, 2025 15:54
Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to squash existing fixup commits.

#define OTP_POLL_PERIOD_US 0
#define OTP_POLL_TIMEOUT_US 1000

#define HW_UNIQUE_KEY_INDEX 0x104
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HW_UNIQUE_KEY_INDEX is only used by tee_otp_get_hw_unique_key() that remains in core/arch/arm/plat-rockchip/platform_rk3588.c. I think the macro definition can remain in this source file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HW_UNIQUE_KEY_INDEX describes the layout of the data in the OTP fuses. There will be other constants for other data, for example the secure boot status or the public key hash. The HW_UNIQUE_KEY_INDEX and other indexes are API for how the OTP driver shall be used and, thus, belongs into the header.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the macro definition to platform_config.h if it's platform flavor specific?
But okay if you really think it deserves to be defined in that driver header file.

That said, being moved outside a specific source file, I think it should also be renamed with ROCKCHIP_OPT_ or like prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving to platform_config.h sounds good. I moved it and changed the name to include a ROCKCHIP_OTP_ prefix.

* @index index of the first word to read in 32 bit words
* @count number of 32 bit words to read
*/
TEE_Result tee_otp_read_secure(uint32_t *value, uint32_t index,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename these 2 exported functions?

@tretter
Copy link
Contributor Author

tretter commented Oct 7, 2025

All comments have been addressed

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I suggest an extra build-time assertion. Feel free to squash the fixup commits.
Reviewed-by: Etienne Carriere <[email protected]>

{
TEE_Result res = TEE_SUCCESS;
uint32_t buffer[HW_UNIQUE_KEY_LENGTH / sizeof(uint32_t)] = { };
uint32_t buffer[ROCKCHIP_OTP_HUK_SIZE] = { };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest a build time assertion like static_assert(sizeof(buffer) == sizeof(hwkey->data)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of a build time assertion, but I'd add it in a follow-up pull request, since #7515 touches this code as well.

The OTP handling is useful outside the rk3588 platform implementation.
For example, the fuses for secure boot are accessible via the OTP.

Extract the OTP write and read support to a separate driver to make it
available for other modules.

Signed-off-by: Michael Tretter <[email protected]>
Reviewed-by: Etienne Carriere <[email protected]>
@tretter
Copy link
Contributor Author

tretter commented Oct 7, 2025

Fixed up commits with tag and ready to be merged

@jforissier jforissier merged commit d2c909e into OP-TEE:master Oct 7, 2025
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants