Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 1/6/2020
An Introduction to RISC-V
Boot Flow
Atish Patra <Atish.Patra@wdc.com>
Anup Patel <Anup.Patel@wdc.com>
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 2
Outline
• Common embedded boot flow
• Current RISC-V boot flow
• OpenSBI Project
• Tutorials
• Current Status
• Future work
• Tutorials
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 3
Prerequisite
• Download the presentation
• Needs a Linux machine (Any distro will do)
• Linux Kernel source code build environment setup (optional)
• Instructions for Ubuntu
shorturl.at/clITU
sudo apt-get install git build-essential kernel-package fakeroot libncurses5-dev libssl-
dev bison flex
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 4
Getting started..
• Create a working directory
• Download cross-compiling toolchain
– https://toolchains.bootlin.com/releases_riscv64.html
• Download pre-built images
– https://wdc.box.com/s/ihywc2xap5m4mflyngjtndf0sy62zha3
• Clone OpenSBI
• Clone U-Boot
shorturl.at/clITU
git clone https://github.com/riscv/opensbi.git
mkdir summit_demo; cd summit_demo
git clone https://github.com/u-boot/u-boot.git ; git checkout v2019.10
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 5
Common boot flow
Commonly used multiple boot stages model
ROM LOADER RUNTIME BOOTLOADER OS
Loads
Jumps
• Runs from On-Chip
ROM
• Uses On-Chip SRAM
• SOC power-up and
clock setup
• DDR initialization
• Loads RUNTIME and
BOOTLOADER
• Examples:
• BIOS/UEFI
• U-Boot SPL
• Coreboot
• Runs from On-Chip SRAM or
DDR
• SOC security setup
• Runtime services as-per
specifications
• Examples:
• ATF
• BIOS/UEFI
• Runs from DDR
• Typically open-source
• Filesystem support
• Network booting
• Boot configuration
• Examples:
• U-Boot
• GRUB
• LinuxBoot
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6
Common boot flow in ARM64
Commonly used multiple boot stages model
ROM
Coreboot/U-Boot
SPL/ ATF BL2
ATF BL31 U-Boot OS
Loads
Jumps
Falcon mode in U-Boot
ARM64
specific
*ATF (ARM TRUSTED FIRMWARE)
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 7
RISC-V Upstream Boot Flow
Follows commonly used multiple boot stages model
• For HiFive Unleashed hardware (only Linux capable RISC-V platform available)
• Follows a standard boot flow
• Uses U-Boot as the last stage boot loader
• U-Boot binary as the payload to OpenSBI
• FSBL is SiFive specific and will be replaced by Coreboot/U-Boot SPL
• OpenSBI is a RISC-V specific runtime service provider
Linux
(S-mode)
(OS)
ZSBL
(M-mode)
(ROM)
FSBL
(M-mode)
(LOADER)
OpenSBI
(M-mode)
(RUNTIME)
U-Boot
(S-mode)
(BOOTLOADER)
Loads
Jumps
RISC-V
specific
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 8
RISC-V boot flow development timeline
OpenSBI
v0.1
release
U-Boot
SMP
support
U-Boot
MMC
support
U-Boot SPL
Coreboot
Legacy
Feb 18
Jan 19
Mar 19
July 19
Jul 19
Aug 19
EDK2
Oct 19
U-Boot
support for
Unleashed
Feb 19Grub
support
Nov 18
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 9
What is SBI ?
• SBI is the 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:
– 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
– Currently, SBI v0.1 in-use and SBI v0.2 in draft stage
– https://github.com/riscv/riscv-sbi-doc
SEE (M-Mode)
SBI
OS (S-Mode)
ABI ABI
App1 App2
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 10
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
– Maintained by the community
• 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
• Source
– https://github.com/riscv/opensbi
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 11
Key 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
– Hypervisor support
– Misaligned load/store handling
– Missing CSR emulation
– Protects firmware using PMP support
Platform Specific
Reference Firmware
Platform Specific
Library
SBI Library
OpenSBI Layers
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 12
Platform support
• SiFive HiFive Unleashed
• Andes AE350
• Ariane FPGA SOC
• Kendryte K210
• QEMU virt machines (32-bit/64-bit)
• OmniXtend
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 13
Tutorial
• Working setup
• Extract toolchain and add it to the environment path
• Change the permission of qemu binary
• Set environment variable CROSS_COMPILE and ARCH
Setup details
chmod a+x qemu-system-riscv64
export ARCH=riscv; export CROSS_COMPILE=riscv64-linux-
tar –xvf riscv64--glibc--bleeding-edge-2018.11-1.tar.bz2
export PATH=$PATH:riscv64--glibc--bleeding-edge-2018.11-1/bin/
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 14
Tutorial-I
• Compile OpenSBI
• Run it in Qemu
Boot Linux in Qemu as a payload to OpenSBI
cd opensbi; make PLATFORM=qemu/virt FW_PAYLOAD_PATH=../linux_Image; cd ..
./qemu-system-riscv64 -M virt -m 256M -nographic 
-kernel opensbi/build/platform/qemu/virt/firmware/fw_payload.elf 
-drive file=linux_rootfs.img,format=raw,id=hd0 
-device virtio-blk-device,drive=hd0 
-append "root=/dev/vda rw console=ttyS0"
Linux kernel
imageVirt machine
in Qemu
OpenSBI
image
Linux rootfs
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 15
Adding Support for New Platforms
• To add support for a new <xyz> platform
1. Create directory named <xyz> under /platform directory
2. Create platform configuration file <xyz>/config.mk
 config.mk will provide compiler flags, select common drivers, and select firmware options
 platform/template/config.mk can be used as reference for creating config.mk
