Skip to content

Commit 1f62834

Browse files
committed
CMakeLists: Add a RISCV_NONE toolchain
Add a RISCV_NONE toolchain to target an embedded environment. This allows building libspdm libraries with mbedtls. Signed-off-by: Alistair Francis <[email protected]>
1 parent d836331 commit 1f62834

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
8989
MESSAGE("TOOLCHAIN = RISCV_GNU")
9090
elseif(TOOLCHAIN STREQUAL "RISCV64_GCC")
9191
MESSAGE("TOOLCHAIN = RISCV64_GCC")
92+
elseif(TOOLCHAIN STREQUAL "RISCV_NONE")
93+
MESSAGE("TOOLCHAIN = RISCV_NONE")
9294
elseif(TOOLCHAIN STREQUAL "RISCV_XPACK")
9395
MESSAGE("TOOLCHAIN = RISCV_XPACK")
9496
elseif(TOOLCHAIN STREQUAL "ARC_GCC")
@@ -417,6 +419,30 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
417419

418420
SET(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Wl,--start-group <LINK_LIBRARIES> -Wl,--end-group")
419421

422+
elseif(TOOLCHAIN STREQUAL "RISCV_NONE")
423+
SET(CMAKE_C_COMPILER riscv64-elf-gcc)
424+
ADD_COMPILE_OPTIONS(-nostdlib -lgcc)
425+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
426+
ADD_COMPILE_OPTIONS(-g)
427+
endif()
428+
429+
if(ARCH STREQUAL "riscv32")
430+
ADD_COMPILE_OPTIONS(-march=rv32imac_zicsr -mabi=ilp32)
431+
elseif(ARCH STREQUAL "riscv64")
432+
ADD_COMPILE_OPTIONS(-march=rv64imac_zicsr -mabi=lp64)
433+
else()
434+
ADD_COMPILE_OPTIONS(-march=error -mabi=error)
435+
endif()
436+
437+
SET(CMAKE_AR riscv64-elf-ar)
438+
439+
SET(CMAKE_LINKER riscv64-elf-gcc)
440+
SET(CMAKE_EXE_LINKER_FLAGS "-no-pie" )
441+
442+
SET(MBEDTLS_FLAGS -nostdlib -lgcc)
443+
444+
SET(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Wl,--start-group <LINK_LIBRARIES> -Wl,--end-group")
445+
420446
elseif(TOOLCHAIN STREQUAL "RISCV_XPACK")
421447
SET(CMAKE_C_COMPILER riscv-none-elf-gcc)
422448
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
| [RISCV_GNU](https://github.com/riscv/riscv-gnu-toolchain) | - | - | - | - | riscv32-unknown-linux-gnu-gcc | riscv64-unknown-linux-gnu-gcc |
9393
| [RISCV64_GCC](https://packages.ubuntu.com/bionic/gcc-riscv64-linux-gnu) | - | - | - | - | - | riscv64-linux-gnu-gcc |
9494
| [RISCV_XPACK](https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack) | - | - | - | - | riscv-none-elf-gcc | riscv-none-elf-gcc |
95+
| [RISCV_NONE](https://github.com/riscv/riscv-gnu-toolchain) | - | - | - | - | riscv64-elf-gcc | riscv64-elf-gcc |
9596

9697
## Documents
9798

doc/build.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ b) [RISCV GNU](https://github.com/riscv-collab/riscv-gnu-toolchain)
9797
c) [RISCV64 GCC](https://packages.ubuntu.com/bionic/gcc-riscv64-linux-gnu) for RISCV64 only
9898
- `sudo apt-get install gcc-riscv64-linux-gnu`
9999
100+
c) [RISCV NONE](https://github.com/riscv/riscv-gnu-toolchain)
101+
- `sudo pacman -Syu riscv32-elf-binutils riscv32-elf-newlib riscv64-elf-binutils riscv64-elf-gcc riscv64-elf-newlib`
102+
100103
#### Compiler for ARC
101104
102105
a) [ARC GNU](https://github.com/foss-for-synopsys-dwc-arc-processors).
@@ -291,3 +294,15 @@ Unit tests can be disable by adding -DDISABLE_TESTS=1 to CMake.
291294
```shell
292295
-DDISABLE_TESTS=1
293296
```
297+
298+
### Embedded builds for RISC-V
299+
300+
The libspdm libraries can be build along with mbedtls to target an embedded
301+
environment. You can then use newlibc to create final binaries linking with
302+
libspdm and mbedtls
303+
304+
To build libspdm with mbedtls for RISC-V 32-bit run the following
305+
306+
```
307+
cmake -DARCH=riscv32 -DTOOLCHAIN=RISCV_NONE -DTARGET=Debug -DCRYPTO=mbedtls -DDISABLE_TESTS=1 ..
308+
```

0 commit comments

Comments
 (0)