Skip to contentSkip to conversation

boot: optee-os: enable RISC-V (64-bit) architecture

PATCH Applied Yu Chien Peter Lin via buildroot 1 participant 4 messages Aug 17, 2024 – Sep 16, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 boot: optee-os: enable RISC-V (64-bit) architecture

OP-TEE OS and TAs can run on RISC-V (64-bit) machines, so allow optee-os to be compiled for the new architecture.

---
 boot/optee-os/Config.in   |  2 +-
 boot/optee-os/optee-os.mk | 29 ++++++++++++++++++++++++-----
 2 files changed, 25 insertions(+), 6 deletions(-)
boot/optee-os/Config.in +1 -1
index 2f996cbafc..cc0044f00a 100644
@@ -1,6 +1,6 @@
 config BR2_TARGET_OPTEE_OS
 	bool "optee_os"
-	depends on BR2_ARM_CPU_ARMV8A || BR2_ARM_CPU_ARMV7A
+	depends on BR2_ARM_CPU_ARMV8A || BR2_ARM_CPU_ARMV7A || BR2_RISCV_64
 	help
 	  OP-TEE OS provides the secure world boot image and the trust
 	  application development kit of the OP-TEE project. OP-TEE OS
boot/optee-os/optee-os.mk +24 -5
index 6b04a0f5e1..d135de6dc7 100644
@@ -44,26 +44,41 @@ ifeq ($(BR2_TARGET_OPTEE_OS_NEEDS_DTC),y)
 OPTEE_OS_DEPENDENCIES += host-dtc
 endif
 
+OPTEE_OS_MAKE_OPTS = \
+	CROSS_COMPILE="$(TARGET_CROSS)" \
+	CROSS_COMPILE_core="$(TARGET_CROSS)" \
+	PYTHON3="$(HOST_DIR)/bin/python3"
+
+ifeq ($(BR2_RISCV_64),y)
+OPTEE_OS_MAKE_OPTS += CROSS_COMPILE_ta_rv64="$(TARGET_CROSS)"
+else
 # On 64bit targets, OP-TEE OS can be built in 32bit mode, or
 # can be built in 64bit mode and support 32bit and 64bit
 # trusted applications. Since buildroot currently references
 # a single cross compiler, build exclusively in 32bit
 # or 64bit mode.
-OPTEE_OS_MAKE_OPTS = \
-	CROSS_COMPILE="$(TARGET_CROSS)" \
-	CROSS_COMPILE_core="$(TARGET_CROSS)" \
+OPTEE_OS_MAKE_OPTS += \
 	CROSS_COMPILE_ta_arm64="$(TARGET_CROSS)" \
-	CROSS_COMPILE_ta_arm32="$(TARGET_CROSS)" \
-	PYTHON3="$(HOST_DIR)/bin/python3"
+	CROSS_COMPILE_ta_arm32="$(TARGET_CROSS)"
+endif
 
+ifeq ($(BR2_riscv),y)
+OPTEE_OS_MAKE_OPTS += \
+	ARCH=riscv \
+	CFG_RV64_core=y \
+	CFG_USER_TA_TARGETS=ta_rv64
+else
 ifeq ($(BR2_aarch64),y)
 OPTEE_OS_MAKE_OPTS += \
+	ARCH=aarch64 \
 	CFG_ARM64_core=y \
 	CFG_USER_TA_TARGETS=ta_arm64
 else
 OPTEE_OS_MAKE_OPTS += \
+	ARCH=arm \
 	CFG_ARM32_core=y
 endif
+endif
 
 # Get mandatory PLAFORM and optional PLATFORM_FLAVOR and additional
 # variables
@@ -77,6 +92,10 @@ OPTEE_OS_MAKE_OPTS += $(call qstrip,$(BR2_TARGET_OPTEE_OS_ADDITIONAL_VARIABLES))
 # root path otherwise the output directory path depends on the target
 # platform name.
 OPTEE_OS_BUILDDIR_OUT = out
+ifeq ($(BR2_riscv),y)
+OPTEE_OS_LOCAL_SDK = $(OPTEE_OS_BUILDDIR_OUT)/export-ta_rv64
+OPTEE_OS_SDK = $(STAGING_DIR)/lib/optee/export-ta_rv64
+endif
 ifeq ($(BR2_aarch64),y)
 OPTEE_OS_LOCAL_SDK = $(OPTEE_OS_BUILDDIR_OUT)/export-ta_arm64
 OPTEE_OS_SDK = $(STAGING_DIR)/lib/optee/export-ta_arm64
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw
In reply to Yu Chien Peter Lin via buildroot
Quoted 4 lines · Yu Chien Peter Lin via buildroot

OP-TEE OS and TAs can run on RISC-V (64-bit) machines, so allow optee-os to be compiled for the new architecture.

Hi Peter,

Applied to master, thanks. I made some changes, see below, please check if
things are still OK!

Quoted 37 lines
---
  boot/optee-os/Config.in   |  2 +-
  boot/optee-os/optee-os.mk | 29 ++++++++++++++++++++++++-----
  2 files changed, 25 insertions(+), 6 deletions(-)
boot/optee-os/Config.in +1 -1
index 2f996cbafc..cc0044f00a 100644
@@ -1,6 +1,6 @@
  config BR2_TARGET_OPTEE_OS
  	bool "optee_os"
