OpenSBI Deep Dive
Anup Patel
Western Digital Research
Outline
• OpenSBI Introduction
– Overview and features
• OpenSBI Platform Specific Support
• OpenSBI Usage
– As a firmware: Reference Firmwares
– As a library: API
• Conclusion
OpenSBI Introduction
© 2019 Western Digital Corporation or its affiliates. All rights reserved.
6/12/2019
3
What is SBI ?
• SBI stands for RISC-V Supervisor Binary Interface
– System call style calling convention between Supervisor (S-mode OS) and Supervisor
Execution Environment (SEE)
• SEE can be:
– A M-mode RUNTIME firmware for OS/Hypervisor running in HS-mode
– A HS-mode Hypervisor for Guest OS running in VS-mode
• SBI calls help:
App1
ABI
App2
ABI
OS (S-Mode)
SBI
SEE (M-Mode)
– Reduce duplicate platform code across OSes (Linux, FreeBSD, etc)
– Provide common drivers for an OS which can be shared by multiple platforms
– Provide an interface for direct access to hardware resources (M-mode only resources)
• Specifications being drafted by the Unix Platform Specification Working group
– Maintain and evolve the SBI specifications
– Currently, SBI v0.1 in-use and SBI v0.2 in draft stage
© 2019 Western Digital Corporation or its affiliates. All rights reserved.
6/12/2019
4
What is OpenSBI ?
• OpenSBI is an open-source implementation of the RISC-V Supervisor Binary Interface
(SBI) specifications
– Licensed under the terms of the BSD-2 clause license
– Helps to avoid SBI implementation fragmentation
• Aimed at providing RUNTIME services in M-mode
– Typically used in boot stage following ROM/LOADER
• Provides support for reference platforms
– Generic simple drivers included for M-mode to operate
PLIC, CLINT, UART 8250
– Other platforms can reuse the common code and add needed drivers
© 2019 Western Digital Corporation or its affiliates. All rights reserved.
6/12/2019
5
Typical Boot Flow
Authenticate & Loads
Jumps
• Runs from On-Chip SRAM
• DDR initialization
• Loads RUNTIME and
BOOTLOADER
• Runs from DDR
• Typically open-source
• Filesystem support
• Network booting
• Boot configuration
• Lots of other features
ROM
LOADER
RUNTIME
(OpenSBI)
BOOTLOADER
OS
• Runs from On-Chip
ROM
• Uses On-Chip SRAM
• SOC power-up and
clock setup
• Runs from DDR
• SOC security setup
• Runtime services as-per
specifications
© 2019 Western Digital Corporation or its affiliates. All rights reserved.
6/12/2019
6
Important Features
• Layered structure to accommodate various use cases
– Generic SBI library with platform abstraction
• Typically used with external firmware and bootloader
– EDK2 (UEFI implementation), Secure boot working group
– Platform specific library
• Similar to core library but including platform specific drivers
– Platform specific reference firmware
• Three different types of RUNTIME firmware
• Wide range of hardware features supported
– RV32 and RV64
– Misaligned load/store handling
– Missing CSR emulation
– Protects firmware using PMP support
• Well documented using Doxygen
OpenSBI Layers
Platform Specific
Reference Firmware
Platform Specific
Library
SBI Library
© 2019 Western Digital Corporation or its affiliates. All rights reserved.
6/12/2019
7
OpenSBI Platform Specific Support
© 2019 Western Digital Corporation or its affiliates. All rights reserved.
6/12/2019
8