3. Create platform objects file <xyz>/objects.mk for listing platform-specific objects to be compiled
 platform/template/objects.mk can be used as reference for creating objects.mk
4. Create platform source file <xyz>/platform.c providing “struct sbi_platform” instance
 platform/template/platform.c can be used as reference for creating platform.c
• The <xyz> platform support directory can also placed outside OpenSBI sources
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 16
Reference Firmwares
• OpenSBI provides several types of reference firmware, all platform-specific
– FW_PAYLOAD
• Firmware with the next booting stage as a payload
• Default firmware being used in Linux capable RISC-V hardware
– FW_JUMP
• Firmware with fixed jump address to the next booting stage
• Default method for QEMU
– FW_DYNAMIC
• Firmware with dynamic information on the next booting stage
• U-Boot SPL/Coreboot is using FW_DYNAMIC
• SOC Vendors may choose:
– Use one of OpenSBI reference firmwares as their M-mode RUNTIME firmware
– Build M-mode RUNTIME firmware from scratch with OpenSBI as library
– Extend existing M-mode firmwares (U-Boot_M_mode/EDK2) with OpenSBI as library
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 17
U-Boot
• Most commonly used in embedded systems
• Used as a last stage boot loader
• Support
– many ISAs (x86, ARM, AARCH64, RISC-V, ARC..)
– Peripherals (UART, SPI, I2C, ethernet, SD, USB..)
– Multiple file systems
– Various network protocols
• Can load images from network, file system, removable devices
• Easy command line interface for management
• Lot of customization
– U-Boot SPL (a redacted version of U-Boot used as first stage boot loader)
– Falcon mode (for fast booting)
An universal boot loader
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 18
Tutorial - II
• Compile U-Boot
• Compile OpenSBI
• Run it in Qemu
Boot Linux in Qemu using U-Boot proper
cd opensbi; make PLATFORM=qemu/virt; cd ..
virt machine in Qemu
./qemu-system-riscv64 -M virt -smp 4 -m 256M -nographic 
-bios opensbi/build/platform/qemu/virt/firmware/fw_jump.elf 
-kernel u-boot/u-boot.bin -device loader,file=linux_Image,addr=0x84000000 
-drive file=linux_rootfs.img,format=raw,id=hd0 
-device virtio-blk-device,drive=hd0
OpenSBI firmware
(fw_jump)
Kernel address
expected by U-
boot
cd u-boot; make qemu-riscv64_smode_defconfig; make; cd ..
No payload!!
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 19
Tutorial - II
• At U-Boot prompt
Boot Linux in Qemu using U-Boot proper
=>setenv bootargs "root=/dev/vda rw console=ttyS0 earlycon=sbi"
=>cp.l ${fdtcontroladdr} ${fdt_addr_r} 0x10000
=>booti ${kernel_addr_r} - ${fdt_addr_r}
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 20
Boot flow using OpenSBI dynamic firmware
• OpenSBI firmware with dynamic information about the next booting
stage
• Coreboot support available on both hardware & QEMU
• U-Boot SPL available for QEMU and Andes AE350
• HiFive Unleashed U-Boot SPL support not available yet
Passed via ‘a2’ register
Linux
(S-mode)
(OS)
ZSBL
(M-mode)
(ROM)
U-Boot SPL/
Coreboot
(M-mode)
OpenSBI
(M-mode)
(RUNTIME)
U-Boot
(S-mode)
(BOOTLOADER)
Loads
Jumps
Proprietary
Open
Source
RISC-V
specific
struct
fw_dynamic_info
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 21
cd opensbi; make PLATFORM=qemu/virt; cd ..
Tutorial - III
• Compile OpenSBI
• Compile U-Boot SPL
• Run it in Qemu
Boot Linux in Qemu using U-Boot SPL
cd u-boot; export OPENSBI=../opensbi/build/platform/qemu/virt/firmware/fw_dynamic.bin;
ARCH=riscv CROSS_COMPILE=riscv64-linux- make qemu-riscv64_spl_defconfig
ARCH=riscv CROSS_COMPILE=riscv64-linux- make; cd ..
No payload!!
./qemu-system-riscv64 -nographic -machine virt -m 2G -bios u-boot/spl/u-boot-spl 
-kernel u-boot/u-boot.itb -device loader,file=linux_Image,addr=0x86000000 
-drive file=linux_rootfs.img,format=raw,id=hd0 
-device virtio-blk-device,drive=hd0
U-Boot SPL binary
FIT image
(OpenSBI + U-Boot
proper
Path to OpenSBI
dynamic firmware
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 22
Tutorial - III
• At U-Boot prompt
Boot Linux in Qemu using U-Boot proper
=>cp.b 0x86000000 ${kernel_addr_r} 0x1000000
=>setenv bootargs "root=/dev/vda rw console=ttyS0 earlycon=sbi"
=>cp.l ${fdtcontroladdr} ${fdt_addr_r} 0x10000
=>booti ${kernel_addr_r} - ${fdt_addr_r}
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 23
Boot flow using OpenSBI as a library
• OpenSBI as a part of external firmware source
code
• Must configure program stack and scratch
space for OpenSBI
• Same GCC target option for external firmware
and OpenSBI
• Currently EDK2 integration with OpenSBI
– HPE leading this effort
– Available in EDK2 mailing list for U540 on Xilinx VC707
FPGA
– OpenSBI built with EDK2 build environment
– OpenSBI used as library in Pre-EFI Initialization (PEI)
phase
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 24
Constraints on using OpenSBI as a 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:
– Program Stack
– OpenSBI scratch space (i.e. struct sbi_scratch instance with extra space above)
• Two constraints in calling any OpenSBI functions from external firmware:
– MSCRATCH CSR of calling HART must be set to its own OpenSBI scratch space
– 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
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 25
Current status
• OpenSBI
– Actively developed and maintained
– Version 0.5 released
– Default in Buildroot, Yocto/OpenEmbedded and
the QEMU “BIOS”
– Fedora/Debian provides images available with
OpenSBI binary
• U-Boot
– U-Boot-2019.10 release has full support HiFive
Unleashed S-mode
– Boot via network/MMC supported
– FIT image support
– EFI support for RISC-V available
• Grub
– RISC-V support available upstream
• Linux Kernel
– Upstream kernel boots in QEMU
– Device tree hosted in Kernel
– v5.3 kernel works with OpenSBI+U-Boot
on HiFive Unleashed
Rapid progress: traditional full boot support expected by year end
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 26
Future boot support
• EFI stub support in Linux kernel for full UEFI support in progress
– Enterprise class boot environment
• U-Boot SPL support for HiFive Unleashed
• SMP support in coreboot
• EDK2 project upstreaming (in progress)
• Oreboot (Coreboot written in Rust)
• LinuxBoot ?
• Other bootloaders ?
Toward a stable and easy to use boot ecosystem
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 27
Ongoing work
• SBI specifications
– SBI v0.2 specification
– Hart state management extension in SBI
– Legacy SBI extension replacement in SBI
• OpenSBI
– Sequential cpu boot via CPU hotplug
– Support other M-mode boot loader such as
Coreboot/U-Boot SPL
– Hypervisor support when specification changes
– More platforms support
• Need hardware !
• Linux kernel
– SBI v0.2 implementation (patches are under
review)
– EFI stub in Linux kernel (work in progress)
– SBI legacy extension replacements
– Sequential booting
– CPU hotplug
Toward a stable and easy to use boot ecosystem
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 28
Acknowledgements
• U-Boot
– Lukas Auler
– Bin Meng
– Anup Patel
• Coreboot
– Ron Minnich
– Jonathan Neuschäfer
– Patrick Rudolph
– Philip Hug
• EDK2
– Abner Chang
• And others
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 29
Thank you!!
• Q&A ?
© 2019 Western Digital Corporation or its affiliates. All rights reserved. 1/6/2020
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 31
Backup
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 32
EDK2 implementation details
• OpenSBI used as library
• Open Source EDK2 (UEFI implementation) OpenSBI integration
– HPE leading this effort
– Available in EDK2 staging area for U540 on Xilinx VC707 FPGA
– OpenSBI built with EDK2 build environment
Passed via ‘a2’ register
ZSBL
(M-mode)
(ROM)
Bootloader
(Grub/U-
Boot)
Loads
Jumps
Open
Source
RISC-V
specific
EDK2
FSBL
(M-mode)
(ROM)
Linux
(S-Mode)
OS
SEC
phase
PEI phase
(M-Mode)
DXE phase
(S-Mode)
BDS phase
(S-Mode)
EDK2 OpenSBI DXE Driver
(S-Mode)
OpenSBI library
(M-Mode)
1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 33
Reference
• SBI
– https://github.com/riscv/riscv-sbi-doc
• EDK2
– https://edk2.groups.io/g/devel/message/46479?p=,,,20,0,0,0::Created,,riscv,20,2,0,33047245

More Related Content

An Introduction to RISC-V bootflow

  • 1. © 2019 Western Digital Corporation or its affiliates. All rights reserved. 1/6/2020 An Introduction to RISC-V Boot Flow Atish Patra <Atish.Patra@wdc.com> Anup Patel <Anup.Patel@wdc.com>
  • 2. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 2 Outline • Common embedded boot flow • Current RISC-V boot flow • OpenSBI Project • Tutorials • Current Status • Future work • Tutorials
  • 3. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 3 Prerequisite • Download the presentation • Needs a Linux machine (Any distro will do) • Linux Kernel source code build environment setup (optional) • Instructions for Ubuntu shorturl.at/clITU sudo apt-get install git build-essential kernel-package fakeroot libncurses5-dev libssl- dev bison flex
  • 4. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 4 Getting started.. • Create a working directory • Download cross-compiling toolchain – https://toolchains.bootlin.com/releases_riscv64.html • Download pre-built images – https://wdc.box.com/s/ihywc2xap5m4mflyngjtndf0sy62zha3 • Clone OpenSBI • Clone U-Boot shorturl.at/clITU git clone https://github.com/riscv/opensbi.git mkdir summit_demo; cd summit_demo git clone https://github.com/u-boot/u-boot.git ; git checkout v2019.10
  • 5. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 5 Common boot flow Commonly used multiple boot stages model ROM LOADER RUNTIME BOOTLOADER OS Loads Jumps • Runs from On-Chip ROM • Uses On-Chip SRAM • SOC power-up and clock setup • DDR initialization • Loads RUNTIME and BOOTLOADER • Examples: • BIOS/UEFI • U-Boot SPL • Coreboot • Runs from On-Chip SRAM or DDR • SOC security setup • Runtime services as-per specifications • Examples: • ATF • BIOS/UEFI • Runs from DDR • Typically open-source • Filesystem support • Network booting • Boot configuration • Examples: • U-Boot • GRUB • LinuxBoot
  • 6. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 6 Common boot flow in ARM64 Commonly used multiple boot stages model ROM Coreboot/U-Boot SPL/ ATF BL2 ATF BL31 U-Boot OS Loads Jumps Falcon mode in U-Boot ARM64 specific *ATF (ARM TRUSTED FIRMWARE)
  • 7. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 7 RISC-V Upstream Boot Flow Follows commonly used multiple boot stages model • For HiFive Unleashed hardware (only Linux capable RISC-V platform available) • Follows a standard boot flow • Uses U-Boot as the last stage boot loader • U-Boot binary as the payload to OpenSBI • FSBL is SiFive specific and will be replaced by Coreboot/U-Boot SPL • OpenSBI is a RISC-V specific runtime service provider Linux (S-mode) (OS) ZSBL (M-mode) (ROM) FSBL (M-mode) (LOADER) OpenSBI (M-mode) (RUNTIME) U-Boot (S-mode) (BOOTLOADER) Loads Jumps RISC-V specific
  • 8. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 8 RISC-V boot flow development timeline OpenSBI v0.1 release U-Boot SMP support U-Boot MMC support U-Boot SPL Coreboot Legacy Feb 18 Jan 19 Mar 19 July 19 Jul 19 Aug 19 EDK2 Oct 19 U-Boot support for Unleashed Feb 19Grub support Nov 18
  • 9. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 9 What is SBI ? • SBI is the 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: – 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 – Currently, SBI v0.1 in-use and SBI v0.2 in draft stage – https://github.com/riscv/riscv-sbi-doc SEE (M-Mode) SBI OS (S-Mode) ABI ABI App1 App2
  • 10. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 10 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 – Maintained by the community • 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 • Source – https://github.com/riscv/opensbi
  • 11. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 11 Key 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 – Hypervisor support – Misaligned load/store handling – Missing CSR emulation – Protects firmware using PMP support Platform Specific Reference Firmware Platform Specific Library SBI Library OpenSBI Layers
  • 12. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 12 Platform support • SiFive HiFive Unleashed • Andes AE350 • Ariane FPGA SOC • Kendryte K210 • QEMU virt machines (32-bit/64-bit) • OmniXtend
  • 13. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 13 Tutorial • Working setup • Extract toolchain and add it to the environment path • Change the permission of qemu binary • Set environment variable CROSS_COMPILE and ARCH Setup details chmod a+x qemu-system-riscv64 export ARCH=riscv; export CROSS_COMPILE=riscv64-linux- tar –xvf riscv64--glibc--bleeding-edge-2018.11-1.tar.bz2 export PATH=$PATH:riscv64--glibc--bleeding-edge-2018.11-1/bin/
  • 14. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 14 Tutorial-I • Compile OpenSBI • Run it in Qemu Boot Linux in Qemu as a payload to OpenSBI cd opensbi; make PLATFORM=qemu/virt FW_PAYLOAD_PATH=../linux_Image; cd .. ./qemu-system-riscv64 -M virt -m 256M -nographic -kernel opensbi/build/platform/qemu/virt/firmware/fw_payload.elf -drive file=linux_rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -append "root=/dev/vda rw console=ttyS0" Linux kernel imageVirt machine in Qemu OpenSBI image Linux rootfs
  • 15. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 15 Adding Support for New Platforms • To add support for a new <xyz> platform 1. Create directory named <xyz> under /platform directory 2. Create platform configuration file <xyz>/config.mk  config.mk will provide compiler flags, select common drivers, and select firmware options  platform/template/config.mk can be used as reference for creating config.mk 3. Create platform objects file <xyz>/objects.mk for listing platform-specific objects to be compiled  platform/template/objects.mk can be used as reference for creating objects.mk 4. Create platform source file <xyz>/platform.c providing “struct sbi_platform” instance  platform/template/platform.c can be used as reference for creating platform.c • The <xyz> platform support directory can also placed outside OpenSBI sources
  • 16. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 16 Reference Firmwares • OpenSBI provides several types of reference firmware, all platform-specific – FW_PAYLOAD • Firmware with the next booting stage as a payload • Default firmware being used in Linux capable RISC-V hardware – FW_JUMP • Firmware with fixed jump address to the next booting stage • Default method for QEMU – FW_DYNAMIC • Firmware with dynamic information on the next booting stage • U-Boot SPL/Coreboot is using FW_DYNAMIC • SOC Vendors may choose: – Use one of OpenSBI reference firmwares as their M-mode RUNTIME firmware – Build M-mode RUNTIME firmware from scratch with OpenSBI as library – Extend existing M-mode firmwares (U-Boot_M_mode/EDK2) with OpenSBI as library
  • 17. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 17 U-Boot • Most commonly used in embedded systems • Used as a last stage boot loader • Support – many ISAs (x86, ARM, AARCH64, RISC-V, ARC..) – Peripherals (UART, SPI, I2C, ethernet, SD, USB..) – Multiple file systems – Various network protocols • Can load images from network, file system, removable devices • Easy command line interface for management • Lot of customization – U-Boot SPL (a redacted version of U-Boot used as first stage boot loader) – Falcon mode (for fast booting) An universal boot loader
  • 18. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 18 Tutorial - II • Compile U-Boot • Compile OpenSBI • Run it in Qemu Boot Linux in Qemu using U-Boot proper cd opensbi; make PLATFORM=qemu/virt; cd .. virt machine in Qemu ./qemu-system-riscv64 -M virt -smp 4 -m 256M -nographic -bios opensbi/build/platform/qemu/virt/firmware/fw_jump.elf -kernel u-boot/u-boot.bin -device loader,file=linux_Image,addr=0x84000000 -drive file=linux_rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 OpenSBI firmware (fw_jump) Kernel address expected by U- boot cd u-boot; make qemu-riscv64_smode_defconfig; make; cd .. No payload!!
  • 19. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 19 Tutorial - II • At U-Boot prompt Boot Linux in Qemu using U-Boot proper =>setenv bootargs "root=/dev/vda rw console=ttyS0 earlycon=sbi" =>cp.l ${fdtcontroladdr} ${fdt_addr_r} 0x10000 =>booti ${kernel_addr_r} - ${fdt_addr_r}
  • 20. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 20 Boot flow using OpenSBI dynamic firmware • OpenSBI firmware with dynamic information about the next booting stage • Coreboot support available on both hardware & QEMU • U-Boot SPL available for QEMU and Andes AE350 • HiFive Unleashed U-Boot SPL support not available yet Passed via ‘a2’ register Linux (S-mode) (OS) ZSBL (M-mode) (ROM) U-Boot SPL/ Coreboot (M-mode) OpenSBI (M-mode) (RUNTIME) U-Boot (S-mode) (BOOTLOADER) Loads Jumps Proprietary Open Source RISC-V specific struct fw_dynamic_info
  • 21. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 21 cd opensbi; make PLATFORM=qemu/virt; cd .. Tutorial - III • Compile OpenSBI • Compile U-Boot SPL • Run it in Qemu Boot Linux in Qemu using U-Boot SPL cd u-boot; export OPENSBI=../opensbi/build/platform/qemu/virt/firmware/fw_dynamic.bin; ARCH=riscv CROSS_COMPILE=riscv64-linux- make qemu-riscv64_spl_defconfig ARCH=riscv CROSS_COMPILE=riscv64-linux- make; cd .. No payload!! ./qemu-system-riscv64 -nographic -machine virt -m 2G -bios u-boot/spl/u-boot-spl -kernel u-boot/u-boot.itb -device loader,file=linux_Image,addr=0x86000000 -drive file=linux_rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 U-Boot SPL binary FIT image (OpenSBI + U-Boot proper Path to OpenSBI dynamic firmware
  • 22. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 22 Tutorial - III • At U-Boot prompt Boot Linux in Qemu using U-Boot proper =>cp.b 0x86000000 ${kernel_addr_r} 0x1000000 =>setenv bootargs "root=/dev/vda rw console=ttyS0 earlycon=sbi" =>cp.l ${fdtcontroladdr} ${fdt_addr_r} 0x10000 =>booti ${kernel_addr_r} - ${fdt_addr_r}
  • 23. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 23 Boot flow using OpenSBI as a library • OpenSBI as a part of external firmware source code • Must configure program stack and scratch space for OpenSBI • Same GCC target option for external firmware and OpenSBI • Currently EDK2 integration with OpenSBI – HPE leading this effort – Available in EDK2 mailing list for U540 on Xilinx VC707 FPGA – OpenSBI built with EDK2 build environment – OpenSBI used as library in Pre-EFI Initialization (PEI) phase
  • 24. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 24 Constraints on using OpenSBI as a 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: – Program Stack – OpenSBI scratch space (i.e. struct sbi_scratch instance with extra space above) • Two constraints in calling any OpenSBI functions from external firmware: – MSCRATCH CSR of calling HART must be set to its own OpenSBI scratch space – 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
  • 25. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 25 Current status • OpenSBI – Actively developed and maintained – Version 0.5 released – Default in Buildroot, Yocto/OpenEmbedded and the QEMU “BIOS” – Fedora/Debian provides images available with OpenSBI binary • U-Boot – U-Boot-2019.10 release has full support HiFive Unleashed S-mode – Boot via network/MMC supported – FIT image support – EFI support for RISC-V available • Grub – RISC-V support available upstream • Linux Kernel – Upstream kernel boots in QEMU – Device tree hosted in Kernel – v5.3 kernel works with OpenSBI+U-Boot on HiFive Unleashed Rapid progress: traditional full boot support expected by year end
  • 26. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 26 Future boot support • EFI stub support in Linux kernel for full UEFI support in progress – Enterprise class boot environment • U-Boot SPL support for HiFive Unleashed • SMP support in coreboot • EDK2 project upstreaming (in progress) • Oreboot (Coreboot written in Rust) • LinuxBoot ? • Other bootloaders ? Toward a stable and easy to use boot ecosystem
  • 27. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 27 Ongoing work • SBI specifications – SBI v0.2 specification – Hart state management extension in SBI – Legacy SBI extension replacement in SBI • OpenSBI – Sequential cpu boot via CPU hotplug – Support other M-mode boot loader such as Coreboot/U-Boot SPL – Hypervisor support when specification changes – More platforms support • Need hardware ! • Linux kernel – SBI v0.2 implementation (patches are under review) – EFI stub in Linux kernel (work in progress) – SBI legacy extension replacements – Sequential booting – CPU hotplug Toward a stable and easy to use boot ecosystem
  • 28. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 28 Acknowledgements • U-Boot – Lukas Auler – Bin Meng – Anup Patel • Coreboot – Ron Minnich – Jonathan Neuschäfer – Patrick Rudolph – Philip Hug • EDK2 – Abner Chang • And others
  • 29. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 29 Thank you!! • Q&A ?
  • 30. © 2019 Western Digital Corporation or its affiliates. All rights reserved. 1/6/2020
  • 31. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 31 Backup
  • 32. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 32 EDK2 implementation details • OpenSBI used as library • Open Source EDK2 (UEFI implementation) OpenSBI integration – HPE leading this effort – Available in EDK2 staging area for U540 on Xilinx VC707 FPGA – OpenSBI built with EDK2 build environment Passed via ‘a2’ register ZSBL (M-mode) (ROM) Bootloader (Grub/U- Boot) Loads Jumps Open Source RISC-V specific EDK2 FSBL (M-mode) (ROM) Linux (S-Mode) OS SEC phase PEI phase (M-Mode) DXE phase (S-Mode) BDS phase (S-Mode) EDK2 OpenSBI DXE Driver (S-Mode) OpenSBI library (M-Mode)
  • 33. 1/6/2020© 2019 Western Digital Corporation or its affiliates. All rights reserved. 33 Reference • SBI – https://github.com/riscv/riscv-sbi-doc • EDK2 – https://edk2.groups.io/g/devel/message/46479?p=,,,20,0,0,0::Created,,riscv,20,2,0,33047245

Editor's Notes

  1. U-Boot supports MMC card & tftpbooting Why another runtime service Provider ? Why OpenSBI ?? Qemu can load super
  2. That’s the personification of RISC-V I could come up with which tells how incapable is right brain is  Legacy – BBL + Vmlinux as a single binary Grub was ported to RISC-V were upstreamed sometime in last year. UEFI support in U-Boot was done even before that time. But it was way ahead of its time as there was no effort in separating supervisor binary interface implementation from the Linux.
  3. Maintain and evolve the SBI specifications
  4. 20K lines of code 49K – dynamic firmware
  5. SPL (Secondary Program Loader) is a small binary, generated from U-Boot source, that fits in the SRAM and loads the main U-Boot into system RAM. SPL also support network/mmc boot.
  6. OpenSBI firmware with dynamic information about the next booting stage The next stage booting stage (i.e. BOOTLADER) and FW_DYNAMIC are loaded by the previous booting stage (i.e. LOADER) The previous booting stage (i.e. LOADER) passes the location of struct fw_dynamic_info to FW_DYNAMIC via ‘a2’ register Down-side: Previous booting stage (i.e. LOADER) needs to be aware of struct fw_dynamic_info