Skip to content

Commit 403bb0f

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 8c34a17 commit 403bb0f

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

CMakeLists.txt

+26
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

+1
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://archlinux.org/packages/extra/x86_64/riscv64-elf-gcc/) | - | - | - | - | riscv64-elf-gcc | riscv64-elf-gcc |
9596

9697
## Documents
9798

doc/build.md

+21
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ 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+
d) [RISCV NONE](https://archlinux.org/packages/extra/x86_64/riscv64-elf-gcc/)
101+
- Use a [GCC](https://gcc.gnu.org/) compiler configured for building
102+
baremetal (not Linux) binaries. This is supported by any modern Linux
103+
distro.
104+
105+
- On Arch it can be installed with
106+
```
107+
sudo pacman -Syu riscv32-elf-binutils riscv32-elf-newlib riscv64-elf-binutils riscv64-elf-gcc riscv64-elf-newlib
108+
```
109+
100110
#### Compiler for ARC
101111
102112
a) [ARC GNU](https://github.com/foss-for-synopsys-dwc-arc-processors).
@@ -291,3 +301,14 @@ Unit tests can be disable by adding -DDISABLE_TESTS=1 to CMake.
291301
```shell
292302
-DDISABLE_TESTS=1
293303
```
304+
305+
### Embedded builds for RISC-V
306+
307+
The libspdm libraries can be built along with Mbed TLS to target an embedded
308+
environment. The Integrator must provide a C library and runtime, such as Newlib.
309+
310+
To build libspdm with Mbed TLS for RISC-V 32-bit run the following
311+
312+
```
313+
cmake -DARCH=riscv32 -DTOOLCHAIN=RISCV_NONE -DTARGET=Debug -DCRYPTO=mbedtls -DDISABLE_TESTS=1 ..
314+
```

0 commit comments

Comments
 (0)