1 Copyright (c) 2019 Western Digital Corporation or its affiliates.
3 RISC-V Open Source Supervisor Binary Interface (OpenSBI)
4 ========================================================
6 The **RISC-V Supervisor Binary Interface (SBI)** is the recommended interface
9 1. A platform specific firmware running in M-mode and bootloader, hypervisor or
10 a general purpose OS executing in S-mode or HS-mode.
11 2. A hypervisor running in HS-mode and a bootloader or a general purpose OS
14 The *RISC-V SBI specification* is maintained as an independent project by the
15 RISC-V Foundation in [Github].
17 The goal of the OpenSBI project is to provide an open-source reference
18 implementation of the RISC-V SBI specifications for platform specific firmwares
19 executing in M-mode (case 1 mentioned above). OpenSBI implementation can be
20 easily extended by RISC-V platform and system-on-chip vendors to fit a
21 particular hardware configuration.
23 The main component of OpenSBI is provided in the form of a platform independent
24 static library **libsbi.a** implementing the SBI interface. A firmware or
25 bootloader implementation can link against this library to ensure conformance
26 with the SBI interface specifications. *libsbi.a* also defines an interface for
27 integrating with platform specific operations provided by the platform firmware
28 implementation (e.g. console access functions, inter-processor interrupts
31 To illustrate the use of *libsbi.a* library, OpenSBI also provides a set of
32 platform specific support examples. For each example, a platform
33 specific static library *libplatsbi.a* can be compiled. This library implements
34 SBI calls processing by integrating *libsbi.a* with necessary platform dependent
35 hardware manipulation functions. For all supported platforms, OpenSBI also
36 provides several runtime firmware examples built using the platform
37 *libplatsbi.a*. These example firmwares can be used to replace the legacy
38 *riskv-pk* bootloader (aka BBL) and enable the use of well known bootloaders
44 OpenSBI can be compiled natively or cross-compiled on a x86 host. For
45 cross-compilation, you can build your tool chain or just download from
46 the [bootlin] (https://toolchains.bootlin.com/).
48 Please note that only 64bit version of toolchain is available in bootlin
51 Building and Installing OpenSBI Platform Independent Library
52 ------------------------------------------------------------
54 OpenSBI platform independent static library *libsbi.a* can be natively compiled
55 or cross-compiled on a host with a different base architecture than RISC-V.
57 For cross-compiling, the environment variable *CROSS_COMPILE* must be defined
58 to specify the name prefix of the RISC-V compiler toolchain executables, e.g.
59 *riscv64-unknown-elf-* if the gcc executable used is *riscv64-unknown-elf-gcc*.
61 To build *libsbi.a* simply execute:
66 All compiled binaries as well as the result *libsbi.a* static library file will
67 be placed in the *build/lib* directory. To specify an alternate build root
70 make O=<build_directory>
73 To generate files to be installed for using *libsbi.a* in other projects, run:
78 This will create the *install* directory with all necessary include files
79 copied under the *install/include* directory and library file copied in the
80 *install/lib* directory. To specify an alternate installation root directory
83 make I=<install_directory> install
86 Building and Installing a Reference Platform Static Library and Firmwares
87 -------------------------------------------------------------------------
89 When the *PLATFORM=<platform_subdir>* argument is specified on the make command
90 line, the platform specific static library *libplatsbi.a* and firmware examples
91 are built for the platform *<platform_subdir>* present in the directory
92 *platform* in OpenSBI top directory. For example, to compile the platform
93 library and firmware examples for QEMU RISC-V *virt* machine,
94 *<platform_subdir>* should be *qemu/virt*.
96 To build *libsbi.a*, *libplatsbi.a* and the firmwares for one of the supported
99 make PLATFORM=<platform_subdir>
102 An alternate build directory path can also be specified.
104 make PLATFORM=<platform_subdir> O=<build_directory>
107 The platform specific library *libplatsbi.a* will be generated in the
108 *build/platform/<platform_subdir>/lib* directory. The platform firmware files
109 will be under the *build/platform/<platform_subdir>/firmware* directory.
110 The compiled firmwares will be available in two different format: an ELF file
111 and an expanded image file.
113 To install *libsbi.a*, *libplatsbi.a*, and the compiled firmwares, run:
115 make PLATFORM=<platform_subdir> install
118 This will copy the compiled platform specific libraries and firmware files
119 under the *install/platform/<platform_subdir>/* directory. An alternate
120 install root directory path can be specified as follows.
122 make PLATFORM=<platform_subdir> I=<install_directory> install
125 In addition, platform specific configuration options can be specified with the
126 top-level make command line. These options, such as *PLATFORM_<xyz>* or
127 *FW_<abc>*, are platform specific and described in more details in the
128 *docs/platform/<platform_name>.md* files and
129 *docs/firmware/<firmware_name>.md* files.
134 OpenSBI is distributed under the terms of the BSD 2-clause license
135 ("Simplified BSD License" or "FreeBSD License", SPDX: *BSD-2-Clause*).
136 A copy of this license with OpenSBI copyright can be found in the file
139 All source files in OpenSBI contain the 2-Clause BSD license SPDX short
140 identifier in place of the full license text.
143 SPDX-License-Identifier: BSD-2-Clause
146 This enables machine processing of license information based on the SPDX
147 License Identifiers that are available on the [SPDX] web site.
149 OpenSBI source code also contains code reused from other projects as listed
150 below. The original license text of these projects is included in the source
151 files where the reused code is present.
153 1. The libfdt source code is disjunctively dual licensed
154 (GPL-2.0+ OR BSD-2-Clause). Some of this project code is used in OpenSBI
155 under the terms of the BSD 2-Clause license. Any contributions to this
156 code must be made under the terms of both licenses.
157 2. Some source file for the Kendryte/k210 platform code are based on code from
158 the Kendryte [standalone SDK] available on github. These files retain the
159 original copyright and license of the Kendryte standalone SDK project and
160 are licensed under the terms of the Apache License, Version 2.0.
162 See also the [third party notices] file for more information.
164 Contributing to OpenSBI
165 -----------------------
167 The OpenSBI project encourages and welcomes contributions. Contributions should
168 follow the rules described in OpenSBI [Contribution Guideline] document.
169 In particular, all patches sent should contain a Signed-off-by tag.
174 Detailed documentation of various aspects of OpenSBI can be found under the
175 *docs* directory. The documentation covers the following topics.
177 * [Contribution Guideline]: Guideline for contributing code to OpenSBI project
178 * [Library Usage]: API documentation of OpenSBI static library *libsbi.a*
179 * [Platform Support Guide]: Guideline for implementing support for new platforms
180 * [Platform Documentation]: Documentation of the platforms currently supported.
181 * [Firmware Documentation]: Documentation for the different types of firmware
182 examples build supported by OpenSBI.
184 OpenSBI source code is also well documented. For source level documentation,
185 doxygen style is used. Please refer to [Doxygen manual] for details on this
188 Doxygen can be installed on Linux distributions using *.deb* packages using
189 the following command.
191 sudo apt-get install doxygen doxygen-latex doxygen-doc doxygen-gui graphviz
194 For *.rpm* based Linux distributions, the following commands can be used.
196 sudo yum install doxygen doxygen-latex doxywizard graphviz
200 sudo yum install doxygen doxygen-latex doxywizard graphviz
203 To build a consolidated *refman.pdf* of all documentation, run:
209 make O=<build_directory> docs
212 the resulting *refman.pdf* will be available under the directory
213 *<build_directory>/docs/latex*. To install this file, run:
219 make I=<install_directory> install_docs
222 *refman.pdf* will be installed under *<install_directory>/docs*.
224 [Github]: https://github.com/riscv/riscv-sbi-doc
225 [U-Boot]: https://www.denx.de/wiki/U-Boot/SourceCode
226 [COPYING.BSD]: COPYING.BSD
227 [SPDX]: http://spdx.org/licenses/
228 [Contribution Guideline]: docs/contributing.md
229 [Library Usage]: docs/library_usage.md
230 [Platform Support Guide]: docs/platform_guide.md
231 [Platform Documentation]: docs/platform/platform.md
232 [Firmware Documentation]: docs/firmware/fw.md
233 [Doxygen manual]: http://www.stack.nl/~dimitri/doxygen/manual.html
234 [standalone SDK]: https://github.com/kendryte/kendryte-standalone-sdk
235 [third party notices]: ThirdPartyNotices.md