Skip to content

Commit

Permalink
Riscv zephyr support (#1641)
Browse files Browse the repository at this point in the history
* added riscv32 to zephyr (qemu)

* added to PLATFORMS.md
  • Loading branch information
trigpolynom authored Jan 14, 2024
1 parent 5bee5aa commit bb23b3f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
if(${OQS_DIST_BUILD})
set(OQS_DIST_S390X_BUILD ON)
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv")
set(ARCH "riscv")
elseif(OQS_PERMIT_UNSUPPORTED_ARCHITECTURE)
message(WARNING "Unknown or unsupported processor: " ${CMAKE_SYSTEM_PROCESSOR})
message(WARNING "Compilation on an unsupported processor should only be used for testing, as it may result an insecure configuration, for example due to variable-time instructions leaking secret information.")
Expand Down
2 changes: 1 addition & 1 deletion PLATFORMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ In this policy, the words "must" and "must not" specify absolute requirements th
- x86_64/amd64/x64 for Windows 2022
- armeabi-v7a, arm64-v8a, x86, x86_64 for Android
- aarch64 for Apple iOS and tvOS (CMake `-DPLATFORM=OS64` and `TVOS`)
- arm64, arm (32 bit), x86, x86_64 for Zephyr
- arm64, arm (32 bit), x86, x86_64, riscv32, riscv64 for Zephyr

### Tier 3

Expand Down
21 changes: 20 additions & 1 deletion zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,33 @@

# Only add liboqs Zephyr module if enabled in Kconfig
if(CONFIG_LIBOQS)

# Workarounds for Zephyr
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
# Workaround as the generic name "arm" is not a supported architecture in liboqs.
# In Zephyr, however, it is exclusively used for 32-bit ARM architectures.
set(CMAKE_SYSTEM_PROCESSOR "armv7")
# We have to set that manually as CMake can't detect it properly in Zephyr
set(CMAKE_SIZEOF_VOID_P 4)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv")
if(BOARD STREQUAL "qemu_riscv32")
set(CMAKE_SYSTEM_PROCESSOR "riscv32")
# We have to set that manually as CMake can't detect it properly in Zephyr
set(CMAKE_SIZEOF_VOID_P 4)
elseif(BOARD STREQUAL "hifive1_revb")
set(CMAKE_SYSTEM_PROCESSOR "riscv32")
# We have to set that manually as CMake can't detect it properly in Zephyr
set(CMAKE_SIZEOF_VOID_P 4)
elseif(BOARD STREQUAL "qemu_riscv64")
set(CMAKE_SYSTEM_PROCESSOR "riscv64")
# We have to set that manually as CMake can't detect it properly in Zephyr
set(CMAKE_SIZEOF_VOID_P 8)
else()
message(FATAL_ERROR "Unsupported board ${BOARD} with riscv architecture")
endif()
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "posix")
# Workaround to enable the native Zephyr builds on the Linux host system.
if(BOARD MATCHES "native_posix|native_sim")
if(BOARD STREQUAL "native_posix|native_sim")
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
else()
message(FATAL_ERROR "Unsupported board ${BOARD} with posix architecture")
Expand Down
4 changes: 2 additions & 2 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

config LIBOQS
bool "Enable liboqs"
depends on ARM || ARM64 || X86 || ARCH_POSIX
depends on ARM || ARM64 || X86 || ARCH_POSIX || RISCV
help
This option enables the liboqs as a Zephyr module. Currenty, the port is only
available for ARM, ARM64, and x86 architectures and the native Posix simulators.
available for ARM, ARM64, x86, RISCV-32, and RISCV-64 architectures and the native Posix simulators.

menu "Liboqs algorithm configuration"

Expand Down
2 changes: 2 additions & 0 deletions zephyr/samples/KEMs/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ tests:
integration_platforms:
- qemu_x86
- qemu_cortex_a53
- qemu_riscv32
- qemu_riscv64
2 changes: 2 additions & 0 deletions zephyr/samples/Signatures/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ tests:
integration_platforms:
- qemu_x86
- qemu_cortex_a53
- qemu_riscv32
- qemu_riscv64

0 comments on commit bb23b3f

Please sign in to comment.