-	depends on BR2_ARM_CPU_ARMV8A || BR2_ARM_CPU_ARMV7A
+	depends on BR2_ARM_CPU_ARMV8A || BR2_ARM_CPU_ARMV7A || BR2_RISCV_64
  	help
  	  OP-TEE OS provides the secure world boot image and the trust
  	  application development kit of the OP-TEE project. OP-TEE OS
boot/optee-os/optee-os.mk +8 -0
index 6b04a0f5e1..d135de6dc7 100644
@@ -44,26 +44,41 @@ ifeq ($(BR2_TARGET_OPTEE_OS_NEEDS_DTC),y)
  OPTEE_OS_DEPENDENCIES += host-dtc
  endif
 
+OPTEE_OS_MAKE_OPTS = \
+	CROSS_COMPILE="$(TARGET_CROSS)" \
+	CROSS_COMPILE_core="$(TARGET_CROSS)" \
+	PYTHON3="$(HOST_DIR)/bin/python3"
+
+ifeq ($(BR2_RISCV_64),y)
+OPTEE_OS_MAKE_OPTS += CROSS_COMPILE_ta_rv64="$(TARGET_CROSS)"
+else
  # On 64bit targets, OP-TEE OS can be built in 32bit mode, or
  # can be built in 64bit mode and support 32bit and 64bit
  # trusted applications. Since buildroot currently references
  # a single cross compiler, build exclusively in 32bit

boot/optee-os/optee-os.mk ifeq ($(BR2_TARGET_OPTEE_OS_NEEDS_DTC),y) · line 63

Quoted 10 lines
boot/optee-os/optee-os.mk +3 -5
  # or 64bit mode.
-OPTEE_OS_MAKE_OPTS = \
-	CROSS_COMPILE="$(TARGET_CROSS)" \
-	CROSS_COMPILE_core="$(TARGET_CROSS)" \
+OPTEE_OS_MAKE_OPTS += \
  	CROSS_COMPILE_ta_arm64="$(TARGET_CROSS)" \
-	CROSS_COMPILE_ta_arm32="$(TARGET_CROSS)" \
-	PYTHON3="$(HOST_DIR)/bin/python3"
+	CROSS_COMPILE_ta_arm32="$(TARGET_CROSS)"
+endif

I've removed this condition and reverted to the orginal situation, i.e.
setting CROSS_COMPILE_* for all architecture irrespective of the one we actually use. I guess if it works for arm64/arm32, it will work for rv64 as well... I wasn't really able to test though so let us know if something went wrong there.

boot/optee-os/optee-os.mk ifeq ($(BR2_TARGET_OPTEE_OS_NEEDS_DTC),y) · line 73

Quoted 10 lines
boot/optee-os/optee-os.mk +7 -0
+ifeq ($(BR2_riscv),y)
+OPTEE_OS_MAKE_OPTS += \
+	ARCH=riscv \
+	CFG_RV64_core=y \
+	CFG_USER_TA_TARGETS=ta_rv64
+else
  ifeq ($(BR2_aarch64),y)
  OPTEE_OS_MAKE_OPTS += \
+	ARCH=aarch64 \

This is in fact wrong, it should have been ARCH=arm.

Regards,
Arnout

Quoted 12 lines
boot/optee-os/optee-os.mk +2 -0
  	CFG_ARM64_core=y \
  	CFG_USER_TA_TARGETS=ta_arm64
  else
  OPTEE_OS_MAKE_OPTS += \
+	ARCH=arm \
  	CFG_ARM32_core=y
  endif
+endif
 
  # Get mandatory PLAFORM and optional PLATFORM_FLAVOR and additional
  # variables

boot/optee-os/optee-os.mk OPTEE_OS_MAKE_OPTS += $(call qstrip,$(BR2_TARGET_OPTEE_OS_ADDITIONAL_VARIABLES)) · line 101

Quoted 10 lines
boot/optee-os/optee-os.mk +4 -0
@@ -77,6 +92,10 @@ OPTEE_OS_MAKE_OPTS += $(call qstrip,$(BR2_TARGET_OPTEE_OS_ADDITIONAL_VARIABLES))
  # root path otherwise the output directory path depends on the target
  # platform name.
  OPTEE_OS_BUILDDIR_OUT = out
+ifeq ($(BR2_riscv),y)
+OPTEE_OS_LOCAL_SDK = $(OPTEE_OS_BUILDDIR_OUT)/export-ta_rv64
+OPTEE_OS_SDK = $(STAGING_DIR)/lib/optee/export-ta_rv64
+endif
  ifeq ($(BR2_aarch64),y)
  OPTEE_OS_LOCAL_SDK = $(OPTEE_OS_BUILDDIR_OUT)/export-ta_arm64
  OPTEE_OS_SDK = $(STAGING_DIR)/lib/optee/export-ta_arm64

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#3 lore raw
Quoted 11 lines · Arnout Vandecappelle
Quoted 4 lines · Yu Chien Peter Lin via buildroot

OP-TEE OS and TAs can run on RISC-V (64-bit) machines, so allow optee-os to be compiled for the new architecture.

Hi Peter,

Applied to master, thanks. I made some changes, see below, please check if
things are still OK!

Hi Arnout,

I've confirmed that the qemu_riscv64_virt_defconfig generates the RISC-V OP-TEE binaries, thanks for handling this.

Best regards,
Peter Lin
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot