{"id":13470384,"url":"https://github.com/riscv-software-src/opensbi","last_synced_at":"2025-05-14T07:08:57.431Z","repository":{"id":38016180,"uuid":"156304184","full_name":"riscv-software-src/opensbi","owner":"riscv-software-src","description":"RISC-V Open Source Supervisor Binary Interface","archived":false,"fork":false,"pushed_at":"2025-04-21T04:26:26.000Z","size":2714,"stargazers_count":1174,"open_issues_count":83,"forks_count":561,"subscribers_count":65,"default_branch":"master","last_synced_at":"2025-04-21T05:36:33.887Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/riscv-software-src.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"COPYING.BSD","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-11-06T00:50:48.000Z","updated_at":"2025-04-21T04:26:30.000Z","dependencies_parsed_at":"2023-12-08T12:24:46.595Z","dependency_job_id":"7aed6fa7-c565-46e8-9f42-4e055490bc50","html_url":"https://github.com/riscv-software-src/opensbi","commit_stats":null,"previous_names":["riscv/opensbi"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riscv-software-src%2Fopensbi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riscv-software-src%2Fopensbi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riscv-software-src%2Fopensbi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riscv-software-src%2Fopensbi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/riscv-software-src","download_url":"https://codeload.github.com/riscv-software-src/opensbi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254092776,"owners_count":22013290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T16:00:29.485Z","updated_at":"2025-05-14T07:08:52.417Z","avatar_url":"https://github.com/riscv-software-src.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"RISC-V Open Source Supervisor Binary Interface (OpenSBI)\n========================================================\n\n![RISC-V OpenSBI](docs/riscv_opensbi_logo_final_color.png)\n\nCopyright and License\n---------------------\n\nThe OpenSBI project is:\n\n* Copyright (c) 2019 Western Digital Corporation or its affiliates\n* Copyright (c) 2023 RISC-V International\n\nIt is distributed under the terms of the BSD 2-clause license\n(\"Simplified BSD License\" or \"FreeBSD License\", SPDX: *BSD-2-Clause*).\nA copy of this license with OpenSBI copyright can be found in the file\n[COPYING.BSD].\n\nAll source files in OpenSBI contain the 2-Clause BSD license SPDX short\nidentifier in place of the full license text.\n\n```\nSPDX-License-Identifier:    BSD-2-Clause\n```\n\nThis enables machine processing of license information based on the SPDX\nLicense Identifiers that are available on the [SPDX] web site.\n\nOpenSBI source code also contains code reused from other projects as listed\nbelow. The original license text of these projects is included in the source\nfiles where the reused code is present.\n\n* The libfdt source code is disjunctively dual licensed\n  (GPL-2.0+ OR BSD-2-Clause). Some of this project code is used in OpenSBI\n  under the terms of the BSD 2-Clause license. Any contributions to this\n  code must be made under the terms of both licenses.\n\nSee also the [third party notices] file for more information.\n\nIntroduction\n------------\n\nThe **RISC-V Supervisor Binary Interface (SBI)** is the recommended interface\nbetween:\n\n1. A platform-specific firmware running in M-mode and a bootloader, a\n   hypervisor or a general-purpose OS executing in S-mode or HS-mode.\n2. A hypervisor running in HS-mode and a bootloader or a general-purpose OS\n   executing in VS-mode.\n\nThe *RISC-V SBI specification* is maintained as an independent project by the\nRISC-V Foundation on [Github].\n\nThe goal of the OpenSBI project is to provide an open-source reference\nimplementation of the RISC-V SBI specifications for platform-specific firmwares\nexecuting in M-mode (case 1 mentioned above). An OpenSBI implementation can be\neasily extended by RISC-V platform and system-on-chip vendors to fit a\nparticular hardware configuration.\n\nThe main component of OpenSBI is provided in the form of a platform-independent\nstatic library **libsbi.a** implementing the SBI interface. A firmware or\nbootloader implementation can link against this library to ensure conformance\nwith the SBI interface specifications. *libsbi.a* also defines an interface for\nintegrating with platform-specific operations provided by the platform firmware\nimplementation (e.g. console access functions, inter-processor interrupt\ncontrol, etc).\n\nTo illustrate the use of the *libsbi.a* library, OpenSBI also provides a set of\nplatform-specific support examples. For each example, a platform-specific\nstatic library *libplatsbi.a* can be compiled. This library implements\nSBI call processing by integrating *libsbi.a* with the necessary\nplatform-dependent hardware manipulation functions. For all supported platforms,\nOpenSBI also provides several runtime firmware examples built using the platform\n*libplatsbi.a*. These example firmwares can be used to replace the legacy\n*riscv-pk* bootloader (aka BBL) and enable the use of well-known bootloaders\nsuch as [U-Boot].\n\nSupported SBI version\n---------------------\nCurrently, OpenSBI fully supports SBI specification *v0.2*. OpenSBI also\nsupports Hart State Management (HSM) SBI extension starting from OpenSBI v0.7.\nHSM extension allows S-mode software to boot all the harts a defined order\nrather than legacy method of random booting of harts. As a result, many\nrequired features such as CPU hotplug, kexec/kdump can also be supported easily\nin S-mode. HSM extension in OpenSBI is implemented in a non-backward compatible\nmanner to reduce the maintenance burden and avoid confusion. That's why, any\nS-mode software using OpenSBI will not be able to boot more than 1 hart if HSM\nextension is not supported in S-mode.\n\nLinux kernel already supports SBI v0.2 and HSM SBI extension starting from\n**v5.7-rc1**. If you are using an Linux kernel older than **5.7-rc1** or any\nother S-mode software without HSM SBI extension, you should stick to OpenSBI\nv0.6 to boot all the harts. For a UMP systems, it doesn't matter.\n\nN.B. Any S-mode boot loader (i.e. U-Boot) doesn't need to support HSM extension,\nas it doesn't need to boot all the harts. The operating system should be\ncapable enough to bring up all other non-booting harts using HSM extension.\n\nRequired Toolchain and Packages\n-------------------------------\n\nOpenSBI can be compiled natively or cross-compiled on a host machine. For\ncross-compilation, you can build your own toolchain, download a prebuilt one\nfrom the [Bootlin toolchain repository] or install a distribution-provided\ntoolchain; if you opt to use LLVM/Clang, most distribution toolchains will\nsupport cross-compiling for RISC-V using the same toolchain as your native\nLLVM/Clang toolchain due to LLVM's ability to support multiple backends in the\nsame binary, so is often an easy way to obtain a working cross-compilation\ntoolchain.\n\nToolchains with Position Independent Executable (PIE) support like\n*riscv64-linux-gnu-gcc*, *riscv64-unknown-freebsd-gcc*, or *Clang/LLVM* are\nrequired in order to generate PIE firmware images that can run at arbitrary\naddress with appropriate alignment. Bare-metal GNU toolchains (e.g.\n*riscv64-unknown-elf-gcc*) cannot be used. *Clang/LLVM* can still generate PIE\nimages if a bare-metal triple is used (e.g. *-target riscv64-unknown-elf*).\n\nIn addition to a toolchain, OpenSBI also requires the following packages on\nthe host:\n\n1. device-tree-compiler: The device tree compiler for compiling device\n   tree sources (DTS files).\n2. python3: The python 3.0 (or compatible) language support for various\n   scripts.\n\nBuilding and Installing the OpenSBI Platform-Independent Library\n----------------------------------------------------------------\n\nThe OpenSBI platform-independent static library *libsbi.a* can be compiled\nnatively or it can be cross-compiled on a host with a different base\narchitecture than RISC-V.\n\nFor cross-compiling, the environment variable *CROSS_COMPILE* must be defined\nto specify the name prefix of the RISC-V compiler toolchain executables, e.g.\n*riscv64-linux-gnu-* if the gcc executable used is *riscv64-linux-gnu-gcc*.\n\nTo build *libsbi.a* simply execute:\n```\nmake\n```\n\nAll compiled binaries as well as the resulting *libsbi.a* static library file\nwill be placed in the *build/lib* directory. To specify an alternate build root\ndirectory path, run:\n```\nmake O=\u003cbuild_directory\u003e\n```\n\nTo generate files to be installed for using *libsbi.a* in other projects, run:\n```\nmake install\n```\n\nThis will create the *install* directory with all necessary include files\ncopied under the *install/include* directory and the library file copied into\nthe *install/lib* directory. To specify an alternate installation root\ndirectory path, run:\n```\nmake I=\u003cinstall_directory\u003e install\n```\n\nBuilding and Installing a Reference Platform Static Library and Firmware\n------------------------------------------------------------------------\n\nWhen the *PLATFORM=\u003cplatform_subdir\u003e* argument is specified on the make command\nline, the platform-specific static library *libplatsbi.a* and firmware examples\nare built for the platform *\u003cplatform_subdir\u003e* present in the directory\n*platform* in the OpenSBI top directory. For example, to compile the platform\nlibrary and the firmware examples for the QEMU RISC-V *virt* machine,\n*\u003cplatform_subdir\u003e* should be *generic*.\n\nTo build *libsbi.a*, *libplatsbi.a* and the firmware for one of the supported\nplatforms, run:\n```\nmake PLATFORM=\u003cplatform_subdir\u003e\n```\n\nAn alternate build directory path can also be specified:\n```\nmake PLATFORM=\u003cplatform_subdir\u003e O=\u003cbuild_directory\u003e\n```\n\nThe platform-specific library *libplatsbi.a* will be generated in the\n*build/platform/\u003cplatform_subdir\u003e/lib* directory. The platform firmware files\nwill be under the *build/platform/\u003cplatform_subdir\u003e/firmware* directory.\nThe compiled firmwares will be available in two different formats: an ELF file\nand an expanded image file.\n\nTo install *libsbi.a*, *libplatsbi.a*, and the compiled firmwares, run:\n```\nmake PLATFORM=\u003cplatform_subdir\u003e install\n```\n\nThis will copy the compiled platform-specific libraries and firmware files\nunder the *install/platform/\u003cplatform_subdir\u003e/* directory. An alternate\ninstall root directory path can be specified as follows:\n```\nmake PLATFORM=\u003cplatform_subdir\u003e I=\u003cinstall_directory\u003e install\n```\n\nIn addition, platform-specific configuration options can be specified with the\ntop-level make command line. These options, such as *PLATFORM_\u003cxyz\u003e* or\n*FW_\u003cabc\u003e*, are platform-specific and described in more details in the\n*docs/platform/\u003cplatform_name\u003e.md* files and\n*docs/firmware/\u003cfirmware_name\u003e.md* files.\n\nAll OpenSBI platforms support Kconfig style build-time configuration. Users\ncan change the build-time configuration of a platform using a graphical\ninterface as follows:\n```\nmake PLATFORM=\u003cplatform_subdir\u003e menuconfig\n```\n\nAlternately, an OpenSBI platform can have multiple default configurations\nand users can select a custom default configuration as follows:\n```\nmake PLATFORM=\u003cplatform_subdir\u003e PLATFORM_DEFCONFIG=\u003cplatform_custom_defconfig\u003e\n```\n\nBuilding 32-bit / 64-bit OpenSBI Images\n---------------------------------------\nBy default, building OpenSBI generates 32-bit or 64-bit images based on the\nsupplied RISC-V cross-compile toolchain. For example if *CROSS_COMPILE* is set\nto *riscv64-linux-gnu-*, 64-bit OpenSBI images will be generated. If building\n32-bit OpenSBI images, *CROSS_COMPILE* should be set to a toolchain that is\npre-configured to generate 32-bit RISC-V codes, like *riscv32-linux-gnu-*.\n\nHowever it's possible to explicitly specify the image bits we want to build with\na given RISC-V toolchain. This can be done by setting the environment variable\n*PLATFORM_RISCV_XLEN* to the desired width, for example:\n\n```\nexport CROSS_COMPILE=riscv64-linux-gnu-\nexport PLATFORM_RISCV_XLEN=32\n```\n\nwill generate 32-bit OpenSBI images. And vice vesa.\n\nBuilding with Clang/LLVM\n------------------------\n\nOpenSBI can also be built with Clang/LLVM. To build with just Clang but keep\nthe default binutils (which will still use the *CROSS_COMPILE* prefix if\ndefined), override the *CC* make variable with:\n```\nmake CC=clang\n```\n\nTo build with a full LLVM-based toolchain, not just Clang, enable the *LLVM*\noption with:\n```\nmake LLVM=1\n```\n\nWhen using Clang, *CROSS_COMPILE* often does not need to be defined unless\nusing GNU binutils with prefixed binary names. *PLATFORM_RISCV_XLEN* will be\nused to infer a default triple to pass to Clang, so if *PLATFORM_RISCV_XLEN*\nitself defaults to an undesired value then prefer setting that rather than the\nfull triple via *CROSS_COMPILE*. If *CROSS_COMPILE* is nonetheless defined,\nrather than being used as a prefix for the executable name, it will instead be\npassed via the `--target` option with the trailing `-` removed, so must be a\nvalid triple.\n\nThese can also be mixed; for example using a GCC cross-compiler but LLVM\nbinutils would be:\n```\nmake CC=riscv64-linux-gnu-gcc LLVM=1\n```\n\nThese variables must be passed for all the make invocations described in this\ndocument.\n\nNOTE: Using Clang with a `riscv*-linux-gnu` GNU binutils linker has been seen\nto produce broken binaries with missing relocations; it is therefore currently\nrecommended that this combination be avoided.\n\nBuilding with timestamp and compiler info\n-----------------------------------------\n\nWhen doing development, we may want to know the build time and compiler info\nfor debug purpose. OpenSBI can also be built with timestamp and compiler info.\nTo build with those info and print it out at boot time, we can just simply add\n`BUILD_INFO=y`, like:\n```\nmake BUILD_INFO=y\n```\n\nBut if you have used `BUILD_INFO=y`, and want to switch back to `BUILD_INFO=n`,\nyou must do\n```\nmake clean\n```\nbefore the next build.\n\nNOTE: Using `BUILD_INFO=y` without specifying SOURCE_DATE_EPOCH will violate\n[reproducible builds]. This definition is ONLY for development and debug\npurpose, and should NOT be used in a product which follows \"reproducible\nbuilds\".\n\nBuilding with optimization off for debugging\n--------------------------------------------\n\nWhen debugging OpenSBI, we may want to turn off the compiler optimization and\nmake debugging produce the expected results for a better debugging experience.\nTo build with optimization off we can just simply add `DEBUG=1`, like:\n```\nmake DEBUG=1\n```\n\nThis definition is ONLY for development and debug purpose, and should NOT be\nused in a product build.\n\nContributing to OpenSBI\n-----------------------\n\nThe OpenSBI project encourages and welcomes contributions. Contributions should\nfollow the rules described in the OpenSBI [Contribution Guideline] document.\nIn particular, all patches sent should contain a Signed-off-by tag.\n\nThe [Contributors List] document provides a list of individuals and\norganizations actively contributing to the OpenSBI project.\n\nDocumentation\n-------------\n\nDetailed documentation of various aspects of OpenSBI can be found under the\n*docs* directory. The documentation covers the following topics.\n\n* [Contribution Guideline]: Guideline for contributing code to OpenSBI project\n* [Library Usage]: API documentation of OpenSBI static library *libsbi.a*\n* [Platform Requirements]: Requirements for using OpenSBI on a platform\n* [Platform Support Guide]: Guideline for implementing support for new platforms\n* [Platform Documentation]: Documentation of the platforms currently supported.\n* [Firmware Documentation]: Documentation for the different types of firmware\n  examples build supported by OpenSBI.\n* [Domain Support]: Documentation for the OpenSBI domain support which helps\n  users achieve system-level partitioning using OpenSBI.\n\nOpenSBI source code is also well documented. For source level documentation,\ndoxygen style is used. Please refer to the [Doxygen manual] for details on this\nformat.\n\nDoxygen can be installed on Linux distributions using *.deb* packages using\nthe following command.\n```\nsudo apt-get install doxygen doxygen-latex doxygen-doc doxygen-gui graphviz\n```\n\nFor *.rpm* based Linux distributions, the following commands can be used.\n```\nsudo yum install doxygen doxygen-latex doxywizard graphviz\n```\nor\n```\nsudo yum install doxygen doxygen-latex doxywizard graphviz\n```\n\nTo build a consolidated *refman.pdf* of all documentation, run:\n```\nmake docs\n```\nor\n```\nmake O=\u003cbuild_directory\u003e docs\n```\n\nthe resulting *refman.pdf* will be available under the directory\n*\u003cbuild_directory\u003e/docs/latex*. To install this file, run:\n```\nmake install_docs\n```\nor\n```\nmake I=\u003cinstall_directory\u003e install_docs\n```\n\n*refman.pdf* will be installed under *\u003cinstall_directory\u003e/docs*.\n\n[Github]: https://github.com/riscv/riscv-sbi-doc\n[U-Boot]: https://www.denx.de/wiki/U-Boot/SourceCode\n[Bootlin toolchain repository]: https://toolchains.bootlin.com/\n[COPYING.BSD]: COPYING.BSD\n[SPDX]: http://spdx.org/licenses/\n[Contribution Guideline]: docs/contributing.md\n[Contributors List]: CONTRIBUTORS.md\n[Library Usage]: docs/library_usage.md\n[Platform Requirements]: docs/platform_requirements.md\n[Platform Support Guide]: docs/platform_guide.md\n[Platform Documentation]: docs/platform/platform.md\n[Firmware Documentation]: docs/firmware/fw.md\n[Domain Support]: docs/domain_support.md\n[Doxygen manual]: http://www.doxygen.nl/manual/index.html\n[Kendryte standalone SDK]: https://github.com/kendryte/kendryte-standalone-sdk\n[third party notices]: ThirdPartyNotices.md\n[reproducible builds]: https://reproducible-builds.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friscv-software-src%2Fopensbi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Friscv-software-src%2Fopensbi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friscv-software-src%2Fopensbi/lists"}