Lab5 Tutorial
Lab5 Tutorial
• OpenSBI Introduction
– Overview and features
• Conclusion
OpenSBI Introduction
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 3
What is SBI ?
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 4
What is OpenSBI ?
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 5
Typical Boot Flow
RUNTIME
ROM LOADER BOOTLOADER OS
(OpenSBI)
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 6
Important Features
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 8
Why Platform Specific Support ?
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 10
Adding Support for New Platforms
• The <xyz> platform support directory can also placed outside OpenSBI sources
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 11
Compilation Options for Platform Support
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 12
Using OpenSBI As a Firmware
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 13
Reference Firmwares
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 14
FW_PAYLOAD
Loads
Jumps FW_PAYLOAD
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 15
FW_JUMP
Loads
Jumps
• OpenSBI firmware with a fixed jump address to the next booting stage
– Next stage booting stage (i.e. BOOTLADER) and FW_JUMP are loaded by the previous booting stage
(i.e. LOADER)
– Very useful for QEMU because we can use pre-compiled FW_JUMP
• Down-side:
– Previous booting stage (i.e. LOADER) has to load next booting stage (i.e. BOOTLADER) at a fixed location
– No mechanism to pass parameters from pervious booting stage (i.e. LOADER) to FW_JUMP
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 16
FW_DYNAMIC
Loads
Jumps Passed via ‘a2’ register
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 18
Typical use as Library
Loads
Jumps
External Firmware
(EDK2)
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 19
Constraints on using OpenSBI Library
• Same GCC target options (i.e. -march, -mabi, and -mcmodel) need to be used for the
external firmware and OpenSBI sources
• External firmware must create per-HART non-overlapping:
1. Program Stack
2. OpenSBI scratch space (i.e. struct sbi_scratch instance with extra space above)
• Two constraints in calling any OpenSBI functions from external firmware:
1. MSCRATCH CSR of calling HART must be set to its own OpenSBI scratch space
2. SP register (i.e. the stack pointer) of calling HART must be set to its own stack
• External firmware must also ensure that:
– Interrupts are disabled in the MSTATUS and MIE CSRs when calling sbi_init()
– sbi_init() is called for each HART that is powered-up at boot-time or in response to a CPU hotplug event
– sbi_trap_handler() is called for M-mode interrupts and M-mode traps
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 20
Conclusion
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 21
Important Facts
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 22
On-Going and Future Work
• SBI specifications
– SBI v0.2 specification
– SBI v0.2 HART power management extension
– SBI v0.2 remote fences extension (fence.i, sfence.vma, hfence.gvma, and hfence.bvma)
• OpenSBI
– RISC-V hypervisor extension support (We have a demo here !!!)
– SBI v0.2 support
– SBI v0.2 HART power management support
– SBI v0.2 remote fences support
– Support other M-mode bootloaders such as U-Boot_SPL/Coreboot
– Support RISC-V EDK2 integration
– More platforms support
• Need hardware !
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019 23
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6/12/2019